Skip to content

Commit

Permalink
Fix Knockback direction (#7093)
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 authored Sep 23, 2024
1 parent ee8907e commit cdd2262
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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, startPos);
if (monster.type().type != MT_GOLEM)
M_StartHit(monster, player, dam);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3734,9 +3734,9 @@ void M_ClearSquares(const Monster &monster)
}
}

void M_GetKnockback(Monster &monster)
void M_GetKnockback(Monster &monster, WorldTilePosition attackerStartPos)
{
Direction dir = Opposite(monster.direction);
Direction dir = GetDirection(attackerStartPos, monster.position.tile);
if (!IsRelativeMoveOK(monster, monster.position.old, dir)) {
return;
}
Expand Down Expand Up @@ -4449,7 +4449,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);
Expand All @@ -4470,7 +4470,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;
Expand Down
2 changes: 1 addition & 1 deletion Source/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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);
Expand Down
2 changes: 1 addition & 1 deletion Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,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;
Expand Down

0 comments on commit cdd2262

Please sign in to comment.