Skip to content

Commit 9a755a3

Browse files
authored
Merge pull request #42 from azerothcore/sudlud-pach-42-4
fix build, codestyle and add enabled hook list for performance improv…
2 parents 281290d + 2d8540e commit 9a755a3

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

src/npc_buffer.cpp

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ This code and content is released under the [GNU AGPL v3](https://github.com/aze
6464
6565
*/
6666

67-
#include "Config.h"
68-
#include "ScriptMgr.h"
6967
#include "Chat.h"
68+
#include "Config.h"
69+
#include "Log.h"
7070
#include "Player.h"
7171
#include "ScriptedCreature.h"
7272
#include "ScriptedGossip.h"
73+
#include "ScriptMgr.h"
7374
#include "SpellMgr.h"
74-
#include "Log.h"
7575

7676
static bool BFEnableModule;
7777
static bool BFAnnounceModule;
@@ -87,7 +87,9 @@ static uint32 MaxLevel = 80;
8787
class BufferConfig : public WorldScript
8888
{
8989
public:
90-
BufferConfig() : WorldScript("BufferConfig_conf") {}
90+
BufferConfig() : WorldScript("BufferConfig_conf", {
91+
WORLDHOOK_ON_BEFORE_CONFIG_LOAD
92+
}) {}
9193

9294
void OnBeforeConfigLoad(bool /*reload*/) override
9395
{
@@ -107,25 +109,23 @@ class BufferConfig : public WorldScript
107109
if (BuffMessageTimer != 0)
108110
{
109111
if (BuffMessageTimer < 60000 || BuffMessageTimer > 300000)
110-
{
111112
BuffMessageTimer = 60000;
112-
}
113113
}
114114
}
115115
};
116116

117117
class BufferAnnounce : public PlayerScript
118118
{
119119
public:
120-
BufferAnnounce() : PlayerScript("BufferAnnounce") {}
120+
BufferAnnounce() : PlayerScript("BufferAnnounce", {
121+
PLAYERHOOK_ON_LOGIN
122+
}) {}
121123

122-
void OnLogin(Player *player)
124+
void OnPlayerLogin(Player *player)
123125
{
124126
// Announce Module
125127
if (BFEnableModule && BFAnnounceModule)
126-
{
127128
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00BufferNPC |rmodule.");
128-
}
129129
}
130130
};
131131

@@ -143,17 +143,13 @@ class buff_npc : public CreatureScript
143143

144144
// if the character is level max level or higher, return the last spell in the chain
145145
if (level >= MaxLevel)
146-
{
147146
return sSpellMgr->GetLastSpellInChain(spell_id);
148-
}
149147

150148
uint32 first_spell = sSpellMgr->GetFirstSpellInChain(spell_id);
151149
uint32 next_spell = first_spell;
152150
uint32 number_of_spells_in_chain = 0;
153151
for (; next_spell; next_spell = sSpellMgr->GetNextSpellInChain(next_spell))
154-
{
155152
number_of_spells_in_chain++;
156-
}
157153

158154
// if the chain is empty, return the first spell
159155
if (number_of_spells_in_chain == 0)
@@ -164,9 +160,7 @@ class buff_npc : public CreatureScript
164160

165161
// if the chain has only one spell, return that spell
166162
if (number_of_spells_in_chain == 1)
167-
{
168163
return first_spell;
169-
}
170164

171165
// if the chain has more than one spell, calculate the level-appropriate spell
172166
uint32 spell_index = (level * number_of_spells_in_chain) / MaxLevel;
@@ -200,9 +194,7 @@ class buff_npc : public CreatureScript
200194

201195
// Sanitize
202196
if (whisper == "")
203-
{
204197
whisper = "ERROR! NPC Emote Text Not Found! Check the npc_buffer.conf!";
205-
}
206198

207199
std::string randMsg = sConfigMgr->GetOption<std::string>(whisper.c_str(), "");
208200
replace(randMsg, "%s", Name);
@@ -219,9 +211,7 @@ class buff_npc : public CreatureScript
219211

220212
// Sanitize
221213
if (phrase == "")
222-
{
223214
phrase = "ERROR! NPC Emote Text Not Found! Check the npc_buffer.conf!";
224-
}
225215

226216
std::string randMsg = sConfigMgr->GetOption<std::string>(phrase.c_str(), "");
227217
return randMsg.c_str();
@@ -231,9 +221,7 @@ class buff_npc : public CreatureScript
231221
bool OnGossipHello(Player* player, Creature* creature)
232222
{
233223
if (!BFEnableModule)
234-
{
235224
return false;
236-
}
237225

238226
// Who are we dealing with?
239227
std::string CreatureWhisper = "Init";
@@ -243,9 +231,7 @@ class buff_npc : public CreatureScript
243231
std::vector<uint32> vecBuffs = {};
244232
std::stringstream ss(sConfigMgr->GetOption<std::string>("Buff.Spells", ""));
245233
for (std::string buff; std::getline(ss, buff, ';');)
246-
{
247234
vecBuffs.push_back(stoul(buff));
248-
}
249235

250236
// Cure Resurrection Sickness
251237
if (BuffCureRes && player->HasAura(15007))
@@ -270,17 +256,13 @@ class buff_npc : public CreatureScript
270256
{
271257
// No level requirement, so buff with max level default buffs
272258
for (std::vector<uint32>::const_iterator itr = vecBuffs.begin(); itr != vecBuffs.end(); itr++)
273-
{
274259
player->CastSpell(player, *itr, true);
275-
}
276260
}
277261

278262
// Choose and speak a random phrase to the player
279263
// Phrases are stored in the config file
280264
if (BuffNumWhispers > 0)
281-
{
282265
creature->Whisper(PickWhisper(PlayerName).c_str(), LANG_UNIVERSAL, player);
283-
}
284266

285267
// Emote and Close
286268
creature->HandleEmoteCommand(EMOTE_ONESHOT_FLEX);
@@ -298,9 +280,8 @@ class buff_npc : public CreatureScript
298280
// Called once when client is loaded
299281
void Reset()
300282
{
301-
if (BuffMessageTimer != 0) {
283+
if (BuffMessageTimer != 0)
302284
MessageTimer = urand(BuffMessageTimer, 300000); // 1-5 minutes
303-
}
304285
}
305286

306287
// Called at World update tick
@@ -318,24 +299,18 @@ class buff_npc : public CreatureScript
318299

319300
// Use gesture?
320301
if (BuffEmoteCommand != 0)
321-
{
322302
me->HandleEmoteCommand(BuffEmoteCommand);
323-
}
324303

325304
// Alert players?
326305
if (BuffEmoteSpell != 0)
327-
{
328306
me->CastSpell(me, BuffEmoteSpell);
329-
}
330307

331308
MessageTimer = urand(BuffMessageTimer, 300000);
332309
}
333310
else { MessageTimer -= diff; }
334311
}
335312
else
336-
{
337313
MessageTimer -= diff;
338-
}
339314
}
340315
};
341316

0 commit comments

Comments
 (0)