From 7ba878fd4d5f3d026e61ed5cfbaf6c08374af176 Mon Sep 17 00:00:00 2001 From: qndel Date: Thu, 19 Aug 2021 21:42:45 +0200 Subject: [PATCH] fix reflect on loading --- Source/missiles.cpp | 46 ++++++++++++++++++++--------- Source/msg.cpp | 72 +++++++++++++++++++++++++++++---------------- Source/msg.h | 6 ++-- Source/player.cpp | 4 +++ 4 files changed, 87 insertions(+), 41 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 5bf648f73..690ae79f0 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -951,6 +951,11 @@ void DeleteMissile(int mi, int i) if (src == MyPlayerId) NetSendCmd(true, CMD_REMSHIELD); Players[src].pManaShield = false; + } else if (missile._mitype == MIS_REFLECT) { + int src = missile._misource; + if (src == MyPlayerId) + NetSendCmd(true, CMD_REMREFLECT); + Players[src].wReflections = 0; } AvailableMissiles[MAXMISSILES - ActiveMissileCount] = mi; @@ -1260,7 +1265,6 @@ void InitMissiles() dFlags[i][j] &= ~BFLAG_MISSILE; } } - myPlayer.wReflections = 0; } void AddHiveExplosion(int mi, Point /*src*/, Point /*dst*/, int midir, int8_t mienemy, int id, int dam) @@ -1347,12 +1351,10 @@ void AddReflection(int mi, Point /*src*/, Point /*dst*/, int /*midir*/, int8_t / { auto &missile = Missiles[mi]; if (id >= 0) { - int lvl = 2; - if (missile._mispllvl != 0) - lvl = missile._mispllvl; - auto &player = Players[id]; - player.wReflections += lvl * player._pLevel; + player.wReflections += (missile._mispllvl != 0 ? missile._mispllvl : 2) * player._pLevel; + if (id == MyPlayerId) + NetSendCmdParam1(true, CMD_SETREFLECT, player.wReflections); UseMana(id, SPL_REFLECT); } @@ -2951,6 +2953,21 @@ int AddMissile(Point src, Point dst, int midir, int mitype, int8_t micaster, int } } + if (mitype == MIS_REFLECT) { + auto &player = Players[id]; + if (player.wReflections) { + if (currlevel != player.plrlevel) + return -1; + + for (int i = 0; i < ActiveMissileCount; i++) { + int mi = ActiveMissiles[i]; + auto &missile = Missiles[mi]; + if (missile._mitype == MIS_REFLECT && missile._misource == id) + return -1; + } + } + } + int mi = AvailableMissiles[0]; auto &missile = Missiles[mi]; @@ -3471,14 +3488,15 @@ void MI_LightningArrow(int i) void MI_Reflect(int i) { auto &missile = Missiles[i]; - int src = missile._misource; - auto &player = Players[src]; - - if (src != MyPlayerId && currlevel != player.plrlevel) - missile._miDelFlag = true; - if (player.wReflections <= 0) { - missile._miDelFlag = true; - NetSendCmd(true, CMD_REFLECT); + int id = missile._misource; + if (id != MyPlayerId) { + if (currlevel != Players[id].plrlevel) + missile._miDelFlag = true; + } else { + if (Players[id].wReflections <= 0 || !Players[id].plractive) { + missile._miDelFlag = true; + NetSendCmd(true, CMD_ENDREFLECT); + } } PutMissile(i); } diff --git a/Source/msg.cpp b/Source/msg.cpp index 9844456bd..c35e40e44 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1683,22 +1683,6 @@ DWORD OnSyncQuest(TCmd *pCmd, int pnum) return sizeof(*p); } -DWORD OnEndShield(TCmd *pCmd, int pnum) -{ - if (gbBufferMsgs != 1 && pnum != MyPlayerId && currlevel == Players[pnum].plrlevel) { - for (int i = 0; i < ActiveMissileCount; i++) { - int mi = ActiveMissiles[i]; - auto &missile = Missiles[mi]; - if (missile._mitype == MIS_MANASHIELD && missile._misource == pnum) { - ClearMissileSpot(mi); - DeleteMissile(mi, i); - } - } - } - - return sizeof(*pCmd); -} - DWORD OnCheatExperience(TCmd *pCmd, int pnum) // NOLINT(misc-unused-parameters) { #ifdef _DEBUG @@ -1769,14 +1753,48 @@ DWORD OnRemoveShield(TCmd *pCmd, PlayerStruct &player) return sizeof(*pCmd); } -DWORD OnReflect(TCmd *pCmd, int pnum) +DWORD OnEndShield(TCmd *pCmd, int pnum) { if (gbBufferMsgs != 1 && pnum != MyPlayerId && currlevel == Players[pnum].plrlevel) { for (int i = 0; i < ActiveMissileCount; i++) { - int mx = ActiveMissiles[i]; - if (Missiles[mx]._mitype == MIS_REFLECT && Missiles[mx]._misource == pnum) { - ClearMissileSpot(mx); - DeleteMissile(mx, i); + int mi = ActiveMissiles[i]; + auto &missile = Missiles[mi]; + if (missile._mitype == MIS_MANASHIELD && missile._misource == pnum) { + ClearMissileSpot(mi); + DeleteMissile(mi, i); + } + } + } + + return sizeof(*pCmd); +} + +DWORD OnSetReflect(TCmd *pCmd, PlayerStruct &player) +{ + auto *p = (TCmdParam1 *)pCmd; + if (gbBufferMsgs != 1) + player.wReflections = p->wParam1; + + return sizeof(*p); +} + +DWORD OnRemoveReflect(TCmd *pCmd, PlayerStruct &player) +{ + if (gbBufferMsgs != 1) + player.wReflections = 0; + + return sizeof(*pCmd); +} + +DWORD OnEndReflect(TCmd *pCmd, int pnum) +{ + if (gbBufferMsgs != 1 && pnum != MyPlayerId && currlevel == Players[pnum].plrlevel) { + for (int i = 0; i < ActiveMissileCount; i++) { + int mi = ActiveMissiles[i]; + auto &missile = Missiles[mi]; + if (missile._mitype == MIS_REFLECT && missile._misource == pnum) { + ClearMissileSpot(mi); + DeleteMissile(mi, i); } } } @@ -2662,8 +2680,6 @@ DWORD ParseCmd(int pnum, TCmd *pCmd) return OnString(pCmd, pnum); case CMD_SYNCQUEST: return OnSyncQuest(pCmd, pnum); - case CMD_ENDSHIELD: - return OnEndShield(pCmd, pnum); case CMD_CHEAT_EXPERIENCE: return OnCheatExperience(pCmd, pnum); case CMD_CHEAT_SPELL_LEVEL: @@ -2674,8 +2690,14 @@ DWORD ParseCmd(int pnum, TCmd *pCmd) return OnSetShield(pCmd, player); case CMD_REMSHIELD: return OnRemoveShield(pCmd, player); - case CMD_REFLECT: - return OnReflect(pCmd, pnum); + case CMD_ENDSHIELD: + return OnEndShield(pCmd, pnum); + case CMD_SETREFLECT: + return OnSetReflect(pCmd, player); + case CMD_REMREFLECT: + return OnRemoveReflect(pCmd, player); + case CMD_ENDREFLECT: + return OnEndReflect(pCmd, pnum); case CMD_NAKRUL: return OnNakrul(pCmd); case CMD_OPENHIVE: diff --git a/Source/msg.h b/Source/msg.h index 30d1a9e22..1d600cab9 100644 --- a/Source/msg.h +++ b/Source/msg.h @@ -116,12 +116,14 @@ enum _cmd_id : uint8_t { CMD_SYNCPUTITEM, CMD_KILLGOLEM, CMD_SYNCQUEST, - CMD_ENDSHIELD, CMD_AWAKEGOLEM, CMD_NOVA, CMD_SETSHIELD, CMD_REMSHIELD, - CMD_REFLECT, + CMD_ENDSHIELD, + CMD_SETREFLECT, + CMD_REMREFLECT, + CMD_ENDREFLECT, CMD_NAKRUL, CMD_OPENHIVE, CMD_OPENCRYPT, diff --git a/Source/player.cpp b/Source/player.cpp index 9613f5a00..675df923c 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3222,6 +3222,10 @@ void RemovePlrMissiles(int pnum) ClearMissileSpot(am); DeleteMissile(am, i); } + if (Missiles[am]._mitype == MIS_REFLECT && Missiles[am]._misource == pnum) { + ClearMissileSpot(am); + DeleteMissile(am, i); + } if (Missiles[am]._mitype == MIS_ETHEREALIZE && Missiles[am]._misource == pnum) { ClearMissileSpot(am); DeleteMissile(am, i);