diff --git a/EXILED/Exiled.API/Features/Items/Item.cs b/EXILED/Exiled.API/Features/Items/Item.cs index 308c757582..7cff7ab1e4 100644 --- a/EXILED/Exiled.API/Features/Items/Item.cs +++ b/EXILED/Exiled.API/Features/Items/Item.cs @@ -26,6 +26,7 @@ namespace Exiled.API.Features.Items using InventorySystem.Items.ThrowableProjectiles; using InventorySystem.Items.ToggleableLights; using InventorySystem.Items.Usables; + using InventorySystem.Items.Usables.Scp1344; using InventorySystem.Items.Usables.Scp1576; using InventorySystem.Items.Usables.Scp244; using InventorySystem.Items.Usables.Scp330; @@ -205,6 +206,7 @@ public static Item Get(ItemBase itemBase) Scp330Bag scp330Bag => new Scp330(scp330Bag), Scp244Item scp244Item => new Scp244(scp244Item), Scp1576Item scp1576 => new Scp1576(scp1576), + Scp1344Item scp1344 => new Scp1344(scp1344), BaseConsumable consumable => new Consumable(consumable), _ => new Usable(usable), }, @@ -272,6 +274,7 @@ public static T Get(ushort serial) ///
- SCP-330 can be casted to . ///
- SCP-2176 can be casted to the class. ///
- SCP-1576 can be casted to the class. + ///
- SCP-1344 can be casted to the class. ///
- Jailbird can be casted to the class. /// /// @@ -300,6 +303,7 @@ ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemTy ItemType.SCP330 => new Scp330(), ItemType.SCP2176 => new Scp2176(owner), ItemType.SCP1576 => new Scp1576(), + ItemType.SCP1344 => new Scp1344(), ItemType.Jailbird => new Jailbird(), _ => new Item(type), }; @@ -325,6 +329,7 @@ ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemTy ///
- SCP-330 can be casted to . ///
- SCP-2176 can be casted to the class. ///
- SCP-1576 can be casted to the class. + ///
- SCP-1344 can be casted to the class. ///
- Jailbird can be casted to the class. ///
/// diff --git a/EXILED/Exiled.API/Features/Items/Scp1344.cs b/EXILED/Exiled.API/Features/Items/Scp1344.cs new file mode 100644 index 0000000000..805ff2d745 --- /dev/null +++ b/EXILED/Exiled.API/Features/Items/Scp1344.cs @@ -0,0 +1,83 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Features.Items +{ + using Exiled.API.Interfaces; + using InventorySystem.Items.Usables; + using InventorySystem.Items.Usables.Scp1344; + using PlayerRoles.FirstPersonControl.Thirdperson.Subcontrollers; + + /// + /// A wrapper class for . + /// + public class Scp1344 : Usable, IWrapper + { + /// + /// Initializes a new instance of the class. + /// + /// The base class. + public Scp1344(Scp1344Item itemBase) + : base(itemBase) + { + Base = itemBase; + } + + /// + /// Initializes a new instance of the class. + /// + internal Scp1344() + : this((Scp1344Item)Server.Host.Inventory.CreateItemInstance(new(ItemType.SCP1344, 0), false)) + { + } + + /// + /// Gets the that this class is encapsulating. + /// + public new Scp1344Item Base { get; } + + /// + /// Gets a value indicating whether it can be started to use. + /// + public bool CanStartUsing => Base.CanStartUsing; + + /// + /// Gets or sets the status of Scp1344. + /// + public Scp1344Status Status + { + get => Base.Status; + set => Base.Status = value; + } + + /// + /// Forcefully Deactivate SCP-1344. + /// + /// Drop or not the item. + public void Deactivate(bool dropItem = false) + { + if (Status is not(Scp1344Status.Active or Scp1344Status.Stabbing or Scp1344Status.Dropping)) + { + return; + } + + Base.Owner.DisableWearables(WearableElements.Scp1344Goggles); + Base.ActivateFinalEffects(); + Status = Scp1344Status.Idle; + + if (dropItem) + { + Base.ServerDropItem(true); + } + } + + /// + /// Forcefully activated SCP-1344. + /// + public void Actived() => Status = Scp1344Status.Stabbing; + } +} diff --git a/EXILED/Exiled.Events/EventArgs/Interfaces/IScp1344Event.cs b/EXILED/Exiled.Events/EventArgs/Interfaces/IScp1344Event.cs new file mode 100644 index 0000000000..c2009ae7de --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Interfaces/IScp1344Event.cs @@ -0,0 +1,22 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Interfaces +{ + using Exiled.API.Features.Items; + + /// + /// Event args used for all related events. + /// + public interface IScp1344Event : IItemEvent + { + /// + /// Gets the triggering the event. + /// + public Scp1344 Scp1344 { get; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/EventArgs/Scp1344/ChangedStatusEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp1344/ChangedStatusEventArgs.cs new file mode 100644 index 0000000000..11afddf79c --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp1344/ChangedStatusEventArgs.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.EventArgs.Interfaces; + using InventorySystem.Items.Usables.Scp1344; + + /// + /// Contains all information after SCP-1344 status changing. + /// + public class ChangedStatusEventArgs : IScp1344Event, IPlayerEvent, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public ChangedStatusEventArgs(Item item, Scp1344Status scp1344Status) + { + Item = item; + Scp1344 = item as Scp1344; + Player = item.Owner; + Scp1344Status = scp1344Status; + } + + /// + /// Gets the new state. + /// + public Scp1344Status Scp1344Status { get; } + + /// + /// Gets the item. + /// + public Item Item { get; } + + /// + /// Gets the player in owner of the item. + /// + public Exiled.API.Features.Player Player { get; } + + /// + /// Gets Scp1344 item. + /// + public Scp1344 Scp1344 { get; } + + /// + public bool IsAllowed { get; set; } + } +} diff --git a/EXILED/Exiled.Events/EventArgs/Scp1344/ChangingStatusEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp1344/ChangingStatusEventArgs.cs new file mode 100644 index 0000000000..89329e0730 --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp1344/ChangingStatusEventArgs.cs @@ -0,0 +1,64 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.EventArgs.Interfaces; + using InventorySystem.Items.Usables.Scp1344; + + /// + /// Contains all information before SCP-1344 status changing. + /// + public class ChangingStatusEventArgs : IPlayerEvent, IScp1344Event, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + public ChangingStatusEventArgs(Item item, Scp1344Status scp1344StatusNew, Scp1344Status scp1344StatusOld, bool isAllowed = true) + { + Item = item; + Scp1344 = item as Scp1344; + Player = item.Owner; + Scp1344StatusNew = scp1344StatusNew; + Scp1344StatusOld = scp1344StatusOld; + IsAllowed = isAllowed; + } + + /// + /// Gets the current status. + /// + public Scp1344Status Scp1344StatusOld { get; } + + /// + /// Gets or sets the new state. + /// + public Scp1344Status Scp1344StatusNew { get; set; } + + /// + /// Gets the item. + /// + public Item Item { get; } + + /// + /// Gets the player in owner of the item. + /// + public Exiled.API.Features.Player Player { get; } + + /// + /// Gets Scp1344 item. + /// + public Scp1344 Scp1344 { get; } + + /// + public bool IsAllowed { get; set; } + } +} diff --git a/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatedEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatedEventArgs.cs new file mode 100644 index 0000000000..79ec6925ee --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatedEventArgs.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information after deactivating. + /// + public class DeactivatedEventArgs : IPlayerEvent, IScp1344Event + { + /// + /// Initializes a new instance of the class. + /// + /// + public DeactivatedEventArgs(Item item) + { + Item = item; + Scp1344 = item as Scp1344; + Player = item.Owner; + } + + /// + /// Gets the item. + /// + public Item Item { get; } + + /// + /// Gets the player in owner of the item. + /// + public Exiled.API.Features.Player Player { get; } + + /// + /// Gets Scp1344 item. + /// + public Scp1344 Scp1344 { get; } + } +} diff --git a/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatingEventArgs.cs new file mode 100644 index 0000000000..96bcbc211e --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp1344/DeactivatingEventArgs.cs @@ -0,0 +1,49 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information before deactivating. + /// + public class DeactivatingEventArgs : IPlayerEvent, IScp1344Event, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public DeactivatingEventArgs(Item item, bool isAllowed = true) + { + Item = item; + Scp1344 = item as Scp1344; + Player = item.Owner; + IsAllowed = isAllowed; + } + + /// + /// Gets the item. + /// + public Item Item { get; } + + /// + /// Gets the player in owner of the item. + /// + public Exiled.API.Features.Player Player { get; } + + /// + /// Gets Scp1344 item. + /// + public Scp1344 Scp1344 { get; } + + /// + public bool IsAllowed { get; set; } + } +} diff --git a/EXILED/Exiled.Events/EventArgs/Scp1344/TryingDeactivatingEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp1344/TryingDeactivatingEventArgs.cs new file mode 100644 index 0000000000..f236851f1c --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Scp1344/TryingDeactivatingEventArgs.cs @@ -0,0 +1,49 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.EventArgs.Interfaces; + + /// + /// Contains all information before trying deactivating. + /// + public class TryingDeactivatingEventArgs : IPlayerEvent, IScp1344Event, IDeniableEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + public TryingDeactivatingEventArgs(Item item, bool isAllowed = true) + { + Item = item; + Scp1344 = item as Scp1344; + Player = item.Owner; + IsAllowed = isAllowed; + } + + /// + /// Gets the item. + /// + public Item Item { get; } + + /// + /// Gets the player in owner of the item. + /// + public Exiled.API.Features.Player Player { get; } + + /// + /// Gets Scp1344 item. + /// + public Scp1344 Scp1344 { get; } + + /// + public bool IsAllowed { get; set; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Scp1344.cs b/EXILED/Exiled.Events/Handlers/Scp1344.cs new file mode 100644 index 0000000000..e3cd688c7c --- /dev/null +++ b/EXILED/Exiled.Events/Handlers/Scp1344.cs @@ -0,0 +1,75 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Handlers +{ +#pragma warning disable SA1623 // Property summary documentation should match accessors + + using Exiled.Events.EventArgs.Scp1344; + using Exiled.Events.Features; + + /// + /// SCP-1344 related events. + /// + public static class Scp1344 + { + /// + /// Invoked before SCP-1344 status changing. + /// + public static Event ChangingStatus { get; set; } = new(); + + /// + /// Invoked after SCP-1344 status changing. + /// + public static Event ChangedStatus { get; set; } = new(); + + /// + /// Invoked after trying deactivating SCP-1344. + /// + public static Event TryingDeactivating { get; set; } = new(); + + /// + /// Invoked before deactivating SCP-1344. + /// + public static Event Deactivating { get; set; } = new(); + + /// + /// Invoked after deactivating SCP-1344. + /// + public static Event Deactivated { get; set; } = new(); + + /// + /// Called after deactivating SCP-1344. + /// + /// The instance. + public static void OnDeactivated(DeactivatedEventArgs ev) => Deactivated.InvokeSafely(ev); + + /// + /// Called before deactivating SCP-1344. + /// + /// The instance. + public static void OnDeactivating(DeactivatingEventArgs ev) => Deactivating.InvokeSafely(ev); + + /// + /// Called after trying deactivating SCP-1344. + /// + /// The instance. + public static void OnTryingDeactivating(TryingDeactivatingEventArgs ev) => TryingDeactivating.InvokeSafely(ev); + + /// + /// Called before SCP-1344 status changing. + /// + /// The instance. + public static void OnChangingStatus(ChangingStatusEventArgs ev) => ChangingStatus.InvokeSafely(ev); + + /// + /// Called after SCP-1344 status changing. + /// + /// The instance. + public static void OnChangedStatus(ChangedStatusEventArgs ev) => ChangedStatus.InvokeSafely(ev); + } +} diff --git a/EXILED/Exiled.Events/Patches/Events/Scp1344/Deactivating.cs b/EXILED/Exiled.Events/Patches/Events/Scp1344/Deactivating.cs new file mode 100644 index 0000000000..e1b3066099 --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Scp1344/Deactivating.cs @@ -0,0 +1,73 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + +namespace Exiled.Events.Patches.Events.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Scp1344; + using HarmonyLib; + using InventorySystem.Items.Usables.Scp1344; + using InventorySystem.Items.Usables.Scp244; + using UnityEngine; + + /// + /// Patches . + /// Adds the event, + /// event and + /// event. + /// + [EventPatch(typeof(Handlers.Scp1344), nameof(Handlers.Scp1344.TryingDeactivating))] + [EventPatch(typeof(Handlers.Scp1344), nameof(Handlers.Scp1344.Deactivating))] + [EventPatch(typeof(Handlers.Scp1344), nameof(Handlers.Scp1344.Deactivated))] + [HarmonyPatch(typeof(Scp1344Item), nameof(Scp1344Item.ServerUpdateDeactivating))] + internal static class Deactivating + { + private static bool Prefix(ref Scp1344Item __instance) + { + if (__instance._useTime == 0) + { + var ev = new TryingDeactivatingEventArgs(Item.Get(__instance)); + Exiled.Events.Handlers.Scp1344.OnTryingDeactivating(ev); + + if (!ev.IsAllowed) + { + return StopDeactivation(__instance); + } + } + + if (__instance._useTime + Time.deltaTime >= 5.1f) + { + var deactivating = new DeactivatingEventArgs(Item.Get(__instance)); + Exiled.Events.Handlers.Scp1344.OnDeactivating(deactivating); + + if (!deactivating.IsAllowed) + { + return StopDeactivation(__instance); + } + + __instance.ActivateFinalEffects(); + __instance.ServerDropItem(__instance); + + var ev = new DeactivatedEventArgs(Item.Get(__instance)); + Exiled.Events.Handlers.Scp1344.OnDeactivated(ev); + return false; + } + + return true; + } + + private static bool StopDeactivation(Scp1344Item instance) + { + instance.Status = Scp1344Status.Active; + instance.ServerSetStatus(Scp1344Status.Active); + return false; + } + } +} diff --git a/EXILED/Exiled.Events/Patches/Events/Scp1344/Status.cs b/EXILED/Exiled.Events/Patches/Events/Scp1344/Status.cs new file mode 100644 index 0000000000..bfe734986c --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Scp1344/Status.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + +namespace Exiled.Events.Patches.Events.Scp1344 +{ + using Exiled.API.Features.Items; + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Scp1344; + using HarmonyLib; + using InventorySystem.Items.Usables.Scp1344; + + /// + /// Patches . + /// Adds the event and + /// event. + /// + [EventPatch(typeof(Handlers.Scp1344), nameof(Handlers.Scp1344.ChangingStatus))] + [EventPatch(typeof(Handlers.Scp1344), nameof(Handlers.Scp1344.ChangedStatus))] + [HarmonyPatch(typeof(Scp1344Item), nameof(Scp1344Item.Status), MethodType.Setter)] + internal static class Status + { + private static bool Prefix(Scp1344Item __instance, ref Scp1344Status value) + { + ChangingStatusEventArgs ev = new(Item.Get(__instance), value, __instance._status); + Handlers.Scp1344.OnChangingStatus(ev); + value = ev.Scp1344StatusNew; + return ev.IsAllowed; + } + + private static void Postfix(Scp1344Item __instance, ref Scp1344Status value) + { + ChangedStatusEventArgs ev = new(Item.Get(__instance), value); + Handlers.Scp1344.OnChangedStatus(ev); + } + } +} \ No newline at end of file