From ddd0f1b051add70cf95dbd556e9902177b4ff1cd Mon Sep 17 00:00:00 2001 From: qndel Date: Thu, 25 May 2023 19:49:51 +0200 Subject: [PATCH] dont always force staff recharge to change spell --- Source/inv.cpp | 2 +- Source/msg.cpp | 5 +++-- Source/msg.h | 3 ++- Source/player.cpp | 10 ++++++---- Source/player.h | 3 ++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index 695e81a16..b00e5961c 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -260,7 +260,7 @@ void ChangeEquipment(Player &player, inv_body_loc bodyLocation, const Item &item player.InvBody[bodyLocation] = item; if (&player == MyPlayer) { - NetSendCmdChItem(false, bodyLocation); + NetSendCmdChItem(false, bodyLocation, true); } } diff --git a/Source/msg.cpp b/Source/msg.cpp index 76a117ff6..e71133bee 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1907,7 +1907,7 @@ size_t OnChangePlayerItems(const TCmd *pCmd, size_t pnum) CheckInvSwap(player, bodyLocation); } - player.ReadySpellFromEquipment(bodyLocation); + player.ReadySpellFromEquipment(bodyLocation, message.forceSpell); return sizeof(message); } @@ -2990,7 +2990,7 @@ void NetSendCmdPItem(bool bHiPri, _cmd_id bCmd, Point position, const Item &item NetSendLoPri(MyPlayerId, (byte *)&cmd, sizeof(cmd)); } -void NetSendCmdChItem(bool bHiPri, uint8_t bLoc) +void NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange) { TCmdChItem cmd {}; @@ -2998,6 +2998,7 @@ void NetSendCmdChItem(bool bHiPri, uint8_t bLoc) cmd.bCmd = CMD_CHANGEPLRITEMS; cmd.bLoc = bLoc; + cmd.forceSpell = forceSpellChange; PrepareItemForNetwork(item, cmd); if (bHiPri) diff --git a/Source/msg.h b/Source/msg.h index c0a4f7ef2..008ee9be6 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -611,6 +611,7 @@ struct TCmdPItem { struct TCmdChItem { _cmd_id bCmd; uint8_t bLoc; + bool forceSpell; union { TItemDef def; @@ -756,7 +757,7 @@ 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 NetSendCmdChItem(bool bHiPri, uint8_t bLoc, bool forceSpellChange = false); void NetSendCmdDelItem(bool bHiPri, uint8_t bLoc); void NetSendCmdChInvItem(bool bHiPri, int invGridIndex); void NetSendCmdChBeltItem(bool bHiPri, int invGridIndex); diff --git a/Source/player.cpp b/Source/player.cpp index c79d649e3..739636757 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1831,13 +1831,15 @@ void Player::RestorePartialMana() } } -void Player::ReadySpellFromEquipment(inv_body_loc bodyLocation) +void Player::ReadySpellFromEquipment(inv_body_loc bodyLocation, bool forceSpell) { auto &item = InvBody[bodyLocation]; if (item._itype == ItemType::Staff && IsValidSpell(item._iSpell) && item._iCharges > 0) { - _pRSpell = item._iSpell; - _pRSplType = SpellType::Charges; - RedrawEverything(); + if (forceSpell || _pRSpell == SpellID::Invalid || _pRSplType == SpellType::Invalid) { + _pRSpell = item._iSpell; + _pRSplType = SpellType::Charges; + RedrawEverything(); + } } } diff --git a/Source/player.h b/Source/player.h index 8e93dd217..59789f663 100644 --- a/Source/player.h +++ b/Source/player.h @@ -700,8 +700,9 @@ struct Player { /** * @brief Sets the readied spell to the spell in the specified equipment slot. Does nothing if the item does not have a valid spell. * @param bodyLocation - the body location whose item will be checked for the spell. + * @param forceSpell - if true, always change active spell, if false, only when current spell slot is empty */ - void ReadySpellFromEquipment(inv_body_loc bodyLocation); + void ReadySpellFromEquipment(inv_body_loc bodyLocation, bool forceSpell); /** * @brief Does the player currently have a ranged weapon equipped?