Reflect changes (#15071)
This commit is contained in:
@@ -17,33 +17,28 @@ public sealed class ReflectComponent : Component
|
|||||||
public bool Enabled = true;
|
public bool Enabled = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reflect chance for hitscan weapons (lasers) and projectiles with heat damage (disabler)
|
/// Probability for a projectile to be reflected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("energeticChance"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("reflectProb"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float EnergeticChance;
|
public float ReflectProb;
|
||||||
|
|
||||||
[DataField("kineticChance"), ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public float KineticChance;
|
|
||||||
|
|
||||||
[DataField("spread"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("spread"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public Angle Spread = Angle.FromDegrees(5);
|
public Angle Spread = Angle.FromDegrees(5);
|
||||||
|
|
||||||
[DataField("onReflect")]
|
[DataField("soundOnReflect")]
|
||||||
public SoundSpecifier? OnReflect = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg");
|
public SoundSpecifier? SoundOnReflect = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/laser_sear_wall.ogg");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class ReflectComponentState : ComponentState
|
public sealed class ReflectComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public bool Enabled;
|
public bool Enabled;
|
||||||
public float EnergeticChance;
|
public float ReflectProb;
|
||||||
public float KineticChance;
|
|
||||||
public Angle Spread;
|
public Angle Spread;
|
||||||
public ReflectComponentState(bool enabled, float energeticChance, float kineticChance, Angle spread)
|
public ReflectComponentState(bool enabled, float reflectProb, Angle spread)
|
||||||
{
|
{
|
||||||
Enabled = enabled;
|
Enabled = enabled;
|
||||||
EnergeticChance = energeticChance;
|
ReflectProb = reflectProb;
|
||||||
KineticChance = kineticChance;
|
|
||||||
Spread = spread;
|
Spread = spread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Content.Shared.Weapons.Ranged.Events;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Robust.Shared.Physics.Components;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Projectiles;
|
using Content.Shared.Projectiles;
|
||||||
using Content.Shared.Weapons.Ranged.Events;
|
using Content.Shared.Weapons.Ranged.Events;
|
||||||
@@ -33,55 +37,62 @@ public abstract class SharedReflectSystem : EntitySystem
|
|||||||
|
|
||||||
private static void OnHandleState(EntityUid uid, ReflectComponent component, ref ComponentHandleState args)
|
private static void OnHandleState(EntityUid uid, ReflectComponent component, ref ComponentHandleState args)
|
||||||
{
|
{
|
||||||
if (args.Current is not ReflectComponentState state) return;
|
if (args.Current is not ReflectComponentState state)
|
||||||
|
return;
|
||||||
|
|
||||||
component.Enabled = state.Enabled;
|
component.Enabled = state.Enabled;
|
||||||
component.EnergeticChance = state.EnergeticChance;
|
component.ReflectProb = state.ReflectProb;
|
||||||
component.KineticChance = state.KineticChance;
|
|
||||||
component.Spread = state.Spread;
|
component.Spread = state.Spread;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnGetState(EntityUid uid, ReflectComponent component, ref ComponentGetState args)
|
private static void OnGetState(EntityUid uid, ReflectComponent component, ref ComponentGetState args)
|
||||||
{
|
{
|
||||||
args.State = new ReflectComponentState(component.Enabled, component.EnergeticChance, component.KineticChance, component.Spread);
|
args.State = new ReflectComponentState(component.Enabled, component.ReflectProb, component.Spread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHandReflectProjectile(EntityUid uid, HandsComponent hands, ref ProjectileReflectAttemptEvent args)
|
private void OnHandReflectProjectile(EntityUid uid, HandsComponent hands, ref ProjectileReflectAttemptEvent args)
|
||||||
{
|
{
|
||||||
if (args.Cancelled)
|
if (args.Cancelled)
|
||||||
return;
|
return;
|
||||||
if (TryReflectProjectile(uid, hands.ActiveHandEntity, args.ProjUid, args.Component))
|
|
||||||
|
if (TryReflectProjectile(uid, hands.ActiveHandEntity, args.ProjUid))
|
||||||
args.Cancelled = true;
|
args.Cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryReflectProjectile(EntityUid user, EntityUid? reflector, EntityUid projectile, ProjectileComponent component)
|
private bool TryReflectProjectile(EntityUid user, EntityUid? reflector, EntityUid projectile)
|
||||||
{
|
{
|
||||||
var isEnergyProjectile = component.Damage.DamageDict.ContainsKey("Heat");
|
if (!TryComp<ReflectComponent>(reflector, out var reflect) ||
|
||||||
var isKineticProjectile = !isEnergyProjectile;
|
!reflect.Enabled ||
|
||||||
if (TryComp<ReflectComponent>(reflector, out var reflect) &&
|
!_random.Prob(reflect.ReflectProb) ||
|
||||||
reflect.Enabled &&
|
!TryComp<PhysicsComponent>(projectile, out var physics))
|
||||||
(isEnergyProjectile && _random.Prob(reflect.EnergeticChance) || isKineticProjectile && _random.Prob(reflect.KineticChance)))
|
|
||||||
{
|
{
|
||||||
var rotation = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2).Opposite();
|
return false;
|
||||||
|
|
||||||
var relVel = _physics.GetMapLinearVelocity(projectile) - _physics.GetMapLinearVelocity(user);
|
|
||||||
var newVel = rotation.RotateVec(relVel);
|
|
||||||
_physics.SetLinearVelocity(projectile, newVel);
|
|
||||||
|
|
||||||
var locRot = Transform(projectile).LocalRotation;
|
|
||||||
var newRot = rotation.RotateVec(locRot.ToVec());
|
|
||||||
_transform.SetLocalRotation(projectile, newRot.ToAngle());
|
|
||||||
|
|
||||||
_popup.PopupEntity(Loc.GetString("reflect-shot"), user, PopupType.Small);
|
|
||||||
_audio.PlayPvs(reflect.OnReflect, user, AudioHelpers.WithVariation(0.05f, _random));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
var rotation = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2).Opposite();
|
||||||
|
var existingVelocity = _physics.GetMapLinearVelocity(projectile, component: physics);
|
||||||
|
var relativeVelocity = existingVelocity - _physics.GetMapLinearVelocity(user);
|
||||||
|
var newVelocity = rotation.RotateVec(relativeVelocity);
|
||||||
|
|
||||||
|
// Have the velocity in world terms above so need to convert it back to local.
|
||||||
|
var difference = newVelocity - existingVelocity;
|
||||||
|
|
||||||
|
_physics.SetLinearVelocity(projectile, physics.LinearVelocity + difference, body: physics);
|
||||||
|
|
||||||
|
var locRot = Transform(projectile).LocalRotation;
|
||||||
|
var newRot = rotation.RotateVec(locRot.ToVec());
|
||||||
|
_transform.SetLocalRotation(projectile, newRot.ToAngle());
|
||||||
|
|
||||||
|
_popup.PopupEntity(Loc.GetString("reflect-shot"), user);
|
||||||
|
_audio.PlayPvs(reflect.SoundOnReflect, user, AudioHelpers.WithVariation(0.05f, _random));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHandsReflectHitscan(EntityUid uid, HandsComponent hands, ref HitScanReflectAttemptEvent args)
|
private void OnHandsReflectHitscan(EntityUid uid, HandsComponent hands, ref HitScanReflectAttemptEvent args)
|
||||||
{
|
{
|
||||||
if (args.Reflected)
|
if (args.Reflected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TryReflectHitscan(uid, hands.ActiveHandEntity, args.Direction, out var dir))
|
if (TryReflectHitscan(uid, hands.ActiveHandEntity, args.Direction, out var dir))
|
||||||
{
|
{
|
||||||
args.Direction = dir.Value;
|
args.Direction = dir.Value;
|
||||||
@@ -93,14 +104,15 @@ public abstract class SharedReflectSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (TryComp<ReflectComponent>(reflector, out var reflect) &&
|
if (TryComp<ReflectComponent>(reflector, out var reflect) &&
|
||||||
reflect.Enabled &&
|
reflect.Enabled &&
|
||||||
_random.Prob(reflect.EnergeticChance))
|
_random.Prob(reflect.ReflectProb))
|
||||||
{
|
{
|
||||||
_popup.PopupEntity(Loc.GetString("reflect-shot"), user, PopupType.Small);
|
_popup.PopupEntity(Loc.GetString("reflect-shot"), user, PopupType.Small);
|
||||||
_audio.PlayPvs(reflect.OnReflect, user, AudioHelpers.WithVariation(0.05f, _random));
|
_audio.PlayPvs(reflect.SoundOnReflect, user, AudioHelpers.WithVariation(0.05f, _random));
|
||||||
var spread = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2);
|
var spread = _random.NextAngle(-reflect.Spread / 2, reflect.Spread / 2);
|
||||||
newDirection = -spread.RotateVec(direction);
|
newDirection = -spread.RotateVec(direction);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
newDirection = null;
|
newDirection = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,7 @@
|
|||||||
malus: 0
|
malus: 0
|
||||||
- type: Reflect
|
- type: Reflect
|
||||||
enabled: false
|
enabled: false
|
||||||
energeticChance: 0.5
|
reflectProb: 0.25
|
||||||
kineticChance: 0.25
|
|
||||||
spread: 45
|
spread: 45
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user