Skip to content

Commit e39238e

Browse files
IScp330Event (#11)
Co-authored-by: Misaka-ZeroTwo <45165615+Misaka-ZeroTwo@users.noreply.github.com>
1 parent 3ffe156 commit e39238e

8 files changed

Lines changed: 74 additions & 17 deletions

File tree

EXILED/Exiled.Events/EventArgs/Interfaces/IHazardEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Exiled.Events.EventArgs.Interfaces
1010
using Exiled.API.Features.Hazards;
1111

1212
/// <summary>
13-
/// Event args for all <see cref="Hazard"/> related events.
13+
/// Event args for all <see cref="API.Features.Hazards.Hazard"/> related events.
1414
/// </summary>
1515
public interface IHazardEvent : IExiledEvent
1616
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="IScp330Event.cs" company="Exiled Team">
3+
// Copyright (c) Exiled Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.Events.EventArgs.Interfaces
9+
{
10+
using Exiled.API.Features.Items;
11+
12+
/// <summary>
13+
/// Event args used for all <see cref="API.Features.Items.Scp330" /> related events.
14+
/// </summary>
15+
public interface IScp330Event : IItemEvent
16+
{
17+
/// <summary>
18+
/// Gets the <see cref="API.Features.Items.Scp330" /> triggering the event.
19+
/// </summary>
20+
public Scp330 Scp330 { get; }
21+
}
22+
}

EXILED/Exiled.Events/EventArgs/Interfaces/IUsableEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace Exiled.Events.EventArgs.Interfaces
1010
using Exiled.API.Features.Items;
1111

1212
/// <summary>
13-
/// Event args used for all <see cref="Usable" /> related events.
13+
/// Event args used for all <see cref="API.Features.Items.Usable" /> related events.
1414
/// </summary>
1515
public interface IUsableEvent : IItemEvent
1616
{
1717
/// <summary>
18-
/// Gets the <see cref="Usable" /> triggering the event.
18+
/// Gets the <see cref="API.Features.Items.Usable" /> triggering the event.
1919
/// </summary>
2020
public Usable Usable { get; }
2121
}

EXILED/Exiled.Events/EventArgs/Scp330/DroppingScp330EventArgs.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Exiled.Events.EventArgs.Scp330
1717
/// <summary>
1818
/// Contains all information before a player drops a SCP-330 candy.
1919
/// </summary>
20-
public class DroppingScp330EventArgs : IPlayerEvent, IDeniableEvent
20+
public class DroppingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
2121
{
2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="DroppingScp330EventArgs" /> class.
@@ -39,9 +39,12 @@ public DroppingScp330EventArgs(Player player, Scp330Bag scp330, CandyKindID cand
3939
}
4040

4141
/// <summary>
42-
/// Gets or sets a value representing the <see cref="Item" /> being picked up.
42+
/// Gets or sets a value representing the <see cref="API.Features.Items.Item" /> being picked up.
4343
/// </summary>
44-
public Scp330 Scp330 { get; set; }
44+
public Scp330 Scp330 { get; set; } // Todo Remove set
45+
46+
/// <inheritdoc/>
47+
public Item Item => Scp330;
4548

4649
/// <summary>
4750
/// Gets or sets a value indicating whether or not the type of candy drop.

EXILED/Exiled.Events/EventArgs/Scp330/EatenScp330EventArgs.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88
namespace Exiled.Events.EventArgs.Scp330
99
{
1010
using API.Features;
11-
11+
using Exiled.API.Features.Items;
1212
using Interfaces;
1313

1414
using InventorySystem.Items.Usables.Scp330;
1515

1616
/// <summary>
1717
/// Contains all information after a player has eaten SCP-330.
1818
/// </summary>
19-
public class EatenScp330EventArgs : IPlayerEvent
19+
public class EatenScp330EventArgs : IPlayerEvent, IScp330Event
2020
{
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="EatenScp330EventArgs" /> class.
2323
/// </summary>
2424
/// <param name="player"><inheritdoc cref="Player" />.</param>
25+
/// <param name="scp330"><inheritdoc cref="Scp330" />.</param>
2526
/// <param name="candy"><inheritdoc cref="Candy" />.</param>
26-
public EatenScp330EventArgs(Player player, ICandy candy)
27+
public EatenScp330EventArgs(Player player, Scp330Bag scp330, ICandy candy)
2728
{
2829
Player = player;
30+
Scp330 = (Scp330)Item.Get(scp330);
2931
Candy = candy;
3032
}
3133

@@ -38,5 +40,11 @@ public EatenScp330EventArgs(Player player, ICandy candy)
3840
/// Gets the player who has eaten SCP-330.
3941
/// </summary>
4042
public Player Player { get; }
43+
44+
/// <inheritdoc/>
45+
public Scp330 Scp330 { get; }
46+
47+
/// <inheritdoc/>
48+
public Item Item => Scp330;
4149
}
4250
}

EXILED/Exiled.Events/EventArgs/Scp330/EatingScp330EventArgs.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88
namespace Exiled.Events.EventArgs.Scp330
99
{
1010
using API.Features;
11-
11+
using Exiled.API.Features.Items;
1212
using Interfaces;
1313

1414
using InventorySystem.Items.Usables.Scp330;
1515

1616
/// <summary>
1717
/// Contains all information before a player eats SCP-330.
1818
/// </summary>
19-
public class EatingScp330EventArgs : IPlayerEvent, IDeniableEvent
19+
public class EatingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
2020
{
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="EatingScp330EventArgs" /> class.
2323
/// </summary>
2424
/// <param name="player"><see cref="Player" />.</param>
25-
/// <param name="candy"><see cref="ICandy" />.</param>
25+
/// <param name="scp330"><inheritdoc cref="Scp330" />.</param>
26+
/// <param name="candy"><see cref="Candy" />.</param>
2627
/// <param name="isAllowed"><see cref="IsAllowed" />.</param>
27-
public EatingScp330EventArgs(Player player, ICandy candy, bool isAllowed = true)
28+
public EatingScp330EventArgs(Player player, Scp330Bag scp330, ICandy candy, bool isAllowed = true)
2829
{
2930
Player = player;
31+
Scp330 = (Scp330)Item.Get(scp330);
3032
Candy = candy;
3133
IsAllowed = isAllowed;
3234
}
@@ -45,5 +47,11 @@ public EatingScp330EventArgs(Player player, ICandy candy, bool isAllowed = true)
4547
/// Gets the player who's eating SCP-330.
4648
/// </summary>
4749
public Player Player { get; }
50+
51+
/// <inheritdoc/>
52+
public Scp330 Scp330 { get; }
53+
54+
/// <inheritdoc/>
55+
public Item Item => Scp330;
4856
}
4957
}

EXILED/Exiled.Events/EventArgs/Scp330/InteractingScp330EventArgs.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
namespace Exiled.Events.EventArgs.Scp330
99
{
1010
using API.Features;
11-
11+
using Exiled.API.Features.Items;
1212
using Interfaces;
1313

1414
using InventorySystem.Items.Usables.Scp330;
15+
using YamlDotNet.Core.Tokens;
1516

1617
/// <summary>
1718
/// Contains all information before a player interacts with SCP-330.
1819
/// </summary>
19-
public class InteractingScp330EventArgs : IPlayerEvent, IDeniableEvent
20+
public class InteractingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEvent
2021
{
2122
/// <summary>
2223
/// Initializes a new instance of the <see cref="InteractingScp330EventArgs" /> class.
@@ -30,6 +31,7 @@ public class InteractingScp330EventArgs : IPlayerEvent, IDeniableEvent
3031
public InteractingScp330EventArgs(Player player, int usage)
3132
{
3233
Player = player;
34+
Scp330 = Scp330Bag.TryGetBag(player.ReferenceHub, out Scp330Bag scp330Bag) ? (Scp330)Item.Get(scp330Bag) : null;
3335
Candy = Scp330Candies.GetRandom();
3436
UsageCount = usage;
3537
ShouldSever = usage >= 2;
@@ -60,5 +62,13 @@ public InteractingScp330EventArgs(Player player, int usage)
6062
/// Gets the <see cref="API.Features.Player" /> triggering the event.
6163
/// </summary>
6264
public Player Player { get; }
65+
66+
/// <inheritdoc/>
67+
/// <remarks>This value can be null.</remarks>
68+
public Scp330 Scp330 { get; }
69+
70+
/// <inheritdoc/>
71+
/// <remarks>This value can be null.</remarks>
72+
public Item Item => Scp330;
6373
}
6474
}

EXILED/Exiled.Events/Patches/Events/Scp330/EatingScp330.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
5151
new(OpCodes.Callvirt, PropertyGetter(typeof(Scp330Bag), nameof(Scp330Bag.Owner))),
5252
new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
5353

54+
// this
55+
new(OpCodes.Ldarg_0),
56+
5457
// ICandy
5558
new(OpCodes.Ldloc_0),
5659

5760
// true
5861
new(OpCodes.Ldc_I4_1),
5962

60-
// EatingScp330EventArgs ev = new(player, candy, true)
63+
// EatingScp330EventArgs ev = new(Player, Scp330Bag, ICandy, bool)
6164
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EatingScp330EventArgs))[0]),
6265
new(OpCodes.Dup),
6366

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

90+
// this
91+
new(OpCodes.Ldarg_0),
92+
8793
// ICandy
8894
new(OpCodes.Ldloc_0),
8995

90-
// EatenScp330EventArgs ev = new(player, candy)
96+
// EatenScp330EventArgs ev = new(Player, Scp330Bag, ICandy)
9197
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(EatenScp330EventArgs))[0]),
9298

9399
// Handlers.Scp330.OnEatenScp330(ev)

0 commit comments

Comments
 (0)