Skip to content

Commit 2342c3c

Browse files
authored
Merge pull request #55 from azerothcore/sudlud-pach-42-5
fix codestyle, sql and add enabled hook lists for performance improvement
2 parents b2a4a10 + e3cc0a7 commit 2342c3c

File tree

4 files changed

+37
-75
lines changed

4 files changed

+37
-75
lines changed

data/sql/db-characters/mod_solo_craft.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ CREATE TABLE IF NOT EXISTS `custom_solocraft_character_stats` (
55
`SpellPower` int unsigned NOT NULL DEFAULT '0',
66
`Stats` float NOT NULL DEFAULT '100',
77
PRIMARY KEY (`GUID`)
8-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
8+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

src/Solocraft.cpp

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
#include <map>
2-
#include "Log.h"
1+
#include "utils/Utils.h"
2+
#include "Chat.h"
33
#include "Config.h"
4-
#include "ScriptMgr.h"
5-
#include "Unit.h"
6-
#include "Player.h"
7-
#include "Pet.h"
8-
#include "Map.h"
94
#include "Group.h"
105
#include "InstanceScript.h"
11-
#include "Chat.h"
12-
#include <math.h>
13-
#include <unordered_map>
6+
#include "Log.h"
7+
#include "Map.h"
148
#include "ObjectGuid.h"
15-
#include "utils/Utils.h"
9+
#include "Pet.h"
10+
#include "Player.h"
11+
#include "ScriptMgr.h"
12+
#include "Unit.h"
13+
#include <cstdint>
1614
#include <iostream>
17-
#include <vector>
15+
#include <map>
16+
#include <math.h>
1817
#include <string>
19-
#include <cstdint>
18+
#include <unordered_map>
19+
#include <vector>
2020

2121
bool SoloCraftEnable = 1;
2222
bool SoloCraftAnnounceModule = 1;
@@ -45,7 +45,9 @@ float D649H25 = 1.0;
4545
class SolocraftConfig : public WorldScript
4646
{
4747
public:
48-
SolocraftConfig() : WorldScript("SolocraftConfig") {}
48+
SolocraftConfig() : WorldScript("SolocraftConfig", {
49+
WORLDHOOK_ON_BEFORE_CONFIG_LOAD
50+
}) {}
4951

5052
void OnBeforeConfigLoad(bool /*reload*/) override
5153
{
@@ -323,14 +325,17 @@ class SolocraftAnnounce : public PlayerScript
323325
std::map<ObjectGuid, bool> playerInInstanceMap;
324326

325327
public:
326-
SolocraftAnnounce() : PlayerScript("SolocraftAnnounce") {}
328+
SolocraftAnnounce() : PlayerScript("SolocraftAnnounce", {
329+
PLAYERHOOK_ON_LOGIN,
330+
PLAYERHOOK_ON_LOGOUT,
331+
PLAYERHOOK_ON_MAP_CHANGED,
332+
PLAYERHOOK_ON_GIVE_EXP
333+
}) {}
327334

328335
void OnPlayerLogin(Player* player) override
329336
{
330337
if (SoloCraftEnable && SoloCraftAnnounceModule)
331-
{
332338
ChatHandler(player->GetSession()).SendSysMessage("This server is running the |cff4CFF00SoloCraft |rmodule.");
333-
}
334339
}
335340

336341
void OnPlayerLogout(Player* player) override
@@ -347,13 +352,9 @@ class SolocraftAnnounce : public PlayerScript
347352
void OnPlayerMapChanged(Player* player) override
348353
{
349354
if (player->GetMap()->IsDungeon() || player->GetMap()->IsRaid())
350-
{
351355
playerInInstanceMap[player->GetGUID()] = true;
352-
}
353356
else
354-
{
355357
playerInInstanceMap[player->GetGUID()] = false;
356-
}
357358
}
358359

359360
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
@@ -369,7 +370,9 @@ class SolocraftAnnounce : public PlayerScript
369370
class SolocraftPlayerInstanceHandler : public PlayerScript
370371
{
371372
public:
372-
SolocraftPlayerInstanceHandler() : PlayerScript("SolocraftPlayerInstanceHandler") {}
373+
SolocraftPlayerInstanceHandler() : PlayerScript("SolocraftPlayerInstanceHandler", {
374+
PLAYERHOOK_ON_MAP_CHANGED
375+
}) {}
373376

374377
bool IsInSolocraftInstanceExcludedList(uint32 id)
375378
{
@@ -395,48 +398,34 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
395398
if (map)
396399
{
397400
if (IsInSolocraftInstanceExcludedList(map->GetId()))
398-
{
399401
return 0;
400-
}
401402

402403
if (map->Is25ManRaid())
403404
{
404405
if (map->IsHeroic() && map->GetId() == 649)
405-
{
406406
return D649H25;
407-
}
408407
else if (diff_Multiplier_Heroics.find(map->GetId()) == diff_Multiplier_Heroics.end())
409-
{
410408
return D25;
411-
}
412409
else
413410
return diff_Multiplier_Heroics[map->GetId()];
414411
}
415412

416413
if (map->IsHeroic())
417414
{
418415
if (map->GetId() == 649)
419-
{
420416
return D649H10;
421-
}
422417
else if (diff_Multiplier_Heroics.find(map->GetId()) == diff_Multiplier_Heroics.end())
423-
{
424418
return D10;
425-
}
426419
else
427420
return diff_Multiplier_Heroics[map->GetId()];
428421
}
429422

430423
if (diff_Multiplier.find(map->GetId()) == diff_Multiplier.end())
431424
{
432425
if (map->IsDungeon())
433-
{
434426
return D5;
435-
}
436427
else if (map->IsRaid())
437-
{
438428
return D40;
439-
}
440429
}
441430
else
442431
return diff_Multiplier[map->GetId()];
@@ -449,13 +438,9 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
449438
uint32 CalculateDungeonLevel(Map* map)
450439
{
451440
if (dungeons.find(map->GetId()) == dungeons.end())
452-
{
453441
return SolocraftDungeonLevel;
454-
}
455442
else
456-
{
457443
return dungeons[map->GetId()];
458-
}
459444
}
460445

461446
// Get the group's size
@@ -479,13 +464,9 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
479464
uint32 classBalance = 100;
480465

481466
if (classes.find(player->getClass()) == classes.end())
482-
{
483467
return classBalance;
484-
}
485468
else if (classes[player->getClass()] >= 0 && classes[player->getClass()] <= 100)
486-
{
487469
return classes[player->getClass()];
488-
}
489470
else
490471
return classBalance;
491472
}
@@ -507,9 +488,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
507488
if (result)
508489
{
509490
if ((*result)[1].Get<float>() > 0)
510-
{
511491
GroupDifficulty = GroupDifficulty + (*result)[1].Get<float>();
512-
}
513492
}
514493
}
515494
}
@@ -533,33 +512,25 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
533512
SoloCraftXPMod = 1.0;
534513

535514
for (uint32 i = STAT_STRENGTH; i < MAX_STATS; ++i)
536-
{
537515
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, difficulty * StatsMultPct, false);
538-
}
539516

540517
if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && !SolocraftNoXPFlag)
541-
{
542518
player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
543-
}
544519

545520
SolocraftNoXPFlag = 0;
546521
CharacterDatabase.Execute("DELETE FROM custom_solocraft_character_stats WHERE GUID = {}", player->GetGUID().GetCounter());
547522
}
548523

