Correctly implement movement blocking and undo that appearance mess.

This commit is contained in:
Pieter-Jan Briers
2019-04-04 19:43:01 +02:00
parent 0fe1407214
commit ea581e67c8
4 changed files with 35 additions and 56 deletions

View File

@@ -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
/// </summary>
public interface DamageState : IActionBlocker
{
void EnterState(IEntity entity, AppearanceComponent appearance);
{
void EnterState(IEntity entity);
void ExitState(IEntity entity, AppearanceComponent appearance);
void ExitState(IEntity entity);
}
/// <summary>
@@ -22,9 +20,13 @@ namespace Content.Server.GameObjects
/// </summary>
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
/// </summary>
public struct CriticalState : DamageState
{
public void EnterState(IEntity entity, AppearanceComponent appearance) {
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover))
{
return;
}
mover.Disabled = true;
public void EnterState(IEntity entity)
{
}
public void ExitState(IEntity entity, AppearanceComponent appearance) {
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover))
{
return;
}
mover.Disabled = false;
public void ExitState(IEntity entity)
{
}
bool IActionBlocker.CanInteract()
@@ -84,26 +78,22 @@ namespace Content.Server.GameObjects
/// </summary>
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<PlayerInputMoverComponent>(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<PlayerInputMoverComponent>(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()

View File

@@ -29,30 +29,24 @@ namespace Content.Server.GameObjects
/// </summary>
private DamageTemplates DamageTemplate;
AppearanceComponent Appearance;
/// <summary>
/// Variable for serialization
/// </summary>
private string templatename;
public override void Initialize()
{
base.Initialize();
Appearance = Owner.GetComponent<AppearanceComponent>();
}
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;
}

View File

@@ -45,12 +45,6 @@ namespace Content.Server.GameObjects.Components.Movement
[ViewVariables]
public Vector2 VelocityDir { get; private set; }
/// <summary>
/// Blocks entity's movement
/// </summary>
[ViewVariables]
public bool Disabled { get; set; } = false;
/// <inheritdoc />
public override void OnAdd()
{

View File

@@ -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;