-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMQ2LootManager.cpp
More file actions
176 lines (148 loc) · 5.54 KB
/
MQ2LootManager.cpp
File metadata and controls
176 lines (148 loc) · 5.54 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
// MQ2LootManager.cpp : Defines the entry point for the DLL application.
//
// PLUGIN_API is only to be used for callbacks. All existing callbacks at this time
// are shown below. Remove the ones your plugin does not use. Always use Initialize
// and Shutdown for setup and cleanup, do NOT do it in DllMain.
#include <mq/Plugin.h>
#include "MQ2LootManagerFunctions.h"
bool bPaused = false;
PreSetup("MQ2LootManager");
PLUGIN_VERSION(1.0);
void CheckForLoreEquipped() {
if (CXWnd* ConfirmationWnd = FindMQ2Window("ConfirmationDialogBox")) {
if (ConfirmationWnd->IsVisible()) {
if (CStmlWnd* TextWnd = (CStmlWnd*)ConfirmationWnd->GetChildItem("CD_TextOutput")) {
if (TextWnd->GetSTMLText().find("group with an item you already possess") != CXStr::npos) {
if (CButtonWnd* YesBttn = (CButtonWnd*)ConfirmationWnd->GetChildItem("CD_Yes_Button")) {
SendWndClick2(YesBttn, "leftmouseup");
}
}
}
}
}
}
void LootMgrCmd(PSPAWNINFO pSpawn, char* szLine) {
char szArg[MAX_STRING] = { 0 };
GetArg(szArg, szLine, 1);
if (!_stricmp(szArg, "pause")) {
GetArg(szArg, szLine, 2);
if (!strlen(szArg)) {
bPaused = !bPaused;
WriteChatf("%s%s", PluginMsg.c_str(), (bPaused ? "Paused" : "Unpaused"));
}
else if (!_stricmp(szArg, "on")) {
bPaused = true;
WriteChatf("%sPaused", PluginMsg.c_str());
}
else if (!_stricmp(szArg, "off")) {
bPaused = false;
WriteChatf("%sUnpaused", PluginMsg.c_str());
}
return;
}
//User didn't issue a command. Just tell them the status of pause.
WriteChatf("%s%s", PluginMsg.c_str(), (bPaused ? "Paused" : "Unpaused"));
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
AddCommand("/lootmanager", LootMgrCmd);
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
RemoveCommand("/lootmanager");
}
// This is called every time MQ pulses
PLUGIN_API VOID OnPulse(VOID)
{
if (bPaused)//if the plugin is paused, just wait.
return;
{//only pulse every 500 ticks. (every half second? Maybe too fast.)
static uint64_t PulseTimer = 0;
if (PulseTimer > GetTickCount64())
return;
PulseTimer = GetTickCount64() + 500;
}
//If I'm InGame()
if (GetGameState() == GAMESTATE_INGAME && GetCharInfo() && GetCharInfo()->pSpawn && GetPcProfile()) {
//Default to assume if we don't have any giant slots left, we can't carry anything.
//TODO: Make this smarter, based on the item we plan to pickup to see if we can hold that item.
static bool OutOfSpace = false;
if (!GetFreeInventory(Giant)) {
if (!OutOfSpace) {
WriteChatf("%s\arOut of Space!! Clean up your bags you slob!", PluginMsg.c_str());
OutOfSpace = true;
}
return;
}
else if (OutOfSpace) {
WriteChatf("%s\agWe got space again, resuming looting.", PluginMsg.c_str());
OutOfSpace = false;
}
static bool IAmML = false;
if (IAmMasterLooter()) {
if (!IAmML) {
WriteChatf("%sI should collect the loot.", PluginMsg.c_str());
IAmML = true;
}
}
else if (IAmML) {
WriteChatf("%sNo longer collecting the loot.", PluginMsg.c_str());
IAmML = false;
}
if (pAdvancedLootWnd) {//If I'm the master looter and AutoLootAllIsOn.
PCHARINFO pChar = GetCharInfo();
if (!pChar)
return;
PcProfile* pChar2 = GetPcProfile();
if (!pChar2)
return;
CAdvancedLootWnd* pAdvLoot = (CAdvancedLootWnd*)pAdvancedLootWnd;
if (!pAdvLoot)
return;
CListWnd* pPersonalList;
CListWnd* pSharedList;
if (!pAdvLoot->pPLootList || !pAdvLoot->pPLootList->PersonalLootList) {
return;
}
else {
//pPersonalList = (CListWnd*)pAdvLoot->pPLootList->PersonalLootList; This doesn't work, but using this method works for SharedLootList Something broken?
pPersonalList = (CListWnd*)pAdvancedLootWnd->GetChildItem("ADLW_PLLList");
}
if (!pPersonalList)
return;
if (!pAdvLoot->pCLootList || !pAdvLoot->pCLootList->SharedLootList) {
return;
}
else {
pSharedList = (CListWnd*)pAdvLoot->pCLootList->SharedLootList;
}
if (!pSharedList)
return;
//Can't Loot if already Looting.
if (LootInProgress(pAdvLoot, pPersonalList, pSharedList)) {
return;
}
//Do Looting shit here. Personal list first, shared list next.
if (pPersonalList) {
if (HandlePersonalLoot(pChar, pChar2, pAdvLoot, pPersonalList, pSharedList)) {
return;
}
}
if (pSharedList) {
if (IAmML && HandleSharedLoot(pChar, pChar2, pAdvLoot, pPersonalList, pSharedList)) {
return;
}
}
}
//Handle "Lore-Equipped Message.
/*Example
* Penumbra Pauldrons shares a LORE_EQUIP group with an item you already possess, are you sure you wish to loot it?
*
* Found window is ConfirmationDialogBox
* Sub Window for above example text is CD_TextOutput
*/
CheckForLoreEquipped();
}//InGame()
}