From 515ae6ed12684ba3679c753bb208a7621fe23d57 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 23 Jun 2021 23:50:55 -0400 Subject: [PATCH] Core/SAI: Add an action_param3 to "summon gob" to control when the object will despawn Port From (https://github.com/TrinityCore/TrinityCore/commit/4b6e76a5efe5e48ff20b4ef84e0f3dc0f9bc84a0) --- Source/Framework/Constants/GameObjectConst.cs | 6 ++++++ Source/Game/AI/SmartScripts/SmartAIManager.cs | 1 + Source/Game/AI/SmartScripts/SmartScript.cs | 6 ++++-- Source/Game/Entities/Object/WorldObject.cs | 8 ++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/Framework/Constants/GameObjectConst.cs b/Source/Framework/Constants/GameObjectConst.cs index 9e23e758c..db39d4a9e 100644 --- a/Source/Framework/Constants/GameObjectConst.cs +++ b/Source/Framework/Constants/GameObjectConst.cs @@ -134,4 +134,10 @@ namespace Framework.Constants Destroyed = 2, Rebuilding = 3 } + + public enum GameObjectSummonType + { + TimedOrCorpseDespawn = 0, // despawns after a specified time OR when the summoner dies + TimedDespawn = 1 // despawns after a specified time + } } diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 6e60af49a..0c1efc235 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -2731,6 +2731,7 @@ namespace Game.AI { public uint entry; public uint despawnTime; + public uint summonType; } public struct Active { diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index e46cd45e8..a112d8c9e 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -1173,13 +1173,15 @@ namespace Game.AI foreach (var target in targets) { Position pos = target.GetPositionWithOffset(new Position(e.Target.x, e.Target.y, e.Target.z, e.Target.o)); - summoner.SummonGameObject(e.Action.summonGO.entry, pos, Quaternion.fromEulerAnglesZYX(pos.GetOrientation(), 0.0f, 0.0f), e.Action.summonGO.despawnTime); + Quaternion rot = Quaternion.fromEulerAnglesZYX(pos.GetOrientation(), 0f, 0f); + summoner.SummonGameObject(e.Action.summonGO.entry, pos, rot, e.Action.summonGO.despawnTime, (GameObjectSummonType)e.Action.summonGO.summonType); } if (e.GetTargetType() != SmartTargets.Position) break; - summoner.SummonGameObject(e.Action.summonGO.entry, new Position(e.Target.x, e.Target.y, e.Target.z, e.Target.o), Quaternion.fromEulerAnglesZYX(e.Target.o, 0.0f, 0.0f), e.Action.summonGO.despawnTime); + Quaternion _rot = Quaternion.fromEulerAnglesZYX(e.Target.o, 0f, 0f); + summoner.SummonGameObject(e.Action.summonGO.entry, new Position(e.Target.x, e.Target.y, e.Target.z, e.Target.o), _rot, e.Action.summonGO.despawnTime, (GameObjectSummonType)e.Action.summonGO.summonType); break; } case SmartActions.KillUnit: diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 6e0aac109..8dfa80fc4 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -1456,7 +1456,7 @@ namespace Game.Entities return null; } - public GameObject SummonGameObject(uint entry, float x, float y, float z, float ang, Quaternion rotation, uint respawnTime) + public GameObject SummonGameObject(uint entry, float x, float y, float z, float ang, Quaternion rotation, uint respawnTime, GameObjectSummonType summonType = GameObjectSummonType.TimedOrCorpseDespawn) { if (x == 0 && y == 0 && z == 0) { @@ -1465,10 +1465,10 @@ namespace Game.Entities } Position pos = new(x, y, z, ang); - return SummonGameObject(entry, pos, rotation, respawnTime); + return SummonGameObject(entry, pos, rotation, respawnTime, summonType); } - public GameObject SummonGameObject(uint entry, Position pos, Quaternion rotation, uint respawnTime) + public GameObject SummonGameObject(uint entry, Position pos, Quaternion rotation, uint respawnTime, GameObjectSummonType summonType = GameObjectSummonType.TimedOrCorpseDespawn) { if (!IsInWorld) return null; @@ -1488,7 +1488,7 @@ namespace Game.Entities PhasingHandler.InheritPhaseShift(go, this); go.SetRespawnTime((int)respawnTime); - if (IsTypeId(TypeId.Player) || IsTypeId(TypeId.Unit)) //not sure how to handle this + if (IsPlayer() || (IsCreature() && summonType == GameObjectSummonType.TimedOrCorpseDespawn)) //not sure how to handle this ToUnit().AddGameObject(go); else go.SetSpawnedByDefault(false);