Skip to content

Commit

Permalink
Drop spell_affect table.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Sep 26, 2024
1 parent 72090ec commit 9e63169
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 149 deletions.
137 changes: 137 additions & 0 deletions sql/migrations/20240926142033_world.sql

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ ChatCommand * ChatHandler::getCommandTable()
{ "reputation_spillover_template", SEC_DEVELOPER, true, &ChatHandler::HandleReloadReputationSpilloverTemplateCommand, "", nullptr },
{ "skill_fishing_base_level", SEC_DEVELOPER, true, &ChatHandler::HandleReloadSkillFishingBaseLevelCommand, "", nullptr },
{ "skinning_loot_template", SEC_DEVELOPER, true, &ChatHandler::HandleReloadLootTemplatesSkinningCommand, "", nullptr },
{ "spell_affect", SEC_DEVELOPER, true, &ChatHandler::HandleReloadSpellAffectCommand, "", nullptr },
{ "spell_area", SEC_DEVELOPER, true, &ChatHandler::HandleReloadSpellAreaCommand, "", nullptr },
{ "spell_chain", SEC_DEVELOPER, true, &ChatHandler::HandleReloadSpellChainCommand, "", nullptr },
{ "spell_elixir", SEC_DEVELOPER, true, &ChatHandler::HandleReloadSpellElixirCommand, "", nullptr },
Expand Down
1 change: 0 additions & 1 deletion src/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ class ChatHandler
bool HandleReloadReputationRewardRateCommand(char* args);
bool HandleReloadReputationSpilloverTemplateCommand(char* args);
bool HandleReloadSkillFishingBaseLevelCommand(char* args);
bool HandleReloadSpellAffectCommand(char* args);
bool HandleReloadSpellAreaCommand(char* args);
bool HandleReloadSpellChainCommand(char* args);
bool HandleReloadSpellElixirCommand(char* args);
Expand Down
9 changes: 0 additions & 9 deletions src/game/Commands/ServerCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ bool ChatHandler::HandleReloadAllScriptsCommand(char* /*args*/)

bool ChatHandler::HandleReloadAllSpellCommand(char* /*args*/)
{
HandleReloadSpellAffectCommand((char*)"a");
HandleReloadSpellAreaCommand((char*)"a");
HandleReloadSpellChainCommand((char*)"a");
HandleReloadSpellElixirCommand((char*)"a");
Expand Down Expand Up @@ -1358,14 +1357,6 @@ bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(char* /*args*/)
return true;
}

bool ChatHandler::HandleReloadSpellAffectCommand(char* /*args*/)
{
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Re-Loading SpellAffect definitions...");
sSpellMgr.LoadSpellAffects();
SendSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
return true;
}

bool ChatHandler::HandleReloadSpellAreaCommand(char* /*args*/)
{
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Re-Loading SpellArea Data...");
Expand Down
6 changes: 3 additions & 3 deletions src/game/Objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ SpellModifier::SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, A
mask = sSpellMgr.GetSpellAffectMask(aura->GetId(), aura->GetEffIndex());
}

bool SpellModifier::isAffectedOnSpell(SpellEntry const* spell) const
bool SpellModifier::IsAffectedOnSpell(SpellEntry const* spell) const
{
SpellEntry const* affect_spell = sSpellMgr.GetSpellEntry(spellId);
// False if affect_spell == nullptr or spellFamily not equal
Expand Down Expand Up @@ -18058,7 +18058,7 @@ bool Player::HasInstantCastingSpellMod(SpellEntry const* spellInfo) const
{
for (const auto& mod : m_spellMods[SPELLMOD_CASTING_TIME])
{
if ((mod->type == SPELLMOD_PCT) && (mod->value <= -100) && mod->isAffectedOnSpell(spellInfo))
if ((mod->type == SPELLMOD_PCT) && (mod->value <= -100) && mod->IsAffectedOnSpell(spellInfo))
return true;
}
return false;
Expand All @@ -18079,7 +18079,7 @@ bool Player::IsAffectedBySpellmod(SpellEntry const* spellInfo, SpellModifier con
return false;
}

return mod->isAffectedOnSpell(spellInfo);
return mod->IsAffectedOnSpell(spellInfo);
}

void Player::AddSpellMod(SpellModifier* mod, bool apply)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct SpellModifier

SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, Aura* aura, int16 _charges = 0);

bool isAffectedOnSpell(SpellEntry const* spell) const;
bool IsAffectedOnSpell(SpellEntry const* spell) const;

