Skip to content

Commit

Permalink
IScp330Event
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Jul 31, 2024
1 parent 21dae12 commit c78b733
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 18 deletions.
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/EventArgs/Interfaces/IHazardEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Exiled.Events.EventArgs.Interfaces
using Exiled.API.Features.Hazards;

/// <summary>
/// Event args for all <see cref="Hazard"/> related events.
/// Event args for all <see cref="API.Features.Hazards.Hazard"/> related events.
/// </summary>
public interface IHazardEvent : IExiledEvent
{
Expand Down
22 changes: 22 additions & 0 deletions EXILED/Exiled.Events/EventArgs/Interfaces/IScp330Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -----------------------------------------------------------------------
// <copyright file="IScp330Event.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.Interfaces
{
using Exiled.API.Features.Items;

/// <summary>
/// Event args used for all <see cref="API.Features.Items.Scp330" /> related events.
/// </summary>
public interface IScp330Event : IItemEvent
{
/// <summary>
/// Gets the <see cref="API.Features.Items.Scp330" /> triggering the event.
/// </summary>
public Scp330 Scp330 { get; }
}
}
4 changes: 2 additions & 2 deletions EXILED/Exiled.Events/EventArgs/Interfaces/IUsableEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Exiled.Events.EventArgs.Interfaces
using Exiled.API.Features.Items;

/// <summary>
/// Event args used for all <see cref="Usable" /> related events.
/// Event args used for all <see cref="API.Features.Items.Usable" /> related events.
/// </summary>
public interface IUsableEvent : IItemEvent
{
/// <summary>
/// Gets the <see cref="Usable" /> triggering the event.
/// Gets the <see cref="API.Features.Items.Usable" /> triggering the event.
/// </summary>
public Usable Usable { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Scp330
/// <summary>
/// Contains all information before a player drops a SCP-330 candy.
/// </summary>
public class DroppingScp330EventArgs : IPlayerEvent, IDeniableEvent
public class DroppingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DroppingScp330EventArgs" /> class.
Expand All @@ -39,9 +39,12 @@ public DroppingScp330EventArgs(Player player, Scp330Bag scp330, CandyKindID cand
}

/// <summary>
/// Gets or sets a value representing the <see cref="Item" /> being picked up.
/// Gets or sets a value representing the <see cref="API.Features.Items.Item" /> being picked up.
/// </summary>
public Scp330 Scp330 { get; set; }
public Scp330 Scp330 { get; set; } // Todo Remove set

/// <inheritdoc/>
public Item Item => Scp330;

/// <summary>
/// Gets or sets a value indicating whether or not the type of candy drop.
Expand Down
14 changes: 11 additions & 3 deletions EXILED/Exiled.Events/EventArgs/Scp330/EatenScp330EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
namespace Exiled.Events.EventArgs.Scp330
{
using API.Features;

using Exiled.API.Features.Items;
using Interfaces;

using InventorySystem.Items.Usables.Scp330;

/// <summary>
/// Contains all information after a player has eaten SCP-330.
/// </summary>
public class EatenScp330EventArgs : IPlayerEvent
public class EatenScp330EventArgs : IPlayerEvent, IScp330Event
{
/// <summary>
/// Initializes a new instance of the <see cref="EatenScp330EventArgs" /> class.
/// </summary>
/// <param name="player"><inheritdoc cref="Player" />.</param>
/// <param name="scp330"><inheritdoc cref="Scp330" />.</param>
/// <param name="candy"><inheritdoc cref="Candy" />.</param>
public EatenScp330EventArgs(Player player, ICandy candy)
public EatenScp330EventArgs(Player player, Scp330Bag scp330, ICandy candy)
{
Player = player;
Scp330 = (Scp330)Item.Get(scp330);
Candy = candy;
}

Expand All @@ -38,5 +40,11 @@ public EatenScp330EventArgs(Player player, ICandy candy)
/// Gets the player who has eaten SCP-330.
/// </summary>
public Player Player { get; }

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

/// <inheritdoc/>
public Item Item => Scp330;
}
}
16 changes: 12 additions & 4 deletions EXILED/Exiled.Events/EventArgs/Scp330/EatingScp330EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
namespace Exiled.Events.EventArgs.Scp330
{
using API.Features;

using Exiled.API.Features.Items;
using Interfaces;

using InventorySystem.Items.Usables.Scp330;

/// <summary>
/// Contains all information before a player eats SCP-330.
/// </summary>
public class EatingScp330EventArgs : IPlayerEvent, IDeniableEvent
public class EatingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="EatingScp330EventArgs" /> class.
/// </summary>
/// <param name="player"><see cref="Player" />.</param>
/// <param name="candy"><see cref="ICandy" />.</param>
/// <param name="scp330"><inheritdoc cref="Scp330" />.</param>
/// <param name="candy"><see cref="Candy" />.</param>
/// <param name="isAllowed"><see cref="IsAllowed" />.</param>
public EatingScp330EventArgs(Player player, ICandy candy, bool isAllowed = true)
public EatingScp330EventArgs(Player player, Scp330Bag scp330, ICandy candy, bool isAllowed = true)
{
Player = player;
Scp330 = (Scp330)Item.Get(scp330);
Candy = candy;
IsAllowed = isAllowed;
}
Expand All @@ -45,5 +47,11 @@ public EatingScp330EventArgs(Player player, ICandy candy, bool isAllowed = true)
/// Gets the player who's eating SCP-330.
/// </summary>
public Player Player { get; }

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

/// <inheritdoc/>
public Item Item => Scp330;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
namespace Exiled.Events.EventArgs.Scp330
{
using API.Features;

using Exiled.API.Features.Items;
using Interfaces;

using InventorySystem.Items.Usables.Scp330;
using YamlDotNet.Core.Tokens;

/// <summary>
/// Contains all information before a player interacts with SCP-330.
/// </summary>
public class InteractingScp330EventArgs : IPlayerEvent, IDeniableEvent
public class InteractingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="InteractingScp330EventArgs" /> class.
Expand All @@ -30,6 +31,7 @@ public class InteractingScp330EventArgs : IPlayerEvent, IDeniableEvent
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;
Expand Down Expand Up @@ -60,5 +62,13 @@ public InteractingScp330EventArgs(Player player, int usage)
/// Gets the <see cref="API.Features.Player" /> triggering the event.
/// </summary>
public Player Player { get; }

/// <inheritdoc/>
/// <remarks>This value can be null.</remarks>
public Scp330 Scp330 { get; }

/// <inheritdoc/>
/// <remarks>This value can be null.</remarks>
public Item Item => Scp330;
}
}
10 changes: 8 additions & 2 deletions EXILED/Exiled.Events/Patches/Events/Scp330/EatingScp330.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp330Bag), nameof(Scp330Bag.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// this
new(OpCodes.Ldarg_0),

// ICandy
new(OpCodes.Ldloc_0),

// true
new(OpCodes.Ldc_I4_1),

// EatingScp330EventArgs ev = new(player, candy, true)
// EatingScp330EventArgs ev = new(Player, Scp330Bag, ICandy, bool)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EatingScp330EventArgs))[0]),
new(OpCodes.Dup),

Expand All @@ -84,10 +87,13 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp330Bag), nameof(Scp330Bag.Owner))),
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),

// this
new(OpCodes.Ldarg_0),

// ICandy
new(OpCodes.Ldloc_0),

// EatenScp330EventArgs ev = new(player, candy)
// EatenScp330EventArgs ev = new(Player, Scp330Bag, ICandy)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EatenScp330EventArgs))[0]),

// Handlers.Scp330.OnEatenScp330(ev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// bag
new CodeInstruction(OpCodes.Ldloca_S, 3),

// ServerProcessPickup(ReferenceHub, CandyKindID, Scp330Bag)
// ServerProcessPickup(ReferenceHub, CandyKindID, ref Scp330Bag)
new CodeInstruction(OpCodes.Call, Method(typeof(InteractingScp330), nameof(ServerProcessPickup), new[] { typeof(ReferenceHub), typeof(CandyKindID), typeof(Scp330Bag).MakeByRefType() })),
});

Expand Down

0 comments on commit c78b733

Please sign in to comment.