Skip to content

Commit

Permalink
Beta 10
Browse files Browse the repository at this point in the history
Fix BonusStat+ Mods, and adds EquipStatDouble. Changes StatModifiers to return an EquipStatDouble.
  • Loading branch information
SuperKael committed Sep 7, 2020
1 parent baa22cf commit 6ae3782
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 11 deletions.
301 changes: 297 additions & 4 deletions API/EquipStats.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;

namespace GadgetCore.API
{
Expand Down Expand Up @@ -50,6 +51,14 @@ public EquipStats(EquipStats stats)
this.stats = stats.stats;
}

/// <summary>
/// Creates a new instance of EquipStats that has the same stats as the given EquipStatsDouble, with the values truncated to integers.
/// </summary>
public static explicit operator EquipStats(EquipStatsDouble stats)
{
return new EquipStats(stats.GetStatArray().Select(x => (int)x).ToArray());
}

/// <summary>
/// Creates a new instance of EquipStats that has the specified stats.
/// </summary>
Expand Down Expand Up @@ -181,6 +190,38 @@ public int[] SubtractFrom(int[] statArray)
return new EquipStats(a.VIT / b.VIT, a.STR / b.STR, a.DEX / b.DEX, a.TEC / b.TEC, a.MAG / b.MAG, a.FTH / b.FTH);
}

/// <summary>
/// Creates a new EquipStats by adding together the values of an EquipStats and an EquipStatsDouble. Truncates excess double values.
/// </summary>
public static EquipStats operator +(EquipStats a, EquipStatsDouble b)
{
return new EquipStats(a.VIT + (int)b.VIT, a.STR + (int)b.STR, a.DEX + (int)b.DEX, a.TEC + (int)b.TEC, a.MAG + (int)b.MAG, a.FTH + (int)b.FTH);
}

/// <summary>
/// Creates a new EquipStats by subtracting the values of an EquipStatsDouble and an EquipStats. Truncates excess double values.
/// </summary>
public static EquipStats operator -(EquipStats a, EquipStatsDouble b)
{
return new EquipStats(a.VIT - (int)b.VIT, a.STR - (int)b.STR, a.DEX - (int)b.DEX, a.TEC - (int)b.TEC, a.MAG - (int)b.MAG, a.FTH - (int)b.FTH);
}

/// <summary>
/// Creates a new EquipStats by multiplying together the values of an EquipStats and an EquipStatsDouble.
/// </summary>
public static EquipStats operator *(EquipStats a, EquipStatsDouble b)
{
return new EquipStats((int)Math.Round(a.VIT * b.VIT), (int)Math.Round(a.STR * b.STR), (int)Math.Round(a.DEX * b.DEX), (int)Math.Round(a.TEC * b.TEC), (int)Math.Round(a.MAG * b.MAG), (int)Math.Round(a.FTH * b.FTH));
}

/// <summary>
/// Creates a new EquipStats by diving the values of an EquipStatsDouble from an EquipStats.
/// </summary>
public static EquipStats operator /(EquipStats a, EquipStatsDouble b)
{
return new EquipStats((int)Math.Round(a.VIT / b.VIT), (int)Math.Round(a.STR / b.STR), (int)Math.Round(a.DEX / b.DEX), (int)Math.Round(a.TEC / b.TEC), (int)Math.Round(a.MAG / b.MAG), (int)Math.Round(a.FTH / b.FTH));
}

/// <summary>
/// Creates a new EquipStats by adding a value to all stats.
/// </summary>
Expand All @@ -200,17 +241,269 @@ public int[] SubtractFrom(int[] statArray)
/// <summary>
/// Creates a new EquipStats by multiplying all stats by a value.
/// </summary>
public static EquipStats operator *(EquipStats a, float b)
public static EquipStats operator *(EquipStats a, double b)
{
return new EquipStats((int)(a.VIT * b), (int)(a.STR * b), (int)(a.DEX * b), (int)(a.TEC * b), (int)(a.MAG * b), (int)(a.FTH * b));
return new EquipStats((int)Math.Round(a.VIT * b), (int)Math.Round(a.STR * b), (int)Math.Round(a.DEX * b), (int)Math.Round(a.TEC * b), (int)Math.Round(a.MAG * b), (int)Math.Round(a.FTH * b));
}

