Skip to content

Commit e236106

Browse files
authored
feat: spawning grenade effect event (#828)
* feat: spawning grenade effect event * fix: respect DynamicPatching * fix: position change
1 parent dcf9fb3 commit e236106

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="SpawningGrenadeEffectEventArgs.cs" company="ExMod Team">
3+
// Copyright (c) ExMod Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.Events.EventArgs.Map
9+
{
10+
using Exiled.API.Features.Pickups;
11+
using Exiled.API.Features.Pickups.Projectiles;
12+
using Exiled.Events.EventArgs.Interfaces;
13+
14+
using UnityEngine;
15+
16+
/// <summary>
17+
/// Contains all information before grenade explosion effect is spawned.
18+
/// </summary>
19+
public class SpawningGrenadeEffectEventArgs : IPickupEvent, IDeniableEvent
20+
{
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="SpawningGrenadeEffectEventArgs"/> class.
23+
/// </summary>
24+
/// <param name="effectGrenade"><inheritdoc cref="Projectile"/></param>
25+
/// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
26+
public SpawningGrenadeEffectEventArgs(TimeGrenadeProjectile effectGrenade, bool isAllowed = false)
27+
{
28+
Projectile = effectGrenade;
29+
Position = effectGrenade.Position;
30+
IsAllowed = isAllowed;
31+
}
32+
33+
/// <summary>
34+
/// Gets or sets a position of this effect.
35+
/// </summary>
36+
public Vector3 Position { get; set; }
37+
38+
/// <inheritdoc/>
39+
public bool IsAllowed { get; set; }
40+
41+
/// <inheritdoc/>
42+
public Pickup Pickup => Projectile;
43+
44+
/// <summary>
45+
/// Gets the projectile that is exploding.
46+
/// </summary>
47+
public TimeGrenadeProjectile Projectile { get; }
48+
}
49+
}

EXILED/Exiled.Events/Events.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public override void OnEnabled()
9898
LabApi.Events.Handlers.Scp127Events.GainingExperience += Handlers.Scp127.OnGainingExperience;
9999
LabApi.Events.Handlers.Scp127Events.GainExperience += Handlers.Scp127.OnGainedExperience;
100100

101+
LabApi.Events.Handlers.ServerEvents.ProjectileExploding += Handlers.Map.OnSpawningGrenadeEffect;
102+
101103
ServerConsole.ReloadServerName();
102104
}
103105

@@ -140,6 +142,8 @@ public override void OnDisabled()
140142
LabApi.Events.Handlers.Scp127Events.Talked -= Handlers.Scp127.OnTalked;
141143
LabApi.Events.Handlers.Scp127Events.GainingExperience -= Handlers.Scp127.OnGainingExperience;
142144
LabApi.Events.Handlers.Scp127Events.GainExperience -= Handlers.Scp127.OnGainedExperience;
145+
146+
LabApi.Events.Handlers.ServerEvents.ProjectileExploding -= Handlers.Map.OnSpawningGrenadeEffect;
143147
}
144148

145149
/// <summary>

EXILED/Exiled.Events/Handlers/Map.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Exiled.Events.Handlers
1010
#pragma warning disable SA1623 // Property summary documentation should match accessors
1111

1212
using Exiled.API.Features.Pickups;
13+
using Exiled.API.Features.Pickups.Projectiles;
1314
using Exiled.Events.EventArgs.Map;
1415
using Exiled.Events.Features;
1516

@@ -130,6 +131,11 @@ public static class Map
130131
/// </summary>
131132
public static Event<GeneratingEventArgs> Generating { get; set; } = new();
132133

134+
/// <summary>
135+
/// Invoked before grenade explosion effect is spawned.
136+
/// </summary>
137+
public static Event<SpawningGrenadeEffectEventArgs> SpawningGrenadeEffect { get; set; } = new();
138+
133139
/// <summary>
134140
/// Called before placing a decal.
135141
/// </summary>
@@ -260,5 +266,21 @@ public static class Map
260266
/// </summary>
261267
/// <param name="ev">The <see cref="GeneratingEventArgs"/> instnace.</param>
262268
public static void OnGenerating(GeneratingEventArgs ev) => Generating.InvokeSafely(ev);
269+
270+
/// <summary>
271+
/// Called before grenade explosion effect is spawned.
272+
/// </summary>
273+
/// <param name="ev">The <see cref="LabApi.Events.Arguments.ServerEvents.ProjectileExplodingEventArgs"/> instance.</param>
274+
public static void OnSpawningGrenadeEffect(LabApi.Events.Arguments.ServerEvents.ProjectileExplodingEventArgs ev)
275+
{
276+
if (!SpawningGrenadeEffect.Patched)
277+
return;
278+
279+
SpawningGrenadeEffectEventArgs exiledEv = new(Pickup.Get<TimeGrenadeProjectile>(ev.TimedGrenade.Base), true);
280+
SpawningGrenadeEffect.InvokeSafely(exiledEv);
281+
282+
ev.Position = exiledEv.Position;
283+
ev.IsAllowed = exiledEv.IsAllowed;
284+
}
263285
}
264286
}

0 commit comments

Comments
 (0)