Skip to content

Commit

Permalink
Merge branch 'ExMod-Team:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
SnivyFilms authored Jan 11, 2025
2 parents 204fc2f + 5dc7ad5 commit 4617cdf
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 16 deletions.
63 changes: 63 additions & 0 deletions EXILED/Exiled.API/Enums/LockerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.API.Enums
{
using System;

/// <summary>
/// Unique identifier for different types of <see cref="Features.Lockers.Locker"/>s.
/// </summary>
Expand All @@ -15,6 +17,7 @@ public enum LockerType
/// <summary>
/// The pedestal used by SCP items.
/// </summary>
[Obsolete("This value is not used.")]
Pedestal,

/// <summary>
Expand Down Expand Up @@ -46,5 +49,65 @@ public enum LockerType
/// Unknow type of locker.
/// </summary>
Unknow,

/// <summary>
/// MircoHid pedestal.
/// </summary>
MicroHid,

/// <summary>
/// Experimental weapon locker.
/// </summary>
ExperimentalWeapon,

/// <summary>
/// SCP-500 pedestal.
/// </summary>
Scp500Pedestal,

/// <summary>
/// SCP-207? (Anti SCP-207) pedestal.
/// </summary>
AntiScp207Pedestal,

/// <summary>
/// SCP-207 pedestal.
/// </summary>
Scp207Pedestal,

/// <summary>
/// SCP-268 pedestal.
/// </summary>
Scp268Pedestal,

/// <summary>
/// SCP-1344 pedestal.
/// </summary>
Scp1344Pedestal,

/// <summary>
/// SCP-018 pedestal.
/// </summary>
Scp018Pedestal,

/// <summary>
/// SCP-1576 pedestal.
/// </summary>
Scp1576Pedestal,

/// <summary>
/// SCP-244 pedestal.
/// </summary>
Scp244Pedestal,

/// <summary>
/// SCP-2176 pedestal.
/// </summary>
Scp2176Pedestal,

/// <summary>
/// SCP-1853 pedestal.
/// </summary>
Scp1853Pedestal,
}
}
15 changes: 13 additions & 2 deletions EXILED/Exiled.API/Extensions/LockerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ public static class LockerExtensions
/// </summary>
/// <param name="name">The name to check.</param>
/// <returns>The corresponding <see cref="LockerType"/>.</returns>
public static LockerType GetLockerTypeByName(this string name) => name.Replace("(Clone)", string.Empty) switch
public static LockerType GetLockerTypeByName(this string name) => name.Split('(')[0].Trim() switch
{
"Scp500PedestalStructure Variant" => LockerType.Pedestal,
"Scp500PedestalStructure Variant" => LockerType.Scp500Pedestal,
"AntiScp207PedestalStructure Variant" => LockerType.AntiScp207Pedestal,
"Scp207PedestalStructure Variant" => LockerType.Scp207Pedestal,
"Experimental Weapon Locker" => LockerType.ExperimentalWeapon,
"Scp1344PedestalStructure Variant" => LockerType.Scp1344Pedestal,
"Scp1576PedestalStructure Variant" => LockerType.Scp1576Pedestal,
"Scp2176PedestalStructure Variant" => LockerType.Scp2176Pedestal,
"Scp1853PedestalStructure Variant" => LockerType.Scp1853Pedestal,
"Scp268PedestalStructure Variant" => LockerType.Scp268Pedestal,
"Scp244PedestalStructure Variant" => LockerType.Scp244Pedestal,
"Scp018PedestalStructure Variant" => LockerType.Scp018Pedestal,
"LargeGunLockerStructure" => LockerType.LargeGun,
"RifleRackStructure" => LockerType.RifleRack,
"MiscLocker" => LockerType.Misc,
"RegularMedkitStructure" => LockerType.Medkit,
"AdrenalineMedkitStructure" => LockerType.Adrenaline,
"MicroHIDpedestal" => LockerType.MicroHid,
_ => LockerType.Unknow,
};
}
Expand Down
11 changes: 9 additions & 2 deletions EXILED/Exiled.API/Features/Lockers/Locker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Vector3 RandomChamberPosition
Chamber randomChamber = Chambers.GetRandomValue();

