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:
@@ -13,7 +13,7 @@ namespace Content.Server.Stunnable.Components
|
||||
// TODO: Can probably predict this.
|
||||
public override string Name => "StunOnCollide";
|
||||
|
||||
// See stunnable for what these do
|
||||
// See stunsystem for what these do
|
||||
[DataField("stunAmount")]
|
||||
public int StunAmount;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.Stunnable.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -17,6 +18,7 @@ namespace Content.Server.Stunnable
|
||||
internal sealed class StunOnCollideSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -28,7 +30,7 @@ namespace Content.Server.Stunnable
|
||||
{
|
||||
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;
|
||||
StandingStateComponent? standingState = null;
|
||||
@@ -38,13 +40,13 @@ namespace Content.Server.Stunnable
|
||||
// Let the actual methods log errors for these.
|
||||
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,
|
||||
alerts, standingState, appearance);
|
||||
_stunSystem.TryKnockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount),
|
||||
status, alerts);
|
||||
|
||||
_stunSystem.Slowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount),
|
||||
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, stunnableComponent, speedModifier, alerts);
|
||||
_stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount),
|
||||
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, speedModifier, alerts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Act;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -21,28 +22,30 @@ namespace Content.Server.Stunnable
|
||||
{
|
||||
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))
|
||||
return;
|
||||
|
||||
Paralyze(uid, TimeSpan.FromSeconds(4f), stunnable);
|
||||
if (!TryParalyze(uid, TimeSpan.FromSeconds(4f), status))
|
||||
return;
|
||||
|
||||
var source = args.Source;
|
||||
var target = args.Target;
|
||||
|
||||
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)
|
||||
{
|
||||
// TODO: Use PopupSystem
|
||||
source.PopupMessageOtherClients(Loc.GetString("stunnable-component-disarm-success-others", ("source", source.Name), ("target", target.Name)));
|
||||
source.PopupMessageCursor(Loc.GetString("stunnable-component-disarm-success", ("target", target.Name)));
|
||||
source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", source.Name), ("target", target.Name)));
|
||||
source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", target.Name)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Jittering;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -25,6 +27,7 @@ namespace Content.Server.Stunnable
|
||||
public class StunbatonSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
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))
|
||||
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)
|
||||
@@ -119,26 +119,27 @@ namespace Content.Server.Stunnable
|
||||
|
||||
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.
|
||||
|
||||
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))
|
||||
_stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable);
|
||||
_stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status);
|
||||
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
|
||||
{
|
||||
if (_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown))
|
||||
_stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable);
|
||||
_stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status);
|
||||
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))
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user