Refactor standing to be ECS (#4142)

* Refactor standing to be ECS

E C S B A B Y

* DONE

* FIX IT FIX IT FIX IT

* IsDown event

* Change to methods

* Fixes

* Address some reviews

* Last of the Mohicans

* Final fixes

* Fix tests
This commit is contained in:
metalgearsloth
2021-06-27 19:02:46 +10:00
committed by GitHub
parent 97f4f0a9bd
commit 50cc526ebd
30 changed files with 328 additions and 268 deletions

View File

@@ -5,14 +5,13 @@ using Content.Server.Alert;
using Content.Server.Hands.Components;
using Content.Server.MobState.States;
using Content.Server.Pulling;
using Content.Server.Standing;
using Content.Server.Stunnable.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Buckle.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification.Managers;
using Content.Shared.Standing;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -130,12 +129,12 @@ namespace Content.Server.Buckle.Components
ownTransform.WorldRotation = strapTransform.WorldRotation;
break;
case StrapPosition.Stand:
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
ownTransform.WorldRotation = strapTransform.WorldRotation;
break;
case StrapPosition.Down:
EntitySystem.Get<StandingStateSystem>().Down(Owner, force: true);
ownTransform.WorldRotation = Angle.South;
EntitySystem.Get<StandingStateSystem>().Down(Owner, false, false);
ownTransform.LocalRotation = Angle.Zero;
break;
}
@@ -343,7 +342,7 @@ namespace Content.Server.Buckle.Components
}
else
{
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
}
_mobState?.CurrentState?.EnterState(Owner);

View File

@@ -50,6 +50,18 @@ namespace Content.Server.Hands
CommandBinds.Unregister<HandsSystem>();
}
protected override void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
{
base.DropAllItemsInHands(entity, doMobChecks);
if (!entity.TryGetComponent(out IHandsComponent? hands)) return;
foreach (var heldItem in hands.GetAllHeldItems())
{
hands.Drop(heldItem.Owner, doMobChecks, intentional:false);
}
}
//TODO: Actually shows all items/clothing/etc.
private void HandleExamined(EntityUid uid, HandsComponent component, ExaminedEvent args)
{

View File

@@ -1,7 +1,6 @@
#nullable enable
using System;
using System.Linq;
using Content.Server.Standing;
using Content.Server.Stunnable.Components;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
@@ -9,8 +8,8 @@ using Content.Shared.DragDrop;
using Content.Shared.Hands;
using Content.Shared.Instruments;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Notification.Managers;
using Content.Shared.Standing;
using Content.Shared.Throwing;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -357,7 +356,7 @@ namespace Content.Server.Instruments
if (mob != null)
{
if (Handheld)
EntitySystem.Get<StandingStateSystem>().DropAllItemsInHands(mob, false);
EntitySystem.Get<StandingStateSystem>().Down(mob, false);
if (mob.TryGetComponent(out StunnableComponent? stun))
{

View File

@@ -1,8 +1,5 @@
using Content.Server.Standing;
using Content.Server.Stunnable.Components;
using Content.Shared.MobState;
using Content.Server.Stunnable.Components;
using Content.Shared.MobState.State;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.MobState.States
@@ -13,17 +10,10 @@ namespace Content.Server.MobState.States
{
base.EnterState(entity);
if (entity.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
}
if (entity.TryGetComponent(out StunnableComponent? stun))
{
stun.CancelAll();
}
EntitySystem.Get<StandingStateSystem>().Down(entity);
}
}
}

View File

@@ -1,5 +1,4 @@
using Content.Server.Alert;
using Content.Server.Standing;
using Content.Server.Stunnable.Components;
using Content.Shared.Alert;
using Content.Shared.MobState;
@@ -15,11 +14,6 @@ namespace Content.Server.MobState.States
{
base.EnterState(entity);
if (entity.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
}
if (entity.TryGetComponent(out ServerAlertsComponent? status))
{
status.ShowAlert(AlertType.HumanDead);
@@ -29,8 +23,6 @@ namespace Content.Server.MobState.States
{
stun.CancelAll();
}
EntitySystem.Get<StandingStateSystem>().Down(entity);
}
}
}

View File

