-
Notifications
You must be signed in to change notification settings - Fork 2
/
Grumboz_Guild_Warz.cpp
5032 lines (4140 loc) · 201 KB
/
Grumboz_Guild_Warz.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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
-- **g****************************************s***
-- ********© Grumbo'z Guild Warz System™ ©********
-- ********** Brought to you by Grumbo *******l**
-- **r*************** slp13at420 ****p************
-- ********************** of *********************
-- **************** Emudevs.com **********1*****
-- **u******************?*********3***************
-- *********************?*************************
-- ************ This is A C++ SCRIPT **a**********
-- ***m*********** This is For *****************
-- ************** TRINITY Core ONLY *t************
-- *?*******************4***********************?*
-- *b* Please Do Not Rem©ve any of the credits ***
-- **** and/or attempt to release as your own **2*
-- ***o******************©*************0**********
-- **************** First Public *****************
-- ********** release date 03-10-2013 ************
-- ***********************************************
Grumbo'z Guild Warz
my fucked up idea of a Guild plot system.
Guild's can own multiple locations and take locations from other Guild's via PvP.
Scripted By Slp13at420 of EmuDevs.com
Trinity Core2 WotlK C++ version.
*/
// !! On to the Madness Now !!
#include "chat.h"
#include "Creature.h"
#include "CreatureAI.h"
#include "Common.h"
#include "Config.h"
#include <cstring>
#include "GameObjectAI.h"
#include "Grumboz_Guild_Warz.h"
#include "Guild.h"
#include "GuildMgr.h"
#include "item.h"
#include "Language.h"
#include "MapManager.h"
#include "ObjectMgr.h"
#include "player.h"
#include "ScriptedCreature.h"
#include "ScriptedGossip.h"
//#include "ScriptMgr.h"
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include "World.h"
#include "WorldSession.h"
// defining most Globals now
// hard stored settings //
float core_version = 6.70f;
float table_version = 2.88f;
float pigpayz_version = 2.50f;
float tele_version = 1.50f;
float pvp_version = 4.88f;
float vendor_version = 1.55f;
uint8 MAX_GUILD_RANKS = 255;
uint8 SERVER_GUILD_TEAM_LOCKED_ID = 3;
uint8 SERVER_GUILD_TEAM = 2;
uint32 SERVER_GUILD_ID = 0;
uint64 Guard_Died_Drop_Reward = 20558; // wsg's not yet added
std::string SERVER_GUILD_NAME = "SERVER";
std::string GUILD_RANK_COMMAND = "rank";
std::string EVIL_DOER = "!Evil Do`er!";
int GGW_MSG = -1;
bool test = false; // test mode true/false . this will cause the core to belch out data as events happen for help with bug fixes.
uint64 seconds = 1000;
uint64 minutes = 60000;
uint64 hours = 3600000;
// db address's in string value for sql updates
std::string Guild_Warz_DB = sConfigMgr->GetStringDefault("GUILD_WARZ.DB_ADDRESS", "guild_warz_335");
std::string commands_db = Guild_Warz_DB + ".commands";
std::string help_db = Guild_Warz_DB + ".help";
std::string zones_db = Guild_Warz_DB + ".zones";
std::string ranking_db = Guild_Warz_DB + ".ranking";
// pre-defining other Global's for later
uint32 GUILDWARZ_PLAYER_CHECK_TIMER;
uint32 GUILDWARZ_PIGPAYZ_VALUE;
uint32 GUILDWARZ_PIGPAYZ_TIMER;
uint32 GUILDWARZ_RANK_TYPE;
uint32 GUILDWARZ_RANKING_TIMER;
uint32 GUILDWARZ_RANKING_MAX;
uint32 Currencyid;
std::string Currencyname;
// ---------------------------------------------------- -
// built - in vendors operational switches and item tables
// ---------------------------------------------------- -
const std::string VENDOR1_BUFF_NAMES[10] = { "Armor + 10%", "Damage + (1 - 10)%", "Resistances + 25", "Agility + 10%", "Intelligence + 10%", "Spirit + 10%", "Strength + 10%", "Stamina + 10%", "Spell Additional Damage + 3% chance", "Heal Me" };
uint32 VENDOR1_BUFF_IDS[10] = { 23767, 23768, 23769, 23736, 23766, 23738, 23735, 23737, 30557, 25840 };
// uint32 VENDOR2_ITEMS[11] = { 7734, 6948, 49912, 34498, 46693, 34499, 35557, 37431, 17202, 21038, 46783 }; // fun items
// uint32 VENDOR3_ITEMS[11] = {32837, 32838, 22736, 19019, 51858, 24550, 2000, 50730, 50070, 34196, 30906}; // misc gear
bool vendor1 = true; // use built - in vendor 1 . false / true = no / yes.
bool vendor2 = true; // use built - in vendor 2 . false / true = no / yes.
bool vendor3 = true; // use built - in vendor 3 . false / true = no / yes.
// pre-define global core tables
std::unordered_map<uint32, Commands>GWCOMM;
std::unordered_map<uint32, Help>GWHELP;
std::unordered_map<uint32, LocData>GWARZ;
std::unordered_map<uint32, GGW_CreatureData>GGW_Creature;
std::map<uint32, rank_info>GW_Ranks;
std::map<uint32, uint32>GW_RANKS;
GuildWarz::GuildWarz() { }
GuildWarz::~GuildWarz()
{
}
uint64 ConvertStringToNumber(std::string arg)
{
uint64 Value64;
std::istringstream(arg) >> Value64;
return Value64;
}
std::string ConvertNumberToString(uint64 numberX)
{
auto number = numberX;
std::stringstream convert;
std::string number32_to_string;
convert << number;
number32_to_string = convert.str();
return number32_to_string;
};
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
{
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim)
{
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
bool LoadCommands()
{
QueryResult ComQry = WorldDatabase.Query(("SELECT * FROM " + Guild_Warz_DB + ".commands;").c_str());
if (ComQry)
{
do
{
Field *fields = ComQry->Fetch();
// Save the DB values to the Commands object
std::string guild = fields[0].GetString();
uint32 guild_id = fields[1].GetUInt32();
uint32 team = fields[2].GetUInt32();
std::string commands = fields[3].GetString();
std::string info_loc = fields[4].GetString();
std::string list_loc = fields[5].GetString();
std::string tele = fields[6].GetString();
std::string version = fields[7].GetString();
uint8 GLD_lvlb = fields[8].GetUInt8();
uint8 GLD_lvls = fields[9].GetUInt8();
std::string respawn_flag = fields[10].GetString();
std::string details_loc = fields[11].GetString();
std::string table = fields[12].GetString();
uint8 GM_admin = fields[13].GetUInt8();
uint8 GM_minimum = fields[14].GetUInt8();
uint64 currency = fields[15].GetUInt64();
uint64 pig_payz = fields[16].GetUInt64();
uint64 pig_payz_timer = fields[17].GetUInt64();
uint8 gift_count = fields[18].GetUInt8();
uint8 flag_require = fields[19].GetUInt8();
std::string Server = fields[20].GetString();
std::string command_set = fields[21].GetString();
uint8 anarchy = fields[22].GetUInt8();
uint8 f_timer = fields[23].GetUInt8();
uint64 s_timer = fields[24].GetUInt64();
uint8 guild_invite = fields[25].GetBool();
std::string loc = fields[26].GetString();
uint32 loc_cost = fields[27].GetUInt32();
uint64 flag_id = fields[28].GetUInt64();
std::string farm = fields[29].GetString();
uint32 farm_cost = fields[30].GetUInt32();
uint32 farm_L = fields[31].GetUInt32();
uint64 farm_id = fields[32].GetUInt64();
std::string barrack = fields[33].GetString();
uint32 barrack_cost = fields[34].GetUInt32();
uint32 barrack_L = fields[35].GetUInt32();
uint64 barrack_id = fields[36].GetUInt64();
std::string hall = fields[37].GetString();
uint32 hall_cost = fields[38].GetUInt32();
uint32 hall_L = fields[39].GetUInt32();
uint64 hall_id = fields[40].GetUInt64();
std::string pig = fields[41].GetString();
uint32 pig_cost = fields[42].GetUInt32();
uint32 pig_L = fields[43].GetUInt32();
uint64 pig_id = fields[44].GetUInt64();
std::string guard = fields[45].GetString();
uint32 guard_cost = fields[46].GetUInt32();
uint32 guard_L = fields[47].GetUInt32();
uint64 guard_id = fields[48].GetUInt64();
std::string vendor1 = fields[49].GetString();
uint32 vendor1_cost = fields[50].GetUInt32();
uint32 vendor1_L = fields[51].GetUInt32();
uint64 vendor1_id = fields[52].GetUInt64();
std::string vendor2 = fields[53].GetString();
uint32 vendor2_cost = fields[54].GetUInt32();
uint32 vendor2_L = fields[55].GetUInt32();
uint64 vendor2_id = fields[56].GetUInt64();
std::string vendor3 = fields[57].GetString();
uint32 vendor3_cost = fields[58].GetUInt32();
uint32 vendor3_L = fields[59].GetUInt32();
uint64 vendor3_id = fields[60].GetUInt64();
std::string cannon = fields[61].GetString();
uint32 cannon_cost = fields[62].GetUInt32();
uint32 cannon_L = fields[63].GetUInt32();
uint64 cannon_id = fields[64].GetUInt64();
std::string vault = fields[65].GetString();
uint16 vault_cost = fields[66].GetUInt32();
uint16 vault_L = fields[67].GetUInt32();
uint64 vault_id = fields[68].GetUInt64();
std::string mailbox = fields[69].GetString();
uint32 mailbox_cost = fields[70].GetUInt32();
uint32 mailbox_L = fields[71].GetUInt32();
uint64 mailbox_id = fields[72].GetUInt64();
std::string setup = fields[73].GetString();
std::string color_1 = fields[74].GetString();
std::string color_2 = fields[75].GetString();
std::string color_3 = fields[76].GetString();
std::string color_4 = fields[77].GetString();
std::string color_5 = fields[78].GetString();
std::string color_6 = fields[79].GetString();
std::string color_7 = fields[80].GetString();
std::string color_8 = fields[81].GetString();
std::string color_9 = fields[82].GetString();
std::string color_10 = fields[83].GetString();
std::string color_11 = fields[84].GetString();
std::string color_12 = fields[85].GetString();
std::string color_13 = fields[86].GetString();
std::string color_14 = fields[87].GetString();
std::string color_15 = fields[88].GetString();
Commands& data = GWCOMM[guild_id]; // like Lua table GWARZ[guild_id].entry
data.guild = guild;
data.guild_id = guild_id;
data.team = team;
data.commands = commands;
data.info_loc = info_loc;
data.list_loc = list_loc;
data.tele = tele;
data.version = version;
data.GLD_lvlb = GLD_lvlb;
data.GLD_lvls = GLD_lvls;
data.respawn_flag = respawn_flag;
data.details_loc = details_loc;
data.table = table;
data.GM_admin = GM_admin;
data.GM_minimum = GM_minimum;
data.currency = currency;
data.pig_payz = pig_payz;
data.pig_payz_timer = pig_payz_timer;
data.gift_count = gift_count;
data.flag_require = flag_require;
data.Server = Server;
data.command_set = command_set;
data.anarchy = anarchy;
data.f_timer = f_timer;
data.s_timer = s_timer;
data.guild_invite = guild_invite;
data.loc = loc;
data.loc_cost = loc_cost;
data.flag_id = flag_id;
data.farm = farm;
data.farm_cost = farm_cost;
data.farm_L = farm_L;
data.farm_id = farm_id;
data.barrack = barrack;
data.barrack_cost = barrack_cost;
data.barrack_L = barrack_L;
data.barrack_id = barrack_id;
data.hall = hall;
data.hall_cost = hall_cost;
data.hall_L = hall_L;
data.hall_id = hall_id;
data.pig = pig;
data.pig_cost = pig_cost;
data.pig_L = pig_L;
data.pig_id = pig_id;
data.guard = guard;
data.guard_cost = guard_cost;
data.guard_L = guard_L;
data.guard_id = guard_id;
data.vendor1 = vendor1;
data.vendor1_cost = vendor1_cost;
data.vendor1_L = vendor1_L;
data.vendor1_id = vendor1_id;
data.vendor2 = vendor2;
data.vendor2_cost = vendor2_cost;
data.vendor2_L = vendor2_L;
data.vendor2_id = vendor2_id;
data.vendor3 = vendor3;
data.vendor3_cost = vendor3_cost;
data.vendor3_L = vendor3_L;
data.vendor3_id = vendor3_id;
data.cannon = cannon;
data.cannon_cost = cannon_cost;
data.cannon_L = cannon_L;
data.cannon_id = cannon_id;
data.vault = vault;
data.vault_cost = vault_cost;
data.vault_L = vault_L;
data.vault_id = vault_id;
data.mailbox = mailbox;
data.mailbox_cost = mailbox_cost;
data.mailbox_L = mailbox_L;
data.mailbox_id = mailbox_id;
data.setup = setup;
data.color_1 = color_1;
data.color_2 = color_2;
data.color_3 = color_3;
data.color_4 = color_4;
data.color_5 = color_5;
data.color_6 = color_6;
data.color_7 = color_7;
data.color_8 = color_8;
data.color_9 = color_9;
data.color_10 = color_10;
data.color_11 = color_11;
data.color_12 = color_12;
data.color_13 = color_13;
data.color_14 = color_14;
data.color_15 = color_15;
} while (ComQry->NextRow());
return true;
}
return false;
};
bool LoadHelp()
{
QueryResult HlpQry = WorldDatabase.Query(("SELECT * FROM " + Guild_Warz_DB + ".help;").c_str());
if (HlpQry)
{
do
{
Field *fields = HlpQry->Fetch();
// Save the DB values to the Help object
uint32 entry = fields[0].GetUInt32();
std::string name = fields[1].GetString();
std::string description = fields[2].GetString();
std::string example = fields[3].GetString();
uint8 command_level = fields[4].GetUInt8();
Help& data = GWHELP[entry]; // like Lua table GWHELP[entry].entry
data.entry = entry;
data.name = name;
data.description = description;
data.example = example;
data.command_level = command_level;
} while (HlpQry->NextRow());
return true;
}
return false;
};
bool LoadLoc()
{
QueryResult LocQry = WorldDatabase.Query(("SELECT * FROM " + Guild_Warz_DB + ".zones").c_str());
if (LocQry)
{
do
{
Field *fields = LocQry->Fetch();
// Save the DB values to the LocData object
uint32 entry = fields[0].GetUInt32();
uint32 map_id = fields[1].GetUInt32();
uint32 area_id = fields[2].GetUInt32();
uint32 zone_id = fields[3].GetUInt32();
std::string guild_name = fields[4].GetString();
uint8 team = fields[5].GetUInt8();
float x = fields[6].GetFloat();
float y = fields[7].GetFloat();
float z = fields[8].GetFloat();
uint64 farm_count = fields[9].GetUInt64();
uint64 barrack_count = fields[10].GetUInt64();
uint64 hall_count = fields[11].GetUInt64();
uint64 pig_count = fields[12].GetUInt64();
uint64 guard_count = fields[13].GetUInt64();
uint64 vendor1_count = fields[14].GetUInt64();
uint64 vendor2_count = fields[15].GetUInt64();
uint64 vendor3_count = fields[16].GetUInt64();
uint64 cannon_count = fields[17].GetUInt64();
uint16 vault_count = fields[18].GetUInt64();
uint64 mailbox_count = fields[19].GetUInt64();
uint64 flag_id = fields[20].GetUInt64();
uint64 fs_time = fields[21].GetUInt64();
uint32 guild_id = fields[22].GetUInt32();
LocData& data = GWARZ[entry]; // like Lua table GWARZ[guild_id].entry
data.entry = entry;
data.map_id = map_id;
data.area_id = area_id;
data.zone_id = zone_id;
data.guild_name = guild_name;
data.team = team;
data.x = x;
data.y = y;
data.z = z;
data.farm_count = farm_count;
data.barrack_count = barrack_count;
data.hall_count = hall_count;
data.pig_count = pig_count;
data.guard_count = guard_count;
data.vendor1_count = vendor1_count;
data.vendor2_count = vendor2_count;
data.vendor3_count = vendor3_count;
data.cannon_count = cannon_count;
data.vault_count = vault_count;
data.mailbox_count = mailbox_count;
data.flag_id = flag_id;
data.fs_time = fs_time;
data.guild_id = guild_id;
} while (LocQry->NextRow());
return true;
}
return false;
};
float GW_version = ((table_version + core_version + pigpayz_version + tele_version + pvp_version + vendor_version) / 4);
uint32 GetTotalPigs(uint32 guild_id)
{
uint32 loc_id = 0;
uint32 pig_total = 0;
for (loc_id = 1; loc_id < GWARZ.size(); loc_id++)
{
if (GWARZ[loc_id].guild_id == guild_id) { pig_total = pig_total + GWARZ[loc_id].pig_count; };
}
return pig_total;
};
uint32 CalculateTotalLocations(uint32 guild_id)
{
uint32 loc_id = 0;
uint32 loc_total = 0;
for (loc_id = 1; loc_id < GWARZ.size(); loc_id++)
{
if (GWARZ[loc_id].guild_id == guild_id) { loc_total = loc_total + 1; };
}
return loc_total;
};
uint32 CalculateLocationValue(uint32 loc_id)
{
uint32 loc_value = 0;
if (GWARZ[loc_id].entry == loc_id)
{
loc_value += GWCOMM[SERVER_GUILD_ID].loc_cost;
loc_value += (GWARZ[loc_id].farm_count * GWCOMM[SERVER_GUILD_ID].farm_cost);
loc_value += (GWARZ[loc_id].pig_count * GWCOMM[SERVER_GUILD_ID].pig_cost);
loc_value += (GWARZ[loc_id].barrack_count * GWCOMM[SERVER_GUILD_ID].barrack_cost);
// loc_value += (GWARZ[loc_id].guard_count * GWCOMM[SERVER_GUILD_ID].guard_cost); // guards are non-refundable so no value added
loc_value += (GWARZ[loc_id].hall_count * GWCOMM[SERVER_GUILD_ID].hall_cost);
loc_value += (GWARZ[loc_id].vendor1_count * GWCOMM[SERVER_GUILD_ID].vendor1_cost);
loc_value += (GWARZ[loc_id].vendor2_count * GWCOMM[SERVER_GUILD_ID].vendor2_cost);
loc_value += (GWARZ[loc_id].vendor3_count * GWCOMM[SERVER_GUILD_ID].vendor3_cost);
loc_value += (GWARZ[loc_id].vault_count * GWCOMM[SERVER_GUILD_ID].vault_cost);
loc_value += (GWARZ[loc_id].mailbox_count * GWCOMM[SERVER_GUILD_ID].mailbox_cost);
loc_value += (GWARZ[loc_id].cannon_count * GWCOMM[SERVER_GUILD_ID].cannon_cost);
};
return loc_value;
};
uint64 CalculateTotalLocationsValue(uint32 guild_id)
{
uint32 loc_id = 0;
uint32 loc_value = 0;
uint64 loc_total_value = 0;
for (loc_id = 1; loc_id < GWARZ.size(); loc_id++)
{
if (GWARZ[loc_id].guild_id == guild_id)
{
loc_value = CalculateLocationValue(loc_id);
loc_total_value = uint64(loc_total_value + loc_value);
};
}
return loc_total_value;
};
uint32 GetRank(uint32 guild_id)
{
uint32 rank;
uint32 guild_rank;
uint32 size = GW_Ranks.size();
for (rank = 1; rank <= size; rank++)
{
if (GW_Ranks[rank].guild_id == guild_id)
{
guild_rank = rank;
break;
};
}
return guild_rank;
};
bool UpdateRankEntry(uint32 guild_id, uint32 total_gross_worth, uint8 team)
{
if (test) { TC_LOG_INFO("server.loading", "UPDATE RANK ENRTY:: GUILD:%u WORTH:%u TEAM:%u", guild_id, total_gross_worth, team); };
if (GWCOMM[guild_id].guild_id = guild_id)
{
WorldDatabase.PExecute("REPLACE INTO %s (`guild_id`, `team`, `total_gross_worth`) VALUES('%u', '%u', '%u');", ranking_db.c_str(), guild_id, team, total_gross_worth);
uint32 rank;
if (GetRank(guild_id))
rank = GetRank(guild_id);
else
{
rank = GW_Ranks.size() + 1;
}
GW_Ranks[rank].guild_id = guild_id;
GW_Ranks[rank].team = team;
GW_Ranks[rank].total_gross_worth = total_gross_worth;
}
return true;
};
void BuildRankList()
{
GW_Ranks.clear();
uint32 rank = 1;
QueryResult RankQry = WorldDatabase.Query(("SELECT `guild_id`,`team`,`total_gross_worth` FROM " + ranking_db + " WHERE guild_id != '0' ORDER BY `total_gross_worth` DESC;").c_str());
if (RankQry)
{
do
{
Field *fields = RankQry->Fetch();
// Save the DB values to the LocData object
uint32 guild_id = fields[0].GetUInt32();
uint8 team = fields[1].GetUInt32();
uint32 total_gross_worth = fields[2].GetUInt32();
if (GWCOMM[guild_id].guild != "")
{
if(test){ TC_LOG_INFO("server.loading", "<RANK>%u <NAME>%s <GUILD_ID>%u <TEAM>%u", rank, GWCOMM[guild_id].guild, guild_id, team); };
GW_Ranks[rank].guild_id = guild_id;
GW_Ranks[rank].team = team;
GW_Ranks[rank].total_gross_worth = total_gross_worth;
GW_Ranks[rank].name = GWCOMM[guild_id].guild;
rank = rank + 1;
}
} while (RankQry->NextRow());
}
}
bool CreateRankList()
{
uint32 guildid;
for (std::unordered_map<uint32, Commands>::iterator itr1 = GWCOMM.begin(); itr1 != GWCOMM.end(); itr1++)
{
guildid = itr1->first;
if (guildid != 0)
{
uint32 total_gross_worth = CalculateTotalLocationsValue(guildid);
bool dummyUpdateRankEntry = UpdateRankEntry(guildid, total_gross_worth, GWCOMM[guildid].team);
}
}
BuildRankList();
return true;
};
bool rank_binary_ticker = false;
class GGW_RankTimer : public WorldScript
{
public:
GGW_RankTimer() : WorldScript("GGW_RankTimer")
{
events.ScheduleEvent(1, GUILDWARZ_RANKING_TIMER);
};
void OnUpdate(uint32 diff) override
{
events.Update(diff);
uint8 id = events.ExecuteEvent();
if (rank_binary_ticker == true)
rank_binary_ticker = false;
else
{
switch (id)
{
case 1:
events.CancelEvent(1);
CreateRankList();
new GGW_RankTimer();
rank_binary_ticker = true;
break;
};
};
};
EventMap events;
};
class GGW_LoadGWtable : public WorldScript
{
public: GGW_LoadGWtable() : WorldScript("GGW_LoadGWtable"){ };
virtual void OnConfigLoad(bool /*reload*/)
{
TC_LOG_INFO("server.loading", "______________________________________");
TC_LOG_INFO("server.loading", "- Grumbo'z Guild Warz CPP -");
TC_LOG_INFO("server.loading", "- -");
TC_LOG_INFO("server.loading", "- For Trinity Core WotlK 3.3.5a -");
TC_LOG_INFO("server.loading", "______________________________________");
TC_LOG_INFO("server.loading", "- LOADING -");
bool com_table = LoadCommands();
if (com_table)
{
TC_LOG_INFO("server.loading", "- commands loaded -", GWCOMM.size());
}
bool help_table = LoadHelp();
if (help_table)
{
TC_LOG_INFO("server.loading", "- help system loaded -");
}
bool loc_table = LoadLoc();
if (loc_table)
{
TC_LOG_INFO("server.loading", "- %u locations loaded ", GWARZ.size());
}
GUILDWARZ_PIGPAYZ_VALUE = sConfigMgr->GetIntDefault("GUILD_WARZ.PIGPAYZ_REWARD", 1000);
GUILDWARZ_PIGPAYZ_TIMER = (sConfigMgr->GetIntDefault("GUILD_WARZ.PIGPAYZ_TIMER", 30)) * minutes;
GUILDWARZ_RANKING_TIMER = (sConfigMgr->GetIntDefault("GUILD_WARZ.RANKING_TIMER", 10)) * minutes;
GUILDWARZ_RANK_TYPE = sConfigMgr->GetIntDefault("GUILD_WARZ.RANK_TYPE", 1);
GUILDWARZ_RANKING_MAX = sConfigMgr->GetIntDefault("GUILD_WARZ.RANK_MAX", 100);
if (test){ TC_LOG_INFO("server.loading", "LOADING :: PIG_PAYZ :: PAYZ:%u TIMER:%u", GUILDWARZ_PIGPAYZ_VALUE, GUILDWARZ_PIGPAYZ_TIMER); };
Currencyid = GWCOMM[SERVER_GUILD_ID].currency;
if (!sObjectMgr->GetItemTemplate(Currencyid))
{
TC_LOG_INFO("server.loading", "- Error Loading Currency ID:%d . Item May NOT exsist in the sql DB.", Currencyid);
TC_LOG_INFO("server.loading", "- Make sure you are using a valid item entry id in the sql DB.");
TC_LOG_INFO("server.loading", "- Prepare for crash.");
}
Currencyname = sObjectMgr->GetItemTemplate(Currencyid)->Name1;
TC_LOG_INFO("server.loading", "- Core version:%.2f -", core_version);
TC_LOG_INFO("server.loading", "- tables version:%.2f -", table_version);
TC_LOG_INFO("server.loading", "- Pig Payz version:%.2f -", pigpayz_version);
TC_LOG_INFO("server.loading", "- Teleporter version:%.2f -", tele_version);
TC_LOG_INFO("server.loading", "- PvP version:%.2f -", pvp_version);
if (vendor1) { TC_LOG_INFO("server.loading", "- Vendor1 loaded -"); };
if (vendor2) { TC_LOG_INFO("server.loading", "- Vendor2 loaded -"); };
if (vendor3) { TC_LOG_INFO("server.loading", "- Vendor3 loaded -"); };
TC_LOG_INFO("server.loading", "- Vendor Core:%.2f -", tele_version);
if (GUILDWARZ_RANK_TYPE < 2)
{
TC_LOG_INFO("server.loading", "- Guild Ranking type:Timer -", GW_version);
CreateRankList();
new GGW_RankTimer();
};
if (GUILDWARZ_RANK_TYPE > 1) TC_LOG_INFO("server.loading", "- Guild Ranking type:OnEvent -", GW_version);
TC_LOG_INFO("server.loading", "______________________________________");
TC_LOG_INFO("server.loading", "- Goliath Online -", GW_version);
TC_LOG_INFO("server.loading", "- -");
TC_LOG_INFO("server.loading", "- Guild Warz Ver:%.2fc -", GW_version);
TC_LOG_INFO("server.loading", "______________________________________");
};
};
void SendGuildMessage(uint32 guild_id, std::string msg)
{
SessionMap sessions = sWorld->GetAllSessions();
msg = "[" + GWCOMM[guild_id].color_8 + "GuildWarz" + "|r]:" + msg;
for (SessionMap::iterator itr = sessions.begin(); itr != sessions.end(); ++itr)
{
if (!itr->second)
continue;
Player *player = itr->second->GetPlayer();
if (player->GetGuildId() == guild_id)
{
ChatHandler(player->GetSession()).PSendSysMessage(msg.c_str());
}
}
};
uint32 CreateGuildLocation(uint32 map_id, uint32 area_id, uint32 zone_id, float pX, float pY, float pZ)
{
uint32 CLentry = (GWARZ.size()); // + 1
if (GWARZ[CLentry].entry == CLentry)
do
{
CLentry++;
} while (GWARZ[CLentry].entry == CLentry);
WorldDatabase.PExecute("INSERT INTO %s (entry, map_id, area_id, zone_id, x, y, z) VALUES('%u', '%u', '%u', '%u', '%f', '%f', '%f');", zones_db.c_str(), CLentry, map_id, area_id, zone_id, pX, pY, pZ);
LocData& data = GWARZ[CLentry]; // like Lua table GWARZ[guild_id].entry
data.entry = CLentry;
data.map_id = map_id;
data.area_id = area_id;
data.zone_id = zone_id;
data.guild_name = SERVER_GUILD_NAME;
data.team = SERVER_GUILD_TEAM;
data.x = pX;
data.y = pY;
data.z = pZ;
data.farm_count = 0;
data.barrack_count = 0;
data.hall_count = 0;
data.pig_count = 0;
data.guard_count = 0;
data.vendor1_count = 0;
data.vendor2_count = 0;
data.vendor3_count = 0;
data.cannon_count = 0;
data.vault_count = 0;
data.mailbox_count = 0;
data.flag_id = 0;
data.fs_time = 0;
data.guild_id = SERVER_GUILD_ID;
return CLentry;
};
void UpdateGuildLocData(std::string column_target, std::string new_data, uint32 loc_id)
{
WorldDatabase.PExecute("UPDATE %s SET `%s` = '%s' WHERE `entry` = '%u';", zones_db.c_str(), column_target.c_str(), new_data.c_str(), loc_id);
if (column_target == "guild_name")
{
GWARZ[loc_id].guild_name = new_data.c_str();
}
if (column_target == "team")
{
GWARZ[loc_id].team = uint8(ConvertStringToNumber(new_data));
}
if (column_target == "farm_count")
{
GWARZ[loc_id].farm_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "barrack_count")
{
GWARZ[loc_id].barrack_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "hall_count")
{
GWARZ[loc_id].hall_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "pig_count")
{
GWARZ[loc_id].pig_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "guard_count")
{
GWARZ[loc_id].guard_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "vendor1_count")
{
GWARZ[loc_id].vendor1_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "vendor2_count")
{
GWARZ[loc_id].vendor2_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "vendor3_count")
{
GWARZ[loc_id].vendor3_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "cannon_count")
{
GWARZ[loc_id].cannon_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "vault_count")
{
GWARZ[loc_id].vault_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "mailbox_count")
{
GWARZ[loc_id].mailbox_count = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "flag_id")
{
GWARZ[loc_id].flag_id = uint32(ConvertStringToNumber(new_data));
}
if (column_target == "fs_time")
{
GWARZ[loc_id].fs_time = ConvertStringToNumber(new_data); // sWorld->GetGameTime();
}
if (column_target == "guild_id")
{
GWARZ[loc_id].guild_id = uint32(ConvertStringToNumber(new_data));
}
};
void UpdateGuildLocFloat(float x, float y, float z, uint32 loc_id)
{
WorldDatabase.PExecute("UPDATE %s SET x='%f', y='%f', z='%f' WHERE entry='%u';", zones_db.c_str(), x, y, z, loc_id);
GWARZ[loc_id].x = x;
GWARZ[loc_id].y = y;
GWARZ[loc_id].z = z;
};
uint32 GetLocationID(uint32 map_id, uint32 area_id, uint32 zone_id)
{
uint32 loc_id = NULL;
for (loc_id = 1; loc_id < GWARZ.size(); loc_id++)
{
if (GWARZ[loc_id].map_id == map_id && GWARZ[loc_id].area_id == area_id && GWARZ[loc_id].zone_id == zone_id)
{
return loc_id;
break;
}
}
return false;
};
uint32 CreateGuildCommands(std::string guild_name, uint32 guild_id)
{
WorldDatabase.PExecute("INSERT INTO %s (guild_id, guild) VALUES('%u', '%s');", commands_db.c_str(), guild_id, guild_name.c_str());
Commands& data = GWCOMM[guild_id]; // like Lua table GWCOMM[guild_id].commands
data.guild = guild_name;
data.guild_id = guild_id;
data.commands = GWCOMM[SERVER_GUILD_ID].commands;
data.info_loc = GWCOMM[SERVER_GUILD_ID].info_loc;
data.list_loc = GWCOMM[SERVER_GUILD_ID].list_loc;
data.tele = GWCOMM[SERVER_GUILD_ID].tele;
data.version = GWCOMM[SERVER_GUILD_ID].version;
data.GLD_lvlb = GWCOMM[SERVER_GUILD_ID].GLD_lvlb;
data.GLD_lvls = GWCOMM[SERVER_GUILD_ID].GLD_lvls;
data.respawn_flag = GWCOMM[SERVER_GUILD_ID].respawn_flag;
data.details_loc = GWCOMM[SERVER_GUILD_ID].details_loc;
data.table = GWCOMM[SERVER_GUILD_ID].table;
data.GM_admin = GWCOMM[SERVER_GUILD_ID].GM_admin;
data.GM_minimum = GWCOMM[SERVER_GUILD_ID].GM_minimum;
data.currency = GWCOMM[SERVER_GUILD_ID].currency;
data.pig_payz = GWCOMM[SERVER_GUILD_ID].pig_payz;
data.pig_payz_timer = GWCOMM[SERVER_GUILD_ID].pig_payz_timer;
data.gift_count = GWCOMM[SERVER_GUILD_ID].gift_count;
data.flag_require = GWCOMM[SERVER_GUILD_ID].flag_require;
data.Server = GWCOMM[SERVER_GUILD_ID].Server;
data.command_set = GWCOMM[SERVER_GUILD_ID].command_set;
data.anarchy = GWCOMM[SERVER_GUILD_ID].anarchy;
data.f_timer = GWCOMM[SERVER_GUILD_ID].f_timer;
data.s_timer = GWCOMM[SERVER_GUILD_ID].s_timer;
data.guild_invite = GWCOMM[SERVER_GUILD_ID].guild_invite;
data.loc = GWCOMM[SERVER_GUILD_ID].loc;
data.loc_cost = GWCOMM[SERVER_GUILD_ID].loc_cost;
data.flag_id = GWCOMM[SERVER_GUILD_ID].flag_id;
data.farm = GWCOMM[SERVER_GUILD_ID].farm;
data.farm_cost = GWCOMM[SERVER_GUILD_ID].farm_cost;
data.farm_L = GWCOMM[SERVER_GUILD_ID].farm_L;
data.farm_id = GWCOMM[SERVER_GUILD_ID].farm_id;
data.barrack = GWCOMM[SERVER_GUILD_ID].barrack;
data.barrack_cost = GWCOMM[SERVER_GUILD_ID].barrack_cost;
data.barrack_L = GWCOMM[SERVER_GUILD_ID].barrack_L;
data.barrack_id = GWCOMM[SERVER_GUILD_ID].barrack_id;
data.hall = GWCOMM[SERVER_GUILD_ID].hall;
data.hall_cost = GWCOMM[SERVER_GUILD_ID].hall_cost;
data.hall_L = GWCOMM[SERVER_GUILD_ID].hall_L;
data.hall_id = GWCOMM[SERVER_GUILD_ID].hall_id;
data.pig = GWCOMM[SERVER_GUILD_ID].pig;
data.pig_cost = GWCOMM[SERVER_GUILD_ID].pig_cost;
data.pig_L = GWCOMM[SERVER_GUILD_ID].pig_L;
data.pig_id = GWCOMM[SERVER_GUILD_ID].pig_id;
data.guard = GWCOMM[SERVER_GUILD_ID].guard;
data.guard_cost = GWCOMM[SERVER_GUILD_ID].guard_cost;
data.guard_L = GWCOMM[SERVER_GUILD_ID].guard_L;
data.guard_id = GWCOMM[SERVER_GUILD_ID].guard_id;
data.vendor1 = GWCOMM[SERVER_GUILD_ID].vendor1;
data.vendor1_cost = GWCOMM[SERVER_GUILD_ID].vendor1_cost;
data.vendor1_L = GWCOMM[SERVER_GUILD_ID].vendor1_L;
data.vendor1_id = GWCOMM[SERVER_GUILD_ID].vendor1_id;
data.vendor2 = GWCOMM[SERVER_GUILD_ID].vendor2;
data.vendor2_cost = GWCOMM[SERVER_GUILD_ID].vendor2_cost;
data.vendor2_L = GWCOMM[SERVER_GUILD_ID].vendor2_L;
data.vendor2_id = GWCOMM[SERVER_GUILD_ID].vendor2_id;
data.vendor3 = GWCOMM[SERVER_GUILD_ID].vendor3;
data.vendor3_cost = GWCOMM[SERVER_GUILD_ID].vendor3_cost;
data.vendor3_L = GWCOMM[SERVER_GUILD_ID].vendor3_L;
data.vendor3_id = GWCOMM[SERVER_GUILD_ID].vendor3_id;
data.cannon = GWCOMM[SERVER_GUILD_ID].cannon;
data.cannon_cost = GWCOMM[SERVER_GUILD_ID].cannon_cost;
data.cannon_L = GWCOMM[SERVER_GUILD_ID].cannon_L;
data.cannon_id = GWCOMM[SERVER_GUILD_ID].cannon_id;
data.vault = GWCOMM[SERVER_GUILD_ID].vault;
data.vault_cost = GWCOMM[SERVER_GUILD_ID].vault_cost;
data.vault_L = GWCOMM[SERVER_GUILD_ID].vault_L;
data.vault_id = GWCOMM[SERVER_GUILD_ID].vault_id;
data.mailbox = GWCOMM[SERVER_GUILD_ID].mailbox;
data.mailbox_cost = GWCOMM[SERVER_GUILD_ID].mailbox_cost;
data.mailbox_L = GWCOMM[SERVER_GUILD_ID].mailbox_L;
data.mailbox_id = GWCOMM[SERVER_GUILD_ID].mailbox_id;
data.setup = GWCOMM[SERVER_GUILD_ID].setup;
data.color_1 = GWCOMM[SERVER_GUILD_ID].color_1;
data.color_2 = GWCOMM[SERVER_GUILD_ID].color_2;
data.color_3 = GWCOMM[SERVER_GUILD_ID].color_3;
data.color_4 = GWCOMM[SERVER_GUILD_ID].color_4;
data.color_5 = GWCOMM[SERVER_GUILD_ID].color_5;
data.color_6 = GWCOMM[SERVER_GUILD_ID].color_6;
data.color_7 = GWCOMM[SERVER_GUILD_ID].color_7;
data.color_8 = GWCOMM[SERVER_GUILD_ID].color_8;
data.color_9 = GWCOMM[SERVER_GUILD_ID].color_9;
data.color_10 = GWCOMM[SERVER_GUILD_ID].color_10;
data.color_11 = GWCOMM[SERVER_GUILD_ID].color_11;
data.color_12 = GWCOMM[SERVER_GUILD_ID].color_12;
data.color_13 = GWCOMM[SERVER_GUILD_ID].color_13;
data.color_14 = GWCOMM[SERVER_GUILD_ID].color_14;
data.color_15 = GWCOMM[SERVER_GUILD_ID].color_15;
return GWCOMM[guild_id].guild_id;
};
void UpdateGuildCommandData(std::string column_target, std::string new_data, uint32 guild_id)
{
WorldDatabase.PExecute("UPDATE %s SET `%s`='%s' WHERE `guild_id` = '%u';", commands_db.c_str(), column_target.c_str(), new_data.c_str(), guild_id);
// GUILD MASTER
if (column_target == "commands")
{
GWCOMM[guild_id].commands = new_data.c_str();
}
if (column_target == "info_loc")
{
GWCOMM[guild_id].info_loc = new_data.c_str();
}
if (column_target == "list_loc")
{
GWCOMM[guild_id].list_loc = new_data.c_str();
}
if (column_target == "tele")