Core/Players: Implemented setting tradeskill recipes as favorite

Port From (https://github.com/TrinityCore/TrinityCore/commit/0555ab2f56e5ad326948df96f5c2e35254e0cf4f)
This commit is contained in:
hondacrx
2023-01-04 16:25:50 -05:00
parent 66605b58ac
commit a6a063d526
7 changed files with 101 additions and 22 deletions
@@ -92,6 +92,7 @@ namespace Framework.Database
PrepareStatement(CharStatements.SEL_CHARACTER_AURAS, "SELECT casterGuid, itemGuid, spell, effectMask, recalculateMask, difficulty, stackCount, maxDuration, remainTime, remainCharges, castItemId, castItemLevel FROM character_aura WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_AURAS, "SELECT casterGuid, itemGuid, spell, effectMask, recalculateMask, difficulty, stackCount, maxDuration, remainTime, remainCharges, castItemId, castItemLevel FROM character_aura WHERE guid = ?");
PrepareStatement(CharStatements.SEL_CHARACTER_AURA_EFFECTS, "SELECT casterGuid, itemGuid, spell, effectMask, effectIndex, amount, baseAmount FROM character_aura_effect WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_AURA_EFFECTS, "SELECT casterGuid, itemGuid, spell, effectMask, effectIndex, amount, baseAmount FROM character_aura_effect WHERE guid = ?");
PrepareStatement(CharStatements.SEL_CHARACTER_SPELL, "SELECT spell, active, disabled FROM character_spell WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_SPELL, "SELECT spell, active, disabled FROM character_spell WHERE guid = ?");
PrepareStatement(CharStatements.SEL_CHARACTER_SPELL_FAVORITES, "SELECT spell FROM character_spell_favorite WHERE guid = ?");
PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS, "SELECT quest, status, explored, acceptTime, endTime FROM character_queststatus WHERE guid = ? AND status <> 0"); PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS, "SELECT quest, status, explored, acceptTime, endTime FROM character_queststatus WHERE guid = ? AND status <> 0");
PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS_OBJECTIVES, "SELECT quest, objective, data FROM character_queststatus_objectives WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS_OBJECTIVES, "SELECT quest, objective, data FROM character_queststatus_objectives WHERE guid = ?");
PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS_OBJECTIVES_CRITERIA, "SELECT questObjectiveId FROM character_queststatus_objectives_criteria WHERE guid = ?"); PrepareStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS_OBJECTIVES_CRITERIA, "SELECT questObjectiveId FROM character_queststatus_objectives_criteria WHERE guid = ?");
@@ -627,6 +628,9 @@ namespace Framework.Database
PrepareStatement(CharStatements.INS_CHAR_SKILLS, "INSERT INTO character_skills (guid, skill, value, max) VALUES (?, ?, ?, ?)"); PrepareStatement(CharStatements.INS_CHAR_SKILLS, "INSERT INTO character_skills (guid, skill, value, max) VALUES (?, ?, ?, ?)");
PrepareStatement(CharStatements.UPD_CHAR_SKILLS, "UPDATE character_skills SET value = ?, max = ? WHERE guid = ? AND skill = ?"); PrepareStatement(CharStatements.UPD_CHAR_SKILLS, "UPDATE character_skills SET value = ?, max = ? WHERE guid = ? AND skill = ?");
PrepareStatement(CharStatements.INS_CHAR_SPELL, "INSERT INTO character_spell (guid, spell, active, disabled) VALUES (?, ?, ?, ?)"); PrepareStatement(CharStatements.INS_CHAR_SPELL, "INSERT INTO character_spell (guid, spell, active, disabled) VALUES (?, ?, ?, ?)");
PrepareStatement(CharStatements.DEL_CHAR_SPELL_FAVORITE, "DELETE FROM character_spell_favorite WHERE guid = ? AND spell = ?");
PrepareStatement(CharStatements.DEL_CHAR_SPELL_FAVORITE_BY_CHAR, "DELETE FROM character_spell_favorite WHERE guid = ?");
PrepareStatement(CharStatements.INS_CHAR_SPELL_FAVORITE, "INSERT INTO character_spell_favorite (guid, spell) VALUES (?, ?)");
PrepareStatement(CharStatements.DEL_CHAR_STATS, "DELETE FROM character_stats WHERE guid = ?"); PrepareStatement(CharStatements.DEL_CHAR_STATS, "DELETE FROM character_stats WHERE guid = ?");
PrepareStatement(CharStatements.INS_CHAR_STATS, "INSERT INTO character_stats (guid, maxhealth, maxpower1, maxpower2, maxpower3, maxpower4, maxpower5, maxpower6, maxpower7, strength, agility, stamina, intellect, " + PrepareStatement(CharStatements.INS_CHAR_STATS, "INSERT INTO character_stats (guid, maxhealth, maxpower1, maxpower2, maxpower3, maxpower4, maxpower5, maxpower6, maxpower7, strength, agility, stamina, intellect, " +
"armor, resHoly, resFire, resNature, resFrost, resShadow, resArcane, blockPct, dodgePct, parryPct, critPct, rangedCritPct, spellCritPct, attackPower, rangedAttackPower, " + "armor, resHoly, resFire, resNature, resFrost, resShadow, resArcane, blockPct, dodgePct, parryPct, critPct, rangedCritPct, spellCritPct, attackPower, rangedAttackPower, " +
@@ -805,6 +809,7 @@ namespace Framework.Database
SEL_CHARACTER_AURAS, SEL_CHARACTER_AURAS,
SEL_CHARACTER_AURA_EFFECTS, SEL_CHARACTER_AURA_EFFECTS,
SEL_CHARACTER_SPELL, SEL_CHARACTER_SPELL,
SEL_CHARACTER_SPELL_FAVORITES,
SEL_CHARACTER_QUESTSTATUS, SEL_CHARACTER_QUESTSTATUS,
SEL_CHARACTER_QUESTSTATUS_OBJECTIVES, SEL_CHARACTER_QUESTSTATUS_OBJECTIVES,
@@ -1260,6 +1265,9 @@ namespace Framework.Database
INS_CHAR_SKILLS, INS_CHAR_SKILLS,
UPD_CHAR_SKILLS, UPD_CHAR_SKILLS,
INS_CHAR_SPELL, INS_CHAR_SPELL,
DEL_CHAR_SPELL_FAVORITE,
DEL_CHAR_SPELL_FAVORITE_BY_CHAR,
INS_CHAR_SPELL_FAVORITE,
DEL_CHAR_STATS, DEL_CHAR_STATS,
INS_CHAR_STATS, INS_CHAR_STATS,
DEL_PETITION_BY_OWNER, DEL_PETITION_BY_OWNER,
@@ -451,9 +451,6 @@ namespace Game.Entities
public List<uint> BonusListIDs = new(); public List<uint> BonusListIDs = new();
public uint PlayerConditionId; public uint PlayerConditionId;
public bool IgnoreFiltering; public bool IgnoreFiltering;
//helpers
public bool IsGoldRequired(ItemTemplate pProto) { return pProto.HasFlag(ItemFlags2.DontIgnoreBuyPrice) || ExtendedCost == 0; }
} }
public class VendorItemData public class VendorItemData
+42 -16
View File
@@ -450,7 +450,7 @@ namespace Game.Entities
if (HasSkill(SkillType.FistWeapons)) if (HasSkill(SkillType.FistWeapons))
SetSkill(SkillType.FistWeapons, 0, GetSkillValue(SkillType.Unarmed), GetMaxSkillValueForLevel()); SetSkill(SkillType.FistWeapons, 0, GetSkillValue(SkillType.Unarmed), GetMaxSkillValueForLevel());
} }
void _LoadSpells(SQLResult result) void _LoadSpells(SQLResult result, SQLResult favoritesResult)
{ {
if (!result.IsEmpty()) if (!result.IsEmpty())
{ {
@@ -460,6 +460,16 @@ namespace Game.Entities
} }
while (result.NextRow()); while (result.NextRow());
} }
if (!favoritesResult.IsEmpty())
{
do
{
var spell = m_spells.LookupByKey(favoritesResult.Read<uint>(0));
if (spell !=null)
spell.Favorite = true;
} while (favoritesResult.NextRow());
}
} }
void _LoadAuras(SQLResult auraResult, SQLResult effectResult, uint timediff) void _LoadAuras(SQLResult auraResult, SQLResult effectResult, uint timediff)
@@ -1823,35 +1833,51 @@ namespace Game.Entities
{ {
PreparedStatement stmt; PreparedStatement stmt;
foreach (var spell in m_spells.ToList()) foreach (var (id, spell) in m_spells.ToList())
{ {
if (spell.Value.State == PlayerSpellState.Removed || spell.Value.State == PlayerSpellState.Changed) if (spell.State == PlayerSpellState.Removed || spell.State == PlayerSpellState.Changed)
{ {
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_SPELL_BY_SPELL); stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_SPELL_BY_SPELL);
stmt.AddValue(0, spell.Key); stmt.AddValue(0, id);
stmt.AddValue(1, GetGUID().GetCounter()); stmt.AddValue(1, GetGUID().GetCounter());
trans.Append(stmt); trans.Append(stmt);
} }
// add only changed/new not dependent spells if (spell.State == PlayerSpellState.New || spell.State == PlayerSpellState.Changed)
if (!spell.Value.Dependent && (spell.Value.State == PlayerSpellState.New || spell.Value.State == PlayerSpellState.Changed))
{ {
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_SPELL); // add only changed/new not dependent spells
stmt.AddValue(0, GetGUID().GetCounter()); if (!spell.Dependent)
stmt.AddValue(1, spell.Key); {
stmt.AddValue(2, spell.Value.Active); stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_SPELL);
stmt.AddValue(3, spell.Value.Disabled); stmt.AddValue(0, GetGUID().GetCounter());
stmt.AddValue(1, id);
stmt.AddValue(2, spell.Active);
stmt.AddValue(3, spell.Disabled);
trans.Append(stmt);
}
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_SPELL_FAVORITE);
stmt.AddValue(0, id);
stmt.AddValue(1, GetGUID().GetCounter());
trans.Append(stmt); trans.Append(stmt);
if (spell.Favorite)
{
stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_SPELL_FAVORITE);
stmt.AddValue(0, GetGUID().GetCounter());
stmt.AddValue(1, id);
trans.Append(stmt);
}
} }
if (spell.Value.State == PlayerSpellState.Removed) if (spell.State == PlayerSpellState.Removed)
{ {
m_spells.Remove(spell.Key); m_spells.Remove(id);
continue; continue;
} }
if (spell.Value.State != PlayerSpellState.Temporary) if (spell.State != PlayerSpellState.Temporary)
spell.Value.State = PlayerSpellState.Unchanged; spell.State = PlayerSpellState.Unchanged;
} }
} }
void _SaveAuras(SQLTransaction trans) void _SaveAuras(SQLTransaction trans)
@@ -3294,7 +3320,7 @@ namespace Game.Entities
UpdateDisplayPower(); UpdateDisplayPower();
_LoadTalents(holder.GetResult(PlayerLoginQueryLoad.Talents)); _LoadTalents(holder.GetResult(PlayerLoginQueryLoad.Talents));
_LoadPvpTalents(holder.GetResult(PlayerLoginQueryLoad.PvpTalents)); _LoadPvpTalents(holder.GetResult(PlayerLoginQueryLoad.PvpTalents));
_LoadSpells(holder.GetResult(PlayerLoginQueryLoad.Spells)); _LoadSpells(holder.GetResult(PlayerLoginQueryLoad.Spells), holder.GetResult(PlayerLoginQueryLoad.SpellFavorites));
GetSession().GetCollectionMgr().LoadToys(); GetSession().GetCollectionMgr().LoadToys();
GetSession().GetCollectionMgr().LoadHeirlooms(); GetSession().GetCollectionMgr().LoadHeirlooms();
GetSession().GetCollectionMgr().LoadMounts(); GetSession().GetCollectionMgr().LoadMounts();
+23 -3
View File
@@ -2029,7 +2029,7 @@ namespace Game.Entities
void SendKnownSpells() void SendKnownSpells()
{ {
SendKnownSpells knownSpells = new(); SendKnownSpells knownSpells = new();
knownSpells.InitialLogin = false; // @todo knownSpells.InitialLogin = IsLoading();
foreach (var spell in m_spells.ToList()) foreach (var spell in m_spells.ToList())
{ {
@@ -2040,6 +2040,8 @@ namespace Game.Entities
continue; continue;
knownSpells.KnownSpells.Add(spell.Key); knownSpells.KnownSpells.Add(spell.Key);
if (spell.Value.Favorite)
knownSpells.FavoriteSpells.Add(spell.Key);
} }
SendPacket(knownSpells); SendPacket(knownSpells);
@@ -2056,8 +2058,9 @@ namespace Game.Entities
bool disabled = (spell != null) && spell.Disabled; bool disabled = (spell != null) && spell.Disabled;
bool active = !disabled || spell.Active; bool active = !disabled || spell.Active;
bool favorite = spell != null ? spell.Favorite : false;
bool learning = AddSpell(spellId, active, true, dependent, false, false, fromSkill, traitDefinitionId); bool learning = AddSpell(spellId, active, true, dependent, false, false, fromSkill, favorite, traitDefinitionId);
// prevent duplicated entires in spell book, also not send if not in world (loading) // prevent duplicated entires in spell book, also not send if not in world (loading)
if (learning && IsInWorld) if (learning && IsInWorld)
@@ -2065,6 +2068,7 @@ namespace Game.Entities
LearnedSpells learnedSpells = new(); LearnedSpells learnedSpells = new();
LearnedSpellInfo learnedSpellInfo = new(); LearnedSpellInfo learnedSpellInfo = new();
learnedSpellInfo.SpellID = spellId; learnedSpellInfo.SpellID = spellId;
learnedSpellInfo.IsFavorite = favorite;
learnedSpellInfo.TraitDefinitionID = traitDefinitionId; learnedSpellInfo.TraitDefinitionID = traitDefinitionId;
learnedSpells.SuppressMessaging = suppressMessaging; learnedSpells.SuppressMessaging = suppressMessaging;
learnedSpells.ClientLearnedSpellData.Add(learnedSpellInfo); learnedSpells.ClientLearnedSpellData.Add(learnedSpellInfo);
@@ -2268,6 +2272,18 @@ namespace Game.Entities
SendPacket(unlearnedSpells); SendPacket(unlearnedSpells);
} }
} }
public void SetSpellFavorite(uint spellId, bool favorite)
{
var spell = m_spells.LookupByKey(spellId);
if (spell == null)
return;
spell.Favorite = favorite;
if (spell.State == PlayerSpellState.Unchanged)
spell.State = PlayerSpellState.Changed;
}
bool HandlePassiveSpellLearn(SpellInfo spellInfo) bool HandlePassiveSpellLearn(SpellInfo spellInfo)
{ {
// note: form passives activated with shapeshift spells be implemented by HandleShapeshiftBoosts instead of spell_learn_spell // note: form passives activated with shapeshift spells be implemented by HandleShapeshiftBoosts instead of spell_learn_spell
@@ -2320,7 +2336,7 @@ namespace Game.Entities
return null; return null;
} }
bool AddSpell(uint spellId, bool active, bool learning, bool dependent, bool disabled, bool loading = false, uint fromSkill = 0, int? traitDefinitionId = null) bool AddSpell(uint spellId, bool active, bool learning, bool dependent, bool disabled, bool loading = false, uint fromSkill = 0, bool favorite = false, int? traitDefinitionId = null)
{ {
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None); SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None);
if (spellInfo == null) if (spellInfo == null)
@@ -2411,6 +2427,8 @@ namespace Game.Entities
spell.TraitDefinitionId = traitDefinitionId; spell.TraitDefinitionId = traitDefinitionId;
} }
spell.Favorite = favorite;
// update active state for known spell // update active state for known spell
if (spell.Active != active && spell.State != PlayerSpellState.Removed && !spell.Disabled) if (spell.Active != active && spell.State != PlayerSpellState.Removed && !spell.Disabled)
{ {
@@ -2492,6 +2510,7 @@ namespace Game.Entities
newspell.Active = active; newspell.Active = active;
newspell.Dependent = dependent; newspell.Dependent = dependent;
newspell.Disabled = disabled; newspell.Disabled = disabled;
newspell.Favorite = favorite;
if (traitDefinitionId.HasValue) if (traitDefinitionId.HasValue)
newspell.TraitDefinitionId = traitDefinitionId.Value; newspell.TraitDefinitionId = traitDefinitionId.Value;
@@ -3591,6 +3610,7 @@ namespace Game.Entities
public bool Active; public bool Active;
public bool Dependent; public bool Dependent;
public bool Disabled; public bool Disabled;
public bool Favorite;
public int? TraitDefinitionId; public int? TraitDefinitionId;
} }
} }
+5
View File
@@ -2659,6 +2659,10 @@ namespace Game
stmt.AddValue(0, lowGuid); stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.Spells, stmt); SetQuery(PlayerLoginQueryLoad.Spells, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_SPELL_FAVORITES);
stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.SpellFavorites, stmt);
stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS); stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_QUESTSTATUS);
stmt.AddValue(0, lowGuid); stmt.AddValue(0, lowGuid);
SetQuery(PlayerLoginQueryLoad.QuestStatus, stmt); SetQuery(PlayerLoginQueryLoad.QuestStatus, stmt);
@@ -2930,6 +2934,7 @@ namespace Game
AuraEffects, AuraEffects,
AuraStoredLocations, AuraStoredLocations,
Spells, Spells,
SpellFavorites,
QuestStatus, QuestStatus,
QuestStatusObjectives, QuestStatusObjectives,
QuestStatusObjectivesCriteria, QuestStatusObjectivesCriteria,
+9
View File
@@ -117,5 +117,14 @@ namespace Game
GetPlayer().SetSkill(packet.SkillLine, 0, 0, 0); GetPlayer().SetSkill(packet.SkillLine, 0, 0, 0);
} }
[WorldPacketHandler(ClientOpcodes.TradeSkillSetFavorite, Processing = PacketProcessing.Inplace)]
void HandleTradeSkillSetFavorite(TradeSkillSetFavorite tradeSkillSetFavorite)
{
if (!_player.HasSpell(tradeSkillSetFavorite.RecipeID))
return;
_player.SetSpellFavorite(tradeSkillSetFavorite.RecipeID, tradeSkillSetFavorite.IsFavorite);
}
} }
} }
@@ -1160,6 +1160,20 @@ namespace Game.Networking.Packets
public bool Reverse; public bool Reverse;
public uint SpellID; public uint SpellID;
} }
class TradeSkillSetFavorite : ClientPacket
{
public uint RecipeID;
public bool IsFavorite;
public TradeSkillSetFavorite(WorldPacket packet) : base(packet) { }
public override void Read()
{
RecipeID = _worldPacket.ReadUInt32();
IsFavorite = _worldPacket.HasBit();
}
}
//Structs //Structs
public struct SpellLogPowerData public struct SpellLogPowerData