From 802481a7e19c45da2128de18359b44f1a95c476c Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 26 May 2009 15:25:55 +0100 Subject: Fixed attacking for tmwserv. Added back attacking with keyboard for tmwserv. --- src/game.cpp | 12 +++++++----- src/localplayer.cpp | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 98985e74..41bcc9cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -728,7 +728,7 @@ void Game::handleInput() default: break; } - if (keyboard.isEnabled() && + if (keyboard.isEnabled() && !chatWindow->isInputFocused() && !npcDialog->isInputFocused()) { const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); @@ -988,7 +988,7 @@ void Game::handleInput() } #else player_node->setWalkingDir(direction); - +#endif // Attacking monsters if (keyboard.isKeyActive(keyboard.KEY_ATTACK) || (joystick && joystick->buttonPressed(0))) @@ -1005,7 +1005,11 @@ void Game::handleInput() // A set target has highest priority if (!player_node->getTarget()) { +#ifdef TMWSERV_SUPPORT + Uint16 targetX = x / 32, targetY = y / 32; +#else Uint16 targetX = x, targetY = y; +#endif // Only auto target Monsters target = beingManager->findNearestLivingBeing(targetX, targetY, 20, Being::MONSTER); @@ -1013,8 +1017,6 @@ void Game::handleInput() player_node->attack(target, newTarget); } -#endif - // Target the nearest player/monster/npc if ((keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) || keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || @@ -1058,7 +1060,7 @@ void Game::handleInput() } // Stop attacking if the right key is pressed - if (!keyboard.isKeyActive(keyboard.KEY_ATTACK) + if (!keyboard.isKeyActive(keyboard.KEY_ATTACK) && keyboard.isKeyActive(keyboard.KEY_TARGET)) { player_node->stopAttack(); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index c9dc771d..9cdf0bf8 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -703,6 +703,22 @@ void LocalPlayer::attack(Being *target, bool keep) return; #endif +#ifdef TMWSERV_SUPPORT + if (abs(dist_y) >= abs(dist_x)) + { + if (dist_y < 0) + setDirection(DOWN); + else + setDirection(UP); + } + else + { + if (dist_x < 0) + setDirection(RIGHT); + else + setDirection(LEFT); + } +#else if (abs(dist_y) >= abs(dist_x)) { if (dist_y > 0) @@ -717,6 +733,7 @@ void LocalPlayer::attack(Being *target, bool keep) else setDirection(LEFT); } +#endif #ifdef TMWSERV_SUPPORT mLastAction = tick_time; @@ -738,9 +755,6 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } -#ifdef TMWSERV_SUPPORT - if (mLastAction == STAND) -#endif Net::getPlayerHandler()->attack(target->getId()); #ifdef EATHENA_SUPPORT if (!keep) -- cgit v1.2.3-70-g09d2