Status effect refactor (#4868)

* Oops! All Changes In One Commit

* try desperately to fix prediction issues and fail

* oops

* test

* actually fixes prediction issues

* port jittering to status effect

* default merge behavior + alert cooldown stuff

* silly test issue

* zabloing

* address reviews
This commit is contained in:
mirrorcult
2021-10-15 14:45:04 -07:00
committed by GitHub
parent 51578304f1
commit ae1ce0b31c
36 changed files with 811 additions and 511 deletions

View File

@@ -48,7 +48,7 @@ namespace Content.Client.Jittering
private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args) private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args)
{ {
if(args.Key != _jitterAnimationKey || jittering.EndTime <= GameTiming.CurTime) if(args.Key != _jitterAnimationKey)
return; return;
if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer) if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer)

View File

@@ -24,7 +24,9 @@ namespace Content.IntegrationTests.Tests
id: InventoryStunnableDummy id: InventoryStunnableDummy
components: components:
- type: Inventory - type: Inventory
- type: Stunnable - type: StatusEffects
allowed:
- Stun
- type: entity - type: entity
name: InventoryJumpsuitJanitorDummy name: InventoryJumpsuitJanitorDummy
@@ -52,7 +54,6 @@ namespace Content.IntegrationTests.Tests
IEntity human = null; IEntity human = null;
InventoryComponent inventory = null; InventoryComponent inventory = null;
StunnableComponent stun = null;
server.Assert(() => server.Assert(() =>
{ {
@@ -64,7 +65,6 @@ namespace Content.IntegrationTests.Tests
human = entityMan.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); human = entityMan.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace);
inventory = human.GetComponent<InventoryComponent>(); inventory = human.GetComponent<InventoryComponent>();
stun = human.GetComponent<StunnableComponent>();
// Can't do the test if this human doesn't have the slots for it. // Can't do the test if this human doesn't have the slots for it.
Assert.That(inventory.HasSlot(Slots.INNERCLOTHING)); Assert.That(inventory.HasSlot(Slots.INNERCLOTHING));
@@ -76,7 +76,7 @@ namespace Content.IntegrationTests.Tests
Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform)); Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform));
Assert.That(uniform.Owner.Prototype != null && uniform.Owner.Prototype.ID == "InventoryJumpsuitJanitorDummy"); Assert.That(uniform.Owner.Prototype != null && uniform.Owner.Prototype.ID == "InventoryJumpsuitJanitorDummy");
EntitySystem.Get<StunSystem>().Stun(human.Uid, TimeSpan.FromSeconds(1f), stun); EntitySystem.Get<StunSystem>().TryStun(human.Uid, TimeSpan.FromSeconds(1f));
// Since the mob is stunned, they can't equip this. // Since the mob is stunned, they can't equip this.
Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy", true), Is.False); Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy", true), Is.False);

View File

@@ -9,6 +9,7 @@ using Content.Shared.Damage;
using Content.Shared.Jittering; using Content.Shared.Jittering;
using Content.Shared.MobState; using Content.Shared.MobState;
using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.Components;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Console; using Robust.Shared.Console;
@@ -59,10 +60,7 @@ namespace Content.Server.Administration.Commands
target.GetComponentOrNull<HungerComponent>()?.ResetFood(); target.GetComponentOrNull<HungerComponent>()?.ResetFood();
target.GetComponentOrNull<ThirstComponent>()?.ResetThirst(); target.GetComponentOrNull<ThirstComponent>()?.ResetThirst();
if (target.TryGetComponent(out StunnableComponent? stunnable)) EntitySystem.Get<StatusEffectsSystem>().TryRemoveAllStatusEffects(target.Uid);
{
EntitySystem.Get<StunSystem>().Reset(target.Uid, stunnable);
}
if (target.TryGetComponent(out FlammableComponent? flammable)) if (target.TryGetComponent(out FlammableComponent? flammable))
{ {

View File

@@ -153,10 +153,9 @@ namespace Content.Server.Atmos.EntitySystems
public void Resist(EntityUid uid, public void Resist(EntityUid uid,
FlammableComponent? flammable = null, FlammableComponent? flammable = null,
StunnableComponent? stunnable = null,
ServerAlertsComponent? alerts = null) ServerAlertsComponent? alerts = null)
{ {
if (!Resolve(uid, ref flammable, ref stunnable)) if (!Resolve(uid, ref flammable, ref alerts))
return; return;
if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting) if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting)
@@ -165,7 +164,7 @@ namespace Content.Server.Atmos.EntitySystems
flammable.Resisting = true; flammable.Resisting = true;
flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message")); flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
_stunSystem.Paralyze(uid, TimeSpan.FromSeconds(2f), stunnable, alerts); _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), alerts: alerts);
// TODO FLAMMABLE: Make this not use TimerComponent... // TODO FLAMMABLE: Make this not use TimerComponent...
flammable.Owner.SpawnTimer(2000, () => flammable.Owner.SpawnTimer(2000, () =>

View File

@@ -40,7 +40,6 @@ namespace Content.Server.Buckle.Components
[ComponentDependency] public readonly AppearanceComponent? Appearance = null; [ComponentDependency] public readonly AppearanceComponent? Appearance = null;
[ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null; [ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null;
[ComponentDependency] private readonly StunnableComponent? _stunnable = null;
[ComponentDependency] private readonly MobStateComponent? _mobState = null; [ComponentDependency] private readonly MobStateComponent? _mobState = null;
[DataField("size")] [DataField("size")]
@@ -336,7 +335,7 @@ namespace Content.Server.Buckle.Components
Appearance?.SetData(BuckleVisuals.Buckled, false); Appearance?.SetData(BuckleVisuals.Buckled, false);
if (_stunnable is { KnockedDown: true } if (Owner.HasComponent<KnockedDownComponent>()
|| (_mobState?.IsIncapacitated() ?? false)) || (_mobState?.IsIncapacitated() ?? false))
{ {
EntitySystem.Get<StandingStateSystem>().Down(Owner.Uid); EntitySystem.Get<StandingStateSystem>().Down(Owner.Uid);

View File

@@ -62,11 +62,8 @@ namespace Content.Server.Conveyor
signal != TwoWayLeverSignal.Middle) signal != TwoWayLeverSignal.Middle)
{ {
args.Cancel(); args.Cancel();
if (args.Attemptee.TryGetComponent<StunnableComponent>(out var stunnableComponent)) _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f));
{ component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link"));
_stunSystem.Paralyze(uid, TimeSpan.FromSeconds(2f), stunnableComponent);
component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link"));
}
} }
} }

View File

@@ -198,7 +198,7 @@ namespace Content.Server.Cuffs.Components
{ {
var cuffTime = CuffTime; var cuffTime = CuffTime;
if (target.TryGetComponent<StunnableComponent>(out var stun) && stun.Stunned) if (target.HasComponent<StunnedComponent>())
{ {
cuffTime = MathF.Max(0.1f, cuffTime - StunBonus); cuffTime = MathF.Max(0.1f, cuffTime - StunBonus);
} }

View File

@@ -46,8 +46,8 @@ namespace Content.Server.Damage.Systems
component.LastHit = _gameTiming.CurTime; component.LastHit = _gameTiming.CurTime;
if (EntityManager.TryGetComponent(uid, out StunnableComponent? stun) && _robustRandom.Prob(component.StunChance)) if (_robustRandom.Prob(component.StunChance))
_stunSystem.Stun(uid, TimeSpan.FromSeconds(component.StunSeconds), stun); _stunSystem.TryStun(uid, TimeSpan.FromSeconds(component.StunSeconds));
var damageScale = (speed / component.MinimumSpeed) * component.Factor; var damageScale = (speed / component.MinimumSpeed) * component.Factor;
_damageableSystem.TryChangeDamage(uid, component.Damage * damageScale); _damageableSystem.TryChangeDamage(uid, component.Damage * damageScale);

View File

@@ -136,8 +136,7 @@ namespace Content.Server.DoAfter
} }
if (EventArgs.BreakOnStun && if (EventArgs.BreakOnStun &&
entityManager.TryGetComponent(EventArgs.User, out StunnableComponent? stunnableComponent) && entityManager.HasComponent<StunnedComponent>(EventArgs.User))
stunnableComponent.Stunned)
{ {
return true; return true;
} }

View File

