diff options
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index e9bc30f2..782a461a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -71,7 +71,10 @@ #include <cassert> #ifdef TMWSERV_SUPPORT -const short walkingKeyboardDelay = 100; +// This is shorter then it really needs to be for normal use +// But if we ever wanted to increase player speed, having this lower +// Won't hurt +const short walkingKeyboardDelay = 40; #endif LocalPlayer *player_node = NULL; @@ -193,6 +196,8 @@ void LocalPlayer::logic() mLastTarget = -1; } +#endif + if (mTarget) { if (mTarget->getType() == Being::NPC) @@ -203,13 +208,18 @@ void LocalPlayer::logic() } else { +#ifdef TMWSERV_SUPPORT + // Find whether target is in range + const int rangeX = abs(mTarget->getPosition().x - getPosition().x); + const int rangeY = abs(mTarget->getPosition().y - getPosition().y); +#else // Find whether target is in range const int rangeX = abs(mTarget->mX - mX); const int rangeY = abs(mTarget->mY - mY); +#endif const int attackRange = getAttackRange(); const int inRange = rangeX > attackRange || rangeY > attackRange ? 1 : 0; - mTarget->setTargetAnimation( mTargetCursor[inRange][mTarget->getTargetCursorSize()]); @@ -220,7 +230,6 @@ void LocalPlayer::logic() attack(mTarget, true); } } -#endif Player::logic(); } @@ -280,9 +289,7 @@ void LocalPlayer::nextStep() if (mGoingToTarget && mTarget && withinAttackRange(mTarget)) { mAction = Being::STAND; -#ifdef EATHENA_SUPPORT attack(mTarget, true); -#endif mGoingToTarget = false; mPath.clear(); return; @@ -433,9 +440,9 @@ void LocalPlayer::walk(unsigned char dir) int dScaler; // Distance to walk - // Checks our path up to 5 tiles, if a blocking tile is found + // Checks our path up to 2 tiles, if a blocking tile is found // We go to the last good tile, and break out of the loop - for (dScaler = 1; dScaler <= 10; dScaler++) + for (dScaler = 1; dScaler <= 2; dScaler++) { if ( (dx || dy) && !mMap->getWalk( ((int) pos.x + (dx * dScaler)) / 32, @@ -606,7 +613,7 @@ void LocalPlayer::emote(Uint8 emotion) } #ifdef TMWSERV_SUPPORT - +/* void LocalPlayer::attack() { if (mLastAction != -1) @@ -656,16 +663,25 @@ void LocalPlayer::attack() } Net::GameServer::Player::attack(getSpriteDirection()); } - +*/ void LocalPlayer::useSpecial(int special) { Net::GameServer::Player::useSpecial(special); } -#else +#endif void LocalPlayer::attack(Being *target, bool keep) { +#ifdef TMWSERV_SUPPORT + if (mLastAction != -1) + return; + + // Can only attack when standing still + if (mAction != STAND && mAction != ATTACK) + return; +#endif + mKeepAttacking = keep; if (!target || target->getType() == Being::NPC) @@ -676,14 +692,36 @@ void LocalPlayer::attack(Being *target, bool keep) mLastTarget = -1; setTarget(target); } - +#ifdef TMWSERV_SUPPORT + Vector plaPos = this->getPosition(); + Vector tarPos = mTarget->getPosition(); + int dist_x = plaPos.x - tarPos.x; + int dist_y = plaPos.y - tarPos.y; +#else int dist_x = target->mX - mX; int dist_y = target->mY - mY; // Must be standing to attack if (mAction != STAND) 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) @@ -698,9 +736,14 @@ void LocalPlayer::attack(Being *target, bool keep) else setDirection(LEFT); } +#endif +#ifdef TMWSERV_SUPPORT + mLastAction = tick_time; +#else mWalkTime = tick_time; mTargetTime = tick_time; +#endif setAction(ATTACK); @@ -715,14 +758,13 @@ void LocalPlayer::attack(Being *target, bool keep) sound.playSfx("sfx/fist-swish.ogg"); } - Net::getPlayerHandler()->attack(target); - + Net::getPlayerHandler()->attack(target->getId()); +#ifdef EATHENA_SUPPORT if (!keep) stopAttack(); +#endif } -#endif // no TMWSERV_SUPPORT - void LocalPlayer::stopAttack() { if (mTarget) @@ -845,7 +887,7 @@ int LocalPlayer::getAttackRange() const ItemInfo info = weapon->getInfo(); return info.getAttackRange(); } - return 32; // unarmed range + return 48; // unarmed range #else return mAttackRange; #endif |