]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predicted armor (#20560)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Thu, 28 Sep 2023 10:48:50 +0000 (06:48 -0400)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2023 10:48:50 +0000 (20:48 +1000)
Content.Client/Armor/ArmorSystem.cs [new file with mode: 0644]
Content.Server/Armor/ArmorComponent.cs [deleted file]
Content.Server/Armor/ArmorSystem.cs
Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Content.Shared/Armor/ArmorComponent.cs [new file with mode: 0644]
Content.Shared/Armor/SharedArmorSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Vehicles/buckleable.yml

diff --git a/Content.Client/Armor/ArmorSystem.cs b/Content.Client/Armor/ArmorSystem.cs
new file mode 100644 (file)
index 0000000..a4116d2
--- /dev/null
@@ -0,0 +1,9 @@
+using Content.Shared.Armor;
+
+namespace Content.Client.Armor;
+
+/// <inheritdoc/>
+public sealed class ArmorSystem : SharedArmorSystem
+{
+
+}
diff --git a/Content.Server/Armor/ArmorComponent.cs b/Content.Server/Armor/ArmorComponent.cs
deleted file mode 100644 (file)
index 09be3bf..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-using Content.Shared.Damage;
-
-namespace Content.Server.Armor
-{
-    [RegisterComponent]
-    public sealed partial class ArmorComponent : Component
-    {
-        [DataField("modifiers", required: true)]
-        public DamageModifierSet Modifiers = default!;
-    }
-}
index dc02b06667e629bbec80b35bc0b253d6dcc39630..dc4b3c7935f06f6c9f1f6b11ed09a74cdf12bb03 100644 (file)
-using Content.Shared.Damage;
-using Content.Server.Examine;
-using Content.Shared.Verbs;
-using Robust.Shared.Utility;
 using Content.Server.Cargo.Systems;
+using Content.Shared.Armor;
 using Robust.Shared.Prototypes;
 using Content.Shared.Damage.Prototypes;
-using Content.Shared.Inventory;
-using Content.Shared.Silicons.Borgs;
 
-namespace Content.Server.Armor
-{
-    public sealed class ArmorSystem : EntitySystem
-    {
-        const double CoefDefaultPrice = 2; // default price of 1% protection against any type of damage
-        const double FlatDefaultPrice = 10; //default price of 1 damage protection against a certain type of damage
-
-        [Dependency] private readonly ExamineSystem _examine = default!;
-        [Dependency] private readonly IPrototypeManager _protoManager = default!;
-
-        public override void Initialize()
-        {
-            base.Initialize();
-
-            SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
-            SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
-            SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
-            SubscribeLocalEvent<ArmorComponent, PriceCalculationEvent>(GetArmorPrice);
-        }
-
-        private void GetArmorPrice(EntityUid uid, ArmorComponent component, ref PriceCalculationEvent args)
-        {
-            if (component.Modifiers == null)
-                return;
-
-            double price = 0;
-
-            foreach (var modifier in component.Modifiers.Coefficients)
-            {
-                _protoManager.TryIndex(modifier.Key, out DamageTypePrototype? damageType);
-
-                if (damageType != null)
-                {
-                    price += damageType.ArmorPriceCoefficient * 100 * (1 - modifier.Value);
-                }
-                else
-                {
-                    price += CoefDefaultPrice * 100 * (1 - modifier.Value);
-                }
-            }
-            foreach (var modifier in component.Modifiers.FlatReduction)
-            {
-                _protoManager.TryIndex(modifier.Key, out DamageTypePrototype? damageType);
+namespace Content.Server.Armor;
 
-                if (damageType != null)
-                {
-                    price += damageType.ArmorPriceFlat * modifier.Value;
-                }
-                else
-                {
-                    price += FlatDefaultPrice * modifier.Value;
-                }
-            }
-            args.Price += price;
-        }
+/// <inheritdoc/>
+public sealed class ArmorSystem : SharedArmorSystem
+{
+    [Dependency] private readonly IPrototypeManager _protoManager = default!;
 
-        private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)
-        {
-            args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
-        }
+    public override void Initialize()
+    {
+        base.Initialize();
 
-        private void OnBorgDamageModify(EntityUid uid, ArmorComponent component, ref BorgModuleRelayedEvent<DamageModifyEvent> args)
-        {
-            args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
-        }
+        SubscribeLocalEvent<ArmorComponent, PriceCalculationEvent>(GetArmorPrice);
+    }
 
-        private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent<ExamineVerb> args)
+    private void GetArmorPrice(EntityUid uid, ArmorComponent component, ref PriceCalculationEvent args)
+    {
+        foreach (var modifier in component.Modifiers.Coefficients)
         {
-            if (!args.CanInteract || !args.CanAccess)
-                return;
-
-            var armorModifiers = component.Modifiers;
-
-            if (armorModifiers == null)
-                return;
-
-            var examineMarkup = GetArmorExamine(armorModifiers);
-
-            var ev = new ArmorExamineEvent(examineMarkup);
-            RaiseLocalEvent(uid, ref ev);
-
-            _examine.AddDetailedExamineVerb(args, component, examineMarkup, Loc.GetString("armor-examinable-verb-text"), "/Textures/Interface/VerbIcons/dot.svg.192dpi.png", Loc.GetString("armor-examinable-verb-message"));
+            var damageType = _protoManager.Index<DamageTypePrototype>(modifier.Key);
+            args.Price += damageType.ArmorPriceCoefficient * 100 * (1 - modifier.Value);
         }
 
-        private FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers)
+        foreach (var modifier in component.Modifiers.FlatReduction)
         {
-            var msg = new FormattedMessage();
-
-            msg.AddMarkup(Loc.GetString("armor-examine"));
-
-            foreach (var coefficientArmor in armorModifiers.Coefficients)
-            {
-                msg.PushNewline();
-                msg.AddMarkup(Loc.GetString("armor-coefficient-value",
-                    ("type", coefficientArmor.Key),
-                    ("value", MathF.Round((1f - coefficientArmor.Value) * 100,1))
-                    ));
-            }
-
-            foreach (var flatArmor in armorModifiers.FlatReduction)
-            {
-                msg.PushNewline();
-                msg.AddMarkup(Loc.GetString("armor-reduction-value",
-                    ("type", flatArmor.Key),
-                    ("value", flatArmor.Value)
-                    ));
-            }
-
-            return msg;
+            var damageType = _protoManager.Index<DamageTypePrototype>(modifier.Key);
+            args.Price += damageType.ArmorPriceFlat * modifier.Value;
         }
     }
 }
