MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / tryUseFight

Method tryUseFight

source/creatureskill/CreatureSkillMissileLaunch.cpp:69–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69bool CreatureSkillMissileLaunch::tryUseFight(GameMap& gameMap, Creature* creature, float range,
70 GameEntity* attackedObject, Tile* attackedTile, bool ko, bool notifyPlayerIfHit) const
71{
72 Tile* creatureTile = creature->getPositionTile();
73 if(creatureTile == nullptr)
74 {
75 OD_LOG_ERR("creature=" + creature->getName() + ", pos=" + Helper::toString(creature->getPosition()));
76 return false;
77 }
78
79 Ogre::Vector3 position;
80 position.x = static_cast<Ogre::Real>(creatureTile->getX());
81 position.y = static_cast<Ogre::Real>(creatureTile->getY());
82 position.z = CANNON_MISSILE_HEIGHT;
83 Ogre::Vector3 missileDirection(static_cast<Ogre::Real>(attackedTile->getX()),
84 static_cast<Ogre::Real>(attackedTile->getY()), CANNON_MISSILE_HEIGHT);
85 missileDirection = missileDirection - position;
86 missileDirection.normalise();
87
88 double level = static_cast<double>(creature->getLevel());
89 double phyAtk = mPhyAtk + (level * mPhyAtkPerLvl);
90 double magAtk = mMagAtk + (level * mMagAtkPerLvl);
91 double eleAtk = mMagAtk + (level * mEleAtkPerLvl);
92 if(creature->getWeaponL() != nullptr)
93 {
94 phyAtk +=creature->getWeaponL()->getPhysicalDamage();
95 magAtk +=creature->getWeaponL()->getMagicalDamage();
96 eleAtk +=creature->getWeaponL()->getElementDamage();
97 }
98 if(creature->getWeaponR() != nullptr)
99 {
100 phyAtk +=creature->getWeaponR()->getPhysicalDamage();
101 magAtk +=creature->getWeaponR()->getMagicalDamage();
102 eleAtk +=creature->getWeaponR()->getElementDamage();
103 }
104
105 MissileOneHit* missile = new MissileOneHit(&gameMap, creature->getSeat(), creature->getName(),
106 mMissileMesh, mMissilePartScript, missileDirection, mMissileSpeed, phyAtk, magAtk, eleAtk,
107 attackedObject, false, ko, notifyPlayerIfHit);
108 missile->addToGameMap();
109 missile->createMesh();
110 missile->setPosition(position);
111 // We don't want the missile to stay idle for 1 turn. Because we are in a doUpkeep context,
112 // we can safely call the missile doUpkeep as we know the engine will not call it the turn
113 // it has been added
114 missile->doUpkeep();
115
116 return true;
117}
118
119CreatureSkillMissileLaunch* CreatureSkillMissileLaunch::clone() const
120{

Callers

nothing calls this directly

Calls 15

getPositionTileMethod · 0.80
getLevelMethod · 0.80
getWeaponLMethod · 0.80
getPhysicalDamageMethod · 0.80
getMagicalDamageMethod · 0.80
getElementDamageMethod · 0.80
getWeaponRMethod · 0.80
createMeshMethod · 0.80
toStringFunction · 0.50
getXMethod · 0.45
getYMethod · 0.45
getSeatMethod · 0.45

Tested by

no test coverage detected