Browse Source

Sync more item data with TCmdChItem

pull/5333/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
e28a8065e9
  1. 30
      Source/inv.cpp
  2. 5
      Source/inv.h
  3. 207
      Source/msg.cpp
  4. 11
      Source/msg.h

30
Source/inv.cpp

@ -1452,17 +1452,10 @@ bool GoldAutoPlace(Player &player, Item &goldStack)
return goldStack._ivalue == 0; return goldStack._ivalue == 0;
} }
void CheckInvSwap(Player &player, inv_body_loc bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) void CheckInvSwap(Player &player, inv_body_loc bLoc)
{ {
Item &item = player.InvBody[bLoc]; Item &item = player.InvBody[bLoc];
item = {};
RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
if (bId) {
item._iIdentified = true;
}
if (bLoc == INVLOC_HAND_LEFT && player.GetItemLocation(item) == ILOC_TWOHAND) { if (bLoc == INVLOC_HAND_LEFT && player.GetItemLocation(item) == ILOC_TWOHAND) {
player.InvBody[INVLOC_HAND_RIGHT].clear(); player.InvBody[INVLOC_HAND_RIGHT].clear();
} else if (bLoc == INVLOC_HAND_RIGHT && player.GetItemLocation(item) == ILOC_TWOHAND) { } else if (bLoc == INVLOC_HAND_RIGHT && player.GetItemLocation(item) == ILOC_TWOHAND) {
@ -1479,15 +1472,8 @@ void inv_update_rem_item(Player &player, inv_body_loc iv)
CalcPlrInv(player, player._pmode != PM_DEATH); CalcPlrInv(player, player._pmode != PM_DEATH);
} }
void CheckInvSwap(Player &player, int invGridIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff) void CheckInvSwap(Player &player, const Item &item, int invGridIndex)
{ {
Item item = {};
RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
if (bId) {
item._iIdentified = true;
}
auto itemSize = GetInventorySize(item); auto itemSize = GetInventorySize(item);
const int pitch = 10; const int pitch = 10;
@ -1536,18 +1522,6 @@ void CheckInvRemove(Player &player, int invGridIndex)
} }
} }
void CheckBeltSwap(Player &player, int beltIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff)
{
Item &item = player.SpdList[beltIndex];
item = {};
RecreateItem(player, item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
if (bId) {
item._iIdentified = true;
}
}
void TransferItemToStash(Player &player, int location) void TransferItemToStash(Player &player, int location)
{ {
if (location == -1) { if (location == -1) {

5
Source/inv.h

@ -180,11 +180,10 @@ int RoomForGold();
*/ */
int AddGoldToInventory(Player &player, int value); int AddGoldToInventory(Player &player, int value);
bool GoldAutoPlace(Player &player, Item &goldStack); bool GoldAutoPlace(Player &player, Item &goldStack);
void CheckInvSwap(Player &player, inv_body_loc bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); void CheckInvSwap(Player &player, inv_body_loc bLoc);
void inv_update_rem_item(Player &player, inv_body_loc iv); void inv_update_rem_item(Player &player, inv_body_loc iv);
void CheckInvSwap(Player &player, int invGridIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff); void CheckInvSwap(Player &player, const Item &item, int invGridIndex);
void CheckInvRemove(Player &player, int invGridIndex); void CheckInvRemove(Player &player, int invGridIndex);
void CheckBeltSwap(Player &player, int beltIndex, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void TransferItemToStash(Player &player, int location); void TransferItemToStash(Player &player, int location);
void CheckInvItem(bool isShiftHeld = false, bool isCtrlHeld = false); void CheckInvItem(bool isShiftHeld = false, bool isCtrlHeld = false);

207
Source/msg.cpp

@ -1832,8 +1832,43 @@ size_t OnChangePlayerItems(const TCmd *pCmd, size_t pnum)
if (gbBufferMsgs == 1) { if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message)); SendPacket(pnum, &message, sizeof(message));
} else if (&player != MyPlayer && message.wIndx <= IDI_LAST) { } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) {
CheckInvSwap(player, bodyLocation, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); Item &item = player.InvBody[message.bLoc];
item = {};
if (message.def.wIndx == IDI_EAR) {
RecreateEar(
item,
message.ear.wCI,
message.ear.dwSeed,
message.ear.bCursval,
message.ear.heroname);
} else {
RecreateItem(
player,
item,
message.item.wIndx,
message.item.wCI,
message.item.dwSeed,
message.item.wValue,
(message.item.dwBuff & CF_HELLFIRE) != 0);
if (message.item.bId != 0)
item._iIdentified = true;
item._iDurability = message.item.bDur;
item._iMaxDur = message.item.bMDur;
item._iCharges = message.item.bCh;
item._iMaxCharges = message.item.bMCh;
item._iPLToHit = message.item.wToHit;
item._iMaxDam = message.item.wMaxDam;
item._iMinStr = message.item.bMinStr;
item._iMinMag = message.item.bMinMag;
item._iMinDex = message.item.bMinDex;
item._iAC = message.item.bAC;
item.dwBuff = message.item.dwBuff;
}
CheckInvSwap(player, bodyLocation);
} }
player.ReadySpellFromEquipment(bodyLocation); player.ReadySpellFromEquipment(bodyLocation);
@ -1861,10 +1896,47 @@ size_t OnChangeInventoryItems(const TCmd *pCmd, int pnum)
const auto &message = *reinterpret_cast<const TCmdChItem *>(pCmd); const auto &message = *reinterpret_cast<const TCmdChItem *>(pCmd);
Player &player = Players[pnum]; Player &player = Players[pnum];
if (message.bLoc >= InventoryGridCells)
return sizeof(message);
if (gbBufferMsgs == 1) { if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message)); SendPacket(pnum, &message, sizeof(message));
} else if (&player != MyPlayer && message.bLoc < InventoryGridCells && message.wIndx <= IDI_LAST) { } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) {
CheckInvSwap(player, message.bLoc, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); Item item {};
if (message.def.wIndx == IDI_EAR) {
RecreateEar(
item,
message.ear.wCI,
message.ear.dwSeed,
message.ear.bCursval,
message.ear.heroname);
} else {
RecreateItem(
player,
item,
message.item.wIndx,
message.item.wCI,
message.item.dwSeed,
message.item.wValue,
(message.item.dwBuff & CF_HELLFIRE) != 0);
if (message.item.bId != 0)
item._iIdentified = true;
item._iDurability = message.item.bDur;
item._iMaxDur = message.item.bMDur;
item._iCharges = message.item.bCh;
item._iMaxCharges = message.item.bMCh;
item._iPLToHit = message.item.wToHit;
item._iMaxDam = message.item.wMaxDam;
item._iMinStr = message.item.bMinStr;
item._iMinMag = message.item.bMinMag;
item._iMinDex = message.item.bMinDex;
item._iAC = message.item.bAC;
item.dwBuff = message.item.dwBuff;
}
CheckInvSwap(player, item, message.bLoc);
} }
return sizeof(message); return sizeof(message);
@ -1889,10 +1961,46 @@ size_t OnChangeBeltItems(const TCmd *pCmd, int pnum)
const auto &message = *reinterpret_cast<const TCmdChItem *>(pCmd); const auto &message = *reinterpret_cast<const TCmdChItem *>(pCmd);
Player &player = Players[pnum]; Player &player = Players[pnum];
if (message.bLoc >= MaxBeltItems)
return sizeof(message);
if (gbBufferMsgs == 1) { if (gbBufferMsgs == 1) {
SendPacket(pnum, &message, sizeof(message)); SendPacket(pnum, &message, sizeof(message));
} else if (&player != MyPlayer && message.bLoc < MaxBeltItems && message.wIndx <= IDI_LAST) { } else if (&player != MyPlayer && IsItemAvailable(message.def.wIndx)) {
CheckBeltSwap(player, message.bLoc, message.wIndx, message.wCI, message.dwSeed, message.bId != 0, message.dwBuff); Item &item = player.SpdList[message.bLoc];
item = {};
if (message.def.wIndx == IDI_EAR) {
RecreateEar(
item,
message.ear.wCI,
message.ear.dwSeed,
message.ear.bCursval,
message.ear.heroname);
} else {
RecreateItem(
player,
item,
message.item.wIndx,
message.item.wCI,
message.item.dwSeed,
message.item.wValue,
(message.item.dwBuff & CF_HELLFIRE) != 0);
if (message.item.bId != 0)
item._iIdentified = true;
item._iDurability = message.item.bDur;
item._iMaxDur = message.item.bMDur;
item._iCharges = message.item.bCh;
item._iMaxCharges = message.item.bMCh;
item._iPLToHit = message.item.wToHit;
item._iMaxDam = message.item.wMaxDam;
item._iMinStr = message.item.bMinStr;
item._iMinMag = message.item.bMinMag;
item._iMinDex = message.item.bMinDex;
item._iAC = message.item.bAC;
item.dwBuff = message.item.dwBuff;
}
} }
return sizeof(message); return sizeof(message);
@ -3045,17 +3153,34 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item
void NetSendCmdChItem(bool bHiPri, uint8_t bLoc) void NetSendCmdChItem(bool bHiPri, uint8_t bLoc)
{ {
TCmdChItem cmd; TCmdChItem cmd {};
Item &item = MyPlayer->InvBody[bLoc]; Item &item = MyPlayer->InvBody[bLoc];
cmd.bCmd = CMD_CHANGEPLRITEMS; cmd.bCmd = CMD_CHANGEPLRITEMS;
cmd.bLoc = bLoc; cmd.bLoc = bLoc;
cmd.wIndx = item.IDidx; cmd.def.wIndx = item.IDidx;
cmd.wCI = item._iCreateInfo; cmd.def.wCI = item._iCreateInfo;
cmd.dwSeed = item._iSeed; cmd.def.dwSeed = item._iSeed;
cmd.bId = item._iIdentified ? 1 : 0;
cmd.dwBuff = item.dwBuff; if (item.IDidx == IDI_EAR) {
cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6);
CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname));
} else {
cmd.item.bId = item._iIdentified ? 1 : 0;
cmd.item.bDur = item._iDurability;
cmd.item.bMDur = item._iMaxDur;
cmd.item.bCh = item._iCharges;
cmd.item.bMCh = item._iMaxCharges;
cmd.item.wValue = item._ivalue;
cmd.item.wToHit = item._iPLToHit;
cmd.item.wMaxDam = item._iMaxDam;
cmd.item.bMinStr = item._iMinStr;
cmd.item.bMinMag = item._iMinMag;
cmd.item.bMinDex = item._iMinDex;
cmd.item.bAC = item._iAC;
cmd.item.dwBuff = item.dwBuff;
}
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
@ -3077,18 +3202,35 @@ void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc)
void NetSendCmdChInvItem(bool bHiPri, int invGridIndex) void NetSendCmdChInvItem(bool bHiPri, int invGridIndex)
{ {
TCmdChItem cmd; TCmdChItem cmd {};
int8_t invListIndex = abs(MyPlayer->InvGrid[invGridIndex]) - 1; int8_t invListIndex = abs(MyPlayer->InvGrid[invGridIndex]) - 1;
const Item &item = MyPlayer->InvList[invListIndex]; const Item &item = MyPlayer->InvList[invListIndex];
cmd.bCmd = CMD_CHANGEINVITEMS; cmd.bCmd = CMD_CHANGEINVITEMS;
cmd.bLoc = invGridIndex; cmd.bLoc = invGridIndex;
cmd.wIndx = item.IDidx; cmd.def.wIndx = item.IDidx;
cmd.wCI = item._iCreateInfo; cmd.def.wCI = item._iCreateInfo;
cmd.dwSeed = item._iSeed; cmd.def.dwSeed = item._iSeed;
cmd.bId = item._iIdentified ? 1 : 0;
cmd.dwBuff = item.dwBuff; if (item.IDidx == IDI_EAR) {
cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6);
CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname));
} else {
cmd.item.bId = item._iIdentified ? 1 : 0;
cmd.item.bDur = item._iDurability;
cmd.item.bMDur = item._iMaxDur;
cmd.item.bCh = item._iCharges;
cmd.item.bMCh = item._iMaxCharges;
cmd.item.wValue = item._ivalue;
cmd.item.wToHit = item._iPLToHit;
cmd.item.wMaxDam = item._iMaxDam;
cmd.item.bMinStr = item._iMinStr;
cmd.item.bMinMag = item._iMinMag;
cmd.item.bMinDex = item._iMinDex;
cmd.item.bAC = item._iAC;
cmd.item.dwBuff = item.dwBuff;
}
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));
@ -3098,17 +3240,34 @@ void NetSendCmdChInvItem(bool bHiPri, int invGridIndex)
void NetSendCmdChBeltItem(bool bHiPri, int beltIndex) void NetSendCmdChBeltItem(bool bHiPri, int beltIndex)
{ {
TCmdChItem cmd; TCmdChItem cmd {};
const Item &item = MyPlayer->SpdList[beltIndex]; const Item &item = MyPlayer->SpdList[beltIndex];
cmd.bCmd = CMD_CHANGEBELTITEMS; cmd.bCmd = CMD_CHANGEBELTITEMS;
cmd.bLoc = beltIndex; cmd.bLoc = beltIndex;
cmd.wIndx = item.IDidx; cmd.def.wIndx = item.IDidx;
cmd.wCI = item._iCreateInfo; cmd.def.wCI = item._iCreateInfo;
cmd.dwSeed = item._iSeed; cmd.def.dwSeed = item._iSeed;
cmd.bId = item._iIdentified ? 1 : 0;
cmd.dwBuff = item.dwBuff; if (item.IDidx == IDI_EAR) {
cmd.ear.bCursval = item._ivalue | ((item._iCurs - ICURS_EAR_SORCERER) << 6);
CopyUtf8(cmd.ear.heroname, item._iIName, sizeof(cmd.ear.heroname));
} else {
cmd.item.bId = item._iIdentified ? 1 : 0;
cmd.item.bDur = item._iDurability;
cmd.item.bMDur = item._iMaxDur;
cmd.item.bCh = item._iCharges;
cmd.item.bMCh = item._iMaxCharges;
cmd.item.wValue = item._ivalue;
cmd.item.wToHit = item._iPLToHit;
cmd.item.wMaxDam = item._iMaxDam;
cmd.item.bMinStr = item._iMinStr;
cmd.item.bMinMag = item._iMinMag;
cmd.item.bMinDex = item._iMinDex;
cmd.item.bAC = item._iAC;
cmd.item.dwBuff = item.dwBuff;
}
if (bHiPri) if (bHiPri)
NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); NetSendHiPri(MyPlayerId, (byte *)&cmd, sizeof(cmd));

11
Source/msg.h

@ -626,11 +626,12 @@ struct TCmdPItem {
struct TCmdChItem { struct TCmdChItem {
_cmd_id bCmd; _cmd_id bCmd;
uint8_t bLoc; uint8_t bLoc;
uint16_t wIndx;
uint16_t wCI; union {
int32_t dwSeed; TItemDef def;
uint8_t bId; TItem item;
uint32_t dwBuff; TEar ear;
};
}; };
struct TCmdDelItem { struct TCmdDelItem {

Loading…
Cancel
Save