-
-[ByRefEvent]
-public record struct ArmorExamineEvent(FormattedMessage Msg);
index 06c95383fcb1218cfffac2148e91e654210887e2..aa007c61c05566bbb117194bab7554cb207db685 100644 (file)
@@ -6,6 +6,7 @@ using Content.Server.Chat.Managers;
 using Content.Server.Explosion.Components;
 using Content.Server.NodeContainer.EntitySystems;
 using Content.Server.NPC.Pathfinding;
+using Content.Shared.Armor;
 using Content.Shared.Camera;
 using Content.Shared.CCVar;
 using Content.Shared.Damage;
diff --git a/Content.Shared/Armor/ArmorComponent.cs b/Content.Shared/Armor/ArmorComponent.cs
new file mode 100644 (file)
index 0000000..a1bb759
--- /dev/null
@@ -0,0 +1,25 @@
+using Content.Shared.Damage;
+using Robust.Shared.GameStates;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Armor;
+
+/// <summary>
+/// Used for clothing that reduces damage when worn.
+/// </summary>
+[RegisterComponent, NetworkedComponent, Access(typeof(SharedArmorSystem))]
+public sealed partial class ArmorComponent : Component
+{
+    /// <summary>
+    /// The damage reduction
+    /// </summary>
+    [DataField(required: true)]
+    public DamageModifierSet Modifiers = default!;
+}
+
+/// <summary>
+/// Event raised on an armor entity to get additional examine text relating to its armor.
+/// </summary>
+/// <param name="Msg"></param>
+[ByRefEvent]
+public record struct ArmorExamineEvent(FormattedMessage Msg);
diff --git a/Content.Shared/Armor/SharedArmorSystem.cs b/Content.Shared/Armor/SharedArmorSystem.cs
new file mode 100644 (file)
index 0000000..89141fc
--- /dev/null
@@ -0,0 +1,78 @@
+using Content.Shared.Damage;
+using Content.Shared.Examine;
+using Content.Shared.Inventory;
+using Content.Shared.Silicons.Borgs;
+using Content.Shared.Verbs;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Armor;
+
+/// <summary>
+/// This handles logic relating to <see cref="ArmorComponent"/>
+/// </summary>
+public abstract class SharedArmorSystem : EntitySystem
+{
+    [Dependency] private readonly ExamineSystemShared _examine = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
+        SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
+        SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
+    }
+
+    private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)
+    {
+        args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
+    }
+
+    private void OnBorgDamageModify(EntityUid uid, ArmorComponent component, ref BorgModuleRelayedEvent<DamageModifyEvent> args)
+    {
+        args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
+    }
+
+    private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent<ExamineVerb> args)
+    {
+        if (!args.CanInteract || !args.CanAccess)
+            return;
+
+        var examineMarkup = GetArmorExamine(component.Modifiers);
+
+        var ev = new ArmorExamineEvent(examineMarkup);
+        RaiseLocalEvent(uid, ref ev);
+
+        _examine.AddDetailedExamineVerb(args, component, examineMarkup,
+            Loc.GetString("armor-examinable-verb-text"), "/Textures/Interface/VerbIcons/dot.svg.192dpi.png",
+            Loc.GetString("armor-examinable-verb-message"));
+    }
+
+    private FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers)
+    {
+        var msg = new FormattedMessage();
+
+        msg.AddMarkup(Loc.GetString("armor-examine"));
+
+        foreach (var coefficientArmor in armorModifiers.Coefficients)
+        {
+            msg.PushNewline();
+            msg.AddMarkup(Loc.GetString("armor-coefficient-value",
+                ("type", coefficientArmor.Key),
+                ("value", MathF.Round((1f - coefficientArmor.Value) * 100,1))
+                ));
+        }
+
+        foreach (var flatArmor in armorModifiers.FlatReduction)
+        {
+            msg.PushNewline();
+            msg.AddMarkup(Loc.GetString("armor-reduction-value",
+                ("type", flatArmor.Key),
+                ("value", flatArmor.Value)
+                ));
+        }
+
+        return msg;
+    }
+}
index d807bcc5a9fad489b9ebfe83dd91466f7d633036..4a8fa0da5cb95749e9e27eefab751c8133baae5e 100644 (file)
@@ -39,7 +39,7 @@
         sound:
           path: /Audio/Effects/metalbreak.ogg
       - !type:ExplodeBehavior
-  
+
 - type: entity
   parent: BaseVehicle
   id: BaseVehicleRideable
     baseSprintSpeed: 6
   - type: Armor
     modifiers:
-      coeffecients:
+      coefficients:
         Blunt: 0.8
         Slash: 0.6
         Piercing: 0.85
       maxBuckleDistance: 1
     - type: Armor
       modifiers:
-        coeffecients:
+        coefficients:
           Blunt: 0.8
           Slash: 0.6
           Piercing: 0.85