diff --git a/EXILED/Exiled.Events/EventArgs/Map/PlacingPickupIntoPocketDimensionEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/PlacingPickupIntoPocketDimensionEventArgs.cs new file mode 100644 index 000000000..dfe70c3ed --- /dev/null +++ b/EXILED/Exiled.Events/EventArgs/Map/PlacingPickupIntoPocketDimensionEventArgs.cs @@ -0,0 +1,83 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.EventArgs.Map +{ + using Exiled.API.Features.Pickups; + using Exiled.Events.EventArgs.Interfaces; + using InventorySystem.Items.Pickups; + + using UnityEngine; + + using static PlayerRoles.PlayableScps.Scp106.Scp106PocketItemManager; + + /// + /// Contains information about items in the pocket dimension. + /// + public class PlacingPickupIntoPocketDimensionEventArgs : IDeniableEvent, IPickupEvent + { + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + public PlacingPickupIntoPocketDimensionEventArgs(ItemPickupBase pickupBase, PocketItem pocketItem, bool isAllowed) + { + Pickup = Pickup.Get(pickupBase); + PocketItem = pocketItem; + IsAllowed = isAllowed; + } + + /// + public Pickup Pickup { get; } + + /// + /// Gets the value of the PocketItem. + /// + public PocketItem PocketItem { get; } + + /// + /// Gets or sets a value indicating when the Pickup will be dropped onto the map. + /// + public double DropTime + { + get => PocketItem.TriggerTime; + set => PocketItem.TriggerTime = value; + } + + /// + /// Gets or sets a value indicating whether the pickup should be removed from the Pocket Dimension. + /// + public bool ShouldRemove + { + get => PocketItem.Remove; + set => PocketItem.Remove = value; + } + + /// + /// Gets or sets a value indicating whether the warning sound for the pickup should be sent. + /// + public bool ShouldWarn + { + get => !PocketItem.WarningSent; + set => PocketItem.WarningSent = !value; + } + + /// + /// Gets or sets the location where the pickup will drop onto the map. + /// + public Vector3 Position + { + get => PocketItem.DropPosition.Position; + set => PocketItem.DropPosition = new(value); + } + + /// + public bool IsAllowed { get; set; } + } +} \ No newline at end of file diff --git a/EXILED/Exiled.Events/Handlers/Map.cs b/EXILED/Exiled.Events/Handlers/Map.cs index 561a2f9b8..41f1978ae 100644 --- a/EXILED/Exiled.Events/Handlers/Map.cs +++ b/EXILED/Exiled.Events/Handlers/Map.cs @@ -110,6 +110,11 @@ public static class Map /// public static Event Scp244Spawning { get; set; } = new(); + /// + /// Invoked before an item is placed in the pocket dimension. + /// + public static Event PlacingPickupIntoPocketDimension { get; set; } = new(); + /// /// Called before placing a decal. /// @@ -216,5 +221,11 @@ public static class Map /// /// The instance. public static void OnScp244Spawning(Scp244SpawningEventArgs ev) => Scp244Spawning.InvokeSafely(ev); + + /// + /// Called before an item is dropped in the pocket dimension. + /// + /// The instnace. + public static void OnPlacingPickupIntoPocketDimension(PlacingPickupIntoPocketDimensionEventArgs ev) => PlacingPickupIntoPocketDimension.InvokeSafely(ev); } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Map/PlacingPickupIntoPocketDimension.cs b/EXILED/Exiled.Events/Patches/Events/Map/PlacingPickupIntoPocketDimension.cs new file mode 100644 index 000000000..26afed44b --- /dev/null +++ b/EXILED/Exiled.Events/Patches/Events/Map/PlacingPickupIntoPocketDimension.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.Events.Patches.Events.Map +{ + using System.Collections.Generic; + + using Exiled.Events.Attributes; + using Exiled.Events.EventArgs.Map; + using Handlers; + using HarmonyLib; + using InventorySystem.Items.Pickups; + using Mirror; + using PlayerRoles.PlayableScps.Scp106; + + using static PlayerRoles.PlayableScps.Scp106.Scp106PocketItemManager; + + /// + /// Patches + /// Adds the event. + /// + [EventPatch(typeof(Map), nameof(Map.PlacingPickupIntoPocketDimension))] + [HarmonyPatch(typeof(Scp106PocketItemManager), nameof(Scp106PocketItemManager.OnAdded))] + internal static class PlacingPickupIntoPocketDimension + { + private static void Postfix(ItemPickupBase ipb) + { + if (TrackedItems.TryGetValue(ipb, out PocketItem pocketItem)) + { + PlacingPickupIntoPocketDimensionEventArgs ev = new(ipb, pocketItem, true); + Map.OnPlacingPickupIntoPocketDimension(ev); + + if (!ev.IsAllowed) + { + TrackedItems.Remove(ipb); + } + } + } + } +} \ No newline at end of file