Armor price calculations (#11417)

Co-authored-by: CommieFlowers <rasmus.cedergren@hotmail.com>
fixes https://github.com/space-wizards/space-station-14/issues/11299
This commit is contained in:
rolfero
2022-11-08 01:36:53 +01:00
committed by GitHub
parent 7b434354fd
commit 6a497d3f55
5 changed files with 87 additions and 7 deletions

View File

@@ -2,14 +2,20 @@ using Content.Shared.Damage;
using Content.Server.Examine; using Content.Server.Examine;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Content.Server.Cargo.Systems;
using Robust.Shared.Prototypes;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Inventory; using Content.Shared.Inventory;
namespace Content.Server.Armor namespace Content.Server.Armor
{ {
public sealed class ArmorSystem : EntitySystem 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 ExamineSystem _examine = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -17,6 +23,43 @@ namespace Content.Server.Armor
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify); SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine); 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);
if (damageType != null)
{
price += damageType.ArmorPriceFlat * modifier.Value;
}
else
{
price += FlatDefaultPrice * modifier.Value;
}
}
args.Price += price;
} }
private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args) private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)

View File

@@ -12,5 +12,17 @@ namespace Content.Shared.Damage.Prototypes
{ {
[IdDataFieldAttribute] [IdDataFieldAttribute]
public string ID { get; } = default!; public string ID { get; } = default!;
/// <summary>
/// The price for each 1% damage reduction in armors
/// </summary>
[DataField("armorCoefficientPrice")]
public double ArmorPriceCoefficient { get; set; }
/// <summary>
/// The price for each flat damage reduction in armors
/// </summary>
[DataField("armorFlatPrice")]
public double ArmorPriceFlat { get; set; }
} }
} }

View File

@@ -4,7 +4,7 @@
sprite: Clothing/Head/Helmets/bombsuit.rsi sprite: Clothing/Head/Helmets/bombsuit.rsi
state: icon state: icon
product: CrateEmergencyExplosive product: CrateEmergencyExplosive
cost: 500 cost: 650
category: Emergency category: Emergency
group: market group: market
@@ -14,7 +14,7 @@
sprite: Objects/Misc/fire_extinguisher.rsi sprite: Objects/Misc/fire_extinguisher.rsi
state: fire_extinguisher_closed state: fire_extinguisher_closed
product: CrateEmergencyFire product: CrateEmergencyFire
cost: 1000 cost: 1200
category: Emergency category: Emergency
group: market group: market
@@ -34,7 +34,7 @@
sprite: Structures/Wallmounts/signs.rsi sprite: Structures/Wallmounts/signs.rsi
state: radiation state: radiation
product: CrateEmergencyRadiation product: CrateEmergencyRadiation
cost: 500 cost: 900
category: Emergency category: Emergency
group: market group: market

View File

@@ -4,7 +4,7 @@
sprite: Clothing/OuterClothing/Vests/oldarmor.rsi sprite: Clothing/OuterClothing/Vests/oldarmor.rsi
state: icon state: icon
product: CrateSecurityArmor product: CrateSecurityArmor
cost: 500 cost: 700
category: Security category: Security
group: market group: market
@@ -14,7 +14,7 @@
sprite: Clothing/Head/Helmets/security.rsi sprite: Clothing/Head/Helmets/security.rsi
state: icon state: icon
product: CrateSecurityHelmet product: CrateSecurityHelmet
cost: 500 cost: 550
category: Security category: Security
group: market group: market
@@ -44,7 +44,7 @@
sprite: Clothing/OuterClothing/Armor/riot.rsi sprite: Clothing/OuterClothing/Armor/riot.rsi
state: icon state: icon
product: CrateSecurityRiot product: CrateSecurityRiot
cost: 2000 cost: 2800
category: Security category: Security
group: market group: market

View File

@@ -3,41 +3,66 @@
# Usually healed automatically if entity can breathe # Usually healed automatically if entity can breathe
- type: damageType - type: damageType
id: Asphyxiation id: Asphyxiation
armorCoefficientPrice: 5
armorFlatPrice: 50
# Damage representing not having enough blood. # Damage representing not having enough blood.
# Represents there not enough blood to supply oxygen (or equivalent). # Represents there not enough blood to supply oxygen (or equivalent).
- type: damageType - type: damageType
id: Bloodloss id: Bloodloss
armorCoefficientPrice: 5
armorFlatPrice: 50
- type: damageType - type: damageType
id: Blunt id: Blunt
armorCoefficientPrice: 2
armorFlatPrice: 10
- type: damageType - type: damageType
id: Cellular id: Cellular
armorCoefficientPrice: 5
armorFlatPrice: 30
- type: damageType - type: damageType
id: Cold id: Cold
armorCoefficientPrice: 2.5
armorFlatPrice: 20
- type: damageType - type: damageType
id: Heat id: Heat
armorCoefficientPrice: 2.5
armorFlatPrice: 20
- type: damageType - type: damageType
id: Piercing id: Piercing
armorCoefficientPrice: 2
armorFlatPrice: 10
# Poison damage. Generally caused by various reagents being metabolised. # Poison damage. Generally caused by various reagents being metabolised.
- type: damageType - type: damageType
id: Poison id: Poison
armorCoefficientPrice: 10
armorFlatPrice: 60
- type: damageType - type: damageType
id: Radiation id: Radiation
armorCoefficientPrice: 2.5
armorFlatPrice: 16
- type: damageType - type: damageType
id: Shock id: Shock
armorCoefficientPrice: 2.5
armorFlatPrice: 20
- type: damageType - type: damageType
id: Slash id: Slash
armorCoefficientPrice: 2
armorFlatPrice: 10
# Damage represent structures internal integrity. # Damage represent structures internal integrity.
# Exclusive for structures such as walls, airlocks and others. # Exclusive for structures such as walls, airlocks and others.
- type: damageType - type: damageType
id: Structural id: Structural
armorCoefficientPrice: 1
armorFlatPrice: 1