From 786df24ec5d10e4251fa69426c53f9c2e5d545f4 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 16 Mar 2011 00:37:34 +0100 Subject: Fixed the attack range handling for both servers. The attack range is always the default for manaserv, as proper equipment handling is to be added. Anyway, now the proper attack range is handled in tmwAthena and is always set a proper minimum for both protocols. --- src/resources/iteminfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/resources') diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 50633f71..c7e97b3c 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -163,7 +163,7 @@ class ItemInfo * Attack action sub-types (bow, sword, ...) are defined in items.xml. */ std::string mAttackAction; - int mAttackRange; /**< Attack range, will be zero if non weapon. */ + int mAttackRange; /**< Attack range, will be -1 if no weapon. */ // Particle to be shown when weapon attacks std::string mMissileParticle; -- cgit v1.2.3-60-g2f50 From 45c3f943b42423dbe162bfac4a57cad013ba0630 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 17 Mar 2011 02:05:52 +0100 Subject: Simplified the get/setAttackRange() functions as requested. The attack range is still hardcoded for Manaserv as long as generic equipment handling hasn't been implemented. --- src/localplayer.cpp | 34 ++++------------------------------ src/localplayer.h | 9 ++++++++- src/net/manaserv/gamehandler.cpp | 3 ++- src/net/tmwa/inventoryhandler.cpp | 4 ++-- src/resources/iteminfo.h | 4 +++- 5 files changed, 19 insertions(+), 35 deletions(-) (limited to 'src/resources') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5ce21916..7daceb0f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -69,7 +69,7 @@ LocalPlayer *player_node = NULL; LocalPlayer::LocalPlayer(int id, int subtype): Being(id, PLAYER, subtype, 0), - mAttackRange(-1), + mAttackRange(ATTACK_RANGE_NOT_SET), mTargetTime(-1), mLastTarget(-1), mTarget(NULL), @@ -911,48 +911,22 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount, void LocalPlayer::setAttackRange(int range) { - // Still no map, so don't do anything for now. - if (!mMap) - return; // When the range is more than the minimal, we accept it - int unarmedRange = mMap->getTileWidth() / 2 * 3; - if (range >= unarmedRange) + if (range > ATTACK_RANGE_NOT_SET) { mAttackRange = range; } else if (Net::getNetworkType() == ServerInfo::TMWATHENA) { // TODO: Fix this to be more generic - Item *weapon = PlayerInfo::getEquipment( - TmwAthena::EQUIP_FIGHT1_SLOT); + Item *weapon = PlayerInfo::getEquipment(TmwAthena::EQUIP_FIGHT1_SLOT); if (weapon) { const ItemInfo info = weapon->getInfo(); - if (info.getAttackRange() >= unarmedRange) + if (info.getAttackRange() > ATTACK_RANGE_NOT_SET) mAttackRange = info.getAttackRange(); - else - mAttackRange = unarmedRange; } } - else - { - mAttackRange = unarmedRange; - } -} - -int LocalPlayer::getAttackRange() -{ - // Still no map, so don't return anything for now. - if (!mMap) - return -1; - // When the range is realistic, we return it - int unarmedRange = mMap->getTileWidth() / 2 * 3; - if (mAttackRange < unarmedRange) - { - // This will set a proper value to the attack range. - setAttackRange(unarmedRange); - } - return mAttackRange; } bool LocalPlayer::withinAttackRange(Being *target) diff --git a/src/localplayer.h b/src/localplayer.h index 696211ee..01f31e01 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -58,6 +58,11 @@ enum PICKUP_DROP_STEAL, }; +/** + * Attack range not set value + */ +enum { ATTACK_RANGE_NOT_SET = -1 }; + /** * The local player character. @@ -116,7 +121,9 @@ class LocalPlayer : public Being /** * Gets the attack range. */ - int getAttackRange(); + int getAttackRange() + { return mAttackRange; } + void attack(Being *target = NULL, bool keep = false); void setGMLevel(int level); diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp index 040a5e6c..63f84fd1 100644 --- a/src/net/manaserv/gamehandler.cpp +++ b/src/net/manaserv/gamehandler.cpp @@ -141,7 +141,8 @@ void GameHandler::gameLoading() chatHandler->connect(); // Attack range from item DB - player_node->setAttackRange(-1); + // TODO: Deharcode it through equipment handling + player_node->setAttackRange(48); } } // namespace ManaServ diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 8ec97a38..88c72ed6 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -416,7 +416,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) { mEquips.setEquipment(getSlot(equipType), -1); // Reset the attack range to unarmed. - player_node->setAttackRange(-1); + player_node->setAttackRange(ATTACK_RANGE_NOT_SET); } break; @@ -433,7 +433,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) { logger->log("Couldn't set attacke range due to the lack" "of an initialized map."); - player_node->setAttackRange(-1); + player_node->setAttackRange(ATTACK_RANGE_NOT_SET); } } break; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index c7e97b3c..2fbcc228 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -163,7 +163,9 @@ class ItemInfo * Attack action sub-types (bow, sword, ...) are defined in items.xml. */ std::string mAttackAction; - int mAttackRange; /**< Attack range, will be -1 if no weapon. */ + + /** Attack range, will be equal to ATTACK_RANGE_NOT_SET if no weapon. */ + int mAttackRange; // Particle to be shown when weapon attacks std::string mMissileParticle; -- cgit v1.2.3-60-g2f50