Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port/Feature] Knockdown / Сбитие С Ног #114

Merged
merged 13 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override void Update(float frameTime)
// Unarmed will try to disarm
// Melee weapons will wideswing
// Ranged weapons will do a light attack.
if (altDown == BoundKeyState.Down)
if (altDown == BoundKeyState.Down && weapon.CanHeavyAttack) // WD EDIT
{
// Get the target that was clicked on
EntityUid? target = null;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Explosion/EntitySystems/TriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void HandleExplodeTrigger(EntityUid uid, ExplodeOnTriggerComponent compo
private void HandleFlashTrigger(EntityUid uid, FlashOnTriggerComponent component, TriggerEvent args)
{
// TODO Make flash durations sane ffs.
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
_flashSystem.FlashArea(uid, args.User, component.Range, component.Duration * 1000f, probability: component.Probability);
_flashSystem.FlashArea(uid, args.User, component.Range, component.Duration * 1000f, probability: component.Probability, stunTime: component.StunTime, knockdownTime: component.KnockdownTime); // WD EDIT
Spatison marked this conversation as resolved.
Show resolved Hide resolved
args.Handled = true;
}

Expand Down
42 changes: 39 additions & 3 deletions Content.Server/Flash/FlashSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Server._White.Flash;
using Content.Server.Flash.Components;
using Content.Shared.Flash.Components;
using Content.Server.Light.EntitySystems;
Expand Down Expand Up @@ -167,7 +168,39 @@ public void Flash(EntityUid target,
}
}

public void FlashArea(Entity<FlashComponent?> source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null)
// WD EDIT START
private void FlashStun(EntityUid target, float stunDuration, float knockdownDuration, float distance, float range)
{
if (stunDuration <= 0 || knockdownDuration <= 0)
return;
Spatison marked this conversation as resolved.
Show resolved Hide resolved

if (TryComp<FlashSoundSuppressionComponent>(target, out var suppression))
range = MathF.Min(range, suppression.MaxRange);

var ev = new FlashbangedEvent(range);
RaiseLocalEvent(target, ev);

range = MathF.Min(range, ev.MaxRange);
if (range <= 0f)
return;

if (distance < 0f)
distance = 0f;

if (distance > range)
return;

Spatison marked this conversation as resolved.
Show resolved Hide resolved
var knockdownTime = float.Lerp(knockdownDuration, 0f, distance / range);
if (knockdownTime > 0f)
_stun.TryKnockdown(target, TimeSpan.FromSeconds(knockdownTime), true);

var stunTime = float.Lerp(stunDuration, 0f, distance / range);
if (stunTime > 0f)
_stun.TryStun(target, TimeSpan.FromSeconds(stunTime), true);
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
// WD EDIT END
Spatison marked this conversation as resolved.
Show resolved Hide resolved

public void FlashArea(Entity<FlashComponent?> source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null, float stunTime = 0f, float knockdownTime = 0f) // WD EDIT
{
var transform = Transform(source);
var mapPosition = _transform.GetMapCoordinates(transform);
Expand All @@ -187,6 +220,11 @@ public void FlashArea(Entity<FlashComponent?> source, EntityUid? user, float ran

// They shouldn't have flash removed in between right?
Flash(entity, user, source, duration, slowTo, displayPopup, flashableQuery.GetComponent(entity));

// WD EDIT START
var distance = (mapPosition.Position - _transform.GetMapCoordinates(entity).Position).Length();
FlashStun(entity, stunTime, knockdownTime, distance, range);
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
// WD EDIT END
}

_audio.PlayPvs(sound, source, AudioParams.Default.WithVolume(1f).WithMaxDistance(3f));
Expand Down Expand Up @@ -251,6 +289,4 @@ public AfterFlashedEvent(EntityUid target, EntityUid? user, EntityUid? used)
Used = used;
}
}


}
2 changes: 1 addition & 1 deletion Content.Server/Speech/EntitySystems/StutteringSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class StutteringSystem : SharedStutteringSystem
[Dependency] private readonly IRobustRandom _random = default!;