@@ -1,29 +1,15 @@
#nullable enable
using Content.Server.Alert;
using Content.Server.Standing;
using Content.Shared.Alert;
using Content.Shared.Damage.Components;
using Content.Shared.MobState;
using Content.Shared.MobState.State;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.MobState.States
{
public class NormalMobState : SharedNormalMobState
{
public override void EnterState(IEntity entity)
{
base.EnterState(entity);
EntitySystem.Get<StandingStateSystem>().Standing(entity);
if (entity.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(DamageStateVisuals.State, DamageState.Alive);
}
}
public override void UpdateState(IEntity entity, int threshold)
{
base.UpdateState(entity, threshold);

View File

@@ -3,15 +3,14 @@ using System.Threading.Tasks;
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Paper;
using Content.Server.Standing;
using Content.Server.Storage.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Body.Components;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Morgue;
using Content.Shared.Notification.Managers;
using Content.Shared.Standing;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
@@ -39,7 +38,7 @@ namespace Content.Server.Morgue.Components
{
base.Initialize();
_appearance?.SetData(BodyBagVisuals.Label, false);
LabelContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, "body_bag_label", out _);
LabelContainer = Owner.EnsureContainer<ContainerSlot>("body_bag_label", out _);
}
protected override bool AddToContents(IEntity entity)

View File

@@ -131,11 +131,11 @@ namespace Content.Server.Morgue.Components
}
victim.PopupMessageOtherClients(Loc.GetString("crematorium-entity-storage-component-suicide-message-others", ("victim", victim)));
EntitySystem.Get<SharedStandingStateSystem>().Down(victim, false, false, true);
if (CanInsert(victim))
{
Insert(victim);
EntitySystem.Get<StandingStateSystem>().Down(victim, false);
}
else
{

View File

@@ -1,5 +1,4 @@
#nullable enable
using Content.Server.Standing;
using Content.Server.Storage.Components;
using Content.Shared.Body.Components;
using Content.Shared.Directions;
@@ -9,6 +8,7 @@ using Content.Shared.Interaction.Helpers;
using Content.Shared.Morgue;
using Content.Shared.Notification.Managers;
using Content.Shared.Physics;
using Content.Shared.Standing;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
@@ -51,7 +51,7 @@ namespace Content.Server.Morgue.Components
{
base.Initialize();
Appearance?.SetData(MorgueVisuals.Open, false);
TrayContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, "morgue_tray", out _);
TrayContainer = Owner.EnsureContainer<ContainerSlot>("morgue_tray", out _);
}
public override Vector2 ContentsDumpPosition()

View File

@@ -1,83 +0,0 @@
#nullable enable
using Content.Server.Hands.Components;
using Content.Shared.Audio;
using Content.Shared.Rotation;
using Content.Shared.Standing;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.Standing
{
[UsedImplicitly]
public class StandingStateSystem : SharedStandingStateSystem
{
protected override bool OnDown(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false)
{
if (!entity.TryGetComponent(out AppearanceComponent? appearance))
{
return false;
}
var newState = RotationState.Horizontal;
appearance.TryGetData<RotationState>(RotationVisuals.RotationState, out var oldState);
if (newState != oldState)
{
appearance.SetData(RotationVisuals.RotationState, newState);
if (playSound)
{
var file = AudioHelpers.GetRandomFileFromSoundCollection("bodyfall");
SoundSystem.Play(Filter.Pvs(entity), file, entity, AudioHelpers.WithVariation(0.25f));
}
}
return true;
}
protected override bool OnStand(IEntity entity)
{
if (!entity.TryGetComponent(out AppearanceComponent? appearance)) return false;
appearance.TryGetData<RotationState>(RotationVisuals.RotationState, out var oldState);
var newState = RotationState.Vertical;
if (newState == oldState) return false;
appearance.SetData(RotationVisuals.RotationState, newState);
return true;
}
public override void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
{
base.DropAllItemsInHands(entity, doMobChecks);
if (!entity.TryGetComponent(out IHandsComponent? hands)) return;
foreach (var heldItem in hands.GetAllHeldItems())
{
hands.Drop(heldItem.Owner, doMobChecks, intentional:false);
}
}
//TODO: RotationState can be null and I want to burn all lifeforms in the universe for this!!!
//If you use these it's atleast slightly less painful (null is treated as false)
public bool IsStanding(IEntity entity)
{
return entity.TryGetComponent<AppearanceComponent>(out var appearance)
&& appearance.TryGetData<RotationState>(RotationVisuals.RotationState, out var rotation)
&& rotation == RotationState.Vertical;
}
public bool IsDown(IEntity entity)
{
return entity.TryGetComponent<AppearanceComponent>(out var appearance)
&& appearance.TryGetData<RotationState>(RotationVisuals.RotationState, out var rotation)
&& rotation == RotationState.Horizontal;
}
}
}

View File

@@ -1,11 +1,10 @@
#nullable enable
using Content.Server.Act;
using Content.Server.Notification;
using Content.Server.Standing;
using Content.Shared.Audio;
using Content.Shared.MobState;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
@@ -28,7 +27,7 @@ namespace Content.Server.Stunnable.Components
protected override void OnKnockdownEnd()
{
if(Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
}
public void CancelAll()
@@ -46,7 +45,7 @@ namespace Content.Server.Stunnable.Components
if (KnockedDown &&
Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
{
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
}
KnockdownTimer = null;