Precompute base progress/quality increases

This commit is contained in:
Asriel Camora
2023-06-20 17:07:16 -07:00
parent 1d0d4cf8ce
commit cdd4f5923e
8 changed files with 55 additions and 38 deletions
+6 -6
View File
@@ -13,10 +13,9 @@ internal static class Program
//TypeLayout.PrintLayout<Solver.Crafty.SimulationNode>(true); //TypeLayout.PrintLayout<Solver.Crafty.SimulationNode>(true);
//return; //return;
var input = new SimulationInput() var input = new SimulationInput(
{ new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90 },
Stats = new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90 }, new RecipeInfo()
Recipe = new RecipeInfo()
{ {
IsExpert = false, IsExpert = false,
ClassJobLevel = 90, ClassJobLevel = 90,
@@ -29,8 +28,9 @@ internal static class Program
QualityDivider = 115, QualityDivider = 115,
ProgressModifier = 80, ProgressModifier = 80,
ProgressDivider = 130, ProgressDivider = 130,
} },
}; 0
);
var actions = new List<ActionType>(); var actions = new List<ActionType>();
var s = Stopwatch.StartNew(); var s = Stopwatch.StartNew();
+5 -5
View File
@@ -26,11 +26,11 @@ public class SimulatorWindow : Window
MaximumSize = new Vector2(float.MaxValue, float.MaxValue) MaximumSize = new Vector2(float.MaxValue, float.MaxValue)
}; };
State = new(new() State = new(new(
{ new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90, CLvl = CalculateCLvl(90) },
Stats = new CharacterStats { Craftsmanship = 4041, Control = 3905, CP = 609, Level = 90, CLvl = CalculateCLvl(90) }, CreateRecipeInfo(LuminaSheets.RecipeSheet.GetRow(35499)!),
Recipe = CreateRecipeInfo(LuminaSheets.RecipeSheet.GetRow(35499)!) 0
}); ));
Simulation = new(State); Simulation = new(State);
} }
+1 -7
View File
@@ -6,17 +6,11 @@ internal abstract class BaseBuffAction : BaseAction
{ {
public abstract EffectType Effect { get; } public abstract EffectType Effect { get; }
public virtual byte Duration => 1; public virtual byte Duration => 1;
public virtual EffectType[] ConflictingEffects => Array.Empty<EffectType>();
public override int DurabilityCost => 0; public override int DurabilityCost => 0;
public override void UseSuccess() public override void UseSuccess() =>
{
if (ConflictingEffects.Length != 0)
foreach(var effect in ConflictingEffects)
Simulation.RemoveEffect(effect);
Simulation.AddEffect(Effect, Duration); Simulation.AddEffect(Effect, Duration);
}
public override string GetTooltip(bool addUsability) public override string GetTooltip(bool addUsability)
{ {
+6 -1
View File
@@ -10,5 +10,10 @@ internal sealed class WasteNot : BaseBuffAction
public override EffectType Effect => EffectType.WasteNot; public override EffectType Effect => EffectType.WasteNot;
public override byte Duration => 4; public override byte Duration => 4;
public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot2 };
public override void UseSuccess()
{
base.UseSuccess();
Simulation.RemoveEffect(EffectType.WasteNot2);
}
} }
+6 -1
View File
@@ -10,5 +10,10 @@ internal sealed class WasteNot2 : BaseBuffAction
public override EffectType Effect => EffectType.WasteNot2; public override EffectType Effect => EffectType.WasteNot2;
public override byte Duration => 8; public override byte Duration => 8;
public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot };
public override void UseSuccess()
{
base.UseSuccess();
Simulation.RemoveEffect(EffectType.WasteNot);
}
} }
+27 -3
View File
@@ -2,9 +2,33 @@ namespace Craftimizer.Simulator;
public readonly record struct SimulationInput public readonly record struct SimulationInput
{ {
public CharacterStats Stats { get; init; } public CharacterStats Stats { get; }
public RecipeInfo Recipe { get; init; } public RecipeInfo Recipe { get; }
public Random Random { get; init; } public Random Random { get; }
public int BaseProgressGain { get; }
public int BaseQualityGain { get; }
public SimulationInput(CharacterStats stats, RecipeInfo recipe, int seed)
{
Stats = stats;
Recipe = recipe;
Random = new Random(seed);
// https://github.com/NotRanged/NotRanged.github.io/blob/0f4aee074f969fb05aad34feaba605057c08ffd1/app/js/ffxivcraftmodel.js#L88
{
var baseIncrease = (Stats.Craftsmanship * 10f / Recipe.ProgressDivider) + 2;
if (Stats.CLvl <= Recipe.RLvl)
baseIncrease *= Recipe.ProgressModifier / 100f;
BaseProgressGain = (int)baseIncrease;
}
{
var baseIncrease = (Stats.Control * 10f / Recipe.QualityDivider) + 35;
if (Stats.CLvl <= Recipe.RLvl)
baseIncrease *= Recipe.QualityModifier / 100f;
BaseQualityGain = (int)baseIncrease;
}
}
public Condition[] AvailableConditions => ConditionUtils.GetPossibleConditions(Recipe.ConditionsFlag); public Condition[] AvailableConditions => ConditionUtils.GetPossibleConditions(Recipe.ConditionsFlag);
} }
+2 -13
View File
@@ -233,13 +233,7 @@ public class Simulator
_ => 1.00f _ => 1.00f
}; };
// https://github.com/NotRanged/NotRanged.github.io/blob/0f4aee074f969fb05aad34feaba605057c08ffd1/app/js/ffxivcraftmodel.js#L88 var progressGain = (int)(Input.BaseProgressGain * efficiency * conditionModifier * buffModifier);
var baseIncrease = (Input.Stats.Craftsmanship * 10f / Input.Recipe.ProgressDivider) + 2;
if (Input.Stats.CLvl <= Input.Recipe.RLvl)
baseIncrease *= Input.Recipe.ProgressModifier / 100f;
baseIncrease = MathF.Floor(baseIncrease);
var progressGain = (int)(baseIncrease * efficiency * conditionModifier * buffModifier);
return progressGain; return progressGain;
} }
@@ -265,12 +259,7 @@ public class Simulator
_ => 1.00f, _ => 1.00f,
}; };
var baseIncrease = (Input.Stats.Control * 10f / Input.Recipe.QualityDivider) + 35; var qualityGain = (int)(Input.BaseQualityGain * efficiency * conditionModifier * buffModifier);
if (Input.Stats.CLvl <= Input.Recipe.RLvl)
baseIncrease *= Input.Recipe.QualityModifier / 100f;
baseIncrease = MathF.Floor(baseIncrease);
var qualityGain = (int)(baseIncrease * efficiency * conditionModifier * buffModifier);
return qualityGain; return qualityGain;
} }
+2 -2
View File
@@ -324,7 +324,7 @@ public class Solver
return (actions, state); return (actions, state);
} }
Debugger.Break(); //Debugger.Break();
var solver = new Solver(state, true); var solver = new Solver(state, true);
while (!solver.Simulator.IsComplete) while (!solver.Simulator.IsComplete)
{ {
@@ -344,7 +344,7 @@ public class Solver
solver = new Solver(state, true); solver = new Solver(state, true);
} }
Debugger.Break(); //Debugger.Break();
return (actions, state); return (actions, state);
} }