@@ -565,8 +565,7 @@ namespace Content.Server.Doors.Components
if (e.Owner.HasComponent<DamageableComponent>()) if (e.Owner.HasComponent<DamageableComponent>())
EntitySystem.Get<DamageableSystem>().TryChangeDamage(e.Owner.Uid, CrushDamage); EntitySystem.Get<DamageableSystem>().TryChangeDamage(e.Owner.Uid, CrushDamage);
if(e.Owner.TryGetComponent(out StunnableComponent? stun)) EntitySystem.Get<StunSystem>().TryParalyze(e.Owner.Uid, TimeSpan.FromSeconds(DoorStunTime));
EntitySystem.Get<StunSystem>().Paralyze(e.Owner.Uid, TimeSpan.FromSeconds(DoorStunTime), stun);
} }
// If we hit someone, open up after stun (opens right when stun ends) // If we hit someone, open up after stun (opens right when stun ends)

View File

@@ -131,10 +131,8 @@ namespace Content.Server.Flash
flashable.Dirty(); flashable.Dirty();
} }
if (EntityManager.TryGetComponent<StunnableComponent>(target, out var stunnable)) _stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f),
{ slowTo, slowTo);
_stunSystem.Slowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), slowTo, slowTo, stunnable);
}
if (displayPopup && user != null && target != user) if (displayPopup && user != null && target != user)
{ {

View File

@@ -361,14 +361,8 @@ namespace Content.Server.Instruments
if (mob != null) if (mob != null)
{ {
if (Handheld) EntitySystem.Get<StunSystem>().TryParalyze(mob.Uid, TimeSpan.FromSeconds(1));
EntitySystem.Get<StandingStateSystem>().Down(mob.Uid, false); Clean();
if (mob.TryGetComponent(out StunnableComponent? stun))
{
EntitySystem.Get<StunSystem>().Stun(mob.Uid, TimeSpan.FromSeconds(1), stun);
Clean();
}
Owner.PopupMessage(mob, "instrument-component-finger-cramps-max-message"); Owner.PopupMessage(mob, "instrument-component-finger-cramps-max-message");
} }

View File

@@ -1,6 +1,7 @@
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Server.Stunnable.Components; using Content.Server.Stunnable.Components;
using Content.Shared.MobState.State; using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -12,9 +13,9 @@ namespace Content.Server.MobState.States
{ {
base.EnterState(entity); base.EnterState(entity);
if (entity.TryGetComponent(out StunnableComponent? stun)) if (entity.TryGetComponent(out StatusEffectsComponent? stun))
{ {
EntitySystem.Get<StunSystem>().Reset(entity.Uid, stun); EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(entity.Uid, "Stun");
} }
} }
} }

View File

@@ -4,6 +4,7 @@ using Content.Server.Stunnable.Components;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.MobState; using Content.Shared.MobState;
using Content.Shared.MobState.State; using Content.Shared.MobState.State;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -21,10 +22,9 @@ namespace Content.Server.MobState.States
status.ShowAlert(AlertType.HumanDead); status.ShowAlert(AlertType.HumanDead);
} }
if (entity.TryGetComponent(out StunnableComponent? stun)) if (entity.TryGetComponent(out StatusEffectsComponent? stun))
{ {
// TODO: Use resolves to pass ServerAlertsComponent here. EntitySystem.Get<StatusEffectsSystem>().TryRemoveStatusEffect(entity.Uid, "Stun");
EntitySystem.Get<StunSystem>().Reset(entity.Uid, stun);
} }
} }
} }

View File

@@ -13,7 +13,7 @@ namespace Content.Server.Stunnable.Components
// TODO: Can probably predict this. // TODO: Can probably predict this.
public override string Name => "StunOnCollide"; public override string Name => "StunOnCollide";
// See stunnable for what these do // See stunsystem for what these do
[DataField("stunAmount")] [DataField("stunAmount")]
public int StunAmount; public int StunAmount;

View File

@@ -4,6 +4,7 @@ using Content.Server.Stunnable.Components;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.Movement.Components; using Content.Shared.Movement.Components;
using Content.Shared.Standing; using Content.Shared.Standing;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -17,6 +18,7 @@ namespace Content.Server.Stunnable
internal sealed class StunOnCollideSystem : EntitySystem internal sealed class StunOnCollideSystem : EntitySystem
{ {
[Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -28,7 +30,7 @@ namespace Content.Server.Stunnable
{ {
var otherUid = args.OtherFixture.Body.Owner.Uid; var otherUid = args.OtherFixture.Body.Owner.Uid;
if (EntityManager.TryGetComponent(otherUid, out StunnableComponent? stunnableComponent)) if (EntityManager.TryGetComponent<StatusEffectsComponent>(otherUid, out var status))
{ {
ServerAlertsComponent? alerts = null; ServerAlertsComponent? alerts = null;
StandingStateComponent? standingState = null; StandingStateComponent? standingState = null;
@@ -38,13 +40,13 @@ namespace Content.Server.Stunnable
// Let the actual methods log errors for these. // Let the actual methods log errors for these.
Resolve(otherUid, ref alerts, ref standingState, ref appearance, ref speedModifier, false); Resolve(otherUid, ref alerts, ref standingState, ref appearance, ref speedModifier, false);
_stunSystem.Stun(otherUid, TimeSpan.FromSeconds(component.StunAmount), stunnableComponent, alerts); _stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), status, alerts);
_stunSystem.Knockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount), stunnableComponent, _stunSystem.TryKnockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount),
alerts, standingState, appearance); status, alerts);
_stunSystem.Slowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount), _stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount),
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, stunnableComponent, speedModifier, alerts); component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, speedModifier, alerts);
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using Content.Server.Act;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -21,28 +22,30 @@ namespace Content.Server.Stunnable
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<StunnableComponent, DisarmedActEvent>(OnDisarmed); SubscribeLocalEvent<StatusEffectsComponent, DisarmedActEvent>(OnDisarmed);
} }
private void OnDisarmed(EntityUid uid, StunnableComponent stunnable, DisarmedActEvent args) private void OnDisarmed(EntityUid uid, StatusEffectsComponent status, DisarmedActEvent args)
{ {
if (args.Handled || !_random.Prob(args.PushProbability)) if (args.Handled || !_random.Prob(args.PushProbability))
return; return;
Paralyze(uid, TimeSpan.FromSeconds(4f), stunnable); if (!TryParalyze(uid, TimeSpan.FromSeconds(4f), status))
return;
var source = args.Source; var source = args.Source;
var target = args.Target; var target = args.Target;
if (source != null) if (source != null)
{ {
SoundSystem.Play(Filter.Pvs(source), stunnable.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); var knock = EntityManager.GetComponent<KnockedDownComponent>(uid);
SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f));
if (target != null) if (target != null)
{ {
// TODO: Use PopupSystem // TODO: Use PopupSystem
source.PopupMessageOtherClients(Loc.GetString("stunnable-component-disarm-success-others", ("source", source.Name), ("target", target.Name))); source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", source.Name), ("target", target.Name)));
source.PopupMessageCursor(Loc.GetString("stunnable-component-disarm-success", ("target", target.Name))); source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", target.Name)));
} }
} }

View File

@@ -9,7 +9,9 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Jittering;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -25,6 +27,7 @@ namespace Content.Server.Stunnable
public class StunbatonSystem : EntitySystem public class StunbatonSystem : EntitySystem
{ {
[Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!;
public override void Initialize() public override void Initialize()
@@ -62,11 +65,8 @@ namespace Content.Server.Stunnable
if (!EntityManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse)) if (!EntityManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse))
return; return;
if (args.Entity.HasComponent<StunnableComponent>()) args.CanInteract = true;
{ StunEntity(args.Entity, comp);
args.CanInteract = true;
StunEntity(args.Entity, comp);
}
} }
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args) private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)
@@ -119,26 +119,27 @@ namespace Content.Server.Stunnable
private void StunEntity(IEntity entity, StunbatonComponent comp) private void StunEntity(IEntity entity, StunbatonComponent comp)
{ {
if (!entity.TryGetComponent(out StunnableComponent? stunnable) || !comp.Activated) return; if (!entity.TryGetComponent(out StatusEffectsComponent? status) || !comp.Activated) return;
// TODO: Make slowdown inflicted customizable. // TODO: Make slowdown inflicted customizable.
SoundSystem.Play(Filter.Pvs(comp.Owner), comp.StunSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f)); SoundSystem.Play(Filter.Pvs(comp.Owner), comp.StunSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
if (!stunnable.SlowedDown) if (!EntityManager.HasComponent<SlowedDownComponent>(entity.Uid))
{ {
if (_robustRandom.Prob(comp.ParalyzeChanceNoSlowdown)) if (_robustRandom.Prob(comp.ParalyzeChanceNoSlowdown))
_stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable); _stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status);
else else
_stunSystem.Slowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, stunnable); _stunSystem.TrySlowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, status);
} }
else else
{ {
if (_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown)) if (_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown))
_stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable); _stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status);
else else
_stunSystem.Slowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, stunnable); _stunSystem.TrySlowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, status);
} }
_jitterSystem.DoJitter(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime));
if (!comp.Owner.TryGetComponent<PowerCellSlotComponent>(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse)) if (!comp.Owner.TryGetComponent<PowerCellSlotComponent>(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse))
return; return;

