Skip to content

Commit

Permalink
Merge pull request #23 from gameboy9/monsterStats
Browse files Browse the repository at this point in the history
Monster stats
  • Loading branch information
stellamazeika authored Dec 21, 2022
2 parents eed1336 + 0fd5fc5 commit 6437c76
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 1,162 deletions.
26 changes: 26 additions & 0 deletions FF1 PRR/FF1 PRR/Common/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,31 @@ public static bool AreAnyDuplicates<T>(this IEnumerable<T> list)
var hashset = new HashSet<T>();
return list.Any(e => !hashset.Add(e));
}

public static double statAdjust(Random r1, double minimum, double middle, double maximum, int numRolls)
{
if (minimum == middle && middle == maximum) return middle;

int direction = (minimum == middle) ? 1 : (maximum == middle) ? 0 : r1.Next() % 2;

long sumRolls = 0;
// Each "roll" will be from 0 to 2^32-1. Think of it as a d(2^32)
for (int i = 0; i < numRolls; i++)
sumRolls += r1.Next();
long avgRolls = sumRolls / numRolls;

if (direction == 0)
return middle - ((middle - minimum) * ((double)Math.Abs(avgRolls - (int.MaxValue / 2)) / (int.MaxValue / 2)));
else
return middle + ((maximum - middle) * ((double)Math.Abs(avgRolls - (int.MaxValue / 2)) / (int.MaxValue / 2)));
}

public static int range(int value, int min = int.MinValue, int max = int.MaxValue)
{
if (min > max) throw new Exception("min is higher than max");
if (value < min) return min;
if (value > max) return max;
return value;
}
}
}
Loading

0 comments on commit 6437c76

Please sign in to comment.