From 552f26872b277169093625fe7d5e3928caff438d Mon Sep 17 00:00:00 2001 From: IRacle Date: Sat, 20 Jul 2024 13:03:31 +0300 Subject: [PATCH 1/4] e --- EXILED/Exiled.API/Features/Toys/Primitive.cs | 89 +++++++------------ .../Exiled.API/Structs/PrimitiveSettings.cs | 2 +- 2 files changed, 32 insertions(+), 59 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/Primitive.cs b/EXILED/Exiled.API/Features/Toys/Primitive.cs index 647350b16..94cae467c 100644 --- a/EXILED/Exiled.API/Features/Toys/Primitive.cs +++ b/EXILED/Exiled.API/Features/Toys/Primitive.cs @@ -90,7 +90,7 @@ public PrimitiveFlags Flags /// Whether or not the should be initially spawned. /// The new . public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(position, rotation, scale, spawn, null); + => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, Color.gray, false, spawn); /// /// Creates a new . @@ -102,7 +102,7 @@ public static Primitive Create(Vector3? position = null, Vector3? rotation = nul /// Whether or not the should be initially spawned. /// The new . public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(primitiveType, position, rotation, scale, spawn, null); + => Create(primitiveType, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, Color.gray, false, spawn); /// /// Creates a new . @@ -113,21 +113,8 @@ public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Spher /// Whether or not the should be initially spawned. /// The color of the . /// The new . - public static Primitive Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) - { - Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject)); - - primitive.Position = position ?? Vector3.zero; - primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - primitive.Scale = scale ?? Vector3.one; - - if (spawn) - primitive.Spawn(); - - primitive.Color = color ?? Color.gray; - - return primitive; - } + public static Primitive Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) + => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); /// /// Creates a new . @@ -139,22 +126,8 @@ public static Primitive Create(Vector3? position /*= null*/, Vector3? rotation / /// Whether or not the should be initially spawned. /// The color of the . /// The new . - public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) - { - Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject)); - - primitive.Position = position ?? Vector3.zero; - primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - primitive.Scale = scale ?? Vector3.one; - - if (spawn) - primitive.Spawn(); - - primitive.Base.NetworkPrimitiveType = primitiveType; - primitive.Color = color ?? Color.gray; - - return primitive; - } + public static Primitive Create(PrimitiveType primitiveType, Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) + => Create(primitiveType, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); /// /// Creates a new . @@ -167,21 +140,37 @@ public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sph /// Whether or not the should be initially spawned. /// The color of the . /// The new . - public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, PrimitiveFlags flags, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) + public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) + => Create(primitiveType, flags, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); + + /// + /// Creates a new . + /// + /// The type of primitive to spawn. + /// The primitive flags. + /// The position of the . + /// The rotation of the . + /// The scale of the . + /// The color of the . + /// Whether or not the should dynamically update. + /// Whether or not the should be initially spawned. + /// The new . + public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool isStatic, bool spawn) { Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject)); - primitive.Position = position ?? Vector3.zero; - primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - primitive.Scale = scale ?? Vector3.one; + primitive.Position = position; + primitive.Rotation = Quaternion.Euler(rotation); + primitive.Scale = scale; + primitive.Flags = flags; + primitive.IsStatic = isStatic; + primitive.Type = primitiveType; + primitive.Color = color; if (spawn) primitive.Spawn(); - primitive.Base.NetworkPrimitiveType = primitiveType; - primitive.Color = color ?? Color.gray; - return primitive; } @@ -190,24 +179,8 @@ public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sph /// /// The settings of the . /// The new . - public static Primitive Create(PrimitiveSettings primitiveSettings) - { - Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject)); - - primitive.Position = primitiveSettings.Position; - primitive.Rotation = Quaternion.Euler(primitiveSettings.Rotation); - primitive.Scale = primitiveSettings.Scale; - primitive.Flags = primitiveSettings.Flags; - - if (primitiveSettings.Spawn) - primitive.Spawn(); - - primitive.Base.NetworkPrimitiveType = primitiveSettings.PrimitiveType; - primitive.Color = primitiveSettings.Color; - primitive.IsStatic = primitiveSettings.IsStatic; - - return primitive; - } + public static Primitive Create(PrimitiveSettings primitiveSettings) => + Create(primitiveSettings.PrimitiveType, primitiveSettings.Flags, primitiveSettings.Position, primitiveSettings.Rotation, primitiveSettings.Scale, primitiveSettings.Color, primitiveSettings.IsStatic, primitiveSettings.Spawn); /// /// Gets the belonging to the . diff --git a/EXILED/Exiled.API/Structs/PrimitiveSettings.cs b/EXILED/Exiled.API/Structs/PrimitiveSettings.cs index 1cb6639fe..e59462276 100644 --- a/EXILED/Exiled.API/Structs/PrimitiveSettings.cs +++ b/EXILED/Exiled.API/Structs/PrimitiveSettings.cs @@ -111,7 +111,7 @@ public PrimitiveSettings(PrimitiveType primitiveType, PrimitiveFlags primitiveFl public Vector3 Scale { get; } /// - /// Gets a value indicating whether or not the primitive should be spawned. + /// Gets a value indicating whether or not the primitive should dynamically update. /// public bool IsStatic { get; } From 27b3bcce8ac2b03a89df151a6ac0790cf4bca42e Mon Sep 17 00:00:00 2001 From: IRacle Date: Sat, 20 Jul 2024 13:17:23 +0300 Subject: [PATCH 2/4] fuck, ill break it --- EXILED/Exiled.API/Features/Toys/Primitive.cs | 37 ++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/Primitive.cs b/EXILED/Exiled.API/Features/Toys/Primitive.cs index 94cae467c..9edfb3f77 100644 --- a/EXILED/Exiled.API/Features/Toys/Primitive.cs +++ b/EXILED/Exiled.API/Features/Toys/Primitive.cs @@ -81,6 +81,15 @@ public PrimitiveFlags Flags set => Base.NetworkPrimitiveFlags = value; } + /// + /// Creates a new . + /// + /// The type of primitive to spawn. + /// Whether or not the should be initially spawned. + /// The new . + public static Primitive Create(PrimitiveType primitiveType, bool spawn = true) + => Create(primitiveType, Vector3.zero, Vector3.zero, Vector3.one, spawn); + /// /// Creates a new . /// @@ -89,32 +98,32 @@ public PrimitiveFlags Flags /// The scale of the . /// Whether or not the should be initially spawned. /// The new . - public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, Color.gray, false, spawn); + public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true) + => Create(position, rotation, scale, Color.gray, spawn); /// /// Creates a new . /// - /// The type of primitive to spawn. /// The position of the . /// The rotation of the . /// The scale of the . + /// The color of the . /// Whether or not the should be initially spawned. /// The new . - public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(primitiveType, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, Color.gray, false, spawn); + public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn = true) + => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position, rotation, scale, color, spawn); /// /// Creates a new . /// + /// The type of primitive to spawn. /// The position of the . /// The rotation of the . /// The scale of the . /// Whether or not the should be initially spawned. - /// The color of the . /// The new . - public static Primitive Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) - => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); + public static Primitive Create(PrimitiveType primitiveType, Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true) + => Create(primitiveType, position, rotation, scale, Color.gray, spawn); /// /// Creates a new . @@ -123,11 +132,11 @@ public static Primitive Create(Vector3? position, Vector3? rotation, Vector3? sc /// The position of the . /// The rotation of the . /// The scale of the . - /// Whether or not the should be initially spawned. /// The color of the . + /// Whether or not the should be initially spawned. /// The new . - public static Primitive Create(PrimitiveType primitiveType, Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) - => Create(primitiveType, ~PrimitiveFlags.None, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); + public static Primitive Create(PrimitiveType primitiveType, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn = true) + => Create(primitiveType, ~PrimitiveFlags.None, position, rotation, scale, color, spawn); /// /// Creates a new . @@ -137,11 +146,11 @@ public static Primitive Create(PrimitiveType primitiveType, Vector3? position, V /// The position of the . /// The rotation of the . /// The scale of the . - /// Whether or not the should be initially spawned. /// The color of the . + /// Whether or not the should be initially spawned. /// The new . - public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3? position, Vector3? rotation, Vector3? scale, bool spawn, Color? color) - => Create(primitiveType, flags, position ?? Vector3.zero, rotation ?? Vector3.zero, scale ?? Vector3.one, color ?? Color.gray, false, spawn); + public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn) + => Create(primitiveType, flags, position, rotation, scale, color, false, spawn); /// /// Creates a new . From 15d18025018feedb38537f6fda90bed9b5ba391e Mon Sep 17 00:00:00 2001 From: IRacle Date: Sat, 20 Jul 2024 13:19:22 +0300 Subject: [PATCH 3/4] cooked --- EXILED/Exiled.API/Features/Toys/Primitive.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Toys/Primitive.cs b/EXILED/Exiled.API/Features/Toys/Primitive.cs index 9edfb3f77..a5fbf2e49 100644 --- a/EXILED/Exiled.API/Features/Toys/Primitive.cs +++ b/EXILED/Exiled.API/Features/Toys/Primitive.cs @@ -111,7 +111,7 @@ public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale /// Whether or not the should be initially spawned. /// The new . public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn = true) - => Create(PrimitiveType.Sphere, ~PrimitiveFlags.None, position, rotation, scale, color, spawn); + => Create(PrimitiveType.Sphere, position, rotation, scale, color, spawn); /// /// Creates a new . From 5976086521414ca3a8bb22ed3079dd7e5087912b Mon Sep 17 00:00:00 2001 From: IRacle Date: Sat, 20 Jul 2024 13:57:24 +0300 Subject: [PATCH 4/4] other toys --- EXILED/Exiled.API/Features/Toys/Light.cs | 26 ++++++---- .../Features/Toys/ShootingTargetToy.cs | 49 ++++++++++--------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/Light.cs b/EXILED/Exiled.API/Features/Toys/Light.cs index e484c9e04..0c7490ab1 100644 --- a/EXILED/Exiled.API/Features/Toys/Light.cs +++ b/EXILED/Exiled.API/Features/Toys/Light.cs @@ -73,6 +73,14 @@ public bool ShadowEmission set => Base.NetworkLightShadows = value; } + /// + /// Creates a new . + /// + /// Whether the should be initially spawned. + /// The new . + public static Light Create(bool spawn = true) + => Create(Vector3.zero, Vector3.zero, Vector3.one, spawn); + /// /// Creates a new . /// @@ -81,8 +89,8 @@ public bool ShadowEmission /// The scale of the . /// Whether the should be initially spawned. /// The new . - public static Light Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) - => Create(position, rotation, scale, spawn, null); + public static Light Create(Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true) + => Create(position, rotation, scale, Color.gray, spawn); /// /// Creates a new . @@ -90,22 +98,22 @@ public static Light Create(Vector3? position = null, Vector3? rotation = null, V /// The position of the . /// The rotation of the . /// The scale of the . - /// Whether the should be initially spawned. /// The color of the . + /// Whether the should be initially spawned. /// The new . - public static Light Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/) + public static Light Create(Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn) { Light light = new(UnityEngine.Object.Instantiate(ToysHelper.LightBaseObject)); - light.Position = position ?? Vector3.zero; - light.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - light.Scale = scale ?? Vector3.one; + light.Position = position; + light.Rotation = Quaternion.Euler(rotation); + light.Scale = scale; + + light.Color = color; if (spawn) light.Spawn(); - light.Color = color ?? Color.gray; - return light; } diff --git a/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs b/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs index 01cb47db3..ea3130c70 100644 --- a/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs +++ b/EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs @@ -35,6 +35,14 @@ public class ShootingTargetToy : AdminToy, IWrapper { "binaryTargetPrefab", ShootingTargetType.Binary }, }; + private static readonly Dictionary TypeToPrefabs = new() + { + { ShootingTargetType.ClassD, ToysHelper.DboyShootingTargetObject }, + { ShootingTargetType.Binary, ToysHelper.BinaryShootingTargetObject }, + { ShootingTargetType.Sport, ToysHelper.SportShootingTargetObject }, + { ShootingTargetType.Unknown, ToysHelper.SportShootingTargetObject }, + }; + /// /// Initializes a new instance of the class. /// @@ -148,6 +156,15 @@ public bool IsSynced /// public ShootingTargetType Type { get; } + /// + /// Creates a new . + /// + /// The of the . + /// Whether the should be initially spawned. + /// The new . + public static ShootingTargetToy Create(ShootingTargetType type, bool spawn = true) => + Create(type, Vector3.zero, Vector3.zero, Vector3.one, spawn); + /// /// Creates a new . /// @@ -157,34 +174,18 @@ public bool IsSynced /// The scale of the . /// Whether the should be initially spawned. /// The new . - public static ShootingTargetToy Create(ShootingTargetType type, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true) + public static ShootingTargetToy Create(ShootingTargetType type, Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true) { - ShootingTargetToy shootingTargetToy; - - switch (type) + if (!TypeToPrefabs.TryGetValue(type, out ShootingTarget shootingTargetBase)) { - case ShootingTargetType.ClassD: - { - shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.DboyShootingTargetObject)); - break; - } - - case ShootingTargetType.Binary: - { - shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.BinaryShootingTargetObject)); - break; - } - - default: - { - shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.SportShootingTargetObject)); - break; - } + shootingTargetBase = TypeToPrefabs[ShootingTargetType.Unknown]; } - shootingTargetToy.Position = position ?? Vector3.zero; - shootingTargetToy.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); - shootingTargetToy.Scale = scale ?? Vector3.one; + ShootingTargetToy shootingTargetToy = new ShootingTargetToy(shootingTargetBase); + + shootingTargetToy.Position = position; + shootingTargetToy.Rotation = Quaternion.Euler(rotation); + shootingTargetToy.Scale = scale; if (spawn) shootingTargetToy.Spawn();