Skip to content

Commit 5ba1dad

Browse files
committed
Use top-left grid cell when syncing staff charges
1 parent 7ea938e commit 5ba1dad

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Source/msg.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,15 +2164,25 @@ size_t OnDeletePlayerItems(const TCmdDelItem &message, Player &player)
21642164

21652165
size_t OnChangeInventoryItems(const TCmdChItem &message, Player &player)
21662166
{
2167-
if (message.bLoc >= InventoryGridCells)
2167+
const uint8_t topLeft = message.bLoc;
2168+
if (topLeft >= InventoryGridCells)
21682169
return sizeof(message);
21692170

21702171
if (gbBufferMsgs == 1) {
21712172
BufferMessage(player, &message, sizeof(message));
21722173
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx)))) {
21732174
Item item {};
21742175
RecreateItem(player, message, item);
2175-
CheckInvSwap(player, item, message.bLoc);
2176+
2177+
const Size itemSize = GetInventorySize(item);
2178+
const int invPitch = InventorySizeInSlots.width;
2179+
const int verticalShift = itemSize.width - 1;
2180+
const int horizontalShift = itemSize.height - 1;
2181+
const uint8_t bottomRight = static_cast<uint8_t>(topLeft + invPitch * verticalShift + horizontalShift);
2182+
if (bottomRight >= InventoryGridCells)
2183+
return sizeof(message);
2184+
2185+
CheckInvSwap(player, item, topLeft);
21762186
}
21772187

21782188
return sizeof(message);
@@ -3228,7 +3238,7 @@ void NetSyncInvItem(const Player &player, int invListIndex)
32283238
return;
32293239

32303240
for (int j = 0; j < InventoryGridCells; j++) {
3231-
if (player.InvGrid[j] == invListIndex + 1) {
3241+
if (std::abs(player.InvGrid[j]) == invListIndex + 1) {
32323242
NetSendCmdChInvItem(false, j);
32333243
break;
32343244
}

0 commit comments

Comments
 (0)