From e982220cdc83b97f9764ea945213e5108bace19e Mon Sep 17 00:00:00 2001 From: Michal78900 Date: Sun, 8 Aug 2021 21:00:00 +0200 Subject: [PATCH] Added RagdollSpawnPointObject and fixed some stuff --- .../API/Components/RagdollObjectComponent.cs | 26 +++++ MapEditorReborn/API/Enums.cs | 5 + MapEditorReborn/API/Extenstions.cs | 5 +- MapEditorReborn/API/MapSchematic.cs | 7 ++ MapEditorReborn/API/Objects/DoorObject.cs | 44 +++---- .../API/Objects/ItemSpawnPointObject.cs | 20 ++-- .../API/Objects/PlayerSpawnPointObject.cs | 12 +- .../API/Objects/RagdollSpawnPointObject.cs | 36 ++++++ .../API/Objects/WorkStationObject.cs | 16 +-- .../Commands/ModifyingCommands/Position.cs | 5 +- .../UtilityCommands/ShowIndicators.cs | 7 ++ MapEditorReborn/Handler.cs | 56 +++++---- MapEditorReborn/MapEditorReborn.csproj | 2 + MapEditorReborn/Methods.cs | 109 +++++++++++++++--- 14 files changed, 264 insertions(+), 86 deletions(-) create mode 100644 MapEditorReborn/API/Components/RagdollObjectComponent.cs create mode 100644 MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs diff --git a/MapEditorReborn/API/Components/RagdollObjectComponent.cs b/MapEditorReborn/API/Components/RagdollObjectComponent.cs new file mode 100644 index 00000000..d93f16df --- /dev/null +++ b/MapEditorReborn/API/Components/RagdollObjectComponent.cs @@ -0,0 +1,26 @@ +namespace MapEditorReborn.API +{ + using Exiled.API.Features; + using Mirror; + using UnityEngine; + + public class RagdollObjectComponent : MonoBehaviour + { + public string RagdollName = string.Empty; + + public RoleType RagdollRoleType = RoleType.ClassD; + + public Ragdoll AttachedRagdoll = null; + + private void Start() + { + AttachedRagdoll = Map.SpawnRagdoll(RagdollRoleType, DamageTypes.None, RagdollName, gameObject.transform.position, gameObject.transform.rotation); + } + + private void OnDestroy() + { + if (AttachedRagdoll != null) + NetworkServer.Destroy(AttachedRagdoll.gameObject); + } + } +} diff --git a/MapEditorReborn/API/Enums.cs b/MapEditorReborn/API/Enums.cs index 4a4fece0..f1d8a243 100644 --- a/MapEditorReborn/API/Enums.cs +++ b/MapEditorReborn/API/Enums.cs @@ -34,5 +34,10 @@ public enum ToolGunMode /// The mode that will spawn a PlayerSpawnPoint. /// PlayerSpawnPoint = 5, + + /// + /// The mode that will spawn a RagdollSpawnPoint. + /// + RagdollSpawnPoint = 6, } } diff --git a/MapEditorReborn/API/Extenstions.cs b/MapEditorReborn/API/Extenstions.cs index 8c081362..e3e3008c 100644 --- a/MapEditorReborn/API/Extenstions.cs +++ b/MapEditorReborn/API/Extenstions.cs @@ -154,6 +154,9 @@ public static GameObject GetObjectByMode(this ToolGunMode toolGunMode) case ToolGunMode.PlayerSpawnPoint: return Handler.PlayerSpawnPointObj; + case ToolGunMode.RagdollSpawnPoint: + return Handler.RagdollSpawnPointObj; + default: return null; } @@ -311,7 +314,7 @@ public static void UpdateObject(this GameObject gameObject, Player player = null { Handler.SpawnPickupIndicator(gameObject); } - else if (gameObject.name == "PlayerSpawnPointObject(Clone)") + else if (gameObject.name == "PlayerSpawnPointObject(Clone)" || gameObject.name == "RagdollSpawnPointObject(Clone)") { Handler.SpawnDummyIndicator(gameObject); } diff --git a/MapEditorReborn/API/MapSchematic.cs b/MapEditorReborn/API/MapSchematic.cs index 37fbe91b..f8df9727 100644 --- a/MapEditorReborn/API/MapSchematic.cs +++ b/MapEditorReborn/API/MapSchematic.cs @@ -26,6 +26,11 @@ public MapSchematic() /// public bool RemoveDefaultSpawnPoints { get; set; } = false; + public Dictionary> RoleNames { get; set; } = new Dictionary>() + { + { RoleType.ClassD, new List() { "D-9341" } }, + }; + /// /// Gets or sets the list of . /// @@ -45,5 +50,7 @@ public MapSchematic() /// Gets or sets the list of . /// public List PlayerSpawnPoints { get; set; } = new List(); + + public List RagdollSpawnPoints { get; set; } = new List(); } } diff --git a/MapEditorReborn/API/Objects/DoorObject.cs b/MapEditorReborn/API/Objects/DoorObject.cs index eb50eb93..a1a7d2e8 100644 --- a/MapEditorReborn/API/Objects/DoorObject.cs +++ b/MapEditorReborn/API/Objects/DoorObject.cs @@ -36,61 +36,61 @@ public DoorObject(DoorType doorType, Vector3 position, Vector3 rotation, Vector3 } /// - /// Gets or sets the door . + /// Gets the door . /// - public DoorType DoorType { get; set; } + public DoorType DoorType { get; private set; } /// - /// Gets or sets the door's position. + /// Gets the door's position. /// // public Vector3 Position { get; set; } = Vector3.zero; - public SerializableVector3 Position { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the door's rotation. + /// Gets the door's rotation. /// // public Vector3 Rotation { get; set; } = Vector3.zero; - public SerializableVector3 Rotation { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Rotation { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the door's scale. + /// Gets the door's scale. /// // public Vector3 Scale { get; set; } = Vector3.one; - public SerializableVector3 Scale { get; set; } = SerializableVector3.One; + public SerializableVector3 Scale { get; private set; } = SerializableVector3.One; /// - /// Gets or sets the which is used to determine the spawn pos and rotation of the object. + /// Gets the which is used to determine the spawn pos and rotation of the object. /// - public RoomType RoomType { get; set; } = RoomType.Unknown; + public RoomType RoomType { get; private set; } = RoomType.Unknown; /// - /// Gets or sets a value indicating whether the door is opened or not. + /// Gets a value indicating whether the door is opened or not. /// - public bool IsOpen { get; set; } = false; + public bool IsOpen { get; private set; } = false; /// - /// Gets or sets a value indicating whether the door is locked or not. + /// Gets a value indicating whether the door is locked or not. /// - public bool IsLocked { get; set; } = false; + public bool IsLocked { get; private set; } = false; /// - /// Gets or sets a value indicating whether the door has keycard permissions or not. + /// Gets a value indicating whether the door has keycard permissions or not. /// - public KeycardPermissions KeycardPermissions { get; set; } = KeycardPermissions.None; + public KeycardPermissions KeycardPermissions { get; private set; } = KeycardPermissions.None; /// - /// Gets or sets ignored by the door. + /// Gets ignored by the door. /// - public DoorDamageType IgnoredDamageSources { get; set; } = DoorDamageType.Weapon; + public DoorDamageType IgnoredDamageSources { get; private set; } = DoorDamageType.Weapon; /// - /// Gets or sets health of the door. + /// Gets health of the door. /// - public float DoorHealth { get; set; } = 150f; + public float DoorHealth { get; private set; } = 150f; /// - /// Gets or sets a value indicating whether the door will open automatically on warhead activation or not. + /// Gets a value indicating whether the door will open automatically on warhead activation or not. /// - public bool OpenOnWarheadActivation { get; set; } = false; + public bool OpenOnWarheadActivation { get; private set; } = false; } } \ No newline at end of file diff --git a/MapEditorReborn/API/Objects/ItemSpawnPointObject.cs b/MapEditorReborn/API/Objects/ItemSpawnPointObject.cs index c61648cb..85971068 100644 --- a/MapEditorReborn/API/Objects/ItemSpawnPointObject.cs +++ b/MapEditorReborn/API/Objects/ItemSpawnPointObject.cs @@ -27,30 +27,30 @@ public ItemSpawnPointObject(string item, Vector3 position, Vector3 rotation, Roo } /// - /// Gets or sets the name of the item that will be spawned (supports CustomItems). + /// Gets the name of the item that will be spawned (supports CustomItems). /// - public string Item { get; set; } = "KeycardJanitor"; + public string Item { get; private set; } = "KeycardJanitor"; /// - /// Gets or sets the ItemSpawnPoint's position. + /// Gets the ItemSpawnPoint's position. /// // public Vector3 Position { get; set; } = Vector3.zero; - public SerializableVector3 Position { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the ItemSpawnPoint's rotation. + /// Gets the ItemSpawnPoint's rotation. /// // public Vector3 Rotation { get; set; } = Vector3.zero; - public SerializableVector3 Rotation { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Rotation { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the which is used to determine the spawn pos and rotation of the object. + /// Gets the which is used to determine the spawn pos and rotation of the object. /// - public RoomType RoomType { get; set; } = RoomType.Unknown; + public RoomType RoomType { get; private set; } = RoomType.Unknown; /// - /// Gets or sets the spawn chance of the item. + /// Gets the spawn chance of the item. /// - public int SpawnChance { get; set; } = 100; + public int SpawnChance { get; private set; } = 100; } } diff --git a/MapEditorReborn/API/Objects/PlayerSpawnPointObject.cs b/MapEditorReborn/API/Objects/PlayerSpawnPointObject.cs index e1856bd1..ee3e9af7 100644 --- a/MapEditorReborn/API/Objects/PlayerSpawnPointObject.cs +++ b/MapEditorReborn/API/Objects/PlayerSpawnPointObject.cs @@ -26,19 +26,19 @@ public PlayerSpawnPointObject(RoleType roleType, Vector3 position, RoomType room } /// - /// Gets or sets the role which will spawn on the spawnpoint. + /// Gets the role which will spawn on the spawnpoint. /// - public RoleType RoleType { get; set; } = RoleType.Tutorial; + public RoleType RoleType { get; private set; } = RoleType.Tutorial; /// - /// Gets or sets the ItemSpawnPoint's position. + /// Gets the ItemSpawnPoint's position. /// // public Vector3 Position { get; set; } = Vector3.zero; - public SerializableVector3 Position { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the which is used to determine the spawn pos and rotation of the object. + /// Gets the which is used to determine the spawn pos and rotation of the object. /// - public RoomType RoomType { get; set; } = RoomType.Unknown; + public RoomType RoomType { get; private set; } = RoomType.Unknown; } } diff --git a/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs b/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs new file mode 100644 index 00000000..23fe0e56 --- /dev/null +++ b/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs @@ -0,0 +1,36 @@ +namespace MapEditorReborn.API +{ + using Exiled.API.Enums; + using System; + using UnityEngine; + + [Serializable] + public class RagdollSpawnPointObject + { + /// + /// Initializes a new instance of the class. + /// + public RagdollSpawnPointObject() + { + } + + public RagdollSpawnPointObject(string name, RoleType roleType, Vector3 position, Vector3 rotation, RoomType roomType) + { + Name = name; + RoleType = roleType; + Position = position; + Rotation = rotation; + RoomType = roomType; + } + + public string Name { get; private set; } = string.Empty; + + public RoleType RoleType { get; private set; } = RoleType.ClassD; + + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; + + public SerializableVector3 Rotation { get; private set; } = SerializableVector3.Zero; + + public RoomType RoomType { get; private set; } = RoomType.Unknown; + } +} diff --git a/MapEditorReborn/API/Objects/WorkStationObject.cs b/MapEditorReborn/API/Objects/WorkStationObject.cs index 870ef328..b3830829 100644 --- a/MapEditorReborn/API/Objects/WorkStationObject.cs +++ b/MapEditorReborn/API/Objects/WorkStationObject.cs @@ -27,26 +27,26 @@ public WorkStationObject(Vector3 position, Vector3 rotation, Vector3 scale, Room } /// - /// Gets or sets the workstation's position. + /// Gets the workstation's position. /// // public Vector3 Position { get; set; } = Vector3.zero; - public SerializableVector3 Position { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the workstation's rotation. + /// Gets the workstation's rotation. /// // public Vector3 Rotation { get; set; } = Vector3.zero; - public SerializableVector3 Rotation { get; set; } = SerializableVector3.Zero; + public SerializableVector3 Rotation { get; private set; } = SerializableVector3.Zero; /// - /// Gets or sets the workstation's scale. + /// Gets the workstation's scale. /// // public Vector3 Scale { get; set; } = Vector3.one; - public SerializableVector3 Scale { get; set; } = SerializableVector3.One; + public SerializableVector3 Scale { get; private set; } = SerializableVector3.One; /// - /// Gets or sets the which is used to determine the spawn pos and rotation of the object. + /// Gets the which is used to determine the spawn pos and rotation of the object. /// - public RoomType RoomType { get; set; } = RoomType.Unknown; + public RoomType RoomType { get; private set; } = RoomType.Unknown; } } diff --git a/MapEditorReborn/Commands/ModifyingCommands/Position.cs b/MapEditorReborn/Commands/ModifyingCommands/Position.cs index 38cafa02..f39fd799 100644 --- a/MapEditorReborn/Commands/ModifyingCommands/Position.cs +++ b/MapEditorReborn/Commands/ModifyingCommands/Position.cs @@ -104,7 +104,10 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s case "BRING": { - newPosition = player.Position + (Vector3.down * 1.33f); + newPosition = player.Position; + + if (gameObject.name.Contains("Door")) + newPosition += Vector3.down * 1.33f; NetworkServer.UnSpawn(gameObject); gameObject.transform.position = newPosition; diff --git a/MapEditorReborn/Commands/UtilityCommands/ShowIndicators.cs b/MapEditorReborn/Commands/UtilityCommands/ShowIndicators.cs index 2fdf3594..0db55a26 100644 --- a/MapEditorReborn/Commands/UtilityCommands/ShowIndicators.cs +++ b/MapEditorReborn/Commands/UtilityCommands/ShowIndicators.cs @@ -60,6 +60,13 @@ public bool Execute(ArraySegment arguments, ICommandSender sender, out s Handler.SpawnPickupIndicator(gameObject.transform.position, gameObject.transform.rotation, itemSpawnPointComponent.ItemName, gameObject); + break; + } + + case "RagdollSpawnPointObject(Clone)": + { + Handler.SpawnDummyIndicator(gameObject.transform.position, gameObject.GetComponent().RagdollRoleType, gameObject); + break; } } diff --git a/MapEditorReborn/Handler.cs b/MapEditorReborn/Handler.cs index c512c536..dcba546d 100644 --- a/MapEditorReborn/Handler.cs +++ b/MapEditorReborn/Handler.cs @@ -70,6 +70,8 @@ public partial class Handler /// public static GameObject PlayerSpawnPointObj; + public static GameObject RagdollSpawnPointObj; + /// /// Gets or sets currently loaded . /// @@ -102,6 +104,10 @@ internal static void OnGenerated() PlayerSpawnPointObj.name = "PlayerSpawnPointObject"; PlayerSpawnPointObj.transform.localScale = Vector3.zero; + RagdollSpawnPointObj = GameObject.CreatePrimitive(PrimitiveType.Plane); + RagdollSpawnPointObj.name = "RagdollSpawnPointObject"; + RagdollSpawnPointObj.transform.localScale = Vector3.zero; + if (Config.LoadMapsOnStart.Count != 0) { CurrentLoadedMap = GetMapByName(Config.LoadMapsOnStart[Random.Range(0, Config.LoadMapsOnStart.Count)]); @@ -185,14 +191,26 @@ internal static void OnShooting(ShootingEventArgs ev) GameObject parent = hit.collider.GetComponentInParent()?.gameObject ?? // Door (DoorObject) hit.collider.GetComponentInParent()?.gameObject ?? // Workstation (WorkstationObject) - hit.collider.GetComponentInParent()?.gameObject ?? // Dummy Indicator (ItemSpawnPointObject) - hit.collider.GetComponentInParent()?.gameObject; // Pickup indicator (PlayerSpawnPointObject) + hit.collider.GetComponentInParent()?.gameObject ?? // Dummy Indicator (PlayerSpawnPointObject and RagdollSpawnPointObject) + hit.collider.GetComponentInParent()?.gameObject; // Pickup indicator (ItemSpawnPointObject) if (parent != null) { - if (Indicators.TryGetValue(parent, out GameObject primitive)) + // Deleting the object by it's indicator + if (Indicators.TryGetValue(parent, out GameObject primitive) && !ev.Shooter.HasFlashlightEnabled() && !ev.Shooter.ReferenceHub.weaponManager.NetworksyncZoomed) + { + SpawnedObjects.Remove(primitive); + NetworkServer.Destroy(primitive); + + Indicators.Remove(parent); + NetworkServer.Destroy(parent); + + return; + } + + if (primitive != null) { - Log.Debug(primitive?.name, Config.Debug); + Log.Debug(primitive.name, Config.Debug); parent = primitive; } @@ -201,15 +219,15 @@ internal static void OnShooting(ShootingEventArgs ev) // Copying to the ToolGun if (!ev.Shooter.HasFlashlightEnabled() && ev.Shooter.ReferenceHub.weaponManager.NetworksyncZoomed) { - if (parent != null && SpawnedObjects.Contains(parent.gameObject)) + if (parent != null && SpawnedObjects.Contains(parent)) { if (!ev.Shooter.SessionVariables.ContainsKey(copyObject)) { - ev.Shooter.SessionVariables.Add(copyObject, Object.Instantiate(parent.gameObject, Vector3.zero, Quaternion.identity)); + ev.Shooter.SessionVariables.Add(copyObject, Object.Instantiate(parent, Vector3.zero, Quaternion.identity)); } else { - ev.Shooter.SessionVariables[copyObject] = Object.Instantiate(parent.gameObject, Vector3.zero, Quaternion.identity); + ev.Shooter.SessionVariables[copyObject] = Object.Instantiate(parent, Vector3.zero, Quaternion.identity); } ev.Shooter.ShowHint("Object properties have been copied to the ToolGun."); @@ -226,17 +244,17 @@ internal static void OnShooting(ShootingEventArgs ev) // Selecting the object if (ev.Shooter.HasFlashlightEnabled() && ev.Shooter.ReferenceHub.weaponManager.NetworksyncZoomed) { - if (parent != null && SpawnedObjects.Contains(parent.gameObject)) + if (parent != null && SpawnedObjects.Contains(parent)) { - ev.Shooter.ShowGamgeObjectHint(parent.gameObject); + ev.Shooter.ShowGamgeObjectHint(parent); if (!ev.Shooter.SessionVariables.ContainsKey(SelectedObjectSessionVarName)) { - ev.Shooter.SessionVariables.Add(SelectedObjectSessionVarName, parent.gameObject); + ev.Shooter.SessionVariables.Add(SelectedObjectSessionVarName, parent); } else { - ev.Shooter.SessionVariables[SelectedObjectSessionVarName] = parent.gameObject; + ev.Shooter.SessionVariables[SelectedObjectSessionVarName] = parent; } } else @@ -248,26 +266,20 @@ internal static void OnShooting(ShootingEventArgs ev) return; } - if (parent == null || !SpawnedObjects.Contains(parent.gameObject)) + if (parent == null || !SpawnedObjects.Contains(parent)) return; // Deleting the object if (!ev.Shooter.HasFlashlightEnabled() && !ev.Shooter.ReferenceHub.weaponManager.NetworksyncZoomed) { - if (Indicators.ContainsKey(parent.gameObject)) - { - NetworkServer.Destroy(Indicators[parent.gameObject]); - Indicators.Remove(parent.gameObject); - } - - if (ev.Shooter.SessionVariables.TryGetValue(SelectedObjectSessionVarName, out object selectedObject) && (GameObject)selectedObject == parent.gameObject) + if (ev.Shooter.SessionVariables.TryGetValue(SelectedObjectSessionVarName, out object selectedObject) && (GameObject)selectedObject == parent) { ev.Shooter.SessionVariables.Remove(SelectedObjectSessionVarName); ev.Shooter.ShowHint(string.Empty, 0.1f); } - SpawnedObjects.Remove(parent.gameObject); - NetworkServer.Destroy(parent.gameObject); + SpawnedObjects.Remove(parent); + NetworkServer.Destroy(parent); return; } @@ -290,7 +302,7 @@ internal static void OnReloadingWeapon(ReloadingWeaponEventArgs ev) ToolGuns[ev.Player.CurrentItem.uniq]++; - if ((int)ToolGuns[ev.Player.CurrentItem.uniq] > 5) + if ((int)ToolGuns[ev.Player.CurrentItem.uniq] > 6) { ToolGuns[ev.Player.CurrentItem.uniq] = 0; } diff --git a/MapEditorReborn/MapEditorReborn.csproj b/MapEditorReborn/MapEditorReborn.csproj index f2fc2dcf..ee15b012 100644 --- a/MapEditorReborn/MapEditorReborn.csproj +++ b/MapEditorReborn/MapEditorReborn.csproj @@ -102,6 +102,7 @@ + @@ -112,6 +113,7 @@ + diff --git a/MapEditorReborn/Methods.cs b/MapEditorReborn/Methods.cs index d5b61c9a..af4f1a8d 100644 --- a/MapEditorReborn/Methods.cs +++ b/MapEditorReborn/Methods.cs @@ -108,6 +108,15 @@ public static void LoadMap(MapSchematic map) if (map.ItemSpawnPoints.Count > 0) Log.Debug("All item spawn points have been spawned!", Config.Debug); + foreach (RagdollSpawnPointObject ragdollSpawnPoint in map.RagdollSpawnPoints) + { + Log.Debug($"Trying to spawn a ragdoll spawn point at {(Vector3)ragdollSpawnPoint.Position}...", Config.Debug); + SpawnRagdollSpawnPoint(ragdollSpawnPoint); + } + + if (map.RagdollSpawnPoints.Count > 0) + Log.Debug("All ragdoll spawn points have been spawned!", Config.Debug); + Log.Debug("All GameObject have been spawned and the MapSchematic has been fully loaded!", Config.Debug); }); } @@ -195,6 +204,20 @@ public static void SaveMap(string name) break; } + + case "RagdollSpawnPointObject(Clone)": + { + RagdollObjectComponent ragdollObjectComponent = gameObject.GetComponent(); + + map.RagdollSpawnPoints.Add(new RagdollSpawnPointObject( + ragdollObjectComponent.RagdollName, + ragdollObjectComponent.RagdollRoleType, + relativePosition, + relativeRotation, + room.Type)); + + break; + } } } @@ -327,6 +350,32 @@ public static GameObject SpawnPlayerSpawnPoint(PlayerSpawnPointObject playerSpaw return gameObject; } + public static GameObject SpawnRagdollSpawnPoint(RagdollSpawnPointObject ragdollSpawnPoint) + { + Room room = GetRandomRoom(ragdollSpawnPoint.RoomType); + + GameObject gameObject = Object.Instantiate(RagdollSpawnPointObj, GetRelativePosition(ragdollSpawnPoint.Position, room), GetRelativeRotation(ragdollSpawnPoint.Rotation, room)); + + RagdollObjectComponent ragdollObjectComponent = gameObject.AddComponent(); + + if (string.IsNullOrEmpty(ragdollObjectComponent.RagdollName) && CurrentLoadedMap.RoleNames.TryGetValue(ragdollSpawnPoint.RoleType, out List ragdollNames)) + { + ragdollObjectComponent.RagdollName = ragdollNames[Random.Range(0, ragdollNames.Count)]; + } + else + { + ragdollObjectComponent.RagdollName = ragdollSpawnPoint.Name; + } + + ragdollObjectComponent.RagdollRoleType = ragdollSpawnPoint.RoleType; + + SpawnedObjects.Add(gameObject); + + NetworkServer.Spawn(gameObject); + + return gameObject; + } + /// /// Spawns a general . /// Used by the ToolGun. @@ -379,7 +428,14 @@ public static GameObject SpawnObject(Vector3 position, ToolGunMode mode) case ToolGunMode.PlayerSpawnPoint: { gameObject.tag = "SP_173"; - gameObject.transform.position += Vector3.up * 0.1f; + gameObject.transform.position += Vector3.up * 0.25f; + break; + } + + case ToolGunMode.RagdollSpawnPoint: + { + gameObject.transform.position += Vector3.up * 1.5f; + gameObject.AddComponent(); break; } } @@ -510,18 +566,30 @@ public static void SpawnPickupIndicator(Vector3 position, Quaternion rotation, s NetworkServer.Spawn(pickupGameObject); } - public static void SpawnDummyIndicator(GameObject playerSpawnPoint) => SpawnDummyIndicator(playerSpawnPoint.transform.position, playerSpawnPoint.tag.ConvertToRoleType(), playerSpawnPoint); + public static void SpawnDummyIndicator(GameObject callingGameObject) + { + Log.Error(callingGameObject.name); + + if (callingGameObject.name == "PlayerSpawnPointObject(Clone)") + { + SpawnDummyIndicator(callingGameObject.transform.position, callingGameObject.tag.ConvertToRoleType(), callingGameObject); + } + else if (callingGameObject.name == "RagdollSpawnPointObject(Clone)") + { + SpawnDummyIndicator(callingGameObject.transform.position, callingGameObject.GetComponent().RagdollRoleType, callingGameObject); + } + } - public static void SpawnDummyIndicator(Vector3 posistion, RoleType type, GameObject callingPlayerSpawnPointObject) + public static void SpawnDummyIndicator(Vector3 posistion, RoleType type, GameObject callingGameObject) { - if (Indicators.Values.Contains(callingPlayerSpawnPointObject)) + if (Indicators.Values.Contains(callingGameObject)) { - ReferenceHub dummyIndicator = Indicators.First(x => x.Value == callingPlayerSpawnPointObject).Key.GetComponent(); + ReferenceHub dummyIndicator = Indicators.First(x => x.Value == callingGameObject).Key.GetComponent(); try { dummyIndicator.transform.position = posistion; - dummyIndicator.playerMovementSync.OverridePosition(posistion, 0f, true); + dummyIndicator.playerMovementSync.OverridePosition(posistion, 0f); } catch { @@ -531,15 +599,13 @@ public static void SpawnDummyIndicator(Vector3 posistion, RoleType type, GameObj return; } - if (Indicators.ContainsKey(callingPlayerSpawnPointObject)) - { - NetworkServer.Destroy(Indicators[callingPlayerSpawnPointObject]); - Indicators.Remove(callingPlayerSpawnPointObject); - } - GameObject dummyObject = Object.Instantiate(NetworkManager.singleton.spawnPrefabs.FirstOrDefault(p => p.gameObject.name == "Player")); dummyObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); + + if (callingGameObject.name.Contains("Ragdoll")) + dummyObject.transform.localScale *= -1; + dummyObject.transform.position = posistion; QueryProcessor processor = dummyObject.GetComponent(); @@ -569,20 +635,31 @@ public static void SpawnDummyIndicator(Vector3 posistion, RoleType type, GameObj } NicknameSync nicknameSync = dummyObject.GetComponent(); - nicknameSync.Network_myNickSync = $"PLAYER SPAWNPOINT"; - nicknameSync.CustomPlayerInfo = $"{dummyNickname}\nSPAWN POINT"; + + + if (callingGameObject.name.Contains("Ragdoll")) + { + nicknameSync.Network_myNickSync = "RAGDOLL SPAWNPOINT"; + nicknameSync.CustomPlayerInfo = $"{dummyNickname} RAGDOLL\nSPAWN POINT"; + } + else + { + nicknameSync.Network_myNickSync = "PLAYER SPAWNPOINT"; + nicknameSync.CustomPlayerInfo = $"{dummyNickname}\nSPAWN POINT"; + } + nicknameSync.ShownPlayerInfo &= ~PlayerInfoArea.Nickname; nicknameSync.ShownPlayerInfo &= ~PlayerInfoArea.Role; NetworkServer.Spawn(dummyObject); PlayerManager.players.Add(dummyObject); - Indicators.Add(dummyObject, callingPlayerSpawnPointObject); + Indicators.Add(dummyObject, callingGameObject); ReferenceHub rh = dummyObject.GetComponent(); Timing.CallDelayed(0.5f, () => { dummyObject.AddComponent().Hub = rh; - rh.playerMovementSync.OverridePosition(posistion, 0f, true); + rh.playerMovementSync.OverridePosition(posistion, 0f); }); }