-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMQ2TributeManager.cpp
More file actions
375 lines (335 loc) · 8.89 KB
/
MQ2TributeManager.cpp
File metadata and controls
375 lines (335 loc) · 8.89 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
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
// MQ2TributeManager.cpp : Defines the entry point for the DLL application.
//
// MQ2TributeManager
// Manages tribute for you based on combat status
// Author: alt228, alt228@nerdshack.com
//
// Now Saves/Loads previous settings. Still defaults to manual - wired420
// Added option to turn tribute on for names, then back off when no named
// and timer is close to out. - wired420
#include <mq/Plugin.h>
PreSetup("MQ2TributeManager");
PLUGIN_VERSION(1.1);
fEQCommand cmdTribute = nullptr;
enum TributeMode
{
TributeMode_Manual,
TributeMode_Auto,
TributeMode_OffWhenExpired,
TributeMode_Named,
TributeMode_Unused
};
enum CombatState
{
CombatState_COMBAT,
CombatState_DEBUFFED,
CombatState_COOLDOWN,
CombatState_ACTIVE,
CombatState_RESTING
};
// Save & Load
char szTemp[MAX_STRING] = { 0 };
char ourMode[MAX_STRING] = { 0 };
bool initDone = false;
//defaults
TributeMode mode = TributeMode_Manual;
int tributeFudge = 2000;
#define SKIP_PULSES 80
long SkipPulse = 0;
void updateINIFn() {
sprintf_s(INIFileName, "%s\\%s_%s.ini", gPathConfig, GetServerShortName(), pLocalPC->Name);
}
void SaveINI() {
updateINIFn();
sprintf_s(szTemp, "MQ2TributeManager");
WritePrivateProfileSection(szTemp, "", INIFileName);
if (mode == TributeMode_Named) {
WritePrivateProfileString(szTemp, "Mode", "3", INIFileName);
}
else if (mode == TributeMode_Auto) {
WritePrivateProfileString(szTemp, "Mode", "2", INIFileName);
}
else if (mode == TributeMode_OffWhenExpired) {
WritePrivateProfileString(szTemp, "Mode", "1", INIFileName);
}
else {
WritePrivateProfileString(szTemp, "Mode", "0", INIFileName);
}
}
void LoadINI() {
updateINIFn();
sprintf_s(szTemp, "MQ2TributeManager");
DWORD loadMode = GetPrivateProfileString(szTemp, "Mode", "", ourMode, MAX_STRING, INIFileName);
int setTheMode = atoi(ourMode);
if (setTheMode == 0) {
mode = TributeMode_Manual;
}
else if (setTheMode == 1) {
mode = TributeMode_OffWhenExpired;
}
else if (setTheMode == 2) {
mode = TributeMode_Auto;
}
else if (setTheMode == 3) {
mode = TributeMode_Named;
}
initDone = true;
}
void SetTributeStatus(bool tributeOn)
{
if (tributeOn)
{
if (!(bool)((*pTributeActive) ? true : false))
{
DebugSpewAlways("MQ2TributeManager::Turning on tribute");
DoCommand("/notify TributeBenefitWnd TBWP_ActivateButton leftmouseup");
DoCommand("/notify TributeBenefitWnd TBWT_ActivateButton leftmouseup");
}
}
else
{
if ((bool)((*pTributeActive) ? true : false))
{
DebugSpewAlways("MQ2TributeManager::Turning off tribute");
DoCommand("/notify TributeBenefitWnd TBWP_ActivateButton leftmouseup");
DoCommand("/notify TributeBenefitWnd TBWT_ActivateButton leftmouseup");
}
}
}
void TributeManagerCmd(PlayerClient* characterSpawn, const char* line)
{
bool syntaxError = false;
if (line[0] == 0)
{
syntaxError = true;
}
bool setMode = false;
TributeMode newMode = TributeMode_Unused;
bool setStatus = false;
bool newStatus = true;
bool showStatus = false;
char thisArg[MAX_STRING] = { 0 };
int argNumber = 1;
bool moreArgs = true;
// FIXME: Why is this counting to 9 when the max arg length appears to be 2?
while (moreArgs && argNumber < 10)
{
DebugSpewAlways("MQ2TributeManager:: GetArg(%i)", argNumber);
GetArg(thisArg, line, argNumber);
if (thisArg[0] == '\0')
{
moreArgs = false;
}
// Account for the usage of the original EQ command
else if (argNumber == 1 && (ci_equals(thisArg, "personal") || ci_equals(thisArg, "guild")))
{
if (cmdTribute != nullptr)
{
cmdTribute(characterSpawn, line);
}
return;
}
else if (_stricmp(thisArg, "on") == 0)
{
setStatus = true;
newStatus = true;
}
else if (_stricmp(thisArg, "off") == 0)
{
setMode = true;
newMode = TributeMode_OffWhenExpired;
WriteChatColor("Tribute mode: off when expired");
}
else if (_stricmp(thisArg, "forceoff") == 0)
{
setStatus = true;
newStatus = false;
setMode = true;
newMode = TributeMode_Manual;
}
else if (_stricmp(thisArg, "auto") == 0)
{
setMode = true;
newMode = TributeMode_Auto;
WriteChatColor("Tribute mode: automatic");
}
else if (_stricmp(thisArg, "named") == 0)
{
setMode = true;
newMode = TributeMode_Named;
WriteChatColor("Tribute mode: named");
}
else if (_stricmp(thisArg, "manual") == 0)
{
setMode = true;
newMode = TributeMode_Manual;
WriteChatColor("Tribute mode: manual");
}
else if (_stricmp(thisArg, "show") == 0)
{
showStatus = true;
}
else
{
syntaxError = true;
}
argNumber++;
}
if (syntaxError)
{
SyntaxError("Usage: /tribute <auto|named|manual|on|off|forceoff|show>");
return;
}
if (setStatus)
{
SetTributeStatus(newStatus);
}
if (setMode)
{
mode = newMode;
SaveINI();
}
if (showStatus)
{
if (mode == TributeMode_Manual)
{
WriteChatColor("Tribute mode: manual");
}
else if (mode == TributeMode_Auto)
{
WriteChatColor("Tribute mode: automatic");
}
else if (mode == TributeMode_Named)
{
WriteChatColor("Tribute mode: Named");
}
else if (mode == TributeMode_OffWhenExpired)
{
WriteChatColor("Tribute mode: off when expired");
}
if (gGameState == GAMESTATE_INGAME)
{
DebugSpewAlways("MQ2TributeManager:: Active Favor Cost: %i", pTribute->GetActiveFavorCost());
DebugSpewAlways("MQ2TributeManager:: Combat State: %i", pPlayerWnd->CombatState);
DebugSpewAlways("MQ2TributeManager:: Tribute Active: %i", *pTributeActive);
DebugSpewAlways("MQ2TributeManager:: Current Favor: %i", GetCharInfo()->CurrFavor);
DebugSpewAlways("MQ2TributeManager:: Tribute Timer: %i ms", GetCharInfo()->TributeTimer);
}
}
}
// Called once, when the plugin is to initialize
PLUGIN_API void InitializePlugin()
{
DebugSpewAlways("Initializing MQ2TributeManager");
// Capture the original EQ /tribute command before we override it
cmdTribute = FindEQCommand("/tribute");
AddCommand("/tribute", TributeManagerCmd);
}
// Called once, when the plugin is to shutdown
PLUGIN_API void ShutdownPlugin()
{
DebugSpewAlways("Shutting down MQ2TributeManager");
RemoveCommand("/tribute");
// Restore the original EQ /tribute command
if (cmdTribute != nullptr)
{
AddCommand("/tribute", cmdTribute, true);
}
}
PLUGIN_API void SetGameState(int GameState)
{
DebugSpewAlways("MQ2TributeManager::SetGameState()");
// FIXME: GameState is set while zoning and there's no reason to load the ini every zone
if (GameState == GAMESTATE_INGAME)
{
if (!initDone) {
LoadINI();
}
// have to do a little hack here or else other /notify commands will not work
DebugSpewAlways("MQ2TributeManager::SetGameState::initializing tribute window");
DoCommand("/keypress TOGGLE_TRIBUTEBENEFITWIN");
DoCommand("/keypress TOGGLE_TRIBUTEBENEFITWIN");
}
if (GameState != GAMESTATE_INGAME && GameState != GAMESTATE_LOGGINGIN) {
if (initDone) {
initDone = false;
}
}
}
// Are we in combat? We used this check enough that it was time to quit replicating code - wired420
bool inCombat() {
return pPlayerWnd->CombatState == eCombatState_Combat;
}
// Check group main assist for a named target.
bool checkGroupAssistTarget()
{
if (IsNamed(GetSpawnByID(GetGroupMainAssistTargetID())))
{
return true;
}
return false;
}
// Check the three possible raid main assists for a named target.
bool checkRaidAssistTarget()
{
for (int iAssist = 0; iAssist < 3; iAssist++)
{
if (IsNamed(GetSpawnByID(GetRaidMainAssistTargetID(iAssist))))
{
return true;
}
}
return false;
}
// This is called every time MQ pulses
PLUGIN_API void OnPulse()
{
if (gGameState != GAMESTATE_INGAME)
return;
if (!initDone)
return;
if (SkipPulse == SKIP_PULSES) {
SkipPulse = 0;
if (mode == TributeMode_Named)
{
unsigned int activeFavorCost = pTribute->GetActiveFavorCost();
PCHARINFO myCharInfo = GetCharInfo();
if ((inCombat() && !*pTributeActive) && ((pTarget && IsNamed(pTarget)) || (checkRaidAssistTarget() || checkGroupAssistTarget())) && (activeFavorCost <= myCharInfo->CurrFavor) && (activeFavorCost > 0))
{
SetTributeStatus(true);
}
else if (*pTributeActive && (!inCombat() || (inCombat() && pTarget && (!IsNamed(pTarget) || !checkRaidAssistTarget() || !checkGroupAssistTarget()))) && (myCharInfo->TributeTimer < tributeFudge))
{
SetTributeStatus(false);
}
}
if (mode == TributeMode_Auto)
{
unsigned int activeFavorCost = pTribute->GetActiveFavorCost();
PCHARINFO myCharInfo = GetCharInfo();
if ((inCombat()) && (!*pTributeActive) && (activeFavorCost <= myCharInfo->CurrFavor) && (activeFavorCost > 0))
{
//activate tribute
SetTributeStatus(true);
}
else if ((!inCombat()) && (*pTributeActive) && (myCharInfo->TributeTimer < tributeFudge))
{
SetTributeStatus(false);
}
}
else if (mode == TributeMode_OffWhenExpired)
{
if (((*pTributeActive) ? true : false) == false)
{
mode = TributeMode_Manual;
return;
}
if (GetCharInfo()->TributeTimer < tributeFudge)
{
mode = TributeMode_Manual;
SetTributeStatus(false);
}
}
}
SkipPulse++;
}