Skip to content

Commit

Permalink
other toys
Browse files Browse the repository at this point in the history
  • Loading branch information
IRacle1 committed Jul 20, 2024
1 parent 15d1802 commit 5976086
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
26 changes: 17 additions & 9 deletions EXILED/Exiled.API/Features/Toys/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public bool ShadowEmission
set => Base.NetworkLightShadows = value;
}

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
public static Light Create(bool spawn = true)
=> Create(Vector3.zero, Vector3.zero, Vector3.one, spawn);

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
Expand All @@ -81,31 +89,31 @@ public bool ShadowEmission
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
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);

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
/// <param name="position">The position of the <see cref="Light"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Light"/>.</param>
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
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;
}

Expand Down
49 changes: 25 additions & 24 deletions EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public class ShootingTargetToy : AdminToy, IWrapper<ShootingTarget>
{ "binaryTargetPrefab", ShootingTargetType.Binary },
};

private static readonly Dictionary<ShootingTargetType, ShootingTarget> TypeToPrefabs = new()
{
{ ShootingTargetType.ClassD, ToysHelper.DboyShootingTargetObject },
{ ShootingTargetType.Binary, ToysHelper.BinaryShootingTargetObject },
{ ShootingTargetType.Sport, ToysHelper.SportShootingTargetObject },
{ ShootingTargetType.Unknown, ToysHelper.SportShootingTargetObject },
};

/// <summary>
/// Initializes a new instance of the <see cref="ShootingTargetToy"/> class.
/// </summary>
Expand Down Expand Up @@ -148,6 +156,15 @@ public bool IsSynced
/// </summary>
public ShootingTargetType Type { get; }

/// <summary>
/// Creates a new <see cref="ShootingTargetToy"/>.
/// </summary>
/// <param name="type">The <see cref="ShootingTargetType"/> of the <see cref="ShootingTargetToy"/>.</param>
/// <param name="spawn">Whether the <see cref="ShootingTargetToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="ShootingTargetToy"/>.</returns>
public static ShootingTargetToy Create(ShootingTargetType type, bool spawn = true) =>
Create(type, Vector3.zero, Vector3.zero, Vector3.one, spawn);

/// <summary>
/// Creates a new <see cref="ShootingTargetToy"/>.
/// </summary>
Expand All @@ -157,34 +174,18 @@ public bool IsSynced
/// <param name="scale">The scale of the <see cref="ShootingTargetToy"/>.</param>
/// <param name="spawn">Whether the <see cref="ShootingTargetToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="ShootingTargetToy"/>.</returns>
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();
Expand Down

0 comments on commit 5976086

Please sign in to comment.