From a54f29e3313c2eb60369055731b0f50bd2ff20a3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 11 Apr 2012 01:47:14 +0300 Subject: Convert attack handling code to new format. --- src/actionmanager.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/actionmanager.cpp') diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index bbfaf5430..b2df9967b 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -934,6 +934,9 @@ impHandler0(stopAttack) if (player_node) { player_node->stopAttack(); + // not consume if target attack key pressed + if (inputManager.isActionActive(Input::KEY_TARGET_ATTACK)) + return false; return true; } return false; @@ -949,4 +952,73 @@ impHandler0(untarget) return false; } +impHandler0(attack) +{ + if (player_node) + { + if (player_node->getTarget()) + player_node->attack(player_node->getTarget(), true); + return true; + } + return false; +} + +impHandler0(targetAttack) +{ + Being *target = nullptr; + + if (player_node && actorSpriteManager) + { + bool newTarget = !inputManager.isActionActive( + Input::KEY_STOP_ATTACK); + // A set target has highest priority + if (!player_node->getTarget()) + { + // Only auto target Monsters + target = actorSpriteManager->findNearestLivingBeing( + player_node, 90, ActorSprite::MONSTER); + } + else + { + target = player_node->getTarget(); + } + + player_node->attack2(target, newTarget); + return true; + } + return false; +} + +bool setTarget(ActorSprite::Type type); + +bool setTarget(ActorSprite::Type type) +{ + if (actorSpriteManager && player_node) + { + Being *target = actorSpriteManager->findNearestLivingBeing( + player_node, 20, type); + + if (target && target != player_node->getTarget()) + player_node->setTarget(target); + + return true; + } + return false; +} + +impHandler0(targetPlayer) +{ + return setTarget(ActorSprite::PLAYER); +} + +impHandler0(targetMonster) +{ + return setTarget(ActorSprite::MONSTER); +} + +impHandler0(targetNPC) +{ + return setTarget(ActorSprite::NPC); +} + } -- cgit v1.2.3-70-g09d2