Browse Source

dont always force staff recharge to change spell

pull/6156/head
qndel 3 years ago committed by Anders Jenbo
parent
commit
ddd0f1b051
  1. 2
      Source/inv.cpp
  2. 5
      Source/msg.cpp
  3. 3
      Source/msg.h
  4. 10
      Source/player.cpp
  5. 3
      Source/player.h

2
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);
}
}

5
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)

3
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);

10
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();
}
}
}

3
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?

Loading…
Cancel
Save