diff --git a/EXILED/Exiled.API/Features/Items/Scp330.cs b/EXILED/Exiled.API/Features/Items/Scp330.cs index 689929f12b..d0f902184a 100644 --- a/EXILED/Exiled.API/Features/Items/Scp330.cs +++ b/EXILED/Exiled.API/Features/Items/Scp330.cs @@ -87,6 +87,11 @@ internal Scp330() /// public CandyKindID ExposedType { get; set; } = CandyKindID.None; + /// + /// Gets or sets the candy that will be added to the bag. Used for events. + /// + internal CandyKindID CandyToAdd { get; set; } = CandyKindID.None; + /// /// Adds a specific candy to the bag. /// diff --git a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs index 45a5877559..cd4d4922fd 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs @@ -31,12 +31,23 @@ public class InteractingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableE public InteractingScp330EventArgs(Player player, int usage) { Player = player; - Scp330 = Scp330Bag.TryGetBag(player.ReferenceHub, out Scp330Bag scp330Bag) ? (Scp330)Item.Get(scp330Bag) : null; - Candy = Scp330Candies.GetRandom(); UsageCount = usage; ShouldSever = usage >= 2; ShouldPlaySound = true; IsAllowed = Player.IsHuman; + + if (Scp330Bag.TryGetBag(player.ReferenceHub, out Scp330Bag scp330Bag)) + { + Scp330 = (Scp330)Item.Get(scp330Bag); + } + else + { + Scp330 = (Scp330)Item.Create(ItemType.SCP330, player); + Scp330.RemoveAllCandy(); + player.AddItem(Scp330); + } + + Scp330.CandyToAdd = Scp330Candies.GetRandom(); } /// @@ -47,7 +58,11 @@ public InteractingScp330EventArgs(Player player, int usage) /// /// Gets or sets a value indicating the type of candy that will be received from this interaction. /// - public CandyKindID Candy { get; set; } + public CandyKindID Candy + { + get => Scp330.CandyToAdd; + set => Scp330.CandyToAdd = value; + } /// /// Gets or sets a value indicating whether the player's hands should get severed. @@ -71,11 +86,9 @@ public InteractingScp330EventArgs(Player player, int usage) public Player Player { get; } /// - /// This value can be null. public Scp330 Scp330 { get; } /// - /// This value can be null. public Item Item => Scp330; } } \ No newline at end of file diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index bcb4f5308f..7bc53aadec 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -7,14 +7,15 @@ namespace Exiled.Events.Patches.Events.Scp330 { +#pragma warning disable SA1402 +#pragma warning disable SA1313 using System.Collections.Generic; using System.Reflection.Emit; - using Exiled.API.Features; + using Exiled.API.Features.Items; using Exiled.API.Features.Pools; using Exiled.Events.Attributes; using Exiled.Events.EventArgs.Scp330; - using Exiled.Events.Handlers; using HarmonyLib; using Interactables.Interobjects; using InventorySystem.Items.Usables.Scp330; @@ -26,9 +27,9 @@ namespace Exiled.Events.Patches.Events.Scp330 /// /// Patches the method to add the - /// event. + /// event. /// - [EventPatch(typeof(Scp330), nameof(Scp330.InteractingScp330))] + [EventPatch(typeof(Handlers.Scp330), nameof(Handlers.Scp330.InteractingScp330))] [HarmonyPatch(typeof(Scp330Interobject), nameof(Scp330Interobject.ServerInteract))] public static class InteractingScp330 { @@ -66,7 +67,7 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable.Pool.Return(newInstructions); } } + + /// + /// Replaces with . + /// + [EventPatch(typeof(Handlers.Scp330), nameof(Handlers.Scp330.InteractingScp330))] + [HarmonyPatch(typeof(Scp330Bag), nameof(Scp330Bag.TryAddSpecific))] + internal static class ReplaceCandy + { + private static void Prefix(Scp330Bag __instance, ref CandyKindID kind) + { + Scp330 scp330 = Item.Get(__instance); + + if (scp330.CandyToAdd != CandyKindID.None) + kind = scp330.CandyToAdd; + } + } } \ No newline at end of file