From 4a5168f14ceb117839fb4c867af3096bf5d56361 Mon Sep 17 00:00:00 2001 From: Injazz <43905364+Injazz@users.noreply.github.com> Date: Tue, 26 Mar 2019 02:27:03 +0500 Subject: [PATCH] Destructible component rework (#157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Walls are destructible now * Added girders that spawn after wall’s destruction * Girders drop metal sheet on destruction --- Content.Server/EntryPoint.cs | 1 + .../Damage/DestructibleComponent.cs | 33 +++++++++---------- Resources/Maps/stationstation.yml | 10 +++--- Resources/Prototypes/Entities/girder.yml | 22 +++++++++++++ Resources/Prototypes/Entities/walls.yml | 4 +++ 5 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 Resources/Prototypes/Entities/girder.yml diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 9524afa2ad..9fb1fd0b3e 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -45,6 +45,7 @@ using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.Interfaces; using SS14.Server.Interfaces.ServerStatus; using SS14.Shared.Timing; +using Content.Server.GameObjects.Components.Destructible; namespace Content.Server { diff --git a/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs b/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs index 4045c4589c..a0b220f78b 100644 --- a/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs +++ b/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs @@ -9,7 +9,7 @@ using Content.Shared.GameObjects; using SS14.Shared.Serialization; using SS14.Shared.ViewVariables; -namespace Content.Server.GameObjects +namespace Content.Server.GameObjects.Components.Destructible { /// /// Deletes the entity once a certain damage threshold has been reached. @@ -19,9 +19,6 @@ namespace Content.Server.GameObjects /// public override string Name => "Destructible"; - /// - public override uint? NetID => ContentNetIDs.DESTRUCTIBLE; - /// /// Damage threshold calculated from the values /// given in the prototype declaration. @@ -29,35 +26,35 @@ namespace Content.Server.GameObjects [ViewVariables] 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) { base.ExposeData(serializer); - // TODO: Writing - if (serializer.Reading) - { - 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); - } + serializer.DataField(ref damageValue, "thresholdvalue", 100); + serializer.DataField(ref damageType, "thresholdtype", DamageType.Total); + serializer.DataField(ref spawnOnDestroy, "spawnondestroy", "SteelSheet"); } /// - public List GetAllDamageThresholds() + List IOnDamageBehavior.GetAllDamageThresholds() { + Threshold = new DamageThreshold(damageType, damageValue, ThresholdType.Destruction); return new List() { Threshold }; } /// - 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); } } diff --git a/Resources/Maps/stationstation.yml b/Resources/Maps/stationstation.yml index aa8c3ee5fd..df615aa41a 100644 --- a/Resources/Maps/stationstation.yml +++ b/Resources/Maps/stationstation.yml @@ -34,19 +34,19 @@ entities: pos: 4.5,-0.5 rot: -1.570796 rad type: Transform -- type: wall +- type: girder components: - grid: 0 pos: -7,6 rot: -1.570796 rad type: Transform -- type: wall +- type: girder components: - grid: 0 pos: -7,-4 rot: -1.570796 rad type: Transform -- type: wall +- type: girder components: - grid: 0 pos: -7,-3 @@ -178,13 +178,13 @@ entities: pos: -7,-6 rot: -1.570796 rad type: Transform -- type: wall +- type: girder components: - grid: 0 pos: -4,-6 rot: -1.570796 rad type: Transform -- type: wall +- type: girder components: - grid: 0 pos: -4,-5 diff --git a/Resources/Prototypes/Entities/girder.yml b/Resources/Prototypes/Entities/girder.yml new file mode 100644 index 0000000000..d1407c5229 --- /dev/null +++ b/Resources/Prototypes/Entities/girder.yml @@ -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 \ No newline at end of file diff --git a/Resources/Prototypes/Entities/walls.yml b/Resources/Prototypes/Entities/walls.yml index 2af7923347..3f571b595c 100644 --- a/Resources/Prototypes/Entities/walls.yml +++ b/Resources/Prototypes/Entities/walls.yml @@ -15,6 +15,10 @@ - type: BoundingBox - type: Collidable + - type: Damageable + - type: Destructible + thresholdvalue: 100 + spawnondestroy: girder - type: Occluder sizeX: 32 sizeY: 32