Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making TargetsToAffect a Hashset #123

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG
Player = Player.Get(thrower.Hub);
Projectile = Pickup.Get<EffectGrenadeProjectile>(grenade);
Position = position;
TargetsToAffect = ListPool<Player>.Pool.Get();
TargetsToAffect = HashSetPool<Player>.Pool.Get();

if (Projectile.Base is not ExplosionGrenade)
return;
Expand All @@ -59,8 +59,7 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG
{
if (Server.FriendlyFire || IndividualFriendlyFire.CheckFriendlyFirePlayer(thrower, hub))
{
if (!TargetsToAffect.Contains(player))
TargetsToAffect.Add(player);
TargetsToAffect.Add(player);
}
}

Expand All @@ -69,8 +68,7 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG
{
if (Server.FriendlyFire || thrower.Hub == Server.Host.ReferenceHub || HitboxIdentity.IsEnemy(thrower.Role, hub.roleManager.CurrentRole.RoleTypeId))
{
if (!TargetsToAffect.Contains(player))
TargetsToAffect.Add(player);
TargetsToAffect.Add(player);
}
}

Expand All @@ -94,12 +92,12 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG
/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, List<Player> targetsToAffect, bool isAllowed = true)
public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, HashSet<Player> targetsToAffect, bool isAllowed = true)
{
Player = thrower ?? Server.Host;
Projectile = Pickup.Get<EffectGrenadeProjectile>(grenade);
Position = Projectile.Position;
TargetsToAffect = ListPool<Player>.Pool.Get(targetsToAffect ?? new());
TargetsToAffect = HashSetPool<Player>.Pool.Get(targetsToAffect ?? new HashSet<Player>());
IsAllowed = isAllowed;
}

Expand All @@ -108,7 +106,7 @@ public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, List<Pla
/// </summary>
~ExplodingGrenadeEventArgs()
{
ListPool<Player>.Pool.Return(TargetsToAffect);
HashSetPool<Player>.Pool.Return(TargetsToAffect);
}

/// <summary>
Expand All @@ -119,7 +117,7 @@ public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, List<Pla
/// <summary>
/// Gets the players who could be affected by the grenade, if any, and the damage that be dealt.
/// </summary>
public List<Player> TargetsToAffect { get; }
public HashSet<Player> TargetsToAffect { get; }

/// <summary>
/// Gets the grenade that is exploding.
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.Events/Patches/Events/Map/BreakingScp2176.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// true
new(OpCodes.Ldc_I4_1),

// new ExplodingGrenadeEventArgs(Player, EffectGrenade, List<Player>, bool)
new(OpCodes.Newobj, DeclaredConstructor(typeof(ExplodingGrenadeEventArgs), new[] { typeof(Player), typeof(EffectGrenade), typeof(List<Player>), typeof(bool) })),
// new ExplodingGrenadeEventArgs(Player, EffectGrenade, HashSet<Player>, bool)
new(OpCodes.Newobj, DeclaredConstructor(typeof(ExplodingGrenadeEventArgs), new[] { typeof(Player), typeof(EffectGrenade), typeof(HashSet<Player>), typeof(bool) })),
new(OpCodes.Dup),

// Handlers.Map.OnExplodingGrenade(ev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi

private static void ProcessEvent(FlashbangGrenade instance, float distance)
{
List<Player> targetToAffect = ListPool<Player>.Pool.Get();
HashSet<Player> targetToAffect = HashSetPool<Player>.Pool.Get();
foreach (ReferenceHub referenceHub in ReferenceHub.AllHubs)
{
Player player = Player.Get(referenceHub);
Expand All @@ -79,7 +79,7 @@ private static void ProcessEvent(FlashbangGrenade instance, float distance)

ExplodingGrenadeEventArgs explodingGrenadeEvent = new(Player.Get(instance.PreviousOwner.Hub), instance, targetToAffect);

ListPool<Player>.Pool.Return(targetToAffect);
HashSetPool<Player>.Pool.Return(targetToAffect);

Handlers.Map.OnExplodingGrenade(explodingGrenadeEvent);

Expand Down