Skip to content
Merged
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
17 changes: 17 additions & 0 deletions EXILED/Exiled.API/Extensions/RoleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Exiled.API.Extensions

using Enums;
using Exiled.API.Features.Spawn;
using Footprinting;
using InventorySystem;
using InventorySystem.Configs;
using PlayerRoles;
Expand All @@ -27,6 +28,22 @@ namespace Exiled.API.Extensions
/// </summary>
public static class RoleExtensions
{
/// <summary>
/// Compares LifeIdentifier.
/// </summary>
/// <param name="footprint">The footprint to compare.</param>
/// <param name="other">The other footprint.</param>
/// <returns>If LifeIdentifier is the same (same role).</returns>
public static bool CompareLife(this Footprint footprint, Footprint other) => footprint.LifeIdentifier == other.LifeIdentifier;

/// <summary>
/// Compares LifeIdentifier.
/// </summary>
/// <param name="footprint">The footprint to compare.</param>
/// <param name="other">The hub to compare to.</param>
/// <returns>If LifeIdentifier is the same (same role).</returns>
public static bool CompareLife(this Footprint footprint, ReferenceHub other) => footprint.LifeIdentifier == other.roleManager.CurrentRole.UniqueLifeIdentifier;

/// <summary>
/// Gets a <see cref="RoleTypeId">role's</see> <see cref="Color"/>.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions EXILED/Exiled.API/Features/Roles/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ protected Role(PlayerRoleBase baseRole)
/// </summary>
public bool IsValid => Owner != null && Owner.IsConnected && Base == Owner.RoleManager.CurrentRole;

/// <summary>
/// Gets the life identifier for the role.
/// </summary>
public int LifeIdentifier => Base.UniqueLifeIdentifier;

/// <summary>
/// Gets a random spawn position of this role.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions EXILED/Exiled.Events/Patches/Events/Map/ExplodingFlashGrenade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Exiled.Events.Patches.Events.Map

using API.Features;
using API.Features.Pools;
using Exiled.API.Extensions;
using Exiled.Events.EventArgs.Map;
using Exiled.Events.Patches.Generic;
using Footprinting;
Expand Down Expand Up @@ -63,14 +64,13 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
private static void ProcessEvent(FlashbangGrenade instance, float distance)
{
List<Player> targetToAffect = ListPool<Player>.Pool.Get();
foreach (ReferenceHub referenceHub in ReferenceHub.AllHubs)
foreach (Player player in Player.List)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is technically better since we call Player.Get() immediately after

{
Player player = Player.Get(referenceHub);
if ((instance.transform.position - referenceHub.transform.position).sqrMagnitude >= distance)
if ((instance.transform.position - player.Position).sqrMagnitude >= distance)
continue;
if (!ExiledEvents.Instance.Config.CanFlashbangsAffectThrower && instance.PreviousOwner.LifeIdentifier != new Footprint(referenceHub).LifeIdentifier)
if (!ExiledEvents.Instance.Config.CanFlashbangsAffectThrower && instance.PreviousOwner.CompareLife(player.ReferenceHub))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes flashbangs

continue;
if (!IndividualFriendlyFire.CheckFriendlyFirePlayer(instance.PreviousOwner, player.ReferenceHub) && instance.PreviousOwner.LifeIdentifier != new Footprint(referenceHub).LifeIdentifier)
if (!IndividualFriendlyFire.CheckFriendlyFirePlayer(instance.PreviousOwner, player.ReferenceHub) && !instance.PreviousOwner.CompareLife(player.ReferenceHub))
continue;
if (Physics.Linecast(instance.transform.position, player.CameraTransform.position, instance._blindingMask))
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.Events.Patches.Generic
{
using Exiled.API.Extensions;

#pragma warning disable SA1402
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -96,8 +98,7 @@ public static bool CheckFriendlyFirePlayerRules(Footprint attackerFootprint, Ref
return true;

// Only check friendlyFire if the FootPrint hasn't changed (Fix for Grenade not dealing damage because it's from a dead player)
// TODO rework FriendlyFireRule to make it compatible with Footprint
if (!attackerFootprint.Equals(new Footprint(attackerFootprint.Hub)))
if (!attackerFootprint.CompareLife(new Footprint(attackerFootprint.Hub)))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes grenades

return false;

// Check if attackerFootprint.Hub or victimHub is null and log debug information
Expand Down