From 9f72f655ab0e3961341f1aec2f27ea3e500865ba Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 27 Feb 2022 15:07:03 -0500 Subject: [PATCH] Core/SAI: Support SMART_TARGET_POSITION in SMART_ACTION_BECOME_PERSONAL_CLONE_FOR_PLAYER Port From (https://github.com/TrinityCore/TrinityCore/commit/a270005de1122d18ea4b4e01b114a87bc0e7c0eb) --- Source/Game/AI/SmartScripts/SmartScript.cs | 31 +++++++++++++++------- Source/Game/Entities/Object/WorldObject.cs | 4 +-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index f76df2071..a6b6f29d7 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -2468,20 +2468,33 @@ namespace Game.AI } case SmartActions.BecomePersonalCloneForPlayer: { - foreach (WorldObject target in targets) + WorldObject baseObject = GetBaseObject(); + + void doCreatePersonalClone(Position position, Unit owner) { - if (!IsPlayer(target)) - continue; - - ObjectGuid privateObjectOwner = target.GetGUID(); - Creature summon = GetBaseObject().SummonPersonalClone((TempSummonType)e.Action.becomePersonalClone.type, e.Action.becomePersonalClone.duration, 0, 0, privateObjectOwner); + ObjectGuid privateObjectOwner = owner.GetGUID(); + Creature summon = GetBaseObject().SummonPersonalClone(position, (TempSummonType)e.Action.becomePersonalClone.type, e.Action.becomePersonalClone.duration, 0, 0, privateObjectOwner); if (summon != null) - { if (IsSmart(summon)) - ((SmartAI)summon.GetAI()).SetTimedActionList(e, (uint)e.EntryOrGuid, target.ToUnit(), e.EventId + 1); + ((SmartAI)summon.GetAI()).SetTimedActionList(e, (uint)e.EntryOrGuid, owner, e.EventId + 1); + } + // if target is position then targets container was empty + if (e.GetTargetType() != SmartTargets.Position) + { + foreach (WorldObject target in targets) + { + Player playerTarget = target?.ToPlayer(); + if (playerTarget != null) + doCreatePersonalClone(baseObject.GetPosition(), playerTarget); } } + else + { + Player invoker = GetLastInvoker()?.ToPlayer(); + if (invoker != null) + doCreatePersonalClone(new Position(e.Target.x, e.Target.y, e.Target.z, e.Target.o), invoker); + } // action list will continue on personal clones _timedActionList.RemoveAll(script => { return script.EventId > e.EventId; }); @@ -4155,7 +4168,7 @@ namespace Game.AI public void SetTimedActionList(SmartScriptHolder e, uint entry, Unit invoker, uint startFromEventId = 0) { // Do NOT allow to start a new actionlist if a previous one is already running, unless explicitly allowed. We need to always finish the current actionlist - if (e.Action.timedActionList.allowOverride == 0 && !_timedActionList.Empty()) + if (e.GetActionType() == SmartActions.CallTimedActionlist && e.Action.timedActionList.allowOverride == 0 && !_timedActionList.Empty()) return; _timedActionList.Clear(); diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 050906b94..87f559667 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -1442,12 +1442,12 @@ namespace Game.Entities return null; } - public TempSummon SummonPersonalClone(TempSummonType despawnType = TempSummonType.ManualDespawn, uint despawnTime = 0, uint vehId = 0, uint spellId = 0, ObjectGuid privateObjectOwner = default) + public TempSummon SummonPersonalClone(Position pos, TempSummonType despawnType = TempSummonType.ManualDespawn, uint despawnTime = 0, uint vehId = 0, uint spellId = 0, ObjectGuid privateObjectOwner = default) { Map map = GetMap(); if (map != null) { - TempSummon summon = map.SummonCreature(GetEntry(), GetPosition(), null, despawnTime, this, spellId, vehId, privateObjectOwner); + TempSummon summon = map.SummonCreature(GetEntry(), pos, null, despawnTime, this, spellId, vehId, privateObjectOwner); if (summon != null) { summon.SetTempSummonType(despawnType);