[Cleanup] Make use of std::abs where possible. (#2739)

# Notes
- Resolves https://github.com/EQEmu/Server/issues/338
This commit is contained in:
Alex King 2023-01-15 17:02:13 -05:00 committed by GitHub
parent eed45e5250
commit 00658632de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 29 deletions

View File

@ -285,33 +285,37 @@ int64 Mob::GetActDoTDamage(uint16 spell_id, int64 value, Mob* target, bool from_
int64 Mob::GetExtraSpellAmt(uint16 spell_id, int64 extra_spell_amt, int64 base_spell_dmg)
{
if (RuleB(Spells, FlatItemExtraSpellAmt)) {
if (RuleB(Spells, ItemExtraSpellAmtCalcAsPercent))
return abs(base_spell_dmg)*extra_spell_amt/100;
else
if (RuleB(Spells, ItemExtraSpellAmtCalcAsPercent)) {
return std::abs(base_spell_dmg) * extra_spell_amt / 100;
} else {
return extra_spell_amt;
}
}
int total_cast_time = 0;
if (spells[spell_id].recast_time >= spells[spell_id].recovery_time)
total_cast_time = spells[spell_id].recast_time + spells[spell_id].cast_time;
else
if (spells[spell_id].recast_time >= spells[spell_id].recovery_time) {
total_cast_time = spells[spell_id].recast_time + spells[spell_id].cast_time;
} else {
total_cast_time = spells[spell_id].recovery_time + spells[spell_id].cast_time;
if (total_cast_time > 0 && total_cast_time <= 2500)
extra_spell_amt = extra_spell_amt*25/100;
else if (total_cast_time > 2500 && total_cast_time < 7000)
extra_spell_amt = extra_spell_amt*(167*((total_cast_time - 1000)/1000)) / 1000;
else
extra_spell_amt = extra_spell_amt * total_cast_time / 7000;
//Confirmed with parsing 10/9/21 ~Kayen
if (extra_spell_amt * 2 > abs(base_spell_dmg)) {
extra_spell_amt = abs(base_spell_dmg) / 2;
}
if (RuleB(Spells, ItemExtraSpellAmtCalcAsPercent))
return abs(base_spell_dmg)*extra_spell_amt/100;
if (total_cast_time > 0 && total_cast_time <= 2500) {
extra_spell_amt = extra_spell_amt * 25 / 100;
} else if (total_cast_time > 2500 && total_cast_time < 7000) {
extra_spell_amt = extra_spell_amt * (167 * ((total_cast_time - 1000) / 1000)) / 1000;
} else {
extra_spell_amt = extra_spell_amt * total_cast_time / 7000;
}
//Confirmed with parsing 10/9/21 ~Kayen
if (extra_spell_amt * 2 > std::abs(base_spell_dmg)) {
extra_spell_amt = std::abs(base_spell_dmg) / 2;
}
if (RuleB(Spells, ItemExtraSpellAmtCalcAsPercent)) {
return std::abs(base_spell_dmg) * extra_spell_amt / 100;
}
return extra_spell_amt;
}

View File

@ -2864,7 +2864,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
case SE_Instant_Mana_Pct: {
effect_value = spells[spell_id].base_value[i];
int64 amt = abs(GetMaxMana() * effect_value / 10000);
int64 amt = std::abs(GetMaxMana() * effect_value / 10000);
if (spells[spell_id].max_value[i] && amt > spells[spell_id].max_value[i])
amt = spells[spell_id].max_value[i];
@ -2880,7 +2880,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
case SE_Instant_Endurance_Pct: {
effect_value = spells[spell_id].base_value[i];
if (IsClient()) {
int32 amt = abs(CastToClient()->GetMaxEndurance() * effect_value / 10000);
int32 amt = std::abs(CastToClient()->GetMaxEndurance() * effect_value / 10000);
if (spells[spell_id].max_value[i] && amt > spells[spell_id].max_value[i])
amt = spells[spell_id].max_value[i];
@ -2899,7 +2899,7 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove
*/
case SE_Health_Transfer: {
effect_value = spells[spell_id].limit_value[i];
int64 amt = abs(caster->GetMaxHP() * effect_value / 1000);
int64 amt = std::abs(caster->GetMaxHP() * effect_value / 1000);
if (effect_value < 0) {
Damage(caster, amt, spell_id, spell.skill, false, buffslot, false);
@ -4059,7 +4059,7 @@ void Mob::DoBuffTic(const Buffs_Struct &buff, int slot, Mob *caster)
case SE_Duration_HP_Pct: {
effect_value = spells[buff.spellid].base_value[i];
int64 amt = abs(GetMaxHP() * effect_value / 100);
int64 amt = std::abs(GetMaxHP() * effect_value / 100);
if (spells[buff.spellid].max_value[i] && amt > spells[buff.spellid].max_value[i])
amt = spells[buff.spellid].max_value[i];
@ -4074,7 +4074,7 @@ void Mob::DoBuffTic(const Buffs_Struct &buff, int slot, Mob *caster)
case SE_Duration_Mana_Pct: {
effect_value = spells[buff.spellid].base_value[i];
int32 amt = abs(GetMaxMana() * effect_value / 100);
int32 amt = std::abs(GetMaxMana() * effect_value / 100);
if (spells[buff.spellid].max_value[i] && amt > spells[buff.spellid].max_value[i])
amt = spells[buff.spellid].max_value[i];
@ -4092,7 +4092,7 @@ void Mob::DoBuffTic(const Buffs_Struct &buff, int slot, Mob *caster)
effect_value = spells[buff.spellid].base_value[i];
if (IsClient()) {
int32 amt = abs(CastToClient()->GetMaxEndurance() * effect_value / 100);
int32 amt = std::abs(CastToClient()->GetMaxEndurance() * effect_value / 100);
if (spells[buff.spellid].max_value[i] && amt > spells[buff.spellid].max_value[i])
amt = spells[buff.spellid].max_value[i];
@ -6390,7 +6390,7 @@ int64 Mob::GetFocusEffect(focusType type, uint16 spell_id, Mob *caster, bool fro
if (!ins) {
continue;
}
TempItem = ins->GetItem();
if (TempItem && TempItem->Focus.Effect > 0 && TempItem->Focus.Effect != SPELL_UNKNOWN) {
if(rand_effectiveness) {

View File

@ -2768,9 +2768,9 @@ void Zone::CalculateNpcUpdateDistanceSpread()
}
}
int x_spread = int(abs(max_x - min_x));
int y_spread = int(abs(max_y - min_y));
int combined_spread = int(abs((x_spread + y_spread) / 2));
int x_spread = int(std::abs(max_x - min_x));
int y_spread = int(std::abs(max_y - min_y));
int combined_spread = int(std::abs((x_spread + y_spread) / 2));
int update_distance = EQ::ClampLower(int(combined_spread / 4), int(zone->GetMaxMovementUpdateRange()));
SetNpcPositionUpdateDistance(update_distance);