From b2c155406566dd9f33d673573cf3b29da27e4246 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 7 May 2018 17:34:41 -0400 Subject: [PATCH] Core/Refactor: Fix alot of Possible loss of fraction warnings --- Source/Framework/Constants/MapConst.cs | 4 ++-- Source/Framework/Util/MathFunctions.cs | 8 ++++---- Source/Game/BattleFields/BattleField.cs | 2 +- Source/Game/BattleFields/Zones/WinterGrasp.cs | 4 ++-- Source/Game/Collision/RegularGrid2D.cs | 7 ++++--- Source/Game/DataStorage/M2Storage.cs | 6 +++--- Source/Game/Entities/AreaTrigger/AreaTrigger.cs | 4 ++-- Source/Game/Entities/Creature/Creature.cs | 2 +- Source/Game/Entities/Player/CinematicManager.cs | 4 ++-- Source/Game/Entities/Player/Player.Items.cs | 2 +- Source/Game/Entities/StatSystem.cs | 2 +- Source/Game/Entities/TemporarySummon.cs | 4 ++-- Source/Game/Entities/Unit/Unit.Combat.cs | 4 ++-- Source/Game/Movement/MoveSpline.cs | 2 +- Source/Game/Network/Packets/MailPackets.cs | 2 +- Source/Game/OutdoorPVP/OutdoorPvP.cs | 2 +- Source/Scripts/Spells/Warlock.cs | 2 +- 17 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Source/Framework/Constants/MapConst.cs b/Source/Framework/Constants/MapConst.cs index 319baaf1e..f5244b06a 100644 --- a/Source/Framework/Constants/MapConst.cs +++ b/Source/Framework/Constants/MapConst.cs @@ -23,8 +23,8 @@ namespace Framework.Constants //Grids public const int MaxGrids = 64; public const float SizeofGrids = 533.33333f; - public const float CenterGridCellId = (MaxCells * MaxGrids / 2); - public const float CenterGridId = (MaxGrids / 2); + public const int CenterGridCellId = (MaxCells * MaxGrids / 2); + public const int CenterGridId = (MaxGrids / 2); public const float CenterGridOffset = (SizeofGrids / 2); public const float CenterGridCellOffset = (SizeofCells / 2); diff --git a/Source/Framework/Util/MathFunctions.cs b/Source/Framework/Util/MathFunctions.cs index 317a16a2b..95afde825 100644 --- a/Source/Framework/Util/MathFunctions.cs +++ b/Source/Framework/Util/MathFunctions.cs @@ -71,7 +71,7 @@ public static class MathFunctions /// Returns the clamped value. /// result = (EpsilonF > Abs(value-calmpedValue)) ? calmpedValue : value; /// - /// is used for tolerance. + /// is used for tolerance. public static float Clamp(float value, float calmpedValue) { return (Epsilon > Math.Abs(value - calmpedValue)) ? calmpedValue : value; @@ -81,10 +81,10 @@ public static class MathFunctions static double eps(double a, double b) { double aa = Math.Abs(a) + 1.0; - if (aa == double.PositiveInfinity) + if (double.IsPositiveInfinity(aa)) return double.Epsilon; - else - return double.Epsilon * aa; + + return double.Epsilon * aa; } public static float lerp(float a, float b, float f) diff --git a/Source/Game/BattleFields/BattleField.cs b/Source/Game/BattleFields/BattleField.cs index 321e08bf5..c62bf8f13 100644 --- a/Source/Game/BattleFields/BattleField.cs +++ b/Source/Game/BattleFields/BattleField.cs @@ -1174,7 +1174,7 @@ namespace Game.BattleFields } // get the difference of numbers - float fact_diff = (m_activePlayers[TeamId.Alliance].Count - m_activePlayers[TeamId.Horde].Count) * diff / 1000; + float fact_diff = ((float)m_activePlayers[TeamId.Alliance].Count - m_activePlayers[TeamId.Horde].Count) * diff / 1000; if (MathFunctions.fuzzyEq(fact_diff, 0.0f)) return false; diff --git a/Source/Game/BattleFields/Zones/WinterGrasp.cs b/Source/Game/BattleFields/Zones/WinterGrasp.cs index 4c837134c..a0a85d23f 100644 --- a/Source/Game/BattleFields/Zones/WinterGrasp.cs +++ b/Source/Game/BattleFields/Zones/WinterGrasp.cs @@ -930,9 +930,9 @@ namespace Game.BattleFields if (alliancePlayers != 0 && hordePlayers != 0) { if (alliancePlayers < hordePlayers) - newStack = (int)(((float)(hordePlayers / alliancePlayers) - 1) * 4); // positive, should cast on alliance + newStack = (int)((((float)hordePlayers / alliancePlayers) - 1) * 4); // positive, should cast on alliance else if (alliancePlayers > hordePlayers) - newStack = (int)((1 - (float)(alliancePlayers / hordePlayers)) * 4); // negative, should cast on horde + newStack = (int)((1 - ((float)alliancePlayers / hordePlayers)) * 4); // negative, should cast on horde } if (newStack == m_tenacityStack) diff --git a/Source/Game/Collision/RegularGrid2D.cs b/Source/Game/Collision/RegularGrid2D.cs index ef7f087ad..19b71f19e 100644 --- a/Source/Game/Collision/RegularGrid2D.cs +++ b/Source/Game/Collision/RegularGrid2D.cs @@ -83,16 +83,17 @@ namespace Game.Collision { return base.Equals(obj); } + public override int GetHashCode() { - return base.GetHashCode(); + return x.GetHashCode() ^ y.GetHashCode(); } public static Cell ComputeCell(float fx, float fy) { Cell c = new Cell(); - c.x = (int)(fx * (1.0f / CELL_SIZE) + (CELL_NUMBER / 2)); - c.y = (int)(fy * (1.0f / CELL_SIZE) + (CELL_NUMBER / 2)); + c.x = (int)(fx * (1.0f / CELL_SIZE) + (CELL_NUMBER / 2f)); + c.y = (int)(fy * (1.0f / CELL_SIZE) + (CELL_NUMBER / 2f)); return c; } diff --git a/Source/Game/DataStorage/M2Storage.cs b/Source/Game/DataStorage/M2Storage.cs index 363c183d4..0e6bf32f5 100644 --- a/Source/Game/DataStorage/M2Storage.cs +++ b/Source/Game/DataStorage/M2Storage.cs @@ -146,9 +146,9 @@ namespace Game.DataStorage float xDiff = nextTarget.locations.X - lastTarget.locations.X; float yDiff = nextTarget.locations.Y - lastTarget.locations.Y; float zDiff = nextTarget.locations.Z - lastTarget.locations.Z; - x = lastTarget.locations.X + (xDiff * (timeDiffThis / timeDiffTarget)); - y = lastTarget.locations.Y + (yDiff * (timeDiffThis / timeDiffTarget)); - z = lastTarget.locations.Z + (zDiff * (timeDiffThis / timeDiffTarget)); + x = lastTarget.locations.X + (xDiff * ((float)timeDiffThis / timeDiffTarget)); + y = lastTarget.locations.Y + (yDiff * ((float)timeDiffThis / timeDiffTarget)); + z = lastTarget.locations.Z + (zDiff * ((float)timeDiffThis / timeDiffTarget)); } float xDiff1 = x - thisCam.locations.X; float yDiff1 = y - thisCam.locations.Y; diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index 77dcdd231..07211fce1 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -225,7 +225,7 @@ namespace Game.Entities float GetProgress() { - return GetTimeSinceCreated() < GetTimeToTargetScale() ? GetTimeSinceCreated() / GetTimeToTargetScale() : 1.0f; + return GetTimeSinceCreated() < GetTimeToTargetScale() ? (float)GetTimeSinceCreated() / GetTimeToTargetScale() : 1.0f; } void UpdateTargetList() @@ -655,7 +655,7 @@ namespace Game.Entities return; } - float currentTimePercent = _movementTime / GetTimeToTarget(); + float currentTimePercent = (float)_movementTime / GetTimeToTarget(); if (currentTimePercent <= 0.0f) return; diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index cf566c573..e5ba534e2 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2318,7 +2318,7 @@ namespace Game.Entities if (getLevel() < levelForTarget) return 1.0f; - return GetMaxHealthByLevel(levelForTarget) / GetCreateHealth(); + return (float)GetMaxHealthByLevel(levelForTarget) / GetCreateHealth(); } float GetBaseDamageForLevel(uint level) diff --git a/Source/Game/Entities/Player/CinematicManager.cs b/Source/Game/Entities/Player/CinematicManager.cs index d64141b18..d6c275b12 100644 --- a/Source/Game/Entities/Player/CinematicManager.cs +++ b/Source/Game/Entities/Player/CinematicManager.cs @@ -161,8 +161,8 @@ namespace Game.Entities float xDiff = nextPosition.posX - lastPosition.posX; float yDiff = nextPosition.posY - lastPosition.posY; float zDiff = nextPosition.posZ - lastPosition.posZ; - Position interPosition = new Position(lastPosition.posX + (xDiff * (interDiff / timeDiff)), lastPosition.posY + - (yDiff * (interDiff / timeDiff)), lastPosition.posZ + (zDiff * (interDiff / timeDiff))); + Position interPosition = new Position(lastPosition.posX + (xDiff * ((float)interDiff / timeDiff)), lastPosition.posY + + (yDiff * ((float)interDiff / timeDiff)), lastPosition.posZ + (zDiff * ((float)interDiff / timeDiff))); // Advance (at speed) to this position. The remote sight object is used // to send update information to player in cinematic diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index 38e26e86b..cefe4091b 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -3772,7 +3772,7 @@ namespace Game.Entities ulong price = 0; if (crItem.IsGoldRequired(pProto) && pProto.GetBuyPrice() > 0) //Assume price cannot be negative (do not know why it is int32) { - float buyPricePerItem = pProto.GetBuyPrice() / pProto.GetBuyCount(); + float buyPricePerItem = (float)pProto.GetBuyPrice() / pProto.GetBuyCount(); ulong maxCount = (ulong)(PlayerConst.MaxMoneyAmount / buyPricePerItem); if (count > maxCount) { diff --git a/Source/Game/Entities/StatSystem.cs b/Source/Game/Entities/StatSystem.cs index e17a893ae..009174c90 100644 --- a/Source/Game/Entities/StatSystem.cs +++ b/Source/Game/Entities/StatSystem.cs @@ -1104,7 +1104,7 @@ namespace Game.Entities var mAPbyArmor = GetAuraEffectsByType(AuraType.ModAttackPowerOfArmor); foreach (var iter in mAPbyArmor) // always: ((*i).GetModifier().m_miscvalue == 1 == SPELL_SCHOOL_MASK_NORMAL) - attPowerMod += GetArmor() / iter.GetAmount(); + attPowerMod += (int)(GetArmor() / iter.GetAmount()); } SetUInt32Value(index, (uint)base_attPower); //UNIT_FIELD_(RANGED)_ATTACK_POWER field diff --git a/Source/Game/Entities/TemporarySummon.cs b/Source/Game/Entities/TemporarySummon.cs index 9f91da292..6c69c893a 100644 --- a/Source/Game/Entities/TemporarySummon.cs +++ b/Source/Game/Entities/TemporarySummon.cs @@ -548,8 +548,8 @@ namespace Game.Entities if (pInfo == null) SetCreateHealth(30 + 30 * petlevel); float bonusDmg = GetOwner().SpellBaseDamageBonusDone(SpellSchoolMask.Nature) * 0.15f; - SetBaseWeaponDamage(WeaponAttackType.BaseAttack, WeaponDamageRange.MinDamage, petlevel * 2.5f - (petlevel / 2) + bonusDmg); - SetBaseWeaponDamage(WeaponAttackType.BaseAttack, WeaponDamageRange.MaxDamage, petlevel * 2.5f + (petlevel / 2) + bonusDmg); + SetBaseWeaponDamage(WeaponAttackType.BaseAttack, WeaponDamageRange.MinDamage, petlevel * 2.5f - ((float)petlevel / 2) + bonusDmg); + SetBaseWeaponDamage(WeaponAttackType.BaseAttack, WeaponDamageRange.MaxDamage, petlevel * 2.5f + ((float)petlevel / 2) + bonusDmg); break; } case 15352: //earth elemental 36213 diff --git a/Source/Game/Entities/Unit/Unit.Combat.cs b/Source/Game/Entities/Unit/Unit.Combat.cs index cffc5f00d..7b824b85a 100644 --- a/Source/Game/Entities/Unit/Unit.Combat.cs +++ b/Source/Game/Entities/Unit/Unit.Combat.cs @@ -784,7 +784,7 @@ namespace Game.Entities uint VictimDefense = victim.GetMaxSkillValueForLevel(this); uint AttackerMeleeSkill = GetMaxSkillValueForLevel(); - Probability *= (float)(AttackerMeleeSkill / VictimDefense * 0.16); + Probability *= (AttackerMeleeSkill / (float)VictimDefense * 0.16f); if (Probability < 0) Probability = 0; @@ -1014,7 +1014,7 @@ namespace Game.Entities victim.ToCreature().LowerPlayerDamageReq(health < damage ? health : damage); } - damage /= (uint)victim.GetHealthMultiplierForTarget(this); + damage = (uint)(damage / victim.GetHealthMultiplierForTarget(this)); if (health <= damage) { diff --git a/Source/Game/Movement/MoveSpline.cs b/Source/Game/Movement/MoveSpline.cs index b959c5ab0..d007debc5 100644 --- a/Source/Game/Movement/MoveSpline.cs +++ b/Source/Game/Movement/MoveSpline.cs @@ -197,7 +197,7 @@ namespace Game.Movement float t_passedf = MSToSec((uint)(time_point - effect_start_time)); float t_durationf = MSToSec((uint)(Duration() - effect_start_time)); //client use not modified duration here if (spell_effect_extra.HasValue && spell_effect_extra.Value.ParabolicCurveId != 0) - t_passedf *= Global.DB2Mgr.GetCurveValueAt(spell_effect_extra.Value.ParabolicCurveId, time_point / Duration()); + t_passedf *= Global.DB2Mgr.GetCurveValueAt(spell_effect_extra.Value.ParabolicCurveId, (float)time_point / Duration()); el += (t_durationf - t_passedf) * 0.5f * vertical_acceleration * t_passedf; } diff --git a/Source/Game/Network/Packets/MailPackets.cs b/Source/Game/Network/Packets/MailPackets.cs index 988d08852..40c218a6a 100644 --- a/Source/Game/Network/Packets/MailPackets.cs +++ b/Source/Game/Network/Packets/MailPackets.cs @@ -400,7 +400,7 @@ namespace Game.Network.Packets StationeryID = (int)mail.stationery; SentMoney = mail.money; Flags = (int)mail.checkMask; - DaysLeft = (mail.expire_time - Time.UnixTime) / Time.Day; + DaysLeft = (float)(mail.expire_time - Time.UnixTime) / Time.Day; MailTemplateID = (int)mail.mailTemplateId; Subject = mail.subject; Body = mail.body; diff --git a/Source/Game/OutdoorPVP/OutdoorPvP.cs b/Source/Game/OutdoorPVP/OutdoorPvP.cs index 586215b67..a85c64232 100644 --- a/Source/Game/OutdoorPVP/OutdoorPvP.cs +++ b/Source/Game/OutdoorPVP/OutdoorPvP.cs @@ -536,7 +536,7 @@ namespace Game.PvP } // get the difference of numbers - float fact_diff = (m_activePlayers[0].Count - m_activePlayers[1].Count) * diff / 1000; + float fact_diff = (float)(m_activePlayers[0].Count - m_activePlayers[1].Count) * diff / 1000; if (fact_diff == 0.0f) return false; diff --git a/Source/Scripts/Spells/Warlock.cs b/Source/Scripts/Spells/Warlock.cs index 714f26ff6..21c85d58b 100644 --- a/Source/Scripts/Spells/Warlock.cs +++ b/Source/Scripts/Spells/Warlock.cs @@ -136,7 +136,7 @@ namespace Scripts.Spells.Warlock } // You take ${$s2/3}% reduced damage - float damageReductionPct = effect1.GetAmount() / 3; + float damageReductionPct = (float)effect1.GetAmount() / 3; // plus a random amount of up to ${$s2/3}% additional reduced damage damageReductionPct += RandomHelper.FRand(0.0f, damageReductionPct);