diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-11 11:10:47 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-12 14:56:28 +0200 |
commit | 9e6a0f98ecb52e04ab5afce817cb1d7fe2076450 (patch) | |
tree | 97b6ffedbfbaf09389fe05c1d183471a97740ebb /src/game-server/combatcomponent.cpp | |
parent | d7fa7ea64f6bb0bc0b097e4bf1ceb4bd9620d0da (diff) | |
download | manaserv-9e6a0f98ecb52e04ab5afce817cb1d7fe2076450.tar.gz manaserv-9e6a0f98ecb52e04ab5afce817cb1d7fe2076450.tar.bz2 manaserv-9e6a0f98ecb52e04ab5afce817cb1d7fe2076450.tar.xz manaserv-9e6a0f98ecb52e04ab5afce817cb1d7fe2076450.zip |
Moved Actor into an Component
This was the final step to remove the hierachy with Entity on the top.
Diffstat (limited to 'src/game-server/combatcomponent.cpp')
-rw-r--r-- | src/game-server/combatcomponent.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/game-server/combatcomponent.cpp b/src/game-server/combatcomponent.cpp index df2d034d..38c7716e 100644 --- a/src/game-server/combatcomponent.cpp +++ b/src/game-server/combatcomponent.cpp @@ -41,11 +41,6 @@ CombatComponent::~CombatComponent() void CombatComponent::update(Entity &entity) { - // Temporary for as long as Being is not split into Components - // Prevents to implement all at once - // TODO: remove this as soon as possible - Actor &actor = static_cast<Actor&>(entity); - auto *beingComponent = entity.getComponent<BeingComponent>(); if (beingComponent->getAction() != ATTACK || !mTarget) @@ -69,12 +64,18 @@ void CombatComponent::update(Entity &entity) for (std::vector<Attack *>::const_iterator it = attacksReady.begin(), it_end = attacksReady.end(); it != it_end; ++it) { + const Point &attackerPosition = + entity.getComponent<ActorComponent>()->getPosition(); + const Point &targetPosition = + mTarget->getComponent<ActorComponent>()->getPosition(); + // check if target is in range using the pythagorean theorem - int distx = actor.getPosition().x - mTarget->getPosition().x; - int disty = actor.getPosition().y - mTarget->getPosition().y; + int distx = attackerPosition.x - targetPosition.x; + int disty = attackerPosition.y - targetPosition.y; int distSquare = (distx * distx + disty * disty); AttackInfo *info = (*it)->getAttackInfo(); - int maxDist = info->getDamage().range + actor.getSize(); + int maxDist = info->getDamage().range + + entity.getComponent<ActorComponent>()->getSize(); if (distSquare <= maxDist * maxDist && (!highestPriorityAttack || @@ -88,9 +89,12 @@ void CombatComponent::update(Entity &entity) { mAttacks.startAttack(highestPriorityAttack); mCurrentAttack = highestPriorityAttack; - beingComponent->setDestination(entity, actor.getPosition()); + const Point &point = + entity.getComponent<ActorComponent>()->getPosition(); + beingComponent->setDestination(entity, point); // TODO: Turn into direction of enemy - actor.raiseUpdateFlags(UPDATEFLAG_ATTACK); + entity.getComponent<ActorComponent>()->raiseUpdateFlags( + UPDATEFLAG_ATTACK); } } @@ -155,7 +159,8 @@ int CombatComponent::damage(Entity &target, { mHitsTaken.push_back(HPloss); const Attribute *HP = beingComponent->getAttribute(ATTR_HP); - LOG_DEBUG("Being " << static_cast<Actor &>(target).getPublicID() + LOG_DEBUG("Being " + << target.getComponent<ActorComponent>()->getPublicID() << " suffered " << HPloss << " damage. HP: " << HP->getModifiedAttribute() << "/" |