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:
@@ -2,14 +2,20 @@ using Content.Shared.Damage;
|
||||
using Content.Server.Examine;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Server.Cargo.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Inventory;
|
||||
|
||||
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()
|
||||
{
|
||||
@@ -17,6 +23,43 @@ namespace Content.Server.Armor
|
||||
|
||||
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user