From c5e077efc1f368aa9982e37ce44003d44c02bf6f Mon Sep 17 00:00:00 2001
From: Injazz <43905364+Injazz@users.noreply.github.com>
Date: Wed, 27 Mar 2019 17:29:06 +0500
Subject: [PATCH] mob dead state tweaks (#162)
~~well, it SHOULD make mob rotate on death, but it doesn't, i have no idea why~~
- Blocks character movement in crit/death
- rotates character ~~360noscope~~ 90 degrees to convince you it's lying down when dead
resolves #145
resolves #158
related to #115
---
Content.Client/Content.Client.csproj | 1 +
.../Components/Mobs/SpeciesVisualizer2D.cs | 35 +++++++++++++++
.../Components/Mobs/DamageStates.cs | 45 +++++++++++++------
.../Components/Mobs/SpeciesComponent.cs | 20 +++++----
Content.Shared/Content.Shared.csproj | 1 +
.../Components/Mobs/SharedSpeciesComponent.cs | 34 ++++++++++++++
Resources/Prototypes/Entities/Mobs.yml | 3 ++
SpaceStation14Content.sln | 8 ----
8 files changed, 118 insertions(+), 29 deletions(-)
create mode 100644 Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs
create mode 100644 Content.Shared/GameObjects/Components/Mobs/SharedSpeciesComponent.cs
diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj
index 9091c2f9c1..24f52e8351 100644
--- a/Content.Client/Content.Client.csproj
+++ b/Content.Client/Content.Client.csproj
@@ -111,6 +111,7 @@
+
diff --git a/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs b/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs
new file mode 100644
index 0000000000..e5bd756988
--- /dev/null
+++ b/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs
@@ -0,0 +1,35 @@
+using Content.Shared.GameObjects.Components.Mobs;
+using SS14.Client.GameObjects;
+using SS14.Client.Interfaces.GameObjects.Components;
+using SS14.Shared.Interfaces.GameObjects;
+using SS14.Shared.Maths;
+
+namespace Content.Client.GameObjects.Components.Mobs
+{
+ public class SpeciesVisualizer2D : AppearanceVisualizer
+ {
+ public override void InitializeEntity(IEntity entity)
+ {
+ base.InitializeEntity(entity);
+ }
+
+ public override void OnChangeData(AppearanceComponent component)
+ {
+ base.OnChangeData(component);
+
+ var sprite = component.Owner.GetComponent();
+ if (component.TryGetData(SharedSpeciesComponent.MobVisuals.RotationState, out var state))
+ {
+ switch (state)
+ {
+ case SharedSpeciesComponent.MobState.Stand:
+ sprite.Rotation = 0;
+ break;
+ case SharedSpeciesComponent.MobState.Down:
+ sprite.Rotation = Angle.FromDegrees(90);
+ break;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Content.Server/GameObjects/Components/Mobs/DamageStates.cs b/Content.Server/GameObjects/Components/Mobs/DamageStates.cs
index 3dc711531d..f50e6b6269 100644
--- a/Content.Server/GameObjects/Components/Mobs/DamageStates.cs
+++ b/Content.Server/GameObjects/Components/Mobs/DamageStates.cs
@@ -1,4 +1,5 @@
using Content.Server.GameObjects.EntitySystems;
+using Content.Shared.GameObjects.Components.Mobs;
using SS14.Server.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Maths;
@@ -9,10 +10,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);
+ {
+ void EnterState(IEntity entity, AppearanceComponent appearance);
- void ExitState(IEntity entity);
+ void ExitState(IEntity entity, AppearanceComponent appearance);
}
///
@@ -20,9 +21,9 @@ namespace Content.Server.GameObjects
///
public struct NormalState : DamageState
{
- public void EnterState(IEntity entity){}
+ public void EnterState(IEntity entity, AppearanceComponent appearance) {}
- public void ExitState(IEntity entity){}
+ public void ExitState(IEntity entity, AppearanceComponent appearance) {}
bool IActionBlocker.CanInteract()
{
@@ -45,9 +46,21 @@ namespace Content.Server.GameObjects
///
public struct CriticalState : DamageState
{
- public void EnterState(IEntity entity) { }
+ public void EnterState(IEntity entity, AppearanceComponent appearance) {
+ if (!entity.TryGetComponent(out var mover))
+ {
+ return;
+ }
+ mover.Disabled = true;
+ }
- public void ExitState(IEntity entity) { }
+ public void ExitState(IEntity entity, AppearanceComponent appearance) {
+ if (!entity.TryGetComponent(out var mover))
+ {
+ return;
+ }
+ mover.Disabled = false;
+ }
bool IActionBlocker.CanInteract()
{
@@ -70,20 +83,26 @@ namespace Content.Server.GameObjects
///
public struct DeadState : DamageState
{
- public void EnterState(IEntity entity)
+ public void EnterState(IEntity entity, AppearanceComponent appearance)
{
- if(entity.TryGetComponent(out SpriteComponent sprite))
+ var newstate = SpeciesComponent.MobState.Down;
+ appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate);
+ if (!entity.TryGetComponent(out var mover))
{
- sprite.Rotation = sprite.Rotation + Angle.FromDegrees(90);
+ return;
}
+ mover.Disabled = true;
}
- public void ExitState(IEntity entity)
+ public void ExitState(IEntity entity, AppearanceComponent appearance)
{
- if (entity.TryGetComponent(out SpriteComponent sprite))
+ var newstate = SpeciesComponent.MobState.Stand;
+ appearance.SetData(SpeciesComponent.MobVisuals.RotationState, newstate);
+ if (!entity.TryGetComponent(out var mover))
{
- sprite.Rotation = sprite.Rotation - Angle.FromDegrees(90);
+ return;
}
+ 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 106f3e514c..0ddc8edca4 100644
--- a/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs
+++ b/Content.Server/GameObjects/Components/Mobs/SpeciesComponent.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
-using Content.Shared.GameObjects;
+using Content.Shared.GameObjects.Components.Mobs;
using SS14.Server.GameObjects;
using SS14.Shared.ContentPack;
using SS14.Shared.GameObjects;
@@ -12,12 +12,8 @@ using SS14.Shared.Serialization;
namespace Content.Server.GameObjects
{
- public class SpeciesComponent : Component, IActionBlocker, IOnDamageBehavior
+ public class SpeciesComponent : SharedSpeciesComponent, IActionBlocker, IOnDamageBehavior
{
- public override string Name => "Species";
-
- public override uint? NetID => ContentNetIDs.SPECIES;
-
///
/// Damagestates are reached by reaching a certain damage threshold, they will block actions after being reached
///
@@ -33,11 +29,19 @@ 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);
@@ -104,9 +108,9 @@ namespace Content.Server.GameObjects
return;
}
- CurrentDamageState.ExitState(Owner);
+ CurrentDamageState.ExitState(Owner, Appearance);
CurrentDamageState = DamageTemplates.StateThresholdMap[threshold];
- CurrentDamageState.EnterState(Owner);
+ CurrentDamageState.EnterState(Owner, Appearance);
currentstate = threshold;
}
diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj
index dc4fbedaf8..93f267c422 100644
--- a/Content.Shared/Content.Shared.csproj
+++ b/Content.Shared/Content.Shared.csproj
@@ -87,6 +87,7 @@
+
diff --git a/Content.Shared/GameObjects/Components/Mobs/SharedSpeciesComponent.cs b/Content.Shared/GameObjects/Components/Mobs/SharedSpeciesComponent.cs
new file mode 100644
index 0000000000..2e78fa4642
--- /dev/null
+++ b/Content.Shared/GameObjects/Components/Mobs/SharedSpeciesComponent.cs
@@ -0,0 +1,34 @@
+using System;
+using SS14.Shared.GameObjects;
+using SS14.Shared.Serialization;
+
+namespace Content.Shared.GameObjects.Components.Mobs
+{
+ public abstract class SharedSpeciesComponent : Component
+ {
+ public sealed override string Name => "Species";
+
+ public override uint? NetID => ContentNetIDs.SPECIES;
+
+ [Serializable, NetSerializable]
+ public enum MobVisuals
+ {
+ RotationState
+ }
+
+ [Serializable, NetSerializable]
+ public enum MobState
+ {
+ ///
+ /// Mob is standing up
+ ///
+ Stand,
+
+ ///
+ /// Mob is laying down
+ ///
+ Down,
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Resources/Prototypes/Entities/Mobs.yml b/Resources/Prototypes/Entities/Mobs.yml
index 060a008ba3..b6a8f9e4e5 100644
--- a/Resources/Prototypes/Entities/Mobs.yml
+++ b/Resources/Prototypes/Entities/Mobs.yml
@@ -56,6 +56,9 @@
zoom: 0.5, 0.5
- type: CameraRecoil
+ - type: Appearance
+ visuals:
+ - type: SpeciesVisualizer2D
- type: entity
id: MobObserver
diff --git a/SpaceStation14Content.sln b/SpaceStation14Content.sln
index a37ac0fa01..ab95e93211 100644
--- a/SpaceStation14Content.sln
+++ b/SpaceStation14Content.sln
@@ -4,9 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.Shared", "Content.Shared\Content.Shared.csproj", "{26AEEBB3-DDE7-443A-9F43-7BC7F4ACF6B5}"
- ProjectSection(ProjectDependencies) = postProject
- {0529F740-0000-0000-0000-000000000000} = {0529F740-0000-0000-0000-000000000000}
- EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SS14.Shared", "engine\SS14.Shared\SS14.Shared.csproj", "{0529F740-0000-0000-0000-000000000000}"
EndProject
@@ -22,11 +19,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.Server", "Content.S
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Content.Client", "Content.Client\Content.Client.csproj", "{A2E5F175-78AF-4DDD-8F97-E2D2552372ED}"
- ProjectSection(ProjectDependencies) = postProject
- {0529F740-0000-0000-0000-000000000000} = {0529F740-0000-0000-0000-000000000000}
- {26AEEBB3-DDE7-443A-9F43-7BC7F4ACF6B5} = {26AEEBB3-DDE7-443A-9F43-7BC7F4ACF6B5}
- {83429BD6-6358-4B18-BE51-401DF8EA2673} = {83429BD6-6358-4B18-BE51-401DF8EA2673}
- EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "engine\Lidgren.Network\Lidgren.Network.csproj", "{59250BAF-0000-0000-0000-000000000000}"
EndProject