-
Notifications
You must be signed in to change notification settings - Fork 9
/
NPC_GiverDB_Pets.cpp
261 lines (257 loc) · 12.2 KB
/
NPC_GiverDB_Pets.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
/*
NPC_GiverDB_Pets
testet: 3.3.5a
stand: 01.11.2016
SET @CREATURTEMPLATE_ENTRY = 96105;
SET @CREATURTEMPLATE_NAME = "Giver NPC (Pets)";
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_Pets', 0);
MySQL Testsyntax:
SELECT ItemLevel, count(*) FROM world.item_template WHERE class = '15' AND subclass = '2' AND spellid_2 > '0' GROUP BY ItemLevel ORDER BY ItemLevel ASC
*/
// ******************************************************************************
// namespace
// ******************************************************************************
using namespace std;
// ******************************************************************************
// class
// ******************************************************************************
class NPC_GiverDB_Pets : public CreatureScript
{
// ******************************************************************************
// public
// ******************************************************************************
public: NPC_GiverDB_Pets() : CreatureScript("NPC_GiverDB_Pets") { }
// ******************************************************************************
// init
// ******************************************************************************
uint32 StartIndex = 0;
vector<uint32> NPC_GiverDB_Pets_DATA_filtered;
array<string, 9> NPC_GiverDB_Pets_DATA_quality = { "404040","FFFFFF","008000","000080","a335ee","ffd100","800000","8080FF","8080FF" };
// ******************************************************************************
// OnGossipHello
// ******************************************************************************
bool OnGossipHello(Player* player, Creature* creature) override
{
ClearGossipMenuFor(player);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Alle Haustiere|r", GOSSIP_SENDER_MAIN, 105);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Haustiere bis iLV 20|r", GOSSIP_SENDER_MAIN, 110);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Haustiere bis iLV 40|r", GOSSIP_SENDER_MAIN, 115);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Haustiere bis iLV 60|r", GOSSIP_SENDER_MAIN, 120);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Haustiere ab iLV 61|r", GOSSIP_SENDER_MAIN, 125);
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|TInterface\\icons\\INV_Box_PetCarrier_01:30:30:-18|t Gib mir alle die du hast|r", GOSSIP_SENDER_MAIN, 130);
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, 99, "name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 2)
if (action == 110)
{
FN_getMYSQL(player, 0, 20, "ItemLevel ASC, name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 3)
if (action == 115)
{
FN_getMYSQL(player, 21, 40, "ItemLevel ASC, name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 4)
if (action == 120)
{
FN_getMYSQL(player, 41, 60, "ItemLevel ASC, name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 5)
if (action == 125)
{
FN_getMYSQL(player, 61, 99, "ItemLevel ASC, name ASC");
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Hauptmenu (Option 6)
if (action == 130)
{
creature->CastSpell(player, 38588, false); // Nur als Effekt
FN_getMYSQL(player, 0, 999, "name ASC");
uint32 MaxIndex = NPC_GiverDB_Pets_DATA_filtered.size();
for (uint32 i = 0; i < MaxIndex; i++)
{
ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(NPC_GiverDB_Pets_DATA_filtered[i]);
if (!player->HasItemCount(NPC_GiverDB_Pets_DATA_filtered[i], 1, true) && !player->HasSpell(item_template->Spells[1].SpellId))
{
//player->AddItem(NPC_GiverDB_Pets_DATA_filtered[i], 1);
player->LearnSpell(item_template->Spells[1].SpellId, false);
}//if
}//for
creature->Say("Ich habe Dir alle moeglichen Begleitertier gelehrt.", LANG_UNIVERSAL, NULL);
ClearGossipMenuFor(player);
CloseGossipMenuFor(player);
return true;
}
// --- Submenu (abbruch)
if (action == 999997)
{
StartIndex = 0;
CloseGossipMenuFor(player);
OnGossipHello(player, creature);
return true;
}
// --- Submenu (weiter)
if (action == 999998)
{
StartIndex = StartIndex + 25;
if (StartIndex > NPC_GiverDB_Pets_DATA_filtered.size())
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Submenu (zurueck)
if (action == 999999)
{
StartIndex = StartIndex - 25;
if (StartIndex < 0)
StartIndex = 0;
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
// --- Submenu (auswahl)
if (action >= 100000 && action < 999997)
{
uint32 i = (action - 100000);
if (NPC_GiverDB_Pets_DATA_filtered[i] <= 0) {
creature->Say("Dieses Haustiere habe ich z.Zt. nicht im Angebot.", LANG_UNIVERSAL, NULL);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(NPC_GiverDB_Pets_DATA_filtered[i]);
if (player->HasItemCount(NPC_GiverDB_Pets_DATA_filtered[i], 1, true) || player->HasSpell(item_template->Spells[1].SpellId))
{
creature->Say("Du hast dieses Haustiere schon !", LANG_UNIVERSAL, NULL);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
return true;
}
player->AddItem(NPC_GiverDB_Pets_DATA_filtered[i], 1);
creature->Say("Ich habe Dir das gewuenschte Haustiere gegeben.", LANG_UNIVERSAL, NULL);
CloseGossipMenuFor(player);
OnGossipSelect_Sub(player, creature, StartIndex);
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_Pets_DATA_filtered.size();
for (uint32 i = StartIndex; i < MaxIndex; i++)
{
// ---
ItemTemplate const* item_template = sObjectMgr->GetItemTemplate(NPC_GiverDB_Pets_DATA_filtered[i]);
string t_name;
string t_icon;
if (ItemLocale const* item_locale = sObjectMgr->GetItemLocale(item_template->ItemId))
sObjectMgr->GetLocaleString(item_locale->Name, player->GetSession()->GetSessionDbLocaleIndex() , t_name);
else
t_name = item_template->Name1;
/* bis dato nicht in dbc_stores.cpp
const ItemDisplayInfoEntry* dispInfo = NULL;
dispInfo = sItemDisplayInfoStore.LookupEntry(item_template->DisplayInfoID);
if (dispInfo)
t_icon = dispInfo->inventoryIcon;
char const ItemDisplayTemplateEntryfmt[] = "nxxxxxxxxxxixxxxxxxxxxx";
DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); //-- not used currently
LoadDBC(dbcCount, availableDbcLocales, bad_dbc_files, sItemDisplayInfoStore, dbcPath, "ItemDisplayInfo.dbc"); // -- not used currently
*/
// ---
AddGossipItemFor(player, GOSSIP_ICON_VENDOR, "|cff000000|t " + t_name + "|n|cff" + NPC_GiverDB_Pets_DATA_quality[item_template->Quality] + "|t (iLevel " + to_string(item_template->ItemLevel) + ")|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, uint32 t_itemlevelmin, uint32 t_itemlevelmax, string ORDER)
{
NPC_GiverDB_Pets_DATA_filtered.clear();
QueryResult result = WorldDatabase.PQuery("SELECT entry FROM world.item_template WHERE class = '15' AND subclass = '2' AND spellid_2 > '0' AND (AllowableRace = '-1' OR (AllowableRace & %u) > 0) AND (AllowableClass = '-1' OR (AllowableClass & %u) > 0) AND ItemLevel >= %u AND ItemLevel <= %u ORDER BY %s",player->getRace(), player->getClass(), t_itemlevelmin, t_itemlevelmax, ORDER);
if (result)
{
Field * fields = NULL;
do
{
fields = result->Fetch();
NPC_GiverDB_Pets_DATA_filtered.push_back(fields[0].GetUInt32());
} while (result->NextRow());
}
else
{
TC_LOG_ERROR("misc", "DATABASE ERROR - NPC_GiverDB_Pets");
}
return;
};//FN_getMYSQL
};
// ******************************************************************************
// AddSC_...
// ******************************************************************************
void AddSC_NPC_GiverDB_Pets()
{
new NPC_GiverDB_Pets();
};