SpellModOp op : 8;
SpellModType type : 8;
Expand Down
18 changes: 9 additions & 9 deletions src/game/Objects/SpellCaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ float SpellCaster::SpellHealingBonusDone(Unit const* pVictim, SpellEntry const*
Unit::AuraList const& mOverrideClassScript = owner->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for (const auto i : mOverrideClassScript)
{
if (!i->isAffectedOnSpell(spellProto))
if (!i->IsAffectedOnSpell(spellProto))
continue;
switch (i->GetModifier()->m_miscvalue)
{
Expand Down Expand Up @@ -1363,17 +1363,17 @@ float SpellCaster::SpellDamageBonusDone(Unit const* pVictim, SpellEntry const* s
Unit::AuraList const& mOverrideClassScript = owner->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for (const auto i : mOverrideClassScript)
{
if (!i->isAffectedOnSpell(spellProto))
if (!i->IsAffectedOnSpell(spellProto))
continue;
switch (i->GetModifier()->m_miscvalue)
{
case 4418: // Increased Shock Damage
case 4554: // Increased Lightning Damage
case 4555: // Improved Moonfire
{
DoneTotal += i->GetModifier()->m_amount;
break;
}
case 4418: // Increased Shock Damage
case 4554: // Increased Lightning Damage
case 4555: // Improved Moonfire
{
DoneTotal += i->GetModifier()->m_amount;
break;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4651,7 +4651,7 @@ void Spell::HandleAddTargetTriggerAuras()
auto const& targetTriggers = m_casterUnit->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER);
for (const auto targetTrigger : targetTriggers)
{
if (!targetTrigger->isAffectedOnSpell(m_spellInfo))
if (!targetTrigger->IsAffectedOnSpell(m_spellInfo))
continue;
for (const auto& ihit : m_UniqueTargetInfo)
{
Expand Down
8 changes: 4 additions & 4 deletions src/game/Spells/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,10 @@ void Aura::ApplyModifier(bool apply, bool Real, bool skipCheckExclusive)
GetHolder()->SetInUse(false);
}

bool Aura::isAffectedOnSpell(SpellEntry const* spell) const
bool Aura::IsAffectedOnSpell(SpellEntry const* spell) const
{
if (m_spellmod)
return m_spellmod->isAffectedOnSpell(spell);
return m_spellmod->IsAffectedOnSpell(spell);

// Check family name
if (spell->SpellFamilyName != GetSpellProto()->SpellFamilyName)
Expand All @@ -948,7 +948,7 @@ bool Aura::isAffectedOnSpell(SpellEntry const* spell) const

bool Aura::CanProcFrom(SpellEntry const* spell, uint32 EventProcEx, uint32 procEx, bool active, bool useClassMask) const
{
// Check EffectClassMask (in pre-3.x stored in spell_affect in fact)
// Check EffectClassMask (stored in EffectItemType)
uint64 mask = sSpellMgr.GetSpellAffectMask(GetId(), GetEffIndex());

// Nostalrius: c'est la moindre des choses d'utiliser un peu 'spell_proc_event' non ?
Expand Down Expand Up @@ -1002,7 +1002,7 @@ void Aura::ReapplyAffectedPassiveAuras(Unit* target)
// and affected by aura
itr->second->GetCasterGuid() == target->GetObjectGuid() &&
// and affected by spellmod
isAffectedOnSpell(itr->second->GetSpellProto()))
IsAffectedOnSpell(itr->second->GetSpellProto()))
affectedSelf[itr->second->GetId()] = itr->second->GetCastItemGuid();
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/SpellAuras.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class Aura
void TriggerSpell();

// more limited that used in future versions (spell_affect table based only), so need be careful with backporting uses
bool isAffectedOnSpell(SpellEntry const* spell) const;
bool IsAffectedOnSpell(SpellEntry const* spell) const;
bool CanProcFrom(SpellEntry const* spell, uint32 EventProcEx, uint32 procEx, bool active, bool useClassMask) const;

SpellAuraHolder* GetHolder() const { return m_spellAuraHolder; }
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/SpellEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class SpellEntry
uint32 EffectAmplitude[MAX_EFFECT_INDEX] = {}; // 97-99
float EffectMultipleValue[MAX_EFFECT_INDEX] = {}; // 100-102
uint32 EffectChainTarget[MAX_EFFECT_INDEX] = {}; // 103-105
uint32 EffectItemType[MAX_EFFECT_INDEX] = {}; // 106-108
uint64 EffectItemType[MAX_EFFECT_INDEX] = {}; // 106-108
int32 EffectMiscValue[MAX_EFFECT_INDEX] = {}; // 109-111
uint32 EffectTriggerSpell[MAX_EFFECT_INDEX] = {}; // 112-114
float EffectPointsPerComboPoint[MAX_EFFECT_INDEX] = {};// 115-117
Expand Down
107 changes: 3 additions & 104 deletions src/game/Spells/SpellMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3043,107 +3043,6 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
return true;
}

void SpellMgr::LoadSpellAffects()
{
mSpellAffectMap.clear(); // need for reload case

uint32 count = 0;

// 0 1 2
std::unique_ptr<QueryResult> result(WorldDatabase.PQuery("SELECT `entry`, `effectId`, `SpellFamilyMask` FROM `spell_affect` WHERE (`build_min` <= %u) && (`build_max` >= %u)", SUPPORTED_CLIENT_BUILD, SUPPORTED_CLIENT_BUILD));
if (!result)
{

BarGoLink bar(1);

bar.step();

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "");
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u spell affect definitions", count);
return;
}

BarGoLink bar(result->GetRowCount());

do
{
Field* fields = result->Fetch();

bar.step();

uint32 entry = fields[0].GetUInt32();
uint8 effectId = fields[1].GetUInt8();

SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(entry);

if (!spellInfo)
{
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Spell %u listed in `spell_affect` does not exist", entry);
continue;
}

if (effectId >= MAX_EFFECT_INDEX)
{
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Spell %u listed in `spell_affect` have invalid effect index (%u)", entry, effectId);
continue;
}

if (spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || (
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER &&
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_OVERRIDE_CLASS_SCRIPTS))
{
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) or SPELL_AURA_OVERRIDE_CLASS_SCRIPTS (%u) for effect index (%u)", entry, SPELL_AURA_ADD_FLAT_MODIFIER, SPELL_AURA_ADD_PCT_MODIFIER, SPELL_AURA_ADD_TARGET_TRIGGER, SPELL_AURA_OVERRIDE_CLASS_SCRIPTS, effectId);
continue;
}

uint64 spellAffectMask = fields[2].GetUInt64();

// Spell.dbc have own data for low part of SpellFamilyMask
if (spellInfo->EffectItemType[effectId])
{
if (static_cast<uint64>(spellInfo->EffectItemType[effectId]) == spellAffectMask)
{
sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Spell %u listed in `spell_affect` have redundant (same with EffectItemType%d) data for effect index (%u) and not needed, skipped.", entry, effectId + 1, effectId);
continue;
}
}

mSpellAffectMap.insert(SpellAffectMap::value_type((entry << 8) + effectId, spellAffectMask));

++count;
}
while (result->NextRow());

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "");
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u spell affect definitions", count);

for (uint32 id = 0; id < sSpellMgr.GetMaxSpellId(); ++id)
{
SpellEntry const* spellInfo = sSpellMgr.GetSpellEntry(id);
if (!spellInfo)
continue;

for (uint8 effectId = 0; effectId < MAX_EFFECT_INDEX; ++effectId)
{
if (spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || (
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER))
continue;

if (spellInfo->EffectItemType[effectId] != 0)
continue;

if (mSpellAffectMap.find((id << 8) + effectId) != mSpellAffectMap.end())
continue;

sLog.Out(LOG_DBERROR, LOG_LVL_MINIMAL, "Spell %u (%s) misses spell_affect for effect %u", id, spellInfo->SpellName[sWorld.GetDefaultDbcLocale()].c_str(), effectId);
}
}
}

void SpellMgr::LoadExistingSpellIds()
{
mExistingSpellsSet.clear();
Expand Down Expand Up @@ -3841,9 +3740,9 @@ void SpellMgr::LoadSpells()
spell->EffectChainTarget[0] = fields[104].GetUInt32();
spell->EffectChainTarget[1] = fields[105].GetUInt32();
spell->EffectChainTarget[2] = fields[106].GetUInt32();
spell->EffectItemType[0] = fields[107].GetUInt32();
spell->EffectItemType[1] = fields[108].GetUInt32();
spell->EffectItemType[2] = fields[109].GetUInt32();
spell->EffectItemType[0] = fields[107].GetUInt64();
spell->EffectItemType[1] = fields[108].GetUInt64();
spell->EffectItemType[2] = fields[109].GetUInt64();
spell->EffectMiscValue[0] = fields[110].GetInt32();
spell->EffectMiscValue[1] = fields[111].GetInt32();
spell->EffectMiscValue[2] = fields[112].GetInt32();
Expand Down
8 changes: 0 additions & 8 deletions src/game/Spells/SpellMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class Player;
class Spell;
class Unit;

// Spell affects related declarations (accessed using SpellMgr functions)
typedef std::map<uint32, uint64> SpellAffectMap;

struct SpellProcEventEntry
{
uint32 schoolMask;
Expand Down Expand Up @@ -391,9 +388,6 @@ class SpellMgr
// Spell affects
uint64 GetSpellAffectMask(uint32 spellId, SpellEffectIndex effectId) const
{
SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
if (itr != mSpellAffectMap.end())
return itr->second;
if (SpellEntry const* spellEntry = GetSpellEntry(spellId))
return spellEntry->EffectItemType[effectId];
return 0;
Expand Down Expand Up @@ -682,7 +676,6 @@ class SpellMgr
void LoadSpellLearnSkills();
void LoadSpellLearnSpells();
void LoadSpellScriptTarget();
void LoadSpellAffects();
void LoadSpellElixirs();
void LoadSpellProcEvents();
void LoadSpellProcItemEnchant();
Expand Down Expand Up @@ -729,7 +722,6 @@ class SpellMgr
SpellLearnSkillMap mSpellLearnSkills;
SpellLearnSpellMap mSpellLearnSpells;
SpellTargetPositionMap mSpellTargetPositions;
SpellAffectMap mSpellAffectMap;
SpellElixirMap mSpellElixirs;
SpellThreatMap mSpellThreatMap;
SpellProcEventMap mSpellProcEventMap;
Expand Down
8 changes: 7 additions & 1 deletion src/game/Spells/SpellModMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ SpellModMgr::~SpellModMgr()
SQL : cf sql/nostalrius/spell_mod.sql et sql/nostalrius/spell_effect_mod.sql
*/

inline void ModUInt64ValueIfExplicit(Field &f, uint64& value)
{
if (f.GetInt64() >= 0)
value = f.GetUInt64();
}

inline void ModUInt32ValueIfExplicit(Field &f, uint32& value)
{
if (f.GetInt32() >= 0)
Expand Down Expand Up @@ -238,7 +244,7 @@ void SpellModMgr::LoadSpellMods()
// 7 8 9 10
// EffectRadiusIndex, EffectItemType, EffectMiscValue, EffectTriggerSpell
ModUInt32ValueIfExplicit(fields[7], spell->EffectRadiusIndex[effect_idx]);
ModUInt32ValueIfExplicit(fields[8], spell->EffectItemType[effect_idx]);
ModUInt64ValueIfExplicit(fields[8], spell->EffectItemType[effect_idx]);
ModInt32ValueIfExplicit(fields[9], spell->EffectMiscValue[effect_idx]);
ModUInt32ValueIfExplicit(fields[10], spell->EffectTriggerSpell[effect_idx]);

Expand Down
3 changes: 0 additions & 3 deletions src/game/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,9 +1599,6 @@ void World::SetInitialWorldSettings()
sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Loading spell target destination coordinates...");
sSpellMgr.LoadSpellTargetPositions();

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Loading SpellAffect definitions...");
sSpellMgr.LoadSpellAffects();

sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Loading spell pet auras...");
sSpellMgr.LoadSpellPetAuras();

Expand Down
12 changes: 10 additions & 2 deletions src/shared/Database/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ class Field
}
float GetFloat() const { return mValue ? static_cast<float>(atof(mValue)) : 0.0f; }
bool GetBool() const { return mValue ? atoi(mValue) > 0 : false; }
int32 GetInt32() const { return mValue ? static_cast<int32>(atol(mValue)) : int32(0); }
uint8 GetUInt8() const { return mValue ? static_cast<uint8>(atol(mValue)) : uint8(0); }
uint16 GetUInt16() const { return mValue ? static_cast<uint16>(atol(mValue)) : uint16(0); }
int16 GetInt16() const { return mValue ? static_cast<int16>(atol(mValue)) : int16(0); }
uint16 GetUInt16() const { return mValue ? static_cast<uint16>(atol(mValue)) : uint16(0); }
int32 GetInt32() const { return mValue ? static_cast<int32>(atol(mValue)) : int32(0); }
uint32 GetUInt32() const { return mValue ? static_cast<uint32>(atol(mValue)) : uint32(0); }
int64 GetInt64() const
{
int64 value = 0;
if (!mValue || sscanf(mValue, SI64FMTD, &value) == -1)
return 0;

return value;
}
uint64 GetUInt64() const
{
uint64 value = 0;
Expand Down

0 comments on commit 9e63169

Please sign in to comment.