Skip to content

Commit

Permalink
Merge pull request #6541 from WinterSolstice8/equip_inventory_dirty
Browse files Browse the repository at this point in the history
[core] Dirty & Undirty inventory when changing gear
  • Loading branch information
zach2good authored Dec 18, 2024
2 parents 8a3a8d2 + 2074c20 commit 32ee8de
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/map/entities/charentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,23 @@ void CCharEntity::PostTick()
pushPacket(new CCharAppearancePacket(this));
}

// notify client containers are dirty and then no longer dirty
if (!dirtyInventoryContainers.empty())
{

// Notify client containers were dirty
// Note: Retail sends this in the same chunk as the inventory equip packets, but it doesnt seem to matter as long as it arrives
for (const auto& [container, dirty]: dirtyInventoryContainers)
{
pushPacket(new CInventoryFinishPacket(container));
}

dirtyInventoryContainers.clear();

// Notify client containers are now ok
pushPacket(new CInventoryFinishPacket());
}

if (ReloadParty())
{
charutils::ReloadParty(this);
Expand Down
4 changes: 4 additions & 0 deletions src/map/entities/charentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define _CHARENTITY_H

#include "event_info.h"
#include "item_container.h"
#include "monstrosity.h"
#include "packets/char.h"
#include "packets/entity_update.h"
Expand Down Expand Up @@ -511,6 +512,9 @@ class CCharEntity : public CBattleEntity
bool getBlockingAid() const;
void setBlockingAid(bool isBlockingAid);

// Send updates about dirty containers in post tick
std::map<CONTAINER_ID, bool> dirtyInventoryContainers;

bool m_EquipSwap; // true if equipment was recently changed
bool m_EffectsChanged;
time_point m_LastSynthTime;
Expand Down
22 changes: 17 additions & 5 deletions src/map/utils/charutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,6 @@ namespace charutils
PChar->pushPacket(new CInventoryItemPacket(PItem, LocationID, slotID));
}
}

PChar->pushPacket(new CInventoryFinishPacket(LocationID));
};

// Send important items first
Expand Down Expand Up @@ -1859,6 +1857,9 @@ namespace charutils
PChar->UpdateHealth();
PChar->m_EquipSwap = true;
PChar->updatemask |= UPDATE_LOOK;

// Mark container dirty
PChar->dirtyInventoryContainers[static_cast<CONTAINER_ID>(PItem->getLocationID())] = true;
}
}
}
Expand Down Expand Up @@ -2657,9 +2658,10 @@ namespace charutils
return;
}

CItemEquipment* PItem = dynamic_cast<CItemEquipment*>(PChar->getStorage(containerID)->GetItem(slotID));
CItemEquipment* PItem = dynamic_cast<CItemEquipment*>(PChar->getStorage(containerID)->GetItem(slotID));
CItem* POldItem = PChar->getEquip(static_cast<SLOTTYPE>(equipSlotID));

if (PItem && PItem == PChar->getEquip((SLOTTYPE)equipSlotID))
if (PItem && PItem == PChar->getEquip(static_cast<SLOTTYPE>(equipSlotID)))
{
return;
}
Expand Down Expand Up @@ -2725,7 +2727,6 @@ namespace charutils
// Do not forget to update the timer when equipping the subject

PChar->pushPacket(new CInventoryItemPacket(PItem, containerID, slotID));
PChar->pushPacket(new CInventoryFinishPacket());
}
PItem->setSubType(ITEM_LOCKED);

Expand Down Expand Up @@ -2776,6 +2777,17 @@ namespace charutils
PChar->UpdateHealth();
PChar->m_EquipSwap = true;
PChar->updatemask |= UPDATE_LOOK;

// PItem can be null if item id is 0 (unequip)
if (PItem)
{
PChar->dirtyInventoryContainers[static_cast<CONTAINER_ID>(PItem->getLocationID())] = true;
}

if (POldItem)
{
PChar->dirtyInventoryContainers[static_cast<CONTAINER_ID>(POldItem->getLocationID())] = true;
}
}

/************************************************************************
Expand Down

0 comments on commit 32ee8de

Please sign in to comment.