Core/Items: Refactored learning spells from items to check for ITEM_SPELLTRIGGER_LEARN_SPELL_ID instead of hardcoded spell ids

Port From (https://github.com/TrinityCore/TrinityCore/commit/6b69338990a651c54dd9d2b5ad3281a4d702efb7)
This commit is contained in:
hondacrx
2021-10-16 18:18:28 -04:00
parent e9c6424cd8
commit d2c62555c1
4 changed files with 25 additions and 48 deletions
-5
View File
@@ -2592,11 +2592,6 @@ namespace Game.Entities
public void SetChildItem(ObjectGuid childItem) { m_childItem = childItem; }
public ItemEffectRecord[] GetEffects() { return _bonusData.Effects[0.._bonusData.EffectCount]; }
public ItemEffectRecord GetEffect(int i)
{
Cypher.Assert(i < _bonusData.EffectCount, $"Attempted to get effect at index {i} but item has only {_bonusData.EffectCount} effects!");
return _bonusData.Effects[i];
}
//Static
public static bool ItemCanGoIntoBag(ItemTemplate pProto, ItemTemplate pBagProto)
@@ -1472,37 +1472,6 @@ namespace Game.Entities
{
if (!item.GetTemplate().GetFlags().HasFlag(ItemFlags.Legacy))
{
// special learning case
if (item.GetBonus().EffectCount >= 2)
{
if (item.GetEffect(0).SpellID == 483 || item.GetEffect(0).SpellID == 55884)
{
uint learn_spell_id = (uint)item.GetEffect(0).SpellID;
uint learning_spell_id = (uint)item.GetEffect(1).SpellID;
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(learn_spell_id, Difficulty.None);
if (spellInfo == null)
{
Log.outError(LogFilter.Player, "Player.CastItemUseSpell: Item (Entry: {0}) in have wrong spell id {1}, ignoring ", item.GetEntry(), learn_spell_id);
SendEquipError(InventoryResult.InternalBagError, item);
return;
}
Spell spell = new(this, spellInfo, TriggerCastFlags.None);
SpellPrepare spellPrepare = new();
spellPrepare.ClientCastID = castCount;
spellPrepare.ServerCastID = spell.m_castId;
SendPacket(spellPrepare);
spell.m_fromClient = true;
spell.m_CastItem = item;
spell.SetSpellValue(SpellValueMod.BasePoint0, (int)learning_spell_id);
spell.Prepare(targets);
return;
}
}
// item spells casted at use
foreach (ItemEffectRecord effectData in item.GetEffects())
{
+10 -9
View File
@@ -1059,16 +1059,17 @@ namespace Game
if (!item)
return;
if (item.GetBonus().EffectCount < 2)
return;
uint spellToLearn = (uint)item.GetEffect(1).SpellID;
var entry = Global.SpellMgr.GetBattlePetSpecies(spellToLearn);
if (entry != null)
foreach (var itemEffect in item.GetEffects())
{
GetBattlePetMgr().AddPet(entry.Id, BattlePetMgr.SelectPetDisplay(entry), BattlePetMgr.RollPetBreed(entry.Id), BattlePetMgr.GetDefaultPetQuality(entry.Id));
_player.UpdateCriteria(CriteriaType.UniquePetsOwned);
if (itemEffect.TriggerType != ItemSpelltriggerType.LearnSpellId)
continue;
var entry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID);
if (entry != null)
{
GetBattlePetMgr().AddPet(entry.Id, BattlePetMgr.SelectPetDisplay(entry), BattlePetMgr.RollPetBreed(entry.Id), BattlePetMgr.GetDefaultPetQuality(entry.Id));
_player.UpdateCriteria(CriteriaType.UniquePetsOwned);
}
}
GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
+15 -3
View File
@@ -1816,10 +1816,22 @@ namespace Game.Spells
Player player = unitTarget.ToPlayer();
uint spellToLearn = (m_spellInfo.Id == 483 || m_spellInfo.Id == 55884) ? (uint)damage : effectInfo.TriggerSpell;
player.LearnSpell(spellToLearn, false);
if (m_CastItem != null && effectInfo.TriggerSpell == 0)
{
foreach (var itemEffect in m_CastItem.GetEffects())
{
if (itemEffect.TriggerType != ItemSpelltriggerType.LearnSpellId)
continue;
Log.outDebug(LogFilter.Spells, "Spell: Player {0} has learned spell {1} from NpcGUID={2}", player.GetGUID().ToString(), spellToLearn, m_caster.GetGUID().ToString());
player.LearnSpell((uint)itemEffect.SpellID, false);
}
}
if (effectInfo.TriggerSpell != 0)
{
player.LearnSpell(effectInfo.TriggerSpell, false);
Log.outDebug(LogFilter.Spells, $"Spell: {player.GetGUID()} has learned spell {effectInfo.TriggerSpell} from {m_caster.GetGUID()}");
}
}
[SpellEffectHandler(SpellEffectName.Dispel)]