muffin v7.4.7
This commit is contained in:
parent
1cc65e495d
commit
63f975ff4f
16 changed files with 1659 additions and 939 deletions
|
|
@ -252,4 +252,140 @@ internal static class Duty
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record StartLevelingModeTask(int RequiredLevel, string? QuestName) : ITask
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"StartLevelingMode(target: Lv{RequiredLevel} for '{QuestName}')";
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class StartLevelingModeExecutor(AutoDutyIpc autoDutyIpc, ICondition condition, ILogger<StartLevelingModeExecutor> logger) : TaskExecutor<StartLevelingModeTask>(), IStoppableTaskExecutor, ITaskExecutor
|
||||
{
|
||||
private bool _started;
|
||||
|
||||
private DateTime _startTime;
|
||||
|
||||
private DateTime _lastRetryTime = DateTime.MinValue;
|
||||
|
||||
protected override bool Start()
|
||||
{
|
||||
logger.LogInformation("Starting AutoDuty Leveling mode to reach level {RequiredLevel} for quest '{QuestName}'", base.Task.RequiredLevel, base.Task.QuestName);
|
||||
_started = autoDutyIpc.StartLevelingMode();
|
||||
_startTime = DateTime.Now;
|
||||
return _started;
|
||||
}
|
||||
|
||||
public override ETaskResult Update()
|
||||
{
|
||||
bool flag = condition[ConditionFlag.BoundByDuty];
|
||||
bool flag2 = condition[ConditionFlag.InDutyQueue];
|
||||
if (flag || flag2)
|
||||
{
|
||||
logger.LogInformation("AutoDuty started successfully (inDuty={InDuty}, inQueue={InQueue})", flag, flag2);
|
||||
return ETaskResult.TaskComplete;
|
||||
}
|
||||
if (!autoDutyIpc.IsStopped())
|
||||
{
|
||||
return ETaskResult.StillRunning;
|
||||
}
|
||||
if (DateTime.Now - _lastRetryTime > TimeSpan.FromSeconds(5L))
|
||||
{
|
||||
logger.LogWarning("AutoDuty stopped before entering duty, retrying...");
|
||||
_started = autoDutyIpc.StartLevelingMode();
|
||||
_lastRetryTime = DateTime.Now;
|
||||
}
|
||||
if (DateTime.Now - _startTime > TimeSpan.FromSeconds(60L))
|
||||
{
|
||||
logger.LogError("AutoDuty failed to start after 60 seconds");
|
||||
return ETaskResult.TaskComplete;
|
||||
}
|
||||
return ETaskResult.StillRunning;
|
||||
}
|
||||
|
||||
public void StopNow()
|
||||
{
|
||||
autoDutyIpc.Stop();
|
||||
}
|
||||
|
||||
public override bool ShouldInterruptOnDamage()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record WaitLevelingModeTask(int RequiredLevel) : ITask
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"WaitLevelingMode(until Lv{RequiredLevel})";
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class WaitLevelingModeExecutor(AutoDutyIpc autoDutyIpc, IObjectTable objectTable, ICondition condition, IChatGui chatGui, ILogger<WaitLevelingModeExecutor> logger) : TaskExecutor<WaitLevelingModeTask>(), IStoppableTaskExecutor, ITaskExecutor
|
||||
{
|
||||
private bool _wasInDuty;
|
||||
|
||||
private DateTime _lastStatusMessage = DateTime.MinValue;
|
||||
|
||||
private DateTime _idleStartTime = DateTime.MinValue;
|
||||
|
||||
protected override bool Start()
|
||||
{
|
||||
_wasInDuty = false;
|
||||
_idleStartTime = DateTime.MinValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override ETaskResult Update()
|
||||
{
|
||||
bool flag = condition[ConditionFlag.BoundByDuty];
|
||||
bool flag2 = condition[ConditionFlag.InDutyQueue];
|
||||
if (flag && !_wasInDuty)
|
||||
{
|
||||
logger.LogInformation("Entered duty for leveling");
|
||||
_wasInDuty = true;
|
||||
_idleStartTime = DateTime.MinValue;
|
||||
}
|
||||
if (flag || flag2)
|
||||
{
|
||||
_idleStartTime = DateTime.MinValue;
|
||||
}
|
||||
byte b = objectTable.LocalPlayer?.Level ?? 0;
|
||||
if (b >= base.Task.RequiredLevel)
|
||||
{
|
||||
logger.LogInformation("Reached required level {RequiredLevel} (current: {CurrentLevel})", base.Task.RequiredLevel, b);
|
||||
chatGui.Print($"Reached level {b}, can now continue MSQ.", "Questionable", 576);
|
||||
return ETaskResult.TaskComplete;
|
||||
}
|
||||
if (autoDutyIpc.IsStopped() && !flag && !flag2)
|
||||
{
|
||||
if (_idleStartTime == DateTime.MinValue)
|
||||
{
|
||||
_idleStartTime = DateTime.Now;
|
||||
}
|
||||
if (_wasInDuty && DateTime.Now - _idleStartTime > TimeSpan.FromSeconds(3L))
|
||||
{
|
||||
_ = base.Task.RequiredLevel;
|
||||
_lastStatusMessage = DateTime.Now;
|
||||
logger.LogInformation("Starting another leveling run (current: {CurrentLevel}, need: {RequiredLevel})", b, base.Task.RequiredLevel);
|
||||
autoDutyIpc.StartLevelingMode();
|
||||
_wasInDuty = false;
|
||||
_idleStartTime = DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
return ETaskResult.StillRunning;
|
||||
}
|
||||
|
||||
public void StopNow()
|
||||
{
|
||||
autoDutyIpc.Stop();
|
||||
}
|
||||
|
||||
public override bool ShouldInterruptOnDamage()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue