mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-21 09:45:48 +08:00
play with merge event
This commit is contained in:
@@ -30,11 +30,12 @@ public class KeyMouseMacroPlayer
|
||||
|
||||
var script = JsonSerializer.Deserialize<KeyMouseScript>(macro, KeyMouseRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize macro");
|
||||
script.Adapt(TaskContext.Instance().SystemInfo.CaptureAreaRect, TaskContext.Instance().DpiScale);
|
||||
script.Merge();
|
||||
SystemControl.ActivateWindow();
|
||||
|
||||
if (withDelay)
|
||||
{
|
||||
for (var i = 1; i >= 1; i--)
|
||||
for (var i = 2; i >= 1; i--)
|
||||
{
|
||||
TaskControl.Logger.LogInformation("{Sec}秒后进行重放...", i);
|
||||
await Task.Delay(1000, ct);
|
||||
|
||||
@@ -39,64 +39,11 @@ public class KeyMouseRecorder
|
||||
public string ToJsonMacro()
|
||||
{
|
||||
var rect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
// 合并鼠标移动事件
|
||||
// var mergedMacroEvents = new List<MacroEvent>();
|
||||
// MacroEvent? currentMerge = null;
|
||||
// foreach (var macroEvent in MacroEvents)
|
||||
// {
|
||||
// if (currentMerge == null)
|
||||
// {
|
||||
// currentMerge = macroEvent;
|
||||
// continue;
|
||||
// }
|
||||
// if (currentMerge.Type != macroEvent.Type)
|
||||
// {
|
||||
// mergedMacroEvents.Add(currentMerge);
|
||||
// currentMerge = macroEvent;
|
||||
// continue;
|
||||
// }
|
||||
// switch (macroEvent.Type)
|
||||
// {
|
||||
// case MacroEventType.MouseMoveTo:
|
||||
// // 控制合并时间片段长度
|
||||
// if (macroEvent.Time - currentMerge.Time > MergedEventTimeMax)
|
||||
// {
|
||||
// mergedMacroEvents.Add(currentMerge);
|
||||
// currentMerge = macroEvent;
|
||||
// break;
|
||||
// }
|
||||
// // 合并为最后一个事件的位置,避免丢步
|
||||
// currentMerge.MouseX = macroEvent.MouseX;
|
||||
// currentMerge.MouseY = macroEvent.MouseY;
|
||||
// break;
|
||||
//
|
||||
// case MacroEventType.MouseMoveBy:
|
||||
// if (macroEvent.Time - currentMerge.Time > MergedEventTimeMax)
|
||||
// {
|
||||
// mergedMacroEvents.Add(currentMerge);
|
||||
// currentMerge = macroEvent;
|
||||
// break;
|
||||
// }
|
||||
// // 相对位移量相加
|
||||
// currentMerge.MouseX += macroEvent.MouseX;
|
||||
// currentMerge.MouseY += macroEvent.MouseY;
|
||||
// if (macroEvent.CameraOrientation != null)
|
||||
// {
|
||||
// currentMerge.CameraOrientation = macroEvent.CameraOrientation;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// mergedMacroEvents.Add(currentMerge);
|
||||
// mergedMacroEvents.Add(macroEvent);
|
||||
// currentMerge = null;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
KeyMouseScript keyMouseScript = new()
|
||||
{
|
||||
MacroEvents = MacroEvents,
|
||||
MouseMoveByMacroEvents = MouseMoveByMacroEvents,
|
||||
MouseMoveToMacroEvents = MouseMoveToMacroEvents,
|
||||
Info = new KeyMouseScriptInfo
|
||||
{
|
||||
X = rect.X,
|
||||
|
||||
@@ -10,6 +10,7 @@ public class KeyMouseScript
|
||||
{
|
||||
public List<MacroEvent> MacroEvents { get; set; } = [];
|
||||
public List<MacroEvent> MouseMoveByMacroEvents { get; set; } = [];
|
||||
public List<MacroEvent> MouseMoveToMacroEvents { get; set; } = [];
|
||||
public KeyMouseScriptInfo? Info { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -39,4 +40,70 @@ public class KeyMouseScript
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Merge()
|
||||
{
|
||||
// 合并鼠标移动事件
|
||||
const int mergedEventTimeMax = 20;
|
||||
var mergedMacroEvents = new List<MacroEvent>();
|
||||
MacroEvent? currentMerge = null;
|
||||
foreach (var macroEvent in MacroEvents)
|
||||
{
|
||||
if (currentMerge == null)
|
||||
{
|
||||
currentMerge = macroEvent;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentMerge.Type != macroEvent.Type)
|
||||
{
|
||||
mergedMacroEvents.Add(currentMerge);
|
||||
currentMerge = macroEvent;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (macroEvent.Type)
|
||||
{
|
||||
case MacroEventType.MouseMoveTo:
|
||||
// 控制合并时间片段长度
|
||||
if (macroEvent.Time - currentMerge.Time > mergedEventTimeMax)
|
||||
{
|
||||
mergedMacroEvents.Add(currentMerge);
|
||||
currentMerge = macroEvent;
|
||||
break;
|
||||
}
|
||||
|
||||
// 合并为最后一个事件的位置,避免丢步
|
||||
currentMerge.MouseX = macroEvent.MouseX;
|
||||
currentMerge.MouseY = macroEvent.MouseY;
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseMoveBy:
|
||||
if (macroEvent.Time - currentMerge.Time > mergedEventTimeMax)
|
||||
{
|
||||
mergedMacroEvents.Add(currentMerge);
|
||||
currentMerge = macroEvent;
|
||||
break;
|
||||
}
|
||||
|
||||
// 相对位移量相加
|
||||
currentMerge.MouseX += macroEvent.MouseX;
|
||||
currentMerge.MouseY += macroEvent.MouseY;
|
||||
if (macroEvent.CameraOrientation != null)
|
||||
{
|
||||
currentMerge.CameraOrientation = macroEvent.CameraOrientation;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
mergedMacroEvents.Add(currentMerge);
|
||||
mergedMacroEvents.Add(macroEvent);
|
||||
currentMerge = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MacroEvents = mergedMacroEvents;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user