fix to be identical to crafty, remove debugs
This commit is contained in:
@@ -32,14 +32,17 @@ public abstract class BaseAction
|
||||
|
||||
public virtual void Use()
|
||||
{
|
||||
if (Simulation.RollSuccess(SuccessRate))
|
||||
UseSuccess();
|
||||
|
||||
Simulation.ReduceCP(CPCost);
|
||||
Simulation.ReduceDurability(DurabilityCost);
|
||||
|
||||
if (Simulation.HasEffect(EffectType.Manipulation))
|
||||
Simulation.RestoreDurability(5);
|
||||
|
||||
if (Simulation.RollSuccess(SuccessRate))
|
||||
UseSuccess();
|
||||
if (Simulation.Durability > 0)
|
||||
{
|
||||
if (Simulation.HasEffect(EffectType.Manipulation))
|
||||
Simulation.RestoreDurability(5);
|
||||
}
|
||||
|
||||
if (IncreasesStepCount)
|
||||
Simulation.IncreaseStepCount();
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace Craftimizer.Simulator.Actions;
|
||||
|
||||
internal abstract class BaseBuffAction : BaseAction
|
||||
{
|
||||
public abstract Effect Effect { get; }
|
||||
public abstract EffectType Effect { get; }
|
||||
public virtual byte Duration => 1;
|
||||
public virtual EffectType[] ConflictingEffects => Array.Empty<EffectType>();
|
||||
|
||||
public override int DurabilityCost => 0;
|
||||
@@ -14,13 +15,13 @@ internal abstract class BaseBuffAction : BaseAction
|
||||
if (ConflictingEffects.Length != 0)
|
||||
foreach(var effect in ConflictingEffects)
|
||||
Simulation.RemoveEffect(effect);
|
||||
Simulation.AddEffect(Effect.Type, Effect.Duration, Effect.Strength);
|
||||
Simulation.AddEffect(Effect, Duration);
|
||||
}
|
||||
|
||||
public override string GetTooltip(bool addUsability)
|
||||
{
|
||||
var builder = new StringBuilder(base.GetTooltip(addUsability));
|
||||
builder.AppendLine($"{Effect.Duration} Steps");
|
||||
builder.AppendLine($"{Duration} Steps");
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ internal class ByregotsBlessing : BaseAction
|
||||
public override uint ActionId => 100339;
|
||||
|
||||
public override int CPCost => 24;
|
||||
public override float Efficiency => 1.00f + (0.20f * (Simulation.GetEffect(EffectType.InnerQuiet)?.Strength ?? 0));
|
||||
public override float Efficiency => 1.00f + (0.20f * Simulation.GetEffectStrength(EffectType.InnerQuiet));
|
||||
public override bool IncreasesQuality => true;
|
||||
|
||||
public override bool CanUse => Simulation.HasEffect(EffectType.InnerQuiet) && base.CanUse;
|
||||
|
||||
@@ -9,5 +9,6 @@ internal class FinalAppraisal : BaseBuffAction
|
||||
public override int CPCost => 1;
|
||||
public override bool IncreasesStepCount => false;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.FinalAppraisal, Duration = 5 };
|
||||
public override EffectType Effect => EffectType.FinalAppraisal;
|
||||
public override byte Duration => 5;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ internal class GreatStrides : BaseBuffAction
|
||||
|
||||
public override int CPCost => 32;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.GreatStrides, Duration = 3 };
|
||||
public override EffectType Effect => EffectType.GreatStrides;
|
||||
public override byte Duration => 3;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ internal class Groundwork : BaseAction
|
||||
get
|
||||
{
|
||||
var ret = Simulation.Input.Stats.Level >= 86 ? 3.60f : 3.00f;
|
||||
// TODO: does not account for waste not
|
||||
return Simulation.Durability < DurabilityCost ? ret / 2 : ret;
|
||||
return Simulation.Durability < Simulation.CalculateDurabilityCost(DurabilityCost) ? ret / 2 : ret;
|
||||
}
|
||||
}
|
||||
public override bool IncreasesProgress => true;
|
||||
|
||||
@@ -9,7 +9,7 @@ internal class HeartAndSoul : BaseBuffAction
|
||||
public override int CPCost => 0;
|
||||
public override bool IncreasesStepCount => false;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.HeartAndSoul };
|
||||
public override EffectType Effect => EffectType.HeartAndSoul;
|
||||
|
||||
public override bool CanUse => Simulation.Input.Stats.IsSpecialist && Simulation.CountPreviousAction(ActionType.HeartAndSoul) == 0;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ internal class Innovation : BaseBuffAction
|
||||
|
||||
public override int CPCost => 18;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.Innovation, Duration = 4 };
|
||||
public override EffectType Effect => EffectType.Innovation;
|
||||
public override byte Duration => 4;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,19 @@ internal class Manipulation : BaseBuffAction
|
||||
|
||||
public override int CPCost => 96;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.Manipulation, Duration = 8 };
|
||||
public override EffectType Effect => EffectType.Manipulation;
|
||||
public override byte Duration => 8;
|
||||
|
||||
public override void Use()
|
||||
{
|
||||
if (Simulation.HasEffect(EffectType.Manipulation))
|
||||
Simulation.RestoreDurability(5);
|
||||
|
||||
Simulation.ReduceCP(CPCost);
|
||||
Simulation.ReduceDurability(DurabilityCost);
|
||||
|
||||
UseSuccess();
|
||||
|
||||
Simulation.IncreaseStepCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ internal class TrainedFinesse : BaseAction
|
||||
public override int DurabilityCost => 0;
|
||||
|
||||
public override bool CanUse =>
|
||||
(Simulation.GetEffect(EffectType.InnerQuiet)?.Strength ?? 0) == 10
|
||||
Simulation.GetEffectStrength(EffectType.InnerQuiet) == 10
|
||||
&& base.CanUse;
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@ internal class Veneration : BaseBuffAction
|
||||
public override int CPCost => 18;
|
||||
public override int DurabilityCost => 0;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.Veneration, Duration = 4 };
|
||||
public override EffectType Effect => EffectType.Veneration;
|
||||
public override byte Duration => 4;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ internal class WasteNot : BaseBuffAction
|
||||
|
||||
public override int CPCost => 56;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.WasteNot, Duration = 4 };
|
||||
public override EffectType Effect => EffectType.WasteNot;
|
||||
public override byte Duration => 4;
|
||||
public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot2 };
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ internal class WasteNot2 : BaseBuffAction
|
||||
|
||||
public override int CPCost => 98;
|
||||
|
||||
public override Effect Effect => new() { Type = EffectType.WasteNot2, Duration = 8 };
|
||||
public override EffectType Effect => EffectType.WasteNot2;
|
||||
public override byte Duration => 8;
|
||||
public override EffectType[] ConflictingEffects => new[] { EffectType.WasteNot };
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
public readonly record struct Effect
|
||||
{
|
||||
public EffectType Type { get; init; }
|
||||
public int? Duration { get; init; }
|
||||
public int? Strength { get; init; }
|
||||
|
||||
public bool HasDuration => Duration != null;
|
||||
public bool HasStrength => Strength != null;
|
||||
|
||||
public Effect DecrementDuration() => this with { Duration = Duration - 1 };
|
||||
public Effect IncrementStrength() => this with { Strength = Strength + 1 };
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
public record struct Effects
|
||||
{
|
||||
public byte InnerQuiet { get; set; }
|
||||
public byte WasteNot { get; set; }
|
||||
public byte Veneration { get; set; }
|
||||
public byte GreatStrides { get; set; }
|
||||
public byte Innovation { get; set; }
|
||||
public byte FinalAppraisal { get; set; }
|
||||
public byte WasteNot2 { get; set; }
|
||||
public byte MuscleMemory { get; set; }
|
||||
public byte Manipulation { get; set; }
|
||||
public bool HeartAndSoul { get; set; }
|
||||
|
||||
public void SetDuration(EffectType effect, byte duration)
|
||||
{
|
||||
switch (effect)
|
||||
{
|
||||
case EffectType.InnerQuiet:
|
||||
if (duration == 0)
|
||||
InnerQuiet = 0;
|
||||
break;
|
||||
case EffectType.WasteNot:
|
||||
WasteNot = duration;
|
||||
break;
|
||||
case EffectType.Veneration:
|
||||
Veneration = duration;
|
||||
break;
|
||||
case EffectType.GreatStrides:
|
||||
GreatStrides = duration;
|
||||
break;
|
||||
case EffectType.Innovation:
|
||||
Innovation = duration;
|
||||
break;
|
||||
case EffectType.FinalAppraisal:
|
||||
FinalAppraisal = duration;
|
||||
break;
|
||||
case EffectType.WasteNot2:
|
||||
WasteNot2 = duration;
|
||||
break;
|
||||
case EffectType.MuscleMemory:
|
||||
MuscleMemory = duration;
|
||||
break;
|
||||
case EffectType.Manipulation:
|
||||
Manipulation = duration;
|
||||
break;
|
||||
case EffectType.HeartAndSoul:
|
||||
HeartAndSoul = duration != 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Strengthen(EffectType effect)
|
||||
{
|
||||
if (effect == EffectType.InnerQuiet && InnerQuiet < 10)
|
||||
InnerQuiet++;
|
||||
}
|
||||
|
||||
public byte GetDuration(EffectType effect) =>
|
||||
effect switch
|
||||
{
|
||||
EffectType.InnerQuiet => (byte)(InnerQuiet != 0 ? 1 : 0),
|
||||
EffectType.WasteNot => WasteNot,
|
||||
EffectType.Veneration => Veneration,
|
||||
EffectType.GreatStrides => GreatStrides,
|
||||
EffectType.Innovation => Innovation,
|
||||
EffectType.FinalAppraisal => FinalAppraisal,
|
||||
EffectType.WasteNot2 => WasteNot2,
|
||||
EffectType.MuscleMemory => MuscleMemory,
|
||||
EffectType.Manipulation => Manipulation,
|
||||
EffectType.HeartAndSoul => (byte)(HeartAndSoul ? 1 : 0),
|
||||
_ => 0
|
||||
};
|
||||
|
||||
public byte GetStrength(EffectType effect) =>
|
||||
effect == EffectType.InnerQuiet ? InnerQuiet :
|
||||
(byte)(GetDuration(effect) != 0 ? 1 : 0);
|
||||
|
||||
public bool HasEffect(EffectType effect) =>
|
||||
GetDuration(effect) != 0;
|
||||
|
||||
public void DecrementDuration()
|
||||
{
|
||||
if (WasteNot > 0)
|
||||
WasteNot--;
|
||||
if (WasteNot2 > 0)
|
||||
WasteNot2--;
|
||||
if (Veneration > 0)
|
||||
Veneration--;
|
||||
if (GreatStrides > 0)
|
||||
GreatStrides--;
|
||||
if (Innovation > 0)
|
||||
Innovation--;
|
||||
if (FinalAppraisal > 0)
|
||||
FinalAppraisal--;
|
||||
if (MuscleMemory > 0)
|
||||
MuscleMemory--;
|
||||
if (Manipulation > 0)
|
||||
Manipulation--;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using Craftimizer.Simulator.Actions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Craftimizer.Simulator;
|
||||
|
||||
@@ -16,7 +14,7 @@ public readonly record struct SimulationState
|
||||
public int Durability { get; init; }
|
||||
public int CP { get; init; }
|
||||
public Condition Condition { get; init; }
|
||||
public List<Effect> ActiveEffects { get; init; }
|
||||
public Effects ActiveEffects { get; init; }
|
||||
public List<ActionType> ActionHistory { get; init; }
|
||||
|
||||
// https://github.com/ffxiv-teamcraft/simulator/blob/0682dfa76043ff4ccb38832c184d046ceaff0733/src/model/tables.ts#L2
|
||||
|
||||
+17
-49
@@ -11,7 +11,7 @@ public class Simulator
|
||||
public int Durability { get; private set; }
|
||||
public int CP { get; private set; }
|
||||
public Condition Condition { get; private set; }
|
||||
public List<Effect> ActiveEffects { get; private set; }
|
||||
public Effects ActiveEffects;
|
||||
public List<ActionType> ActionHistory { get; private set; }
|
||||
|
||||
public bool IsFirstStep => StepCount == 0;
|
||||
@@ -47,7 +47,7 @@ public class Simulator
|
||||
Durability = state.Durability;
|
||||
CP = state.CP;
|
||||
Condition = state.Condition;
|
||||
ActiveEffects = new(state.ActiveEffects);
|
||||
ActiveEffects = state.ActiveEffects;
|
||||
ActionHistory = new(state.ActionHistory);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Simulator
|
||||
Durability = Durability,
|
||||
CP = CP,
|
||||
Condition = Condition,
|
||||
ActiveEffects = ActiveEffects!,
|
||||
ActiveEffects = ActiveEffects,
|
||||
ActionHistory = ActionHistory!,
|
||||
};
|
||||
|
||||
@@ -88,68 +88,36 @@ public class Simulator
|
||||
baseAction.Use();
|
||||
ActionHistory!.Add(action);
|
||||
|
||||
for (var i = 0; i < ActiveEffects!.Count; ++i)
|
||||
{
|
||||
var effect = ActiveEffects[i].DecrementDuration();
|
||||
if (effect.Duration == 0)
|
||||
{
|
||||
ActiveEffects.RemoveAt(i);
|
||||
--i;
|
||||
}
|
||||
else
|
||||
ActiveEffects[i] = effect;
|
||||
}
|
||||
ActiveEffects.DecrementDuration();
|
||||
|
||||
return ActionResponse.UsedAction;
|
||||
}
|
||||
|
||||
private int GetEffectIdx(EffectType effect) =>
|
||||
ActiveEffects!.FindIndex(e => e.Type == effect);
|
||||
public int GetEffectStrength(EffectType effect) =>
|
||||
ActiveEffects.GetStrength(effect);
|
||||
|
||||
public Effect? GetEffect(EffectType effect)
|
||||
{
|
||||
var idx = GetEffectIdx(effect);
|
||||
return idx == -1 ? null : ActiveEffects![idx];
|
||||
}
|
||||
public int GetEffectDuration(EffectType effect) =>
|
||||
ActiveEffects.GetDuration(effect);
|
||||
|
||||
public void AddEffect(EffectType effect, int? duration = null, int? strength = null)
|
||||
public void AddEffect(EffectType effect, int duration)
|
||||
{
|
||||
if (Condition == Condition.Primed && duration != null)
|
||||
if (Condition == Condition.Primed)
|
||||
duration += 2;
|
||||
|
||||
// Duration will be decreased in the next step, so we need to add 1
|
||||
if (duration != null)
|
||||
duration++;
|
||||
duration++;
|
||||
|
||||
var newEffect = new Effect { Type = effect, Duration = duration, Strength = strength };
|
||||
|
||||
var effectIdx = GetEffectIdx(effect);
|
||||
if (effectIdx != -1)
|
||||
ActiveEffects![effectIdx] = newEffect;
|
||||
else
|
||||
ActiveEffects!.Add(newEffect);
|
||||
ActiveEffects.SetDuration(effect, (byte)duration);
|
||||
}
|
||||
|
||||
public void StrengthenEffect(EffectType effect, int? duration = null)
|
||||
{
|
||||
if (duration != null)
|
||||
duration += 1;
|
||||
|
||||
var effectIdx = GetEffectIdx(effect);
|
||||
if (effectIdx != -1)
|
||||
{
|
||||
if (effect == EffectType.InnerQuiet && ActiveEffects![effectIdx].Strength < 10)
|
||||
ActiveEffects[effectIdx] = ActiveEffects[effectIdx].IncrementStrength();
|
||||
}
|
||||
else
|
||||
ActiveEffects!.Add(new Effect { Type = effect, Duration = duration, Strength = 1 });
|
||||
}
|
||||
public void StrengthenEffect(EffectType effect) =>
|
||||
ActiveEffects.Strengthen(effect);
|
||||
|
||||
public void RemoveEffect(EffectType effect) =>
|
||||
ActiveEffects!.RemoveAll(e => e.Type == effect);
|
||||
ActiveEffects.SetDuration(effect, 0);
|
||||
|
||||
public bool HasEffect(EffectType effect) =>
|
||||
ActiveEffects!.Any(e => e.Type == effect);
|
||||
ActiveEffects.HasEffect(effect);
|
||||
|
||||
public bool IsPreviousAction(ActionType action, int stepsBack = 1) =>
|
||||
ActionHistory!.Count >= stepsBack && ActionHistory[^stepsBack] == action;
|
||||
@@ -287,7 +255,7 @@ public class Simulator
|
||||
if (HasEffect(EffectType.Innovation))
|
||||
buffModifier += 0.50f;
|
||||
|
||||
buffModifier *= 1 + ((GetEffect(EffectType.InnerQuiet)?.Strength ?? 0) * 0.10f);
|
||||
buffModifier *= 1 + (GetEffectStrength(EffectType.InnerQuiet) * 0.10f);
|
||||
|
||||
var conditionModifier = Condition switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user