diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2006-12-27 20:39:21 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2006-12-27 20:39:21 +0000 |
commit | b2ef30efb59c8aa4df3bbaab376d46c583a40d98 (patch) | |
tree | bfa5f4b4dbb937b4413e79427bf1bbab8522dbdb /src | |
parent | 8da32105732949b4b0273c718d118bcfae70a1c9 (diff) | |
download | Mana-b2ef30efb59c8aa4df3bbaab376d46c583a40d98.tar.gz Mana-b2ef30efb59c8aa4df3bbaab376d46c583a40d98.tar.bz2 Mana-b2ef30efb59c8aa4df3bbaab376d46c583a40d98.tar.xz Mana-b2ef30efb59c8aa4df3bbaab376d46c583a40d98.zip |
Client-sided implementation of attacks
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 43 | ||||
-rw-r--r-- | src/gui/popupmenu.cpp | 8 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 23 | ||||
-rw-r--r-- | src/localplayer.cpp | 55 | ||||
-rw-r--r-- | src/localplayer.h | 3 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 17 | ||||
-rw-r--r-- | src/net/beinghandler.h | 1 | ||||
-rw-r--r-- | src/net/connection.cpp | 4 | ||||
-rw-r--r-- | src/net/connection.h | 3 | ||||
-rw-r--r-- | src/net/gameserver/player.cpp | 7 | ||||
-rw-r--r-- | src/net/gameserver/player.h | 1 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 1 | ||||
-rw-r--r-- | src/net/protocol.h | 2 |
13 files changed, 49 insertions, 119 deletions
diff --git a/src/game.cpp b/src/game.cpp index 15298ec6..21b6008e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -509,6 +509,17 @@ void Game::handleInput() } break; + // attacking + // TODO: Reimplement attacking with joystick buttons + // (old code allowed permanent attacking and not 1 attack + // with each button push) + // I would like to do this but i don't own a joystick. + case SDLK_LCTRL: + case SDLK_RCTRL: + player_node->attack(); + used = true; + break; + // Quitting confirmation dialog case SDLK_ESCAPE: if (!exitConfirm) { @@ -651,38 +662,6 @@ void Game::handleInput() player_node->walk(direction); - // Attacking monsters - if (keys[SDLK_LCTRL] || keys[SDLK_RCTRL] || - joystick && joystick->buttonPressed(0)) - { - Being *target = NULL; - bool newTarget = keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]; - - // A set target has highest priority - if (newTarget || !player_node->getTarget()) - { - Uint16 targetX = x, targetY = y; - - if (player_node->getDirection() & Being::UP) - targetY--; - if (player_node->getDirection() & Being::DOWN) - targetY++; - if (player_node->getDirection() & Being::LEFT) - targetX--; - if (player_node->getDirection() & Being::RIGHT) - targetX++; - - // Attack priority is: Monster, Player, auto target - target = beingManager->findBeing( - targetX, targetY, Being::MONSTER); - if (!target) - target = beingManager->findBeing( - targetX, targetY, Being::PLAYER); - } - - player_node->attack(target, newTarget); - } - // Target the nearest monster if 'a' pressed if (keys[SDLK_a]) { diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c2959e1d..c7c77ef4 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -136,14 +136,6 @@ void PopupMenu::handleLink(const std::string& link) tradePartnerName = mBeing->getName(); } - // Attack action - else if (link == "attack" && - mBeing != NULL && - mBeing->getType() == Being::PLAYER) - { - player_node->attack(mBeing, true); - } - /* // Follow Player action else if (link == "follow") diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index d0525a2f..f26d8d70 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -291,29 +291,9 @@ Viewport::mousePress(int mx, int my, int button) Being *being; FloorItem *item; - // Interact with some being - if ((being = beingManager->findBeing(tilex, tiley))) - { - switch (being->getType()) - { - case Being::NPC: - dynamic_cast<NPC*>(being)->talk(); - break; - - case Being::MONSTER: - case Being::PLAYER: - if (being->mAction == Being::DEAD) - break; - player_node->attack(being, true); - break; - - default: - break; - } - } // Pick up some item - else if ((item = floorItemManager->findByCoordinates(tilex, tiley))) + if ((item = floorItemManager->findByCoordinates(tilex, tiley))) { player_node->pickUp(item); } @@ -325,7 +305,6 @@ Viewport::mousePress(int mx, int my, int button) if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) { player_node->setDestination(mx + mCameraX, my + mCameraY); - player_node->stopAttack(); } mPlayerFollowMouse = true; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index c887dd1c..6918fa60 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -51,11 +51,6 @@ LocalPlayer::~LocalPlayer() void LocalPlayer::logic() { - if (mAction == ATTACK && get_elapsed_time(mWalkTime) >= mAttackSpeed) - { - attack(); - } - // Actions are allowed once per second if (get_elapsed_time(mLastAction) >= 1000) { mLastAction = -1; @@ -166,7 +161,6 @@ void LocalPlayer::pickUp(FloorItem *item) } else { setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16); mPickUpTarget = item; - stopAttack(); } } @@ -352,59 +346,26 @@ bool LocalPlayer::tradeRequestOk() const return !mTrading; } -void LocalPlayer::attack(Being *target, bool keep) +void LocalPlayer::attack() { - // Can only attack when standing still - if (mAction != STAND) + if (mLastAction != -1) return; - if (keep && target) - mTarget = target; - else if (mTarget) - target = mTarget; - - if (!target) + // Can only attack when standing still + if (mAction != STAND && mAction != ATTACK) return; - int dist_x = target->mX - mX; - int dist_y = target->mY - mY; - - 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); - } - - // Implement charging attacks here - mLastAttackTime = 0; + mLastAction = tick_time; + mWalkTime = tick_time; setAction(ATTACK); - mWalkTime = tick_time; + if (getWeapon() == 2) sound.playSfx("sfx/bow_shoot_1.ogg"); else sound.playSfx("sfx/fist-swish.ogg"); - // XXX Convert for new server - /* - MessageOut outMsg(0x0089); - outMsg.writeLong(target->getId()); - outMsg.writeByte(0); - */ -} - -void LocalPlayer::stopAttack() -{ - mTarget = NULL; + Net::GameServer::Player::attack(); } Being* LocalPlayer::getTarget() const diff --git a/src/localplayer.h b/src/localplayer.h index f632b1b9..59b59812 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -103,8 +103,7 @@ class LocalPlayer : public Player */ void setTrading(bool trading) { mTrading = trading; } - void attack(Being *target=NULL, bool keep=false); - void stopAttack(); + void attack(); Being* getTarget() const; /** diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 6d8ff6c6..c6db8e33 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -53,6 +53,7 @@ BeingHandler::BeingHandler() //SMSG_PLAYER_UPDATE_2, //SMSG_PLAYER_MOVE, //0x0119, + GPMSG_BEING_ATTACK, GPMSG_BEING_ENTER, GPMSG_BEING_LEAVE, GPMSG_BEINGS_MOVE, @@ -85,6 +86,9 @@ void BeingHandler::handleMessage(MessageIn &msg) case GPMSG_BEINGS_MOVE: handleBeingsMoveMessage(msg); break; + case GPMSG_BEING_ATTACK: + handleBeingAttackMessage(msg); + break; /* case SMSG_BEING_VISIBLE: @@ -432,10 +436,7 @@ void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) { Being *being = beingManager->findBeing(msg.readShort()); if (!being) return; - if (being == player_node->getTarget()) - { - player_node->stopAttack(); - } + beingManager->destroyBeing(being); } @@ -489,3 +490,11 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) } } } + +void BeingHandler::handleBeingAttackMessage(MessageIn &msg) +{ + Being *being = beingManager->findBeing(msg.readShort()); + if (!being) return; + + being->setAction(Being::ATTACK); +} diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index 59539ffe..ca6ad1b6 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -34,6 +34,7 @@ class BeingHandler : public MessageHandler void handleMessage(MessageIn &msg); private: + void handleBeingAttackMessage(MessageIn &msg); void handleBeingEnterMessage(MessageIn &msg); void handleBeingLeaveMessage(MessageIn &msg); void handleBeingsMoveMessage(MessageIn &msg); diff --git a/src/net/connection.cpp b/src/net/connection.cpp index a17bc727..4ce05d4a 100644 --- a/src/net/connection.cpp +++ b/src/net/connection.cpp @@ -48,7 +48,7 @@ bool Net::Connection::connect(const std::string &address, short port) if (address.empty()) { logger->log("Net::Connection::connect() got empty address!"); - mState = ERROR; + mState = NET_ERROR; return false; } @@ -63,7 +63,7 @@ bool Net::Connection::connect(const std::string &address, short port) if (!mConnection) { logger->log("Unable to initiate connection to the server."); - mState = ERROR; + mState = NET_ERROR; return false; } diff --git a/src/net/connection.h b/src/net/connection.h index 179367c6..d8ea3124 100644 --- a/src/net/connection.h +++ b/src/net/connection.h @@ -36,7 +36,8 @@ namespace Net { public: enum State { - OK, ERROR + OK, + NET_ERROR }; ~Connection(); diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp index 1f27276a..46cee230 100644 --- a/src/net/gameserver/player.cpp +++ b/src/net/gameserver/player.cpp @@ -66,3 +66,10 @@ void Net::GameServer::Player::equip(int itemId, char slot) Net::GameServer::connection->send(msg); } + +void Net::GameServer::Player::attack() +{ + MessageOut msg(PGMSG_ATTACK); + + Net::GameServer::connection->send(msg); +} diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h index 34d5bb45..3fb21516 100644 --- a/src/net/gameserver/player.h +++ b/src/net/gameserver/player.h @@ -39,6 +39,7 @@ namespace Net // void pickUp(...); void useItem(int itemId); void equip(int itemId, char slot); + void attack(); } } } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 37291c0a..79875d1c 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -309,7 +309,6 @@ PlayerHandler::handleMapChangeMessage(MessageIn &msg) current_npc = 0; player_node->setAction(Being::STAND); - player_node->stopAttack(); player_node->mX = x; player_node->mY = y; diff --git a/src/net/protocol.h b/src/net/protocol.h index 07b5c926..081a70fc 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -159,6 +159,8 @@ enum { GPMSG_BEING_LEAVE = 0x0201, // W being id PGMSG_WALK = 0x0260, // W*2 destination GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position] [, W*2 destination] }* + PGMSG_ATTACK = 0x0290, // - + GPMSG_BEING_ATTACK = 0x0291, // W being id PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text PGMSG_USE_ITEM = 0x0300, // L item id |