// Determine if the chamber uses multiple spawn points and has at least one available spawn point.
if (randomChamber.UseMultipleSpawnpoints && randomChamber.Spawnpoints.Count() > 0)
if (randomChamber.UseMultipleSpawnpoints && randomChamber.Spawnpoints.Any())
{
// Return the position of a random spawn point within the chamber.
return randomChamber.Spawnpoints.GetRandomValue().position;
Expand All @@ -136,11 +136,18 @@ public Vector3 RandomChamberPosition
/// <returns>The <see cref="Locker"/> with the given <see cref="ZoneType"/> or <see langword="null"/> if not found.</returns>
public static IEnumerable<Locker> Get(ZoneType zoneType) => Get(room => room.Zone.HasFlag(zoneType));

/// <summary>
/// Gets an <see cref="IEnumerable{T}"/> of <see cref="Locker"/> given the specified <see cref="LockerType"/>.
/// </summary>
/// <param name="lockerType">The <see cref="LockerType"/> to search for.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satisfy the condition.</returns>
public static IEnumerable<Locker> Get(LockerType lockerType) => Get(x => x.Type == lockerType);

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Locker"/> filtered based on a predicate.
/// </summary>
/// <param name="predicate">The condition to satify.</param>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satify the condition.</returns>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Locker"/> which contains elements that satisfy the condition.</returns>
public static IEnumerable<Locker> Get(Func<Locker, bool> predicate) => List.Where(predicate);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static Npc Spawn(string name, RoleTypeId role = RoleTypeId.None, bool ign

Timing.CallDelayed(0.5f, () =>
{
npc.Role.Set(role, SpawnReason.RoundStart, position is null ? RoleSpawnFlags.All : RoleSpawnFlags.AssignInventory);
npc.Role.Set(role, SpawnReason.ForceClass, position is null ? RoleSpawnFlags.All : RoleSpawnFlags.AssignInventory);

if (position is not null)
npc.Position = position.Value;
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ private void OnInternalChangingNickname(ChangingNicknameEventArgs ev)

private void OnInternalSpawning(SpawningEventArgs ev)
{
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance)
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.NewRole == Role && Loader.Random.NextDouble() * 100 <= SpawnChance)
AddRole(ev.Player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item
{
Player = Player.Get(player);
Jailbird = (Jailbird)Item.Get(swingItem);
#pragma warning disable CS0618
IsAllowed = isAllowed;
#pragma warning restore CS0618
}

/// <summary>
Expand All @@ -47,8 +45,8 @@ public ChargingJailbirdEventArgs(ReferenceHub player, InventorySystem.Items.Item
public Item Item => Jailbird;

/// <summary>
/// Gets a value indicating whether the Jailbird can be charged.
/// Gets or sets a value indicating whether the Jailbird can be charged.
/// </summary>
public bool IsAllowed { get; }
public bool IsAllowed { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// -----------------------------------------------------------------------
// <copyright file="ElevatorSequencesUpdatedEventArgs.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Map
{
using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;
using Interactables.Interobjects;

/// <summary>
/// Contains all information after an elevator sequence is updated.
/// </summary>
public class ElevatorSequencesUpdatedEventArgs : IExiledEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ElevatorSequencesUpdatedEventArgs"/> class.
/// </summary>
/// <param name="elevatorChamber"><inheritdoc cref="ElevatorChamber"/></param>
/// <param name="sequence"><inheritdoc cref="ElevatorChamber.ElevatorSequence"/></param>
public ElevatorSequencesUpdatedEventArgs(ElevatorChamber elevatorChamber, ElevatorChamber.ElevatorSequence sequence)
{
Elevator = elevatorChamber;
Lift = Lift.Get(elevatorChamber);
Sequence = sequence;
}

/// <summary>
/// Gets the elevator chamber that triggered this event.
/// </summary>
public ElevatorChamber Elevator { get; }

/// <summary>
/// Gets the lift that triggered this event.
/// </summary>
public Lift Lift { get; }

/// <summary>
/// Gets the new sequence of the elevator.
/// </summary>
public ElevatorChamber.ElevatorSequence Sequence { get; }
}
}
17 changes: 16 additions & 1 deletion EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ namespace Exiled.Events.EventArgs.Map
/// </summary>
public class ExplodingGrenadeEventArgs : IPlayerEvent, IDeniableEvent
{
private ExplosionType explosionType;

/// <summary>
/// Initializes a new instance of the <see cref="ExplodingGrenadeEventArgs"/> class.
/// </summary>
/// <param name="thrower"><inheritdoc cref="Player"/></param>
/// <param name="position"><inheritdoc cref="Position"/></param>
/// <param name="grenade"><inheritdoc cref="Projectile"/></param>
/// <param name="targets"><inheritdoc cref="TargetsToAffect"/></param>
public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionGrenade grenade, Collider[] targets)
/// <param name="explosionType"><inheritdoc cref="ExplosionType"/></param>
public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionGrenade grenade, Collider[] targets, ExplosionType explosionType)
{
Player = Player.Get(thrower.Hub);
Projectile = Pickup.Get<EffectGrenadeProjectile>(grenade);
Position = position;
TargetsToAffect = HashSetPool<Player>.Pool.Get();
ExplosionType = explosionType;

if (Projectile.Base is not ExplosionGrenade)
return;
Expand Down Expand Up @@ -97,6 +101,7 @@ public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, HashSet<
Player = thrower ?? Server.Host;
Projectile = Pickup.Get<EffectGrenadeProjectile>(grenade);
Position = Projectile.Position;
ExplosionType = ExplosionType.Custom;
TargetsToAffect = HashSetPool<Player>.Pool.Get(targetsToAffect ?? new HashSet<Player>());
IsAllowed = isAllowed;
}
Expand All @@ -114,6 +119,16 @@ public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, HashSet<
/// </summary>
public Vector3 Position { get; }

/// <summary>
/// Gets or sets the Explosion type.
/// </summary>
/// <remarks>Explosion that are not from <see cref="ExplosionGrenadeProjectile"/> will return <see cref="ExplosionType.Custom"/> and can't be modified.</remarks>
public ExplosionType ExplosionType
{
get => explosionType;
set => explosionType = Projectile is ExplosionGrenadeProjectile ? value : ExplosionType.Custom;
}

/// <summary>
/// Gets the players who could be affected by the grenade, if any, and the damage that be dealt.
/// </summary>
Expand Down
15 changes: 13 additions & 2 deletions EXILED/Exiled.Events/Handlers/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static class Map
/// </summary>
public static Event<DecontaminatingEventArgs> Decontaminating { get; set; } = new();

/// <summary>
/// Invoked after an elevator sequence is updated.
/// </summary>
public static Event<ElevatorSequencesUpdatedEventArgs> ElevatorSequencesUpdated { get; set; } = new();

/// <summary>
/// Invoked before a grenade explodes.
/// </summary>
Expand Down Expand Up @@ -91,12 +96,12 @@ public static class Map
public static Event<TurningOffLightsEventArgs> TurningOffLights { get; set; } = new();

/// <summary>
/// Invoked after an pickup is spawned.
/// Invoked after a pickup is spawned.
/// </summary>
public static Event<PickupAddedEventArgs> PickupAdded { get; set; } = new();

/// <summary>
/// Invoked after an pickup is destroyed.
/// Invoked after a pickup is destroyed.
/// </summary>
public static Event<PickupDestroyedEventArgs> PickupDestroyed { get; set; } = new();

Expand Down Expand Up @@ -157,6 +162,12 @@ public static class Map
/// <param name="ev">The <see cref="DecontaminatingEventArgs"/> instance.</param>
public static void OnDecontaminating(DecontaminatingEventArgs ev) => Decontaminating.InvokeSafely(ev);

/// <summary>
/// Called after an elevator sequence is updated.
/// </summary>
/// <param name="ev">The <see cref="ElevatorSequencesUpdatedEventArgs"/> instance.</param>
public static void OnElevatorSequencesUpdated(ElevatorSequencesUpdatedEventArgs ev) => ElevatorSequencesUpdated.InvokeSafely(ev);

/// <summary>
/// Called before a grenade explodes.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion EXILED/Exiled.Events/Patches/Events/Item/JailbirdPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ private static bool HandleJailbird(JailbirdItem instance, JailbirdMessageType me
ChargingJailbirdEventArgs ev = new(instance.Owner, instance);

Item.OnChargingJailbird(ev);
return true;
if (ev.IsAllowed)
return true;

ev.Player.RemoveHeldItem(destroy: false);
ev.Player.AddItem(ev.Item);
return false;
}

default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// -----------------------------------------------------------------------
// <copyright file="ElevatorSequencesUpdated.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Events.Map
{
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Map;
using HarmonyLib;
using Interactables.Interobjects;

/// <summary>
/// Patches <see cref="ElevatorChamber.CurSequence" />'s setter.
/// Adds the <see cref="Handlers.Map.ElevatorSequencesUpdated" /> event.
/// </summary>
[EventPatch(typeof(Handlers.Map), nameof(Handlers.Map.ElevatorSequencesUpdated))]
[HarmonyPatch(typeof(ElevatorChamber), nameof(ElevatorChamber.CurSequence), MethodType.Setter)]
internal class ElevatorSequencesUpdated
{
#pragma warning disable SA1313
private static void Postfix(ElevatorChamber __instance)
#pragma warning restore SA1313
{
ElevatorSequencesUpdatedEventArgs ev = new(__instance, __instance.CurSequence);
Handlers.Map.OnElevatorSequencesUpdated(ev);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// Collider[]
new(OpCodes.Ldloc_3),

// ExplodingGrenadeEventArgs ev = new(player, position, grenade, colliders);
new(OpCodes.Newobj, DeclaredConstructor(typeof(ExplodingGrenadeEventArgs), new[] { typeof(Footprint), typeof(Vector3), typeof(ExplosionGrenade), typeof(Collider[]) })),
// explosionType
new(OpCodes.Ldarg_3),

// ExplodingGrenadeEventArgs ev = new(player, position, grenade, colliders, ExplosionType);
new(OpCodes.Newobj, DeclaredConstructor(typeof(ExplodingGrenadeEventArgs), new[] { typeof(Footprint), typeof(Vector3), typeof(ExplosionGrenade), typeof(Collider[]), typeof(ExplosionType) })),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Stloc, ev.LocalIndex),
Expand Down

0 comments on commit 4617cdf

Please sign in to comment.