From b8a5f9ad48351a925287d9f8f2e88882e58be1ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com>
Date: Mon, 26 Feb 2024 16:32:53 +0800
Subject: [PATCH] feat: add offset delay.
---
Resources/HostileCastingArea.json | 6 ++-
Resources/RotationSolverRecord.json | 4 +-
.../Conditions/DelayCondition.cs | 9 ++++-
RotationSolver.Basic/Data/OffsetDelay.cs | 39 +++++++++++++++++++
RotationSolver.Basic/Data/RandomDelay.cs | 2 +-
RotationSolver/Data/UiString.cs | 3 ++
RotationSolver/UI/ConditionDrawer.cs | 9 ++++-
7 files changed, 66 insertions(+), 6 deletions(-)
create mode 100644 RotationSolver.Basic/Data/OffsetDelay.cs
diff --git a/Resources/HostileCastingArea.json b/Resources/HostileCastingArea.json
index 6f2ed079f..bbabcf426 100644
--- a/Resources/HostileCastingArea.json
+++ b/Resources/HostileCastingArea.json
@@ -507,5 +507,9 @@
11612,
11306,
11308,
- 33139
+ 33139,
+ 21009,
+ 26071,
+ 26072,
+ 26064
]
\ No newline at end of file
diff --git a/Resources/RotationSolverRecord.json b/Resources/RotationSolverRecord.json
index 4af6db0f5..7a517daa9 100644
--- a/Resources/RotationSolverRecord.json
+++ b/Resources/RotationSolverRecord.json
@@ -1,5 +1,5 @@
{
- "ClickingCount": 81534,
- "SayingHelloCount": 72,
+ "ClickingCount": 84394,
+ "SayingHelloCount": 73,
"SaidUsers": []
}
\ No newline at end of file
diff --git a/RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs b/RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
index 02158cc06..950398c04 100644
--- a/RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
+++ b/RotationSolver.Basic/Configuration/Conditions/DelayCondition.cs
@@ -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;
@@ -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;
diff --git a/RotationSolver.Basic/Data/OffsetDelay.cs b/RotationSolver.Basic/Data/OffsetDelay.cs
new file mode 100644
index 000000000..0f1fff8a7
--- /dev/null
+++ b/RotationSolver.Basic/Data/OffsetDelay.cs
@@ -0,0 +1,39 @@
+namespace RotationSolver.Basic.Data;
+
+///
+/// Off set the whole bool
+///
+///
+public struct OffsetDelay(Func getDelay)
+{
+ bool _lastValue = false;
+ bool _nowValue = false;
+ readonly Queue _changeTimes = new();
+
+ ///
+ ///
+ ///
+ public readonly Func GetDelay => getDelay;
+
+ ///
+ /// Delay the value to change.
+ ///
+ ///
+ ///
+ 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;
+ }
+}
diff --git a/RotationSolver.Basic/Data/RandomDelay.cs b/RotationSolver.Basic/Data/RandomDelay.cs
index 832aca770..e768add33 100644
--- a/RotationSolver.Basic/Data/RandomDelay.cs
+++ b/RotationSolver.Basic/Data/RandomDelay.cs
@@ -31,7 +31,7 @@ public RandomDelay(Func getRange)
}
///
- /// Delay the bool.
+ /// Delay the bool to be true.
///
///
///
diff --git a/RotationSolver/Data/UiString.cs b/RotationSolver/Data/UiString.cs
index fe882bc37..56d31eb99 100644
--- a/RotationSolver/Data/UiString.cs
+++ b/RotationSolver/Data/UiString.cs
@@ -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,
diff --git a/RotationSolver/UI/ConditionDrawer.cs b/RotationSolver/UI/ConditionDrawer.cs
index 405268105..fdb6a1c60 100644
--- a/RotationSolver/UI/ConditionDrawer.cs
+++ b/RotationSolver/UI/ConditionDrawer.cs
@@ -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,
@@ -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)