diff options
-rw-r--r-- | src/localplayer.cpp | 57 | ||||
-rw-r--r-- | src/localplayer.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/inventoryhandler.cpp | 23 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 2 |
4 files changed, 62 insertions, 22 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 52168237..5ce21916 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(0), + mAttackRange(-1), mTargetTime(-1), mLastTarget(-1), mTarget(NULL), @@ -114,14 +114,10 @@ void LocalPlayer::logic() { if (mMessageTime == 0) { - //const Vector &pos = getPosition(); - MessagePair info = mMessages.front(); particleEngine->addTextRiseFadeOutEffect( info.first, - /*(int) pos.x, - (int) pos.y - 48,*/ getPixelX(), getPixelY() - 48, &userPalette->getColor(info.second), @@ -913,27 +909,50 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount, } } -int LocalPlayer::getAttackRange() +void LocalPlayer::setAttackRange(int range) { - if (mAttackRange > -1) + // 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) { - return mAttackRange; + mAttackRange = range; } - else + else if (Net::getNetworkType() == ServerInfo::TMWATHENA) { - if (Net::getNetworkType() == ServerInfo::TMWATHENA) + // TODO: Fix this to be more generic + Item *weapon = PlayerInfo::getEquipment( + TmwAthena::EQUIP_FIGHT1_SLOT); + if (weapon) { - // TODO: Fix this to be more generic - Item *weapon = PlayerInfo::getEquipment( - TmwAthena::EQUIP_FIGHT1_SLOT); - if (weapon) - { - const ItemInfo info = weapon->getInfo(); - return info.getAttackRange(); - } + const ItemInfo info = weapon->getInfo(); + if (info.getAttackRange() >= unarmedRange) + mAttackRange = info.getAttackRange(); + else + mAttackRange = unarmedRange; } - return 48; // unarmed range } + 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 b1a41697..696211ee 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -111,7 +111,7 @@ class LocalPlayer : public Being /** * Sets the attack range. */ - void setAttackRange(int range) { mAttackRange = range; } + void setAttackRange(int range); /** * Gets the attack range. diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 1d99eca4..8ec97a38 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -24,6 +24,7 @@ #include "configuration.h" #include "equipment.h" #include "event.h" +#include "game.h" #include "inventory.h" #include "item.h" #include "itemshortcut.h" @@ -408,13 +409,33 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) flag = msg.readInt8(); if (!flag) + { SERVER_NOTICE(_("Unable to unequip.")) + } else + { mEquips.setEquipment(getSlot(equipType), -1); + // Reset the attack range to unarmed. + player_node->setAttackRange(-1); + } break; case SMSG_PLAYER_ATTACK_RANGE: - player_node->setAttackRange(msg.readInt16()); + { + // The range is in tiles, so we translate it back to pixels + Map *map = Game::instance()->getCurrentMap(); + if (map) + { + player_node->setAttackRange(msg.readInt16() + * map->getTileWidth()); + } + else + { + logger->log("Couldn't set attacke range due to the lack" + "of an initialized map."); + player_node->setAttackRange(-1); + } + } break; case SMSG_PLAYER_ARROW_EQUIP: 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; |