Skip to content

Commit

Permalink
NaN value is messing things up.
Browse files Browse the repository at this point in the history
  • Loading branch information
zerratar committed Jul 24, 2023
1 parent 6b90672 commit 5d212c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public override void Process(
var expForNextLevel = GameMath.ExperienceForLevel(nextLevel);
village.Experience += GameMath.GetVillageExperience(village.Level, players.Count, elapsed);

if (double.IsNaN(village.Experience))
{
village.Experience = 0;
}

// check if this village gone mad.
var percentage = village.Experience / (double)expForNextLevel;
if (percentage > 2)
Expand Down
7 changes: 6 additions & 1 deletion src/RavenNest.BusinessLogic/Utilities/GameMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ public static double GetVillageExperience(int level, int playerCount, TimeSpan e
var bTicksForLevel = Exp.GetMaxMinutesForLevel(level) * 60; // multiply by 60 to get seconds, since we have 1 tick per second
var expForNextLevel = ExperienceForLevel(nextlevel);
var expGain = expForNextLevel / bTicksForLevel;
return Lerp(0, expGain, factor);
var value = Lerp(0, expGain, factor);
if (double.IsNaN(value))
{
return 0;
}
return value;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 5d212c4

Please sign in to comment.