// Regex of characters to stutter.
private static readonly Regex Stutter = new(@"[b-df-hj-np-tv-wxyz]",
private static readonly Regex Stutter = new(@"[b-df-hj-np-tv-wxyz-б-вд-к-лмн-прст]", // WD EDIT
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
RegexOptions.Compiled | RegexOptions.IgnoreCase);

public override void Initialize()
Expand Down
8 changes: 8 additions & 0 deletions Content.Server/_White/Flash/FlashSoundSuppressionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Server._White.Flash;

[RegisterComponent]
public sealed partial class FlashSoundSuppressionComponent : Component
{
[DataField]
public float MaxRange = 2f;
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
19 changes: 19 additions & 0 deletions Content.Server/_White/Flash/FlashSoundSuppressionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Shared.Flash;
using Content.Shared.Inventory;

namespace Content.Server._White.Flash;

public sealed class FlashSoundSuppressionSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<FlashSoundSuppressionComponent, InventoryRelayedEvent<FlashbangedEvent>>(OnFlashbanged);
}

private void OnFlashbanged(Entity<FlashSoundSuppressionComponent> ent, ref InventoryRelayedEvent<FlashbangedEvent> args)
{
args.Args.MaxRange = MathF.Min(args.Args.MaxRange, ent.Comp.MaxRange);
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 16 additions & 0 deletions Content.Server/_White/Knockdown/BaseKnockdownOnComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Content.Server._White.Knockdown;

public abstract partial class BaseKnockdownOnComponent : Component
{
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(2);

[DataField]
public TimeSpan KnockdownTime = TimeSpan.FromSeconds(5);

[DataField]
public TimeSpan JitterTime = TimeSpan.FromSeconds(15);

[DataField]
public TimeSpan StutterTime = TimeSpan.FromSeconds(15);
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions Content.Server/_White/Knockdown/KnockComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Content.Server._White.Knockdown;

[RegisterComponent]
public sealed partial class KnockComponent : Component
{
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(2);

[DataField]
public TimeSpan KnockdownTime = TimeSpan.FromSeconds(5);
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server._White.Knockdown;

[RegisterComponent]
public sealed partial class KnockdownOnCollideComponent : BaseKnockdownOnComponent;
4 changes: 4 additions & 0 deletions Content.Server/_White/Knockdown/KnockdownOnHitComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server._White.Knockdown;

[RegisterComponent]
public sealed partial class KnockdownOnHitComponent : BaseKnockdownOnComponent;
Spatison marked this conversation as resolved.
Show resolved Hide resolved
77 changes: 77 additions & 0 deletions Content.Server/_White/Knockdown/KnockdownSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Content.Server.Jittering;
using Content.Server.Speech.EntitySystems;
using Content.Server.Stunnable;
using Content.Shared.Damage.Events;
using Content.Shared.Projectiles;
using Content.Shared.StatusEffect;
using Content.Shared.Throwing;
using Robust.Shared.Timing;

namespace Content.Server._White.Knockdown;

public sealed class KnockdownSystem : EntitySystem
{
[Dependency] private readonly StunSystem _sharedStun = default!;
[Dependency] private readonly JitteringSystem _jitter = default!;
[Dependency] private readonly StutteringSystem _stutter = default!;
[Dependency] private readonly IGameTiming _timing = default!;
Spatison marked this conversation as resolved.
Show resolved Hide resolved

public override void Initialize()
{
SubscribeLocalEvent<KnockdownOnHitComponent, TakeStaminaDamageEvent>(OnMeleeHit);
SubscribeLocalEvent<KnockdownOnCollideComponent, ProjectileHitEvent>(OnProjectileHit);
SubscribeLocalEvent<KnockdownOnCollideComponent, ThrowDoHitEvent>(OnThrowDoHit);
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved

private void OnMeleeHit(EntityUid uid, KnockdownOnHitComponent component, TakeStaminaDamageEvent args)
{
Knockdown(args.Target, component);
}

private void OnProjectileHit(EntityUid uid, KnockdownOnCollideComponent component, ProjectileHitEvent args)
{
Knockdown(args.Target, component);
}

private void OnThrowDoHit(EntityUid uid, KnockdownOnCollideComponent component, ThrowDoHitEvent args)
{
Knockdown(args.Target, component);
}

private void Knockdown(EntityUid target, BaseKnockdownOnComponent component)
{
if (!TryComp<StatusEffectsComponent>(target, out var statusEffects))
return;
Spatison marked this conversation as resolved.
Show resolved Hide resolved

if (component.JitterTime > TimeSpan.Zero)
_jitter.DoJitter(target, component.JitterTime, true, status: statusEffects);

if (component.StutterTime > TimeSpan.Zero)
_stutter.DoStutter(target, component.StutterTime, true, statusEffects);

if (component.Delay == TimeSpan.Zero)
{
_sharedStun.TryKnockdown(target, component.KnockdownTime, true, statusEffects);
return;
}

var knockdown = EnsureComp<KnockComponent>(target);
knockdown.Delay = _timing.CurTime + component.Delay;
knockdown.KnockdownTime = component.KnockdownTime;
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<KnockComponent>();
while (query.MoveNext(out var uid, out var delayedKnockdown))
{
if (delayedKnockdown.Delay > _timing.CurTime)
continue;

_sharedStun.TryKnockdown(uid, delayedKnockdown.KnockdownTime, true);
RemCompDeferred<KnockComponent>(uid);
}
}
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions Content.Shared/Alert/AlertType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum AlertType : byte
Hot,
Weightless,
Stun,
KnockedDown, // WD EDIT
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Handcuffed,
Ensnared,
Buckled,
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Flash/Components/FlashOnTriggerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public sealed partial class FlashOnTriggerComponent : Component
[DataField] public float Range = 1.0f;
[DataField] public float Duration = 8.0f;
[DataField] public float Probability = 1.0f;

// WD EDIT START
[DataField]
public float StunTime;
Spatison marked this conversation as resolved.
Show resolved Hide resolved

[DataField]
public float KnockdownTime;
// WD EDIT END
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 15 additions & 0 deletions Content.Shared/Flash/SharedFlashSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Inventory;
using Robust.Shared.GameStates;

namespace Content.Shared.Flash
Expand All @@ -16,4 +17,18 @@ private static void OnFlashableGetState(EntityUid uid, FlashableComponent compon
args.State = new FlashableComponentState(component.Duration, component.LastFlash, component.EyeDamageChance, component.EyeDamage, component.DurationMultiplier);
}
}

// WD EDIT START
public sealed class FlashbangedEvent : EntityEventArgs, IInventoryRelayEvent
{
public float MaxRange;
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved
Spatison marked this conversation as resolved.
Show resolved Hide resolved

public SlotFlags TargetSlots => SlotFlags.EARS | SlotFlags.HEAD;

public FlashbangedEvent(float maxRange)
{
MaxRange = maxRange;
}
}
// WD EDIT END
}
2 changes: 2 additions & 0 deletions Content.Shared/Inventory/InventorySystem.Relay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Electrocution;
using Content.Shared.Explosion;
using Content.Shared.Eye.Blinding.Systems;
using Content.Shared.Flash;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Movement.Systems;
Expand All @@ -29,6 +30,7 @@ public void InitializeRelay()
SubscribeLocalEvent<InventoryComponent, SeeIdentityAttemptEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, GetDefaultRadioChannelEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, FlashbangedEvent>(RelayInventoryEvent); // WD EDIT

// by-ref events
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent componen

if (!clothing.Slots.HasFlag(args.SlotFlags)) return;

if (component.Components.Count > 1)
if (component.Components.Count > 8) // WD EDIT
{
Logger.Error("Although a component registry supports multiple components, we cannot bookkeep more than 1 component for ClothingGrantComponent at this time.");
Logger.Error("Although a component registry supports multiple components, we cannot bookkeep more than 8 component for ClothingGrantComponent at this time."); // WD EDIT
return;
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -46,9 +46,9 @@ private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent componen
var temp = (object) newComp;
_serializationManager.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(args.Equipee, (Component)temp!);

component.IsActive = true;
}

component.IsActive = true; // WD EDIT
Spatison marked this conversation as resolved.
Show resolved Hide resolved
}

private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent component, GotUnequippedEvent args)
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Stunnable/SharedStunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void UpdateCanMove(EntityUid uid, StunnedComponent component, EntityEven
private void OnKnockInit(EntityUid uid, KnockedDownComponent component, ComponentInit args)
{
RaiseNetworkEvent(new CheckAutoGetUpEvent(GetNetEntity(uid)));
_layingDown.TryLieDown(uid, null, null, DropHeldItemsBehavior.DropIfStanding);
_layingDown.TryLieDown(uid, null, null, DropHeldItemsBehavior.AlwaysDrop); // WD EDIT
}

private void OnKnockShutdown(EntityUid uid, KnockedDownComponent component, ComponentShutdown args)
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Weapons/Melee/MeleeWeaponComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public sealed partial class MeleeWeaponComponent : Component
// WD EDIT START
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public EntProtoId DisarmAnimation = "WeaponArcDisarm";

[DataField, AutoNetworkedField]
public bool CanHeavyAttack = true;
// WD EDIT END

/// <summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Content.Shared.Standing;

namespace Content.Shared._White.Collision.Knockdown;
namespace Content.Shared._White.Collision.LayDown;

[RegisterComponent]
public sealed partial class KnockdownOnCollideComponent : Component
public sealed partial class LayDownOnCollideComponent : Component
{
[DataField]
public DropHeldItemsBehavior Behavior = DropHeldItemsBehavior.NoDrop;
Expand Down
Loading
Loading