-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMQ2TSTrophy.cpp
More file actions
461 lines (416 loc) · 13.5 KB
/
MQ2TSTrophy.cpp
File metadata and controls
461 lines (416 loc) · 13.5 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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/**
MQ2TSTrophy by Sic & CWTN; a RedGuides Exclusive
Purpose: Equipping your Tradeskill Trophies when opening an environmental crafting container.
Actions: This plugin will see if you have a trophy that matches the environmental container you have open,
if it is not equipped, it will equip it. It does not swap back to anything.
**/
#include <mq/Plugin.h>
PreSetup("MQ2TSTrophy");
PLUGIN_VERSION(3.1);
const std::string pluginname = "\ar[\atMQ2TSTrophy\ar]\aw:: ";
bool WorldContainerCheck();
bool InGame();
void EquipTrophy(const char* pTrophy, const char* pSlot = "Ammo"); // Defaulted to ammo slot
std::string TrophyCheckByType(const std::string& trophytype);
bool IsTrophyEquipped(const std::string& trophy);
ItemClient* Cursor();
bool containerfound = false;
bool bMatches = false;
char szContainerName[32] = { 0 };
int iStep = 1;
int iPulse = 0;
const std::vector<int> vSlot = {
eInventorySlot::InvSlot_Ammo,
eInventorySlot::InvSlot_Range,
eInventorySlot::InvSlot_Primary,
eInventorySlot::InvSlot_Secondary
};
class MQ2TrophyType : public MQ2Type
{
public:
enum TrophyMembers
{
Version,
Matches,
Alchemy,
Baking,
Brewing,
Fletching,
Jewelry,
Tinkering,
Pottery,
Research,
Blacksmithing,
Tailoring,
Poison,
Fishing,
Container,
};
MQ2TrophyType() : MQ2Type("Trophy") {
TypeMember(Version);
TypeMember(Matches);
TypeMember(Alchemy);
TypeMember(Baking);
TypeMember(Brewing);
TypeMember(Fletching);
TypeMember(Jewelry);
TypeMember(Tinkering);
TypeMember(Pottery);
TypeMember(Research);
TypeMember(Blacksmithing);
TypeMember(Tailoring);
TypeMember(Poison);
TypeMember(Fishing);
TypeMember(Container);
};
~MQ2TrophyType()
{
}
virtual bool GetMember(MQVarPtr VarPtr, const char* Member, char* Index, MQTypeVar& Dest) override
{
MQTypeMember* pMember = MQ2TrophyType::FindMember(Member);
if (!pMember)
return false;
if (!pLocalPlayer)
return false;
switch ((TrophyMembers)pMember->ID)
{
case Version:
Dest.Float = MQ2Version;
Dest.Type = mq::datatypes::pFloatType;
return true;
case Matches: // this will return true/false if our equipped tradeskill trophy matches the world/enviro container we are in
Dest.DWord = bMatches;
Dest.Type = mq::datatypes::pBoolType;
return true;
case Alchemy:
strcpy_s(DataTypeTemp, TrophyCheckByType("Alchemy").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Baking:
strcpy_s(DataTypeTemp, TrophyCheckByType("Baking").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Brewing:
strcpy_s(DataTypeTemp, TrophyCheckByType("Brewing").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Fletching:
strcpy_s(DataTypeTemp, TrophyCheckByType("Fletching").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Jewelry:
strcpy_s(DataTypeTemp, TrophyCheckByType("Jewelry").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Tinkering:
strcpy_s(DataTypeTemp, TrophyCheckByType("Tinkering").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Pottery:
strcpy_s(DataTypeTemp, TrophyCheckByType("Pottery").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Research:
strcpy_s(DataTypeTemp, TrophyCheckByType("Research").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Blacksmithing:
strcpy_s(DataTypeTemp, TrophyCheckByType("Blacksmithing").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Tailoring:
strcpy_s(DataTypeTemp, TrophyCheckByType("Tailoring").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Poison:
strcpy_s(DataTypeTemp, TrophyCheckByType("Poison").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Fishing:
strcpy_s(DataTypeTemp, TrophyCheckByType("Fishing").c_str());
Dest.Ptr = DataTypeTemp;
Dest.Type = mq::datatypes::pStringType;
return true;
case Container: // this returns true/false if we see a world/enviro tradeskill container
Dest.DWord = containerfound;
Dest.Type = mq::datatypes::pBoolType;
return true;
default:
break;
}
return false;
}
bool ToString(MQVarPtr VarPtr, const char* Destination)
{
return true;
}
};
MQ2TrophyType* pTrophyType = nullptr;
bool TrophyData(const char* szIndex, MQTypeVar& Dest)
{
Dest.DWord = 1;
Dest.Type = pTrophyType;
return true;
}
PLUGIN_API void InitializePlugin()
{
DebugSpewAlways("Initializing MQ2TSTrophy");
AddMQ2Data("Trophy", TrophyData);
pTrophyType = new MQ2TrophyType;
}
PLUGIN_API void ShutdownPlugin()
{
DebugSpewAlways("Shutting down MQ2TSTrophy");
RemoveMQ2Data("Trophy");
delete pTrophyType;
}
PLUGIN_API int OnIncomingChat(const char* pLine, unsigned long Color)
{
return 0;
}
PLUGIN_API void OnPulse()
{
int iPulseDelay = 20;
if (!InGame()) return;
if (++iPulse < iPulseDelay) return;
iPulse = 0;
WorldContainerCheck();
if (iStep == 3) {
if (ItemOnCursor()) {
EzCommand("/autoinv");
}
iStep = 4;
}
if (containerfound) {
std::string type;
if (strstr(szContainerName, "Alchemy Table")) {
type = "Alchemy";
}
else if (strstr(szContainerName, "Mixing Bowl") || strstr(szContainerName, "Oven") || strstr(szContainerName, "Ice Cream")) {
type = "Baking";
}
else if (strstr(szContainerName, "Brewing Barrel")) {
type = "Brewing";
}
else if (strstr(szContainerName, "Fletching Table")) {
type = "Fletching";
}
else if (strstr(szContainerName, "Jewelry Making Table")) {
type = "Jewelry";
}
else if (strstr(szContainerName, "Fly Making Bench")) {
type = "Fishing";
}
else if (strstr(szContainerName, "Kiln") || strstr(szContainerName, "Pottery Wheel")) {
type = "Pottery";
}
else if (strstr(szContainerName, "Poisoncrafting Table")) {
type = "Poison";
}
else if (strstr(szContainerName, "Forge")) {
type = "Blacksmithing";
}
else if (strstr(szContainerName, "Spell Research Table")) {
type = "Research";
}
else if (strstr(szContainerName, "Loom")) {
type = "Tailoring";
}
else if (strstr(szContainerName, "Tinkering")) {
type = "Tinkering";
}
else {
containerfound = false;
}
if (!type.empty()) {
auto needtrophy = TrophyCheckByType(type);
if (!needtrophy.empty() && !IsTrophyEquipped(needtrophy)) {
bMatches = false;
if (type == "Fishing" || (type == "Tailoring" && string_equals(needtrophy, "Blessed Akhevan Shadow Shears"))) {
// Fishing is the only item that requires mainhand
// Blessed Ahkevan Shadow Shears requires pri or secondary
EquipTrophy(needtrophy.c_str(), "Mainhand");
}
else
EquipTrophy(needtrophy.c_str());
}
else {
bMatches = true;
}
}
if (iStep == 4) {
iStep = 1;
}
}
else {
if (iStep > 1)
iStep = 1;
}
}
PLUGIN_API void OnZoned()
{
if (!InGame()) return;
iStep = 1;
}
// This checks any "world containers" like a ground spawn crafting bench/table
bool WorldContainerCheck()
{
if (CContainerMgr* pWnd = pContainerMgr) {
ItemClient* thiscontaineritem = pWnd->pWorldContainer;
if (thiscontaineritem && thiscontaineritem->Open == 1) {
if (ItemDefinition* worldContainer = GetItemFromContents(thiscontaineritem)) {
strcpy_s(szContainerName, worldContainer->Name);
containerfound = true;
}
}
else {
containerfound = false;
}
}
return containerfound;
}
void EquipTrophy(const char* pTrophy, const char* pSlot)
{
for (const auto& i : vSlot) {
if (pTrophy) {
char szBuffer[128] = { 0 };
if (iStep == 1) {
WriteChatf("%s\ayPicking up: \ap%s", pluginname.c_str(), pTrophy);
sprintf_s(szBuffer, "/squelch /nomodkey /shiftkey /itemnotify \"%s\" leftmouseup", pTrophy);
EzCommand(szBuffer);
iStep = 2;
}
else if (iStep == 2) {
if (ItemClient* pCursor = Cursor()) {
if (!_stricmp(pCursor->GetName(), pTrophy)) {
WriteChatf("%s\aySwapping: \ap%s\aw into slot: \ay%s", pluginname.c_str(), pTrophy, pSlot);
sprintf_s(szBuffer, "/squelch /nomodkey /shiftkey /itemnotify %s leftmouseup", pSlot);
EzCommand(szBuffer);
iStep = 3;
}
}
}
}
}
}
bool IsTrophyEquipped(const std::string& trophy)
{
bool equipped = false;
for (const auto& i : vSlot) {
if (ItemClient* pItem = FindItemBySlot(i)) {
if (pItem->GetItemDefinition()->Name == trophy) {
equipped = true;
}
}
}
return equipped;
}
ItemClient* Cursor()
{
return GetPcProfile()->GetInventorySlot(InvSlot_Cursor);
}
inline bool InGame()
{
return GetGameState() == GAMESTATE_INGAME && pLocalPlayer && pLocalPC && GetPcProfile();
}
std::map <const std::string, std::vector<std::string> > mTrophies = {
{ "Alchemy", {
// Mundunugu: 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Mundunugu Medicine Stick", "Master Alchemist Trophy", "Expert Alchemist Trophy", "Journeyman Alchemist Trophy",
"Freshman Alchemist Trophy", "Apprentice Alchemist Trophy", "Beginner Alchemist Trophy"
}
},
{ "Baking", {
// Denmother's: 15%|50, 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Denmother's Rolling Pin", "Master Baker Trophy", "Expert Baker Trophy", "Journeyman Baker Trophy",
"Grandmaster Baker's Spoon", "Freshman Baker Trophy", "Apprentice Baker Trophy", "Beginner Baker Trophy"
}
},
{ "Brewing", {
// Brewmaster's: 15%|50, 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Brewmaster's Mug", "Master Brewer Trophy", "Expert Brewer Trophy", "Journeyman Brewer Trophy",
"Grandmaster Brewer's Corker", "Freshman Brewer Trophy", "Apprentice Brewer Trophy", "Beginner Brewer Trophy"
}
},
{ "Fletching", {
// Fletcher's: 15%|50, 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Fletcher's Arrow", "Master Fletcher Trophy", "Expert Fletcher Trophy", "Journeyman Fletcher Trophy",
"Grandmaster Fletcher's Knife", "Freshman Fletcher Trophy", "Apprentice Fletcher Trophy", "Beginner Fletcher Trophy"
}
},
{ "Jewelry", {
// Intricate: 15%|50, 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Intricate Jewelers Glass", "Master Jeweler Trophy", "Expert Jeweler Trophy", "Journeyman Jeweler Trophy",
"Grandmaster Jeweler's Eyeglass", "Freshman Jeweler Trophy", "Apprentice Jeweler Trophy", "Beginner Jeweler Trophy"
}
},
{ "Tinkering", {
// Hovering: 15%|50, 15%|50, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Hovering Contraption", "Master Mechanist Trophy", "Expert Mechanist Trophy", "Journeyman Mechanist Trophy",
"Grandmaster Tinkerer's Spanner", "Freshman Mechanist Trophy", "Apprentice Mechanist Trophy", "Beginner Mechanist Trophy"
}
},
{ "Pottery", {
// Clay: 15%|50, 15%|50, Master:12%|36, Expert: 8%|24, Journey: 5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Clay Flinger's Loop", "Master Potter Trophy", "Expert Potter Trophy", "Journeyman Potter Trophy", "Grandmaster Potter's Sculpter",
"Freshman Potter Trophy", "Apprentice Potter Trophy", "Beginner Potter Trophy"
}
},
{ "Research", {
// Brewmaster's: 15%|50, Master: 12%|36, Expert: 8%|24, Journey: 5%|12, Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Ethereal Quill", "Master Researcher Trophy", "Expert Researcher Trophy", "Journeyman Researcher Trophy",
"Freshman Researcher Trophy", "Apprentice Researcher Trophy", "Beginner Researcher Trophy"
}
},
{ "Blacksmithing", {
// Blacksmith's: 15%|50, Hammer: 15%|45, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Blacksmith's Adamantine Hammer", "Hammer of the Ironfrost", "Master Smith Trophy", "Expert Smith Trophy", "Journeyman Smith Trophy",
"Grandmaster Smith's Hammer", "Freshman Smith Trophy", "Apprentice Smith Trophy", "Beginner Smith Trophy"
}
},
{ "Poison", {
// Peerless: 15%|50, Master: 12%|36, Expert: 8%|24, Journey: 5%|12, Freshman: 4%|12, Apprentice: %2|6, Beginner: 1%|3
"Peerless Pestle", "Master Toxicologist Trophy", "Expert Toxicologist Trophy", "Journeyman Toxicologist Trophy",
"Freshman Toxicologist Trophy", "Apprentice Toxicologist Trophy", "Beginner Toxicologist Trophy"
}
},
{ "Tailoring", {
// Blessed: 15%|50, Mytical: 15%|45, Master: 12%|36, Expert: 8%|24, Journey:5%|12, Grandnmaster (old): 5%|12,
// Freshman: 4%|12, Apprentice: %2|6, Beginner:1%|3
"Blessed Akhevan Shadow Shears", "Mystical Bolt", "Master Tailor Trophy", "Expert Tailor Trophy", "Journeyman Tailor Trophy",
"Grandmaster Tailor's Needle", "Freshman Tailor Trophy", "Apprentice Tailor Trophy", "Beginner Tailor Trophy"
}
},
{ "Fishing", {
"The Bone Rod", "Collapsible Fishing Pole"
}
}
};
std::string TrophyCheckByType(const std::string& trophytype) {
for (auto& trophyname : mTrophies.at(trophytype)) {
if (FindItemByName(&trophyname[0], 1)) {
return trophyname;
}
}
return {};
}