Skip to content

Commit 955cb95

Browse files
committed
Merge branch 'master' into dev
2 parents 0b71c24 + 2884abf commit 955cb95

4 files changed

Lines changed: 69 additions & 115 deletions

File tree

EXILED/Exiled.API/Features/Player.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Exiled.API.Features
99
{
1010
using System;
1111
using System.Collections.Generic;
12+
using System.Diagnostics.CodeAnalysis;
1213
using System.Linq;
1314
using System.Reflection;
1415
using System.Runtime.CompilerServices;
@@ -4080,6 +4081,64 @@ public bool TryGetComponent<T>(Type type, out T component)
40804081
return component is not null;
40814082
}
40824083

4084+
/// <summary>
4085+
/// Tries to raycast.
4086+
/// </summary>
4087+
/// <param name="maxDistance">Maximum distance of raycast.</param>
4088+
/// <param name="layerMasks">Layer masks to be applied to raycast.</param>
4089+
/// <param name="hit">Calculated <see cref="RaycastHit"/> or <c>default</c>.</param>
4090+
/// <returns><c>true</c> if raycast was successful. Otherwise, <c>false</c>.</returns>
4091+
/// <seealso cref="TryGetRaycastedPlayer"/>
4092+
public bool TryGetRaycast(float maxDistance, LayerMasks layerMasks, out RaycastHit hit)
4093+
{
4094+
if (layerMasks.HasFlag(LayerMasks.Hitbox))
4095+
HitscanHitregModuleBase.ToggleColliders(ReferenceHub, false);
4096+
4097+
bool result = Physics.Raycast(CameraTransform.position, CameraTransform.forward, out hit, maxDistance, (int)layerMasks);
4098+
4099+
if (layerMasks.HasFlag(LayerMasks.Hitbox))
4100+
HitscanHitregModuleBase.ToggleColliders(ReferenceHub, true);
4101+
4102+
return result;
4103+
}
4104+
4105+
/// <summary>
4106+
/// Tries to get a <see cref="HitboxIdentity"/> from a raycast.
4107+
/// </summary>
4108+
/// <param name="maxDistance">Maximum distance of raycast.</param>
4109+
/// <param name="additionalMasks">Additional LayerMasks that should be applied to raycast. <see cref="LayerMasks.Hitbox"/> will be applied by default.</param>
4110+
/// <param name="hitboxIdentity">Found <see cref="HitboxIdentity"/> or <c>null</c>.</param>
4111+
/// <returns><c>true</c> if <paramref name="hitboxIdentity"/> was successfully found. Otherwise, <c>false</c>.</returns>
4112+
/// <seealso cref="TryGetRaycastedPlayer"/>
4113+
public bool TryGetRaycastedHitbox(float maxDistance, LayerMasks additionalMasks, [MaybeNullWhen(false)] out HitboxIdentity hitboxIdentity)
4114+
{
4115+
hitboxIdentity = null;
4116+
4117+
if (TryGetRaycast(maxDistance, LayerMasks.Hitbox | additionalMasks, out RaycastHit hit))
4118+
hitboxIdentity = hit.collider.gameObject.GetComponent<HitboxIdentity>();
4119+
4120+
return hitboxIdentity != null;
4121+
}
4122+
4123+
/// <summary>
4124+
/// Tries to get a <see cref="Player"/> from a raycast.
4125+
/// </summary>
4126+
/// <param name="maxDistance">Maximum distance of raycast.</param>
4127+
/// <param name="additionalMasks">Additional LayerMasks that should be applied to raycast. <see cref="LayerMasks.Hitbox"/> will be applied by default.</param>
4128+
/// <param name="target">Found <see cref="Player"/> or <c>null</c>.</param>
4129+
/// <returns><c>true</c> if <paramref name="target"/> was successfully found. Otherwise, <c>false</c>.</returns>
4130+
/// <seealso cref="TryGetRaycastedHitbox"/>
4131+
public bool TryGetRaycastedPlayer(float maxDistance, LayerMasks additionalMasks, [MaybeNullWhen(false)] out Player target)
4132+
{
4133+
target = null;
4134+
4135+
if (!TryGetRaycastedHitbox(maxDistance, additionalMasks, out HitboxIdentity hitboxIdentity))
4136+
return false;
4137+
4138+
target = Get(hitboxIdentity.TargetHub);
4139+
return target != null;
4140+
}
4141+
40834142
/// <inheritdoc/>
40844143
public bool HasComponent<T>(bool depthInheritance = false) => depthInheritance
40854144
? componentsInChildren.Any(comp => typeof(T).IsSubclassOf(comp.GetType()))

EXILED/Exiled.Events/EventArgs/Player/InteractingShootingTargetEventArgs.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ public int NewMaxHp
7474
set
7575
{
7676
if (!ShootingTarget.IsSynced)
77-
throw new InvalidOperationException("Attempted to set MaxHp while target is in local mode. Set target's IsSynced to true before setting IsAllowed.");
77+
{
78+
Log.Warn("Attempted to set MaxHp while target is in local mode. Set target's IsSynced to true before setting NewMaxHp.");
79+
return;
80+
}
81+
7882
field = Mathf.Clamp(value, 1, 256);
7983
}
8084
}
@@ -88,7 +92,11 @@ public int NewAutoResetTime
8892
set
8993
{
9094
if (!ShootingTarget.IsSynced)
91-
throw new InvalidOperationException("Attempted to set AutoResetTime while target is in local mode. Set target's IsSynced to true before setting IsAllowed.");
95+
{
96+
Log.Warn("Attempted to set AutoResetTime while target is in local mode. Set target's IsSynced to true before setting NewAutoResetTime.");
97+
return;
98+
}
99+
92100
field = Mathf.Clamp(value, 0, 10);
93101
}
94102
}

EXILED/Exiled.Events/Patches/Fixes/HurtingFix.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

EXILED/Exiled.Events/Patches/Fixes/Scp3114AttackAhpFix.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)