Skip to content

Commit

Permalink
Refactor and Bugfix Min-Max Damage
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Mar 14, 2024
1 parent bc4f434 commit dbcbb05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/missiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, in
if (t == MissileID::BoneSpirit) {
dam = monster.hitPoints / 3 >> 6;
} else {
dam = mindam + GenerateRnd(maxdam - mindam + 1);
dam = RandomIntBetween(mindam, maxdam);
}

if (missileData.isArrow() && damageType == DamageType::Physical) {
Expand Down Expand Up @@ -3304,7 +3304,7 @@ void ProcessLightningControl(Missile &missile)
dam = (GenerateRnd(2) + GenerateRnd(Players[missile._misource].getCharacterLevel()) + 2) << 6;
} else {
auto &monster = Monsters[missile._misource];
dam = 2 * (monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1));
dam = 2 * RandomIntBetween(monster.minDamage, monster.maxDamage);
}

SpawnLightning(missile, dam);
Expand Down
9 changes: 5 additions & 4 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void InitMonster(Monster &monster, Direction rd, size_t typeIndex, Point positio
monster.animInfo.tickCounterOfCurrentFrame = GenerateRnd(monster.animInfo.ticksPerFrame - 1);
monster.animInfo.currentFrame = GenerateRnd(monster.animInfo.numberOfFrames - 1);

int maxhp = monster.data().hitPointsMinimum + GenerateRnd(monster.data().hitPointsMaximum - monster.data().hitPointsMinimum + 1);
int maxhp = RandomIntBetween(monster.data().hitPointsMinimum, monster.data().hitPointsMaximum);
if (monster.type().type == MT_DIABLO && !gbIsHellfire) {
maxhp /= 2;
}
Expand Down Expand Up @@ -1086,7 +1086,7 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind
if (hit >= hper)
return;

int dam = (mind + GenerateRnd(maxd - mind + 1)) << 6;
int dam = RandomIntBetween(mind, maxd) << 6;
ApplyMonsterDamage(DamageType::Physical, target, dam);

if (attacker.isPlayerMinion()) {
Expand Down Expand Up @@ -1191,7 +1191,8 @@ void MonsterAttackPlayer(Monster &monster, Player &player, int hit, int minDam,
}
}
}
int dam = (minDam << 6) + GenerateRnd(((maxDam - minDam) << 6) + 1);
// New method fixes a bug which caused the maximum possible damage value to be 63/64ths too low.
int dam = RandomIntBetween(minDam, maxDam) << 6;
dam = std::max(dam + (player._pIGetHit << 6), 64);
if (&player == MyPlayer) {
if (player.wReflections > 0) {
Expand Down Expand Up @@ -2650,7 +2651,7 @@ void CounselorAi(Monster &monster)
if (distanceToEnemy >= 2) {
if (v < 5 * (monster.intelligence + 10) && LineClearMissile(monster.position.tile, monster.enemyPosition)) {
constexpr MissileID MissileTypes[4] = { MissileID::Firebolt, MissileID::ChargedBolt, MissileID::LightningControl, MissileID::Fireball };
StartRangedAttack(monster, MissileTypes[monster.intelligence], monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1));
StartRangedAttack(monster, MissileTypes[monster.intelligence], RandomIntBetween(monster.minDamage, monster.maxDamage));
} else if (GenerateRnd(100) < 30) {
monster.goal = MonsterGoal::Move;
monster.goalVar1 = 0;
Expand Down
8 changes: 4 additions & 4 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,12 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false)
}

if (gbIsHellfire && HasAllOf(player._pIFlags, ItemSpecialEffect::FireDamage | ItemSpecialEffect::LightningDamage)) {
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam);
int midam = RandomIntBetween(player._pIFMinDam, player._pIFMaxDam);
AddMissile(player.position.tile, player.position.temp, player._pdir, MissileID::SpectralArrow, TARGET_MONSTERS, player, midam, 0);
}
int mind = player._pIMinDam;
int maxd = player._pIMaxDam;
int dam = GenerateRnd(maxd - mind + 1) + mind;
int dam = RandomIntBetween(mind, maxd);
dam += dam * player._pIBonusDam / 100;
dam += player._pIBonusDamMod;
int dam2 = dam << 6;
Expand Down Expand Up @@ -773,7 +773,7 @@ bool PlrHitPlr(Player &attacker, Player &target)

int mind = attacker._pIMinDam;
int maxd = attacker._pIMaxDam;
int dam = GenerateRnd(maxd - mind + 1) + mind;
int dam = RandomIntBetween(mind, maxd);
dam += (dam * attacker._pIBonusDam) / 100;
dam += attacker._pIBonusDamMod + attacker._pDamageMod;

Expand Down Expand Up @@ -920,7 +920,7 @@ bool DoRangeAttack(Player &player)
mistype = MissileID::LightningArrow;
}
if (HasAllOf(player._pIFlags, ItemSpecialEffect::FireArrows | ItemSpecialEffect::LightningArrows)) {
dmg = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam);
dmg = RandomIntBetween(player._pIFMinDam, player._pIFMaxDam);
mistype = MissileID::SpectralArrow;
}

Expand Down

0 comments on commit dbcbb05

Please sign in to comment.