diff options
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/accountconnection.cpp | 5 | ||||
-rw-r--r-- | src/game-server/character.cpp | 45 | ||||
-rw-r--r-- | src/game-server/character.hpp | 25 | ||||
-rw-r--r-- | src/game-server/inventory.cpp | 82 |
4 files changed, 57 insertions, 100 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 3ae5816e..de1ec618 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -24,14 +24,15 @@ #include "configuration.h" #include "defines.h" #include "game-server/accountconnection.hpp" +#include "game-server/character.hpp" #include "game-server/gamehandler.hpp" #include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/mapmanager.hpp" -#include "game-server/character.hpp" #include "game-server/state.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" +#include "serialize/characterdata.hpp" #include "utils/logger.h" #include "utils/tokendispenser.hpp" #include "utils/tokencollector.hpp" @@ -59,7 +60,7 @@ bool AccountConnection::start() void AccountConnection::sendCharacterData(Character *p) { MessageOut msg(GAMSG_PLAYER_DATA); - p->serialize(msg); + serializeCharacterData(*p, msg); send(msg); } diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index c33300b0..b9613c1f 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -20,15 +20,13 @@ * $Id$ */ -#include "game-server/character.hpp" - #include <cassert> #include "defines.h" +#include "game-server/character.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" - -InventoryItem tempItem; +#include "serialize/characterdata.hpp" Character::Character(MessageIn & msg): Being(OBJECT_CHARACTER, 65535), @@ -37,16 +35,11 @@ Character::Character(MessageIn & msg): mDatabaseID(-1), mName(""), mGender(0), mHairStyle(0), mHairColor(0), mLevel(0), mMoney(0) { - // clear equipment - for (int i = 0; i < EQUIPMENT_SLOTS; ++i) - { - mPossessions.equipment[i] = 0; - } // prepare attributes vector mAttributes.resize(NB_ATTRIBUTES_CHAR, 1); mOldAttributes.resize(NB_ATTRIBUTES_CHAR, 0); // get base attributes - deserialize(msg); + deserializeCharacterData(*this, msg); // give the player 10 weapon skill for testing purpose setAttribute(CHAR_SKILL_WEAPON_UNARMED, 10); @@ -72,38 +65,6 @@ Character::update() } } -int -Character::getNumberOfInventoryItems() const -{ - // TODO: implement after redesign/improvement of Inventory - return 0; -} - -InventoryItem const & -Character::getInventoryItem(unsigned short slot) const -{ - // TODO: implement after redesign/improvement of Inventory - //InventoryItem tempItem; - - tempItem.itemClassId = 0; - tempItem.numberOfItemsInSlot = 0; - tempItem.isEquiped = false; - - return tempItem; -} - -void -Character::clearInventory() -{ - // TODO: implement after redesign/improvement of Inventory -} - -void -Character::addItemToInventory(const InventoryItem& item) -{ - // TODO: implement after redesign/improvement of Inventory -} - void Character::calculateDerivedAttributes() { Being::calculateDerivedAttributes(); diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index 4931624c..275b5e67 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -23,27 +23,21 @@ #ifndef _TMWSERV_CHARACTER_HPP_ #define _TMWSERV_CHARACTER_HPP_ -#include "abstractcharacterdata.hpp" -#include "game-server/being.hpp" - #include <string> #include <vector> +#include "game-server/being.hpp" +#include "common/inventorydata.hpp" + class GameClient; class MessageIn; +class MessageOut; class Point; - -struct Possessions -{ - unsigned short equipment[EQUIPMENT_SLOTS]; - std::vector< InventoryItem > inventory; -}; - /** * The representation of a player's character in the game world. */ -class Character : public Being, public AbstractCharacterData +class Character : public Being { public: @@ -71,8 +65,13 @@ class Character : public Being, public AbstractCharacterData { mClient = c; } /** - * Gets a reference on the possession. - * Used in the current Inventory class + * Gets a reference on the possessions. + */ + Possessions const &getPossessions() const + { return mPossessions; } + + /** + * Gets a reference on the possessions. */ Possessions &getPossessions() { return mPossessions; } diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 0d2a82f5..c8cea6de 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -30,9 +30,6 @@ #include "game-server/itemmanager.hpp" #include "net/messageout.hpp" -// For the InventoryItem structure -#include "abstractcharacterdata.hpp" - Inventory::Inventory(Character *p) : poss(p->getPossessions()), msg(GPMSG_INVENTORY), client(p) {} @@ -62,16 +59,16 @@ void Inventory::sendFull() const for (std::vector< InventoryItem >::iterator i = poss.inventory.begin(), i_end = poss.inventory.end(); i != i_end; ++i) { - if (i->itemClassId) + if (i->itemId) { m.writeByte(slot); - m.writeShort(i->itemClassId); - m.writeByte(i->numberOfItemsInSlot); + m.writeShort(i->itemId); + m.writeByte(i->amount); ++slot; } else { - slot += i->numberOfItemsInSlot; + slot += i->amount; } } @@ -85,10 +82,10 @@ int Inventory::getItem(int slot) const { if (slot == 0) { - return i->itemClassId; + return i->itemId; } - slot -= i->itemClassId ? 1 : i->numberOfItemsInSlot; + slot -= i->itemId ? 1 : i->amount; if (slot < 0) { @@ -109,7 +106,7 @@ int Inventory::getIndex(int slot) const return index; } - slot -= i->itemClassId ? 1 : i->numberOfItemsInSlot; + slot -= i->itemId ? 1 : i->amount; if (slot < 0) { @@ -125,7 +122,7 @@ int Inventory::getSlot(int index) const for (std::vector< InventoryItem >::iterator i = poss.inventory.begin(), i_end = poss.inventory.begin() + index; i != i_end; ++i) { - slot += i->itemClassId ? 1 : i->numberOfItemsInSlot; + slot += i->itemId ? 1 : i->amount; } return slot; } @@ -136,18 +133,18 @@ int Inventory::fillFreeSlot(int itemId, int amount, int maxPerSlot) for (int i = 0, i_end = poss.inventory.size(); i < i_end; ++i) { InventoryItem &it = poss.inventory[i]; - if (it.itemClassId == 0) + if (it.itemId == 0) { int nb = std::min(amount, maxPerSlot); - if (it.numberOfItemsInSlot <= 1) + if (it.amount <= 1) { - it.itemClassId = itemId; - it.numberOfItemsInSlot = nb; + it.itemId = itemId; + it.amount = nb; } else { - --it.numberOfItemsInSlot; - InventoryItem iu = { itemId, nb, false }; + --it.amount; + InventoryItem iu = { itemId, nb }; poss.inventory.insert(poss.inventory.begin() + i, iu); ++i_end; } @@ -169,7 +166,7 @@ int Inventory::fillFreeSlot(int itemId, int amount, int maxPerSlot) { int nb = std::min(amount, maxPerSlot); amount -= nb; - InventoryItem it = { itemId, nb, false }; + InventoryItem it = { itemId, nb }; poss.inventory.push_back(it); msg.writeByte(slot + EQUIP_CLIENT_INVENTORY); @@ -189,15 +186,15 @@ int Inventory::insert(int itemId, int amount) for (std::vector< InventoryItem >::iterator i = poss.inventory.begin(), i_end = poss.inventory.end(); i != i_end; ++i) { - if (i->itemClassId == itemId) + if (i->itemId == itemId) { - int nb = std::min(maxPerSlot - i->numberOfItemsInSlot, amount); - i->numberOfItemsInSlot += nb; + int nb = std::min(maxPerSlot - i->amount, amount); + i->amount += nb; amount -= nb; msg.writeByte(slot + EQUIP_CLIENT_INVENTORY); msg.writeShort(itemId); - msg.writeByte(i->numberOfItemsInSlot); + msg.writeByte(i->amount); if (amount == 0) { @@ -207,7 +204,7 @@ int Inventory::insert(int itemId, int amount) } else { - slot += i->itemClassId ? 1 : i->numberOfItemsInSlot; + slot += i->itemId ? 1 : i->amount; } } @@ -221,9 +218,9 @@ int Inventory::count(int itemId) const for (std::vector< InventoryItem >::iterator i = poss.inventory.begin(), i_end = poss.inventory.end(); i != i_end; ++i) { - if (i->itemClassId == itemId) + if (i->itemId == itemId) { - nb += i->numberOfItemsInSlot; + nb += i->amount; } } @@ -238,23 +235,22 @@ void Inventory::freeIndex(int i) { poss.inventory.pop_back(); } - else if (poss.inventory[i + 1].itemClassId == 0) + else if (poss.inventory[i + 1].itemId == 0) { - it.itemClassId = 0; - it.numberOfItemsInSlot = poss.inventory[i + 1].numberOfItemsInSlot + 1; + it.itemId = 0; + it.amount = poss.inventory[i + 1].amount + 1; poss.inventory.erase(poss.inventory.begin() + i + 1); } else { - it.itemClassId = 0; - it.numberOfItemsInSlot = 1; + it.itemId = 0; + it.amount = 1; } - if (i > 0 && poss.inventory[i - 1].itemClassId == 0) + if (i > 0 && poss.inventory[i - 1].itemId == 0) { // Note: "it" is no longer a valid iterator. - poss.inventory[i - 1].numberOfItemsInSlot - += poss.inventory[i].numberOfItemsInSlot; + poss.inventory[i - 1].amount += poss.inventory[i].amount; poss.inventory.erase(poss.inventory.begin() + i); } } @@ -264,18 +260,18 @@ int Inventory::remove(int itemId, int amount) for (int i = poss.inventory.size() - 1; i >= 0; --i) { InventoryItem &it = poss.inventory[i]; - if (it.itemClassId == itemId) + if (it.itemId == itemId) { - int nb = std::min((int)it.numberOfItemsInSlot, amount); - it.numberOfItemsInSlot -= nb; + int nb = std::min((int)it.amount, amount); + it.amount -= nb; amount -= nb; msg.writeByte(getSlot(i) + EQUIP_CLIENT_INVENTORY); msg.writeShort(itemId); - msg.writeByte(it.numberOfItemsInSlot); + msg.writeByte(it.amount); // If the slot is empty, compress the inventory. - if (it.numberOfItemsInSlot == 0) + if (it.amount == 0) { freeIndex(i); } @@ -300,16 +296,16 @@ int Inventory::removeFromSlot(int slot, int amount) } InventoryItem &it = poss.inventory[i]; - int nb = std::min((int)it.numberOfItemsInSlot, amount); - it.numberOfItemsInSlot -= nb; + int nb = std::min((int)it.amount, amount); + it.amount -= nb; amount -= nb; msg.writeByte(slot + EQUIP_CLIENT_INVENTORY); - msg.writeShort(it.itemClassId); - msg.writeByte(it.numberOfItemsInSlot); + msg.writeShort(it.itemId); + msg.writeByte(it.amount); // If the slot is empty, compress the inventory. - if (it.numberOfItemsInSlot == 0) + if (it.amount == 0) { freeIndex(i); } |