From 1745204beea151115b43efc54836fd1f7d64aca2 Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 00:07:53 -0400 Subject: [PATCH 1/7] Fix Knockback --- Source/missiles.cpp | 2 +- Source/monster.cpp | 4 ++-- Source/monster.h | 2 +- Source/msg.cpp | 2 +- Source/player.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 95b963af6cd..0b0665a8dac 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -268,7 +268,7 @@ bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, in PlayEffect(monster, MonsterSound::Hit); } else { if (monster.mode != MonsterMode::Petrified && missileData.isArrow() && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback)) - M_GetKnockback(monster); + M_GetKnockback(monster, player.position.tile); if (monster.type().type != MT_GOLEM) M_StartHit(monster, player, dam); } diff --git a/Source/monster.cpp b/Source/monster.cpp index d05a0febcf5..3d57f85e2d5 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3733,9 +3733,9 @@ void M_ClearSquares(const Monster &monster) } } -void M_GetKnockback(Monster &monster) +void M_GetKnockback(Monster &monster, WorldTilePosition playerPos) { - Direction dir = Opposite(monster.direction); + auto dir = GetDirection(playerPos, monster.position.future); if (!IsRelativeMoveOK(monster, monster.position.old, dir)) { return; } diff --git a/Source/monster.h b/Source/monster.h index 44d46ed31a5..38be01b0ed1 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -514,7 +514,7 @@ void ApplyMonsterDamage(DamageType damageType, Monster &monster, int damage); bool M_Talker(const Monster &monster); void M_StartStand(Monster &monster, Direction md); void M_ClearSquares(const Monster &monster); -void M_GetKnockback(Monster &monster); +void M_GetKnockback(Monster &monster, WorldTilePosition playerPos); void M_StartHit(Monster &monster, int dam); void M_StartHit(Monster &monster, const Player &player, int dam); void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg); diff --git a/Source/msg.cpp b/Source/msg.cpp index 0a6e2e445bd..cbcfd6bcb31 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -1659,7 +1659,7 @@ size_t OnKnockback(const TCmd *pCmd, Player &player) if (gbBufferMsgs != 1 && player.isOnActiveLevel() && monsterIdx < MaxMonsters) { Monster &monster = Monsters[monsterIdx]; - M_GetKnockback(monster); + M_GetKnockback(monster, player.position.tile); M_StartHit(monster, player, 0); } diff --git a/Source/player.cpp b/Source/player.cpp index 0b2d6beac34..9cc473da332 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -678,7 +678,7 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) M_StartKill(monster, player); } else { if (monster.mode != MonsterMode::Petrified && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback)) - M_GetKnockback(monster); + M_GetKnockback(monster, player.position.tile); M_StartHit(monster, player, dam); } return true; From f367b164af6e2a4374ef294d30a48f31cede1f11 Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 17:35:29 -0400 Subject: [PATCH 2/7] Use missile start position --- Source/missiles.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 0b0665a8dac..89004d3a642 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -203,7 +203,7 @@ int ProjectileTrapDamage() return currlevel + GenerateRnd(2 * currlevel); } -bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, int dist, MissileID t, DamageType damageType, bool shift) +bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, int dist, MissileID t, WorldTilePosition startPos, DamageType damageType, bool shift) { Monster &monster = Monsters[monsterId]; @@ -268,7 +268,7 @@ bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, in PlayEffect(monster, MonsterSound::Hit); } else { if (monster.mode != MonsterMode::Petrified && missileData.isArrow() && HasAnyOf(player._pIFlags, ItemSpecialEffect::Knockback)) - M_GetKnockback(monster, player.position.tile); + M_GetKnockback(monster, startPos); if (monster.type().type != MT_GOLEM) M_StartHit(monster, player, dam); } @@ -422,7 +422,7 @@ void CheckMissileCol(Missile &missile, DamageType damageType, int minDamage, int // then the missile can potentially hit this target isMonsterHit = MonsterTrapHit(mid, minDamage, maxDamage, missile._midist, missile._mitype, damageType, isDamageShifted); } else if (IsAnyOf(missile._micaster, TARGET_BOTH, TARGET_MONSTERS)) { - isMonsterHit = MonsterMHit(*missile.sourcePlayer(), mid, minDamage, maxDamage, missile._midist, missile._mitype, damageType, isDamageShifted); + isMonsterHit = MonsterMHit(*missile.sourcePlayer(), mid, minDamage, maxDamage, missile._midist, missile._mitype, missile.position.start, damageType, isDamageShifted); } } From 96f775923939807b0e855e40a2325865618f9f2a Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 17:44:45 -0400 Subject: [PATCH 3/7] Update variable name --- Source/monster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 3d57f85e2d5..5766d339f21 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3733,9 +3733,9 @@ void M_ClearSquares(const Monster &monster) } } -void M_GetKnockback(Monster &monster, WorldTilePosition playerPos) +void M_GetKnockback(Monster &monster, WorldTilePosition attackerStartPos) { - auto dir = GetDirection(playerPos, monster.position.future); + auto dir = GetDirection(attackerStartPos, monster.position.future); if (!IsRelativeMoveOK(monster, monster.position.old, dir)) { return; } From 1ae70a1db714c51922aa8139138bd918e4c395e9 Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 17:49:30 -0400 Subject: [PATCH 4/7] Update monster.h --- Source/monster.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/monster.h b/Source/monster.h index 38be01b0ed1..a4d72243135 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -514,7 +514,7 @@ void ApplyMonsterDamage(DamageType damageType, Monster &monster, int damage); bool M_Talker(const Monster &monster); void M_StartStand(Monster &monster, Direction md); void M_ClearSquares(const Monster &monster); -void M_GetKnockback(Monster &monster, WorldTilePosition playerPos); +void M_GetKnockback(Monster &monster, WorldTilePosition attackerStartPos); void M_StartHit(Monster &monster, int dam); void M_StartHit(Monster &monster, const Player &player, int dam); void StartMonsterDeath(Monster &monster, const Player &player, bool sendmsg); From 2410299f4533399b6806500314900639033ef213 Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 18:12:05 -0400 Subject: [PATCH 5/7] Fix monster charging knockback --- Source/monster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 5766d339f21..ed5063ef987 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -4448,7 +4448,7 @@ void MissToMonst(Missile &missile, Point position) if (player->_pmode != PM_GOTHIT && player->_pmode != PM_DEATH) StartPlrHit(*player, 0, true); - Point newPosition = oldPosition + monster.direction; + Point newPosition = oldPosition + GetDirection(missile.position.start, oldPosition); if (PosOkPlayer(*player, newPosition)) { player->position.tile = newPosition; FixPlayerLocation(*player, player->_pdir); @@ -4469,7 +4469,7 @@ void MissToMonst(Missile &missile, Point position) if (IsAnyOf(monster.type().type, MT_NSNAKE, MT_RSNAKE, MT_BSNAKE, MT_GSNAKE)) return; - Point newPosition = oldPosition + monster.direction; + Point newPosition = oldPosition + GetDirection(missile.position.start, oldPosition); if (IsTileAvailable(*target, newPosition)) { monster.occupyTile(newPosition, false); dMonster[oldPosition.x][oldPosition.y] = 0; From b22aef64e9110a4b386a14ad6ddfe7bb9d5ad3b0 Mon Sep 17 00:00:00 2001 From: KPhoenix Date: Thu, 18 Apr 2024 18:44:02 -0400 Subject: [PATCH 6/7] Update monster.cpp --- Source/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index ed5063ef987..08d7b4b5f67 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3735,7 +3735,7 @@ void M_ClearSquares(const Monster &monster) void M_GetKnockback(Monster &monster, WorldTilePosition attackerStartPos) { - auto dir = GetDirection(attackerStartPos, monster.position.future); + auto dir = GetDirection(attackerStartPos, monster.position.tile); if (!IsRelativeMoveOK(monster, monster.position.old, dir)) { return; } From 68c585e1cf969500d709a15a2ed2f5514ff584af Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sun, 22 Sep 2024 20:32:59 -0400 Subject: [PATCH 7/7] Change local var type --- Source/monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 08d7b4b5f67..1421c1da48f 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3735,7 +3735,7 @@ void M_ClearSquares(const Monster &monster) void M_GetKnockback(Monster &monster, WorldTilePosition attackerStartPos) { - auto dir = GetDirection(attackerStartPos, monster.position.tile); + Direction dir = GetDirection(attackerStartPos, monster.position.tile); if (!IsRelativeMoveOK(monster, monster.position.old, dir)) { return; }