summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-04 17:36:58 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-07 22:27:48 +0100
commita1bc8e1974d04a111127b744413094a886de4de6 (patch)
treee3d64bbbb325bffe17014382e227bdd27cfd733e /src
parent3556885ee1027b79c8151e3fb2aeb5906483d3d3 (diff)
downloadmana-a1bc8e1974d04a111127b744413094a886de4de6.tar.gz
mana-a1bc8e1974d04a111127b744413094a886de4de6.tar.bz2
mana-a1bc8e1974d04a111127b744413094a886de4de6.tar.xz
mana-a1bc8e1974d04a111127b744413094a886de4de6.zip
Fixed handling of equipment
* Fixed ManaServ::EquipBackend removing all slots in response to GPMSG_INVENTORY_FULL, rather than resetting them to empty. * Fixed updating of buttons in InventoryWindow as relevant from the ManaServ::InventoryHandler. * Updated handling of equipment sprites in messages related to character appearance (Manaserv now always sends all relevant equipment and as such does not send removals).
Diffstat (limited to 'src')
-rw-r--r--src/being.h3
-rw-r--r--src/net/manaserv/beinghandler.cpp35
-rw-r--r--src/net/manaserv/inventoryhandler.cpp16
-rw-r--r--src/net/manaserv/inventoryhandler.h1
4 files changed, 37 insertions, 18 deletions
diff --git a/src/being.h b/src/being.h
index 1cfac80f..6cc0575f 100644
--- a/src/being.h
+++ b/src/being.h
@@ -274,6 +274,9 @@ class Being : public ActorSprite, public EventListener
void setSpriteColor(unsigned slot,
const std::string &color = std::string());
+ unsigned getSpriteCount() const
+ { return mSpriteStates.size(); }
+
bool drawnWhenBehind() const override;
/**
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp
index 7f16ae19..d1eb67aa 100644
--- a/src/net/manaserv/beinghandler.cpp
+++ b/src/net/manaserv/beinghandler.cpp
@@ -112,16 +112,35 @@ static void handleLooks(Being *being, MessageIn &msg)
being->setSprite(SPRITE_LAYER_HAIR, hairStyle * -1,
hairDB.getHairColor(hairColor));
- if (msg.getUnreadLength() < 1)
- return;
+ std::map<unsigned, int> equippedSlots;
+
+ if (msg.getUnreadLength() > 1) {
+ int equippedSlotCount = msg.readInt8();
+ while (equippedSlotCount-- > 0) {
+ unsigned slot = msg.readInt8();
+ int itemId = msg.readInt16();
+ equippedSlots[slot] = itemId;
+ }
+ }
+
+ unsigned endSlot = equippedSlots.empty() ? 0 : equippedSlots.rbegin()->first + 1;
+ if (being->getSpriteCount() > endSlot + FIXED_SPRITE_LAYER_SIZE)
+ endSlot = being->getSpriteCount() - FIXED_SPRITE_LAYER_SIZE;
- int lookChanges = msg.readInt8();
- while (lookChanges-- > 0)
+ for (unsigned slot = 0; slot < endSlot; ++slot)
{
- unsigned int slotTypeId = msg.readInt8();
- being->setSprite(slotTypeId + FIXED_SPRITE_LAYER_SIZE,
- msg.readInt16(), "",
- Net::getInventoryHandler()->isWeaponSlot(slotTypeId));
+ auto it = equippedSlots.find(slot);
+ if (it == equippedSlots.end())
+ {
+ being->setSprite(slot + FIXED_SPRITE_LAYER_SIZE, 0);
+ }
+ else
+ {
+ being->setSprite(slot + FIXED_SPRITE_LAYER_SIZE,
+ it->second,
+ std::string(),
+ Net::getInventoryHandler()->isWeaponSlot(slot));
+ }
}
}
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index 0e822ca0..219e4350 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -51,11 +51,6 @@ EquipBackend::EquipBackend()
mVisibleSlots = 0;
}
-EquipBackend::~EquipBackend()
-{
- clear();
-}
-
Item *EquipBackend::getEquipment(int slotIndex) const
{
auto it = mSlots.find(slotIndex);
@@ -84,7 +79,8 @@ void EquipBackend::triggerUnequip(int slotIndex) const
void EquipBackend::clear()
{
- mSlots.clear();
+ for (auto &[_, slot] : mSlots)
+ slot.inventorySlot = -1;
}
void EquipBackend::equip(int inventorySlot, int equipmentSlot)
@@ -131,7 +127,7 @@ void EquipBackend::event(Event::Channel, const Event &event)
void EquipBackend::readEquipFile()
{
- clear();
+ mSlots.clear();
XML::Document doc(EQUIP_FILE);
XML::Node rootNode = doc.rootNode();
@@ -276,9 +272,9 @@ void InventoryHandler::handleMessage(MessageIn &msg)
if (equipmentSlot > 0)
mEquipBackend.equip(slot, equipmentSlot);
- else
- mEquipBackend.unequip(slot);
}
+
+ inventoryWindow->updateButtons();
}
break;
@@ -297,12 +293,14 @@ void InventoryHandler::handleMessage(MessageIn &msg)
const int inventorySlot = msg.readInt16();
const int equipmentSlot = msg.readInt16();
mEquipBackend.equip(inventorySlot, equipmentSlot);
+ inventoryWindow->updateButtons();
}
case GPMSG_UNEQUIP:
{
const int inventorySlot = msg.readInt16();
mEquipBackend.unequip(inventorySlot);
+ inventoryWindow->updateButtons();
}
break;
}
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index 9402f349..2b6c98fe 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -36,7 +36,6 @@ class EquipBackend final : public Equipment::Backend, public EventListener
{
public:
EquipBackend();
- ~EquipBackend() override;
Item *getEquipment(int slotIndex) const override;
std::string getSlotName(int slotIndex) const override;