Skip to content

Commit

Permalink
Readded the Placing Pickup Into Pocket Dimension Event (with Yamato's…
Browse files Browse the repository at this point in the history
… Patch) into good Exiled
  • Loading branch information
Snivy Films committed Oct 5, 2024
1 parent 244172f commit 0e8e8f9
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// -----------------------------------------------------------------------
// <copyright file="PlacingPickupIntoPocketDimensionEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// Contains information about items in the pocket dimension.
/// </summary>
public class PlacingPickupIntoPocketDimensionEventArgs : IDeniableEvent, IPickupEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="PlacingPickupIntoPocketDimensionEventArgs"/> class.
/// </summary>
/// <param name="pickupBase"><inheritdoc cref="Pickup"/></param>
/// <param name="pocketItem"><inheritdoc cref="PocketItem"/></param>
/// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
public PlacingPickupIntoPocketDimensionEventArgs(ItemPickupBase pickupBase, PocketItem pocketItem, bool isAllowed)
{
Pickup = Pickup.Get(pickupBase);
PocketItem = pocketItem;
IsAllowed = isAllowed;
}

/// <inheritdoc/>
public Pickup Pickup { get; }

/// <summary>
/// Gets the value of the PocketItem.
/// </summary>
public PocketItem PocketItem { get; }

/// <summary>
/// Gets or sets a value indicating when the Pickup will be dropped onto the map.
/// </summary>
public double DropTime
{
get => PocketItem.TriggerTime;
set => PocketItem.TriggerTime = value;
}

/// <summary>
/// Gets or sets a value indicating whether the pickup should be removed from the Pocket Dimension.
/// </summary>
public bool ShouldRemove
{
get => PocketItem.Remove;
set => PocketItem.Remove = value;
}

/// <summary>
/// Gets or sets a value indicating whether the warning sound for the pickup should be sent.
/// </summary>
public bool ShouldWarn
{
get => !PocketItem.WarningSent;
set => PocketItem.WarningSent = !value;
}

/// <summary>
/// Gets or sets the location where the pickup will drop onto the map.
/// </summary>
public Vector3 Position
{
get => PocketItem.DropPosition.Position;
set => PocketItem.DropPosition = new(value);
}

/// <inheritdoc/>
public bool IsAllowed { get; set; }
}
}
11 changes: 11 additions & 0 deletions EXILED/Exiled.Events/Handlers/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public static class Map
/// </summary>
public static Event<Scp244SpawningEventArgs> Scp244Spawning { get; set; } = new();

/// <summary>
/// Invoked before an item is placed in the pocket dimension.
/// </summary>
public static Event<PlacingPickupIntoPocketDimensionEventArgs> PlacingPickupIntoPocketDimension { get; set; } = new();

/// <summary>
/// Called before placing a decal.
/// </summary>
Expand Down Expand Up @@ -216,5 +221,11 @@ public static class Map
/// </summary>
/// <param name="ev">The <see cref="Scp244SpawningEventArgs"/> instance.</param>
public static void OnScp244Spawning(Scp244SpawningEventArgs ev) => Scp244Spawning.InvokeSafely(ev);

/// <summary>
/// Called before an item is dropped in the pocket dimension.
/// </summary>
/// <param name="ev">The <see cref="PlacingPickupIntoPocketDimensionEventArgs"/> instnace.</param>
public static void OnPlacingPickupIntoPocketDimension(PlacingPickupIntoPocketDimensionEventArgs ev) => PlacingPickupIntoPocketDimension.InvokeSafely(ev);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// -----------------------------------------------------------------------
// <copyright file="PlacingPickupIntoPocketDimension.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// Patches <see cref="Scp106PocketItemManager"/>
/// Adds the <see cref="Map.PlacingPickupIntoPocketDimension" /> event.
/// </summary>
[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);
}
}
}
}
}

0 comments on commit 0e8e8f9

Please sign in to comment.