Browse Source

Synchronize gold in player's inventories

pull/5333/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
147a13d66c
  1. 6
      Source/control.cpp
  2. 7
      Source/inv.cpp
  3. 13
      Source/msg.cpp
  4. 1
      Source/msg.h

6
Source/control.cpp

@ -378,10 +378,12 @@ void RemoveGold(Player &player, int goldIndex)
{
int gi = goldIndex - INVITEM_INV_FIRST;
player.InvList[gi]._ivalue -= dropGoldValue;
if (player.InvList[gi]._ivalue > 0)
if (player.InvList[gi]._ivalue > 0) {
SetPlrHandGoldCurs(player.InvList[gi]);
else
NetSyncInvItem(player, gi);
} else {
player.RemoveInvItem(gi);
}
MakeGoldStack(player.HoldItem, dropGoldValue);
NewCursor(player.HoldItem);

7
Source/inv.cpp

@ -523,6 +523,9 @@ void CheckInvPaste(Player &player, Point cursorPosition)
player._pNumInv++;
player.InvGrid[ii] = player._pNumInv;
}
if (&player == MyPlayer) {
NetSendCmdChInvItem(false, ii);
}
} else {
if (it == 0) {
player.InvList[player._pNumInv] = player.HoldItem.pop();
@ -1020,6 +1023,9 @@ int CreateGoldItemInInventorySlot(Player &player, int slotIndex, int value)
MakeGoldStack(goldItem, std::min(value, MaxGold));
player._pNumInv++;
player.InvGrid[slotIndex] = player._pNumInv;
if (&player == MyPlayer) {
NetSendCmdChInvItem(false, slotIndex);
}
value -= goldItem._ivalue;
@ -1424,6 +1430,7 @@ int AddGoldToInventory(Player &player, int value)
value = 0;
}
NetSyncInvItem(player, i);
SetPlrHandGoldCurs(goldItem);
}

13
Source/msg.cpp

@ -3118,6 +3118,19 @@ void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc)
NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
}
void NetSyncInvItem(const Player &player, int invListIndex)
{
if (&player != MyPlayer)
return;
for (int j = 0; j < InventoryGridCells; j++) {
if (player.InvGrid[j] == invListIndex + 1) {
NetSendCmdChInvItem(false, j);
break;
}
}
}
void NetSendCmdChInvItem(bool bHiPri, int invGridIndex)
{
TCmdChItem cmd {};

1
Source/msg.h

@ -768,6 +768,7 @@ void NetSendCmdParam4(bool bHiPri, _cmd_id bCmd, uint16_t wParam1, uint16_t wPar
void NetSendCmdQuest(bool bHiPri, const Quest &quest);
void NetSendCmdGItem(bool bHiPri, _cmd_id bCmd, uint8_t pnum, uint8_t ii);
void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item);
void NetSyncInvItem(const Player &player, int invListIndex);
void NetSendCmdChItem(bool bHiPri, uint8_t bLoc);
void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc);
void NetSendCmdChInvItem(bool bHiPri, int invGridIndex);

Loading…
Cancel
Save