forked from RedGuides/MQ2Boxr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxr.cpp
445 lines (362 loc) · 10.4 KB
/
boxr.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#include <fmt/format.h>
#include "boxr.h"
#include "boxr_util.h"
#include <fmt/format.h>
#include <string_view>
// Need to pace macro commands; the macro has to issue a /doevents between
// each command.
#define MACRO_COMMAND_DELAY "/timed 3 "
template <typename... Args>
void boxrRunCommandf(std::string_view format, Args&&... args) {
auto command = fmt::format(format, std::forward<Args>(args)...);
if (LOGGER.isDebugEnabled()) {
DoCommandf(command.c_str());
LOGGER.debug("Running Command: {}", command);
} else {
DoCommandf("/squelch %s", command.c_str());
}
}
void MasterBoxControl::Pause() {
auto box = GetBox();
LOGGER.info("Pausing {}", box->GetName());
box->Pause();
}
void MasterBoxControl::Unpause() {
auto box = GetBox();
LOGGER.info("Unpausing {}", box->GetName());
box->Unpause();
}
void MasterBoxControl::Chase() {
LOGGER.info("Setting \ayCHASE\ax mode");
GetBox()->Chase();
}
void MasterBoxControl::Camp() {
LOGGER.info("Setting \ayCAMP\ax mode");
GetBox()->Camp();
}
void MasterBoxControl::Manual() {
LOGGER.info("Setting \ayMANUAL\ax mode");
GetBox()->Manual();
}
void MasterBoxControl::BurnNow() {
LOGGER.info("Burn phase NOW!");
GetBox()->BurnNow();
}
void MasterBoxControl::BurnOff() {
LOGGER.info("Burns are turned OFF!");
GetBox()->BurnOff();
}
void MasterBoxControl::BurnNamed() {
LOGGER.info("Burning NAMED!");
GetBox()->BurnNamed();
}
void MasterBoxControl::RaidAssistNum(int raidAssistNum) {
#if !defined(ROF2EMU) && !defined(UFEMU)
LOGGER.info("Setting \a-tRaidAssistNum\ax to \at{}\ax (\at{}\ax)", raidAssistNum, GetRaidMainAssistName(raidAssistNum));
LOGGER.debug("RaidAssist 1: {}", GetCharInfo()->raidData.MainAssistNames[0]);
LOGGER.debug("RaidAssist 2: {}", GetCharInfo()->raidData.MainAssistNames[1]);
LOGGER.debug("RaidAssist 3: {}", GetCharInfo()->raidData.MainAssistNames[2]);
GetBox()->SetRaidAssistNum(raidAssistNum);
#endif
}
bool MasterBoxControl::IsPaused() {
auto box = GetBox();
try {
LOGGER.debug("Checking if \aw{}\ax is paused by evaluating '\ay{}\ax'", box->GetName(), box->GetPauseQuery());
return EvaluateBooleanMacroExpression(box->GetPauseQuery());
} catch (std::runtime_error &e) {
throw InvalidBoxConfigurationException(fmt::format("Unable to determine whether \aw{}\ax is paused: {}", box->GetName(), e.what()));
}
}
std::string MasterBoxControl::Current() {
return GetBox()->GetKey();
}
MasterBoxControl::MasterBoxControl() {
// Assume that if a macro is running, it is controlling the character, even if
// a the class's CWTN plugin is loaded (since otherwise, why start the macro?)
boxes.push_back(std::make_shared<RGMercsControl>());
boxes.push_back(std::make_shared<KissAssistControl>());
boxes.push_back(std::make_shared<MuleAssistControl>());
boxes.push_back(std::make_shared<EntropyControl>());
boxes.push_back(std::make_shared<AlsoKissAssistControl>());
boxes.push_back(std::make_shared<XGenControl>());
boxes.push_back(std::make_shared<RGMercsLuaControl>());
boxes.push_back(std::make_shared<CwtnControl>());
}
std::shared_ptr<BoxControl> MasterBoxControl::GetBox() {
for (std::shared_ptr<BoxControl> box : boxes) {
if (box->IsRunning()) {
LOGGER.debug("Detected running: {}", box->GetName());
return box;
}
}
return this->noopControl;
}
void PauseTwist() {
if (GetPcProfile()->Class == Bard) {
boxrRunCommandf("/twist off");
}
}
bool RGMercsControl::IsRunning() {
return ci_starts_with(gszMacroName, "rgmercs");
}
void RGMercsControl::Pause() {
boxrRunCommandf("/mqp on");
PauseTwist();
}
void RGMercsControl::Unpause() {
boxrRunCommandf("/mqp off");
}
void RGMercsControl::Chase() {
boxrRunCommandf("/rg chaseon");
}
void RGMercsControl::Camp() {
boxrRunCommandf("/rg camphard");
}
void RGMercsControl::Manual() {
boxrRunCommandf("/rg chaseoff");
boxrRunCommandf(MACRO_COMMAND_DELAY "/rg campoff");
}
void RGMercsControl::BurnNow() {
LOGGER.info("BurnNow is not supported for rgmercs");
}
void RGMercsControl::BurnOff() {
LOGGER.info("BurnOff is not supported for rgmercs");
}
void RGMercsControl::BurnNamed() {
LOGGER.info("BurnNamed is not supported for rgmercs");
}
void RGMercsControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/rg AssistOutside 1");
boxrRunCommandf(MACRO_COMMAND_DELAY "/rg OutsideAssistList {}", GetRaidMainAssistName(raidAssistNum));
}
bool RGMercsLuaControl::IsRunning() {
return EvaluateBooleanMacroExpression("${Lua.Script[rgmercs].Status.Equal[RUNNING]}");
}
void RGMercsLuaControl::Pause() {
boxrRunCommandf("/rgl pause");
PauseTwist();
}
void RGMercsLuaControl::Unpause() {
boxrRunCommandf("/rgl unpause");
}
void RGMercsLuaControl::Chase() {
boxrRunCommandf("/rgl chaseon");
}
void RGMercsLuaControl::Camp() {
boxrRunCommandf("/rgl campon");
}
void RGMercsLuaControl::Manual() {
boxrRunCommandf("/rgl chaseoff");
boxrRunCommandf("/rgl campoff");
}
void RGMercsLuaControl::BurnNow() {
boxrRunCommandf("/rgl set BurnAlways 1");
}
void RGMercsLuaControl::BurnOff() {
boxrRunCommandf("/rgl set BurnAlways 0");
boxrRunCommandf("/rgl set BurnAuto 0");
}
void RGMercsLuaControl::BurnNamed() {
boxrRunCommandf("/rgl set BurnAuto 1");
}
void RGMercsLuaControl::SetRaidAssistNum(int raidAssistNum) {
LOGGER.info("RaidAssistNum is not supported for RGMercs - Lua edition");
}
bool KissAssistControl::IsRunning() {
return ci_starts_with(gszMacroName, "kiss");
}
void KissAssistControl::Pause() {
boxrRunCommandf("/mqp on");
PauseTwist();
}
void KissAssistControl::Unpause() {
boxrRunCommandf("/mqp off");
}
void KissAssistControl::Chase() {
boxrRunCommandf("/chaseon");
}
void KissAssistControl::Camp() {
boxrRunCommandf("/camphere on");
}
void KissAssistControl::Manual() {
boxrRunCommandf("/chaseoff");
boxrRunCommandf(MACRO_COMMAND_DELAY "/camphere off ");
}
void KissAssistControl::BurnNow() {
boxrRunCommandf("/burn on doburn");
}
void KissAssistControl::BurnOff() {
boxrRunCommandf("/burn off");
}
void KissAssistControl::BurnNamed() {
boxrRunCommandf("/burn on");
}
void KissAssistControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/switchma {} tank 1", GetRaidMainAssistName(raidAssistNum));
}
bool MuleAssistControl::IsRunning() {
return ci_starts_with(gszMacroName, "muleassist");
}
void MuleAssistControl::BurnNow() {
boxrRunCommandf("/burn");
}
void MuleAssistControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/changema {}", GetRaidMainAssistName(raidAssistNum));
}
bool AlsoKissAssistControl::IsRunning() {
return strstr(gszMacroName, "alsokissassist") != nullptr;
}
void AlsoKissAssistControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/switchma {}", GetRaidMainAssistName(raidAssistNum));
}
bool CwtnControl::IsRunning() {
return IsClassPluginLoaded();
}
void CwtnControl::Pause() {
boxrRunCommandf("/{} pause on", GetClassCommand());
}
void CwtnControl::Unpause() {
boxrRunCommandf("/{} pause off", GetClassCommand());
}
void CwtnControl::Chase() {
boxrRunCommandf("/{} mode chase", GetClassCommand());
}
void CwtnControl::Camp() {
boxrRunCommandf("/{} mode assist", GetClassCommand());
boxrRunCommandf("/{} resetcamp", GetClassCommand());
}
void CwtnControl::Manual() {
boxrRunCommandf("/{} mode manual", GetClassCommand());
}
void CwtnControl::BurnNow() {
boxrRunCommandf("/{} BurnNow", GetClassCommand());
}
void CwtnControl::BurnOff() {
boxrRunCommandf("/{} BurnAlways off", GetClassCommand());
boxrRunCommandf("/{} BurnAllNamed off", GetClassCommand());
}
void CwtnControl::BurnNamed() {
boxrRunCommandf("/{} BurnAllNamed on", GetClassCommand());
}
void CwtnControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/{} raidassistnum {}", GetClassCommand(), raidAssistNum);
}
bool EntropyControl::IsRunning() {
return ci_starts_with(gszMacroName, "entropy");
}
void EntropyControl::Pause() {
boxrRunCommandf("/mqp on");
}
void EntropyControl::Unpause() {
boxrRunCommandf("/mqp off");
}
void EntropyControl::Chase() {
boxrRunCommandf("/tie on");
}
void EntropyControl::Camp() {
boxrRunCommandf("/tie off");
boxrRunCommandf(MACRO_COMMAND_DELAY "/home set on");
}
void EntropyControl::Manual() {
boxrRunCommandf("/env auto off");
}
void EntropyControl::BurnNow() {
boxrRunCommandf("/burn force on");
LOGGER.info("Will burn all the time. Use \ay/burn force off\ax to stop burning.");
}
void EntropyControl::BurnOff() {
boxrRunCommandf("/burn force off");
boxrRunCommandf(MACRO_COMMAND_DELAY "/burn auto off");
LOGGER.info("All Burns turned off");
}
void EntropyControl::BurnNamed() {
boxrRunCommandf("/burn auto on");
LOGGER.info("Burn NAMED is on");
}
void EntropyControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/cc ass smart {}", raidAssistNum);
}
bool XGenControl::IsRunning() {
return ci_starts_with(gszMacroName, "xgen");
}
void XGenControl::Pause() {
boxrRunCommandf("/mqp on");
}
void XGenControl::Unpause() {
boxrRunCommandf("/mqp off");
}
void XGenControl::Chase() {
boxrRunCommandf("/cc follow");
boxrRunCommandf(MACRO_COMMAND_DELAY "/cc camp off");
}
void XGenControl::Camp() {
boxrRunCommandf("/cc camp on");
boxrRunCommandf(MACRO_COMMAND_DELAY "/cc follow off");
}
void XGenControl::Manual() {
boxrRunCommandf("/cc manual");
}
void XGenControl::BurnNow() {
boxrRunCommandf("/cc burnonce");
LOGGER.info("Will burn current mob only.");
}
void XGenControl::BurnOff() {
boxrRunCommandf("/cc burn off");
LOGGER.info("Burns turned off");
}
void XGenControl::BurnNamed() {
boxrRunCommandf("/cc burn on");
LOGGER.info("Burns are turned on.");
}
void XGenControl::SetRaidAssistNum(int raidAssistNum) {
boxrRunCommandf("/cc setassist {}", raidAssistNum);
}
const char* CwtnControl::GetClassCommand() {
return ClassInfo[GetPcProfile()->Class].ShortName;
}
bool CwtnControl::IsClassPluginLoaded() {
const char* classPluginName = GetClassPlugin();
if (classPluginName == nullptr) {
return false;
}
return IsPluginLoaded(classPluginName);
}
const char* CwtnControl::GetClassPlugin() {
switch (GetPcProfile()->Class) {
case Bard:
return "MQ2Bard";
case Beastlord:
return "MQ2Bst";
case Berserker:
return "MQ2BerZerker";
case Cleric:
return "MQ2Cleric";
case Druid:
return "MQ2Druid";
case Enchanter:
return "MQ2Enchanter";
case Mage:
return "MQ2Mage";
case Monk:
return "MQ2Monk";
case Necromancer:
return "MQ2Necro";
case Paladin:
return "MQ2Paladin";
case Ranger:
return "MQ2Ranger";
case Rogue:
return "MQ2Rogue";
case Shadowknight:
return "MQ2Eskay";
case Shaman:
return "MQ2Shaman";
case Warrior:
return "MQ2War";
case Wizard:
return "MQ2Wizard";
default:
return nullptr;
}
}