Core/Players: Fix reusing skill slots when re-learning a skill

Port From (https://github.com/TrinityCore/TrinityCore/commit/9aa5f625a6177b47325635bddee8d603aa9dc769)
This commit is contained in:
hondacrx
2020-02-09 16:55:42 -05:00
parent 752137af52
commit 0c919ad97d
+36 -23
View File
@@ -1162,20 +1162,36 @@ namespace Game.Entities
} }
else //add else //add
{ {
currVal = 0; // Check if the player already has a skill, otherwise pick a empty skill slot if available
for (uint i = 0; i < SkillConst.MaxPlayerSkills; ++i) byte skillSlot = skillStatusData != null ? skillStatusData.Pos : (byte)0;
if (skillSlot == 0)
{ {
if (skillInfoField.SkillLineID[(int)i] == 0) for (int i = 0; i < SkillConst.MaxPlayerSkills; ++i)
{ {
var skillEntry = CliDB.SkillLineStorage.LookupByKey(id); if (((SkillInfo)m_activePlayerData.Skill).SkillLineID[i] == 0)
if (skillEntry == null)
{ {
Log.outError(LogFilter.Spells, "Skill not found in SkillLineStore: skill #{0}", id); skillSlot = (byte)i;
break;
}
}
}
if (skillSlot == 0)
{
Log.outError(LogFilter.Misc, $"Tried to add skill #{id} but the player cannot have additional skills");
return; return;
} }
SkillLineRecord skillEntry = CliDB.SkillLineStorage.LookupByKey(id);
if (skillEntry == null)
{
Log.outError(LogFilter.Misc, $"Player.SetSkill: Skill (SkillID: {id}) not found in SkillLineStore for player '{GetName()}' ({GetGUID().ToString()})");
return;
}
if (skillEntry.ParentSkillLineID != 0) if (skillEntry.ParentSkillLineID != 0)
{
if (skillEntry.ParentTierIndex > 0)
{ {
SkillRaceClassInfoRecord rcEntry = Global.DB2Mgr.GetSkillRaceClassInfo(skillEntry.ParentSkillLineID, GetRace(), GetClass()); SkillRaceClassInfoRecord rcEntry = Global.DB2Mgr.GetSkillRaceClassInfo(skillEntry.ParentSkillLineID, GetRace(), GetClass());
if (rcEntry != null) if (rcEntry != null)
@@ -1188,8 +1204,10 @@ namespace Game.Entities
} }
} }
} }
}
else else
{ // also learn missing child skills at 0 value {
// also learn missing child skills at 0 value
List<SkillLineRecord> childSkillLines = Global.DB2Mgr.GetSkillLinesForParentSkill(id); List<SkillLineRecord> childSkillLines = Global.DB2Mgr.GetSkillLinesForParentSkill(id);
if (childSkillLines != null) if (childSkillLines != null)
foreach (SkillLineRecord childSkillLine in childSkillLines) foreach (SkillLineRecord childSkillLine in childSkillLines)
@@ -1204,27 +1222,25 @@ namespace Game.Entities
} }
} }
SetSkillLineId(i, (ushort)id); if (skillStatusData == null)
SetSkillLineId(skillSlot, (ushort)id);
SetSkillStep(i, (ushort)step); SetSkillStep(skillSlot, (ushort)step);
SetSkillRank(i, (ushort)newVal); SetSkillRank(skillSlot, (ushort)newVal);
SetSkillStartingRank(i, 1); SetSkillStartingRank(skillSlot, 1);
SetSkillMaxRank(i, (ushort)maxVal); SetSkillMaxRank(skillSlot, (ushort)maxVal);
// apply skill bonuses // apply skill bonuses
SetSkillTempBonus(i, 0); SetSkillTempBonus(skillSlot, 0);
SetSkillPermBonus(i, 0); SetSkillPermBonus(skillSlot, 0);
UpdateSkillEnchantments(id, currVal, (ushort)newVal); UpdateSkillEnchantments(id, 0, (ushort)newVal);
// insert new entry or update if not deleted old entry yet // update or add entry
if (skillStatusData != null) if (skillStatusData != null)
{
skillStatusData.Pos = (byte)i;
skillStatusData.State = SkillState.Changed; skillStatusData.State = SkillState.Changed;
}
else else
mSkillStatus.Add(id, new SkillStatusData((uint)i, SkillState.New)); mSkillStatus.Add(id, new SkillStatusData((uint)skillSlot, SkillState.New));
if (newVal != 0) if (newVal != 0)
{ {
@@ -1251,9 +1267,6 @@ namespace Game.Entities
// Learn all spells for skill // Learn all spells for skill
LearnSkillRewardedSpells(id, newVal); LearnSkillRewardedSpells(id, newVal);
} }
return;
}
}
} }
} }