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:
@@ -2592,11 +2592,6 @@ namespace Game.Entities
|
|||||||
public void SetChildItem(ObjectGuid childItem) { m_childItem = childItem; }
|
public void SetChildItem(ObjectGuid childItem) { m_childItem = childItem; }
|
||||||
|
|
||||||
public ItemEffectRecord[] GetEffects() { return _bonusData.Effects[0.._bonusData.EffectCount]; }
|
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
|
//Static
|
||||||
public static bool ItemCanGoIntoBag(ItemTemplate pProto, ItemTemplate pBagProto)
|
public static bool ItemCanGoIntoBag(ItemTemplate pProto, ItemTemplate pBagProto)
|
||||||
|
|||||||
@@ -1472,37 +1472,6 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
if (!item.GetTemplate().GetFlags().HasFlag(ItemFlags.Legacy))
|
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
|
// item spells casted at use
|
||||||
foreach (ItemEffectRecord effectData in item.GetEffects())
|
foreach (ItemEffectRecord effectData in item.GetEffects())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1059,16 +1059,17 @@ namespace Game
|
|||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (item.GetBonus().EffectCount < 2)
|
foreach (var itemEffect in item.GetEffects())
|
||||||
return;
|
|
||||||
|
|
||||||
uint spellToLearn = (uint)item.GetEffect(1).SpellID;
|
|
||||||
|
|
||||||
var entry = Global.SpellMgr.GetBattlePetSpecies(spellToLearn);
|
|
||||||
if (entry != null)
|
|
||||||
{
|
{
|
||||||
GetBattlePetMgr().AddPet(entry.Id, BattlePetMgr.SelectPetDisplay(entry), BattlePetMgr.RollPetBreed(entry.Id), BattlePetMgr.GetDefaultPetQuality(entry.Id));
|
if (itemEffect.TriggerType != ItemSpelltriggerType.LearnSpellId)
|
||||||
_player.UpdateCriteria(CriteriaType.UniquePetsOwned);
|
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);
|
GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
|
||||||
|
|||||||
@@ -1816,10 +1816,22 @@ namespace Game.Spells
|
|||||||
|
|
||||||
Player player = unitTarget.ToPlayer();
|
Player player = unitTarget.ToPlayer();
|
||||||
|
|
||||||
uint spellToLearn = (m_spellInfo.Id == 483 || m_spellInfo.Id == 55884) ? (uint)damage : effectInfo.TriggerSpell;
|
if (m_CastItem != null && effectInfo.TriggerSpell == 0)
|
||||||
player.LearnSpell(spellToLearn, false);
|
{
|
||||||
|
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)]
|
[SpellEffectHandler(SpellEffectName.Dispel)]
|
||||||
|
|||||||
Reference in New Issue
Block a user