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

Method useAttack

source/entities/Creature.cpp:2039–2064  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2037}
2038
2039void Creature::useAttack(CreatureSkillData& skillData, GameEntity& entityAttack,
2040 Tile& tileAttack, bool ko, bool notifyPlayerIfHit)
2041{
2042 // Turn to face the entity we are attacking and set the animation state to Attack.
2043 const Ogre::Vector3& pos = getPosition();
2044 Ogre::Vector3 walkDirection(tileAttack.getX() - pos.x, tileAttack.getY() - pos.y, 0);
2045 walkDirection.normalise();
2046 setAnimationState(EntityAnimation::attack_anim, false, walkDirection, true);
2047 fireCreatureSound(CreatureSound::Attack);
2048 setNbTurnsWithoutBattle(0);
2049
2050 // Calculate how much damage we do.
2051 Tile* myTile = getPositionTile();
2052 float range = Pathfinding::distanceTile(*myTile, tileAttack);
2053
2054 // We use the skill
2055 skillData.mSkill->tryUseFight(*getGameMap(), this, range,
2056 &entityAttack, &tileAttack, ko, notifyPlayerIfHit);
2057 skillData.mWarmup = skillData.mSkill->getWarmupNbTurns();
2058 skillData.mCooldown = skillData.mSkill->getCooldownNbTurns();
2059
2060 // Fighting is tiring
2061 decreaseWakefulness(0.5);
2062 // but gives experience
2063 receiveExp(1.5);
2064}
2065
2066bool Creature::isActionInList(CreatureActionType action) const
2067{

Callers 2

handleFightMethod · 0.80
handleFightMethod · 0.80

Calls 6

distanceTileFunction · 0.85
getWarmupNbTurnsMethod · 0.80
getCooldownNbTurnsMethod · 0.80
getXMethod · 0.45
getYMethod · 0.45
tryUseFightMethod · 0.45

Tested by

no test coverage detected