Destructible component rework (#157)

* Walls are destructible now
* Added girders that spawn after wall’s destruction
* Girders drop metal sheet on destruction
This commit is contained in:
Injazz
2019-03-26 02:27:03 +05:00
committed by Pieter-Jan Briers
parent 9a224398d3
commit 4a5168f14c
5 changed files with 47 additions and 23 deletions

View File

@@ -45,6 +45,7 @@ using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using SS14.Server.Interfaces.ServerStatus; using SS14.Server.Interfaces.ServerStatus;
using SS14.Shared.Timing; using SS14.Shared.Timing;
using Content.Server.GameObjects.Components.Destructible;
namespace Content.Server namespace Content.Server
{ {

View File

@@ -9,7 +9,7 @@ using Content.Shared.GameObjects;
using SS14.Shared.Serialization; using SS14.Shared.Serialization;
using SS14.Shared.ViewVariables; using SS14.Shared.ViewVariables;
namespace Content.Server.GameObjects namespace Content.Server.GameObjects.Components.Destructible
{ {
/// <summary> /// <summary>
/// Deletes the entity once a certain damage threshold has been reached. /// Deletes the entity once a certain damage threshold has been reached.
@@ -19,9 +19,6 @@ namespace Content.Server.GameObjects
/// <inheritdoc /> /// <inheritdoc />
public override string Name => "Destructible"; public override string Name => "Destructible";
/// <inheritdoc />
public override uint? NetID => ContentNetIDs.DESTRUCTIBLE;
/// <summary> /// <summary>
/// Damage threshold calculated from the values /// Damage threshold calculated from the values
/// given in the prototype declaration. /// given in the prototype declaration.
@@ -29,35 +26,35 @@ namespace Content.Server.GameObjects
[ViewVariables] [ViewVariables]
public DamageThreshold Threshold { get; private set; } public DamageThreshold Threshold { get; private set; }
public DamageType damageType = DamageType.Total;
public int damageValue = 0;
public string spawnOnDestroy = "SteelSheet";
public bool destroyed = false;
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
// TODO: Writing serializer.DataField(ref damageValue, "thresholdvalue", 100);
if (serializer.Reading) serializer.DataField(ref damageType, "thresholdtype", DamageType.Total);
{ serializer.DataField(ref spawnOnDestroy, "spawnondestroy", "SteelSheet");
DamageType damageType = DamageType.Total;
int damageValue = 0;
serializer.DataReadFunction("thresholdtype", DamageType.Total, type => damageType = type);
serializer.DataReadFunction("thresholdvalue", 0, val => damageValue = val);
Threshold = new DamageThreshold(damageType, damageValue, ThresholdType.Destruction);
}
} }
/// <inheritdoc /> /// <inheritdoc />
public List<DamageThreshold> GetAllDamageThresholds() List<DamageThreshold> IOnDamageBehavior.GetAllDamageThresholds()
{ {
Threshold = new DamageThreshold(damageType, damageValue, ThresholdType.Destruction);
return new List<DamageThreshold>() { Threshold }; return new List<DamageThreshold>() { Threshold };
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnDamageThresholdPassed(object obj, DamageThresholdPassedEventArgs e) void IOnDamageBehavior.OnDamageThresholdPassed(object obj, DamageThresholdPassedEventArgs e)
{ {
if (e.Passed && e.DamageThreshold == Threshold) if (e.Passed && e.DamageThreshold == Threshold && destroyed == false)
{ {
destroyed = true;
var wreck = Owner.EntityManager.SpawnEntity(spawnOnDestroy);
wreck.Transform.GridPosition = Owner.Transform.GridPosition;
Owner.EntityManager.DeleteEntity(Owner); Owner.EntityManager.DeleteEntity(Owner);
} }
} }

View File

@@ -34,19 +34,19 @@ entities:
pos: 4.5,-0.5 pos: 4.5,-0.5
rot: -1.570796 rad rot: -1.570796 rad
type: Transform type: Transform
- type: wall - type: girder
components: components:
- grid: 0 - grid: 0
pos: -7,6 pos: -7,6
rot: -1.570796 rad rot: -1.570796 rad
type: Transform type: Transform
- type: wall - type: girder
components: components:
- grid: 0 - grid: 0
pos: -7,-4 pos: -7,-4
rot: -1.570796 rad rot: -1.570796 rad
type: Transform type: Transform
- type: wall - type: girder
components: components:
- grid: 0 - grid: 0
pos: -7,-3 pos: -7,-3
@@ -178,13 +178,13 @@ entities:
pos: -7,-6 pos: -7,-6
rot: -1.570796 rad rot: -1.570796 rad
type: Transform type: Transform
- type: wall - type: girder
components: components:
- grid: 0 - grid: 0
pos: -4,-6 pos: -4,-6
rot: -1.570796 rad rot: -1.570796 rad
type: Transform type: Transform
- type: wall - type: girder
components: components:
- grid: 0 - grid: 0
pos: -4,-5 pos: -4,-5

View File

@@ -0,0 +1,22 @@
- type: entity
id: girder
name: Girder
components:
- type: Clickable
- type: Sprite
texture: Buildings/wall_girder.png
- type: Icon
texture: Buildings/wall_girder.png
- type: BoundingBox
- type: Collidable
- type: Damageable
- type: Destructible
thresholdvalue: 50
spawnondestroy: SteelSheet1
- type: SnapGrid
offset: Edge
placement:
snap:
- Wall

View File

@@ -15,6 +15,10 @@
- type: BoundingBox - type: BoundingBox
- type: Collidable - type: Collidable
- type: Damageable
- type: Destructible
thresholdvalue: 100
spawnondestroy: girder
- type: Occluder - type: Occluder
sizeX: 32 sizeX: 32
sizeY: 32 sizeY: 32