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:
@@ -1,6 +1,6 @@
|
||||
using Content.Client.Standing;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState.State;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -16,25 +16,6 @@ namespace Content.Client.MobState.States
|
||||
{
|
||||
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
|
||||
}
|
||||
|
||||
EntitySystem.Get<StandingStateSystem>().Down(entity);
|
||||
|
||||
if (entity.TryGetComponent(out PhysicsComponent? physics))
|
||||
{
|
||||
physics.CanCollide = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExitState(IEntity entity)
|
||||
{
|
||||
base.ExitState(entity);
|
||||
|
||||
EntitySystem.Get<StandingStateSystem>().Standing(entity);
|
||||
|
||||
if (entity.TryGetComponent(out PhysicsComponent? physics))
|
||||
{
|
||||
physics.CanCollide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,5 @@ namespace Content.Client.MobState.States
|
||||
{
|
||||
public class NormalMobState : SharedNormalMobState
|
||||
{
|
||||
public override void EnterState(IEntity entity)
|
||||
{
|
||||
base.EnterState(entity);
|
||||
|
||||
if (entity.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(DamageStateVisuals.State, DamageState.Alive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using Content.Shared.Rotation;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Standing
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
template: HumanoidTemplate
|
||||
preset: HumanPreset
|
||||
centerSlot: torso
|
||||
- type: StandingState
|
||||
";
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Content.IntegrationTests.Tests.Buckle
|
||||
template: HumanoidTemplate
|
||||
preset: HumanPreset
|
||||
centerSlot: torso
|
||||
- type: StandingState
|
||||
|
||||
- type: entity
|
||||
name: {StrapDummyId}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Content.Shared.Body.Components
|
||||
if (part.PartType == BodyPartType.Leg &&
|
||||
GetPartsOfType(BodyPartType.Leg).ToArray().Length == 0)
|
||||
{
|
||||
EntitySystem.Get<SharedStandingStateSystem>().Down(Owner);
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner);
|
||||
}
|
||||
|
||||
// creadth: immediately kill entity if last vital part removed
|
||||
|
||||
@@ -48,10 +48,7 @@ namespace Content.Shared.Buckle.Components
|
||||
return !Buckled;
|
||||
}
|
||||
|
||||
bool IEffectBlocker.CanFall()
|
||||
{
|
||||
return !Buckled;
|
||||
}
|
||||
bool IEffectBlocker.CanFall() => !Buckled;
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEvent args)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
@@ -10,6 +11,24 @@ namespace Content.Shared.Buckle
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedBuckleComponent, PreventCollideEvent>(PreventCollision);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, DownAttemptEvent>(HandleDown);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, StandAttemptEvent>(HandleStand);
|
||||
}
|
||||
|
||||
private void HandleStand(EntityUid uid, SharedBuckleComponent component, StandAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDown(EntityUid uid, SharedBuckleComponent component, DownAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void PreventCollision(EntityUid uid, SharedBuckleComponent component, PreventCollideEvent args)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -23,6 +23,38 @@ namespace Content.Shared.Hands
|
||||
SubscribeNetworkEvent<RequestDropHeldEntityEvent>(HandleDrop);
|
||||
}
|
||||
|
||||
public void DropHandItems(IEntity entity, bool doMobChecks = true)
|
||||
{
|
||||
if (!entity.TryGetComponent(out SharedHandsComponent? handsComponent)) return;
|
||||
DropHandItems(handsComponent, doMobChecks);
|
||||
}
|
||||
|
||||
private void DropHandItems(SharedHandsComponent handsComponent, bool doMobChecks = true)
|
||||
{
|
||||
var msg = new DropHandItemsAttemptEvent();
|
||||
var entity = handsComponent.Owner;
|
||||
var uid = entity.Uid;
|
||||
var eventBus = EntityManager.EventBus;
|
||||
|
||||
eventBus.RaiseLocalEvent(uid, msg);
|
||||
|
||||
if (msg.Cancelled) return;
|
||||
|
||||
if (entity.TryGetContainerMan(out var containerManager))
|
||||
{
|
||||
var parentMsg = new ContainedEntityDropHandItemsAttemptEvent(uid);
|
||||
eventBus.RaiseLocalEvent(containerManager.Owner.Uid, parentMsg);
|
||||
|
||||
if (parentMsg.Cancelled) return;
|
||||
}
|
||||
|
||||
DropAllItemsInHands(entity, doMobChecks);
|
||||
}
|
||||
|
||||
protected virtual void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
|
||||
{
|
||||
}
|
||||
|
||||
private void HandleSetHand(RequestSetHandEvent msg, EntitySessionEventArgs eventArgs)
|
||||
{
|
||||
var entity = eventArgs.SenderSession?.AttachedEntity;
|
||||
@@ -46,6 +78,18 @@ namespace Content.Shared.Hands
|
||||
protected abstract void HandleContainerModified(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args);
|
||||
}
|
||||
|
||||
public sealed class ContainedEntityDropHandItemsAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public EntityUid EntityUid { get; }
|
||||
|
||||
public ContainedEntityDropHandItemsAttemptEvent(EntityUid uid)
|
||||
{
|
||||
EntityUid = uid;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DropHandItemsAttemptEvent : CancellableEntityEventArgs {}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class RequestSetHandEvent : EntityEventArgs
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -20,13 +21,20 @@ namespace Content.Shared.MobState.State
|
||||
{
|
||||
status.ShowAlert(AlertType.HumanCrit); // TODO: combine humancrit-0 and humancrit-1 into a gif and display it
|
||||
}
|
||||
|
||||
EntitySystem.Get<StandingStateSystem>().Down(entity);
|
||||
|
||||
if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExitState(IEntity entity)
|
||||
{
|
||||
base.ExitState(entity);
|
||||
|
||||
EntitySystem.Get<SharedStandingStateSystem>().Standing(entity);
|
||||
EntitySystem.Get<StandingStateSystem>().Stand(entity);
|
||||
}
|
||||
|
||||
public override bool CanInteract()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.MobState.State
|
||||
{
|
||||
@@ -11,6 +13,18 @@ namespace Content.Shared.MobState.State
|
||||
base.EnterState(entity);
|
||||
var wake = entity.EnsureComponent<CollisionWakeComponent>();
|
||||
wake.Enabled = true;
|
||||
var standingState = EntitySystem.Get<StandingStateSystem>();
|
||||
standingState.Down(entity);
|
||||
|
||||
if (standingState.IsDown(entity) && entity.TryGetComponent(out PhysicsComponent? physics))
|
||||
{
|
||||
physics.CanCollide = false;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(DamageStateVisuals.State, DamageState.Dead);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExitState(IEntity entity)
|
||||
@@ -20,6 +34,14 @@ namespace Content.Shared.MobState.State
|
||||
{
|
||||
entity.RemoveComponent<CollisionWakeComponent>();
|
||||
}
|
||||
|
||||
var standingState = EntitySystem.Get<StandingStateSystem>();
|
||||
standingState.Stand(entity);
|
||||
|
||||
if (!standingState.IsDown(entity) && entity.TryGetComponent(out PhysicsComponent? physics))
|
||||
{
|
||||
physics.CanCollide = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanInteract()
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Shared.MobState.State
|
||||
{
|
||||
@@ -9,6 +12,17 @@ namespace Content.Shared.MobState.State
|
||||
{
|
||||
protected override DamageState DamageState => DamageState.Alive;
|
||||
|
||||
public override void EnterState(IEntity entity)
|
||||
{
|
||||
base.EnterState(entity);
|
||||
EntitySystem.Get<StandingStateSystem>().Stand(entity);
|
||||
|
||||
if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(DamageStateVisuals.State, DamageState.Alive);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanInteract()
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace Content.Shared.NetIDs
|
||||
public const uint LIGHT_REPLACER = 1090;
|
||||
public const uint SINGULARITY_DISTORTION = 1091;
|
||||
public const uint GRAVITY = 1092;
|
||||
public const uint STANDING_STATE = 1093;
|
||||
|
||||
// Net IDs for integration tests.
|
||||
public const uint PREDICTION_TEST = 10001;
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
#nullable enable
|
||||
using Content.Shared.EffectBlocker;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Standing
|
||||
{
|
||||
public abstract class SharedStandingStateSystem : EntitySystem
|
||||
{
|
||||
protected abstract bool OnDown(IEntity entity, bool playSound = true, bool dropItems = true,
|
||||
bool force = false);
|
||||
|
||||
protected abstract bool OnStand(IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// Set's the mob standing state to down.
|
||||
/// </summary>
|
||||
/// <param name="entity">The mob in question</param>
|
||||
/// <param name="playSound">Whether to play a sound when falling down or not</param>
|
||||
/// <param name="dropItems">Whether to make the mob drop all the items on his hands</param>
|
||||
/// <param name="force">Whether or not to check if the entity can fall.</param>
|
||||
/// <returns>False if the mob was already downed or couldn't set the state</returns>
|
||||
public bool Down(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false)
|
||||
{
|
||||
if (dropItems)
|
||||
{
|
||||
DropAllItemsInHands(entity, false);
|
||||
}
|
||||
|
||||
if (!force && !EffectBlockerSystem.CanFall(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return OnDown(entity, playSound, dropItems, force);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the mob's standing state to standing.
|
||||
/// </summary>
|
||||
/// <param name="entity">The mob in question.</param>
|
||||
/// <returns>False if the mob was already standing or couldn't set the state</returns>
|
||||
public bool Standing(IEntity entity)
|
||||
{
|
||||
return OnStand(entity);
|
||||
}
|
||||
|
||||
public virtual void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Content.Shared/Standing/StandingStateComponent.cs
Normal file
54
Content.Shared/Standing/StandingStateComponent.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Content.Shared.EffectBlocker;
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Standing
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class StandingStateComponent : Component, IEffectBlocker
|
||||
{
|
||||
public override string Name => "StandingState";
|
||||
|
||||
public override uint? NetID => ContentNetIDs.STANDING_STATE;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("downSoundCollection")]
|
||||
public string? DownSoundCollection { get; } = "BodyFall";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("standing")]
|
||||
public bool Standing { get; set; } = true;
|
||||
|
||||
public bool CanFall() => Standing;
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new StandingComponentState(Standing);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
if (curState is not StandingComponentState state) return;
|
||||
|
||||
Standing = state.Standing;
|
||||
}
|
||||
|
||||
// I'm not calling it StandingStateComponentState
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class StandingComponentState : ComponentState
|
||||
{
|
||||
public bool Standing { get; }
|
||||
|
||||
public StandingComponentState(bool standing) : base(ContentNetIDs.STANDING_STATE)
|
||||
{
|
||||
Standing = standing;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
Content.Shared/Standing/StandingStateSystem.cs
Normal file
126
Content.Shared/Standing/StandingStateSystem.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Rotation;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Shared.Standing
|
||||
{
|
||||
public sealed class StandingStateSystem : EntitySystem
|
||||
{
|
||||
public bool IsDown(IEntity entity)
|
||||
{
|
||||
if (entity.TryGetComponent(out StandingStateComponent? standingState) &&
|
||||
standingState.Standing) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Down(IEntity entity, bool playSound = true, bool dropHeldItems = true)
|
||||
{
|
||||
if (!entity.TryGetComponent(out StandingStateComponent? comp)) return;
|
||||
Down(comp, playSound, dropHeldItems);
|
||||
}
|
||||
|
||||
public void Stand(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out StandingStateComponent? comp)) return;
|
||||
Stand(comp);
|
||||
}
|
||||
|
||||
public void Down(StandingStateComponent component, bool playSound = true, bool dropHeldItems = true)
|
||||
{
|
||||
if (!component.Standing) return;
|
||||
|
||||
var entity = component.Owner;
|
||||
var uid = entity.Uid;
|
||||
|
||||
// This is just to avoid most callers doing this manually saving boilerplate
|
||||
// 99% of the time you'll want to drop items but in some scenarios (e.g. buckling) you don't want to.
|
||||
// We do this BEFORE downing because something like buckle may be blocking downing but we want to drop hand items anyway
|
||||
// and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
|
||||
if (dropHeldItems)
|
||||
{
|
||||
Get<SharedHandsSystem>().DropHandItems(entity, false);
|
||||
}
|
||||
|
||||
var msg = new DownAttemptEvent();
|
||||
EntityManager.EventBus.RaiseLocalEvent(uid, msg);
|
||||
|
||||
if (msg.Cancelled) return;
|
||||
|
||||
component.Standing = false;
|
||||
component.Dirty();
|
||||
EntityManager.EventBus.RaiseLocalEvent(uid, new DownedEvent());
|
||||
|
||||
// Seemed like the best place to put it
|
||||
if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(RotationVisuals.RotationState, RotationState.Horizontal);
|
||||
}
|
||||
|
||||
// Currently shit is only downed by server but when it's predicted we can probably only play this on server / client
|
||||
var sound = component.DownSoundCollection;
|
||||
|
||||
if (playSound && !string.IsNullOrEmpty(sound))
|
||||
{
|
||||
var file = AudioHelpers.GetRandomFileFromSoundCollection(sound);
|
||||
SoundSystem.Play(Filter.Pvs(entity), file, entity, AudioHelpers.WithVariation(0.25f));
|
||||
}
|
||||
}
|
||||
|
||||
public void Stand(StandingStateComponent component)
|
||||
{
|
||||
if (component.Standing) return;
|
||||
|
||||
var entity = component.Owner;
|
||||
var uid = entity.Uid;
|
||||
|
||||
var msg = new StandAttemptEvent();
|
||||
EntityManager.EventBus.RaiseLocalEvent(uid, msg);
|
||||
|
||||
if (msg.Cancelled) return;
|
||||
|
||||
component.Standing = true;
|
||||
component.Dirty();
|
||||
EntityManager.EventBus.RaiseLocalEvent(uid, new StoodEvent());
|
||||
|
||||
if (entity.TryGetComponent(out SharedAppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(RotationVisuals.RotationState, RotationState.Vertical);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a down attempt.
|
||||
/// </summary>
|
||||
public sealed class DownAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a stand attempt.
|
||||
/// </summary>
|
||||
public sealed class StandAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity becomes standing
|
||||
/// </summary>
|
||||
public sealed class StoodEvent : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity is not standing
|
||||
/// </summary>
|
||||
public sealed class DownedEvent : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@
|
||||
- type: Grammar
|
||||
attributes:
|
||||
proper: true
|
||||
|
||||
- type: StandingState
|
||||
|
||||
- type: entity
|
||||
save: false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- type: soundCollection
|
||||
id: bodyfall
|
||||
id: BodyFall
|
||||
files:
|
||||
- /Audio/Effects/bodyfall1.ogg
|
||||
- /Audio/Effects/bodyfall2.ogg
|
||||
|
||||
Reference in New Issue
Block a user