From 58550514e6d57f7b4e5b4fca21028f412bf39325 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 11 Oct 2021 19:49:26 -0400 Subject: [PATCH] Core/Spells: Implemented SPELL_EFFECT_CANCEL_CONVERSATION Port From (https://github.com/TrinityCore/TrinityCore/commit/1673b6e2ff69b9a59522892280e91cc5085a5ec0) --- Source/Game/Entities/Conversation.cs | 2 +- Source/Game/Maps/GridNotifiers.cs | 18 ++++++++++++++++++ Source/Game/Spells/SpellEffects.cs | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Source/Game/Entities/Conversation.cs b/Source/Game/Entities/Conversation.cs index 426a2b6e8..092a2efc2 100644 --- a/Source/Game/Entities/Conversation.cs +++ b/Source/Game/Entities/Conversation.cs @@ -80,7 +80,7 @@ namespace Game.Entities base.Update(diff); } - void Remove() + public void Remove() { if (IsInWorld) { diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 3c04a1599..770abecd3 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -1341,6 +1341,7 @@ namespace Game.Maps WorldObject _searcher; ICheck i_check; } + public class WorldObjectListSearcher : Notifier { public WorldObjectListSearcher(WorldObject searcher, List objects, ICheck check, GridMapTypeMask mapTypeMask = GridMapTypeMask.All) @@ -2642,6 +2643,23 @@ namespace Game.Maps ObjectGuid _casterGUID; } + class ObjectEntryAndPrivateOwnerIfExistsCheck : ICheck + { + ObjectGuid _ownerGUID; + uint _entry; + + public ObjectEntryAndPrivateOwnerIfExistsCheck(ObjectGuid ownerGUID, uint entry) + { + _ownerGUID = ownerGUID; + _entry = entry; + } + + public bool Invoke(WorldObject obj) + { + return obj.GetEntry() == _entry && (!obj.IsPrivateObject() || obj.GetPrivateObjectOwner() == _ownerGUID); + } + } + class GameObjectFocusCheck : ICheck { public GameObjectFocusCheck(WorldObject caster, uint focusId) diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 7d4ac74b6..b92aab8ae 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -5336,6 +5336,28 @@ namespace Game.Spells Conversation.CreateConversation((uint)effectInfo.MiscValue, unitCaster, destTarget.GetPosition(), ObjectGuid.Empty, GetSpellInfo()); } + [SpellEffectHandler(SpellEffectName.CancelConversation)] + void EffectCancelConversation() + { + if (effectHandleMode != SpellEffectHandleMode.HitTarget) + return; + + if (!unitTarget) + return; + + List objs = new(); + ObjectEntryAndPrivateOwnerIfExistsCheck check = new(unitTarget.GetGUID(), (uint)effectInfo.MiscValue); + WorldObjectListSearcher checker = new(unitTarget, objs, check, GridMapTypeMask.Conversation); + Cell.VisitGridObjects(unitTarget, checker, 100.0f); + + foreach (WorldObject obj in objs) + { + Conversation convo = obj.ToConversation(); + if (convo != null) + convo.Remove(); + } + } + [SpellEffectHandler(SpellEffectName.AddGarrisonFollower)] void EffectAddGarrisonFollower() {