From 3b7740f133e195b0a0b11090ea8c2b8a7b64411c Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 18 Aug 2011 01:40:43 +0200 Subject: Got rid of the superfluous definition of the slot number for tA. --- src/net/tmwa/inventoryhandler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 218723e6..bbb734e7 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -34,6 +34,8 @@ #include "net/tmwa/messagehandler.h" +#include "resources/iteminfo.h" + #include namespace TmwAthena { @@ -54,7 +56,7 @@ class EquipBackend : public Equipment::Backend void clear() { - for (int i = 0; i < EQUIPMENT_SIZE; i++) + for (int i = 0; i < EQUIP_VECTOR_END; i++) { if (mEquipment[i] != -1) { @@ -83,7 +85,7 @@ class EquipBackend : public Equipment::Backend } private: - int mEquipment[EQUIPMENT_SIZE]; + int mEquipment[EQUIP_VECTOR_END]; }; /** -- cgit v1.2.3-70-g09d2 From f8551d9ef4a745327bccb9e4cb54a22f6a28cf80 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 18 Aug 2011 02:24:44 +0200 Subject: Made the client able to successfully equip/unequip! --- src/equipment.h | 25 +++- src/gui/equipmentwindow.cpp | 33 ++---- src/net/manaserv/inventoryhandler.cpp | 217 ++++++++++++++++++++++------------ src/net/manaserv/inventoryhandler.h | 53 +++++++-- src/net/manaserv/manaserv_protocol.h | 4 +- src/net/tmwa/inventoryhandler.h | 10 ++ 6 files changed, 233 insertions(+), 109 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/equipment.h b/src/equipment.h index 67317d39..564eb2ee 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -22,6 +22,8 @@ #ifndef EQUIPMENT_H #define EQUIPMENT_H +#include + class Item; class Equipment @@ -33,16 +35,33 @@ class Equipment class Backend { public: - virtual Item *getEquipment(int index) const = 0; + virtual Item *getEquipment(int slotIndex) const = 0; + virtual std::string getSlotName(int slotIndex) const + { return std::string(); } + virtual void clear() = 0; virtual ~Backend() { } + virtual int getSlotNumber() const = 0; + virtual void triggerUnequip(int slotIndex) const = 0; + private: + virtual void readEquipFile() + {} }; /** * Get equipment at the given slot. */ - Item *getEquipment(int index) const - { return mBackend ? mBackend->getEquipment(index) : 0; } + Item *getEquipment(int slotIndex) const + { return mBackend ? mBackend->getEquipment(slotIndex) : 0; } + + const std::string getSlotName(int slotIndex) const + { return mBackend ? mBackend->getSlotName(slotIndex) : std::string(); } + + int getSlotNumber() const + { return mBackend ? mBackend->getSlotNumber() : 0; } + + void triggerUnequip(int slotIndex) const + { if (mBackend) mBackend->triggerUnequip(slotIndex); } /** * Clears equipment. diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index c17b5e04..d3ac82f3 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -97,26 +97,22 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "unequip" && mSelected > -1) { - Item *item = mEquipment->getEquipment(mSelected); - item->doEvent(Event::DoUnequip); + mEquipment->triggerUnequip(mSelected); setSelected(-1); } } Item *EquipmentWindow::getItem(int x, int y) const { - if (Net::getNetworkType() == ServerInfo::TMWATHENA) + for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) { - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) - { - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); - if (tRect.isPointInRect(x, y)) - return mEquipment->getEquipment(i); - } + if (tRect.isPointInRect(x, y)) + return mEquipment->getEquipment(i); } - return NULL; + return 0; } void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) @@ -129,17 +125,14 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { // Checks if any of the presses were in the equip boxes. - if (Net::getNetworkType() == ServerInfo::TMWATHENA) + for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) { - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) - { - Item *item = mEquipment->getEquipment(i); - gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT); + Item *item = mEquipment->getEquipment(i); + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); - if (tRect.isPointInRect(x, y) && item) - setSelected(i); - } + if (tRect.isPointInRect(x, y) && item) + setSelected(i); } } else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index acef8ddd..021d7696 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -29,6 +29,7 @@ #include "log.h" #include "playerinfo.h" +#include "gui/equipmentwindow.h" #include "gui/inventorywindow.h" #include "net/manaserv/connection.h" @@ -38,6 +39,10 @@ #include "resources/iteminfo.h" +#include "utils/stringutils.h" + +#define EQUIP_FILE "equip.xml" + extern Net::InventoryHandler *inventoryHandler; namespace ManaServ { @@ -45,11 +50,11 @@ namespace ManaServ { struct EquipItemInfo { - EquipItemInfo(int itemId, int equipSlot, int amountUsed): - mItemId(itemId), mEquipSlot(equipSlot), mAmountUsed(amountUsed) + EquipItemInfo(int itemId, int slotTypeId, int amountUsed): + mItemId(itemId), mSlotTypeId(slotTypeId), mAmountUsed(amountUsed) {} - int mItemId, mEquipSlot, mAmountUsed; + int mItemId, mSlotTypeId, mAmountUsed; }; extern Connection *gameServerConnection; @@ -59,29 +64,68 @@ EquipBackend::EquipBackend() listen(Event::ClientChannel); } -Item *EquipBackend::getEquipment(int index) const +Item *EquipBackend::getEquipment(int slotIndex) const +{ + Slots::const_iterator it = mSlots.find(slotIndex); + return it == mSlots.end() ? 0 : it->second.item; +} + +std::string EquipBackend::getSlotName(int slotIndex) const { - if (index < 0 || (unsigned) index >= mSlots.size()) - return 0; - return mSlots.at(index); + Slots::const_iterator it = mSlots.find(slotIndex); + return it == mSlots.end() ? std::string() : it->second.name; +} + +void EquipBackend::triggerUnequip(int slotIndex) const +{ + // First get the itemInstance + Slots::const_iterator it = mSlots.find(slotIndex); + + if (it == mSlots.end() || it->second.itemInstance == 0 || !it->second.item) + return; + + Event event(Event::DoUnequip); + event.setItem("item", it->second.item); + event.setInt("itemInstance", it->second.itemInstance); + event.trigger(Event::ItemChannel); } + void EquipBackend::clear() { - for (std::vector::iterator i = mSlots.begin(), i_end = mSlots.end(); - i != i_end; ++i) + for (Slots::iterator i = mSlots.begin(), i_end = mSlots.end(); + i != i_end; ++i) { - if (Item *item = *i) - item->setEquipped(false); + if (i->second.item) + { + delete i->second.item; + i->second.item = 0; + } } - mSlots.assign(mSlots.size(), 0); + mSlots.clear(); } -void EquipBackend::equip(int itemId, int equipSlot, int amountUsed) +void EquipBackend::equip(int itemId, int slotTypeId, int amountUsed, + int itemInstance) { - if (equipSlot < 0 || (unsigned) equipSlot >= mSlotTypes.size()) + if (itemInstance <= 0) + { + logger->log("ManaServ::EquipBackend: Equipment slot %i" + " has an invalid item instance.", slotTypeId); + return; + } + + Slots::iterator it = mSlots.begin(); + Slots::iterator it_end = mSlots.end(); + bool slotTypeFound = false; + for (; it != it_end; ++it) + if (it->second.slotTypeId == (unsigned)slotTypeId) + slotTypeFound = true; + + if (!slotTypeFound) { - logger->log("ManaServ::EquipBackend: Equipment slot out of range"); + logger->log("ManaServ::EquipBackend: Equipment slot %i" + " is not existing.", slotTypeId); return; } @@ -92,50 +136,52 @@ void EquipBackend::equip(int itemId, int equipSlot, int amountUsed) return; } - const SlotType &slotType = mSlotTypes.at(equipSlot); - - Item *itemInstance = new Item(itemId, 1, true); - - // Start at first index and search upwards for free slots to place the - // item at the given inventory slot in - int i = slotType.firstIndex; - const int end_i = i + slotType.count; - - for (; i < end_i && amountUsed > 0; ++i) + // Place the item in the slots with corresponding id until + // the capacity requested has been reached + for (it = mSlots.begin(); it != it_end && amountUsed > 0; ++it) { - if (!mSlots.at(i)) + // If we're on the right slot type and that its unit + // isn't already equipped, we can equip there. + // The slots are already sorted by id, and subId anyway. + if (it->second.slotTypeId == (unsigned)slotTypeId + && (!it->second.itemInstance) && (!it->second.item)) { - mSlots[i] = itemInstance; + it->second.itemInstance = itemInstance; + it->second.item = new Item(itemId, 1, true); --amountUsed; } } } -void EquipBackend::unequip(int equipmentSlot) +void EquipBackend::unequip(int itemInstance) { - if (equipmentSlot < 0 || (unsigned) equipmentSlot >= mSlotTypes.size()) + Slots::iterator it = mSlots.begin(); + Slots::iterator it_end = mSlots.end(); + bool itemInstanceFound = false; + for (; it != it_end; ++it) + if (it->second.itemInstance == (unsigned)itemInstance) + itemInstanceFound = true; + + if (!itemInstanceFound) { - logger->log("ManaServ::EquipBackend: Equipment slot out of range"); + logger->log("ManaServ::EquipBackend: Equipment item instance %i" + " is not existing. The item couldn't be unequipped!", + itemInstance); return; } - const SlotType &slotType = mSlotTypes.at(equipmentSlot); - - // Start at first index and search upwards for free slots to place the - // item at the given inventory slot in - int i = slotType.firstIndex; - const int end_i = i + slotType.count; - bool deleteDone = false; - for (; i < end_i; ++i) + for (it = mSlots.begin(); it != it_end; ++it) { - if (mSlots.at(i)) + if (it->second.itemInstance != (unsigned)itemInstance) + continue; + + // We remove the item + it->second.itemInstance = 0; + // We also delete the item objects + if (it->second.item) { - if (!deleteDone) - { - delete mSlots[i]; - deleteDone = true; - } - mSlots[i] = 0; + delete it->second.item; + it->second.item = 0; } } } @@ -148,38 +194,56 @@ void EquipBackend::event(Event::Channel, const Event &event) void EquipBackend::readEquipFile() { - mSlots.clear(); - mSlotTypes.clear(); + clear(); - XML::Document doc("equip.xml"); + XML::Document doc(EQUIP_FILE); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "equip-slots")) { - logger->log("ManaServ::EquipBackend: Error while reading equip.xml!"); + logger->log("ManaServ::EquipBackend: Error while reading " + EQUIP_FILE "!"); return; } - int slotCount = 0; + // The current client slot index + unsigned int slotIndex = 0; for_each_xml_child_node(childNode, rootNode) { if (!xmlStrEqual(childNode->name, BAD_CAST "slot")) continue; - SlotType slotType; - slotType.name = XML::getProperty(childNode, "name", std::string()); - slotType.count = XML::getProperty(childNode, "capacity", 1); - slotType.visible = XML::getBoolProperty(childNode, "visible", false); - slotType.firstIndex = slotCount; + Slot slot; + slot.slotTypeId = XML::getProperty(childNode, "id", 0); + std::string name = XML::getProperty(childNode, "name", std::string()); + const int capacity = XML::getProperty(childNode, "capacity", 1); - mSlotTypes.push_back(slotType); - slotCount += slotType.count; - } + if (slot.slotTypeId > 0 && capacity > 0) + { + if (name.empty()) + slot.name = toString(slot.slotTypeId); + else + slot.name = name; - mSlots.resize(slotCount); -} + // The map is filled until the capacity is reached + for (int i = 1; i < capacity + 1; ++i) + { + // Add the capacity part in the name + // when there is more than one slot unit. i.e: 1/3, 2/3 + if (capacity > 1) + { + slot.name = name + " " + toString(i) + + "/" + toString(capacity); + } + slot.subId = i; + mSlots.insert(std::make_pair(slotIndex, slot)); + ++slotIndex; + } + } + } +} InventoryHandler::InventoryHandler() { @@ -212,12 +276,12 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) PlayerInfo::setInventoryItem(slot, id, amount); } - // A map of { item instance, {equip slot, item id, amount used}} + // A map of { item instance, {slot type id, item id, amount used}} std::map equipItemsInfo; std::map::iterator it; while (msg.getUnreadLength()) { - int equipSlot = msg.readInt16(); + int slotTypeId = msg.readInt16(); int itemId = msg.readInt16(); int itemInstance = msg.readInt16(); @@ -227,7 +291,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) { // Add a new entry equipItemsInfo.insert(std::make_pair(itemInstance, - EquipItemInfo(itemId, equipSlot, 1))); + EquipItemInfo(itemId, slotTypeId, 1))); } else { @@ -240,8 +304,9 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) ++it) { mEquipBackend.equip(it->second.mItemId, - it->second.mEquipSlot, - it->second.mAmountUsed); + it->second.mSlotTypeId, + it->second.mAmountUsed, + it->first); } } break; @@ -267,18 +332,22 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) // Otherwise equip the item in the given slots while (equipSlotCount--) { - unsigned int equipSlot = msg.readInt16(); + unsigned int parameter = msg.readInt16(); unsigned int amountUsed = msg.readInt16(); if (amountUsed == 0) { - // No slots means to unequip this item - mEquipBackend.unequip(equipSlot); + // No amount means to unequip this item + // Note that in that case, the parameter is + // in fact the itemInstanceId + mEquipBackend.unequip(parameter); } else { - mEquipBackend.equip(itemId, equipSlot, - amountUsed); + int itemInstance = msg.readInt16(); + // The parameter is in that case the slot type id. + mEquipBackend.equip(itemId, parameter, + amountUsed, itemInstance); } } @@ -293,8 +362,9 @@ void InventoryHandler::event(Event::Channel channel, if (channel == Event::ItemChannel) { Item *item = event.getItem("item"); + int itemInstance = event.getInt("itemInstance", 0); - if (!item) + if (!item && itemInstance == 0) return; int index = item->getInvIndex(); @@ -308,7 +378,7 @@ void InventoryHandler::event(Event::Channel channel, else if (event.getType() == Event::DoUnequip) { MessageOut msg(PGMSG_UNEQUIP); - msg.writeInt16(index); + msg.writeInt16(itemInstance); gameServerConnection->send(msg); } else if (event.getType() == Event::DoUse) @@ -370,8 +440,7 @@ void InventoryHandler::event(Event::Channel channel, bool InventoryHandler::canSplit(const Item *item) { - return item && !item->getInfo().getEquippable() - && item->getQuantity() > 1; + return item && item->getQuantity() > 1; } size_t InventoryHandler::getSize(int type) const diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index a57b493a..aed41d6c 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -38,26 +38,59 @@ class EquipBackend : public Equipment::Backend, public EventListener public: EquipBackend(); - Item *getEquipment(int index) const; + Item *getEquipment(int slotIndex) const; + std::string getSlotName(int slotIndex) const; void clear(); - void equip(int itemId, int equipSlot, int amountUsed = 1); - void unequip(int equipSlot); + void equip(int itemId, int slotTypeId, int amountUsed = 1, + int itemInstance = 0); + void unequip(int slotTypeId); void event(Event::Channel channel, const Event &event); + int getSlotNumber() const + { return mSlots.size(); } + + void triggerUnequip(int slotIndex) const; + private: void readEquipFile(); - struct SlotType { + struct Slot { + Slot(): + item(0), + slotTypeId(0), + subId(0), + itemInstance(0) + {} + + // Generic info std::string name; - int count; - bool visible; - int firstIndex; - }; - std::vector mSlots; - std::vector mSlotTypes; + // The Item reference, used for graphical representation + // and info. + Item *item; + + // Manaserv specific info + + // Used to know which (server-side) slot id it is. + unsigned int slotTypeId; + // Static part + // The sub id is used to know in which order the slots are + // when the slotType has more than one slot capacity: + // I.e.: capacity = 6, subId will be between 1 and 6 + // for each slots in the map. + // This is used to sort the multimap along with the slot id. + unsigned int subId; + + // This is the (per character) unique item Id, used especially when + // equipping the same item multiple times on the same slot type. + unsigned int itemInstance; + }; + + // slot client index, slot info + typedef std::map Slots; + Slots mSlots; }; class InventoryHandler : public MessageHandler, Net::InventoryHandler, diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index 12d05e11..624e5ac0 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -91,11 +91,11 @@ enum { PGMSG_PICKUP = 0x0110, // W*2 position PGMSG_DROP = 0x0111, // W slot, W amount PGMSG_EQUIP = 0x0112, // W inventory slot - PGMSG_UNEQUIP = 0x0113, // W equipment slot + PGMSG_UNEQUIP = 0x0113, // W item Instance id PGMSG_MOVE_ITEM = 0x0114, // W slot1, W slot2, W amount GPMSG_INVENTORY = 0x0120, // { W slot, W item id [, W amount] (if item id is nonzero) }* GPMSG_INVENTORY_FULL = 0x0121, // W inventory slot count { W slot, W itemId, W amount }, { W equip slot type, W item id, W item instance}* - GPMSG_EQUIP = 0x0122, // W item Id, W equip slot type count { W equip slot, W capacity used}* + GPMSG_EQUIP = 0x0122, // W item Id, W equip slot type count //{ W equip slot, W capacity used, W item instance}*//<- When equipping, //{ W item instance, W 0}*//<- When unequipping GPMSG_PLAYER_ATTRIBUTE_CHANGE = 0x0130, // { W attribute, D base value (in 1/256ths), D modified value (in 1/256ths)}* GPMSG_PLAYER_EXP_CHANGE = 0x0140, // { W skill, D exp got, D exp needed }* GPMSG_LEVELUP = 0x0150, // W new level, W character points, W correction points diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index bbb734e7..15fa1fac 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -84,6 +84,16 @@ class EquipBackend : public Equipment::Backend inventoryWindow->updateButtons(); } + void triggerUnequip(int slotIndex) const + { + Item *item = getEquipment(slotIndex); + if (item) + item->doEvent(Event::DoUnequip); + } + + int getSlotNumber() const + { return EQUIP_VECTOR_END; } + private: int mEquipment[EQUIP_VECTOR_END]; }; -- cgit v1.2.3-70-g09d2 From e86f83ed987461adabcbc02508107366b8c65558 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 18 Aug 2011 02:43:38 +0200 Subject: Made the equipment window not use server specific code again. I also made the number of slots displayed taken from the equip.xml file for manaserv. --- src/game.cpp | 10 +- src/gui/equipmentwindow.cpp | 169 ++++++++++++++++------------------ src/gui/equipmentwindow.h | 22 ++--- src/net/manaserv/inventoryhandler.cpp | 3 + src/net/tmwa/inventoryhandler.cpp | 5 + 5 files changed, 96 insertions(+), 113 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/game.cpp b/src/game.cpp index af9c2c39..5fb98e6c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -154,15 +154,7 @@ static void createGuiWindows() minimap = new Minimap; chatWindow = new ChatWindow; tradeWindow = new TradeWindow; - switch (Net::getNetworkType()) - { - case ServerInfo::TMWATHENA: - case ServerInfo::MANASERV: - default: - equipmentWindow = - new TmwAthena::TaEquipmentWindow(PlayerInfo::getEquipment()); - break; - } + equipmentWindow = new EquipmentWindow(PlayerInfo::getEquipment()); statusWindow = new StatusWindow; inventoryWindow = new InventoryWindow(PlayerInfo::getInventory()); skillDialog = new SkillDialog; diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index d3ac82f3..91ab38e8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -50,11 +50,27 @@ static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 36; +// Positions of the boxes, 2nd dimension is X and Y respectively. +const int boxPosition[][2] = { + { 90, 40 }, // EQUIP_TORSO_SLOT + { 8, 78 }, // EQUIP_GLOVES_SLOT + { 70, 0 }, // EQUIP_HEAD_SLOT + { 50, 208 }, // EQUIP_LEGS_SLOT + { 90, 208 }, // EQUIP_FEET_SLOT + { 8, 168 }, // EQUIP_RING1_SLOT + { 129, 168 }, // EQUIP_RING2_SLOT + { 50, 40 }, // EQUIP_NECK_SLOT + { 8, 123 }, // EQUIP_FIGHT1_SLOT + { 129, 123 }, // EQUIP_FIGHT2_SLOT + { 129, 78 } // EQUIP_PROJECTILE_SLOT +}; + EquipmentWindow::EquipmentWindow(Equipment *equipment): Window(_("Equipment")), mEquipBox(0), mSelected(-1), - mEquipment(equipment) + mEquipment(equipment), + mBoxesNumber(0) { mItemPopup = new ItemPopup; setupWindow->registerWindowForReset(this); @@ -80,9 +96,27 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): add(mUnequip); } +void EquipmentWindow::loadEquipBoxes() +{ + if (mEquipBox) + delete[] mEquipBox; + + // Load equipment boxes. + mBoxesNumber = mEquipment->getSlotNumber(); + mEquipBox = new EquipBox[mBoxesNumber]; + + for (int i = 0; i < mBoxesNumber; i++) + { + mEquipBox[i].posX = boxPosition[i][0] + getPadding(); + mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); + } +} + EquipmentWindow::~EquipmentWindow() { delete mItemPopup; + if (mEquipBox) + delete[] mEquipBox; } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -91,6 +125,49 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) Window::draw(graphics); Window::drawChildren(graphics); + + // Draw equipment boxes + Graphics *g = static_cast(graphics); + + for (int i = 0; i < mBoxesNumber; i++) + { + if (i == mSelected) + { + const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); + + // Set color to the highlight color + g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); + g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, + mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + } + + // Set color black + g->setColor(gcn::Color(0, 0, 0)); + // Draw box border + g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + + Item *item = mEquipment->getEquipment(i); + if (item) + { + // Draw Item. + Image *image = item->getImage(); + // Ensure the image is drawn with maximum opacity + image->setAlpha(1.0f); + g->drawImage(image, + mEquipBox[i].posX + 2, + mEquipBox[i].posY + 2); + if (i == TmwAthena::EQUIP_PROJECTILE_SLOT) + { + g->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->drawText(toString(item->getQuantity()), + mEquipBox[i].posX + (BOX_WIDTH / 2), + mEquipBox[i].posY - getFont()->getHeight(), + gcn::Graphics::CENTER); + } + } + } } void EquipmentWindow::action(const gcn::ActionEvent &event) @@ -104,7 +181,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event) Item *EquipmentWindow::getItem(int x, int y) const { - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) + for (int i = 0; i < mBoxesNumber; ++i) { gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, BOX_WIDTH, BOX_HEIGHT); @@ -125,7 +202,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) if (mouseEvent.getButton() == gcn::MouseEvent::LEFT) { // Checks if any of the presses were in the equip boxes. - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) + for (int i = 0; i < mBoxesNumber; ++i) { Item *item = mEquipment->getEquipment(i); gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, @@ -149,7 +226,6 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) } } -// Show ItemTooltip void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) { const int x = event.getX(); @@ -157,6 +233,7 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) Item *item = getItem(x, y); + // Show ItemTooltip if (item) { int mouseX, mouseY; @@ -171,7 +248,6 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) } } -// Hide ItemTooltip void EquipmentWindow::mouseExited(gcn::MouseEvent &event) { mItemPopup->setVisible(false); @@ -182,86 +258,3 @@ void EquipmentWindow::setSelected(int index) mSelected = index; mUnequip->setEnabled(mSelected != -1); } - -namespace TmwAthena { - -TaEquipmentWindow::TaEquipmentWindow(Equipment *equipment): - EquipmentWindow(equipment) -{ - // Positions of the boxes, 2nd dimension is X and Y respectively. - const int boxPosition[][2] = { - { 90, 40 }, // EQUIP_TORSO_SLOT - { 8, 78 }, // EQUIP_GLOVES_SLOT - { 70, 0 }, // EQUIP_HEAD_SLOT - { 50, 208 }, // EQUIP_LEGS_SLOT - { 90, 208 }, // EQUIP_FEET_SLOT - { 8, 168 }, // EQUIP_RING1_SLOT - { 129, 168 }, // EQUIP_RING2_SLOT - { 50, 40 }, // EQUIP_NECK_SLOT - { 8, 123 }, // EQUIP_FIGHT1_SLOT - { 129, 123 }, // EQUIP_FIGHT2_SLOT - { 129, 78 } // EQUIP_PROJECTILE_SLOT - }; - - // Load equipment boxes. - mEquipBox = new EquipBox[TmwAthena::EQUIP_VECTOR_END]; - - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) - { - mEquipBox[i].posX = boxPosition[i][0] + getPadding(); - mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight(); - } -} - -TaEquipmentWindow::~TaEquipmentWindow() -{ - delete[] mEquipBox; -} - -void TaEquipmentWindow::draw(gcn::Graphics *graphics) -{ - EquipmentWindow::draw(graphics); - - // Draw equipment boxes - Graphics *g = static_cast(graphics); - - for (int i = 0; i < TmwAthena::EQUIP_VECTOR_END; i++) - { - if (i == mSelected) - { - const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); - - // Set color to the highlight color - g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); - g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT)); - } - - // Set color black - g->setColor(gcn::Color(0, 0, 0)); - // Draw box border - g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT)); - - Item *item = mEquipment->getEquipment(i); - if (item) - { - // Draw Item. - Image *image = item->getImage(); - image->setAlpha(1.0f); // Ensure the image is drawn with maximum opacity - g->drawImage(image, - mEquipBox[i].posX + 2, - mEquipBox[i].posY + 2); - if (i == TmwAthena::EQUIP_PROJECTILE_SLOT) - { - g->setColor(Theme::getThemeColor(Theme::TEXT)); - graphics->drawText(toString(item->getQuantity()), - mEquipBox[i].posX + (BOX_WIDTH / 2), - mEquipBox[i].posY - getFont()->getHeight(), - gcn::Graphics::CENTER); - } - } - } -} - -} // namespace TmwAthena diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 5ba15ae3..0001dd4e 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -53,6 +53,11 @@ class EquipmentWindow : public Window, public gcn::ActionListener void mousePressed(gcn::MouseEvent& mouseEvent); + /** + * Loads the correct amount of displayed equip boxes. + */ + void loadEquipBoxes(); + protected: /** * Equipment box. @@ -67,6 +72,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener int mSelected; /**< Index of selected item. */ Equipment *mEquipment; + int mBoxesNumber; /**< Number of equipment boxes to display */ private: void mouseExited(gcn::MouseEvent &event); @@ -80,22 +86,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener gcn::Button *mUnequip; }; -namespace TmwAthena { - -class TaEquipmentWindow : public EquipmentWindow -{ - public: - TaEquipmentWindow(Equipment *equipment); - ~TaEquipmentWindow(); - - /** - * Draws the equipment window using TmwAthena routine. - */ - void draw(gcn::Graphics *graphics); -}; - -} // namespace TmwAthena - extern EquipmentWindow *equipmentWindow; #endif // EQUIPMENTWINDOW_H diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 021d7696..a5875e08 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -308,6 +308,9 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) it->second.mAmountUsed, it->first); } + // The backend is ready, we can setup the equipment window. + if (equipmentWindow) + equipmentWindow->loadEquipBoxes(); } break; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ff875e69..76eb85f5 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -31,6 +31,7 @@ #include "localplayer.h" #include "log.h" +#include "gui/equipmentwindow.h" #include "gui/widgets/chattab.h" #include "net/messagein.h" @@ -388,6 +389,10 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg) { mEquips.setEquipment(getSlot(equipType), index); } + + // Load the equipment boxes + if (equipmentWindow) + equipmentWindow->loadEquipBoxes(); } break; -- cgit v1.2.3-70-g09d2 From 36239b2d689b862a951a65a9be7376a500f1ace9 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 18 Aug 2011 03:06:53 +0200 Subject: Improved equip slots description for both protocols. Now the itempopup is also telling what equip slot is under the mouse pointer. --- src/gui/equipmentwindow.cpp | 31 ++++++++++++++++++++++++++----- src/gui/equipmentwindow.h | 1 + src/gui/itempopup.cpp | 3 +++ src/net/tmwa/inventoryhandler.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 91ab38e8..212dcd2b 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -192,6 +192,19 @@ Item *EquipmentWindow::getItem(int x, int y) const return 0; } +const std::string EquipmentWindow::getSlotName(int x, int y) const +{ + for (int i = 0; i < mBoxesNumber; ++i) + { + gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT); + + if (tRect.isPointInRect(x, y)) + return mEquipment->getSlotName(i); + } + return std::string(); +} + void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) { Window::mousePressed(mouseEvent); @@ -231,15 +244,23 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) const int x = event.getX(); const int y = event.getY(); - Item *item = getItem(x, y); + int mouseX, mouseY; + SDL_GetMouseState(&mouseX, &mouseY); // Show ItemTooltip - if (item) + std::string slotName = getSlotName(x, y); + if (!slotName.empty()) { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); + mItemPopup->setEquipmentText(slotName); + + Item *item = getItem(x, y); + if (item) + { + mItemPopup->setItem(item->getInfo()); + } + else + mItemPopup->setNoItem(); - mItemPopup->setItem(item->getInfo()); mItemPopup->position(x + getX(), y + getY()); } else diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 0001dd4e..b8e63efc 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -79,6 +79,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener void mouseMoved(gcn::MouseEvent &event); Item *getItem(int x, int y) const; + const std::string getSlotName(int x, int y) const; void setSelected(int index); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index de8378d5..d65764a5 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -145,6 +145,9 @@ void ItemPopup::setNoItem() mItemName->setForegroundColor(Theme::getThemeColor(Theme::GENERIC)); mItemName->setPosition(getPadding(), getPadding()); + mItemDesc->setText(std::string()); + mItemEffect->setText(std::string()); + setContentSize(mItemName->getWidth() + 2 * getPadding(), 0); } diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 15fa1fac..44ddd896 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -36,6 +36,8 @@ #include "resources/iteminfo.h" +#include "utils/gettext.h" + #include namespace TmwAthena { @@ -54,6 +56,37 @@ class EquipBackend : public Equipment::Backend return PlayerInfo::getInventory()->getItem(invyIndex); } + std::string getSlotName(int slotIndex) const + { + switch (slotIndex) + { + case EQUIP_TORSO_SLOT: + return std::string(_("Torso")); + case EQUIP_ARMS_SLOT: + return std::string(_("Arms")); + case EQUIP_HEAD_SLOT: + return std::string(_("Head")); + case EQUIP_LEGS_SLOT: + return std::string(_("Legs")); + case EQUIP_FEET_SLOT: + return std::string(_("Feet")); + case EQUIP_RING1_SLOT: + return std::string(_("Ring 1/2")); + case EQUIP_RING2_SLOT: + return std::string(_("Ring 2/2")); + case EQUIP_NECKLACE_SLOT: + return std::string(_("Necklace")); + case EQUIP_FIGHT1_SLOT: + return std::string(_("Hand 1/2")); + case EQUIP_FIGHT2_SLOT: + return std::string(_("Hand 2/2")); + case EQUIP_PROJECTILE_SLOT: + return std::string(_("Ammo")); + default: + return std::string(); + } + } + void clear() { for (int i = 0; i < EQUIP_VECTOR_END; i++) -- cgit v1.2.3-70-g09d2 From 27114fa2694318f2a1c56cb828a3b79731efcb74 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 19 Aug 2011 02:37:09 +0200 Subject: Fixed visible equipment updates, and made it based on equip.xml. --- src/being.cpp | 2 -- src/net/inventoryhandler.h | 7 +++++++ src/net/manaserv/beinghandler.cpp | 34 ++++++++++++---------------------- src/net/manaserv/beinghandler.h | 10 ++++++++++ src/net/manaserv/charhandler.cpp | 12 ++++++++---- src/net/manaserv/inventoryhandler.cpp | 29 +++++++++++++++++++++++++++++ src/net/manaserv/inventoryhandler.h | 27 ++++++++++++++++++++++++++- src/net/manaserv/manaserv_protocol.h | 21 ++------------------- src/net/tmwa/inventoryhandler.h | 18 ++++++++++++++++++ 9 files changed, 112 insertions(+), 48 deletions(-) (limited to 'src/net/tmwa') diff --git a/src/being.cpp b/src/being.cpp index 4f546f6d..6c2a1517 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1067,8 +1067,6 @@ void Being::updateColors() void Being::setSprite(unsigned int slot, int id, const std::string &color, bool isWeapon) { - assert(slot < Net::getCharHandler()->maxSprite()); - if (slot >= size()) ensureSize(slot + 1); diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index 93b56a40..f1dea956 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -38,6 +38,13 @@ class InventoryHandler // TODO: fix/remove me virtual size_t getSize(int type) const = 0; + + virtual bool isWeaponSlot(unsigned int slotTypeId) const = 0; + + virtual bool isAmmoSlot(unsigned int slotTypeId) const = 0; + + virtual unsigned int getVisibleSlotsNumber() const + { return 0; } }; } // namespace Net diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 4d45da8a..44c3d77b 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -31,8 +31,10 @@ #include "gui/okdialog.h" +#include "net/net.h" #include "net/messagein.h" +#include "net/manaserv/inventoryhandler.h" #include "net/manaserv/playerhandler.h" #include "net/manaserv/manaserv_protocol.h" @@ -93,29 +95,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) static void handleLooks(Being *being, Net::MessageIn &msg) { - // Order of sent slots. Has to be in sync with the server code. - static int const nb_slots = 4; - static int const slots[nb_slots] = - { SPRITE_WEAPON, SPRITE_HAT, SPRITE_TOPCLOTHES, - SPRITE_BOTTOMCLOTHES }; + int lookChanges = msg.readInt8(); - int mask = msg.readInt8(); - - if (mask & (1 << 7)) - { - // The equipment has to be cleared first. - for (int i = 0; i < nb_slots; ++i) - { - being->setSprite(slots[i], 0); - } - } + if (lookChanges <= 0) + return; - // Fill slots enumerated by the bitmask. - for (int i = 0; i < nb_slots; ++i) + while (lookChanges-- > 0) { - if (!(mask & (1 << i))) continue; - int id = msg.readInt16(); - being->setSprite(slots[i], id,"", (slots[i] == SPRITE_WEAPON)); + unsigned int slotTypeId = msg.readInt8(); + being->setSprite(slotTypeId + FIXED_SPRITE_LAYER_SIZE, + msg.readInt16(), "", + Net::getInventoryHandler()->isWeaponSlot(slotTypeId)); } } @@ -154,7 +144,7 @@ void BeingHandler::handleBeingEnterMessage(Net::MessageIn &msg) being->setName(name); } int hs = msg.readInt8(), hc = msg.readInt8(); - being->setSprite(SPRITE_HAIR, hs * -1, ColorDB::get(hc)); + being->setSprite(SPRITE_LAYER_HAIR, hs * -1, ColorDB::get(hc)); being->setGender(msg.readInt8() == GENDER_MALE ? GENDER_MALE : GENDER_FEMALE); handleLooks(being, msg); @@ -342,7 +332,7 @@ void BeingHandler::handleBeingLooksChangeMessage(Net::MessageIn &msg) { int style = msg.readInt16(); int color = msg.readInt16(); - being->setSprite(SPRITE_HAIR, style * -1, ColorDB::get(color)); + being->setSprite(SPRITE_LAYER_HAIR, style * -1, ColorDB::get(color)); } } diff --git a/src/net/manaserv/beinghandler.h b/src/net/manaserv/beinghandler.h index 04c766d9..4a1f9f21 100644 --- a/src/net/manaserv/beinghandler.h +++ b/src/net/manaserv/beinghandler.h @@ -28,6 +28,16 @@ namespace ManaServ { +/** + * enum for sprites layers. + */ +enum SpriteLayer +{ + SPRITE_LAYER_BASE = 0, + SPRITE_LAYER_HAIR, + FIXED_SPRITE_LAYER_SIZE +}; + class BeingHandler : public MessageHandler { public: diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 79f3b35a..b1ddc96a 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -34,6 +34,8 @@ #include "net/manaserv/connection.h" #include "net/manaserv/gamehandler.h" +#include "net/manaserv/beinghandler.h" +#include "net/manaserv/inventoryhandler.h" #include "net/manaserv/messagein.h" #include "net/manaserv/messageout.h" #include "net/manaserv/manaserv_protocol.h" @@ -355,17 +357,19 @@ void CharHandler::switchCharacter() unsigned int CharHandler::baseSprite() const { - return SPRITE_BASE; + return SPRITE_LAYER_BASE; } unsigned int CharHandler::hairSprite() const { - return SPRITE_HAIR; + return SPRITE_LAYER_HAIR; } unsigned int CharHandler::maxSprite() const { - return SPRITE_VECTOREND; + static unsigned int visibleSlots = FIXED_SPRITE_LAYER_SIZE + + Net::getInventoryHandler()->getVisibleSlotsNumber(); + return visibleSlots; } void CharHandler::updateCharacters() @@ -387,7 +391,7 @@ void CharHandler::updateCharacters() LocalPlayer *player = character->dummy = new LocalPlayer; player->setName(info.name); player->setGender(info.gender); - player->setSprite(SPRITE_HAIR, info.hairStyle * -1, + player->setSprite(SPRITE_LAYER_HAIR, info.hairStyle * -1, ColorDB::get(info.hairColor)); character->data.mAttributes[LEVEL] = info.level; character->data.mAttributes[CHAR_POINTS] = info.characterPoints; diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index a5875e08..1a74f732 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -62,6 +62,7 @@ extern Connection *gameServerConnection; EquipBackend::EquipBackend() { listen(Event::ClientChannel); + mVisibleSlots = 0; } Item *EquipBackend::getEquipment(int slotIndex) const @@ -208,6 +209,7 @@ void EquipBackend::readEquipFile() // The current client slot index unsigned int slotIndex = 0; + mVisibleSlots = 0; for_each_xml_child_node(childNode, rootNode) { @@ -218,6 +220,11 @@ void EquipBackend::readEquipFile() slot.slotTypeId = XML::getProperty(childNode, "id", 0); std::string name = XML::getProperty(childNode, "name", std::string()); const int capacity = XML::getProperty(childNode, "capacity", 1); + slot.weaponSlot = XML::getBoolProperty(childNode, "weapon", false); + slot.ammoSlot = XML::getBoolProperty(childNode, "ammo", false); + + if (XML::getBoolProperty(childNode, "visible", false)) + ++mVisibleSlots; if (slot.slotTypeId > 0 && capacity > 0) { @@ -245,6 +252,28 @@ void EquipBackend::readEquipFile() } } +bool EquipBackend::isWeaponSlot(int slotTypeId) const +{ + for (Slots::const_iterator it = mSlots.begin(), it_end = mSlots.end(); + it != it_end; ++it) + { + if (it->second.slotTypeId == (unsigned)slotTypeId) + return it->second.weaponSlot; + } + return false; +} + +bool EquipBackend::isAmmoSlot(int slotTypeId) const +{ + for (Slots::const_iterator it = mSlots.begin(), it_end = mSlots.end(); + it != it_end; ++it) + { + if (it->second.slotTypeId == (unsigned)slotTypeId) + return it->second.ammoSlot; + } + return false; +} + InventoryHandler::InventoryHandler() { static const Uint16 _messages[] = { diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index aed41d6c..bf3022ab 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -51,8 +51,14 @@ class EquipBackend : public Equipment::Backend, public EventListener int getSlotNumber() const { return mSlots.size(); } + unsigned int getVisibleSlotsNumber() const + { return mVisibleSlots; } + void triggerUnequip(int slotIndex) const; + bool isWeaponSlot(int slotTypeId) const; + bool isAmmoSlot(int slotTypeId) const; + private: void readEquipFile(); @@ -61,7 +67,9 @@ class EquipBackend : public Equipment::Backend, public EventListener item(0), slotTypeId(0), subId(0), - itemInstance(0) + itemInstance(0), + weaponSlot(false), + ammoSlot(false) {} // Generic info @@ -86,8 +94,16 @@ class EquipBackend : public Equipment::Backend, public EventListener // This is the (per character) unique item Id, used especially when // equipping the same item multiple times on the same slot type. unsigned int itemInstance; + + // Tell whether the slot is a weapon slot + bool weaponSlot; + + // Tell whether the slot is an ammo slot + bool ammoSlot; }; + unsigned int mVisibleSlots; + // slot client index, slot info typedef std::map Slots; Slots mSlots; @@ -107,6 +123,15 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler, size_t getSize(int type) const; + bool isWeaponSlot(unsigned int slotTypeId) const + { return mEquipBackend.isWeaponSlot(slotTypeId); } + + bool isAmmoSlot(unsigned int slotTypeId) const + { return mEquipBackend.isAmmoSlot(slotTypeId); } + + unsigned int getVisibleSlotsNumber() const + { return mEquipBackend.getVisibleSlotsNumber(); } + private: EquipBackend mEquipBackend; }; diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h index 624e5ac0..cd24d838 100644 --- a/src/net/manaserv/manaserv_protocol.h +++ b/src/net/manaserv/manaserv_protocol.h @@ -106,12 +106,12 @@ enum { GPMSG_LOWER_ATTRIBUTE_RESPONSE = 0x0171, // B error, W attribute PGMSG_RESPAWN = 0x0180, // - GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position, B direction - // character: S name, B hair style, B hair color, B gender, B item bitmask, { W item id }* + // character: S name, B hair style, B hair color, B gender, B sprite layers changed, { B slot type, W item id }* // monster: W type id // npc: W type id GPMSG_BEING_LEAVE = 0x0201, // W being id GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position - GPMSG_BEING_LOOKS_CHANGE = 0x0210, // W weapon, W hat, W top clothes, W bottom clothes + GPMSG_BEING_LOOKS_CHANGE = 0x0210, // B sprite layers changed, { B slot type, W item id }* PGMSG_WALK = 0x0260, // W*2 destination PGMSG_ACTION_CHANGE = 0x0270, // B Action GPMSG_BEING_ACTION_CHANGE = 0x0271, // W being id, B action @@ -419,23 +419,6 @@ enum BeingDirection RIGHT = 8 }; -/** - * enum for sprites layers. - * WARNING: Has to be in sync with the same enum in the Sprite class - * of the client! - */ -enum SpriteLayer -{ - SPRITE_BASE = 0, - SPRITE_SHOE, - SPRITE_BOTTOMCLOTHES, - SPRITE_TOPCLOTHES, - SPRITE_HAIR, - SPRITE_HAT, - SPRITE_WEAPON, - SPRITE_VECTOREND -}; - } // namespace ManaServ #endif // MANASERV_PROTOCOL_H diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 44ddd896..4c29e95b 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -127,6 +127,18 @@ class EquipBackend : public Equipment::Backend int getSlotNumber() const { return EQUIP_VECTOR_END; } + // Note the slot type id is equal to the slot Index for tA. + bool isWeaponSlot(unsigned int slotTypeId) const + { + return (slotTypeId == EQUIP_FIGHT1_SLOT + || slotTypeId == EQUIP_FIGHT1_SLOT); + } + + bool isAmmoSlot(unsigned int slotTypeId) const + { + return (slotTypeId == EQUIP_PROJECTILE_SLOT); + } + private: int mEquipment[EQUIP_VECTOR_END]; }; @@ -174,6 +186,12 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler, size_t getSize(int type) const; + bool isWeaponSlot(unsigned int slotTypeId) const + { return mEquips.isWeaponSlot(slotTypeId); } + + bool isAmmoSlot(unsigned int slotTypeId) const + { return mEquips.isAmmoSlot(slotTypeId); } + private: EquipBackend mEquips; InventoryItems mInventoryItems; -- cgit v1.2.3-70-g09d2