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
{
currVal = 0;
for (uint i = 0; i < SkillConst.MaxPlayerSkills; ++i)
// Check if the player already has a skill, otherwise pick a empty skill slot if available
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 (skillEntry == null)
if (((SkillInfo)m_activePlayerData.Skill).SkillLineID[i] == 0)
{
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;
}
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.ParentTierIndex > 0)
{
SkillRaceClassInfoRecord rcEntry = Global.DB2Mgr.GetSkillRaceClassInfo(skillEntry.ParentSkillLineID, GetRace(), GetClass());
if (rcEntry != null)
@@ -1188,8 +1204,10 @@ namespace Game.Entities
}
}
}
}
else
{ // also learn missing child skills at 0 value
{
// also learn missing child skills at 0 value
List<SkillLineRecord> childSkillLines = Global.DB2Mgr.GetSkillLinesForParentSkill(id);
if (childSkillLines != null)
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);
SetSkillRank(i, (ushort)newVal);
SetSkillStartingRank(i, 1);
SetSkillMaxRank(i, (ushort)maxVal);
SetSkillStep(skillSlot, (ushort)step);
SetSkillRank(skillSlot, (ushort)newVal);
SetSkillStartingRank(skillSlot, 1);
SetSkillMaxRank(skillSlot, (ushort)maxVal);
// apply skill bonuses
SetSkillTempBonus(i, 0);
SetSkillPermBonus(i, 0);
SetSkillTempBonus(skillSlot, 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)
{
skillStatusData.Pos = (byte)i;
skillStatusData.State = SkillState.Changed;
}
else
mSkillStatus.Add(id, new SkillStatusData((uint)i, SkillState.New));
mSkillStatus.Add(id, new SkillStatusData((uint)skillSlot, SkillState.New));
if (newVal != 0)
{
@@ -1251,9 +1267,6 @@ namespace Game.Entities
// Learn all spells for skill
LearnSkillRewardedSpells(id, newVal);
}
return;
}
}
}
}