Skip to content

Commit

Permalink
MonsterMHit bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wkdgmr committed Oct 6, 2023
1 parent 61a88f4 commit 7523dc0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
36 changes: 6 additions & 30 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,16 @@ int ProjectileTrapDamage(Missile &missile)
return currlevel + GenerateRnd(2 * currlevel);
}

bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, MissileID t, DamageType damageType, bool shift)
bool MonsterMHit(int pnum, int monsterId, int mindam, int maxdam, int dist, Missile missile, MissileID t, DamageType damageType, bool shift)
{
auto &monster = Monsters[monsterId];

if (!monster.isPossibleToHit()) {
if (!monster.isPossibleToHit() || monster.isImmune(missile, t, damageType))
return false;
}

const Player &player = Players[pnum];

if (monster.isImmune(t, damageType)
&& (!((damageType == DamageType::Physical)
|| (t == MissileID::FireArrow)
|| (t == MissileID::WeaponExplosion)
|| (t == MissileID::FireballBow && player._pIMisType == 1 && player.executedSpell.spellId != SpellID::Immolation)
|| (t == MissileID::FireballBow && player._pIMisType == 1 && HasAnyOf(player._pIFlags, ItemSpecialEffect::Empower))
|| (t == MissileID::Fireball && player._pIMisType == 1)
|| (t == MissileID::FireWall && HasAnyOf(player._pIFlags, ItemSpecialEffect::Thorns) && player.executedSpell.spellId != SpellID::FireWall)
|| (t == MissileID::LightningArrow)
|| (t == MissileID::LightningBow && player._pIMisType == 2)
|| (t == MissileID::Lightning && player._pIMisType == 2)
|| (t == MissileID::ChainLightning && player._pIMisType == 2 && HasAnyOf(player._pIFlags, ItemSpecialEffect::Empower))
|| (t == MissileID::ChargedBoltBow)
|| (t == MissileID::Firebolt)
|| (t == MissileID::Inferno)
|| (t == MissileID::ChargedBolt)
|| (t == MissileID::FlashBottom)
|| (t == MissileID::FlashTop)
|| (t == MissileID::Acid && player._pIMisType == 10)))) {
return false;
}

int hit = GenerateRnd(100);
int hper = 0;
const Player &player = Players[pnum];
const MissileData &missileData = GetMissileData(t);
if (missileData.isArrow()) {
hper = player.GetRangedPiercingToHit();
Expand Down Expand Up @@ -462,7 +438,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._misource, mid, minDamage, maxDamage, missile._midist, missile._mitype, damageType, isDamageShifted);
isMonsterHit = MonsterMHit(missile._misource, mid, minDamage, maxDamage, missile._midist, missile, missile._mitype, damageType, isDamageShifted);
}
}

Expand Down Expand Up @@ -994,11 +970,11 @@ Direction16 GetDirection16(Point p1, Point p2)
return ret;
}

bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, MissileID t, DamageType damageType, bool shift)
bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, Missile missile, MissileID t, DamageType damageType, bool shift)
{
auto &monster = Monsters[monsterId];

if (!monster.isPossibleToHit() || monster.isImmune(t, damageType))
if (!monster.isPossibleToHit() || monster.isImmuneTraps(t, damageType))
return false;

int hit = GenerateRnd(100);
Expand Down
37 changes: 36 additions & 1 deletion Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4736,7 +4736,7 @@ bool Monster::isWalking() const
}
}

bool Monster::isImmune(MissileID missileType, DamageType missileElement) const
bool Monster::isImmuneTraps(MissileID missileType, DamageType missileElement) const
{
if (((resistance & IMMUNE_FIRE) != 0 && missileElement == DamageType::Fire)
|| ((resistance & IMMUNE_LIGHTNING) != 0 && missileElement == DamageType::Lightning)
Expand All @@ -4745,6 +4745,41 @@ bool Monster::isImmune(MissileID missileType, DamageType missileElement) const
}
}


bool Monster::isImmune(Missile &missile, MissileID missileType, DamageType missileElement) const
{
Player &player = Players[missile._misource];
bool immune = false;

if ((resistance & IMMUNE_FIRE) != 0 && missileElement == DamageType::Fire) {

immune = !(missileType == MissileID::FireArrow
|| missileType == MissileID::WeaponExplosion
|| missileType == MissileID::FireballBow && player._pIMisType == 1 && player.executedSpell.spellId != SpellID::Immolation
|| missileType == MissileID::FireballBow && player._pIMisType == 1 && HasAnyOf(player._pIFlags, ItemSpecialEffect::Empower)
|| missileType == MissileID::Fireball && player._pIMisType == 1
|| missileType == MissileID::FireWall && HasAnyOf(player._pIFlags, ItemSpecialEffect::Thorns) && player.executedSpell.spellId != SpellID::FireWall
|| missileType == MissileID::Firebolt
|| missileType == MissileID::Inferno);

} else if ((resistance & IMMUNE_LIGHTNING) != 0 && missileElement == DamageType::Lightning) {

immune = !(missileType == MissileID::LightningArrow
|| missileType == MissileID::WeaponExplosion
|| missileType == MissileID::LightningBow && player._pIMisType == 2
|| missileType == MissileID::Lightning && player._pIMisType == 2
|| missileType == MissileID::ChainLightning && player._pIMisType == 2 && HasAnyOf(player._pIFlags, ItemSpecialEffect::Empower)
|| missileType == MissileID::ChargedBoltBow
|| missileType == MissileID::FlashBottom
|| missileType == MissileID::FlashTop);

} else if ((resistance & IMMUNE_ACID) != 0 && missileElement == DamageType::Acid) {
immune = !(missileType == MissileID::Acid && player._pIMisType == 10);
}

return immune;
}

bool Monster::isResistant(MissileID missileType, DamageType missileElement) const
{
if (((resistance & IMMUNE_FIRE) != 0 && missileElement == DamageType::Fire)
Expand Down
3 changes: 2 additions & 1 deletion Source/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ struct Monster { // note: missing field _mAFNum
* @brief Is the monster currently walking?
*/
[[nodiscard]] bool isWalking() const;
[[nodiscard]] bool isImmune(MissileID mitype, DamageType missileElement) const;
[[nodiscard]] bool isImmune(Missile &missile, MissileID mitype, DamageType missileElement) const;
[[nodiscard]] bool isImmuneTraps(MissileID mitype, DamageType missileElement) const;
[[nodiscard]] bool isResistant(MissileID mitype, DamageType missileElement) const;

/**
Expand Down
10 changes: 4 additions & 6 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,16 +1242,12 @@ bool DoRangeAttack(Player &player)
if (player._pIMisType == 1) {
mistype = MissileID::SpectralArrow;
}
}

if (HasAnyOf(player._pIFlags, ItemSpecialEffect::LightningArrows)) {
} else if (HasAnyOf(player._pIFlags, ItemSpecialEffect::LightningArrows)) {
mistype = MissileID::LightningArrow;
if (player._pIMisType == 2) {
mistype = MissileID::SpectralArrow;
}
}

if (HasAnyOf(player._pIFlags, ItemSpecialEffect::MagicDamage)) {
} else if (HasAnyOf(player._pIFlags, ItemSpecialEffect::MagicDamage)) {
switch (player._pIMisType) {
case 100:
case 5:
Expand All @@ -1263,6 +1259,8 @@ bool DoRangeAttack(Player &player)
mistype = MissileID::Arrow;
break;
}
} else {
mistype = MissileID::Arrow;
}

AddMissile(
Expand Down

0 comments on commit 7523dc0

Please sign in to comment.