From ea581e67c864940611173276b44cade8c5bef6a4 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 4 Apr 2019 19:43:01 +0200 Subject: [PATCH] Correctly implement movement blocking and undo that appearance mess. --- .../Components/Mobs/DamageStates.cs | 54 ++++++++----------- .../Components/Mobs/SpeciesComponent.cs | 29 +++++----- .../Movement/PlayerInputMoverComponent.cs | 6 --- .../GameObjects/EntitySystems/MoverSystem.cs | 2 +- 4 files changed, 35 insertions(+), 56 deletions(-) diff --git a/Content.Server/GameObjects/Components/Mobs/DamageStates.cs b/Content.Server/GameObjects/Components/Mobs/DamageStates.cs index 8329b3f701..e38fdf1e98 100644 --- a/Content.Server/GameObjects/Components/Mobs/DamageStates.cs +++ b/Content.Server/GameObjects/Components/Mobs/DamageStates.cs @@ -1,9 +1,7 @@ -using Content.Server.GameObjects.Components.Movement; -using Content.Server.GameObjects.EntitySystems; +using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects.Components.Mobs; using SS14.Server.GameObjects; using SS14.Shared.Interfaces.GameObjects; -using SS14.Shared.Maths; namespace Content.Server.GameObjects { @@ -11,10 +9,10 @@ namespace Content.Server.GameObjects /// Defines the blocking effect of each damage state, and what effects to apply upon entering or exiting the state /// public interface DamageState : IActionBlocker - { - void EnterState(IEntity entity, AppearanceComponent appearance); + { + void EnterState(IEntity entity); - void ExitState(IEntity entity, AppearanceComponent appearance); + void ExitState(IEntity entity); } /// @@ -22,9 +20,13 @@ namespace Content.Server.GameObjects /// public struct NormalState : DamageState { - public void EnterState(IEntity entity, AppearanceComponent appearance) {} + public void EnterState(IEntity entity) + { + } - public void ExitState(IEntity entity, AppearanceComponent appearance) {} + public void ExitState(IEntity entity) + { + } bool IActionBlocker.CanInteract() { @@ -47,20 +49,12 @@ namespace Content.Server.GameObjects /// public struct CriticalState : DamageState { - public void EnterState(IEntity entity, AppearanceComponent appearance) { - if (!entity.TryGetComponent(out var mover)) - { - return; - } - mover.Disabled = true; + public void EnterState(IEntity entity) + { } - public void ExitState(IEntity entity, AppearanceComponent appearance) { - if (!entity.TryGetComponent(out var mover)) - { - return; - } - mover.Disabled = false; + public void ExitState(IEntity entity) + { } bool IActionBlocker.CanInteract() @@ -84,26 +78,22 @@ namespace Content.Server.GameObjects /// public struct DeadState : DamageState { - public void EnterState(IEntity entity, AppearanceComponent appearance) + public void EnterState(IEntity entity) { - var newstate = SpeciesComponent.MobState.Down; - appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate); - if (!entity.TryGetComponent(out var mover)) + if (entity.TryGetComponent(out AppearanceComponent appearance)) { - return; + var newState = SharedSpeciesComponent.MobState.Down; + appearance.SetData(SharedSpeciesComponent.MobVisuals.RotationState, newState); } - mover.Disabled = true; } - public void ExitState(IEntity entity, AppearanceComponent appearance) + public void ExitState(IEntity entity) { - var newstate = SpeciesComponent.MobState.Stand; - appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate); - if (!entity.TryGetComponent(out var mover)) + if (entity.TryGetComponent(out AppearanceComponent appearance)) { - return; + var newState = SharedSpeciesComponent.MobState.Stand; + appearance.SetData(SharedSpeciesComponent.MobVisuals.RotationState, newState); } - mover.Disabled = false; } bool IActionBlocker.CanInteract() diff --git a/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs b/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs index 0ddc8edca4..f8a335e301 100644 --- a/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs @@ -29,30 +29,24 @@ namespace Content.Server.GameObjects /// private DamageTemplates DamageTemplate; - AppearanceComponent Appearance; - /// /// Variable for serialization /// private string templatename; - public override void Initialize() - { - base.Initialize(); - Appearance = Owner.GetComponent(); - } - public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataField(ref templatename, "Template", "Human"); - Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Server").GetType("Content.Server.GameObjects." + templatename); - DamageTemplate = (DamageTemplates)Activator.CreateInstance(type); + Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Server") + .GetType("Content.Server.GameObjects." + templatename); + DamageTemplate = (DamageTemplates) Activator.CreateInstance(type); } - public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) + public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, + IComponent component = null) { switch (message) { @@ -87,14 +81,15 @@ namespace Content.Server.GameObjects void IOnDamageBehavior.OnDamageThresholdPassed(object damageable, DamageThresholdPassedEventArgs e) { - DamageableComponent damage = (DamageableComponent)damageable; + DamageableComponent damage = (DamageableComponent) damageable; - if(e.DamageThreshold.ThresholdType != ThresholdType.HUDUpdate) + if (e.DamageThreshold.ThresholdType != ThresholdType.HUDUpdate) { ChangeDamageState(DamageTemplate.CalculateDamageState(damage)); } - if (Owner.TryGetComponent(out BasicActorComponent actor)) //specifies if we have a client to update the hud for + if (Owner.TryGetComponent(out BasicActorComponent actor) + ) //specifies if we have a client to update the hud for { var hudstatechange = DamageTemplate.ChangeHudState(damage); SendNetworkMessage(hudstatechange); @@ -103,14 +98,14 @@ namespace Content.Server.GameObjects private void ChangeDamageState(ThresholdType threshold) { - if(threshold == currentstate) + if (threshold == currentstate) { return; } - CurrentDamageState.ExitState(Owner, Appearance); + CurrentDamageState.ExitState(Owner); CurrentDamageState = DamageTemplates.StateThresholdMap[threshold]; - CurrentDamageState.EnterState(Owner, Appearance); + CurrentDamageState.EnterState(Owner); currentstate = threshold; } diff --git a/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs b/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs index 879b02adc9..968dde62e4 100644 --- a/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/PlayerInputMoverComponent.cs @@ -45,12 +45,6 @@ namespace Content.Server.GameObjects.Components.Movement [ViewVariables] public Vector2 VelocityDir { get; private set; } - /// - /// Blocks entity's movement - /// - [ViewVariables] - public bool Disabled { get; set; } = false; - /// public override void OnAdd() { diff --git a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs index 8aa52ecf1d..02557bbdc6 100644 --- a/Content.Server/GameObjects/EntitySystems/MoverSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/MoverSystem.cs @@ -105,7 +105,7 @@ namespace Content.Server.GameObjects.EntitySystems private static void UpdateKinematics(ITransformComponent transform, PlayerInputMoverComponent mover, PhysicsComponent physics) { - if (mover.VelocityDir.LengthSquared < 0.001 || mover.Disabled) + if (mover.VelocityDir.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner)) { if (physics.LinearVelocity != Vector2.Zero) physics.LinearVelocity = Vector2.Zero;