From b22dc3bc8a60127287f93e152546cdab138538a2 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 26 Jan 2021 19:27:45 -0500 Subject: [PATCH] Core/Spells: Implemented summoning a personal gameobject effect Port From (https://github.com/TrinityCore/TrinityCore/commit/e601c6d1f9b9743e92e9562abd9f2d24d9aaf175) --- .../Framework/Constants/Spells/SpellConst.cs | 2 +- Source/Game/Entities/GameObject/GameObject.cs | 5 ++ Source/Game/Entities/Object/WorldObject.cs | 5 ++ Source/Game/Spells/SpellEffects.cs | 53 ++++++++++++++++++- Source/Game/Spells/SpellInfo.cs | 2 +- 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Source/Framework/Constants/Spells/SpellConst.cs b/Source/Framework/Constants/Spells/SpellConst.cs index c77b0dee5..da1509c47 100644 --- a/Source/Framework/Constants/Spells/SpellConst.cs +++ b/Source/Framework/Constants/Spells/SpellConst.cs @@ -2177,7 +2177,7 @@ namespace Framework.Constants AllowControlPet = 168, DestroyItem = 169, UpdateZoneAurasPhases = 170, - Effect171 = 171, // Summons Gamebject + SummonPersonalGameobject = 171, // Summons Gameobject ResurrectWithAura = 172, // Aoe Ressurection UnlockGuildVaultTab = 173, // Guild Tab Unlocked (Guild Perk) ApplyAuraOnPet = 174, diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 9f94f4a4a..cd0ed06a7 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -2800,6 +2800,10 @@ namespace Game.Entities void SetRespawnCompatibilityMode(bool mode = true) { m_respawnCompatibilityMode = mode; } public bool GetRespawnCompatibilityMode() { return m_respawnCompatibilityMode; } + public void SetVisibleByUnitOnly(ObjectGuid unit) { m_visibleByUnitOnly = unit; } + public bool IsVisibleByUnitOnly() { return !m_visibleByUnitOnly.IsEmpty(); } + public ObjectGuid GetVisibleByUnitOnly() { return m_visibleByUnitOnly; } + #region Fields protected GameObjectFieldData m_gameObjectData; protected GameObjectValue m_goValue; @@ -2834,6 +2838,7 @@ namespace Game.Entities bool m_respawnCompatibilityMode; ushort _animKitId; uint _worldEffectID; + ObjectGuid m_visibleByUnitOnly; GameObjectState m_prevGoState; // What state to set whenever resetting diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index cc486f98b..f573e796b 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -1147,6 +1147,11 @@ namespace Game.Entities } } + GameObject go = obj.ToGameObject(); + if ( go != null) + if (go.IsVisibleByUnitOnly() && GetGUID() != go.GetVisibleByUnitOnly()) + return false; + if (viewpoint == null) viewpoint = this; diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 05112c16a..0ceaa4576 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -42,7 +42,6 @@ namespace Game.Spells [SpellEffectHandler(SpellEffectName.Portal)] [SpellEffectHandler(SpellEffectName.BindSight)] [SpellEffectHandler(SpellEffectName.CallPet)] - [SpellEffectHandler(SpellEffectName.Effect171)] [SpellEffectHandler(SpellEffectName.Effect177)] [SpellEffectHandler(SpellEffectName.PortalTeleport)] [SpellEffectHandler(SpellEffectName.RitualBase)] @@ -117,6 +116,7 @@ namespace Game.Spells m_caster.DealDamage(unitTarget, (uint)unitTarget.GetHealth(), null, DamageEffectType.NoDamage, SpellSchoolMask.Normal, null, false); } + [SpellEffectHandler(SpellEffectName.EnvironmentalDamage)] void EffectEnvironmentalDMG(uint effIndex) { if (effectHandleMode != SpellEffectHandleMode.HitTarget) @@ -5253,6 +5253,57 @@ namespace Game.Spells guild.HandleBuyBankTab(caster.GetSession(), (byte)(damage - 1)); // Bank tabs start at zero internally } + [SpellEffectHandler(SpellEffectName.SummonPersonalGameobject)] + void EffectSummonPersonalGameObject(uint effIndex) + { + if (effectHandleMode != SpellEffectHandleMode.Hit) + return; + + uint goId = (uint)effectInfo.MiscValue; + if (goId == 0) + return; + + float x, y, z; + if (m_targets.HasDst()) + destTarget.GetPosition(out x, out y, out z); + else + m_caster.GetClosePoint(out x, out y, out z, SharedConst.DefaultPlayerBoundingRadius); + + Map map = m_caster.GetMap(); + Position pos = new Position(x, y, z, m_caster.GetOrientation()); + Quaternion rot = Quaternion.fromEulerAnglesZYX(m_caster.GetOrientation(), 0.0f, 0.0f); + GameObject go = GameObject.CreateGameObject(goId, map, pos, rot, 255, GameObjectState.Ready); + + if (!go) + { + Log.outWarn(LogFilter.Spells, $"SpellEffect Failed to summon personal gameobject. SpellId {m_spellInfo.Id}, effect {effIndex}"); + return; + } + + PhasingHandler.InheritPhaseShift(go, m_caster); + + int duration = m_spellInfo.CalcDuration(m_caster); + + go.SetRespawnTime(duration > 0 ? duration / Time.InMilliseconds : 0); + go.SetSpellId(m_spellInfo.Id); + go.SetVisibleByUnitOnly(m_caster.GetGUID()); + + ExecuteLogEffectSummonObject(effIndex, go); + + map.AddToMap(go); + + GameObject linkedTrap = go.GetLinkedTrap(); + if (linkedTrap != null) + { + PhasingHandler.InheritPhaseShift(linkedTrap, m_caster); + + linkedTrap.SetRespawnTime(duration > 0 ? duration / Time.InMilliseconds : 0); + linkedTrap.SetSpellId(m_spellInfo.Id); + + ExecuteLogEffectSummonObject(effIndex, linkedTrap); + } + } + [SpellEffectHandler(SpellEffectName.ResurrectWithAura)] void EffectResurrectWithAura(uint effIndex) { diff --git a/Source/Game/Spells/SpellInfo.cs b/Source/Game/Spells/SpellInfo.cs index fc9c07b24..629d192bd 100644 --- a/Source/Game/Spells/SpellInfo.cs +++ b/Source/Game/Spells/SpellInfo.cs @@ -4266,7 +4266,7 @@ namespace Game.Spells new StaticData(SpellEffectImplicitTargetTypes.Explicit, SpellTargetObjectTypes.Unit), // 168 SPELL_EFFECT_168 new StaticData(SpellEffectImplicitTargetTypes.Caster, SpellTargetObjectTypes.Unit), // 169 SPELL_EFFECT_DESTROY_ITEM new StaticData(SpellEffectImplicitTargetTypes.Explicit, SpellTargetObjectTypes.Unit), // 170 SPELL_EFFECT_170 - new StaticData(SpellEffectImplicitTargetTypes.None, SpellTargetObjectTypes.Dest), // 171 SPELL_EFFECT_171 + new StaticData(SpellEffectImplicitTargetTypes.None, SpellTargetObjectTypes.Dest), // 171 SPELL_EFFECT_SUMMON_PERSONAL_GAMEOBJECT new StaticData(SpellEffectImplicitTargetTypes.Explicit, SpellTargetObjectTypes.Unit), // 172 SPELL_EFFECT_172 new StaticData(SpellEffectImplicitTargetTypes.None, SpellTargetObjectTypes.None), // 173 SPELL_EFFECT_UNLOCK_GUILD_VAULT_TAB new StaticData(SpellEffectImplicitTargetTypes.Explicit, SpellTargetObjectTypes.Unit), // 174 SPELL_EFFECT_174