Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: make some settings can be used in macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 9, 2023
1 parent 8b983a6 commit 6ab562c
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 42 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private bool TargetAreaMove(float range, bool mustUse)
private bool TargetAreaFriend(float range, bool mustUse, PlayerCharacter player)
{
//如果用户不想使用自动友方地面放置功能
if (!Service.Config.UseGroundBeneficialAbility) return false;
if (!Service.Config.GetValue(SettingsCommand.UseGroundBeneficialAbility)) return false;

if (Service.Config.BeneficialAreaOnTarget && Service.TargetManager.Target != null)
{
Expand Down
14 changes: 6 additions & 8 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ public class PluginConfiguration : IPluginConfiguration
public Dictionary<uint, string> RotationChoices { get; private set; } = new Dictionary<uint, string>();
public Dictionary<uint, byte> TargetToHostileTypes { get; set; } =
new Dictionary<uint, byte>();

private Dictionary<SettingsCommand, bool> SettingsBools { get; set; } = new Dictionary<SettingsCommand, bool>();
public bool GetValue(SettingsCommand command) => Service.Config.SettingsBools.TryGetValue(command, out var value) ? value : command.GetDefault();
public void SetValue(SettingsCommand command, bool value) => Service.Config.SettingsBools[command] = value;

public int AddDotGCDCount = 2;

public int TimelineIndex = 0;
public bool AutoBurst = true;

public bool AutoOffBetweenArea = true;
public bool AutoOffCutScene = true;
public bool AutoOffWhenDead = true;
public bool UseAbility = true;
public bool UseDefenseAbility = true;
public bool NeverReplaceIcon = false;
public bool AutoProvokeForTank = true;
public bool AutoUseTrueNorth = true;
public bool ChangeTargetForFate = true;
public bool MoveTowardsScreenCenter = true;

Expand All @@ -51,10 +52,8 @@ public class PluginConfiguration : IPluginConfiguration
public bool PoslockCasting = false;
public int PoslockModifier = 0;
public bool RaisePlayerByCasting = true;
public bool RaisePlayerBySwift = true;
public bool RaiseBrinkOfDeath = true;
public int LessMPNoRaise = 0;
public bool AutoTankStance = true;
public bool AddEnemyListToHostile = true;
public bool UseAOEWhenManual = false;
public bool UseAOEAction = true;
Expand All @@ -80,7 +79,6 @@ public class PluginConfiguration : IPluginConfiguration
public int KeyBoardNoiseMax = 3;
public float KeyBoardNoiseTimeMin = 0.1f;
public float KeyBoardNoiseTimeMax = 0.2f;
public bool UseGroundBeneficialAbility = true;
public bool MoveAreaActionFarthest = true;
public bool StartOnCountdown = true;
public bool NoNewHostiles = false;
Expand Down
28 changes: 28 additions & 0 deletions RotationSolver.Basic/Data/RSCommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ public enum OtherCommandType : byte
DoActions,
ToggleActions,
}

public enum SettingsCommand : byte
{
AutoBurst,
UseAbility,
UseDefenseAbility,
AutoTankStance,
AutoProvokeForTank,
AutoUseTrueNorth,
RaisePlayerBySwift,
UseGroundBeneficialAbility,
}

public static class SettingsCommandExtension
{
public static bool GetDefault(this SettingsCommand command) => command switch
{
SettingsCommand.AutoBurst => true,
SettingsCommand.UseAbility => true,
SettingsCommand.UseDefenseAbility => true,
SettingsCommand.AutoTankStance => true,
SettingsCommand.AutoProvokeForTank => true,
SettingsCommand.AutoUseTrueNorth => true,
SettingsCommand.RaisePlayerBySwift => true,
SettingsCommand.UseGroundBeneficialAbility => true,
_ => false,
};
}
1 change: 0 additions & 1 deletion RotationSolver.Basic/Data/TerritoryContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public enum TerritoryContentType : uint
Eureka = 26,
UltimateRaids = 28,
VCDungeonFinder = 30,
\
}
12 changes: 7 additions & 5 deletions RotationSolver.Basic/Rotations/CustomRotation_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ private bool Ability(byte abilitiesRemaining, IAction nextGCD, out IAction act,
act = DataCenter.CommandNextAction;
if (act is IBaseAction a && a != null && !a.IsRealGCD && a.CanUse(out _, CanUseOption.MustUse | CanUseOption.SkipDisable | CanUseOption.EmptyOrSkipCombo)) return true;

if (!Service.Config.UseAbility || Player.TotalCastTime - Player.CurrentCastTime > Service.Config.AbilitiesInterval)
if (!Service.Config.GetValue(SettingsCommand.UseAbility)
|| Player.TotalCastTime - Player.CurrentCastTime > Service.Config.AbilitiesInterval)
{
act = null;
return false;
Expand Down Expand Up @@ -86,7 +87,7 @@ private bool ShirkOrShield(JobRole role, SpecialCommandType specialType, out IAc
break;
}

if (DataCenter.SetAutoStatus(AutoStatus.TankStance, Service.Config.AutoTankStance
if (DataCenter.SetAutoStatus(AutoStatus.TankStance, Service.Config.GetValue(SettingsCommand.AutoTankStance)
&& !DataCenter.AllianceTanks.Any(t => t.CurrentHp != 0 && t.HasStatus(false, StatusHelper.TankStanceStatus))
&& !HasTankStance && TankStance.CanUse(out act)))
{
Expand Down Expand Up @@ -157,15 +158,15 @@ private bool AutoDefense(byte abilitiesRemaining, JobRole role, bool helpDefense

//Auto Provoke
if (DataCenter.SetAutoStatus(AutoStatus.Provoke, role == JobRole.Tank
&& (Service.Config.AutoProvokeForTank || DataCenter.AllianceTanks.Count() < 2)
&& (Service.Config.GetValue(SettingsCommand.AutoProvokeForTank) || DataCenter.AllianceTanks.Count() < 2)
&& TargetFilter.ProvokeTarget(DataCenter.HostileTargets, true).Count() != DataCenter.HostileTargets.Count()))
{
if (!HasTankStance && TankStance.CanUse(out act)) return true;
if (Provoke.CanUse(out act, CanUseOption.MustUse)) return true;
}

//No using defense abilities.
if (!Service.Config.UseDefenseAbility) return false;
if (!Service.Config.GetValue(SettingsCommand.UseDefenseAbility)) return false;

if (helpDefenseAOE)
{
Expand Down Expand Up @@ -251,7 +252,8 @@ protected virtual bool EmergencyAbility(byte abilitiesRemaining, IAction nextGCD
if (Job.GetJobRole() is JobRole.Healer or JobRole.RangedMagical &&
action.CastTime >= 5 && Swiftcast.CanUse(out act, CanUseOption.EmptyOrSkipCombo)) return true;

if (Service.Config.AutoUseTrueNorth && abilitiesRemaining == 1 && action.EnemyPositional != EnemyPositional.None && action.Target != null)
if (Service.Config.GetValue(SettingsCommand.AutoUseTrueNorth) && abilitiesRemaining == 1
&& action.EnemyPositional != EnemyPositional.None && action.Target != null)
{
if (action.EnemyPositional != action.Target.FindEnemyPositional() && action.Target.HasPositional())
{
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private bool RaiseSpell(SpecialCommandType specialType, out IAction act, byte ac
return DataCenter.SetAutoStatus(AutoStatus.Raise, true);
}
}
else if (Service.Config.RaisePlayerBySwift && !Swiftcast.IsCoolingDown && actabilityRemain > 0)
else if (Service.Config.GetValue(SettingsCommand.RaisePlayerBySwift) && !Swiftcast.IsCoolingDown && actabilityRemain > 0)
{
return DataCenter.SetAutoStatus(AutoStatus.Raise, true);
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private IAction Invoke(out IAction gcdAction)
}

byte abilityRemain = DataCenter.AbilityRemainCount;
var helpDefenseAOE = Service.Config.UseDefenseAbility && DataCenter.IsHostileCastingAOE;
var helpDefenseAOE = Service.Config.GetValue(SettingsCommand.UseDefenseAbility) && DataCenter.IsHostileCastingAOE;

bool helpDefenseSingle = false;
if (Job.GetJobRole() == JobRole.Healer || Job.RowId == (uint)ClassJobID.Paladin)
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public abstract partial class CustomRotation
/// <summary>
/// Is in burst right now? Usually it used with team support actions.
/// </summary>
protected static bool InBurst => DataCenter.SpecialType == SpecialCommandType.Burst || Service.Config.AutoBurst;
protected static bool InBurst => DataCenter.SpecialType == SpecialCommandType.Burst || Service.Config.GetValue(SettingsCommand.AutoBurst);

bool _canUseHealAction => Job.GetJobRole() == JobRole.Healer || Service.Config.UseHealWhenNotAHealer;

Expand Down
15 changes: 9 additions & 6 deletions RotationSolver/Commands/RSCommands_OtherCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ private static void DoOtherCommand(OtherCommandType otherType, string str)

private static void DoSettingCommand(string str)
{
if (str.Contains(nameof(Service.Config.AutoBurst)))
if (!TryGetOneEnum<SettingsCommand>(str, out var type))
{
Service.Config.AutoBurst = !Service.Config.AutoBurst;

//Say out.
Service.ChatGui.Print(string.Format(LocalizationManager.RightLang.Commands_ChangeAutoBurst,
Service.Config.AutoBurst));
RotationSolverPlugin.OpenConfigWindow();
return;
}

Service.Config.SetValue(type, !Service.Config.GetValue(type));

//Say out.
Service.ChatGui.Print(string.Format(LocalizationManager.RightLang.Commands_ChangeSettingsValue,
type.ToString(), Service.Config.GetValue(type)));
}

private static void ToggleActionCommand(string str)
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal partial class Strings
{
#region Commands
public string Commands_Rotation { get; set; } = "Open config window.";
public string Commands_ChangeAutoBurst { get; set; } = "Modify automatic burst to {0}";
public string Commands_ChangeSettingsValue { get; set; } = "Modify {0} to {1}";
public string Commands_ChangeRotationConfig { get; set; } = "Modify {0} to {1}";
public string Commands_CannotFindRotationConfig { get; set; } = "Failed to find the config in this rotation, please check it.";

Expand Down
43 changes: 26 additions & 17 deletions RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,43 +308,38 @@ private void DrawParamAction()

ImGui.Separator();

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoBurst,
ref Service.Config.AutoBurst, Service.Default.AutoBurst);

ImGui.SameLine();
ImGuiHelper.Spacing();
ImGuiHelper.DisplayCommandHelp(OtherCommandType.Settings, nameof(Service.Config.AutoBurst));
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoBurst, SettingsCommand.AutoBurst);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseItem,
ref Service.Config.UseItem, Service.Default.UseItem,
LocalizationManager.RightLang.ConfigWindow_Param_UseItemDesc);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseAbility,
ref Service.Config.UseAbility, Service.Default.UseAbility);
SettingsCommand.UseAbility);

if (Service.Config.UseAbility)
if (Service.Config.GetValue(SettingsCommand.UseAbility))
{
ImGui.Indent();

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseDefenceAbility,
ref Service.Config.UseDefenseAbility, Service.Default.UseDefenseAbility,
SettingsCommand.UseDefenseAbility,
LocalizationManager.RightLang.ConfigWindow_Param_UseDefenceAbilityDesc);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoShield,
ref Service.Config.AutoTankStance, Service.Default.AutoTankStance);
SettingsCommand.AutoTankStance);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoProvokeForTank,
ref Service.Config.AutoProvokeForTank, Service.Default.AutoProvokeForTank,
SettingsCommand.AutoProvokeForTank,
LocalizationManager.RightLang.ConfigWindow_Param_AutoProvokeForTankDesc);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_AutoUseTrueNorth,
ref Service.Config.AutoUseTrueNorth, Service.Default.AutoUseTrueNorth);
SettingsCommand.AutoUseTrueNorth);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_RaisePlayerBySwift,
ref Service.Config.RaisePlayerBySwift, Service.Default.RaisePlayerBySwift);
SettingsCommand.RaisePlayerBySwift);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseGroundBeneficialAbility,
ref Service.Config.UseGroundBeneficialAbility, Service.Default.UseGroundBeneficialAbility);
SettingsCommand.UseGroundBeneficialAbility);

