Skip to content

Commit

Permalink
Fix specialist bug when having no delineations
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Aug 6, 2024
1 parent fa45ac0 commit d488b9e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
9 changes: 4 additions & 5 deletions Craftimizer/Utils/Gearsets.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Craftimizer.Simulator;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
Expand Down Expand Up @@ -98,10 +97,10 @@ public static GearsetStats CalculateGearsetCurrentStats()
};
}

public static CharacterStats CalculateCharacterStats(GearsetItem[] gearsetItems, int characterLevel, bool canUseManipulation, bool checkDelineations) =>
CalculateCharacterStats(CalculateGearsetStats(gearsetItems), gearsetItems, characterLevel, canUseManipulation, checkDelineations);
public static CharacterStats CalculateCharacterStats(GearsetItem[] gearsetItems, int characterLevel, bool canUseManipulation) =>
CalculateCharacterStats(CalculateGearsetStats(gearsetItems), gearsetItems, characterLevel, canUseManipulation);

public static CharacterStats CalculateCharacterStats(GearsetStats gearsetStats, GearsetItem[] gearsetItems, int characterLevel, bool canUseManipulation, bool checkDelineations) =>
public static CharacterStats CalculateCharacterStats(GearsetStats gearsetStats, GearsetItem[] gearsetItems, int characterLevel, bool canUseManipulation) =>
new()
{
CP = gearsetStats.CP,
Expand All @@ -110,7 +109,7 @@ public static CharacterStats CalculateCharacterStats(GearsetStats gearsetStats,
Level = characterLevel,
CanUseManipulation = canUseManipulation,
HasSplendorousBuff = gearsetItems.Any(IsSplendorousTool),
IsSpecialist = gearsetItems.Any(IsSpecialistSoulCrystal) && (!checkDelineations || HasDelineations()),
IsSpecialist = gearsetItems.Any(IsSpecialistSoulCrystal),
};

public static bool HasDelineations() =>
Expand Down
7 changes: 5 additions & 2 deletions Craftimizer/Windows/MacroEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,13 +1535,16 @@ private void CalculateBestMacro()
SolverStartStepCount = Macro.Count;

var state = State;
SolverTask = new(token => CalculateBestMacroTask(state, token));
SolverTask = new(token => CalculateBestMacroTask(state, token, Gearsets.HasDelineations()));
SolverTask.Start();
}

private int CalculateBestMacroTask(SimulationState state, CancellationToken token)
private int CalculateBestMacroTask(SimulationState state, CancellationToken token, bool hasDelineations)
{
var config = Service.Configuration.EditorSolverConfig;
var canUseDelineations = !Service.Configuration.CheckDelineations || hasDelineations;
if (!canUseDelineations)
config = config.FilterSpecialistActions();

token.ThrowIfCancellationRequested();

Expand Down
14 changes: 13 additions & 1 deletion Craftimizer/Windows/RecipeNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private bool CalculateShouldOpen()

gearItems = Gearsets.GetGearsetItems(container);

var characterStats = Gearsets.CalculateCharacterStats(gearStats, gearItems, RecipeData.ClassJob.GetPlayerLevel(), RecipeData.ClassJob.CanPlayerUseManipulation(), Service.Configuration.CheckDelineations);
var characterStats = Gearsets.CalculateCharacterStats(gearStats, gearItems, RecipeData.ClassJob.GetPlayerLevel(), RecipeData.ClassJob.CanPlayerUseManipulation());
if (characterStats != CharacterStats)
{
CharacterStats = characterStats;
Expand Down Expand Up @@ -1140,11 +1140,15 @@ private static string ResolveNpcResidentName(uint npcRowId)
private void CalculateSavedMacro()
{
SavedMacroTask?.Cancel();
var hasDelineations = Gearsets.HasDelineations();
SavedMacroTask = new(token =>
{
var input = new SimulationInput(CharacterStats!, RecipeData!.RecipeInfo, StartingQuality);
var state = new SimulationState(input);
var config = Service.Configuration.RecipeNoteSolverConfig;
var canUseDelineations = !Service.Configuration.CheckDelineations || hasDelineations;
if (!canUseDelineations)
config = config.FilterSpecialistActions();
var mctsConfig = new MCTSConfig(config);
var simulator = new SimulatorNoRandom();
List<Macro> macros = new(Service.Configuration.Macros);
Expand All @@ -1171,11 +1175,15 @@ private void CalculateSavedMacro()
private void CalculateSuggestedMacro()
{
SuggestedMacroTask?.Cancel();
var hasDelineations = Gearsets.HasDelineations();
SuggestedMacroTask = new(token =>
{
var input = new SimulationInput(CharacterStats!, RecipeData!.RecipeInfo, StartingQuality);
var state = new SimulationState(input);
var config = Service.Configuration.RecipeNoteSolverConfig;
var canUseDelineations = !Service.Configuration.CheckDelineations || hasDelineations;
if (!canUseDelineations)
config = config.FilterSpecialistActions();

token.ThrowIfCancellationRequested();

Expand All @@ -1195,11 +1203,15 @@ private void CalculateSuggestedMacro()
public void CalculateCommunityMacro()
{
CommunityMacroTask?.Cancel();
var hasDelineations = Gearsets.HasDelineations();
CommunityMacroTask = new(token =>
{
var input = new SimulationInput(CharacterStats!, RecipeData!.RecipeInfo, StartingQuality);
var state = new SimulationState(input);
var config = Service.Configuration.RecipeNoteSolverConfig;
var canUseDelineations = !Service.Configuration.CheckDelineations || hasDelineations;
if (!canUseDelineations)
config = config.FilterSpecialistActions();
var mctsConfig = new MCTSConfig(config);
var simulator = new SimulatorNoRandom();
var macros = Service.CommunityMacros.RetrieveRotations((int)RecipeData.Table.RowId, token).GetAwaiter().GetResult();
Expand Down
2 changes: 1 addition & 1 deletion Craftimizer/Windows/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ ref isDirty
DrawOption(
"Check For Delineations",
"Your inventory will be checked to ensure that you have delineations available " +
"before suggesting any specialist acitons.",
"before suggesting any specialist actions.",
Config.CheckDelineations,
v => Config.CheckDelineations = v,
ref isDirty
Expand Down
9 changes: 6 additions & 3 deletions Craftimizer/Windows/SynthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private void OnStartCrafting(ushort recipeId)

var gearItems = Gearsets.GetGearsetItems(container);

var characterStats = Gearsets.CalculateCharacterStats(gearStats, gearItems, RecipeData.ClassJob.GetPlayerLevel(), RecipeData.ClassJob.CanPlayerUseManipulation(), Service.Configuration.CheckDelineations);
var characterStats = Gearsets.CalculateCharacterStats(gearStats, gearItems, RecipeData.ClassJob.GetPlayerLevel(), RecipeData.ClassJob.CanPlayerUseManipulation());
if (characterStats != CharacterStats)
{
CharacterStats = characterStats;
Expand Down Expand Up @@ -596,13 +596,16 @@ private void CalculateBestMacro()
}

var state = CurrentState;
SolverTask = new(token => CalculateBestMacroTask(state, token));
SolverTask = new(token => CalculateBestMacroTask(state, token, Gearsets.HasDelineations()));
SolverTask.Start();
}

private int CalculateBestMacroTask(SimulationState state, CancellationToken token)
private int CalculateBestMacroTask(SimulationState state, CancellationToken token, bool hasDelineations)
{
var config = Service.Configuration.SynthHelperSolverConfig;
var canUseDelineations = !Service.Configuration.CheckDelineations || hasDelineations;
if (!canUseDelineations)
config = config.FilterSpecialistActions();

token.ThrowIfCancellationRequested();

Expand Down
11 changes: 11 additions & 0 deletions Solver/SolverConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public SolverConfig()
public static ActionType[] OptimizeActionPool(IEnumerable<ActionType> actions) =>
[.. actions.Order()];

public SolverConfig FilterSpecialistActions() =>
this with { ActionPool = ActionPool.Where(action => !SpecialistActions.Contains(action)).ToArray() };

public static readonly ActionType[] DeterministicActionPool = OptimizeActionPool(new[]
{
ActionType.MuscleMemory,
Expand Down Expand Up @@ -167,6 +170,14 @@ public static ActionType[] OptimizeActionPool(IEnumerable<ActionType> actions) =
ActionType.DaringTouch,
}.ToFrozenSet();

public static readonly FrozenSet<ActionType> SpecialistActions =
new[]
{
ActionType.CarefulObservation,
ActionType.HeartAndSoul,
ActionType.QuickInnovation,
}.ToFrozenSet();

public static readonly SolverConfig RecipeNoteDefault = new SolverConfig() with
{

Expand Down

1 comment on commit d488b9e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: d488b9e Previous: 1622902 Ratio
Craftimizer.Benchmark.Bench.Solve(State: 37001636, Config: 7D89986B) 76531608.57142857 ns (± 636016.2781852508)
Craftimizer.Benchmark.Bench.Solve(State: 825D46BD, Config: 7D89986B) 91880352.38095239 ns (± 465783.9807285118)

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.