Add prediction for standing states and mob states (#1937)
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Body
|
||||
{
|
||||
public interface IBodyManagerComponent : IDamageableComponent
|
||||
public interface ISharedBodyManagerComponent : IDamageableComponent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Body
|
||||
{
|
||||
public abstract class SharedBodyManagerComponent : DamageableComponent, IBodyManagerComponent
|
||||
public abstract class SharedBodyManagerComponent : DamageableComponent, ISharedBodyManagerComponent
|
||||
{
|
||||
public override string Name => "BodyManager";
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Content.Shared.GameObjects.Components.Damage
|
||||
[Serializable, NetSerializable]
|
||||
public enum DamageState
|
||||
{
|
||||
Invalid = 0,
|
||||
Alive,
|
||||
Critical,
|
||||
Dead
|
||||
|
||||
@@ -143,8 +143,8 @@ namespace Content.Shared.GameObjects.Components.Damage
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
ChangeDamage(DamageType.Piercing, damage, false, null);
|
||||
ChangeDamage(DamageType.Heat, damage, false, null);
|
||||
ChangeDamage(DamageType.Piercing, damage, false);
|
||||
ChangeDamage(DamageType.Heat, damage, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the blocking effects of an associated <see cref="DamageState"/>
|
||||
/// (i.e. Normal, Critical, Dead) and what effects to apply upon entering or
|
||||
/// exiting the state.
|
||||
/// </summary>
|
||||
public interface IMobState : IActionBlocker
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when this state is entered.
|
||||
/// </summary>
|
||||
void EnterState(IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// Called when this state is left for a different state.
|
||||
/// </summary>
|
||||
void ExitState(IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// Called when this state is updated.
|
||||
/// </summary>
|
||||
void UpdateState(IEntity entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
/// <summary>
|
||||
/// A state in which an entity is disabled from acting due to sufficient damage (considered unconscious).
|
||||
/// </summary>
|
||||
public abstract class SharedCriticalState : IMobState
|
||||
{
|
||||
public abstract void EnterState(IEntity entity);
|
||||
|
||||
public abstract void ExitState(IEntity entity);
|
||||
|
||||
public abstract void UpdateState(IEntity entity);
|
||||
|
||||
public bool CanInteract()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanMove()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanUse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanThrow()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanSpeak()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanDrop()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanPickup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanEmote()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanAttack()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanEquip()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanUnequip()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanChangeDirection()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
public abstract class SharedDeadState : IMobState
|
||||
{
|
||||
public abstract void EnterState(IEntity entity);
|
||||
|
||||
public abstract void ExitState(IEntity entity);
|
||||
|
||||
public abstract void UpdateState(IEntity entity);
|
||||
|
||||
public bool CanInteract()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanMove()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanUse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanThrow()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanSpeak()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanDrop()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanPickup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanEmote()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanAttack()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanEquip()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanUnequip()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanChangeDirection()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
/// <summary>
|
||||
/// When attacked to an <see cref="IDamageableComponent"/>, this component will
|
||||
/// handle critical and death behaviors for mobs.
|
||||
/// Additionally, it handles sending effects to clients
|
||||
/// (such as blur effect for unconsciousness) and managing the health HUD.
|
||||
/// </summary>
|
||||
public abstract class SharedMobStateManagerComponent : Component, IOnHealthChangedBehavior, IActionBlocker
|
||||
{
|
||||
public override string Name => "MobStateManager";
|
||||
|
||||
public override uint? NetID => ContentNetIDs.MOB_STATE_MANAGER;
|
||||
|
||||
protected abstract IReadOnlyDictionary<DamageState, IMobState> Behavior { get; }
|
||||
|
||||
public virtual IMobState CurrentMobState { get; protected set; }
|
||||
|
||||
public virtual DamageState CurrentDamageState { get; protected set; }
|
||||
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
|
||||
CurrentDamageState = DamageState.Alive;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
CurrentMobState = Behavior[CurrentDamageState];
|
||||
CurrentMobState.EnterState(Owner);
|
||||
CurrentMobState.UpdateState(Owner);
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanInteract()
|
||||
{
|
||||
return CurrentMobState.CanInteract();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanMove()
|
||||
{
|
||||
return CurrentMobState.CanMove();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanUse()
|
||||
{
|
||||
return CurrentMobState.CanUse();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanThrow()
|
||||
{
|
||||
return CurrentMobState.CanThrow();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanSpeak()
|
||||
{
|
||||
return CurrentMobState.CanSpeak();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanDrop()
|
||||
{
|
||||
return CurrentMobState.CanDrop();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanPickup()
|
||||
{
|
||||
return CurrentMobState.CanPickup();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanEmote()
|
||||
{
|
||||
return CurrentMobState.CanEmote();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanAttack()
|
||||
{
|
||||
return CurrentMobState.CanAttack();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanEquip()
|
||||
{
|
||||
return CurrentMobState.CanEquip();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanUnequip()
|
||||
{
|
||||
return CurrentMobState.CanUnequip();
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanChangeDirection()
|
||||
{
|
||||
return CurrentMobState.CanChangeDirection();
|
||||
}
|
||||
|
||||
public void OnHealthChanged(HealthChangedEventArgs e)
|
||||
{
|
||||
if (e.Damageable.CurrentDamageState != CurrentDamageState)
|
||||
{
|
||||
CurrentDamageState = e.Damageable.CurrentDamageState;
|
||||
CurrentMobState.ExitState(Owner);
|
||||
CurrentMobState = Behavior[CurrentDamageState];
|
||||
CurrentMobState.EnterState(Owner);
|
||||
}
|
||||
|
||||
CurrentMobState.UpdateState(Owner);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class MobStateManagerComponentState : ComponentState
|
||||
{
|
||||
public readonly DamageState DamageState;
|
||||
|
||||
public MobStateManagerComponentState(DamageState damageState) : base(ContentNetIDs.MOB_STATE_MANAGER)
|
||||
{
|
||||
DamageState = damageState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Mobs.State
|
||||
{
|
||||
/// <summary>
|
||||
/// The standard state an entity is in; no negative effects.
|
||||
/// </summary>
|
||||
public abstract class SharedNormalState : IMobState
|
||||
{
|
||||
public abstract void EnterState(IEntity entity);
|
||||
|
||||
public abstract void ExitState(IEntity entity);
|
||||
|
||||
public abstract void UpdateState(IEntity entity);
|
||||
|
||||
public bool CanInteract()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanMove()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanUse()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanThrow()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanSpeak()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanDrop()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanPickup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanEmote()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanAttack()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanEquip()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanUnequip()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanChangeDirection()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ namespace Content.Shared.GameObjects.Components.Movement
|
||||
bool ICollideSpecial.PreventCollide(IPhysBody collidedWith)
|
||||
{
|
||||
// Don't collide with other mobs
|
||||
return collidedWith.Entity.HasComponent<IBodyManagerComponent>();
|
||||
return collidedWith.Entity.HasComponent<ISharedBodyManagerComponent>();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Rotation
|
||||
Reference in New Issue
Block a user