diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2009-08-19 17:53:17 +0200 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2009-08-19 18:07:56 +0200 |
commit | 3327475b675bf94fd827ffd36838baa42a84f11b (patch) | |
tree | 074d052fec85537f28916c82f1f84f701736753d /src/game-server/being.cpp | |
parent | e6471b3ffc2f4cc049184a979db7b02c41a8e475 (diff) | |
download | manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.gz manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.bz2 manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.xz manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.zip |
Removed attack shape from items. Added distance check on attacks (values still hardcoded). performAttack now takes a target and a range argument instead of determining the target with accumulate&fire
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 |