View File

@@ -173,12 +173,7 @@ namespace Content.Server.Weapon.Ranged
{ {
//Wound them //Wound them
EntitySystem.Get<DamageableSystem>().TryChangeDamage(user.Uid, ClumsyDamage); EntitySystem.Get<DamageableSystem>().TryChangeDamage(user.Uid, ClumsyDamage);
EntitySystem.Get<StunSystem>().TryParalyze(user.Uid, TimeSpan.FromSeconds(3f));
// Knock them down
if (user.TryGetComponent(out StunnableComponent? stun))
{
EntitySystem.Get<StunSystem>().Paralyze(user.Uid, TimeSpan.FromSeconds(3f), stun);
}
// Apply salt to the wound ("Honk!") // Apply salt to the wound ("Honk!")
SoundSystem.Play( SoundSystem.Play(

View File

@@ -83,7 +83,7 @@ namespace Content.Shared.Alert
/// <param name="severity">severity, if supported by the alert</param> /// <param name="severity">severity, if supported by the alert</param>
/// <param name="cooldown">cooldown start and end, if null there will be no cooldown (and it will /// <param name="cooldown">cooldown start and end, if null there will be no cooldown (and it will
/// be erased if there is currently a cooldown for the alert)</param> /// be erased if there is currently a cooldown for the alert)</param>
public void ShowAlert(AlertType alertType, short? severity = null, ValueTuple<TimeSpan, TimeSpan>? cooldown = null) public void ShowAlert(AlertType alertType, short? severity = null, (TimeSpan, TimeSpan)? cooldown = null)
{ {
if (AlertManager.TryGet(alertType, out var alert)) if (AlertManager.TryGet(alertType, out var alert))
{ {
@@ -196,7 +196,7 @@ namespace Content.Shared.Alert
public struct AlertState public struct AlertState
{ {
public short? Severity; public short? Severity;
public ValueTuple<TimeSpan, TimeSpan>? Cooldown; public (TimeSpan, TimeSpan)? Cooldown;
public AlertType Type; public AlertType Type;
} }
} }

View File

@@ -14,9 +14,6 @@ namespace Content.Shared.Jittering
{ {
public override string Name => "Jittering"; public override string Name => "Jittering";
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan EndTime { get; set; }
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float Amplitude { get; set; } public float Amplitude { get; set; }
@@ -30,13 +27,11 @@ namespace Content.Shared.Jittering
[Serializable, NetSerializable] [Serializable, NetSerializable]
public class JitteringComponentState : ComponentState public class JitteringComponentState : ComponentState
{ {
public TimeSpan EndTime { get; }
public float Amplitude { get; } public float Amplitude { get; }
public float Frequency { get; } public float Frequency { get; }
public JitteringComponentState(TimeSpan endTime, float amplitude, float frequency) public JitteringComponentState(float amplitude, float frequency)
{ {
EndTime = endTime;
Amplitude = amplitude; Amplitude = amplitude;
Frequency = frequency; Frequency = frequency;
} }

View File

@@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.Alert;
using Content.Shared.StatusEffect;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -13,6 +15,7 @@ namespace Content.Shared.Jittering
public abstract class SharedJitteringSystem : EntitySystem public abstract class SharedJitteringSystem : EntitySystem
{ {
[Dependency] protected readonly IGameTiming GameTiming = default!; [Dependency] protected readonly IGameTiming GameTiming = default!;
[Dependency] protected readonly StatusEffectsSystem StatusEffects = default!;
public float MaxAmplitude = 300f; public float MaxAmplitude = 300f;
public float MinAmplitude = 1f; public float MinAmplitude = 1f;
@@ -20,11 +23,6 @@ namespace Content.Shared.Jittering
public float MaxFrequency = 10f; public float MaxFrequency = 10f;
public float MinFrequency = 1f; public float MinFrequency = 1f;
/// <summary>
/// List of jitter components to be removed, cached so we don't allocate it every tick.
/// </summary>
private readonly List<JitteringComponent> _removeList = new();
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<JitteringComponent, ComponentGetState>(OnGetState); SubscribeLocalEvent<JitteringComponent, ComponentGetState>(OnGetState);
@@ -33,7 +31,7 @@ namespace Content.Shared.Jittering
private void OnGetState(EntityUid uid, JitteringComponent component, ref ComponentGetState args) private void OnGetState(EntityUid uid, JitteringComponent component, ref ComponentGetState args)
{ {
args.State = new JitteringComponentState(component.EndTime, component.Amplitude, component.Frequency); args.State = new JitteringComponentState(component.Amplitude, component.Frequency);
} }
private void OnHandleState(EntityUid uid, JitteringComponent component, ref ComponentHandleState args) private void OnHandleState(EntityUid uid, JitteringComponent component, ref ComponentHandleState args)
@@ -41,7 +39,6 @@ namespace Content.Shared.Jittering
if (args.Current is not JitteringComponentState jitteringState) if (args.Current is not JitteringComponentState jitteringState)
return; return;
component.EndTime = jitteringState.EndTime;
component.Amplitude = jitteringState.Amplitude; component.Amplitude = jitteringState.Amplitude;
component.Frequency = jitteringState.Frequency; component.Frequency = jitteringState.Frequency;
} }
@@ -59,56 +56,26 @@ namespace Content.Shared.Jittering
/// <param name="amplitude">Jitteriness of the animation. See <see cref="MaxAmplitude"/> and <see cref="MinAmplitude"/>.</param> /// <param name="amplitude">Jitteriness of the animation. See <see cref="MaxAmplitude"/> and <see cref="MinAmplitude"/>.</param>
/// <param name="frequency">Frequency for jittering. See <see cref="MaxFrequency"/> and <see cref="MinFrequency"/>.</param> /// <param name="frequency">Frequency for jittering. See <see cref="MaxFrequency"/> and <see cref="MinFrequency"/>.</param>
/// <param name="forceValueChange">Whether to change any existing jitter value even if they're greater than the ones we're setting.</param> /// <param name="forceValueChange">Whether to change any existing jitter value even if they're greater than the ones we're setting.</param>
public void DoJitter(EntityUid uid, TimeSpan time, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false) /// <param name="status">The status effects component to modify.</param>
public void DoJitter(EntityUid uid, TimeSpan time, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false,
StatusEffectsComponent? status=null)
{ {
var jittering = EntityManager.EnsureComponent<JitteringComponent>(uid); if (!Resolve(uid, ref status, false))
return;
var endTime = GameTiming.CurTime + time;
amplitude = Math.Clamp(amplitude, MinAmplitude, MaxAmplitude); amplitude = Math.Clamp(amplitude, MinAmplitude, MaxAmplitude);
frequency = Math.Clamp(frequency, MinFrequency, MaxFrequency); frequency = Math.Clamp(frequency, MinFrequency, MaxFrequency);
if (forceValueChange || jittering.EndTime < endTime) if (StatusEffects.TryAddStatusEffect<JitteringComponent>(uid, "Jitter", time, status))
jittering.EndTime = endTime;
if(forceValueChange || jittering.Amplitude < amplitude)
jittering.Amplitude = amplitude;
if (forceValueChange || jittering.Frequency < frequency)
jittering.Frequency = frequency;
jittering.Dirty();
}
/// <summary>
/// Immediately stops any jitter animation from an entity.
/// </summary>
/// <param name="uid">The entity in question.</param>
public void StopJitter(EntityUid uid)
{
if (!EntityManager.HasComponent<JitteringComponent>(uid))
return;
EntityManager.RemoveComponent<JitteringComponent>(uid);
}
public override void Update(float frameTime)
{
foreach (var jittering in EntityManager.EntityQuery<JitteringComponent>())
{ {
if(jittering.EndTime <= GameTiming.CurTime) var jittering = EntityManager.GetComponent<JitteringComponent>(uid);
_removeList.Add(jittering);
if(forceValueChange || jittering.Amplitude < amplitude)
jittering.Amplitude = amplitude;
if (forceValueChange || jittering.Frequency < frequency)
jittering.Frequency = frequency;
} }
if (_removeList.Count == 0)
return;
foreach (var jittering in _removeList)
{
jittering.Owner.RemoveComponent<JitteringComponent>();
}
_removeList.Clear();
} }
} }
} }

View File

@@ -68,10 +68,7 @@ namespace Content.Shared.Nutrition.EntitySystems
CreamedEntity(uid, creamPied, args); CreamedEntity(uid, creamPied, args);
if (EntityManager.TryGetComponent(uid, out StunnableComponent? stun)) _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime));
{
_stunSystem.Paralyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime), stun);
}
} }
protected virtual void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) {} protected virtual void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) {}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.EffectBlocker; using Content.Shared.EffectBlocker;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable; using Content.Shared.Stunnable;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -17,6 +18,7 @@ namespace Content.Shared.Slippery
public abstract class SharedSlipperySystem : EntitySystem public abstract class SharedSlipperySystem : EntitySystem
{ {
[Dependency] private readonly SharedStunSystem _stunSystem = default!; [Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
private List<SlipperyComponent> _slipped = new(); private List<SlipperyComponent> _slipped = new();
@@ -30,7 +32,7 @@ namespace Content.Shared.Slippery
{ {
var otherUid = args.OtherFixture.Body.Owner.Uid; var otherUid = args.OtherFixture.Body.Owner.Uid;
if (!CanSlip(component, otherUid, out _)) return; if (!CanSlip(component, otherUid)) return;
if (!_slipped.Contains(component)) if (!_slipped.Contains(component))
_slipped.Add(component); _slipped.Add(component);
@@ -49,14 +51,13 @@ namespace Content.Shared.Slippery
} }
} }
public bool CanSlip(SlipperyComponent component, EntityUid uid, [NotNullWhen(true)] out StunnableComponent? stunnableComponent) public bool CanSlip(SlipperyComponent component, EntityUid uid)
{ {
if (!component.Slippery if (!component.Slippery
|| component.Owner.IsInContainer() || component.Owner.IsInContainer()
|| component.Slipped.Contains(uid) || component.Slipped.Contains(uid)
|| !EntityManager.TryGetComponent<StunnableComponent>(uid, out stunnableComponent)) || !_statusEffectsSystem.CanApplyEffect(uid, "Stun"))
{ {
stunnableComponent = null;
return false; return false;
} }
@@ -65,9 +66,9 @@ namespace Content.Shared.Slippery
private bool TrySlip(SlipperyComponent component, IPhysBody ourBody, IPhysBody otherBody) private bool TrySlip(SlipperyComponent component, IPhysBody ourBody, IPhysBody otherBody)
{ {
if (!CanSlip(component, otherBody.Owner.Uid, out var stun)) return false; if (!CanSlip(component, otherBody.Owner.Uid)) return false;
if (otherBody.LinearVelocity.Length < component.RequiredSlipSpeed || stun.KnockedDown) if (otherBody.LinearVelocity.Length < component.RequiredSlipSpeed)
{ {
return false; return false;
} }
@@ -86,7 +87,7 @@ namespace Content.Shared.Slippery
otherBody.LinearVelocity *= component.LaunchForwardsMultiplier; otherBody.LinearVelocity *= component.LaunchForwardsMultiplier;
_stunSystem.Paralyze(stun.Owner.Uid, TimeSpan.FromSeconds(5), stun); _stunSystem.TryParalyze(component.Owner.Uid, TimeSpan.FromSeconds(5));
component.Slipped.Add(otherBody.Owner.Uid); component.Slipped.Add(otherBody.Owner.Uid);
component.Dirty(); component.Dirty();

View File

@@ -0,0 +1,23 @@
using Content.Shared.Alert;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.StatusEffect
{
[Prototype("statusEffect")]
public class StatusEffectPrototype : IPrototype
{
[DataField("id", required: true)]
public string ID { get; } = default!;
[DataField("alert")]
public AlertType? Alert { get; }
/// <summary>
/// Whether a status effect should be able to apply to any entity,
/// regardless of whether it is in ALlowedEffects or not.
/// </summary>
[DataField("alwaysAllowed")]
public bool AlwaysAllowed { get; }
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.StatusEffect
{
[RegisterComponent]
[NetworkedComponent]
[Friend(typeof(StatusEffectsSystem))]
public class StatusEffectsComponent : Component
{
public override string Name => "StatusEffects";
public Dictionary<string, StatusEffectState> ActiveEffects = new();
/// <summary>
/// A list of status effect IDs to be allowed
/// </summary>
[DataField("allowed", required: true)]
public List<string> AllowedEffects = default!;
}
/// <summary>
/// Holds information about an active status effect.
/// </summary>
[Serializable, NetSerializable]
public class StatusEffectState
{
/// <summary>
/// The start and end times of the status effect.
/// </summary>
public (TimeSpan, TimeSpan) Cooldown;
/// <summary>
/// The name of the relevant component that
/// was added alongside the effect, if any.
/// </summary>
public string? RelevantComponent;
public StatusEffectState((TimeSpan, TimeSpan) cooldown, string? relevantComponent=null)
{
Cooldown = cooldown;
RelevantComponent = relevantComponent;
}
}
[Serializable, NetSerializable]
public class StatusEffectsComponentState : ComponentState
{
public Dictionary<string, StatusEffectState> ActiveEffects;
public List<string> AllowedEffects;
public StatusEffectsComponentState(Dictionary<string, StatusEffectState> activeEffects, List<string> allowedEffects)
{
ActiveEffects = activeEffects;
AllowedEffects = allowedEffects;
}
}
}

View File

@@ -0,0 +1,387 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Resources;
using Content.Shared.Alert;
using Robust.Shared.Exceptions;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.StatusEffect
{
public sealed class StatusEffectsSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StatusEffectsComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<StatusEffectsComponent, ComponentHandleState>(OnHandleState);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var curTime = _gameTiming.CurTime;
foreach (var status in EntityManager.EntityQuery<StatusEffectsComponent>(false))
{
if (status.ActiveEffects.Count == 0) continue;
foreach (var state in status.ActiveEffects.ToArray())
{
// if we're past the end point of the effect
if (_gameTiming.CurTime > state.Value.Cooldown.Item2)
{
TryRemoveStatusEffect(status.Owner.Uid, state.Key, status);
}
}
}
}
private void OnGetState(EntityUid uid, StatusEffectsComponent component, ref ComponentGetState args)
{
args.State = new StatusEffectsComponentState(component.ActiveEffects, component.AllowedEffects);
}
private void OnHandleState(EntityUid uid, StatusEffectsComponent component, ref ComponentHandleState args)
{
if (args.Current is StatusEffectsComponentState state)
{
component.AllowedEffects = state.AllowedEffects;
foreach (var effect in state.ActiveEffects)
{
// don't bother with anything if we already have it
if (component.ActiveEffects.ContainsKey(effect.Key))
{
component.ActiveEffects[effect.Key] = effect.Value;
continue;
}
var time = effect.Value.Cooldown.Item2 - effect.Value.Cooldown.Item1;
TryAddStatusEffect(uid, effect.Key, time);
}
}
}
/// <summary>
/// Tries to add a status effect to an entity, with a given component added as well.
/// </summary>
/// <param name="uid">The entity to add the effect to.</param>
/// <param name="key">The status effect ID to add.</param>
/// <param name="time">How long the effect should last for.</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if the effect could not be added or the component already exists, true otherwise.</returns>
/// <typeparam name="T">The component type to add and remove from the entity.</typeparam>
public bool TryAddStatusEffect<T>(EntityUid uid, string key, TimeSpan time,
StatusEffectsComponent? status=null,
SharedAlertsComponent? alerts=null)
where T: Component, new()
{
if (!Resolve(uid, ref status, false))
return false;
Resolve(uid, ref alerts, false);
if (TryAddStatusEffect(uid, key, time, status, alerts))
{
// If they already have the comp, we just won't bother updating anything.
if (!EntityManager.HasComponent<T>(uid))
{
var comp = EntityManager.AddComponent<T>(uid);
status.ActiveEffects[key].RelevantComponent = comp.Name;
}
return true;
}
return false;
}
/// <summary>
/// Tries to add a status effect to an entity with a certain timer.
/// </summary>
/// <param name="uid">The entity to add the effect to.</param>
/// <param name="key">The status effect ID to add.</param>
/// <param name="time">How long the effect should last for.</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if the effect could not be added, or if the effect already existed.</returns>
/// <remarks>
/// This obviously does not add any actual 'effects' on its own. Use the generic overload,
/// which takes in a component type, if you want to automatically add and remove a component.
///
/// If the effect already exists, it will simply replace the cooldown with the new one given.
/// If you want special 'effect merging' behavior, do it your own damn self!
/// </remarks>
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time,
StatusEffectsComponent? status=null,
SharedAlertsComponent? alerts=null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!CanApplyEffect(uid, key, status))
return false;
Resolve(uid, ref alerts, false);
// we already checked if it has the index in CanApplyEffect so a straight index and not tryindex here
// is fine
var proto = _prototypeManager.Index<StatusEffectPrototype>(key);
(TimeSpan, TimeSpan) cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time);
// If they already have this status effect, just bulldoze its cooldown in favor of the new one
// and keep the relevant component the same.
if (HasStatusEffect(uid, key, status))
{
status.ActiveEffects[key] = new StatusEffectState(cooldown, status.ActiveEffects[key].RelevantComponent);
}
else
{
status.ActiveEffects.Add(key, new StatusEffectState(cooldown, null));
}
if (proto.Alert != null && alerts != null)
{
alerts.ShowAlert(proto.Alert.Value, cooldown: GetAlertCooldown(uid, proto.Alert.Value, status));
}
status.Dirty();
// event?
return true;
}
/// <summary>
/// Finds the maximum cooldown among all status effects with the same alert
/// </summary>
/// <remarks>
/// This is mostly for stuns, since Stun and Knockdown share an alert key. Other times this pretty much
/// will not be useful.
/// </remarks>
private (TimeSpan, TimeSpan)? GetAlertCooldown(EntityUid uid, AlertType alert, StatusEffectsComponent status)
{
(TimeSpan, TimeSpan)? maxCooldown = null;
foreach (var kvp in status.ActiveEffects)
{
var proto = _prototypeManager.Index<StatusEffectPrototype>(kvp.Key);
if (proto.Alert == alert)
{
if (maxCooldown == null || kvp.Value.Cooldown.Item2 > maxCooldown.Value.Item2)
{
maxCooldown = kvp.Value.Cooldown;
}
}
}
return maxCooldown;
}
/// <summary>
/// Attempts to remove a status effect from an entity.
/// </summary>
/// <param name="uid">The entity to remove an effect from.</param>
/// <param name="key">The effect ID to remove.</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if the effect could not be removed, true otherwise.</returns>
/// <remarks>
/// Obviously this doesn't automatically clear any effects a status effect might have.
/// That's up to the removed component to handle itself when it's removed.
/// </remarks>
public bool TryRemoveStatusEffect(EntityUid uid, string key,
StatusEffectsComponent? status=null,
SharedAlertsComponent? alerts=null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!status.ActiveEffects.ContainsKey(key))
return false;
if (!_prototypeManager.TryIndex<StatusEffectPrototype>(key, out var proto))
return false;
Resolve(uid, ref alerts, false);
var state = status.ActiveEffects[key];
if (state.RelevantComponent != null)
{
var type = _componentFactory.GetRegistration(state.RelevantComponent).Type;
EntityManager.RemoveComponent(uid, type);
}
if (proto.Alert != null && alerts != null)
{
alerts.ClearAlert(proto.Alert.Value);
}
status.ActiveEffects.Remove(key);
status.Dirty();
// event?
return true;
}
/// <summary>
/// Tries to remove all status effects from a given entity.
/// </summary>
/// <param name="uid">The entity to remove effects from.</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if any status effects failed to be removed, true if they all did.</returns>
public bool TryRemoveAllStatusEffects(EntityUid uid,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
if (!Resolve(uid, ref status, false))
return false;
Resolve(uid, ref alerts, false);
bool failed = false;
foreach (var effect in status.ActiveEffects)
{
if(!TryRemoveStatusEffect(uid, effect.Key, status, alerts))
failed = true;
}
return failed;
}
/// <summary>
/// Returns whether a given entity has the status effect active.
/// </summary>
/// <param name="uid">The entity to check on.</param>
/// <param name="key">The status effect ID to check for</param>
/// <param name="status">The status effect component, should you already have it.</param>
public bool HasStatusEffect(EntityUid uid, string key,
StatusEffectsComponent? status=null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!status.ActiveEffects.ContainsKey(key))
return false;
return true;
}
/// <summary>
/// Returns whether a given entity can have a given effect applied to it.
/// </summary>
/// <param name="uid">The entity to check on.</param>
/// <param name="key">The status effect ID to check for</param>
/// <param name="status">The status effect component, should you already have it.</param>
public bool CanApplyEffect(EntityUid uid, string key,
StatusEffectsComponent? status = null)
{
// don't log since stuff calling this prolly doesn't care if we don't actually have it
if (!Resolve(uid, ref status, false))
return false;
if (!_prototypeManager.TryIndex<StatusEffectPrototype>(key, out var proto))
return false;
if (!status.AllowedEffects.Contains(key) && !proto.AlwaysAllowed)
return false;
return true;
}
/// <summary>
/// Tries to add to the timer of an already existing status effect.
/// </summary>
/// <param name="uid">The entity to add time to.</param>
/// <param name="key">The status effect to add time to.</param>
/// <param name="time">The amount of time to add.</param>
/// <param name="status">The status effect component, should you already have it.</param>
public bool TryAddTime(EntityUid uid, string key, TimeSpan time,
StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!HasStatusEffect(uid, key, status))
return false;
var timer = status.ActiveEffects[key].Cooldown;
timer.Item2 += time;
return true;
}
/// <summary>
/// Tries to remove time from the timer of an already existing status effect.
/// </summary>
/// <param name="uid">The entity to remove time from.</param>
/// <param name="key">The status effect to remove time from.</param>
/// <param name="time">The amount of time to add.</param>
/// <param name="status">The status effect component, should you already have it.</param>
public bool TryRemoveTime(EntityUid uid, string key, TimeSpan time,
StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!HasStatusEffect(uid, key, status))
return false;
var timer = status.ActiveEffects[key].Cooldown;
// what on earth are you doing, Gordon?
if (time > timer.Item2)
return false;
timer.Item2 -= time;
return true;
}
/// <summary>
/// Use if you want to set a cooldown directly.
/// </summary>
/// <remarks>
/// Not used internally; just sets it itself.
/// </remarks>
public bool TrySetTime(EntityUid uid, string key, TimeSpan time,
StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false))
return false;
if (!HasStatusEffect(uid, key, status))
return false;
status.ActiveEffects[key].Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time);
return true;
}
/// <summary>
/// Gets the cooldown for a given status effect on an entity.
/// </summary>
/// <param name="uid">The entity to check for status effects on.</param>
/// <param name="key">The status effect to get time for.</param>
/// <param name="time">Out var for the time, if it exists.</param>
/// <param name="status">The status effects component to use, if any.</param>
/// <returns>False if the status effect was not active, true otherwise.</returns>
public bool TryGetTime(EntityUid uid, string key,
[NotNullWhen(true)] out (TimeSpan, TimeSpan)? time,
StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false) || !HasStatusEffect(uid, key, status))
{
time = null;
return false;
}
time = status.ActiveEffects[key].Cooldown;
return true;
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Stunnable
{
[RegisterComponent]
[NetworkedComponent]
[Friend(typeof(SharedStunSystem))]
public class KnockedDownComponent : Component
{
public override string Name => "KnockedDown";
[DataField("helpInterval")]
public float HelpInterval { get; set; } = 1f;
[DataField("helpAttemptSound")]
public SoundSpecifier StunAttemptSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
[ViewVariables]
public float HelpTimer { get; set; } = 0f;
}
[Serializable, NetSerializable]
public class KnockedDownComponentState : ComponentState
{
public float HelpInterval { get; set; }
public float HelpTimer { get; set; }
public KnockedDownComponentState(float helpInterval, float helpTimer)
{
HelpInterval = helpInterval;
HelpTimer = helpTimer;
}
}
}

