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 Content.Shared.GameObjects.Components.Mobs;
using SS14.Server.GameObjects; using SS14.Server.GameObjects;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Maths;
namespace Content.Server.GameObjects 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 /// Defines the blocking effect of each damage state, and what effects to apply upon entering or exiting the state
/// </summary> /// </summary>
public interface DamageState : IActionBlocker 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> /// <summary>
@@ -22,9 +20,13 @@ namespace Content.Server.GameObjects
/// </summary> /// </summary>
public struct NormalState : DamageState 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() bool IActionBlocker.CanInteract()
{ {
@@ -47,20 +49,12 @@ namespace Content.Server.GameObjects
/// </summary> /// </summary>
public struct CriticalState : DamageState public struct CriticalState : DamageState
{ {
public void EnterState(IEntity entity, AppearanceComponent appearance) { public void EnterState(IEntity entity)
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover)) {
{
return;
}
mover.Disabled = true;
} }
public void ExitState(IEntity entity, AppearanceComponent appearance) { public void ExitState(IEntity entity)
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover)) {
{
return;
}
mover.Disabled = false;
} }
bool IActionBlocker.CanInteract() bool IActionBlocker.CanInteract()
@@ -84,26 +78,22 @@ namespace Content.Server.GameObjects
/// </summary> /// </summary>
public struct DeadState : DamageState public struct DeadState : DamageState
{ {
public void EnterState(IEntity entity, AppearanceComponent appearance) public void EnterState(IEntity entity)
{ {
var newstate = SpeciesComponent.MobState.Down; if (entity.TryGetComponent(out AppearanceComponent appearance))
appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate);
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover))
{ {
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; if (entity.TryGetComponent(out AppearanceComponent appearance))
appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate);
if (!entity.TryGetComponent<PlayerInputMoverComponent>(out var mover))
{ {
return; var newState = SharedSpeciesComponent.MobState.Stand;
appearance.SetData(SharedSpeciesComponent.MobVisuals.RotationState, newState);
} }
mover.Disabled = false;
} }
bool IActionBlocker.CanInteract() bool IActionBlocker.CanInteract()

View File

@@ -29,30 +29,24 @@ namespace Content.Server.GameObjects
/// </summary> /// </summary>
private DamageTemplates DamageTemplate; private DamageTemplates DamageTemplate;
AppearanceComponent Appearance;
/// <summary> /// <summary>
/// Variable for serialization /// Variable for serialization
/// </summary> /// </summary>
private string templatename; private string templatename;
public override void Initialize()
{
base.Initialize();
Appearance = Owner.GetComponent<AppearanceComponent>();
}
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref templatename, "Template", "Human"); serializer.DataField(ref templatename, "Template", "Human");
Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Server").GetType("Content.Server.GameObjects." + templatename); Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Server")
DamageTemplate = (DamageTemplates)Activator.CreateInstance(type); .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) switch (message)
{ {
@@ -87,14 +81,15 @@ namespace Content.Server.GameObjects
void IOnDamageBehavior.OnDamageThresholdPassed(object damageable, DamageThresholdPassedEventArgs e) 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)); 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); var hudstatechange = DamageTemplate.ChangeHudState(damage);
SendNetworkMessage(hudstatechange); SendNetworkMessage(hudstatechange);
@@ -103,14 +98,14 @@ namespace Content.Server.GameObjects
private void ChangeDamageState(ThresholdType threshold) private void ChangeDamageState(ThresholdType threshold)
{ {
if(threshold == currentstate) if (threshold == currentstate)
{ {
return; return;
} }
CurrentDamageState.ExitState(Owner, Appearance); CurrentDamageState.ExitState(Owner);
CurrentDamageState = DamageTemplates.StateThresholdMap[threshold]; CurrentDamageState = DamageTemplates.StateThresholdMap[threshold];
CurrentDamageState.EnterState(Owner, Appearance); CurrentDamageState.EnterState(Owner);
currentstate = threshold; currentstate = threshold;
} }

View File

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