From e0340e7c07e7914de52215e483d26130ff593bc9 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 7 Jan 2022 13:20:16 -0500 Subject: [PATCH] Core/BattlePets: Misc fixes Port From (https://github.com/TrinityCore/TrinityCore/commit/924182f692bde38d8fed85d5dbe7531a09790501) --- Source/Framework/Constants/CliDBConst.cs | 4 +-- Source/Game/BattlePets/BattlePetManager.cs | 12 +++++-- Source/Game/Entities/TemporarySummon.cs | 15 ++++---- Source/Game/Entities/Totem.cs | 2 -- Source/Game/Entities/Unit/Unit.Pets.cs | 23 +++++++++---- Source/Game/Spells/SpellEffects.cs | 40 ++++++++++++---------- Source/Scripts/Spells/Generic.cs | 27 +++++++++++++++ 7 files changed, 86 insertions(+), 37 deletions(-) diff --git a/Source/Framework/Constants/CliDBConst.cs b/Source/Framework/Constants/CliDBConst.cs index 010b635ec..6583cd6b1 100644 --- a/Source/Framework/Constants/CliDBConst.cs +++ b/Source/Framework/Constants/CliDBConst.cs @@ -1743,7 +1743,7 @@ namespace Framework.Constants CannotDismissPet = 0x20, // NYI UseDemonTimeout = 0x40, // NYI UnlimitedSummons = 0x80, // NYI - UseCreatureLevel = 0x100, // NYI + UseCreatureLevel = 0x100, JoinSummonerSpawnGroup = 0x200, // NYI DoNotToggle = 0x400, // NYI DespawnWhenExpired = 0x800, // NYI @@ -1756,7 +1756,7 @@ namespace Framework.Constants CastRideVehicleSpellOnSummoner = 0x40000, // NYI GuardianActsLikePet = 0x80000, // NYI DontSnapSessileToGround = 0x100000, // NYI - SummonFromBattlePetJournal = 0x200000, // NYI + SummonFromBattlePetJournal = 0x200000, UnitClutter = 0x400000, // NYI DefaultNameColor = 0x800000, // NYI UseOwnInvisibilityDetection = 0x1000000, // NYI. Ignore Owner's Invisibility Detection diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index d6b9200f8..350b6b5a6 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -20,6 +20,7 @@ using Framework.Database; using Game.DataStorage; using Game.Entities; using Game.Networking.Packets; +using Game.Spells; using System; using System.Collections.Generic; using System.Linq; @@ -659,10 +660,17 @@ namespace Game.BattlePets if (speciesEntry == null) return; - // TODO: set proper CreatureID for spell SPELL_SUMMON_BATTLE_PET (default EffectMiscValueA is 40721 - Murkimus the Gladiator) Player player = _owner.GetPlayer(); player.SetBattlePetData(pet); - player.CastSpell(_owner.GetPlayer(), speciesEntry.SummonSpellID != 0 ? speciesEntry.SummonSpellID : SharedConst.SpellSummonBattlePet); + + CastSpellExtraArgs args = new(); + uint summonSpellId = speciesEntry.SummonSpellID; + if (summonSpellId == 0) + { + summonSpellId = SharedConst.SpellSummonBattlePet; + args.AddSpellMod(SpellValueMod.BasePoint0, (int)speciesEntry.CreatureID); + } + player.CastSpell(_owner.GetPlayer(), summonSpellId, args); } public void DismissPet() diff --git a/Source/Game/Entities/TemporarySummon.cs b/Source/Game/Entities/TemporarySummon.cs index 3d7c621a4..6cb75e243 100644 --- a/Source/Game/Entities/TemporarySummon.cs +++ b/Source/Game/Entities/TemporarySummon.cs @@ -188,12 +188,8 @@ namespace Game.Entities Unit owner = GetSummonerUnit(); if (owner != null && IsTrigger() && m_spells[0] != 0) - { - SetLevel(owner.GetLevel()); if (owner.IsTypeId(TypeId.Player)) m_ControlledByPlayer = true; - } - if (m_Properties == null) return; @@ -211,15 +207,20 @@ namespace Game.Entities } owner.m_SummonSlot[slot] = GetGUID(); } + + if (!m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseCreatureLevel)) + SetLevel(owner.GetLevel()); } uint faction = m_Properties.Faction; - if (m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag - if (owner) - faction = owner.GetFaction(); + if (owner && m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.UseSummonerFaction)) // TODO: Determine priority between faction and flag + faction = owner.GetFaction(); if (faction != 0) SetFaction(faction); + + if (m_Properties.GetFlags().HasFlag(SummonPropertiesFlags.SummonFromBattlePetJournal)) + RemoveNpcFlag(NPCFlags.WildBattlePet); } public virtual void InitSummon() diff --git a/Source/Game/Entities/Totem.cs b/Source/Game/Entities/Totem.cs index a667c10c9..c9cff3b54 100644 --- a/Source/Game/Entities/Totem.cs +++ b/Source/Game/Entities/Totem.cs @@ -83,8 +83,6 @@ namespace Game.Entities m_type = TotemType.Active; m_duration = duration; - - SetLevel(GetOwner().GetLevel()); } public override void InitSummon() diff --git a/Source/Game/Entities/Unit/Unit.Pets.cs b/Source/Game/Entities/Unit/Unit.Pets.cs index 8e0e30f97..9df031733 100644 --- a/Source/Game/Entities/Unit/Unit.Pets.cs +++ b/Source/Game/Entities/Unit/Unit.Pets.cs @@ -146,18 +146,29 @@ namespace Game.Entities if (GetMinionGUID().IsEmpty()) SetMinionGUID(minion.GetGUID()); - if (minion.m_Properties != null && minion.m_Properties.Title == SummonTitle.Companion) + var properties = minion.m_Properties; + if (properties != null && properties.Title == SummonTitle.Companion) { SetCritterGUID(minion.GetGUID()); Player thisPlayer = ToPlayer(); if (thisPlayer != null) { - var pet = thisPlayer.GetSession().GetBattlePetMgr().GetPet(thisPlayer.GetSummonedBattlePetGUID()); - if (pet != null) + if (properties.GetFlags().HasFlag(SummonPropertiesFlags.SummonFromBattlePetJournal)) { - minion.SetBattlePetCompanionGUID(thisPlayer.GetSummonedBattlePetGUID()); - minion.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp); - minion.SetWildBattlePetLevel(pet.PacketInfo.Level); + var pet = thisPlayer.GetSession().GetBattlePetMgr().GetPet(thisPlayer.GetSummonedBattlePetGUID()); + if (pet != null) + { + minion.SetBattlePetCompanionGUID(thisPlayer.GetSummonedBattlePetGUID()); + minion.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp); + minion.SetWildBattlePetLevel(pet.PacketInfo.Level); + + uint display = pet.PacketInfo.DisplayID; + if (display != 0) + { + minion.SetDisplayId(display); + minion.SetNativeDisplayId(display); + } + } } } } diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 980b62746..62175a4d1 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -1598,9 +1598,6 @@ namespace Game.Spells if (summon == null || !summon.HasUnitTypeMask(UnitTypeMask.Minion)) return; - summon.SelectLevel(); // some summoned creaters have different from 1 DB data for level/hp - summon.SetNpcFlags((NPCFlags)((int)summon.GetCreatureTemplate().Npcflag & 0xFFFFFFFF)); - summon.SetNpcFlags2((NPCFlags2)((int)summon.GetCreatureTemplate().Npcflag >> 32)); summon.SetImmuneToAll(true); break; @@ -4504,21 +4501,6 @@ namespace Game.Spells unitCaster = unitCaster.ToTotem().GetOwner(); // in another case summon new - uint level = unitCaster.GetLevel(); - - // level of pet summoned using engineering item based at engineering skill level - if (m_CastItem != null && unitCaster.IsPlayer()) - { - ItemTemplate proto = m_CastItem.GetTemplate(); - if (proto != null) - if (proto.GetRequiredSkill() == (uint)SkillType.Engineering) - { - ushort skill202 = unitCaster.ToPlayer().GetSkillValue(SkillType.Engineering); - if (skill202 != 0) - level = (uint)(skill202 / 5); - } - } - float radius = 5.0f; int duration = m_spellInfo.CalcDuration(m_originalCaster); @@ -4537,8 +4519,30 @@ namespace Game.Spells TempSummon summon = map.SummonCreature(entry, pos, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner); if (summon == null) return; + if (summon.HasUnitTypeMask(UnitTypeMask.Guardian)) + { + uint level = summon.GetLevel(); + if (properties != null && !properties.GetFlags().HasFlag(SummonPropertiesFlags.UseCreatureLevel)) + level = unitCaster.GetLevel(); + + // level of pet summoned using engineering item based at engineering skill level + if (m_CastItem && unitCaster.IsPlayer()) + { + ItemTemplate proto = m_CastItem.GetTemplate(); + if (proto != null) + { + if (proto.GetRequiredSkill() == (uint)SkillType.Engineering) + { + ushort skill202 = unitCaster.ToPlayer().GetSkillValue(SkillType.Engineering); + if (skill202 != 0) + level = skill202 / 5u; + } + } + } + ((Guardian)summon).InitStatsForLevel(level); + } if (summon.HasUnitTypeMask(UnitTypeMask.Minion) && m_targets.HasDst()) ((Minion)summon).SetFollowAngle(unitCaster.GetAbsoluteAngle(summon.GetPosition())); diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index f6c195a33..3560689e1 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -4149,6 +4149,33 @@ namespace Scripts.Spells.Generic } } + [Script]// 118301 - Summon Battle Pet + class spell_summon_battle_pet : SpellScript + { + void HandleSummon(uint effIndex) + { + uint creatureId = (uint)GetSpellValue().EffectBasePoints[effIndex]; + if (Global.ObjectMgr.GetCreatureTemplate(creatureId) != null) + { + PreventHitDefaultEffect(effIndex); + + Unit caster = GetCaster(); + var properties = CliDB.SummonPropertiesStorage.LookupByKey((uint)GetEffectInfo().MiscValueB); + uint duration = (uint)GetSpellInfo().CalcDuration(caster); + Position pos = GetHitDest().GetPosition(); + + Creature summon = caster.GetMap().SummonCreature(creatureId, pos, properties, duration, caster, GetSpellInfo().Id); + if (summon != null) + summon.SetImmuneToAll(true); + } + } + + public override void Register() + { + OnEffectHit.Add(new EffectHandler(HandleSummon, 0, SpellEffectName.Summon)); + } + } + // 40307 - Stasis Field class StasisFieldSearcher : ICheck {