diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-11 01:47:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-11 01:51:41 +0300 |
commit | a54f29e3313c2eb60369055731b0f50bd2ff20a3 (patch) | |
tree | 4d0c59fb180063f9e0933a2c6ee61bc387609d87 /src/actionmanager.cpp | |
parent | 9be7d0ac1127477a5ff5ffb3fb3dd45487eec213 (diff) | |
download | manaverse-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.gz manaverse-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.bz2 manaverse-a54f29e3313c2eb60369055731b0f50bd2ff20a3.tar.xz manaverse-a54f29e3313c2eb60369055731b0f50bd2ff20a3.zip |
Convert attack handling code to new format.
Diffstat (limited to 'src/actionmanager.cpp')
-rw-r--r-- | src/actionmanager.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
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); +} + } |