Minor ReflectionSystem refactor (#37039)
* ReflectComponentLogicFix Added bool InRightPlace and updated relevant system * Using SlotFlags * edits * refactor * add missing relay --------- Co-authored-by: BIGZi0348 <svalker0348@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@ using Content.Shared.Atmos;
|
|||||||
using Content.Shared.Camera;
|
using Content.Shared.Camera;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
|
using Content.Shared.Projectiles;
|
||||||
|
using Content.Shared.Weapons.Ranged.Events;
|
||||||
|
|
||||||
namespace Content.Shared.Hands.EntitySystems;
|
namespace Content.Shared.Hands.EntitySystems;
|
||||||
|
|
||||||
@@ -15,6 +17,8 @@ public abstract partial class SharedHandsSystem
|
|||||||
|
|
||||||
// By-ref events.
|
// By-ref events.
|
||||||
SubscribeLocalEvent<HandsComponent, ExtinguishEvent>(RefRelayEvent);
|
SubscribeLocalEvent<HandsComponent, ExtinguishEvent>(RefRelayEvent);
|
||||||
|
SubscribeLocalEvent<HandsComponent, ProjectileReflectAttemptEvent>(RefRelayEvent);
|
||||||
|
SubscribeLocalEvent<HandsComponent, HitScanReflectAttemptEvent>(RefRelayEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RelayEvent<T>(Entity<HandsComponent> entity, ref T args) where T : EntityEventArgs
|
private void RelayEvent<T>(Entity<HandsComponent> entity, ref T args) where T : EntityEventArgs
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using Content.Shared.Movement.Events;
|
|||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.NameModifier.EntitySystems;
|
using Content.Shared.NameModifier.EntitySystems;
|
||||||
using Content.Shared.Overlays;
|
using Content.Shared.Overlays;
|
||||||
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Radio;
|
using Content.Shared.Radio;
|
||||||
using Content.Shared.Slippery;
|
using Content.Shared.Slippery;
|
||||||
using Content.Shared.Strip.Components;
|
using Content.Shared.Strip.Components;
|
||||||
@@ -56,6 +57,8 @@ public partial class InventorySystem
|
|||||||
SubscribeLocalEvent<InventoryComponent, GetSlowedOverSlipperyModifierEvent>(RefRelayInventoryEvent);
|
SubscribeLocalEvent<InventoryComponent, GetSlowedOverSlipperyModifierEvent>(RefRelayInventoryEvent);
|
||||||
SubscribeLocalEvent<InventoryComponent, ModifySlowOnDamageSpeedEvent>(RefRelayInventoryEvent);
|
SubscribeLocalEvent<InventoryComponent, ModifySlowOnDamageSpeedEvent>(RefRelayInventoryEvent);
|
||||||
SubscribeLocalEvent<InventoryComponent, ExtinguishEvent>(RefRelayInventoryEvent);
|
SubscribeLocalEvent<InventoryComponent, ExtinguishEvent>(RefRelayInventoryEvent);
|
||||||
|
SubscribeLocalEvent<InventoryComponent, ProjectileReflectAttemptEvent>(RefRelayInventoryEvent);
|
||||||
|
SubscribeLocalEvent<InventoryComponent, HitScanReflectAttemptEvent>(RefRelayInventoryEvent);
|
||||||
SubscribeLocalEvent<InventoryComponent, GetContrabandDetailsEvent>(RefRelayInventoryEvent);
|
SubscribeLocalEvent<InventoryComponent, GetContrabandDetailsEvent>(RefRelayInventoryEvent);
|
||||||
|
|
||||||
// Eye/vision events
|
// Eye/vision events
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Shared.Damage;
|
|||||||
using Content.Shared.DoAfter;
|
using Content.Shared.DoAfter;
|
||||||
using Content.Shared.Hands.EntitySystems;
|
using Content.Shared.Hands.EntitySystems;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Mobs.Components;
|
||||||
using Content.Shared.Throwing;
|
using Content.Shared.Throwing;
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
@@ -238,7 +239,10 @@ public sealed class ImpactEffectEvent : EntityEventArgs
|
|||||||
/// Raised when an entity is just about to be hit with a projectile but can reflect it
|
/// Raised when an entity is just about to be hit with a projectile but can reflect it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct ProjectileReflectAttemptEvent(EntityUid ProjUid, ProjectileComponent Component, bool Cancelled);
|
public record struct ProjectileReflectAttemptEvent(EntityUid ProjUid, ProjectileComponent Component, bool Cancelled) : IInventoryRelayEvent
|
||||||
|
{
|
||||||
|
SlotFlags IInventoryRelayEvent.TargetSlots => SlotFlags.WITHOUT_POCKET;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised when a projectile hits an entity
|
/// Raised when a projectile hits an entity
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Weapons.Reflect;
|
using Content.Shared.Weapons.Reflect;
|
||||||
|
|
||||||
namespace Content.Shared.Weapons.Ranged.Events;
|
namespace Content.Shared.Weapons.Ranged.Events;
|
||||||
@@ -8,4 +9,7 @@ namespace Content.Shared.Weapons.Ranged.Events;
|
|||||||
/// and changing <see cref="Direction"/> where shot will go next
|
/// and changing <see cref="Direction"/> where shot will go next
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct HitScanReflectAttemptEvent(EntityUid? Shooter, EntityUid SourceItem, ReflectType Reflective, Vector2 Direction, bool Reflected);
|
public record struct HitScanReflectAttemptEvent(EntityUid? Shooter, EntityUid SourceItem, ReflectType Reflective, Vector2 Direction, bool Reflected) : IInventoryRelayEvent
|
||||||
|
{
|
||||||
|
SlotFlags IInventoryRelayEvent.TargetSlots => SlotFlags.WITHOUT_POCKET;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using Content.Shared.Inventory;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Weapons.Reflect;
|
namespace Content.Shared.Weapons.Reflect;
|
||||||
|
|
||||||
@@ -13,23 +15,48 @@ public sealed partial class ReflectComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// What we reflect.
|
/// What we reflect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField]
|
[DataField]
|
||||||
public ReflectType Reflects = ReflectType.Energy | ReflectType.NonEnergy;
|
public ReflectType Reflects = ReflectType.Energy | ReflectType.NonEnergy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select in which inventory slots it will reflect.
|
||||||
|
/// By default, it will reflect in any inventory position, except pockets.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public SlotFlags SlotFlags = SlotFlags.WITHOUT_POCKET;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is it allowed to reflect while being in hands.
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool ReflectingInHands = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Can only reflect when placed correctly.
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool InRightPlace;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Probability for a projectile to be reflected.
|
/// Probability for a projectile to be reflected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public float ReflectProb = 0.25f;
|
public float ReflectProb = 0.25f;
|
||||||
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
/// <summary>
|
||||||
|
/// Probability for a projectile to be reflected.
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
public Angle Spread = Angle.FromDegrees(45);
|
public Angle Spread = Angle.FromDegrees(45);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sound to play when reflecting.
|
||||||
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public SoundSpecifier? SoundOnReflect = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg", AudioParams.Default.WithVariation(0.05f));
|
public SoundSpecifier? SoundOnReflect = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg", AudioParams.Default.WithVariation(0.05f));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags, Serializable, NetSerializable]
|
||||||
public enum ReflectType : byte
|
public enum ReflectType : byte
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|||||||
@@ -1,25 +1,20 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Shared.Administration.Logs;
|
using Content.Shared.Administration.Logs;
|
||||||
using Content.Shared.Alert;
|
|
||||||
using Content.Shared.Audio;
|
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Hands;
|
using Content.Shared.Hands;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
using Content.Shared.Inventory.Events;
|
using Content.Shared.Inventory.Events;
|
||||||
using Content.Shared.Item.ItemToggle;
|
using Content.Shared.Item.ItemToggle;
|
||||||
using Content.Shared.Item.ItemToggle.Components;
|
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Projectiles;
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Weapons.Ranged.Components;
|
using Content.Shared.Weapons.Ranged.Components;
|
||||||
using Content.Shared.Weapons.Ranged.Events;
|
using Content.Shared.Weapons.Ranged.Events;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
|
||||||
|
|
||||||
namespace Content.Shared.Weapons.Reflect;
|
namespace Content.Shared.Weapons.Reflect;
|
||||||
|
|
||||||
@@ -28,7 +23,6 @@ namespace Content.Shared.Weapons.Reflect;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ReflectSystem : EntitySystem
|
public sealed class ReflectSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
[Dependency] private readonly INetManager _netManager = default!;
|
[Dependency] private readonly INetManager _netManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||||
@@ -37,74 +31,82 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
Subs.SubscribeWithRelay<ReflectComponent, ProjectileReflectAttemptEvent>(OnReflectUserCollide, baseEvent: false);
|
||||||
|
Subs.SubscribeWithRelay<ReflectComponent, HitScanReflectAttemptEvent>(OnReflectUserHitscan, baseEvent: false);
|
||||||
SubscribeLocalEvent<ReflectComponent, ProjectileReflectAttemptEvent>(OnReflectCollide);
|
SubscribeLocalEvent<ReflectComponent, ProjectileReflectAttemptEvent>(OnReflectCollide);
|
||||||
SubscribeLocalEvent<ReflectComponent, HitScanReflectAttemptEvent>(OnReflectHitscan);
|
SubscribeLocalEvent<ReflectComponent, HitScanReflectAttemptEvent>(OnReflectHitscan);
|
||||||
|
|
||||||
SubscribeLocalEvent<ReflectComponent, GotEquippedEvent>(OnReflectEquipped);
|
SubscribeLocalEvent<ReflectComponent, GotEquippedEvent>(OnReflectEquipped);
|
||||||
SubscribeLocalEvent<ReflectComponent, GotUnequippedEvent>(OnReflectUnequipped);
|
SubscribeLocalEvent<ReflectComponent, GotUnequippedEvent>(OnReflectUnequipped);
|
||||||
SubscribeLocalEvent<ReflectComponent, GotEquippedHandEvent>(OnReflectHandEquipped);
|
SubscribeLocalEvent<ReflectComponent, GotEquippedHandEvent>(OnReflectHandEquipped);
|
||||||
SubscribeLocalEvent<ReflectComponent, GotUnequippedHandEvent>(OnReflectHandUnequipped);
|
SubscribeLocalEvent<ReflectComponent, GotUnequippedHandEvent>(OnReflectHandUnequipped);
|
||||||
SubscribeLocalEvent<ReflectComponent, ItemToggledEvent>(OnToggleReflect);
|
|
||||||
|
|
||||||
SubscribeLocalEvent<ReflectUserComponent, ProjectileReflectAttemptEvent>(OnReflectUserCollide);
|
|
||||||
SubscribeLocalEvent<ReflectUserComponent, HitScanReflectAttemptEvent>(OnReflectUserHitscan);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnReflectUserHitscan(EntityUid uid, ReflectUserComponent component, ref HitScanReflectAttemptEvent args)
|
private void OnReflectUserCollide(Entity<ReflectComponent> ent, ref ProjectileReflectAttemptEvent args)
|
||||||
{
|
|
||||||
if (args.Reflected)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var ent in _inventorySystem.GetHandOrInventoryEntities(uid, SlotFlags.All & ~SlotFlags.POCKET))
|
|
||||||
{
|
|
||||||
if (!TryReflectHitscan(uid, ent, args.Shooter, args.SourceItem, args.Direction, args.Reflective, out var dir))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
args.Direction = dir.Value;
|
|
||||||
args.Reflected = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnReflectUserCollide(EntityUid uid, ReflectUserComponent component, ref ProjectileReflectAttemptEvent args)
|
|
||||||
{
|
|
||||||
foreach (var ent in _inventorySystem.GetHandOrInventoryEntities(uid, SlotFlags.All & ~SlotFlags.POCKET))
|
|
||||||
{
|
|
||||||
if (!TryReflectProjectile(uid, ent, args.ProjUid))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
args.Cancelled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnReflectCollide(EntityUid uid, ReflectComponent component, ref ProjectileReflectAttemptEvent args)
|
|
||||||
{
|
{
|
||||||
if (args.Cancelled)
|
if (args.Cancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TryReflectProjectile(uid, uid, args.ProjUid, reflect: component))
|
if (!ent.Comp.InRightPlace)
|
||||||
|
return; // only reflect when equipped correctly
|
||||||
|
|
||||||
|
if (TryReflectProjectile(ent, ent.Owner, args.ProjUid))
|
||||||
args.Cancelled = true;
|
args.Cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryReflectProjectile(EntityUid user, EntityUid reflector, EntityUid projectile, ProjectileComponent? projectileComp = null, ReflectComponent? reflect = null)
|
private void OnReflectUserHitscan(Entity<ReflectComponent> ent, ref HitScanReflectAttemptEvent args)
|
||||||
{
|
{
|
||||||
if (!Resolve(reflector, ref reflect, false) ||
|
if (args.Reflected)
|
||||||
!TryComp<ReflectiveComponent>(projectile, out var reflective) ||
|
return;
|
||||||
(reflect.Reflects & reflective.Reflective) == 0x0 ||
|
|
||||||
!_toggle.IsActivated(reflector) ||
|
if (!ent.Comp.InRightPlace)
|
||||||
!_random.Prob(reflect.ReflectProb) ||
|
return; // only reflect when equipped correctly
|
||||||
|
|
||||||
|
if (TryReflectHitscan(ent, ent.Owner, args.Shooter, args.SourceItem, args.Direction, args.Reflective, out var dir))
|
||||||
|
{
|
||||||
|
args.Direction = dir.Value;
|
||||||
|
args.Reflected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReflectCollide(Entity<ReflectComponent> ent, ref ProjectileReflectAttemptEvent args)
|
||||||
|
{
|
||||||
|
if (args.Cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (TryReflectProjectile(ent, ent.Owner, args.ProjUid))
|
||||||
|
args.Cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReflectHitscan(Entity<ReflectComponent> ent, ref HitScanReflectAttemptEvent args)
|
||||||
|
{
|
||||||
|
if (args.Reflected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (TryReflectHitscan(ent, ent.Owner, args.Shooter, args.SourceItem, args.Direction, args.Reflective, out var dir))
|
||||||
|
{
|
||||||
|
args.Direction = dir.Value;
|
||||||
|
args.Reflected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryReflectProjectile(Entity<ReflectComponent> reflector, EntityUid user, Entity<ProjectileComponent?> projectile)
|
||||||
|
{
|
||||||
|
if (!TryComp<ReflectiveComponent>(projectile, out var reflective) ||
|
||||||
|
(reflector.Comp.Reflects & reflective.Reflective) == 0x0 ||
|
||||||
|
!_toggle.IsActivated(reflector.Owner) ||
|
||||||
|
!_random.Prob(reflector.Comp.ReflectProb) ||
|
||||||
!TryComp<PhysicsComponent>(projectile, out var physics))
|
!TryComp<PhysicsComponent>(projectile, out var physics))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rotation = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2).Opposite();
|
var rotation = _random.NextAngle(-reflector.Comp.Spread / 2, reflector.Comp.Spread / 2).Opposite();
|
||||||
var existingVelocity = _physics.GetMapLinearVelocity(projectile, component: physics);
|
var existingVelocity = _physics.GetMapLinearVelocity(projectile, component: physics);
|
||||||
var relativeVelocity = existingVelocity - _physics.GetMapLinearVelocity(user);
|
var relativeVelocity = existingVelocity - _physics.GetMapLinearVelocity(user);
|
||||||
var newVelocity = rotation.RotateVec(relativeVelocity);
|
var newVelocity = rotation.RotateVec(relativeVelocity);
|
||||||
@@ -118,15 +120,15 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
var newRot = rotation.RotateVec(locRot.ToVec());
|
var newRot = rotation.RotateVec(locRot.ToVec());
|
||||||
_transform.SetLocalRotation(projectile, newRot.ToAngle());
|
_transform.SetLocalRotation(projectile, newRot.ToAngle());
|
||||||
|
|
||||||
PlayAudioAndPopup(reflect, user);
|
PlayAudioAndPopup(reflector.Comp, user);
|
||||||
|
|
||||||
if (Resolve(projectile, ref projectileComp, false))
|
if (Resolve(projectile, ref projectile.Comp, false))
|
||||||
{
|
{
|
||||||
_adminLogger.Add(LogType.BulletHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected {ToPrettyString(projectile)} from {ToPrettyString(projectileComp.Weapon)} shot by {projectileComp.Shooter}");
|
_adminLogger.Add(LogType.BulletHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected {ToPrettyString(projectile)} from {ToPrettyString(projectile.Comp.Weapon)} shot by {projectile.Comp.Shooter}");
|
||||||
|
|
||||||
projectileComp.Shooter = user;
|
projectile.Comp.Shooter = user;
|
||||||
projectileComp.Weapon = user;
|
projectile.Comp.Weapon = user;
|
||||||
Dirty(projectile, projectileComp);
|
Dirty(projectile, projectile.Comp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -135,19 +137,34 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
private bool TryReflectHitscan(
|
||||||
private void OnReflectHitscan(EntityUid uid, ReflectComponent component, ref HitScanReflectAttemptEvent args)
|
Entity<ReflectComponent> reflector,
|
||||||
|
EntityUid user,
|
||||||
|
EntityUid? shooter,
|
||||||
|
EntityUid shotSource,
|
||||||
|
Vector2 direction,
|
||||||
|
ReflectType hitscanReflectType,
|
||||||
|
[NotNullWhen(true)] out Vector2? newDirection)
|
||||||
{
|
{
|
||||||
if (args.Reflected)
|
if ((reflector.Comp.Reflects & hitscanReflectType) == 0x0 ||
|
||||||
|
!_toggle.IsActivated(reflector.Owner) ||
|
||||||
|
!_random.Prob(reflector.Comp.ReflectProb))
|
||||||
{
|
{
|
||||||
return;
|
newDirection = null;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TryReflectHitscan(uid, uid, args.Shooter, args.SourceItem, args.Direction, args.Reflective, out var dir))
|
PlayAudioAndPopup(reflector.Comp, user);
|
||||||
{
|
|
||||||
args.Direction = dir.Value;
|
var spread = _random.NextAngle(-reflector.Comp.Spread / 2, reflector.Comp.Spread / 2);
|
||||||
args.Reflected = true;
|
newDirection = -spread.RotateVec(direction);
|
||||||
}
|
|
||||||
|
if (shooter != null)
|
||||||
|
_adminLogger.Add(LogType.HitScanHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)} shot by {ToPrettyString(shooter.Value)}");
|
||||||
|
else
|
||||||
|
_adminLogger.Add(LogType.HitScanHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)}");
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayAudioAndPopup(ReflectComponent reflect, EntityUid user)
|
private void PlayAudioAndPopup(ReflectComponent reflect, EntityUid user)
|
||||||
@@ -160,83 +177,27 @@ public sealed class ReflectSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryReflectHitscan(
|
private void OnReflectEquipped(Entity<ReflectComponent> ent, ref GotEquippedEvent args)
|
||||||
EntityUid user,
|
|
||||||
EntityUid reflector,
|
|
||||||
EntityUid? shooter,
|
|
||||||
EntityUid shotSource,
|
|
||||||
Vector2 direction,
|
|
||||||
ReflectType hitscanReflectType,
|
|
||||||
[NotNullWhen(true)] out Vector2? newDirection)
|
|
||||||
{
|
{
|
||||||
if (!TryComp<ReflectComponent>(reflector, out var reflect) ||
|
ent.Comp.InRightPlace = (ent.Comp.SlotFlags & args.SlotFlags) == args.SlotFlags;
|
||||||
(reflect.Reflects & hitscanReflectType) == 0x0 ||
|
Dirty(ent);
|
||||||
!_toggle.IsActivated(reflector) ||
|
|
||||||
!_random.Prob(reflect.ReflectProb))
|
|
||||||
{
|
|
||||||
newDirection = null;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayAudioAndPopup(reflect, user);
|
private void OnReflectUnequipped(Entity<ReflectComponent> ent, ref GotUnequippedEvent args)
|
||||||
|
{
|
||||||
var spread = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2);
|
ent.Comp.InRightPlace = false;
|
||||||
newDirection = -spread.RotateVec(direction);
|
Dirty(ent);
|
||||||
|
|
||||||
if (shooter != null)
|
|
||||||
_adminLogger.Add(LogType.HitScanHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)} shot by {ToPrettyString(shooter.Value)}");
|
|
||||||
else
|
|
||||||
_adminLogger.Add(LogType.HitScanHit, LogImpact.Medium, $"{ToPrettyString(user)} reflected hitscan from {ToPrettyString(shotSource)}");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnReflectEquipped(EntityUid uid, ReflectComponent component, GotEquippedEvent args)
|
private void OnReflectHandEquipped(Entity<ReflectComponent> ent, ref GotEquippedHandEvent args)
|
||||||
{
|
{
|
||||||
if (_gameTiming.ApplyingState)
|
ent.Comp.InRightPlace = ent.Comp.ReflectingInHands;
|
||||||
return;
|
Dirty(ent);
|
||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(args.Equipee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnReflectUnequipped(EntityUid uid, ReflectComponent comp, GotUnequippedEvent args)
|
private void OnReflectHandUnequipped(Entity<ReflectComponent> ent, ref GotUnequippedHandEvent args)
|
||||||
{
|
{
|
||||||
RefreshReflectUser(args.Equipee);
|
ent.Comp.InRightPlace = false;
|
||||||
}
|
Dirty(ent);
|
||||||
|
|
||||||
private void OnReflectHandEquipped(EntityUid uid, ReflectComponent component, GotEquippedHandEvent args)
|
|
||||||
{
|
|
||||||
if (_gameTiming.ApplyingState)
|
|
||||||
return;
|
|
||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(args.User);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnReflectHandUnequipped(EntityUid uid, ReflectComponent component, GotUnequippedHandEvent args)
|
|
||||||
{
|
|
||||||
RefreshReflectUser(args.User);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnToggleReflect(EntityUid uid, ReflectComponent comp, ref ItemToggledEvent args)
|
|
||||||
{
|
|
||||||
if (args.User is {} user)
|
|
||||||
RefreshReflectUser(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Refreshes whether someone has reflection potential so we can raise directed events on them.
|
|
||||||
/// </summary>
|
|
||||||
private void RefreshReflectUser(EntityUid user)
|
|
||||||
{
|
|
||||||
foreach (var ent in _inventorySystem.GetHandOrInventoryEntities(user, SlotFlags.All & ~SlotFlags.POCKET))
|
|
||||||
{
|
|
||||||
if (!HasComp<ReflectComponent>(ent) || !_toggle.IsActivated(ent))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
EnsureComp<ReflectUserComponent>(user);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RemCompDeferred<ReflectUserComponent>(user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
using Robust.Shared.GameStates;
|
|
||||||
|
|
||||||
namespace Content.Shared.Weapons.Reflect;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Added to an entity if it equips a reflection item in a hand slot or into its clothing.
|
|
||||||
/// Reflection events will then be relayed.
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent, NetworkedComponent]
|
|
||||||
public sealed partial class ReflectUserComponent : Component;
|
|
||||||
@@ -83,6 +83,7 @@
|
|||||||
reflectProb: 1
|
reflectProb: 1
|
||||||
reflects:
|
reflects:
|
||||||
- Energy
|
- Energy
|
||||||
|
reflectingInHands: false
|
||||||
|
|
||||||
#Detective's vest
|
#Detective's vest
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
@@ -169,6 +169,8 @@
|
|||||||
- Back
|
- Back
|
||||||
- Belt
|
- Belt
|
||||||
- type: Reflect
|
- type: Reflect
|
||||||
|
slotFlags:
|
||||||
|
- NONE
|
||||||
|
|
||||||
#Greatswords
|
#Greatswords
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user