Make energy sword reflect projectiles and hitscan shots (#14029)
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.EnergySword.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
internal sealed class EnergySwordComponent : Component
|
||||
{
|
||||
public Color BladeColor = Color.DodgerBlue;
|
||||
|
||||
public bool Hacked = false;
|
||||
|
||||
public bool Activated = false;
|
||||
|
||||
[DataField("isSharp")]
|
||||
public bool IsSharp = true;
|
||||
|
||||
/// <summary>
|
||||
/// Does this become hidden when deactivated
|
||||
/// </summary>
|
||||
[DataField("secret")]
|
||||
public bool Secret { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// RGB cycle rate for hacked e-swords.
|
||||
/// </summary>
|
||||
[DataField("cycleRate")]
|
||||
public float CycleRate = 1f;
|
||||
|
||||
[DataField("activateSound")]
|
||||
public SoundSpecifier ActivateSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/ebladeon.ogg");
|
||||
|
||||
[DataField("deActivateSound")]
|
||||
public SoundSpecifier DeActivateSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/ebladeoff.ogg");
|
||||
|
||||
[DataField("onHitOn")]
|
||||
public SoundSpecifier OnHitOn { get; set; } = new SoundPathSpecifier("/Audio/Weapons/eblade1.ogg");
|
||||
|
||||
[DataField("onHitOff")]
|
||||
public SoundSpecifier OnHitOff { get; set; } = new SoundPathSpecifier("/Audio/Weapons/genhit1.ogg");
|
||||
|
||||
[DataField("colorOptions")]
|
||||
public List<Color> ColorOptions = new()
|
||||
{
|
||||
Color.Tomato,
|
||||
Color.DodgerBlue,
|
||||
Color.Aqua,
|
||||
Color.MediumSpringGreen,
|
||||
Color.MediumOrchid
|
||||
};
|
||||
|
||||
[DataField("litDamageBonus")]
|
||||
public DamageSpecifier LitDamageBonus = new();
|
||||
|
||||
[DataField("litDisarmMalus")]
|
||||
public float litDisarmMalus = 0.6f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.EnergySword;
|
||||
|
||||
[RegisterComponent]
|
||||
internal sealed class EnergySwordComponent : Component
|
||||
{
|
||||
public Color BladeColor = Color.DodgerBlue;
|
||||
|
||||
public bool Hacked = false;
|
||||
|
||||
public bool Activated = false;
|
||||
|
||||
[DataField("isSharp")]
|
||||
public bool IsSharp = true;
|
||||
|
||||
/// <summary>
|
||||
/// Does this become hidden when deactivated
|
||||
/// </summary>
|
||||
[DataField("secret")]
|
||||
public bool Secret { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// RGB cycle rate for hacked e-swords.
|
||||
/// </summary>
|
||||
[DataField("cycleRate")]
|
||||
public float CycleRate = 1f;
|
||||
|
||||
[DataField("activateSound")]
|
||||
public SoundSpecifier ActivateSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/ebladeon.ogg");
|
||||
|
||||
[DataField("deActivateSound")]
|
||||
public SoundSpecifier DeActivateSound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/ebladeoff.ogg");
|
||||
|
||||
[DataField("onHitOn")]
|
||||
public SoundSpecifier OnHitOn { get; set; } = new SoundPathSpecifier("/Audio/Weapons/eblade1.ogg");
|
||||
|
||||
[DataField("onHitOff")]
|
||||
public SoundSpecifier OnHitOff { get; set; } = new SoundPathSpecifier("/Audio/Weapons/genhit1.ogg");
|
||||
|
||||
[DataField("colorOptions")]
|
||||
public List<Color> ColorOptions = new()
|
||||
{
|
||||
Color.Tomato,
|
||||
Color.DodgerBlue,
|
||||
Color.Aqua,
|
||||
Color.MediumSpringGreen,
|
||||
Color.MediumOrchid
|
||||
};
|
||||
|
||||
[DataField("litDamageBonus")]
|
||||
public DamageSpecifier LitDamageBonus = new();
|
||||
|
||||
[DataField("litDisarmMalus")]
|
||||
public float LitDisarmMalus = 0.6f;
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly record struct EnergySwordActivatedEvent();
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly record struct EnergySwordDeactivatedEvent();
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Server.Weapons.Melee.EnergySword.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Item;
|
||||
@@ -14,151 +13,150 @@ using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Weapons.Melee.EnergySword
|
||||
namespace Content.Server.Weapons.Melee.EnergySword;
|
||||
|
||||
public sealed class EnergySwordSystem : EntitySystem
|
||||
{
|
||||
public sealed class EnergySwordSystem : EntitySystem
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
base.Initialize();
|
||||
|
||||
public override void Initialize()
|
||||
SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<EnergySwordComponent, IsHotEvent>(OnIsHotEvent);
|
||||
SubscribeLocalEvent<EnergySwordComponent, EnergySwordDeactivatedEvent>(TurnOff);
|
||||
SubscribeLocalEvent<EnergySwordComponent, EnergySwordActivatedEvent>(TurnOn);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, EnergySwordComponent comp, MapInitEvent args)
|
||||
{
|
||||
if (comp.ColorOptions.Count != 0)
|
||||
comp.BladeColor = _random.Pick(comp.ColorOptions);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, EnergySwordComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
// Overrides basic blunt damage with burn+slash as set in yaml
|
||||
args.BonusDamage = comp.LitDamageBonus;
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, EnergySwordComponent comp, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (comp.Activated)
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<EnergySwordComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<EnergySwordComponent, IsHotEvent>(OnIsHotEvent);
|
||||
var ev = new EnergySwordDeactivatedEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new EnergySwordActivatedEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, EnergySwordComponent comp, MapInitEvent args)
|
||||
UpdateAppearance(uid, comp);
|
||||
}
|
||||
|
||||
private void TurnOff(EntityUid uid, EnergySwordComponent comp, ref EnergySwordDeactivatedEvent args)
|
||||
{
|
||||
if (TryComp(uid, out ItemComponent? item))
|
||||
{
|
||||
if (comp.ColorOptions.Count != 0)
|
||||
comp.BladeColor = _random.Pick(comp.ColorOptions);
|
||||
_item.SetSize(uid, 5, item);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, EnergySwordComponent comp, MeleeHitEvent args)
|
||||
if (TryComp<DisarmMalusComponent>(uid, out var malus))
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
// Overrides basic blunt damage with burn+slash as set in yaml
|
||||
args.BonusDamage = comp.LitDamageBonus;
|
||||
malus.Malus -= comp.LitDisarmMalus;
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, EnergySwordComponent comp, UseInHandEvent args)
|
||||
if (TryComp<MeleeWeaponComponent>(uid, out var weaponComp))
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
if (comp.Activated)
|
||||
{
|
||||
TurnOff(comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
TurnOn(comp);
|
||||
}
|
||||
|
||||
UpdateAppearance(comp);
|
||||
weaponComp.HitSound = comp.OnHitOff;
|
||||
if (comp.Secret)
|
||||
weaponComp.HideFromExamine = true;
|
||||
}
|
||||
|
||||
private void TurnOff(EnergySwordComponent comp)
|
||||
if (comp.IsSharp)
|
||||
RemComp<SharpComponent>(uid);
|
||||
|
||||
_audio.Play(comp.DeActivateSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, comp.DeActivateSound.Params);
|
||||
|
||||
comp.Activated = false;
|
||||
}
|
||||
|
||||
private void TurnOn(EntityUid uid, EnergySwordComponent comp, ref EnergySwordActivatedEvent args)
|
||||
{
|
||||
if (TryComp(uid, out ItemComponent? item))
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
if (TryComp(comp.Owner, out ItemComponent? item))
|
||||
{
|
||||
_item.SetSize(comp.Owner, 5, item);
|
||||
}
|
||||
|
||||
if (TryComp<DisarmMalusComponent>(comp.Owner, out var malus))
|
||||
{
|
||||
malus.Malus -= comp.litDisarmMalus;
|
||||
}
|
||||
|
||||
if(TryComp<MeleeWeaponComponent>(comp.Owner, out var weaponComp))
|
||||
{
|
||||
weaponComp.HitSound = comp.OnHitOff;
|
||||
if (comp.Secret)
|
||||
weaponComp.HideFromExamine = true;
|
||||
}
|
||||
|
||||
if (comp.IsSharp)
|
||||
RemComp<SharpComponent>(comp.Owner);
|
||||
|
||||
_audio.Play(comp.DeActivateSound, Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.Owner, true, comp.DeActivateSound.Params);
|
||||
|
||||
comp.Activated = false;
|
||||
_item.SetSize(uid, 9999, item);
|
||||
}
|
||||
|
||||
private void TurnOn(EnergySwordComponent comp)
|
||||
if (comp.IsSharp)
|
||||
EnsureComp<SharpComponent>(uid);
|
||||
|
||||
if (TryComp<MeleeWeaponComponent>(uid, out var weaponComp))
|
||||
{
|
||||
if (comp.Activated)
|
||||
return;
|
||||
|
||||
if (TryComp(comp.Owner, out ItemComponent? item))
|
||||
{
|
||||
_item.SetSize(comp.Owner, 9999, item);
|
||||
}
|
||||
|
||||
if (comp.IsSharp)
|
||||
EnsureComp<SharpComponent>(comp.Owner);
|
||||
|
||||
if(TryComp<MeleeWeaponComponent>(comp.Owner, out var weaponComp))
|
||||
{
|
||||
weaponComp.HitSound = comp.OnHitOn;
|
||||
if (comp.Secret)
|
||||
weaponComp.HideFromExamine = false;
|
||||
}
|
||||
_audio.Play(comp.ActivateSound, Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.Owner, true, comp.ActivateSound.Params);
|
||||
|
||||
if (TryComp<DisarmMalusComponent>(comp.Owner, out var malus))
|
||||
{
|
||||
malus.Malus += comp.litDisarmMalus;
|
||||
}
|
||||
|
||||
comp.Activated = true;
|
||||
weaponComp.HitSound = comp.OnHitOn;
|
||||
if (comp.Secret)
|
||||
weaponComp.HideFromExamine = false;
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EnergySwordComponent component)
|
||||
if (TryComp<DisarmMalusComponent>(uid, out var malus))
|
||||
{
|
||||
if (!TryComp(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
return;
|
||||
|
||||
_appearance.SetData(component.Owner, ToggleableLightVisuals.Enabled, component.Activated, appearanceComponent);
|
||||
_appearance.SetData(component.Owner, ToggleableLightVisuals.Color, component.BladeColor, appearanceComponent);
|
||||
malus.Malus += comp.LitDisarmMalus;
|
||||
}
|
||||
|
||||
_audio.Play(comp.ActivateSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, comp.ActivateSound.Params);
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractUsingEvent args)
|
||||
comp.Activated = true;
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, EnergySwordComponent component)
|
||||
{
|
||||
if (!TryComp(uid, out AppearanceComponent? appearanceComponent))
|
||||
return;
|
||||
|
||||
_appearance.SetData(uid, ToggleableLightVisuals.Enabled, component.Activated, appearanceComponent);
|
||||
_appearance.SetData(uid, ToggleableLightVisuals.Color, component.BladeColor, appearanceComponent);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Used, out ToolComponent? tool) || !tool.Qualities.ContainsAny("Pulsing"))
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
comp.Hacked = !comp.Hacked;
|
||||
|
||||
if (comp.Hacked)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Used, out ToolComponent? tool) || !tool.Qualities.ContainsAny("Pulsing"))
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
comp.Hacked = !comp.Hacked;
|
||||
|
||||
if (comp.Hacked)
|
||||
{
|
||||
var rgb = EnsureComp<RgbLightControllerComponent>(uid);
|
||||
_rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb);
|
||||
}
|
||||
else
|
||||
RemComp<RgbLightControllerComponent>(uid);
|
||||
}
|
||||
private void OnIsHotEvent(EntityUid uid, EnergySwordComponent energySword, IsHotEvent args)
|
||||
{
|
||||
args.IsHot = energySword.Activated;
|
||||
var rgb = EnsureComp<RgbLightControllerComponent>(uid);
|
||||
_rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb);
|
||||
}
|
||||
else
|
||||
RemComp<RgbLightControllerComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnIsHotEvent(EntityUid uid, EnergySwordComponent energySword, IsHotEvent args)
|
||||
{
|
||||
args.IsHot = energySword.Activated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
[Dependency] private readonly PricingSystem _pricing = default!;
|
||||
[Dependency] private readonly StaminaSystem _stamina = default!;
|
||||
[Dependency] private readonly StunSystem _stun = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
public const float DamagePitchVariation = SharedMeleeWeaponSystem.DamagePitchVariation;
|
||||
public const float GunClumsyChance = 0.5f;
|
||||
@@ -192,18 +193,42 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
ShootProjectile(ent.Value, mapDirection, gunVelocity, user, gun.ProjectileSpeed);
|
||||
break;
|
||||
case HitscanPrototype hitscan:
|
||||
var ray = new CollisionRay(fromMap.Position, mapDirection.Normalized, hitscan.CollisionMask);
|
||||
|
||||
var rayCastResults =
|
||||
Physics.IntersectRay(fromMap.MapId, ray, hitscan.MaxLength, user, false).ToList();
|
||||
EntityUid? lastHit = null;
|
||||
|
||||
if (rayCastResults.Count >= 1)
|
||||
var from = fromMap;
|
||||
var fromEffect = fromCoordinates; // can't use map coords above because funny FireEffects
|
||||
var dir = mapDirection.Normalized;
|
||||
var lastUser = user;
|
||||
for (var reflectAttempt = 0; reflectAttempt < 3; reflectAttempt++)
|
||||
{
|
||||
var result = rayCastResults[0];
|
||||
var hitEntity = result.HitEntity;
|
||||
var distance = result.Distance;
|
||||
FireEffects(fromCoordinates, distance, mapDirection.ToAngle(), hitscan, hitEntity);
|
||||
var ray = new CollisionRay(from.Position, dir, hitscan.CollisionMask);
|
||||
var rayCastResults =
|
||||
Physics.IntersectRay(from.MapId, ray, hitscan.MaxLength, lastUser, false).ToList();
|
||||
if (!rayCastResults.Any())
|
||||
break;
|
||||
|
||||
var result = rayCastResults[0];
|
||||
var hit = result.HitEntity;
|
||||
lastHit = hit;
|
||||
|
||||
FireEffects(fromEffect, result.Distance, dir.Normalized.ToAngle(), hitscan, hit);
|
||||
|
||||
var ev = new HitScanReflectAttemptEvent(dir, false);
|
||||
RaiseLocalEvent(hit, ref ev);
|
||||
|
||||
if (!ev.Reflected)
|
||||
break;
|
||||
|
||||
fromEffect = Transform(hit).Coordinates;
|
||||
from = fromEffect.ToMap(EntityManager, _transform);
|
||||
dir = ev.Direction;
|
||||
lastUser = hit;
|
||||
}
|
||||
|
||||
if (lastHit != null)
|
||||
{
|
||||
EntityUid hitEntity = lastHit.Value;
|
||||
if (hitscan.StaminaDamage > 0f)
|
||||
_stamina.TakeStaminaDamage(hitEntity, hitscan.StaminaDamage, source:user);
|
||||
|
||||
@@ -219,7 +244,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
if (!Deleted(hitEntity))
|
||||
{
|
||||
if (dmg.Total > FixedPoint2.Zero)
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {result.HitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
|
||||
RaiseNetworkEvent(new DamageEffectEvent(Color.Red, new List<EntityUid> {hitEntity}), Filter.Pvs(hitEntity, entityManager: EntityManager));
|
||||
|
||||
// TODO get fallback position for playing hit sound.
|
||||
PlayImpactSound(hitEntity, dmg, hitscan.Sound, hitscan.ForceSound);
|
||||
@@ -239,7 +264,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
}
|
||||
else
|
||||
{
|
||||
FireEffects(fromCoordinates, hitscan.MaxLength, mapDirection.ToAngle(), hitscan);
|
||||
FireEffects(fromEffect, hitscan.MaxLength, dir.ToAngle(), hitscan);
|
||||
}
|
||||
|
||||
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
|
||||
|
||||
26
Content.Server/Weapons/Reflect/ReflectSystem.cs
Normal file
26
Content.Server/Weapons/Reflect/ReflectSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Content.Server.Weapons.Melee.EnergySword;
|
||||
using Content.Shared.Weapons.Reflect;
|
||||
|
||||
namespace Content.Server.Weapons.Reflect;
|
||||
|
||||
public sealed class ReflectSystem : SharedReflectSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ReflectComponent, EnergySwordActivatedEvent>(EnableReflect);
|
||||
SubscribeLocalEvent<ReflectComponent, EnergySwordDeactivatedEvent>(DisableReflect);
|
||||
}
|
||||
|
||||
private void EnableReflect(EntityUid uid, ReflectComponent comp, ref EnergySwordActivatedEvent args)
|
||||
{
|
||||
comp.Enabled = true;
|
||||
Dirty(comp);
|
||||
}
|
||||
|
||||
private void DisableReflect(EntityUid uid, ReflectComponent comp, ref EnergySwordDeactivatedEvent args)
|
||||
{
|
||||
comp.Enabled = false;
|
||||
Dirty(comp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user