feat(cpp/conf): Add option to teach all spells on first login (#9)

- Adds a `LearnAllOnFirstLogin` (default: false) option to teach the
player all the spells when he first logs in,
- Disabled by default because of performance concerns,
- Slight optimizations have been added to mitigate this issue
- However enabling this on a more populous server could cause issues
due to the current design of the module
This commit is contained in:
arenacraftwow
2020-04-01 20:22:25 +02:00
committed by GitHub
parent 769e883d18
commit e9ef8ef62e
2 changed files with 64 additions and 55 deletions

View File

@@ -12,6 +12,12 @@ LearnSpells.Enable = 1
LearnSpells.Announce = 1 LearnSpells.Announce = 1
# Should the player receive all spells on first login?
# Useful for instant leveling type of servers
# (1: true | 0: false)
LearnSpells.LearnAllOnFirstLogin = 0
# Max level Limit the player will learn spells # Max level Limit the player will learn spells
# Default: = 80 # Default: = 80

View File

@@ -10,12 +10,7 @@ uint32 MaxLevel;
class LearnSpellsOnLevelUp : public PlayerScript class LearnSpellsOnLevelUp : public PlayerScript
{ {
public: public:
std::vector<uint32> ignoreSpells; std::unordered_set<uint32> ignoreSpells = {
LearnSpellsOnLevelUp() : PlayerScript("LearnSpellsOnLevelUp")
{
uint32 temp[] =
{
64380, 23885, 23880, 44461, 25346, 10274, 10273, 8418, 64380, 23885, 23880, 44461, 25346, 10274, 10273, 8418,
8419, 7270, 7269, 7268, 54648, 12536, 24530, 70909, 8419, 7270, 7269, 7268, 54648, 12536, 24530, 70909,
12494, 57933, 24224, 27095, 27096, 27097, 27099, 32841, 12494, 57933, 24224, 27095, 27096, 27097, 27099, 32841,
@@ -52,10 +47,11 @@ public:
18848, 16979, 49376, 54055, 20647, 42243, 24131 18848, 16979, 49376, 54055, 20647, 42243, 24131
}; };
ignoreSpells = std::vector<uint32>(temp, temp + sizeof(temp) / sizeof(temp[0])); LearnSpellsOnLevelUp() : PlayerScript("LearnSpellsOnLevelUp")
{
} }
void OnLogin(Player *player) void OnLogin(Player *player) override
{ {
if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true)) if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true))
{ {
@@ -66,7 +62,15 @@ public:
} }
} }
void OnLevelChanged(Player* player, uint8 oldLevel) void OnFirstLogin(Player *player) override
{
if (sConfigMgr->GetBoolDefault("LearnSpells.LearnAllOnFirstLogin", false))
{
LearnSpellsForNewLevel(player, 1);
}
}
void OnLevelChanged(Player *player, uint8 oldLevel) override
{ {
if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true)) if (sConfigMgr->GetBoolDefault("LearnSpells.Enable", true))
{ {
@@ -80,10 +84,8 @@ public:
bool IsIgnoredSpell(uint32 spellID) bool IsIgnoredSpell(uint32 spellID)
{ {
for (std::vector<uint32>::const_iterator itr = ignoreSpells.begin(); itr != ignoreSpells.end(); ++itr) auto spellIt = ignoreSpells.find(spellID);
if (spellID == (*itr)) return spellIt != ignoreSpells.end();
return true;
return false;
} }
void LearnSpellsForNewLevel(Player *player, uint8 level) void LearnSpellsForNewLevel(Player *player, uint8 level)
@@ -131,13 +133,13 @@ public:
continue; continue;
if (spellInfo->SpellFamilyName != family) if (spellInfo->SpellFamilyName != family)
continue; continue;
if (IsIgnoredSpell(spellInfo->Id)) if ((spellInfo->AttributesEx7 & SPELL_ATTR7_ALLIANCE_ONLY && player->GetTeamId() != TEAM_ALLIANCE) || (spellInfo->AttributesEx7 & SPELL_ATTR7_HORDE_ONLY && player->GetTeamId() != TEAM_HORDE))
continue; continue;
if (spellInfo->PowerType == POWER_FOCUS) if (spellInfo->PowerType == POWER_FOCUS)
continue; continue;
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, spellInfo->Id, player)) if (IsIgnoredSpell(spellInfo->Id))
continue; continue;
if ((spellInfo->AttributesEx7 & SPELL_ATTR7_ALLIANCE_ONLY && player->GetTeamId() != TEAM_ALLIANCE) || (spellInfo->AttributesEx7 & SPELL_ATTR7_HORDE_ONLY && player->GetTeamId() != TEAM_HORDE)) if (DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, spellInfo->Id, player))
continue; continue;
if (spellInfo->BaseLevel != level && sSpellMgr->IsSpellValid(spellInfo)) if (spellInfo->BaseLevel != level && sSpellMgr->IsSpellValid(spellInfo))
continue; continue;
@@ -177,7 +179,8 @@ public:
void OnBeforeConfigLoad(bool reload) override void OnBeforeConfigLoad(bool reload) override
{ {
if (!reload) { if (!reload)
{
std::string conf_path = _CONF_DIR; std::string conf_path = _CONF_DIR;
std::string cfg_file = conf_path + "/mod_learnspells.conf"; std::string cfg_file = conf_path + "/mod_learnspells.conf";
#ifdef WIN32 #ifdef WIN32