update UpdateVisuals to use Destructible thresholds (#3051)

* update UpdateVisuals to use Destructible thresholds

* refactor windows to use Destructible threshold instead of maxDamage
This commit is contained in:
bhespiritu
2021-02-01 11:22:50 -05:00
committed by GitHub
parent b51b8cb182
commit 6b6ddd0a73
2 changed files with 13 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
#nullable enable #nullable enable
using System; using System;
using Content.Server.Utility; using Content.Server.Utility;
using Content.Shared.Audio; using Content.Shared.Audio;
@@ -6,6 +6,7 @@ using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Server.GameObjects.Components.Destructible;
using Content.Shared.Utility; using Content.Shared.Utility;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
@@ -13,7 +14,6 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.GameObjects.Components namespace Content.Server.GameObjects.Components
@@ -22,14 +22,6 @@ namespace Content.Server.GameObjects.Components
[ComponentReference(typeof(SharedWindowComponent))] [ComponentReference(typeof(SharedWindowComponent))]
public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand
{ {
private int _maxDamage;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _maxDamage, "maxDamage", 100);
}
public override void HandleMessage(ComponentMessage message, IComponent? component) public override void HandleMessage(ComponentMessage message, IComponent? component)
{ {
@@ -50,18 +42,24 @@ namespace Content.Server.GameObjects.Components
{ {
if (Owner.TryGetComponent(out AppearanceComponent? appearance)) if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{ {
appearance.SetData(WindowVisuals.Damage, (float) currentDamage / _maxDamage); if (Owner.TryGetComponent(out DestructibleComponent? destructible))
{
var damageThreshold = destructible.LowestToHighestThresholds.FirstOrNull()?.Key;
if (damageThreshold == null) return;
appearance.SetData(WindowVisuals.Damage, (float) currentDamage / damageThreshold);
}
} }
} }
void IExamine.Examine(FormattedMessage message, bool inDetailsRange) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
var damage = Owner.GetComponentOrNull<IDamageableComponent>()?.TotalDamage; var damage = Owner.GetComponentOrNull<IDamageableComponent>()?.TotalDamage;
if (damage == null) return; var damageThreshold = Owner.GetComponentOrNull<DestructibleComponent>()?.LowestToHighestThresholds.FirstOrNull()?.Key;
var fraction = ((damage == 0 || _maxDamage == 0) if (damage == null || damageThreshold == null) return;
var fraction = ((damage == 0 || damageThreshold == 0)
? 0f ? 0f
: (float) damage / _maxDamage); : (float) damage / damageThreshold);
var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5); var level = Math.Min(ContentHelpers.RoundToLevels((double) fraction, 1, 7), 5);
switch (level) switch (level)
{ {
case 0: case 0:

View File

@@ -46,7 +46,6 @@
- type: Airtight - type: Airtight
- type: Window - type: Window
base: window base: window
maxDamage: 15
- type: Construction - type: Construction
graph: window graph: window
node: window node: window
@@ -81,7 +80,6 @@
acts: [ "Destruction" ] acts: [ "Destruction" ]
- type: Window - type: Window
base: rwindow base: rwindow
maxDamage: 75
- type: Construction - type: Construction
graph: window graph: window
node: reinforcedWindow node: reinforcedWindow
@@ -114,7 +112,6 @@
resistances: metallicResistances resistances: metallicResistances
- type: Window - type: Window
base: pwindow base: pwindow
maxDamage: 100
- type: Construction - type: Construction
graph: window graph: window
node: phoronWindow node: phoronWindow