refactor
This commit is contained in:
parent
2d6a6bd3a1
commit
d80e723b94
28 changed files with 1801 additions and 352 deletions
|
|
@ -24,8 +24,8 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
{
|
||||
private bool _paused;
|
||||
private string _state = "Idle";
|
||||
private int _tradesCompleted;
|
||||
private int _tradesFailed;
|
||||
private volatile int _tradesCompleted;
|
||||
private volatile int _tradesFailed;
|
||||
private readonly long _startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
private bool _started;
|
||||
|
||||
|
|
@ -40,6 +40,11 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
public TradeExecutor TradeExecutor { get; }
|
||||
public TradeQueue TradeQueue { get; }
|
||||
public NavigationExecutor Navigation { get; }
|
||||
public FramePipelineService PipelineService { get; }
|
||||
public GameStateDetector GameState { get; }
|
||||
public HudReader HudReader { get; }
|
||||
public EnemyDetector EnemyDetector { get; }
|
||||
public FrameSaver FrameSaver { get; }
|
||||
private readonly Dictionary<string, ScrapExecutor> _scrapExecutors = new();
|
||||
|
||||
// Events
|
||||
|
|
@ -49,7 +54,7 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
public BotOrchestrator(ConfigStore store, IGameController game, IScreenReader screen,
|
||||
IClientLogWatcher logWatcher, ITradeMonitor tradeMonitor,
|
||||
IInventoryManager inventory, TradeExecutor tradeExecutor,
|
||||
TradeQueue tradeQueue, LinkManager links)
|
||||
TradeQueue tradeQueue, LinkManager links, FramePipelineService pipelineService)
|
||||
{
|
||||
Store = store;
|
||||
Game = game;
|
||||
|
|
@ -60,7 +65,26 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
TradeExecutor = tradeExecutor;
|
||||
TradeQueue = tradeQueue;
|
||||
Links = links;
|
||||
Navigation = new NavigationExecutor(game);
|
||||
PipelineService = pipelineService;
|
||||
|
||||
// Create consumers
|
||||
var minimapCapture = new MinimapCapture(new MinimapConfig(), pipelineService.Backend);
|
||||
GameState = new GameStateDetector();
|
||||
HudReader = new HudReader();
|
||||
EnemyDetector = new EnemyDetector();
|
||||
FrameSaver = new FrameSaver();
|
||||
|
||||
// Register on shared pipeline
|
||||
pipelineService.Pipeline.AddConsumer(minimapCapture);
|
||||
pipelineService.Pipeline.AddConsumer(GameState);
|
||||
pipelineService.Pipeline.AddConsumer(HudReader);
|
||||
pipelineService.Pipeline.AddConsumer(EnemyDetector);
|
||||
pipelineService.Pipeline.AddConsumer(FrameSaver);
|
||||
|
||||
// Pass shared pipeline to NavigationExecutor
|
||||
Navigation = new NavigationExecutor(game, pipelineService.Pipeline, minimapCapture,
|
||||
enemyDetector: EnemyDetector);
|
||||
|
||||
logWatcher.AreaEntered += _ => Navigation.Reset();
|
||||
logWatcher.Start(); // start early so area events fire even before Bot.Start()
|
||||
_paused = store.Settings.Paused;
|
||||
|
|
@ -205,8 +229,8 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
// Wire executor events
|
||||
TradeExecutor.StateChanged += _ => UpdateExecutorState();
|
||||
Navigation.StateChanged += _ => UpdateExecutorState();
|
||||
TradeQueue.TradeCompleted += () => { _tradesCompleted++; StatusUpdated?.Invoke(); };
|
||||
TradeQueue.TradeFailed += () => { _tradesFailed++; StatusUpdated?.Invoke(); };
|
||||
TradeQueue.TradeCompleted += () => { Interlocked.Increment(ref _tradesCompleted); StatusUpdated?.Invoke(); };
|
||||
TradeQueue.TradeFailed += () => { Interlocked.Increment(ref _tradesFailed); StatusUpdated?.Invoke(); };
|
||||
Inventory.Updated += () => StatusUpdated?.Invoke();
|
||||
|
||||
_started = true;
|
||||
|
|
@ -267,9 +291,11 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
Log.Information("Shutting down bot...");
|
||||
foreach (var exec in _scrapExecutors.Values)
|
||||
await exec.Stop();
|
||||
EnemyDetector.Dispose();
|
||||
Screen.Dispose();
|
||||
await TradeMonitor.DisposeAsync();
|
||||
LogWatcher.Dispose();
|
||||
PipelineService.Dispose();
|
||||
}
|
||||
|
||||
private void OnNewListings(string searchId, List<string> itemIds, IPage page)
|
||||
|
|
@ -302,8 +328,8 @@ public class BotOrchestrator : IAsyncDisposable
|
|||
{
|
||||
var scrapExec = new ScrapExecutor(Game, Screen, TradeMonitor, Inventory, Config);
|
||||
scrapExec.StateChanged += _ => UpdateExecutorState();
|
||||
scrapExec.ItemBought += () => { _tradesCompleted++; StatusUpdated?.Invoke(); };
|
||||
scrapExec.ItemFailed += () => { _tradesFailed++; StatusUpdated?.Invoke(); };
|
||||
scrapExec.ItemBought += () => { Interlocked.Increment(ref _tradesCompleted); StatusUpdated?.Invoke(); };
|
||||
scrapExec.ItemFailed += () => { Interlocked.Increment(ref _tradesFailed); StatusUpdated?.Invoke(); };
|
||||
_scrapExecutors[link.Id] = scrapExec;
|
||||
Emit("info", $"Scrap loop started: {link.Name}");
|
||||
StatusUpdated?.Invoke();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue