From 3e506797dffa44d2bdd0dbe61c6d27edec36a3a5 Mon Sep 17 00:00:00 2001 From: Michal78900 Date: Tue, 10 Aug 2021 19:26:29 +0200 Subject: [PATCH] Ragdoll's damage type --- .../API/Components/RagdollObjectComponent.cs | 16 +++++++++++++++- MapEditorReborn/API/Extenstions.cs | 17 +++++++++-------- MapEditorReborn/API/MapSchematic.cs | 6 ++++++ .../API/Objects/RagdollSpawnPointObject.cs | 8 ++++++-- MapEditorReborn/Methods.cs | 5 ++++- MapEditorReborn/Plugin.cs | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/MapEditorReborn/API/Components/RagdollObjectComponent.cs b/MapEditorReborn/API/Components/RagdollObjectComponent.cs index d93f16df..ce5d67a5 100644 --- a/MapEditorReborn/API/Components/RagdollObjectComponent.cs +++ b/MapEditorReborn/API/Components/RagdollObjectComponent.cs @@ -6,15 +6,29 @@ public class RagdollObjectComponent : MonoBehaviour { + /// + /// Ragdoll's nickname. + /// public string RagdollName = string.Empty; + /// + /// Ragdoll's role type. + /// public RoleType RagdollRoleType = RoleType.ClassD; + /// + /// Ragdoll's damage type. + /// + public string RagdollDamageType = "None"; + + /// + /// Ragdoll that is attached to this object. + /// public Ragdoll AttachedRagdoll = null; private void Start() { - AttachedRagdoll = Map.SpawnRagdoll(RagdollRoleType, DamageTypes.None, RagdollName, gameObject.transform.position, gameObject.transform.rotation); + AttachedRagdoll = Map.SpawnRagdoll(RagdollRoleType, RagdollDamageType.ConvertToDamageType(), RagdollName, gameObject.transform.position, gameObject.transform.rotation); } private void OnDestroy() diff --git a/MapEditorReborn/API/Extenstions.cs b/MapEditorReborn/API/Extenstions.cs index e3e3008c..e7313c71 100644 --- a/MapEditorReborn/API/Extenstions.cs +++ b/MapEditorReborn/API/Extenstions.cs @@ -17,10 +17,7 @@ public static class Extenstions /// /// The item to check. /// if the is a Tool Gun, otherwise . - public static bool IsToolGun(this Inventory.SyncItemInfo item) - { - return Handler.ToolGuns.ContainsKey(item.uniq); - } + public static bool IsToolGun(this Inventory.SyncItemInfo item) => Handler.ToolGuns.ContainsKey(item.uniq); /// /// Used for showing details about the to a specifc . @@ -293,15 +290,19 @@ public static RoleType ConvertToRoleType(this string spawnPointTag) } } + /// + /// Converts a string to it's equivalent. + /// + /// The string to convert/. + /// A . + public static DamageTypes.DamageType ConvertToDamageType(this string damageType) => DamageTypes.Types.FirstOrDefault(x => x.Key.name.Replace(" ", string.Empty).Replace("-", string.Empty).ToLower() == damageType.ToLower()).Key; + /// /// Checks if player has enabled flashlight mounted on a gun (ToolGun). /// /// The player to check. /// if the flashlight is enabled, if not. - public static bool HasFlashlightEnabled(this Player player) - { - return player.ReferenceHub.weaponManager.syncFlash && player.ReferenceHub.weaponManager.weapons[player.ReferenceHub.weaponManager.curWeapon].mod_others.Any((item) => item.isActive && item.name == "Flashlight"); - } + public static bool HasFlashlightEnabled(this Player player) => player.ReferenceHub.weaponManager.syncFlash && player.ReferenceHub.weaponManager.weapons[player.ReferenceHub.weaponManager.curWeapon].mod_others.Any((item) => item.isActive && item.name == "Flashlight"); /// /// Updates GameObject's indicator (if it exists) and the player's hint (is the object is selected). diff --git a/MapEditorReborn/API/MapSchematic.cs b/MapEditorReborn/API/MapSchematic.cs index f8df9727..9ad2e825 100644 --- a/MapEditorReborn/API/MapSchematic.cs +++ b/MapEditorReborn/API/MapSchematic.cs @@ -26,6 +26,9 @@ public MapSchematic() /// public bool RemoveDefaultSpawnPoints { get; set; } = false; + /// + /// Gets or sets possible role names for a ragdolls. + /// public Dictionary> RoleNames { get; set; } = new Dictionary>() { { RoleType.ClassD, new List() { "D-9341" } }, @@ -51,6 +54,9 @@ public MapSchematic() /// public List PlayerSpawnPoints { get; set; } = new List(); + /// + /// Gets or sets the list of . + /// public List RagdollSpawnPoints { get; set; } = new List(); } } diff --git a/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs b/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs index 23fe0e56..94f90e57 100644 --- a/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs +++ b/MapEditorReborn/API/Objects/RagdollSpawnPointObject.cs @@ -1,7 +1,7 @@ namespace MapEditorReborn.API { - using Exiled.API.Enums; using System; + using Exiled.API.Enums; using UnityEngine; [Serializable] @@ -14,10 +14,12 @@ public RagdollSpawnPointObject() { } - public RagdollSpawnPointObject(string name, RoleType roleType, Vector3 position, Vector3 rotation, RoomType roomType) + /// + public RagdollSpawnPointObject(string name, RoleType roleType, string damageType, Vector3 position, Vector3 rotation, RoomType roomType) { Name = name; RoleType = roleType; + DamageType = damageType; Position = position; Rotation = rotation; RoomType = roomType; @@ -27,6 +29,8 @@ public RagdollSpawnPointObject(string name, RoleType roleType, Vector3 position, public RoleType RoleType { get; private set; } = RoleType.ClassD; + public string DamageType { get; private set; } = "None"; + public SerializableVector3 Position { get; private set; } = SerializableVector3.Zero; public SerializableVector3 Rotation { get; private set; } = SerializableVector3.Zero; diff --git a/MapEditorReborn/Methods.cs b/MapEditorReborn/Methods.cs index af4f1a8d..11b19b59 100644 --- a/MapEditorReborn/Methods.cs +++ b/MapEditorReborn/Methods.cs @@ -132,7 +132,8 @@ public static void SaveMap(string name) MapSchematic map = new MapSchematic { Name = name, - RemoveDefaultSpawnPoints = Server.Host.SessionVariables.TryGetValue(RemoveDefaultSpawnPointsVarName, out object removeSpawnPoints) && (bool)removeSpawnPoints, + RemoveDefaultSpawnPoints = CurrentLoadedMap?.RemoveDefaultSpawnPoints ?? default, + RoleNames = CurrentLoadedMap?.RoleNames ?? default, }; Log.Debug($"Map name set to \"{map.Name}\"", Config.Debug); @@ -212,6 +213,7 @@ public static void SaveMap(string name) map.RagdollSpawnPoints.Add(new RagdollSpawnPointObject( ragdollObjectComponent.RagdollName, ragdollObjectComponent.RagdollRoleType, + ragdollObjectComponent.RagdollDamageType, relativePosition, relativeRotation, room.Type)); @@ -368,6 +370,7 @@ public static GameObject SpawnRagdollSpawnPoint(RagdollSpawnPointObject ragdollS } ragdollObjectComponent.RagdollRoleType = ragdollSpawnPoint.RoleType; + ragdollObjectComponent.RagdollDamageType = ragdollSpawnPoint.DamageType; SpawnedObjects.Add(gameObject); diff --git a/MapEditorReborn/Plugin.cs b/MapEditorReborn/Plugin.cs index f05942dc..158e9e60 100644 --- a/MapEditorReborn/Plugin.cs +++ b/MapEditorReborn/Plugin.cs @@ -86,7 +86,7 @@ public override void OnDisabled() public override string Author => "Michal78900 (original idea by Killers0992)"; /// - public override Version Version => new Version(0, 3, 0); + public override Version Version => new Version(0, 4, 1); /// public override Version RequiredExiledVersion => new Version(2, 11, 1);