40#define EQUIP_FILE "equip.xml"
56 auto it =
mSlots.find(slotIndex);
65 auto it =
mSlots.find(slotIndex);
66 return it ==
mSlots.end() ? std::string() : it->second.name;
76 event.setItem(
"item", item);
83 slot.inventorySlot = -1;
88 auto slotIt =
mSlots.find(equipmentSlot);
89 if (slotIt ==
mSlots.end())
91 Log::info(
"ManaServ::EquipBackend: Equipment slot %i"
92 " is not existing.", equipmentSlot);
96 slotIt->second.inventorySlot = inventorySlot;
99 item->setEquipped(
true);
106 if (slot.inventorySlot == inventorySlot)
108 slot.inventorySlot = -1;
111 item->setEquipped(
false);
117 Log::info(
"ManaServ::EquipBackend: No equipped item found at inventory "
118 "slot %i!", inventorySlot);
134 if (!rootNode || rootNode.
name() !=
"equip-slots")
136 Log::info(
"ManaServ::EquipBackend: Error while reading "
142 unsigned int slotIndex = 0;
145 for (
auto slotNode : rootNode.
children())
147 if (slotNode.name() !=
"slot")
151 slot.
slotTypeId = slotNode.getProperty(
"id", 0);
152 std::string name = slotNode.getProperty(
"name", std::string());
153 const int capacity = slotNode.getProperty(
"capacity", 1);
154 slot.
weaponSlot = slotNode.getBoolProperty(
"weapon",
false);
155 slot.
ammoSlot = slotNode.getBoolProperty(
"ammo",
false);
157 if (slotNode.getBoolProperty(
"visible",
false))
168 for (
int i = 1; i < capacity + 1; ++i)
179 mSlots.insert(std::make_pair(slotIndex, std::move(slot)));
191 for (
auto boxNode : slotNode.
children())
193 if (boxNode.name() !=
"box")
196 const int x = boxNode.getProperty(
"x" , 0);
197 const int y = boxNode.getProperty(
"y" , 0);
201 const auto icon = boxNode.getProperty(
"icon", std::string());
208 for (
const auto &[
_, slot] :
mSlots)
210 if (slot.slotTypeId == (
unsigned)slotTypeId)
211 return slot.weaponSlot;
218 for (
const auto &[
_, slot] :
mSlots)
220 if (slot.slotTypeId == (
unsigned)slotTypeId)
221 return slot.ammoSlot;
242 static const Uint16 _messages[] = {
268 const int equipmentSlot = msg.
readInt16();
271 if (equipmentSlot > 0)
282 const unsigned int slot = msg.
readInt16();
284 const unsigned int amount =
id ? msg.
readInt16() : 0;
291 const int inventorySlot = msg.
readInt16();
292 const int equipmentSlot = msg.
readInt16();
299 const int inventorySlot = msg.
readInt16();
312 Item *item =
event.getItem(
"item");
338 int amount =
event.getInt(
"amount", 1);
void listen(Event::Channel channel)
void updateButtons()
Updates the buttons.
Item * getItem(int index) const
Returns the item at the specified index.
Represents one or more instances of a certain item type.
int getInvIndex() const
Returns the inventory index of this item.
void send(const ManaServ::MessageOut &msg)
Sends a message.
void readEquipFile() override
unsigned int mVisibleSlots
std::string getSlotName(int slotIndex) const override
Position getBoxPosition(unsigned int slotIndex) const
void event(Event::Channel channel, const Event &event) override
std::map< unsigned int, Slot > mSlots
bool isWeaponSlot(int slotTypeId) const
std::vector< std::string > mBoxIcons
std::vector< Position > mBoxPositions
void unequip(int inventorySlot)
const std::string & getBoxIcon(unsigned int slotIndex) const
void equip(int inventorySlot, int equipmentSlot)
void readBoxNode(XML::Node slotNode)
bool isAmmoSlot(int slotTypeId) const
Item * getEquipment(int slotIndex) const override
void triggerUnequip(int slotIndex) const override
EquipBackend mEquipBackend
size_t getSize(int type) const override
void event(Event::Channel channel, const Event &event) override
void handleMessage(MessageIn &msg) override
Used for parsing an incoming message from manaserv.
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
unsigned int getUnreadLength() const
Returns the length of unread data.
uint16_t getId() const
Returns the message ID.
Used for building an outgoing message to manaserv.
void writeInt16(uint16_t value)
Writes an unsigned 16-bit integer to the message.
const uint16_t * handledMessages
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Children children() const
InventoryWindow * inventoryWindow
Net::InventoryHandler * inventoryHandler
void info(const char *log_text,...) LOG_PRINTF_ATTR
Connection * gameServerConnection
Inventory * getInventory()
Returns the player's inventory.
void clearInventory()
Clears the player's inventory and equipment.
void setInventoryItem(int index, int id, int amount)
Changes the inventory item at the given slot.
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
A position along a being's path.