Core/Players: Fixed pvp talents being reset on login if player is below level 110 (pre level squish code)

Port From (https://github.com/TrinityCore/TrinityCore/commit/9c90a18ee5ecccf597388fe52633813c6d2c5726)
This commit is contained in:
hondacrx
2022-01-28 17:15:36 -05:00
parent 7531735669
commit 300ab632e0
5 changed files with 157 additions and 150 deletions
-141
View File
@@ -27,7 +27,6 @@ using Game.PvP;
using Game.Spells;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Game.Entities
{
@@ -308,146 +307,6 @@ namespace Game.Entities
public void ActivatePvpItemLevels(bool activate) { _usePvpItemLevels = activate; }
public bool IsUsingPvpItemLevels() { return _usePvpItemLevels; }
void ResetPvpTalents()
{
foreach (var talentInfo in CliDB.PvpTalentStorage.Values)
{
if (talentInfo == null)
continue;
RemovePvpTalent(talentInfo);
}
SQLTransaction trans = new();
_SaveTalents(trans);
_SaveSpells(trans);
DB.Characters.CommitTransaction(trans);
}
public TalentLearnResult LearnPvpTalent(uint talentID, byte slot, ref uint spellOnCooldown)
{
if (slot >= PlayerConst.MaxPvpTalentSlots)
return TalentLearnResult.FailedUnknown;
if (IsInCombat())
return TalentLearnResult.FailedAffectingCombat;
if (IsDead())
return TalentLearnResult.FailedCantDoThatRightNow;
PvpTalentRecord talentInfo = CliDB.PvpTalentStorage.LookupByKey(talentID);
if (talentInfo == null)
return TalentLearnResult.FailedUnknown;
if (talentInfo.SpecID != GetPrimarySpecialization())
return TalentLearnResult.FailedUnknown;
if (talentInfo.LevelRequired > GetLevel())
return TalentLearnResult.FailedUnknown;
if (Global.DB2Mgr.GetRequiredLevelForPvpTalentSlot(slot, GetClass()) > GetLevel())
return TalentLearnResult.FailedUnknown;
PvpTalentCategoryRecord talentCategory = CliDB.PvpTalentCategoryStorage.LookupByKey(talentInfo.PvpTalentCategoryID);
if (talentCategory != null)
if (!Convert.ToBoolean(talentCategory.TalentSlotMask & (1 << slot)))
return TalentLearnResult.FailedUnknown;
// Check if player doesn't have this talent in other slot
if (HasPvpTalent(talentID, GetActiveTalentGroup()))
return TalentLearnResult.FailedUnknown;
PvpTalentRecord talent = CliDB.PvpTalentStorage.LookupByKey(GetPvpTalentMap(GetActiveTalentGroup())[slot]);
if (talent != null)
{
if (!HasPlayerFlag(PlayerFlags.Resting) && !HasUnitFlag2(UnitFlags2.AllowChangingTalents))
return TalentLearnResult.FailedRestArea;
if (GetSpellHistory().HasCooldown(talent.SpellID))
{
spellOnCooldown = talent.SpellID;
return TalentLearnResult.FailedCantRemoveTalent;
}
RemovePvpTalent(talent);
}
if (!AddPvpTalent(talentInfo, GetActiveTalentGroup(), slot))
return TalentLearnResult.FailedUnknown;
return TalentLearnResult.LearnOk;
}
bool AddPvpTalent(PvpTalentRecord talent, byte activeTalentGroup, byte slot)
{
//ASSERT(talent);
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talent.SpellID, Difficulty.None);
if (spellInfo == null)
{
Log.outError(LogFilter.Spells, $"Player.AddPvpTalent: Spell (ID: {talent.SpellID}) does not exist.");
return false;
}
if (!Global.SpellMgr.IsSpellValid(spellInfo, this, false))
{
Log.outError(LogFilter.Spells, $"Player.AddPvpTalent: Spell (ID: {talent.SpellID}) is invalid");
return false;
}
if (HasPvpRulesEnabled())
LearnSpell(talent.SpellID, false);
// Move this to toggle ?
if (talent.OverridesSpellID != 0)
AddOverrideSpell(talent.OverridesSpellID, talent.SpellID);
GetPvpTalentMap(activeTalentGroup)[slot] = talent.Id;
return true;
}
void RemovePvpTalent(PvpTalentRecord talent)
{
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(talent.SpellID, Difficulty.None);
if (spellInfo == null)
return;
RemoveSpell(talent.SpellID, true);
// Move this to toggle ?
if (talent.OverridesSpellID != 0)
RemoveOverrideSpell(talent.OverridesSpellID, talent.SpellID);
// if this talent rank can be found in the PlayerTalentMap, mark the talent as removed so it gets deleted
var talents = GetPvpTalentMap(GetActiveTalentGroup());
for (var i = 0; i < PlayerConst.MaxPvpTalentSlots; ++i)
{
if (talents[i] == talent.Id)
talents[i] = 0;
}
}
public void TogglePvpTalents(bool enable)
{
var pvpTalents = GetPvpTalentMap(GetActiveTalentGroup());
foreach (uint pvpTalentId in pvpTalents)
{
PvpTalentRecord pvpTalentInfo = CliDB.PvpTalentStorage.LookupByKey(pvpTalentId);
if (pvpTalentInfo != null)
{
if (enable)
LearnSpell(pvpTalentInfo.SpellID, false);
else
RemoveSpell(pvpTalentInfo.SpellID, true);
}
}
}
bool HasPvpTalent(uint talentID, byte activeTalentGroup)
{
return GetPvpTalentMap(activeTalentGroup).Contains(talentID);
}
public void EnablePvpRules(bool dueToCombat = false)
{
if (HasPvpRulesEnabled())