diff options
Diffstat (limited to 'src/game-server/being.cpp')
-rw-r--r-- | src/game-server/being.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 66a13a60..e5983ee7 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -19,11 +19,11 @@ */ #include <cassert> +#include <cmath> #include "game-server/being.hpp" #include "defines.h" -#include "game-server/attackzone.hpp" #include "game-server/collisiondetection.hpp" #include "game-server/eventlistener.hpp" #include "game-server/mapcomposite.hpp" @@ -233,17 +233,21 @@ int Being::directionToAngle(int direction) } } -void Being::performAttack(const Damage &damage) +void Being::performAttack(Being *target, unsigned range, const Damage &damage) { - if (!mTarget || mTarget == this || mTarget->getAction() == Being::DEAD || !mTarget->canFight()) + // check target legality + if (!target || target == this || target->getAction() == Being::DEAD || !target->canFight()) return; - - if (getMap()->getPvP() == PVP_NONE && mTarget->getType() == OBJECT_CHARACTER && + if (getMap()->getPvP() == PVP_NONE && target->getType() == OBJECT_CHARACTER && getType() == OBJECT_CHARACTER) return; - LOG_DEBUG("Direction: " << getDirection() << - " Target: " << mTarget->getName()); + // check if target is in range + int distx = this->getPosition().x - target->getPosition().x; + int disty = this->getPosition().y - target->getPosition().y; + int dist = std::sqrt(distx * distx + disty * disty); // pythagoras + if (range + target->getSize() < dist ) + return; mTarget->damage(this, damage); mActionTime += 1000; // set to 10 ticks wait time |