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

Commit

Permalink
feat: add offset delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 26, 2024
1 parent 34739eb commit b8a5f9a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,5 +507,9 @@
11612,
11306,
11308,
33139
33139,
21009,
26071,
26072,
26064
]
4 changes: 2 additions & 2 deletions Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ClickingCount": 81534,
"SayingHelloCount": 72,
"ClickingCount": 84394,
"SayingHelloCount": 73,
"SaidUsers": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ internal abstract class DelayCondition : ICondition
{
public float DelayMin = 0;
public float DelayMax = 0;
public float DelayOffset = 0;

RandomDelay _delay = default;
OffsetDelay _offsetDelay = default;

public bool Not = false;

Expand All @@ -31,13 +33,18 @@ public bool IsTrue(ICustomRotation? rotation)
_delay = new(() => (DelayMin, DelayMax));
}

if(_offsetDelay.GetDelay == null)
{
_offsetDelay = new(() => DelayOffset);
}

_callingStack.Push(this);
var value = CheckBefore(rotation) && IsTrueInside(rotation);
if (Not)
{
value = !value;
}
var result = _delay.Delay(value);
var result = _delay.Delay(_offsetDelay.Delay(value));
_callingStack.Pop();

return result;
Expand Down
39 changes: 39 additions & 0 deletions RotationSolver.Basic/Data/OffsetDelay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace RotationSolver.Basic.Data;

/// <summary>
/// Off set the whole bool
/// </summary>
/// <param name="getDelay"></param>
public struct OffsetDelay(Func<float> getDelay)
{
bool _lastValue = false;
bool _nowValue = false;
readonly Queue<DateTime> _changeTimes = new();

/// <summary>
///
/// </summary>
public readonly Func<float> GetDelay => getDelay;

/// <summary>
/// Delay the value to change.
/// </summary>
/// <param name="originData"></param>
/// <returns></returns>
public bool Delay(bool originData)
{
if (originData != _lastValue)
{
_lastValue = originData;
_changeTimes.Enqueue(DateTime.Now + TimeSpan.FromSeconds(GetDelay()));
}

if (_changeTimes.TryPeek(out var time) && time < DateTime.Now)
{
_changeTimes.Dequeue();
_nowValue = !_nowValue;
}

return _nowValue;
}
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Data/RandomDelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RandomDelay(Func<Vector2> getRange)
}

/// <summary>
/// Delay the bool.
/// Delay the bool to be true.
/// </summary>
/// <param name="originData"></param>
/// <returns></returns>
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/Data/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ internal enum UiString
[Description("Delay its turning to true.")]
ActionSequencer_Delay_Description,

[Description("Delay its turning.")]
ActionSequencer_Offset_Description,

[Description("Enought Level")]
ActionConditionType_EnoughLevel,

Expand Down
9 changes: 8 additions & 1 deletion RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static void Draw(this ICondition condition, ICustomRotation rotation)

private static void DrawDelay(this DelayCondition condition)
{
const float MIN = 0, MAX = 60;
const float MIN = 0, MAX = 600;

ImGui.SetNextItemWidth(80 * ImGuiHelpers.GlobalScale);
if (ImGui.DragFloatRange2($"##Random Delay {condition.GetHashCode()}", ref condition.DelayMin, ref condition.DelayMax, 0.1f, MIN, MAX,
Expand All @@ -261,6 +261,13 @@ private static void DrawDelay(this DelayCondition condition)
}
ImguiTooltips.HoveredTooltip(UiString.ActionSequencer_Delay_Description.Local() +
"\n" + ConfigUnitType.Seconds.Local());

ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragFloat($"##Offset Delay {condition.GetHashCode()}", ref condition.DelayOffset, 0.1f, MIN, MAX,
$"{condition.DelayOffset:F1}{ConfigUnitType.Seconds.ToSymbol()}");

ImguiTooltips.HoveredTooltip(UiString.ActionSequencer_Offset_Description.Local() +
"\n" + ConfigUnitType.Seconds.Local());
}

private static void DrawBefore(this ICondition condition)
Expand Down

0 comments on commit b8a5f9a

Please sign in to comment.