From f8f3e17f72d1216bacd5aaa975789b0b790068f6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 24 Oct 2008 19:13:04 +0000 Subject: Made it so the player will auto face its target Fixed it so the correct direction will be Patch by Chuck Miller --- ChangeLog | 6 ++++++ src/localplayer.cpp | 26 ++++++++++++++++++++++++++ src/net/beinghandler.cpp | 11 +++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a77d38b..c25a82e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-24 Chuck Miller + + * src/localplayer.cpp: Made it so the player will auto face its target + * src/net/beinghandler.cpp: Fixed it so the correct direction will be + set + 2008-10-23 Chuck Miller * src/beingmanager.cpp: Fixed a bug causing targets not to work, and diff --git a/src/localplayer.cpp b/src/localplayer.cpp index d272caaf..77fd5b90 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -391,6 +391,32 @@ void LocalPlayer::attack() if (mAction != STAND && mAction != ATTACK) return; + //Face direction of the target + if(mTarget){ + unsigned char dir = 0; + int x = 0, y = 0; + Vector plaPos = this->getPosition(); + Vector tarPos = mTarget->getPosition(); + x = plaPos.x - tarPos.x; + y = plaPos.y - tarPos.y; + if(abs(x) < abs(y)){ + //Check to see if target is above me or below me + if(y > 0){ + dir = UP; + } else { + dir = DOWN; + } + } else { + //check to see if the target is to the left or right of me + if(x > 0){ + dir = LEFT; + } else { + dir = RIGHT; + } + } + setDirection(dir); + } + mLastAction = tick_time; setAction(ATTACK); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index fc3c7d1e..0873764e 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -257,7 +257,7 @@ void BeingHandler::handleBeingAttackMessage(MessageIn &msg) int attackType = msg.readInt8(); if (!being) return; - + switch (direction) { case DIRECTION_UP: being->setDirection(Being::UP); break; @@ -327,5 +327,12 @@ void BeingHandler::handleBeingDirChangeMessage(MessageIn &msg) { Being *being = beingManager->findBeing(msg.readInt16()); if (!being) return; - being->setDirection(msg.readInt8()); + int data = msg.readInt8(); + switch (data) + { + case DIRECTION_UP: being->setDirection(Being::UP); break; + case DIRECTION_DOWN: being->setDirection(Being::DOWN); break; + case DIRECTION_LEFT: being->setDirection(Being::LEFT); break; + case DIRECTION_RIGHT: being->setDirection(Being::RIGHT); break; + } } -- cgit v1.2.3-60-g2f50