From: blueDev2 <89804215+blueDev2@users.noreply.github.com>
Date: Sun, 11 Aug 2024 09:14:35 +0000 (-0400)
Subject: Add MinHealth Construction Condition (#30892)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=b16e57ee9484d347c4ceda635c7240813972660d;p=space-station-14.git
Add MinHealth Construction Condition (#30892)
* Add Min Health Condition and associated Locale
* Add Comment
---
diff --git a/Content.Server/Construction/Conditions/MinHealth.cs b/Content.Server/Construction/Conditions/MinHealth.cs
new file mode 100644
index 0000000000..980f6a49ca
--- /dev/null
+++ b/Content.Server/Construction/Conditions/MinHealth.cs
@@ -0,0 +1,92 @@
+using Content.Server.Destructible;
+using Content.Shared.Construction;
+using Content.Shared.Damage;
+using Content.Shared.Examine;
+using Content.Shared.FixedPoint;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Content.Server.Construction.Conditions;
+
+///
+/// Requires that the structure has at least some amount of health
+///
+[DataDefinition]
+public sealed partial class MinHealth : IGraphCondition
+{
+ ///
+ /// If ByProportion is true, Threshold is a value less than or equal to 1, but more than 0,
+ /// which is compared to the percent of health remaining in the structure.
+ /// Else, Threshold is any positive value with at most 2 decimal points of percision,
+ /// which is compared to the current health of the structure.
+ ///
+ [DataField]
+ public FixedPoint2 Threshold = 1;
+ [DataField]
+ public bool ByProportion = false;
+
+ [DataField]
+ public bool IncludeEquals = true;
+
+ public bool Condition(EntityUid uid, IEntityManager entMan)
+ {
+ if (!entMan.TryGetComponent(uid, out DestructibleComponent? destructibleComp) ||
+ !entMan.TryGetComponent(uid, out DamageableComponent? damageComp))
+ {
+ return false;
+ }
+
+ var destructionSys = entMan.System();
+ var maxHealth = destructionSys.DestroyedAt(uid, destructibleComp);
+ var curHealth = maxHealth - damageComp.TotalDamage;
+ var proportionHealth = curHealth / maxHealth;
+
+ if (IncludeEquals)
+ {
+ if (ByProportion)
+ {
+ return proportionHealth >= Threshold;
+ }
+ else
+ {
+ return curHealth >= Threshold;
+ }
+ }
+ else
+ {
+ if (ByProportion)
+ {
+ return proportionHealth > Threshold;
+ }
+ else
+ {
+ return curHealth > Threshold;
+ }
+ }
+ }
+
+ public bool DoExamine(ExaminedEvent args)
+ {
+ var entMan = IoCManager.Resolve();
+ var entity = args.Examined;
+
+ if (Condition(entity, entMan))
+ {
+ return false;
+ }
+ args.PushMarkup(Loc.GetString("construction-examine-condition-low-health"));
+
+ return true;
+ }
+
+ public IEnumerable GenerateGuideEntry()
+ {
+ yield return new ConstructionGuideEntry()
+ {
+ Localization = "construction-step-condition-low-health"
+ };
+ }
+}
diff --git a/Resources/Locale/en-US/construction/conditions/min-health.ftl b/Resources/Locale/en-US/construction/conditions/min-health.ftl
new file mode 100644
index 0000000000..daaddcf572
--- /dev/null
+++ b/Resources/Locale/en-US/construction/conditions/min-health.ftl
@@ -0,0 +1,2 @@
+construction-examine-condition-low-health = First, repair it.
+construction-step-condition-low-health = It must be repaired.