diff --git a/EXILED/Exiled.API/Features/Items/Scp330.cs b/EXILED/Exiled.API/Features/Items/Scp330.cs index d0f902184a..689929f12b 100644 --- a/EXILED/Exiled.API/Features/Items/Scp330.cs +++ b/EXILED/Exiled.API/Features/Items/Scp330.cs @@ -87,11 +87,6 @@ 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 cd4d4922fd..bbe06102e4 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs @@ -46,8 +46,6 @@ public InteractingScp330EventArgs(Player player, int usage) Scp330.RemoveAllCandy(); player.AddItem(Scp330); } - - Scp330.CandyToAdd = Scp330Candies.GetRandom(); } /// @@ -55,15 +53,6 @@ public InteractingScp330EventArgs(Player player, int usage) /// public int UsageCount { get; } - /// - /// Gets or sets a value indicating the type of candy that will be received from this interaction. - /// - public CandyKindID Candy - { - get => Scp330.CandyToAdd; - set => Scp330.CandyToAdd = value; - } - /// /// Gets or sets a value indicating whether the player's hands should get severed. /// @@ -75,6 +64,11 @@ public CandyKindID Candy /// It won't work if = . public bool ShouldPlaySound { get; set; } + /// + /// Gets or sets a value indicating the type of candy that will be received from this interaction. + /// + public CandyKindID Candy { get; set; } + /// /// Gets or sets a value indicating whether the player is allowed to interact with SCP-330. /// diff --git a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs index 7bc53aadec..c91a8b4ad8 100644 --- a/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs +++ b/EXILED/Exiled.Events/Patches/Events/Scp330/InteractingScp330.cs @@ -9,6 +9,7 @@ namespace Exiled.Events.Patches.Events.Scp330 { #pragma warning disable SA1402 #pragma warning disable SA1313 + using System.Collections.Generic; using System.Reflection.Emit; @@ -18,6 +19,7 @@ namespace Exiled.Events.Patches.Events.Scp330 using Exiled.Events.EventArgs.Scp330; using HarmonyLib; using Interactables.Interobjects; + using InventorySystem; using InventorySystem.Items.Usables.Scp330; using PluginAPI.Events; @@ -73,19 +75,37 @@ private static IEnumerable Transpiler(IEnumerable instruction.Calls(Method(typeof(Scp330Bag), nameof(Scp330Bag.ServerProcessPickup)))) + remove_offset; + + // Remove original add candy logic + newInstructions.RemoveRange(remove_index, 4); + /* next code will used to override sound rpc check by EXILED * old: * if (args.PlaySound) * new: - * if (args.PlaySound && ev.PlaySound) + * if (args.PlaySound | ev.PlaySound) */ - offset = 1; index = newInstructions.FindLastIndex( instruction => instruction.Calls(PropertyGetter(typeof(PlayerInteractScp330Event), nameof(PlayerInteractScp330Event.PlaySound)))) + offset; - newInstructions.InsertRange( index, new[] @@ -93,9 +113,8 @@ private static IEnumerable Transpiler(IEnumerable= 2) @@ -135,21 +154,28 @@ private static 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) + private static bool ServerProcessPickup(ReferenceHub player, CandyKindID candy, out Scp330Bag bag) { - Scp330 scp330 = Item.Get(__instance); + if (!Scp330Bag.TryGetBag(player, out bag)) + { + player.inventory.ServerAddItem(ItemType.SCP330); + + if (!Scp330Bag.TryGetBag(player, out bag)) + return false; + + bag.Candies = new List { candy }; + bag.ServerRefreshBag(); + + return true; + } + + bool result = bag.TryAddSpecific(candy); + + if (bag.AcquisitionAlreadyReceived) + bag.ServerRefreshBag(); - if (scp330.CandyToAdd != CandyKindID.None) - kind = scp330.CandyToAdd; + return result; } } } \ No newline at end of file