549524
if (player->getPowerType() == POWER_MANA || player->getClass() == CLASS_DRUID)
550-
{
551525
player->ApplySpellPowerBonus(SpellPowerBonus, false);
552-
}
553526
}
554527

555528
// Apply the player buffs
556529
void ApplyBuffs(Player* player, Map* map, float difficulty, int dunLevel, int numInGroup, int classBalance)
557530
{
558531
// Check whether to debuff back to normal or check to buff the player
559532
if (difficulty == 0 || IsInSolocraftInstanceExcludedList(map->GetId()))
560-
{
561533
ClearBuffs(player); // Check to revert player back to normal - Moving this here fixed logout and login while in instance buff and debuff issues
562-
}
563534
else
564535
{
565536
std::ostringstream ss;
@@ -568,9 +539,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
568539

569540
// Check for an existing No XP Gain flag - other mod compatibility
570541
if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
571-
{
572542
SolocraftNoXPFlag = 1;
573-
}
574543

575544
// If a player is too high level for dungeon don't buff but if in a group will count towards the group offset balancing.
576545
if (player->GetLevel() <= dunLevel + SolocraftLevelDiff)
@@ -589,9 +558,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
589558

590559
// Disable player XP gain if debuff applied
591560
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && SolocraftXPBalEnabled)
592-
{
593561
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
594-
}
595562
}
596563
else
597564
{
@@ -610,16 +577,12 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
610577
{
611578
SoloCraftXPMod = 0;
612579
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN) && SolocraftXPBalEnabled)
613-
{
614580
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
615-
}
616581
}
617582

618583
// Check XP modifier for over max limit and adjust
619584
if (SoloCraftXPMod > 1)
620-
{
621585
SoloCraftXPMod = 1.0;
622-
}
623586
}
624587

625588
// Check Database for a current dungeon entry
@@ -631,9 +594,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
631594
{
632595
// Check for Dungeon to Dungeon Transfer and remove old buff
633596
if (result)
634-
{
635597
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, (*result)[1].Get<float>() * (*result)[4].Get<float>(), false);
636-
}
637598
// Buff the player
638599
// Unitmods enum UNIT_MOD_STAT_START defined in Unit.h line 391
639600
player->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + i), TOTAL_PCT, difficulty * SoloCraftStatsMult, true);
@@ -678,9 +639,7 @@ class SolocraftPlayerInstanceHandler : public PlayerScript
678639
{
679640
SoloCraftXPMod = 0;
680641
if (!player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN))
681-
{
682642
player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN);
683-
}
684643
}
685644

686645
// Announcements

src/utils/Utils.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#include <string>
55
#include <vector>
66

7-
std::vector<std::string> split(const std::string& str, char delimiter) {
7+
std::vector<std::string> split(const std::string& str, char delimiter)
8+
{
89
std::vector<std::string> res;
9-
if (str.empty()) return res;
10+
if (str.empty())
11+
return res;
1012
std::string token;
1113
std::istringstream tokenStream(str);
12-
while (std::getline(tokenStream, token, delimiter)) {
14+
while (std::getline(tokenStream, token, delimiter))
1315
res.push_back(token);
14-
}
1516
return res;
1617
}

src/utils/Utils.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
#include <cstdint>
55
#include <iostream>
6-
#include <vector>
7-
#include <string>
86
#include <sstream>
7+
#include <string>
8+
#include <vector>
99

1010
std::vector<std::string> split(const std::string& str, char delimiter);
1111

1212
template <class T>
13-
void LoadList(const std::string& value, T& list) {
13+
void LoadList(const std::string& value, T& list)
14+
{
1415
std::vector<std::string> ids = split(value, ',');
15-
for (const std::string& id_str : ids) {
16+
for (const std::string& id_str : ids)
17+
{
1618
uint32_t id = static_cast<uint32_t>(std::atoi(id_str.c_str()));
1719
list.push_back(id);
1820
}

0 commit comments

Comments
 (0)