forked from julianperrott/WowClassicGrindBot
-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathHeadlessServer.cs
More file actions
119 lines (96 loc) · 3.55 KB
/
HeadlessServer.cs
File metadata and controls
119 lines (96 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using CommandLine;
using Core;
using Game;
using Microsoft.Extensions.Logging;
using static System.Diagnostics.Stopwatch;
namespace HeadlessServer;
public sealed partial class HeadlessServer
{
private readonly ILogger<HeadlessServer> logger;
private readonly IBotController botController;
private readonly IAddonReader addonReader;
private readonly ActionBarCostReader actionBarCostReader;
private readonly SpellBookReader spellBookReader;
private readonly BagReader bagReader;
private readonly KeyBindingsReader keyBindingsReader;
private readonly WowProcessInput wowInput;
private readonly Wait wait;
public HeadlessServer(ILogger<HeadlessServer> logger,
IBotController botController,
IAddonReader addonReader,
ActionBarCostReader actionBarCostReader,
SpellBookReader spellBookReader,
BagReader bagReader,
KeyBindingsReader keyBindingsReader,
WowProcessInput wowInput,
Wait wait)
{
this.logger = logger;
this.botController = botController;
this.addonReader = addonReader;
this.actionBarCostReader = actionBarCostReader;
this.spellBookReader = spellBookReader;
this.bagReader = bagReader;
this.keyBindingsReader = keyBindingsReader;
this.wowInput = wowInput;
this.wait = wait;
}
public void Run(ParserResult<RunOptions> options)
{
InitState();
botController.LoadClassProfile(options.Value.ClassConfig!);
botController.ToggleBotStatus();
}
public bool RunLoadOnly(ParserResult<RunOptions> options)
{
return botController.LoadClassProfile(options.Value.ClassConfig!);
}
private void InitState()
{
addonReader.FullReset();
wowInput.PressFlushKey();
const int CELL_UPDATE_TICK = 5 * 2;
int actionbarCost;
int spellBook;
int bag;
int keyBindings;
long startTime = GetTimestamp();
do
{
actionbarCost = actionBarCostReader.Count;
spellBook = spellBookReader.Count;
bag = bagReader.BagItems.Count;
keyBindings = keyBindingsReader.Count;
for (int i = 0; i < CELL_UPDATE_TICK; i++)
wait.Update();
if (actionbarCost != actionBarCostReader.Count ||
spellBook != spellBookReader.Count ||
bag != bagReader.BagItems.Count ||
keyBindings != keyBindingsReader.Count)
{
LogInitStateStatus(logger, actionbarCost, spellBook, bag, keyBindings);
}
} while (
actionbarCost != actionBarCostReader.Count ||
spellBook != spellBookReader.Count ||
bag != bagReader.BagItems.Count ||
keyBindings != keyBindingsReader.Count);
if (logger.IsEnabled(LogLevel.Information))
{
float elapsed = (float)GetElapsedTime(startTime).TotalSeconds;
LogInitStateEnd(logger, elapsed);
}
}
#region Logging
[LoggerMessage(
EventId = 4000,
Level = LogLevel.Information,
Message = "Actionbar: {actionbar,3} | SpellBook: {spellBook,3} | Bag: {bag,3} | Bindings: {keyBindings,3}")]
static partial void LogInitStateStatus(ILogger logger, int actionbar, int spellbook, int bag, int keyBindings);
[LoggerMessage(
EventId = 4001,
Level = LogLevel.Information,
Message = "InitState {elapsedSec}sec")]
static partial void LogInitStateEnd(ILogger logger, float elapsedSec);
#endregion
}