ImGui.Unindent();
}
Expand Down Expand Up @@ -373,7 +368,7 @@ private void DrawParamCondition()
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_OnlyHotOnTanks,
ref Service.Config.OnlyHotOnTanks, Service.Default.OnlyHotOnTanks);

if (Service.Config.UseGroundBeneficialAbility)
if (Service.Config.GetValue(SettingsCommand.UseGroundBeneficialAbility))
{
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_BeneficialAreaOnTarget,
ref Service.Config.BeneficialAreaOnTarget, Service.Default.BeneficialAreaOnTarget);
Expand Down Expand Up @@ -509,18 +504,32 @@ private void DrawParamHostile()
}
}

internal static void DrawCheckBox(string name, SettingsCommand command, string description = "", Action otherThing = null)
{
var value = Service.Config.GetValue(command);
DrawCheckBox(name, ref value, command.GetDefault(), description, () =>
{
Service.Config.SetValue(command, value);
otherThing?.Invoke();
});

ImGui.SameLine();
ImGuiHelper.Spacing();
ImGuiHelper.DisplayCommandHelp(OtherCommandType.Settings, command.ToString());
}

internal static void DrawCheckBox(string name, ref bool value, bool @default, string description = "", Action otherThing = null)
{
if (ImGui.Checkbox(name, ref value))
{
Service.Config.Save();
otherThing?.Invoke();
Service.Config.Save();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)
{
otherThing?.Invoke();
value = @default;
Service.Config.Save();
otherThing?.Invoke();
}
}

Expand Down

0 comments on commit 6ab562c

Please sign in to comment.