/// <summary>
/// Creates a new EquipStats by dividing all stats by a value.
/// </summary>
public static EquipStats operator /(EquipStats a, float b)
public static EquipStats operator /(EquipStats a, double b)
{
return new EquipStats((int)Math.Round(a.VIT / b), (int)Math.Round(a.STR / b), (int)Math.Round(a.DEX / b), (int)Math.Round(a.TEC / b), (int)Math.Round(a.MAG / b), (int)Math.Round(a.FTH / b));
}
}

/// <summary>
/// Represents a set of all six of the player stats, as double-precision floating-point values.
/// </summary>
public struct EquipStatsDouble
{
/// <summary>
/// EquipStatsDouble where all stats are 0.
/// </summary>
public static readonly EquipStatsDouble NONE = new EquipStatsDouble(0, 0, 0, 0, 0, 0);
/// <summary>
/// EquipStatsDouble where all stats are 1.
/// </summary>
public static readonly EquipStatsDouble ONE = new EquipStatsDouble(1, 1, 1, 1, 1, 1);

private readonly double[] stats;
/// <summary>
/// The VIT stat.
/// </summary>
public double VIT { get { return stats != null ? stats[0] : 0; } }
/// <summary>
/// The STR stat.
/// </summary>
public double STR { get { return stats != null ? stats[1] : 0; } }
/// <summary>
/// The DEX stat.
/// </summary>
public double DEX { get { return stats != null ? stats[2] : 0; } }
/// <summary>
/// The TEC stat.
/// </summary>
public double TEC { get { return stats != null ? stats[3] : 0; } }
/// <summary>
/// The MAG stat.
/// </summary>
public double MAG { get { return stats != null ? stats[4] : 0; } }
/// <summary>
/// The FTH stat.
/// </summary>
public double FTH { get { return stats != null ? stats[5] : 0; } }

/// <summary>
/// Creates a new instance of EquipStatsDouble that has the same stats as the given EquipStatsDouble.
/// </summary>
public EquipStatsDouble(EquipStatsDouble stats)
{
this.stats = stats.stats;
}

/// <summary>
/// Creates a new instance of EquipStatsDouble that has the same stats as the given EquipStats.
/// </summary>
public static implicit operator EquipStatsDouble(EquipStats stats)
{
return new EquipStatsDouble(stats.GetStatArray().Select(x => (double)x).ToArray());
}

/// <summary>
/// Creates a new instance of EquipStatsDouble that has the specified stats.
/// </summary>
public EquipStatsDouble(double VIT, double STR, double DEX, double TEC, double MAG, double FTH)
{
stats = new double[6];
stats[0] = VIT;
stats[1] = STR;
stats[2] = DEX;
stats[3] = TEC;
stats[4] = MAG;
stats[5] = FTH;
}

/// <summary>
/// Creates a new instance of EquipStatsDouble where all stats are the given value.
/// </summary>
public EquipStatsDouble(double stat)
{
stats = new double[6];
stats[0] = stat;
stats[1] = stat;
stats[2] = stat;
stats[3] = stat;
stats[4] = stat;
stats[5] = stat;
}

/// <summary>
/// Creates a new instance of EquipStatsDouble from an array of stat values. The array must be of length 6.
/// </summary>
public EquipStatsDouble(double[] statArray)
{
if (statArray == null || statArray.Length != 6) throw new InvalidOperationException("Stat array must be of length 6!");
stats = statArray;
}

/// <summary>
/// Returns the stats as an array of values. Will be of length 6.
/// </summary>
public double[] GetStatArray()
{
return stats != null ? (double[])stats.Clone() : new double[6];
}

/// <summary>
/// Gets the stat with the specified index. 0 is VIT, 1 is STR, 2 is DEX, 3 is TEC, 4 is MAG, 5 is FTH.
/// </summary>
public double GetByIndex(int index)
{
return stats[index];
}

/// <summary>
/// Sets the stat with the specified index. 0 is VIT, 1 is STR, 2 is DEX, 3 is TEC, 4 is MAG, 5 is FTH.
/// </summary>
public void SetByIndex(int index, double stat)
{
stats[index] = stat;
}

/// <summary>
/// Adds to the stat with the specified index. 0 is VIT, 1 is STR, 2 is DEX, 3 is TEC, 4 is MAG, 5 is FTH.
/// </summary>
public void AddByIndex(int index, double stat)
{
stats[index] += stat;
}

/// <summary>
/// Adds this EquipStat's values to the given stat value array. The array must be of length 6.
/// </summary>
public double[] AddTo(double[] statArray)
{
if (statArray == null || statArray.Length != 6) throw new InvalidOperationException("Stat array must be of length 6!");
statArray[0] += VIT;
statArray[1] += STR;
statArray[2] += DEX;
statArray[3] += TEC;
statArray[4] += MAG;
statArray[5] += FTH;
return statArray;
}

/// <summary>
/// Subtracts this EquipStat's values from the given stat value array. The array must be of length 6.
/// </summary>
public double[] SubtractFrom(double[] statArray)
{
if (statArray == null || statArray.Length != 6) throw new InvalidOperationException("Stat array must be of length 6!");
statArray[0] -= VIT;
statArray[1] -= STR;
statArray[2] -= DEX;
statArray[3] -= TEC;
statArray[4] -= MAG;
statArray[5] -= FTH;
return statArray;
}

/// <summary>
/// Creates a new EquipStatsDouble by adding together the values of two other EquipStatsDouble.
/// </summary>
public static EquipStatsDouble operator +(EquipStatsDouble a, EquipStatsDouble b)
{
return new EquipStatsDouble(a.VIT + b.VIT, a.STR + b.STR, a.DEX + b.DEX, a.TEC + b.TEC, a.MAG + b.MAG, a.FTH + b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by subtracting the values of one EquipStatsDouble from another.
/// </summary>
public static EquipStatsDouble operator -(EquipStatsDouble a, EquipStatsDouble b)
{
return new EquipStatsDouble(a.VIT - b.VIT, a.STR - b.STR, a.DEX - b.DEX, a.TEC - b.TEC, a.MAG - b.MAG, a.FTH - b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by multiplying together the values of two other EquipStatsDouble.
/// </summary>
public static EquipStatsDouble operator *(EquipStatsDouble a, EquipStatsDouble b)
{
return new EquipStatsDouble(a.VIT * b.VIT, a.STR * b.STR, a.DEX * b.DEX, a.TEC * b.TEC, a.MAG * b.MAG, a.FTH * b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by diving the values of one EquipStatsDouble from another.
/// </summary>
public static EquipStatsDouble operator /(EquipStatsDouble a, EquipStatsDouble b)
{
return new EquipStatsDouble(a.VIT / b.VIT, a.STR / b.STR, a.DEX / b.DEX, a.TEC / b.TEC, a.MAG / b.MAG, a.FTH / b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by adding together the values of an EquipStatsDouble and an EquipStats.
/// </summary>
public static EquipStatsDouble operator +(EquipStatsDouble a, EquipStats b)
{
return new EquipStatsDouble(a.VIT + b.VIT, a.STR + b.STR, a.DEX + b.DEX, a.TEC + b.TEC, a.MAG + b.MAG, a.FTH + b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by subtracting the values of an EquipStats from an EquipStatsDouble.
/// </summary>
public static EquipStatsDouble operator -(EquipStatsDouble a, EquipStats b)
{
return new EquipStatsDouble(a.VIT - b.VIT, a.STR - b.STR, a.DEX - b.DEX, a.TEC - b.TEC, a.MAG - b.MAG, a.FTH - b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by multiplying together an EquipStatsDouble and an EquipStats.
/// </summary>
public static EquipStatsDouble operator *(EquipStatsDouble a, EquipStats b)
{
return new EquipStatsDouble(a.VIT * b.VIT, a.STR * b.STR, a.DEX * b.DEX, a.TEC * b.TEC, a.MAG * b.MAG, a.FTH * b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by diving the values of an EquipStats from an EquipStatsDouble.
/// </summary>
public static EquipStatsDouble operator /(EquipStatsDouble a, EquipStats b)
{
return new EquipStatsDouble(a.VIT / b.VIT, a.STR / b.STR, a.DEX / b.DEX, a.TEC / b.TEC, a.MAG / b.MAG, a.FTH / b.FTH);
}

/// <summary>
/// Creates a new EquipStatsDouble by adding a value to all stats.
/// </summary>
public static EquipStatsDouble operator +(EquipStatsDouble a, double b)
{
return new EquipStatsDouble(a.VIT + b, a.STR + b, a.DEX + b, a.TEC + b, a.MAG + b, a.FTH + b);
}

/// <summary>
/// Creates a new EquipStatsDouble by subtracting a value from all stats.
/// </summary>
public static EquipStatsDouble operator -(EquipStatsDouble a, double b)
{
return new EquipStatsDouble(a.VIT - b, a.STR - b, a.DEX - b, a.TEC - b, a.MAG - b, a.FTH - b);
}

/// <summary>
/// Creates a new EquipStatsDouble by multiplying all stats by a value.
/// </summary>
public static EquipStatsDouble operator *(EquipStatsDouble a, double b)
{
return new EquipStatsDouble(a.VIT * b, a.STR * b, a.DEX * b, a.TEC * b, a.MAG * b, a.FTH * b);
}

/// <summary>
/// Creates a new EquipStatsDouble by dividing all stats by a value.
/// </summary>
public static EquipStatsDouble operator /(EquipStatsDouble a, double b)
{
return new EquipStats((int)(a.VIT / b), (int)(a.STR / b), (int)(a.DEX / b), (int)(a.TEC / b), (int)(a.MAG / b), (int)(a.FTH / b));
return new EquipStatsDouble(a.VIT / b, a.STR / b, a.DEX / b, a.TEC / b, a.MAG / b, a.FTH / b);
}
}
}
10 changes: 5 additions & 5 deletions API/GadgetCoreAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class GadgetCoreAPI
/// <summary>
/// A slightly more informative version. You generally shouldn't access this directly, instead use <see cref="GetFullVersion()"/>
/// </summary>
public const string FULL_VERSION = "2.0.0.0-BETA9";
public const string FULL_VERSION = "2.0.0.0-BETA10";
/// <summary>
/// Indicates whether this version of GadgetCore is a beta version. You generally shouldn't access this directly, instead use <see cref="GetIsBeta()"/>
/// </summary>
Expand Down Expand Up @@ -776,10 +776,10 @@ public static EquipStats GetGearStats(Item item)
for (int i = 0; i < item.aspect.Length; i++)
{
ItemInfo gearMod = ItemRegistry.GetSingleton().GetEntry(item.aspect[i]);
if (gearMod == null) continue;
if (gearMod == null && (item.aspect[i] < 201 || item.aspect[i] > 206)) continue;
for (int j = 0; j < 6; j++)
{
if (gearMod != null)
if (gearMod != null && !(gearMod is VanillaItemInfo))
{
stats.AddByIndex(j, gearMod.Stats.GetByIndex(j));
}
Expand Down Expand Up @@ -830,7 +830,7 @@ public static EquipStats GetGearStats(Item item)
{
foreach (Tuple<StatModifier, int> modifier in statModifiers[StatModifierType.LevelExpMult])
{
EquipStats multiplier = modifier.Item1(item);
EquipStatsDouble multiplier = modifier.Item1(item);
for (int i = 0;i < level;i++) stats *= multiplier;
}
}
Expand Down Expand Up @@ -885,7 +885,7 @@ internal static void UnregisterStatModifiers(int modID)
/// Delegate used for stat modifiers.
/// </summary>
/// <param name="item">The item who's stats are being modified.</param>
public delegate EquipStats StatModifier(Item item);
public delegate EquipStatsDouble StatModifier(Item item);

/// <summary>
/// Use to check if there is a resource registered at the specified path. This includes resources registered by the base game.
Expand Down
Binary file modified Release/GadgetCore.dll
Binary file not shown.
Loading

0 comments on commit 6ae3782

Please sign in to comment.