Core/Players: Learn parent skilllines if they are missing while learning child skills

Port From (https://github.com/TrinityCore/TrinityCore/commit/9022f2374884b966c3ecf7199c52498140775668)
This commit is contained in:
hondacrx
2024-02-03 17:39:25 -05:00
parent 5606501071
commit 1d4a30cc2d
4 changed files with 54 additions and 15 deletions
+23 -9
View File
@@ -333,7 +333,6 @@ namespace Game.Entities
void _LoadSkills(SQLResult result)
{
Race race = GetRace();
uint count = 0;
Dictionary<uint, uint> loadedSkillValues = new();
List<ushort> loadedProfessionsWithoutSlot = new(); // fixup old characters
if (!result.IsEmpty())
@@ -414,22 +413,37 @@ namespace Game.Entities
while (result.NextRow());
}
// Learn skill rewarded spells after all skills have been loaded to prevent learning a skill from them before its loaded with proper value from DB
foreach (var skill in loadedSkillValues)
foreach (var (skillId, skillValue) in loadedSkillValues)
{
LearnSkillRewardedSpells(skill.Key, skill.Value, race);
List<SkillLineRecord> childSkillLines = Global.DB2Mgr.GetSkillLinesForParentSkill(skill.Key);
LearnSkillRewardedSpells(skillId, skillValue, race);
// enable parent skill line if missing
var skillEntry = CliDB.SkillLineStorage.LookupByKey(skillId);
if (skillEntry.ParentSkillLineID != 0 && skillEntry.ParentTierIndex > 0 && GetSkillStep(skillEntry.ParentSkillLineID) < skillEntry.ParentTierIndex)
{
var rcEntry = Global.DB2Mgr.GetSkillRaceClassInfo(skillEntry.ParentSkillLineID, GetRace(), GetClass());
if (rcEntry != null)
{
var tier = Global.ObjectMgr.GetSkillTier(rcEntry.SkillTierID);
if (tier != null)
SetSkill(skillEntry.ParentSkillLineID, (uint)skillEntry.ParentTierIndex, Math.Max(GetPureSkillValue(skillEntry.ParentSkillLineID), 1u), tier.GetValueForTierIndex(skillEntry.ParentTierIndex - 1));
}
}
List<SkillLineRecord> childSkillLines = Global.DB2Mgr.GetSkillLinesForParentSkill(skillId);
if (childSkillLines != null)
{
foreach (var childItr in childSkillLines)
foreach (var childSkillLine in childSkillLines)
{
if (mSkillStatus.Count >= SkillConst.MaxPlayerSkills)
break;
if (!mSkillStatus.ContainsKey(childItr.Id))
if (!mSkillStatus.ContainsKey(childSkillLine.Id))
{
SetSkillLineId(count, (ushort)childItr.Id);
SetSkillStartingRank(count, 1);
mSkillStatus.Add(childItr.Id, new SkillStatusData(count, SkillState.Unchanged));
uint pos = (uint)mSkillStatus.Count;
SetSkillLineId(pos, (ushort)childSkillLine.Id);
SetSkillStartingRank(pos, 1);
mSkillStatus.Add(childSkillLine.Id, new SkillStatusData(pos, SkillState.Unchanged));
}
}
}
+18 -4
View File
@@ -1097,6 +1097,18 @@ namespace Game.Entities
// Activate and update skill line
if (newVal != 0)
{
// enable parent skill line if missing
if (skillEntry.ParentSkillLineID != 0 && skillEntry.ParentTierIndex > 0 && GetSkillStep(skillEntry.ParentSkillLineID) < skillEntry.ParentTierIndex)
{
var rcEntry = Global.DB2Mgr.GetSkillRaceClassInfo(skillEntry.ParentSkillLineID, GetRace(), GetClass());
if (rcEntry != null)
{
var tier = Global.ObjectMgr.GetSkillTier(rcEntry.SkillTierID);
if (tier != null)
SetSkill(skillEntry.ParentSkillLineID, (uint)skillEntry.ParentTierIndex, Math.Max(GetPureSkillValue(skillEntry.ParentSkillLineID), 1u), tier.GetValueForTierIndex(skillEntry.ParentTierIndex - 1));
}
}
// if skill value is going down, update enchantments before setting the new value
if (newVal < currVal)
UpdateSkillEnchantments(id, currVal, (ushort)newVal);
@@ -1231,7 +1243,7 @@ namespace Game.Entities
if (tier != null)
{
ushort skillval = GetPureSkillValue((SkillType)skillEntry.ParentSkillLineID);
SetSkill(skillEntry.ParentSkillLineID, (uint)skillEntry.ParentTierIndex, Math.Max(skillval, (ushort)1), tier.Value[skillEntry.ParentTierIndex - 1]);
SetSkill(skillEntry.ParentSkillLineID, (uint)skillEntry.ParentTierIndex, Math.Max(skillval, (ushort)1), tier.GetValueForTierIndex(skillEntry.ParentTierIndex - 1));
}
}
}
@@ -2094,7 +2106,7 @@ namespace Game.Entities
case SkillRangeType.Rank:
{
SkillTiersEntry tier = Global.ObjectMgr.GetSkillTier(rcInfo.SkillTierID);
ushort maxValue = (ushort)tier.Value[0];
ushort maxValue = (ushort)tier.GetValueForTierIndex(0);
ushort skillValue = 1;
if (rcInfo.Flags.HasAnyFlag(SkillRaceClassInfoFlags.AlwaysMaxValue))
skillValue = maxValue;
@@ -2291,7 +2303,7 @@ namespace Game.Entities
case SkillRangeType.Rank:
{
var tier = Global.ObjectMgr.GetSkillTier(rcInfo.SkillTierID);
new_skill_max_value = (ushort)tier.Value[prevSkill.step - 1];
new_skill_max_value = (ushort)tier.GetValueForTierIndex(prevSkill.step - 1);
break;
}
default:
@@ -2799,7 +2811,7 @@ namespace Game.Entities
case SkillRangeType.Rank:
{
var tier = Global.ObjectMgr.GetSkillTier(rcInfo.SkillTierID);
new_skill_max_value = (ushort)tier.Value[spellLearnSkill.step - 1];
new_skill_max_value = (ushort)tier.GetValueForTierIndex(spellLearnSkill.step - 1);
break;
}
default:
@@ -2876,6 +2888,7 @@ namespace Game.Entities
// return true (for send learn packet) only if spell active (in case ranked spells) and not replace old spell
return active && !disabled && !superceded_old;
}
public override bool HasSpell(uint spellId)
{
var spell = m_spells.LookupByKey(spellId);
@@ -2884,6 +2897,7 @@ namespace Game.Entities
return false;
}
public bool HasActiveSpell(uint spellId)
{
var spell = m_spells.LookupByKey(spellId);
+11
View File
@@ -11686,6 +11686,17 @@ namespace Game
{
public uint Id;
public uint[] Value = new uint[SkillConst.MaxSkillStep];
public uint GetValueForTierIndex(int tierIndex)
{
if (tierIndex >= SkillConst.MaxSkillStep)
tierIndex = (int)SkillConst.MaxSkillStep - 1;
while (Value[tierIndex] == 0 && tierIndex > 0)
--tierIndex;
return Value[tierIndex];
}
}
public class TerrainSwapInfo
+2 -2
View File
@@ -1962,7 +1962,7 @@ namespace Game.Spells
return;
ushort skillval = Math.Max((ushort)1, playerTarget.GetPureSkillValue(skillid));
ushort maxSkillVal = (ushort)tier.Value[damage - 1];
ushort maxSkillVal = (ushort)tier.GetValueForTierIndex(damage - 1);
if (rcEntry.Flags.HasAnyFlag(SkillRaceClassInfoFlags.AlwaysMaxValue))
skillval = maxSkillVal;
@@ -4297,7 +4297,7 @@ namespace Game.Spells
return;
ushort skillval = Math.Max((ushort)1, playerTarget.GetPureSkillValue(skillid));
ushort maxSkillVal = (ushort)tier.Value[damage - 1];
ushort maxSkillVal = (ushort)tier.GetValueForTierIndex(damage - 1);
if (rcEntry.Flags.HasAnyFlag(SkillRaceClassInfoFlags.AlwaysMaxValue))
skillval = maxSkillVal;