Core/Players: Fixed spells being unintentionally removed by talent swaps when they are learned from more than one spell (affects balance druid Celesial Alignment and Incarnation)

Port From (https://github.com/TrinityCore/TrinityCore/commit/2c6ddcce3d6374a82214bb0ddb9d7432351982c9)
This commit is contained in:
Hondacrx
2024-10-09 00:25:13 -04:00
parent 4c3074d462
commit 3c3c84b736
3 changed files with 27 additions and 1 deletions
@@ -2331,6 +2331,18 @@ namespace Game.Entities
foreach (var spellNode in spell_bounds) foreach (var spellNode in spell_bounds)
{ {
bool hasOtherSpellTeachingThis = Global.SpellMgr.GetSpellLearnedBySpellMapBounds(spellNode.Spell).Any(learnNode =>
{
if (learnNode.SourceSpell == spellId)
return false;
if (!learnNode.Active)
return false;
return HasSpell(learnNode.SourceSpell);
});
if (hasOtherSpellTeachingThis)
continue;
RemoveSpell(spellNode.Spell, disabled); RemoveSpell(spellNode.Spell, disabled);
if (spellNode.OverridesSpell != 0) if (spellNode.OverridesSpell != 0)
RemoveOverrideSpell(spellNode.OverridesSpell, spellNode.Spell); RemoveOverrideSpell(spellNode.OverridesSpell, spellNode.Spell);
+1
View File
@@ -8708,6 +8708,7 @@ namespace Game.Spells
public class SpellLearnSpellNode public class SpellLearnSpellNode
{ {
public uint SourceSpell;
public uint Spell; public uint Spell;
public uint OverridesSpell; public uint OverridesSpell;
public bool Active; // show in spellbook or not public bool Active; // show in spellbook or not
+13
View File
@@ -289,6 +289,11 @@ namespace Game.Entities
return false; return false;
} }
public List<SpellLearnSpellNode> GetSpellLearnedBySpellMapBounds(uint learnedSpellId)
{
return mSpellLearnedBySpells.LookupByKey(learnedSpellId);
}
public SpellTargetPosition GetSpellTargetPosition(uint spell_id, uint effIndex) public SpellTargetPosition GetSpellTargetPosition(uint spell_id, uint effIndex)
{ {
return mSpellTargetPositions.LookupByKey(new KeyValuePair<uint, uint>(spell_id, effIndex)); return mSpellTargetPositions.LookupByKey(new KeyValuePair<uint, uint>(spell_id, effIndex));
@@ -849,6 +854,7 @@ namespace Game.Entities
{ {
uint oldMSTime = Time.GetMSTime(); uint oldMSTime = Time.GetMSTime();
mSpellLearnedBySpells.Clear();
mSpellLearnSpells.Clear(); mSpellLearnSpells.Clear();
// 0 1 2 // 0 1 2
@@ -864,6 +870,7 @@ namespace Game.Entities
uint spell_id = result.Read<uint>(0); uint spell_id = result.Read<uint>(0);
var node = new SpellLearnSpellNode(); var node = new SpellLearnSpellNode();
node.SourceSpell = spell_id;
node.Spell = result.Read<uint>(1); node.Spell = result.Read<uint>(1);
node.OverridesSpell = 0; node.OverridesSpell = 0;
node.Active = result.Read<bool>(2); node.Active = result.Read<bool>(2);
@@ -904,6 +911,7 @@ namespace Game.Entities
if (spellEffectInfo.Effect == SpellEffectName.LearnSpell) if (spellEffectInfo.Effect == SpellEffectName.LearnSpell)
{ {
var dbc_node = new SpellLearnSpellNode(); var dbc_node = new SpellLearnSpellNode();
dbc_node.SourceSpell = entry.Id;
dbc_node.Spell = spellEffectInfo.TriggerSpell; dbc_node.Spell = spellEffectInfo.TriggerSpell;
dbc_node.Active = true; // all dbc based learned spells is active (show in spell book or hide by client itself) dbc_node.Active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
dbc_node.OverridesSpell = 0; dbc_node.OverridesSpell = 0;
@@ -976,6 +984,7 @@ namespace Game.Entities
continue; continue;
SpellLearnSpellNode dbcLearnNode = new(); SpellLearnSpellNode dbcLearnNode = new();
dbcLearnNode.SourceSpell = spellLearnSpell.SpellID;
dbcLearnNode.Spell = spellLearnSpell.LearnSpellID; dbcLearnNode.Spell = spellLearnSpell.LearnSpellID;
dbcLearnNode.OverridesSpell = spellLearnSpell.OverridesSpellID; dbcLearnNode.OverridesSpell = spellLearnSpell.OverridesSpellID;
dbcLearnNode.Active = true; dbcLearnNode.Active = true;
@@ -985,6 +994,9 @@ namespace Game.Entities
++dbc_count; ++dbc_count;
} }
foreach (var (_, learnedSpellNode) in mSpellLearnSpells)
mSpellLearnedBySpells.Add(learnedSpellNode.Spell, learnedSpellNode);
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} spell learn spells, {1} found in Spell.dbc in {2} ms", count, dbc_count, Time.GetMSTimeDiffToNow(oldMSTime)); Log.outInfo(LogFilter.ServerLoading, "Loaded {0} spell learn spells, {1} found in Spell.dbc in {2} ms", count, dbc_count, Time.GetMSTimeDiffToNow(oldMSTime));
} }
@@ -4903,6 +4915,7 @@ namespace Game.Entities
MultiMap<uint, uint> mSpellReq = new(); MultiMap<uint, uint> mSpellReq = new();
Dictionary<uint, SpellLearnSkillNode> mSpellLearnSkills = new(); Dictionary<uint, SpellLearnSkillNode> mSpellLearnSkills = new();
MultiMap<uint, SpellLearnSpellNode> mSpellLearnSpells = new(); MultiMap<uint, SpellLearnSpellNode> mSpellLearnSpells = new();
MultiMap<uint, SpellLearnSpellNode> mSpellLearnedBySpells = new();
Dictionary<KeyValuePair<uint, uint>, SpellTargetPosition> mSpellTargetPositions = new(); Dictionary<KeyValuePair<uint, uint>, SpellTargetPosition> mSpellTargetPositions = new();
MultiMap<uint, SpellGroup> mSpellSpellGroup = new(); MultiMap<uint, SpellGroup> mSpellSpellGroup = new();
MultiMap<SpellGroup, int> mSpellGroupSpell = new(); MultiMap<SpellGroup, int> mSpellGroupSpell = new();