Finish simulation implementation (?)

This commit is contained in:
Asriel Camora
2023-06-13 16:53:08 -07:00
parent e660ff895e
commit bf645eff67
6 changed files with 62 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
namespace Craftimizer.Simulator;
internal enum ActionCategory
public enum ActionCategory
{
FirstTurn,
Synthesis,
+5 -5
View File
@@ -3,12 +3,12 @@ using Craftimizer.Plugin;
namespace Craftimizer.Simulator;
internal record CharacterStats
public record CharacterStats
{
public int Craftsmanship { get; }
public int Control { get; }
public int CP { get; }
public int Level { get; }
public int Craftsmanship { get; init; }
public int Control { get; init; }
public int CP { get; init; }
public int Level { get; init; }
public int CLvl => Level <= 80
? LuminaSheets.ParamGrowSheet.GetRow((uint)Level)!.CraftingLevel
@@ -0,0 +1,7 @@
namespace Craftimizer.Simulator;
public enum CompletionReason
{
ProgressComplete,
NoMoreDurability
}
+1 -1
View File
@@ -1,6 +1,6 @@
namespace Craftimizer.Simulator;
internal enum Condition
public enum Condition
{
Poor,
Normal,
+1 -1
View File
@@ -1,6 +1,6 @@
namespace Craftimizer.Simulator;
internal enum Effect
public enum Effect
{
InnerQuiet,
WasteNot,
+47 -1
View File
@@ -5,13 +5,17 @@ using System.Collections.Generic;
namespace Craftimizer.Simulator;
internal class Simulation
public class Simulation
{
public CharacterStats Stats { get; }
public Recipe Recipe { get; }
public RecipeLevelTable RecipeTable => Recipe.RecipeLevelTable.Value!;
public int RLvl => (int)RecipeTable.RowId;
public int MaxDurability => RecipeTable.Durability * Recipe.DurabilityFactor;
public int MaxQuality => (int)RecipeTable.Quality * Recipe.QualityFactor;
public int MaxProgress => RecipeTable.Difficulty * Recipe.DifficultyFactor;
public int StepCount => ActionHistory.Count;
public int Progress { get; private set; }
public int Quality { get; private set; }
@@ -29,8 +33,44 @@ internal class Simulation
{
Stats = stats;
Recipe = recipe;
Progress = 0;
Quality = 0;
Durability = MaxDurability;
CP = Stats.CP;
Condition = Condition.Normal;
}
public CompletionReason? Execute(BaseAction action)
{
if (!action.CanUse)
return null;
action.Use();
ActionHistory.Add(action);
for (var i = 0; i < ActiveEffects.Count; ++i)
{
var (effect, strength, stepsLeft) = ActiveEffects[i];
if (stepsLeft == 1)
{
ActiveEffects.RemoveAt(i);
--i;
}
else
ActiveEffects[i] = (effect, strength, stepsLeft - 1);
}
if (Progress >= MaxProgress)
return CompletionReason.ProgressComplete;
if (Durability <= 0)
return CompletionReason.NoMoreDurability;
return null;
}
public CompletionReason? Execute<T>() where T : BaseAction =>
Execute((T)Activator.CreateInstance(typeof(T), this)!);
public (int Strength, int Duration)? GetEffect(Effect effect)
{
var idx = ActiveEffects.FindIndex(x => x.effect == effect);
@@ -116,6 +156,12 @@ internal class Simulation
baseIncrease *= RecipeTable.ProgressModifier / 100;
Progress += (int)(baseIncrease * efficiency);
if (HasEffect(Effect.FinalAppraisal) && Progress >= MaxProgress)
{
Progress = MaxProgress - 1;
RemoveEffect(Effect.FinalAppraisal);
}
}
public void IncreaseQuality(float efficiency)