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

Commit

Permalink
fix: add delay for all conditions in action sequencer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 28, 2023
1 parent b2c34bd commit e1009e9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 25 deletions.
14 changes: 10 additions & 4 deletions RotationSolver.Basic/Data/RandomDelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ public struct RandomDelay
{
DateTime _startDelayTime = DateTime.Now;
float _delayTime = -1;
readonly Func<(float min, float max)> _getRange;

readonly Random _ran = new(DateTime.Now.Millisecond);
bool _lastValue = false;

/// <summary>
///
/// </summary>
public Func<(float min, float max)> GetRange { get; set; } = null;

/// <summary>
/// Constructer.
/// </summary>
/// <param name="getRange"></param>
public RandomDelay(Func<(float min, float max)> getRange)
{
_getRange = getRange;
GetRange = getRange;
}

/// <summary>
Expand All @@ -27,7 +32,9 @@ public RandomDelay(Func<(float min, float max)> getRange)
/// <returns></returns>
public bool Delay(bool originData)
{
if (_getRange == null) return false;
if (GetRange == null) return originData;
var (min, max) = GetRange();
if (min <= 0 || max <= 0) return originData;

if (!originData)
{
Expand All @@ -41,7 +48,6 @@ public bool Delay(bool originData)
{
_lastValue = true;
_startDelayTime = DateTime.Now;
var (min, max) = _getRange();
_delayTime = min + (float)_ran.NextDouble() * (max - min);
}
//Times up
Expand Down
8 changes: 5 additions & 3 deletions RotationSolver/ActionSequencer/ActionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace RotationSolver.ActionSequencer;

internal class ActionCondition : ICondition
internal class ActionCondition : BaseCondition
{
private IBaseAction _action;

Expand All @@ -18,7 +18,7 @@ internal class ActionCondition : ICondition
public int Param2;
public float Time;

public bool IsTrue(ICustomRotation rotation)
public override bool IsTrueInside(ICustomRotation rotation)
{
if (!ConditionHelper.CheckBaseAction(rotation, ID, ref _action)) return false;

Expand Down Expand Up @@ -70,7 +70,8 @@ public bool IsTrue(ICustomRotation rotation)
{
HeaderSize = 12,
};
public void Draw(ICustomRotation rotation)

public override void DrawInside(ICustomRotation rotation)
{
ConditionHelper.CheckBaseAction(rotation, ID, ref _action);

Expand Down Expand Up @@ -193,6 +194,7 @@ public void Draw(ICustomRotation rotation)
break;
}
}

}

public enum ActionConditionType : byte
Expand Down
42 changes: 42 additions & 0 deletions RotationSolver/ActionSequencer/BaseCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using RotationSolver.Localization;
using RotationSolver.UI;

namespace RotationSolver.ActionSequencer;

internal abstract class BaseCondition : ICondition
{
public float DelayMin = 0;
public float DelayMax = 0;

private RandomDelay _delay = new RandomDelay();

[JsonIgnore]
private const float MIN = 0, MAX = 60;

public bool IsTrue(ICustomRotation rotation)
{
if (_delay.GetRange == null)
{
_delay.GetRange = () => (DelayMin, DelayMax);
}
return _delay.Delay(IsTrueInside(rotation));
}

public abstract bool IsTrueInside(ICustomRotation rotation);

public void Draw(ICustomRotation rotation)
{
ImGui.SetNextItemWidth(80 * ImGuiHelpers.GlobalScale);
if(ImGui.DragFloatRange2($"##Random Delay {GetHashCode()}", ref DelayMin, ref DelayMax, 0.1f, MIN, MAX))
{
DelayMin = Math.Max(Math.Min(DelayMin, DelayMax), MIN);
DelayMax = Math.Min(Math.Max(DelayMin, DelayMax), MAX);
}
ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_Delay_Description);

ImGui.SameLine();
DrawInside(rotation);
}

public abstract void DrawInside(ICustomRotation rotation);
}
14 changes: 7 additions & 7 deletions RotationSolver/ActionSequencer/ConditionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@

namespace RotationSolver.ActionSequencer;

internal class ConditionSet : ICondition
internal class ConditionSet : BaseCondition
{
public bool IsTrue(ICustomRotation combo)
public override bool IsTrueInside(ICustomRotation rotation)
{
if (Conditions.Count == 0) return false;
switch (Type)
{
case LogicalType.And:
return Conditions.All(c => c.IsTrue(combo));
return Conditions.All(c => c.IsTrue(rotation));
case LogicalType.Or:
return Conditions.Any(c => c.IsTrue(combo));
return Conditions.Any(c => c.IsTrue(rotation));
case LogicalType.NotAnd:
return !Conditions.All(c => c.IsTrue(combo));
return !Conditions.All(c => c.IsTrue(rotation));
case LogicalType.NotOr:
return !Conditions.Any(c => c.IsTrue(combo));
return !Conditions.Any(c => c.IsTrue(rotation));
}
return false;
}
public List<ICondition> Conditions { get; set; } = new List<ICondition>();
public LogicalType Type;

public void Draw(ICustomRotation rotation)
public override void DrawInside(ICustomRotation rotation)
{
ImGui.BeginGroup();

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/ActionSequencer/RotationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace RotationSolver.ActionSequencer;

internal class RotationCondition : ICondition
internal class RotationCondition : BaseCondition
{
public ComboConditionType ComboConditionType = ComboConditionType.Float;
PropertyInfo _prop;
Expand All @@ -29,7 +29,7 @@ private void UpdateInfo(ICustomRotation rotation)
ConditionHelper.CheckMemberInfo(rotation, MethodName, ref _method);
}

public bool IsTrue(ICustomRotation rotation)
public override bool IsTrueInside(ICustomRotation rotation)
{
if (!Player.Available) return false;
UpdateInfo(rotation);
Expand Down Expand Up @@ -100,7 +100,7 @@ public bool IsTrue(ICustomRotation rotation)
{
HeaderSize = 12,
};
public void Draw(ICustomRotation rotation)
public override void DrawInside(ICustomRotation rotation)
{
UpdateInfo(rotation);

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/ActionSequencer/TargetCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace RotationSolver.ActionSequencer;

internal class TargetCondition : ICondition
internal class TargetCondition : BaseCondition
{
private static Status[] _allStatus = null;
private static Status[] AllStatus
Expand All @@ -33,7 +33,7 @@ private static Status[] AllStatus

public string CastingActionName = string.Empty;

public bool IsTrue(ICustomRotation rotation)
public override bool IsTrueInside(ICustomRotation rotation)
{
if (!Player.Available) return false;

Expand Down Expand Up @@ -122,7 +122,7 @@ public bool IsTrue(ICustomRotation rotation)
HeaderSize = 12,
};

public void Draw(ICustomRotation rotation)
public override void DrawInside(ICustomRotation rotation)
{
ConditionHelper.CheckBaseAction(rotation, ID, ref _action);

Expand Down
7 changes: 3 additions & 4 deletions RotationSolver/ActionSequencer/TraitCondition.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using ECommons.GameHelpers;
using Lumina.Data.Parsing;
using RotationSolver.Basic.Traits;
using RotationSolver.Localization;
using RotationSolver.UI;

namespace RotationSolver.ActionSequencer;

internal class TraitCondition : ICondition
internal class TraitCondition : BaseCondition
{
public uint TraitID { get; set; } = 0;
private IBaseTrait _trait;
public bool Condition { get; set; }

public bool IsTrue(ICustomRotation rotation)
public override bool IsTrueInside(ICustomRotation rotation)
{
CheckBaseTrait(rotation);
if (_trait == null || !Player.Available) return false;
Expand All @@ -22,7 +21,7 @@ public bool IsTrue(ICustomRotation rotation)
}

private const int count = 8;
public void Draw(ICustomRotation rotation)
public override void DrawInside(ICustomRotation rotation)
{
CheckBaseTrait(rotation);

Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ internal partial class Strings

#endregion

#region ScriptWindow
#region Action Sequencer
public string ActionSequencer_Load { get; set; } = "Load From folder.";
public string ActionSequencer_Can { get; set; } = "Can";
public string ActionSequencer_Cannot { get; set; } = "Can Not";
Expand All @@ -310,6 +310,7 @@ internal partial class Strings
public string ActionSequencer_Adjusted { get; set; } = "Adjusted";
public string ActionSequencer_StatusSelf { get; set; } = "From Self";
public string ActionSequencer_StatusAll { get; set; } = "From All";
public string ActionSequencer_Delay_Description { get; set; } = "How many seconds do you want to delay its turning to true.";
#endregion

#region Actions
Expand Down

0 comments on commit e1009e9

Please sign in to comment.