-
Notifications
You must be signed in to change notification settings - Fork 9
/
NPC_GiverDB_Hunterpets.cpp
287 lines (284 loc) · 13.9 KB
/
NPC_GiverDB_Hunterpets.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
/*
NPC_GiverDB_Hunterpets
testet: 3.3.5a
stand: 01.11.2016
SET @CREATURTEMPLATE_ENTRY = 96104;
SET @CREATURTEMPLATE_NAME = "Giver NPC (Hunterpets)";
SET @CREATURTEMPLATE_SUBNAME = "Darkstanley Inc.";
SET @CREATURTEMPLATE_MODELID = 24978;
DELETE FROM world.creature WHERE id = @CREATURTEMPLATE_ENTRY;
DELETE FROM world.creature_template WHERE entry = @CREATURTEMPLATE_ENTRY;
INSERT INTO world.creature_template (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `spell1`, `spell2`, `spell3`, `spell4`, `spell5`, `spell6`, `spell7`, `spell8`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `DamageModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES
(@CREATURTEMPLATE_ENTRY, 0, 0, 0, 0, 0, @CREATURTEMPLATE_MODELID, 0, 0, 0, @CREATURTEMPLATE_NAME, @CREATURTEMPLATE_SUBNAME, 'Directions', 0, 80, 80, 0, 35, 3, 1, 1.14286, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 3, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 'NPC_GiverDB_Hunterpets', 0);
MySQL Testsyntax:
SELECT RequiredLevel, count(*) FROM world.item_template WHERE class = '15' AND subclass = '5' AND spellid_2 > '0' AND RequiredSkill > '0' GROUP BY RequiredLevel ORDER BY RequiredLevel ASC
*/
// ******************************************************************************
// include
// ******************************************************************************
#include "Pet.h"
// ******************************************************************************
// namespace
// ******************************************************************************
using namespace std;
// ******************************************************************************
// class
// ******************************************************************************
class NPC_GiverDB_Hunterpets : public CreatureScript
{
// ******************************************************************************
// public
// ******************************************************************************
public: NPC_GiverDB_Hunterpets() : CreatureScript("NPC_GiverDB_Hunterpets") { }
// ******************************************************************************
// init
// ******************************************************************************
uint32 StartIndex = 0;
vector<uint32> NPC_GiverDB_Hunterpets_DATA_filtered;
array<string, 9> NPC_GiverDB_Hunterpets_DATA_quality = { "404040","FFFFFF","008000","000080","a335ee","ffd100","800000","8080FF","8080FF" };
array<string, 47> NPC_GiverDB_Hunterpets_DATA_family = { "NULL","Wolf","Cat","Spider","Bear","Boar","Crocolisk","Carrion","Crab","Gorilla","NULL","Raptor","Tallstrider","NULL","NULL","Felhunter","Voidwalker","Succubus","NULL","Doomguard","Scorpid","Turtle","NULL","Imp","Bat","Hyena","Owl","Wind Serpent","Remote Control","Felguard","Dragonhawk","Ravager","Warp Stalker","Sporebat","Nether Ray","Serpent","NULL","Moth","Chimaera","Devilsaur","Ghoul","Silithid","Worm","Rhino","Wasp","Core Hound","Spirit Beast" };
// ******************************************************************************
// OnGossipHello
// ******************************************************************************
bool OnGossipHello(Player* player, Creature* creature) override
{
ClearGossipMenuFor(player);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t Alle zaehmbaren|r", GOSSIP_SENDER_MAIN, 105);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t nach Gruppen Seite 1|r", GOSSIP_SENDER_MAIN, 110);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t nach Gruppen Seite 2|r", GOSSIP_SENDER_MAIN, 115);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t Alle Exotischen|r", GOSSIP_SENDER_MAIN, 120);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-GroupLoot-Pass-Down:30:30:-18|t auf Wiedersehen|r", GOSSIP_SENDER_MAIN, 999);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}//OnGossipHello
// ******************************************************************************
// OnGossipSelect
// ******************************************************************************
bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action) override
{
if (sender == GOSSIP_SENDER_MAIN)
{
// --- verlassen
if (action == 999)
{
creature->Say("Auf Wiedersehen.", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
// --- im Kampf
if (player->IsInCombat())
{
creature->Say("Du befindest Dich in einem Kampf. Da kann ich Dir nicht helfen !", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
// --- Hauptmenu (Option 1)
if (action == 105)
{
FN_getMYSQL(player, ">", 0, "=", "name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 2)
if (action == 110)
{
ClearGossipMenuFor(player);
for (uint32 i = 1; i <= 25; i++)
{
if (NPC_GiverDB_Hunterpets_DATA_family[i] != "NULL")
AddGossipItemFor(player, GOSSIP_ICON_TRAINER, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t zaehmbare '" + NPC_GiverDB_Hunterpets_DATA_family[i] + "'|r", GOSSIP_SENDER_MAIN, 1000 + i);
}
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t zurueck|r", GOSSIP_SENDER_MAIN, 9997);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}
// --- Hauptmenu (Option 3)
if (action == 115)
{
ClearGossipMenuFor(player);
for (uint32 i = 26; i <= NPC_GiverDB_Hunterpets_DATA_family.size(); i++)
{
if (NPC_GiverDB_Hunterpets_DATA_family[i] != "NULL")
AddGossipItemFor(player, GOSSIP_ICON_TRAINER, "|cff000000|TInterface\\icons\\Ability_Hunter_BeastTaming:30:30:-18|t zaehmbare '" + NPC_GiverDB_Hunterpets_DATA_family[i] + "'|r", GOSSIP_SENDER_MAIN, 1000 + i);
}
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t zurueck|r", GOSSIP_SENDER_MAIN, 9997);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}
// --- Hauptmenu (Option 4)
if (action == 120)
{
FN_getMYSQL(player, ">", 0, ">", "name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (abbruch)
if (action == 9997)
{
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
OnGossipHello(player, creature);
return true;
}
// --- Submenu (auswahl)
if (action > 1000 && action < 9997)
{
uint32 i = (action - 1000);
FN_getMYSQL(player, "=", i, "=", "name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- SubSubmenu (Hauptmenu)
if (action == 999997)
{
StartIndex = 0;
CloseGossipMenuFor(player);
OnGossipHello(player, creature);
return true;
}
// --- SubSubmenu (weiter)
if (action == 999998)
{
StartIndex = StartIndex + 25;
if (StartIndex > NPC_GiverDB_Hunterpets_DATA_filtered.size())
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- SubSubmenu (zurueck)
if (action == 999999)
{
StartIndex = StartIndex - 25;
if (StartIndex < 0)
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- SubSubmenu (auswahl)
if (action >= 100000 && action < 999997)
{
uint32 i = (action - 100000);
if (NPC_GiverDB_Hunterpets_DATA_filtered[i] <= 0) {
creature->Say("Diese zaehmbare Tier habe ich z.Zt. nicht im Angebot.", LANG_UNIVERSAL, NULL);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
CreatureTemplate const* creature_template = sObjectMgr->GetCreatureTemplate(NPC_GiverDB_Hunterpets_DATA_filtered[i]);
if (!creature_template)
return false;
if (player->getClass() != CLASS_HUNTER)
{
creature->Say("Irgendwie siehts Du nicht wie einer aus der Jaegerklasse aus. Ich kann Dir daher kein Tier geben !", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
if (player->GetPet()) {
creature->Say("Du musst erst dein aktives zaehmbare Tier 'parken' !", LANG_UNIVERSAL, NULL);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
if ((creature_template->type_flags & 65536) && !player->CanTameExoticPets())
{
creature->Say("Tja, Du kannst dieses exotische zaehmbare Tier (noch) nicht zaehmen. Ich kann Dir das daher auch nicht geben !", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
Creature *creatureTarget = creature->SummonCreature(NPC_GiverDB_Hunterpets_DATA_filtered[i], player->GetPositionX(), player->GetPositionY() + 2, player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_CORPSE_TIMED_DESPAWN, 500);
if (!creatureTarget)
return false;
Pet* pet = player->CreateTamedPetFrom(creatureTarget, 0);
if (!pet)
return false;
creatureTarget->setDeathState(JUST_DIED);
creatureTarget->RemoveCorpse();
creatureTarget->SetHealth(0);
pet->SetPower(POWER_HAPPINESS, 1048000);
/*
pet->SetUInt32Value(UNIT_FIELD_LEVEL, player->getLevel() - 1);
pet->GetMap()->Add((Creature*)pet);
pet->SetUInt32Value(UNIT_FIELD_LEVEL, player->getLevel());
*/
pet->UpdateAllStats();
player->SetMinion(pet, true);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
pet->InitTalentForLevel();
player->PetSpellInitialize();
creature->Say("Ich habe Dir das gewuenschte zaehmbare Tier gegeben. Behandel es ja gut.", LANG_UNIVERSAL, NULL);
return true;
}
return false;
}//if sender
return false;
}//OnGossipSelect
// ******************************************************************************
// OnGossipSelect_Sub
// ******************************************************************************
bool OnGossipSelect_Sub(Player* player, Creature* creature, uint32 StartIndex)
{
ClearGossipMenuFor(player);
uint32 zaehler = 0;
uint32 MaxIndex = NPC_GiverDB_Hunterpets_DATA_filtered.size();
for (uint32 i = StartIndex; i < MaxIndex; i++)
{
// ---
CreatureTemplate const* creature_template = sObjectMgr->GetCreatureTemplate(NPC_GiverDB_Hunterpets_DATA_filtered[i]);
string t_name;
if (CreatureLocale const* creature_locale = sObjectMgr->GetCreatureLocale(creature_template->Entry))
sObjectMgr->GetLocaleString(creature_locale->Name, player->GetSession()->GetSessionDbLocaleIndex() , t_name);
else
t_name = creature_template->Name;
// ---
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|t " + t_name + "|n|t (Familie '" + NPC_GiverDB_Hunterpets_DATA_family[creature_template->family] + "')|r", GOSSIP_SENDER_MAIN, 100000 + i);
// ---
zaehler = zaehler + 1;
if (zaehler == 25)
{
StartIndex = i;
break;
}//if
}//for
if (StartIndex > 25)
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t zurueck|r", GOSSIP_SENDER_MAIN, 999999);
if (StartIndex < MaxIndex)
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-NextPage-Up:30:30:-18|t weiter|r", GOSSIP_SENDER_MAIN, 999998);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|cff000000|TInterface\\buttons\\UI-SpellbookIcon-PrevPage-Up:30:30:-18|t Hauptmenu|r", GOSSIP_SENDER_MAIN, 999997);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
};//OnGossipSelect_Sub
// ******************************************************************************
// FN_getMYSQL
// ******************************************************************************
void FN_getMYSQL(Player* player, string t_familykennz, uint32 t_family, string t_exotickennz, string t_order)
{
NPC_GiverDB_Hunterpets_DATA_filtered.clear();
QueryResult result = WorldDatabase.PQuery("SELECT entry FROM world.creature_template WHERE type = '1' AND family > 0 AND (faction & %u) > '0' AND family %s '%u' AND (type_flags & 1) > '0' AND (type_flags & 65536) %s '0' ORDER BY %s", player->getFaction(), t_familykennz, t_family, t_exotickennz, t_order);
if (result)
{
Field * fields = NULL;
do
{
fields = result->Fetch();
NPC_GiverDB_Hunterpets_DATA_filtered.push_back(fields[0].GetUInt32());
} while (result->NextRow());
}
else
{
TC_LOG_ERROR("misc", "DATABASE ERROR - NPC_GiverDB_Hunterpets");
}
return;
};//FN_getMYSQL
};
// ******************************************************************************
// AddSC_...
// ******************************************************************************
void AddSC_NPC_GiverDB_Hunterpets()
{
new NPC_GiverDB_Hunterpets();
};