Customizable solver config, remove simulator emplace/displace methods
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Craftimizer.Simulator.Actions;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct ActionStates
|
||||
{
|
||||
public byte TouchComboIdx;
|
||||
|
||||
@@ -46,7 +46,7 @@ public static class ActionUtils
|
||||
var types = typeof(BaseAction).Assembly.GetTypes()
|
||||
.Where(t => t.IsAssignableTo(typeof(BaseAction)) && !t.IsAbstract);
|
||||
Actions = Enum.GetNames<ActionType>()
|
||||
.Select(a => types.First(t => t.Name == a))
|
||||
.Select(a => types.First(t => t.Name.Equals(a, StringComparison.Ordinal)))
|
||||
.Select(t => (Activator.CreateInstance(t) as BaseAction)!)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct Effects
|
||||
{
|
||||
public byte InnerQuiet;
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
public readonly struct SimulationState
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
public struct SimulationState
|
||||
{
|
||||
public SimulationInput Input { get; init; }
|
||||
public readonly SimulationInput Input;
|
||||
|
||||
public int ActionCount { get; init; }
|
||||
public int StepCount { get; init; }
|
||||
public int Progress { get; init; }
|
||||
public int Quality { get; init; }
|
||||
public int Durability { get; init; }
|
||||
public int CP { get; init; }
|
||||
public Condition Condition { get; init; }
|
||||
public Effects ActiveEffects { get; init; }
|
||||
public ActionStates ActionStates { get; init; }
|
||||
public int ActionCount;
|
||||
public int StepCount;
|
||||
public int Progress;
|
||||
public int Quality;
|
||||
public int Durability;
|
||||
public int CP;
|
||||
public Condition Condition;
|
||||
public Effects ActiveEffects;
|
||||
public ActionStates ActionStates;
|
||||
|
||||
// https://github.com/ffxiv-teamcraft/simulator/blob/0682dfa76043ff4ccb38832c184d046ceaff0733/src/model/tables.ts#L2
|
||||
private static readonly int[] HQPercentTable = {
|
||||
@@ -21,9 +24,9 @@ public readonly struct SimulationState
|
||||
17, 18, 18, 18, 19, 19, 20, 20, 21, 22, 23, 24, 26, 28, 31, 34, 38, 42, 47, 52, 58, 64, 68, 71,
|
||||
74, 76, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 94, 96, 98, 100
|
||||
};
|
||||
public int HQPercent => HQPercentTable[(int)Math.Clamp((float)Quality / Input.Recipe.MaxQuality * 100, 0, 100)];
|
||||
public readonly int HQPercent => HQPercentTable[(int)Math.Clamp((float)Quality / Input.Recipe.MaxQuality * 100, 0, 100)];
|
||||
|
||||
public bool IsFirstStep => StepCount == 0;
|
||||
public readonly bool IsFirstStep => StepCount == 0;
|
||||
|
||||
public SimulationState(SimulationInput input)
|
||||
{
|
||||
|
||||
+16
-44
@@ -4,18 +4,20 @@ namespace Craftimizer.Simulator;
|
||||
|
||||
public class Simulator
|
||||
{
|
||||
public SimulationInput Input { get; private set; }
|
||||
public int ActionCount { get; private set; }
|
||||
public int StepCount { get; private set; }
|
||||
public int Progress { get; private set; }
|
||||
public int Quality { get; private set; }
|
||||
public int Durability { get; private set; }
|
||||
public int CP { get; private set; }
|
||||
public Condition Condition { get; private set; }
|
||||
public Effects ActiveEffects;
|
||||
public ActionStates ActionStates;
|
||||
protected SimulationState State;
|
||||
|
||||
public bool IsFirstStep => StepCount == 0;
|
||||
public SimulationInput Input => State.Input;
|
||||
public ref int ActionCount => ref State.ActionCount;
|
||||
public ref int StepCount => ref State.StepCount;
|
||||
public ref int Progress => ref State.Progress;
|
||||
public ref int Quality => ref State.Quality;
|
||||
public ref int Durability => ref State.Durability;
|
||||
public ref int CP => ref State.CP;
|
||||
public ref Condition Condition => ref State.Condition;
|
||||
public ref Effects ActiveEffects => ref State.ActiveEffects;
|
||||
public ref ActionStates ActionStates => ref State.ActionStates;
|
||||
|
||||
public bool IsFirstStep => State.StepCount == 0;
|
||||
|
||||
public CompletionState CompletionState
|
||||
{
|
||||
@@ -32,45 +34,15 @@ public class Simulator
|
||||
|
||||
public IEnumerable<ActionType> AvailableActions => ActionUtils.AvailableActions(this);
|
||||
|
||||
#pragma warning disable CS8618 // Emplace sets all the fields already
|
||||
public Simulator(SimulationState state)
|
||||
#pragma warning restore CS8618
|
||||
{
|
||||
Emplace(state);
|
||||
State = state;
|
||||
}
|
||||
|
||||
private void Emplace(SimulationState state)
|
||||
{
|
||||
Input = state.Input;
|
||||
ActionCount = state.ActionCount;
|
||||
StepCount = state.StepCount;
|
||||
Progress = state.Progress;
|
||||
Quality = state.Quality;
|
||||
Durability = state.Durability;
|
||||
CP = state.CP;
|
||||
Condition = state.Condition;
|
||||
ActiveEffects = state.ActiveEffects;
|
||||
ActionStates = state.ActionStates;
|
||||
}
|
||||
|
||||
private SimulationState Displace() => new()
|
||||
{
|
||||
Input = Input,
|
||||
ActionCount = ActionCount,
|
||||
StepCount = StepCount,
|
||||
Progress = Progress,
|
||||
Quality = Quality,
|
||||
Durability = Durability,
|
||||
CP = CP,
|
||||
Condition = Condition,
|
||||
ActiveEffects = ActiveEffects,
|
||||
ActionStates = ActionStates,
|
||||
};
|
||||
|
||||
public (ActionResponse Response, SimulationState NewState) Execute(SimulationState state, ActionType action)
|
||||
{
|
||||
Emplace(state);
|
||||
return (Execute(action), Displace());
|
||||
State = state;
|
||||
return (Execute(action), State);
|
||||
}
|
||||
|
||||
private ActionResponse Execute(ActionType action)
|
||||
|
||||
Reference in New Issue
Block a user