View File

@@ -10,6 +10,7 @@ using Content.Shared.Movement;
using Content.Shared.Movement.Components; using Content.Shared.Movement.Components;
using Content.Shared.Speech; using Content.Shared.Speech;
using Content.Shared.Standing; using Content.Shared.Standing;
using Content.Shared.StatusEffect;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -25,59 +26,94 @@ namespace Content.Shared.Stunnable
public abstract class SharedStunSystem : EntitySystem public abstract class SharedStunSystem : EntitySystem
{ {
[Dependency] private readonly StandingStateSystem _standingStateSystem = default!; [Dependency] private readonly StandingStateSystem _standingStateSystem = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffectSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<StunnableComponent, ComponentGetState>(OnGetState); SubscribeLocalEvent<KnockedDownComponent, ComponentInit>(OnKnockInit);
SubscribeLocalEvent<StunnableComponent, ComponentHandleState>(OnHandleState); SubscribeLocalEvent<KnockedDownComponent, ComponentRemove>(OnKnockRemove);
SubscribeLocalEvent<StunnableComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<SlowedDownComponent, ComponentInit>(OnSlowInit);
SubscribeLocalEvent<SlowedDownComponent, ComponentRemove>(OnSlowRemove);
SubscribeLocalEvent<SlowedDownComponent, ComponentGetState>(OnSlowGetState);
SubscribeLocalEvent<SlowedDownComponent, ComponentHandleState>(OnSlowHandleState);
SubscribeLocalEvent<KnockedDownComponent, ComponentGetState>(OnKnockGetState);
SubscribeLocalEvent<KnockedDownComponent, ComponentHandleState>(OnKnockHandleState);
// helping people up if they're knocked down
SubscribeLocalEvent<KnockedDownComponent, InteractHandEvent>(OnInteractHand);
// Attempt event subscriptions. // Attempt event subscriptions.
SubscribeLocalEvent<StunnableComponent, MovementAttemptEvent>(OnMoveAttempt); SubscribeLocalEvent<StunnedComponent, MovementAttemptEvent>(OnMoveAttempt);
SubscribeLocalEvent<StunnableComponent, InteractionAttemptEvent>(OnInteractAttempt); SubscribeLocalEvent<StunnedComponent, InteractionAttemptEvent>(OnInteractAttempt);
SubscribeLocalEvent<StunnableComponent, UseAttemptEvent>(OnUseAttempt); SubscribeLocalEvent<StunnedComponent, UseAttemptEvent>(OnUseAttempt);
SubscribeLocalEvent<StunnableComponent, ThrowAttemptEvent>(OnThrowAttempt); SubscribeLocalEvent<StunnedComponent, ThrowAttemptEvent>(OnThrowAttempt);
SubscribeLocalEvent<StunnableComponent, DropAttemptEvent>(OnDropAttempt); SubscribeLocalEvent<StunnedComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<StunnableComponent, PickupAttemptEvent>(OnPickupAttempt); SubscribeLocalEvent<StunnedComponent, PickupAttemptEvent>(OnPickupAttempt);
SubscribeLocalEvent<StunnableComponent, AttackAttemptEvent>(OnAttackAttempt); SubscribeLocalEvent<StunnedComponent, AttackAttemptEvent>(OnAttackAttempt);
SubscribeLocalEvent<StunnableComponent, EquipAttemptEvent>(OnEquipAttempt); SubscribeLocalEvent<StunnedComponent, EquipAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<StunnableComponent, UnequipAttemptEvent>(OnUnequipAttempt); SubscribeLocalEvent<StunnedComponent, UnequipAttemptEvent>(OnUnequipAttempt);
SubscribeLocalEvent<StunnableComponent, StandAttemptEvent>(OnStandAttempt);
} }
private void OnGetState(EntityUid uid, StunnableComponent stunnable, ref ComponentGetState args) private void OnSlowGetState(EntityUid uid, SlowedDownComponent component, ref ComponentGetState args)
{ {
args.State = new StunnableComponentState(stunnable.StunnedTimer, stunnable.KnockdownTimer, stunnable.SlowdownTimer, stunnable.WalkSpeedMultiplier, stunnable.RunSpeedMultiplier); args.State = new SlowedDownComponentState(component.SprintSpeedModifier, component.WalkSpeedModifier);
} }
private void OnHandleState(EntityUid uid, StunnableComponent stunnable, ref ComponentHandleState args) private void OnSlowHandleState(EntityUid uid, SlowedDownComponent component, ref ComponentHandleState args)
{ {
if (args.Current is not StunnableComponentState state) if (args.Current is SlowedDownComponentState state)
return;
stunnable.StunnedTimer = state.StunnedTimer;
stunnable.KnockdownTimer = state.KnockdownTimer;
stunnable.SlowdownTimer = state.SlowdownTimer;
stunnable.WalkSpeedMultiplier = state.WalkSpeedMultiplier;
stunnable.RunSpeedMultiplier = state.RunSpeedMultiplier;
if (EntityManager.TryGetComponent(uid, out MovementSpeedModifierComponent? movement))
movement.RefreshMovementSpeedModifiers();
}
private TimeSpan AdjustTime(TimeSpan time, (TimeSpan Start, TimeSpan End)? timer, float cap)
{
if (timer != null)
{ {
time = timer.Value.End - timer.Value.Start + time; component.SprintSpeedModifier = state.SprintSpeedModifier;
component.WalkSpeedModifier = state.WalkSpeedModifier;
} }
}
if (time.TotalSeconds > cap) private void OnKnockGetState(EntityUid uid, KnockedDownComponent component, ref ComponentGetState args)
time = TimeSpan.FromSeconds(cap); {
args.State = new KnockedDownComponentState(component.HelpInterval, component.HelpTimer);
}
return time; private void OnKnockHandleState(EntityUid uid, KnockedDownComponent component, ref ComponentHandleState args)
{
if (args.Current is KnockedDownComponentState state)
{
component.HelpInterval = state.HelpInterval;
component.HelpTimer = state.HelpTimer;
}
}
private void OnKnockInit(EntityUid uid, KnockedDownComponent component, ComponentInit args)
{
_standingStateSystem.Down(uid);
}
private void OnKnockRemove(EntityUid uid, KnockedDownComponent component, ComponentRemove args)
{
_standingStateSystem.Stand(uid);
}
private void OnSlowInit(EntityUid uid, SlowedDownComponent component, ComponentInit args)
{
// needs to be done so the client can also refresh when the addition is replicated,
// if the initial status effect addition wasn't predicted
if (EntityManager.TryGetComponent<MovementSpeedModifierComponent>(uid, out var move))
{
move.RefreshMovementSpeedModifiers();
}
}
private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentRemove args)
{
if (EntityManager.TryGetComponent<MovementSpeedModifierComponent>(uid, out var move))
{
component.SprintSpeedModifier = 1.0f;
component.WalkSpeedModifier = 1.0f;
move.RefreshMovementSpeedModifiers();
}
} }
// TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...) // TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...)
@@ -85,315 +121,141 @@ namespace Content.Shared.Stunnable
/// <summary> /// <summary>
/// Stuns the entity, disallowing it from doing many interactions temporarily. /// Stuns the entity, disallowing it from doing many interactions temporarily.
/// </summary> /// </summary>
public void Stun(EntityUid uid, TimeSpan time, public bool TryStun(EntityUid uid, TimeSpan time,
StunnableComponent? stunnable = null, StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null) SharedAlertsComponent? alerts = null)
{ {
if (!Resolve(uid, ref stunnable))
return;
time = AdjustTime(time, stunnable.StunnedTimer, stunnable.StunCap);
if (time <= TimeSpan.Zero) if (time <= TimeSpan.Zero)
return; return false;
stunnable.StunnedTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time); Resolve(uid, ref alerts, false);
SetAlert(uid, stunnable, alerts); return _statusEffectSystem.TryAddStatusEffect<StunnedComponent>(uid, "Stun", time, alerts: alerts);
stunnable.Dirty();
} }
/// <summary> /// <summary>
/// Knocks down the entity, making it fall to the ground. /// Knocks down the entity, making it fall to the ground.
/// </summary> /// </summary>
public void Knockdown(EntityUid uid, TimeSpan time, public bool TryKnockdown(EntityUid uid, TimeSpan time,
StunnableComponent? stunnable = null, StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null, SharedAlertsComponent? alerts = null)
StandingStateComponent? standingState = null,
SharedAppearanceComponent? appearance = null)
{ {
if (!Resolve(uid, ref stunnable))
return;
time = AdjustTime(time, stunnable.KnockdownTimer, stunnable.KnockdownCap);
if (time <= TimeSpan.Zero) if (time <= TimeSpan.Zero)
return; return false;
// Check if we can actually knock down the mob. Resolve(uid, ref alerts, false);
if (!_standingStateSystem.Down(uid, standingState:standingState, appearance:appearance))
return;
stunnable.KnockdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time); return _statusEffectSystem.TryAddStatusEffect<KnockedDownComponent>(uid, "KnockedDown", time, alerts: alerts);
SetAlert(uid, stunnable, alerts);
stunnable.Dirty();
} }
/// <summary> /// <summary>
/// Applies knockdown and stun to the entity temporarily. /// Applies knockdown and stun to the entity temporarily.
/// </summary> /// </summary>
public void Paralyze(EntityUid uid, TimeSpan time, public bool TryParalyze(EntityUid uid, TimeSpan time,
StunnableComponent? stunnable = null, StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null) SharedAlertsComponent? alerts = null)
{ {
if (!Resolve(uid, ref stunnable))
return;
// Optional component. // Optional component.
Resolve(uid, ref alerts, false); Resolve(uid, ref alerts, false);
Knockdown(uid, time, stunnable, alerts); return TryKnockdown(uid, time, status, alerts) && TryStun(uid, time, status, alerts);
Stun(uid, time, stunnable, alerts);
} }
/// <summary> /// <summary>
/// Slows down the mob's walking/running speed temporarily /// Slows down the mob's walking/running speed temporarily
/// </summary> /// </summary>
public void Slowdown(EntityUid uid, TimeSpan time, float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f, public bool TrySlowdown(EntityUid uid, TimeSpan time,
StunnableComponent? stunnable = null, float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f,
StatusEffectsComponent? status = null,
MovementSpeedModifierComponent? speedModifier = null, MovementSpeedModifierComponent? speedModifier = null,
SharedAlertsComponent? alerts = null) SharedAlertsComponent? alerts = null)
{ {
if (!Resolve(uid, ref stunnable))
return;
// "Optional" component. // "Optional" component.
Resolve(uid, ref speedModifier, false); Resolve(uid, ref speedModifier, false);
time = AdjustTime(time, stunnable.SlowdownTimer, stunnable.SlowdownCap);
if (time <= TimeSpan.Zero) if (time <= TimeSpan.Zero)
return; return false;
// Doesn't make much sense to have the "Slowdown" method speed up entities now does it? if (_statusEffectSystem.TryAddStatusEffect<SlowedDownComponent>(uid, "SlowedDown", time, status, alerts))
walkSpeedMultiplier = Math.Clamp(walkSpeedMultiplier, 0f, 1f);
runSpeedMultiplier = Math.Clamp(runSpeedMultiplier, 0f, 1f);
stunnable.WalkSpeedMultiplier *= walkSpeedMultiplier;
stunnable.RunSpeedMultiplier *= runSpeedMultiplier;
stunnable.SlowdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time);
speedModifier?.RefreshMovementSpeedModifiers();
SetAlert(uid, stunnable, alerts);
stunnable.Dirty();
}
public void Reset(EntityUid uid,
StunnableComponent? stunnable = null,
MovementSpeedModifierComponent? speedModifier = null,
StandingStateComponent? standingState = null,
SharedAppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref stunnable))
return;
// Optional component.
Resolve(uid, ref speedModifier, false);
stunnable.StunnedTimer = null;
stunnable.SlowdownTimer = null;
stunnable.KnockdownTimer = null;
speedModifier?.RefreshMovementSpeedModifiers();
_standingStateSystem.Stand(uid, standingState, appearance);
stunnable.Dirty();
}
private void SetAlert(EntityUid uid,
StunnableComponent? stunnable = null,
SharedAlertsComponent? alerts = null)
{
// This method is really just optional, doesn't matter if the entity doesn't support alerts.
if (!Resolve(uid, ref stunnable, ref alerts, false))
return;
if (GetTimers(uid, stunnable) is not {} timers)
return;
alerts.ShowAlert(AlertType.Stun, cooldown:timers);
}
private (TimeSpan, TimeSpan)? GetTimers(EntityUid uid, StunnableComponent? stunnable = null)
{
if (!Resolve(uid, ref stunnable))
return null;
// Don't do anything if no stuns are applied.
if (!stunnable.AnyStunActive)
return null;
TimeSpan start = TimeSpan.MaxValue, end = TimeSpan.MinValue;
if (stunnable.StunnedTimer != null)
{ {
if (stunnable.StunnedTimer.Value.Start < start) var slowed = EntityManager.GetComponent<SlowedDownComponent>(uid);
start = stunnable.StunnedTimer.Value.Start; // Doesn't make much sense to have the "TrySlowdown" method speed up entities now does it?
walkSpeedMultiplier = Math.Clamp(walkSpeedMultiplier, 0f, 1f);
runSpeedMultiplier = Math.Clamp(runSpeedMultiplier, 0f, 1f);
if (stunnable.StunnedTimer.Value.End > end) slowed.WalkSpeedModifier *= walkSpeedMultiplier;
end = stunnable.StunnedTimer.Value.End; slowed.SprintSpeedModifier *= runSpeedMultiplier;
speedModifier?.RefreshMovementSpeedModifiers();
return true;
} }
if (stunnable.KnockdownTimer != null) return false;
{
if (stunnable.KnockdownTimer.Value.Start < start)
start = stunnable.KnockdownTimer.Value.Start;
if (stunnable.KnockdownTimer.Value.End > end)
end = stunnable.KnockdownTimer.Value.End;
}
if (stunnable.SlowdownTimer != null)
{
if (stunnable.SlowdownTimer.Value.Start < start)
start = stunnable.SlowdownTimer.Value.Start;
if (stunnable.SlowdownTimer.Value.End > end)
end = stunnable.SlowdownTimer.Value.End;
}
return (start, end);
} }
private void OnInteractHand(EntityUid uid, StunnableComponent stunnable, InteractHandEvent args) private void OnInteractHand(EntityUid uid, KnockedDownComponent knocked, InteractHandEvent args)
{ {
if (args.Handled || stunnable.HelpTimer > 0f || !stunnable.KnockedDown) if (args.Handled || knocked.HelpTimer > 0f)
return; return;
// Set it to half the help interval so helping is actually useful... // Set it to half the help interval so helping is actually useful...
stunnable.HelpTimer = stunnable.HelpInterval/2f; knocked.HelpTimer = knocked.HelpInterval/2f;
stunnable.KnockdownTimer = (stunnable.KnockdownTimer!.Value.Start, stunnable.KnockdownTimer.Value.End - TimeSpan.FromSeconds(stunnable.HelpInterval)); _statusEffectSystem.TryRemoveTime(uid, "KnockedDown", TimeSpan.FromSeconds(knocked.HelpInterval));
SoundSystem.Play(Filter.Pvs(uid), stunnable.StunAttemptSound.GetSound(), uid, AudioHelpers.WithVariation(0.05f)); SoundSystem.Play(Filter.Pvs(uid), knocked.StunAttemptSound.GetSound(), uid, AudioHelpers.WithVariation(0.05f));
SetAlert(uid, stunnable); knocked.Dirty();
stunnable.Dirty();
args.Handled = true; args.Handled = true;
} }
public override void Update(float frameTime)
{
base.Update(frameTime);
var curTime = _gameTiming.CurTime;
foreach (var stunnable in EntityManager.EntityQuery<StunnableComponent>())
{
var uid = stunnable.Owner.Uid;
if(stunnable.HelpTimer > 0f)
// If it goes negative, that's okay.
stunnable.HelpTimer -= frameTime;
if (stunnable.StunnedTimer != null)
{
if (stunnable.StunnedTimer.Value.End <= curTime)
{
stunnable.StunnedTimer = null;
stunnable.Dirty();
}
}
if (stunnable.KnockdownTimer != null)
{
if (stunnable.KnockdownTimer.Value.End <= curTime)
{
stunnable.KnockdownTimer = null;
// Try to stand up the mob...
_standingStateSystem.Stand(uid);
stunnable.Dirty();
}
}
if (stunnable.SlowdownTimer != null)
{
if (stunnable.SlowdownTimer.Value.End <= curTime)
{
if (EntityManager.TryGetComponent(uid, out MovementSpeedModifierComponent? movement))
movement.RefreshMovementSpeedModifiers();
stunnable.SlowdownTimer = null;
stunnable.Dirty();
}
}
if (stunnable.AnyStunActive || !EntityManager.TryGetComponent(uid, out SharedAlertsComponent? status)
|| !status.IsShowingAlert(AlertType.Stun))
continue;
status.ClearAlert(AlertType.Stun);
}
}
#region Attempt Event Handling #region Attempt Event Handling
private void OnMoveAttempt(EntityUid uid, StunnableComponent stunnable, MovementAttemptEvent args) private void OnMoveAttempt(EntityUid uid, StunnedComponent stunned, MovementAttemptEvent args)
{ {
if (stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnInteractAttempt(EntityUid uid, StunnableComponent stunnable, InteractionAttemptEvent args) private void OnInteractAttempt(EntityUid uid, StunnedComponent stunned, InteractionAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnUseAttempt(EntityUid uid, StunnableComponent stunnable, UseAttemptEvent args) private void OnUseAttempt(EntityUid uid, StunnedComponent stunned, UseAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnThrowAttempt(EntityUid uid, StunnableComponent stunnable, ThrowAttemptEvent args) private void OnThrowAttempt(EntityUid uid, StunnedComponent stunned, ThrowAttemptEvent args)
{ {
if (stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnDropAttempt(EntityUid uid, StunnableComponent stunnable, DropAttemptEvent args) private void OnDropAttempt(EntityUid uid, StunnedComponent stunned, DropAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnPickupAttempt(EntityUid uid, StunnableComponent stunnable, PickupAttemptEvent args) private void OnPickupAttempt(EntityUid uid, StunnedComponent stunned, PickupAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnAttackAttempt(EntityUid uid, StunnableComponent stunnable, AttackAttemptEvent args) private void OnAttackAttempt(EntityUid uid, StunnedComponent stunned, AttackAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnEquipAttempt(EntityUid uid, StunnableComponent stunnable, EquipAttemptEvent args) private void OnEquipAttempt(EntityUid uid, StunnedComponent stunned, EquipAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
} }
private void OnUnequipAttempt(EntityUid uid, StunnableComponent stunnable, UnequipAttemptEvent args) private void OnUnequipAttempt(EntityUid uid, StunnedComponent stunned, UnequipAttemptEvent args)
{ {
if(stunnable.Stunned) args.Cancel();
args.Cancel();
}
private void OnStandAttempt(EntityUid uid, StunnableComponent stunnable, StandAttemptEvent args)
{
if(stunnable.KnockedDown)
args.Cancel();
} }
#endregion #endregion

View File

@@ -0,0 +1,33 @@
using System;
using Content.Shared.Movement.Components;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Stunnable
{
[RegisterComponent]
[NetworkedComponent]
[Friend(typeof(SharedStunSystem))]
public class SlowedDownComponent : Component, IMoveSpeedModifier
{
public override string Name => "SlowedDown";
public float SprintSpeedModifier { get; set; } = 0.5f;
public float WalkSpeedModifier { get; set; } = 0.5f;
}
[Serializable, NetSerializable]
public class SlowedDownComponentState : ComponentState
{
public float SprintSpeedModifier { get; set; }
public float WalkSpeedModifier { get; set; }
public SlowedDownComponentState(float sprintSpeedModifier, float walkSpeedModifier)
{
SprintSpeedModifier = sprintSpeedModifier;
WalkSpeedModifier = walkSpeedModifier;
}
}
}

View File

@@ -1,96 +0,0 @@
using System;
using Content.Shared.Movement.Components;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Stunnable
{
[Friend(typeof(SharedStunSystem))]
[RegisterComponent, NetworkedComponent]
public sealed class StunnableComponent : Component, IMoveSpeedModifier
{
public sealed override string Name => "Stunnable";
public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; set; }
public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; set; }
public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; set; }
[ViewVariables]
public float StunnedSeconds =>
StunnedTimer == null ? 0f : (float)(StunnedTimer.Value.End - StunnedTimer.Value.Start).TotalSeconds;
[ViewVariables]
public float KnockdownSeconds =>
KnockdownTimer == null ? 0f : (float)(KnockdownTimer.Value.End - KnockdownTimer.Value.Start).TotalSeconds;
[ViewVariables]
public float SlowdownSeconds =>
SlowdownTimer == null ? 0f : (float)(SlowdownTimer.Value.End - SlowdownTimer.Value.Start).TotalSeconds;
[ViewVariables]
public bool AnyStunActive => Stunned || KnockedDown || SlowedDown;
[ViewVariables]
public bool Stunned => StunnedTimer != null;
[ViewVariables]
public bool KnockedDown => KnockdownTimer != null;
[ViewVariables]
public bool SlowedDown => SlowdownTimer != null;
[DataField("stunCap")]
public float StunCap { get; set; } = 20f;
[DataField("knockdownCap")]
public float KnockdownCap { get; set; } = 20f;
[DataField("slowdownCap")]
public float SlowdownCap { get; set; } = 20f;
[DataField("helpInterval")]
public float HelpInterval { get; set; } = 1f;
[DataField("stunAttemptSound")]
public SoundSpecifier StunAttemptSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
[ViewVariables]
public float HelpTimer { get; set; } = 0f;
[ViewVariables]
public float WalkSpeedMultiplier { get; set; } = 0f;
[ViewVariables]
public float RunSpeedMultiplier { get; set; } = 0f;
[ViewVariables]
public float WalkSpeedModifier => (SlowedDown ? (WalkSpeedMultiplier <= 0f ? 0.5f : WalkSpeedMultiplier) : 1f);
[ViewVariables]
public float SprintSpeedModifier => (SlowedDown ? (RunSpeedMultiplier <= 0f ? 0.5f : RunSpeedMultiplier) : 1f);
}
[Serializable, NetSerializable]
public sealed class StunnableComponentState : ComponentState
{
public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; }
public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; }
public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; }
public float WalkSpeedMultiplier { get; }
public float RunSpeedMultiplier { get; }
public StunnableComponentState(
(TimeSpan Start, TimeSpan End)? stunnedTimer, (TimeSpan Start, TimeSpan End)? knockdownTimer,
(TimeSpan Start, TimeSpan End)? slowdownTimer, float walkSpeedMultiplier, float runSpeedMultiplier)
{
StunnedTimer = stunnedTimer;
KnockdownTimer = knockdownTimer;
SlowdownTimer = slowdownTimer;
WalkSpeedMultiplier = walkSpeedMultiplier;
RunSpeedMultiplier = runSpeedMultiplier;
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using Content.Shared.Movement.Components;
using Content.Shared.Sound;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Stunnable
{
[Friend(typeof(SharedStunSystem))]
[RegisterComponent, NetworkedComponent]
public sealed class StunnedComponent : Component
{
public sealed override string Name => "Stunned";
}
}

View File

@@ -51,8 +51,7 @@ namespace Content.Shared.Tabletop
protected static bool StunnedOrNoHands(IEntity playerEntity) protected static bool StunnedOrNoHands(IEntity playerEntity)
{ {
var stunned = playerEntity.TryGetComponent<StunnableComponent>(out var stun) && var stunned = playerEntity.HasComponent<StunnedComponent>();
stun.Stunned;
var hasHand = playerEntity.TryGetComponent<SharedHandsComponent>(out var handsComponent) && var hasHand = playerEntity.TryGetComponent<SharedHandsComponent>(out var handsComponent) &&
handsComponent.Hands.Count > 0; handsComponent.Hands.Count > 0;

View File

@@ -117,7 +117,11 @@
- type: HeatResistance - type: HeatResistance
- type: CombatMode - type: CombatMode
- type: Internals - type: Internals
- type: Stunnable - type: StatusEffects
allowed:
- Stun
- KnockedDown
- SlowedDown
- type: Examiner - type: Examiner
- type: UnarmedCombat - type: UnarmedCombat
range: 1.5 range: 1.5

View File

@@ -62,8 +62,11 @@
solution: bloodstream solution: bloodstream
- type: Bloodstream - type: Bloodstream
max_volume: 100 max_volume: 100
# StatusEffects - type: StatusEffects
- type: Stunnable allowed:
- Stun
- KnockedDown
- SlowedDown
# Other # Other
- type: Inventory - type: Inventory
- type: Clickable - type: Clickable

View File

@@ -0,0 +1,17 @@
# Status effect prototypes.
# Holds no actual logic, just some basic data about the effect.
- type: statusEffect
id: Stun
alert: Stun
- type: statusEffect
id: KnockedDown
alert: Stun
- type: statusEffect
id: SlowedDown
- type: statusEffect
id: Jitter
alwaysAllowed: true