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

Commit

Permalink
fix: fixed recursion in condition set.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Oct 27, 2023
1 parent 54099e0 commit a8e3246
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ClickingCount": 21505,
"ClickingCount": 22479,
"SaidUsers": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override bool CheckBefore(ICustomRotation rotation)
return CheckBaseAction(rotation, ID, ref _action) && base.CheckBefore(rotation);
}

public override bool IsTrueInside(ICustomRotation rotation)
protected override bool IsTrueInside(ICustomRotation rotation)
{
var result = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class ConditionSet : DelayCondition

public LogicalType Type;

public override bool IsTrueInside(ICustomRotation rotation)
protected override bool IsTrueInside(ICustomRotation rotation)
{
if (Conditions.Count == 0) return false;

Expand Down
32 changes: 25 additions & 7 deletions RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ECommons.GameHelpers;
using ECommons.DalamudServices;
using ECommons.GameHelpers;

namespace RotationSolver.Basic.Configuration.Conditions;

Expand All @@ -9,17 +10,32 @@ internal abstract class DelayCondition : ICondition

RandomDelay _delay = default;

[ThreadStatic]
private static Stack<ICondition> _callingStack;

public bool IsTrue(ICustomRotation rotation)
{
_callingStack ??= new(64);

if (_callingStack.Contains(this))
{
//Do something for recursion!
return false;
}

if (_delay.GetRange == null)
{
_delay = new(() => (DelayMin, DelayMax));
}

return _delay.Delay(CheckBefore(rotation) && IsTrueInside(rotation));
_callingStack.Push(this);
var result = _delay.Delay(CheckBefore(rotation) && IsTrueInside(rotation));
_callingStack.Pop();

return result;
}

public abstract bool IsTrueInside(ICustomRotation rotation);
protected abstract bool IsTrueInside(ICustomRotation rotation);

public virtual bool CheckBefore(ICustomRotation rotation)
{
Expand All @@ -38,26 +54,28 @@ internal static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref

internal static bool CheckMemberInfo<T>(ICustomRotation rotation, ref string name, ref T value) where T : MemberInfo
{
if (rotation == null) return false;

if (!string.IsNullOrEmpty(name) && (value == null || value.Name != name))
{
var memberName = name;
if (typeof(T).IsAssignableFrom(typeof(PropertyInfo)))
{
value = (T)GetAllMethods(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
value = (T)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
}
else if (typeof(T).IsAssignableFrom(typeof(MethodInfo)))
{
value = (T)GetAllMethods(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
value = (T)GetAllMembers(rotation.GetType(), RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
}
}
return true;
}

private static IEnumerable<MemberInfo> GetAllMethods(Type type, Func<Type, IEnumerable<MemberInfo>> getFunc)
private static IEnumerable<MemberInfo> GetAllMembers(Type type, Func<Type, IEnumerable<MemberInfo>> getFunc)
{
if (type == null || getFunc == null) return Array.Empty<MemberInfo>();

var methods = getFunc(type);
return methods.Union(GetAllMethods(type.BaseType, getFunc));
return methods.Union(GetAllMembers(type.BaseType, getFunc));
}
}
31 changes: 16 additions & 15 deletions RotationSolver.Basic/Configuration/Conditions/MajorConditionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ public Dictionary<uint, ConditionSet> DisableConditionDict
public Dictionary<PluginConfigBool, ConditionSet> ForceDisableConditions { get; private set; }
= new();

public ConditionSet HealAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet HealSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet EsunaStanceNorthConditionSet { get; set; } = new ConditionSet();
public ConditionSet RaiseShirkConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveForwardConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveBackConditionSet { get; set; } = new ConditionSet();
public ConditionSet AntiKnockbackConditionSet { get; set; } = new ConditionSet();
public ConditionSet SpeedConditionSet { get; set; } = new ConditionSet();

public ConditionSet SwitchAutoConditionSet { get; set; } = new ConditionSet();
public ConditionSet SwitchManualConditionSet { get; set; } = new ConditionSet();
public ConditionSet SwitchCancelConditionSet { get; set; } = new ConditionSet();

public ConditionSet HealAreaConditionSet { get; set; } = new ();
public ConditionSet HealSingleConditionSet { get; set; } = new ();
public ConditionSet DefenseAreaConditionSet { get; set; } = new ();
public ConditionSet DefenseSingleConditionSet { get; set; } = new ();
public ConditionSet EsunaStanceNorthConditionSet { get; set; } = new ();
public ConditionSet RaiseShirkConditionSet { get; set; } = new ();
public ConditionSet MoveForwardConditionSet { get; set; } = new ();
public ConditionSet MoveBackConditionSet { get; set; } = new ();
public ConditionSet AntiKnockbackConditionSet { get; set; } = new ();
public ConditionSet SpeedConditionSet { get; set; } = new ();

public ConditionSet SwitchAutoConditionSet { get; set; } = new ();
public ConditionSet SwitchManualConditionSet { get; set; } = new ();
public ConditionSet SwitchCancelConditionSet { get; set; } = new ();

//public Dictionary<string, ConditionSet> NamedConditions { get; set; } = new ();

public string Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override bool CheckBefore(ICustomRotation rotation)
return base.CheckBefore(rotation);
}

public override bool IsTrueInside(ICustomRotation rotation)
protected override bool IsTrueInside(ICustomRotation rotation)
{
switch (ComboConditionType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class TargetCondition : DelayCondition

public string CastingActionName = string.Empty;

public override bool IsTrueInside(ICustomRotation rotation)
protected override bool IsTrueInside(ICustomRotation rotation)
{
BattleChara tar;
if (_action != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override bool CheckBefore(ICustomRotation rotation)
return base.CheckBefore(rotation);
}

public override bool IsTrueInside(ICustomRotation rotation)
protected override bool IsTrueInside(ICustomRotation rotation)
{
if (_trait == null || !Player.Available) return false;

Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static float AbilityRemain
public static bool IsMoveForward => SpecialType == SpecialCommandType.MoveForward || RightSet.MoveForwardConditionSet.IsTrue(RightNowRotation);
public static bool IsMoveBack => SpecialType == SpecialCommandType.MoveBack || RightSet.MoveBackConditionSet.IsTrue(RightNowRotation);
public static bool IsAntiKnockback => SpecialType == SpecialCommandType.AntiKnockback || RightSet.AntiKnockbackConditionSet.IsTrue(RightNowRotation);
public static bool IsBurst => SpecialType == SpecialCommandType.Burst;
public static bool IsBurst => SpecialType == SpecialCommandType.Burst || Service.Config.GetValue(Configuration.PluginConfigBool.AutoBurst);
public static bool IsSpeed => SpecialType == SpecialCommandType.Speed || RightSet.SpeedConditionSet.IsTrue(RightNowRotation);

public static bool State { get; set; } = false;
Expand Down
77 changes: 36 additions & 41 deletions RotationSolver.Basic/Rotations/CustomRotation_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,28 +295,26 @@ public override bool CanUse(out IAction act, CanUseOption option = CanUseOption.
ActionOption.DutyAction | ActionOption.Friendly)
{
StatusProvide = new StatusID[] {StatusID.LostSpellforge },
ActionCheck = (b, m) => Target?.HasStatus(false, StatusID.MagicalAversion) ?? false,
ChoiceTarget = (targets, mustUse) => targets.FirstOrDefault(t =>
{
switch((Job)t.ClassJob.Id)
{
case Job.WAR:
case Job.GNB:
case Job.MNK:
case Job.SAM:
case Job.DRG:
case Job.MCH:
case Job.DNC:

case Job.PLD:
case Job.DRK:
case Job.NIN:
case Job.BRD:
case Job.RDM:
return true;
}
return false;
}),
ActionCheck = (b, m) => Target?.HasStatus(false, StatusID.MagicalAversion) ?? false,
ChoiceTarget = (targets, mustUse) => targets.FirstOrDefault(t => (Job)t.ClassJob.Id switch
{
Job.WAR
or Job.GNB
or Job.MNK
or Job.SAM
or Job.DRG
or Job.MCH
or Job.DNC

or Job.PLD
or Job.DRK
or Job.NIN
or Job.BRD
or Job.RDM
=> true,

_ => false,
}),
};

/// <summary>
Expand All @@ -327,26 +325,23 @@ public override bool CanUse(out IAction act, CanUseOption option = CanUseOption.
{
StatusProvide = new StatusID[] { StatusID.LostSteelsting },
ActionCheck = (b, m) => Target?.HasStatus(false, StatusID.PhysicalAversion) ?? false,
ChoiceTarget = (targets, mustUse) => targets.FirstOrDefault(t =>
ChoiceTarget = (targets, mustUse) => targets.FirstOrDefault(t => (Job)t.ClassJob.Id switch
{
switch ((Job)t.ClassJob.Id)
{
case Job.WHM:
case Job.SCH:
case Job.AST:
case Job.SGE:
case Job.BLM:
case Job.SMN:

case Job.PLD:
case Job.DRK:
case Job.NIN:
case Job.BRD:
case Job.RDM:
return true;
}

return false;
Job.WHM
or Job.SCH
or Job.AST
or Job.SGE
or Job.BLM
or Job.SMN

or Job.PLD
or Job.DRK
or Job.NIN
or Job.BRD
or Job.RDM
=> true,

_ => false,
}),
};

Expand Down
8 changes: 1 addition & 7 deletions RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,10 @@ public static bool IsLongerThan(float time)
#endregion

#region Command
/// <summary>
/// Is in burst right now? Usually it used with team support actions. Please use <see cref="IsBurst"/> instead.
/// </summary>
[Obsolete("It will be removed in the future version", true)]
public static bool InBurst => IsBurst;

/// <summary>
/// Is in burst right now? Usually it used with team support actions.
/// </summary>
public static bool IsBurst => DataCenter.IsBurst || Service.Config.GetValue(Configuration.PluginConfigBool.AutoBurst);
public static bool IsBurst => DataCenter.IsBurst;

/// <summary>
/// Is in the command heal area.
Expand Down
Loading

0 comments on commit a8e3246

Please sign in to comment.