Files
tbd-station-14/Content.Server/Armor/ArmorSystem.cs
Nemanja 98fa00a21f Borgs (#18136)
* Laws

* positronic brain and PAI rewrite

* MMI

* MMI pt. 2

* borg brain transfer

* Roleban support, Borg job (WIP), the end of mind shenaniganry

* battery drain, item slot cleanup, alerts

* visuals

* fix this pt1

* fix this pt2

* Modules, Lingering Stacks, Better borg flashlight

* Start on UI, fix battery alerts, expand activation/deactivation, low movement speed on no power.

* sprotes

* no zombie borgs

* oh fuck yeah i love a good relay

* charger

* fix the tiniest of sprite issues

* adjustable names

* a functional UI????

* foobar

* more modules

* this shit for some reason

* upstream

* genericize selectable borg modules

* upstream again

* holy fucking shit

* i love christ

* proper construction

* da job

* AA borgs

* and boom more shit

* admin logs

* laws redux

* ok just do this rq

* oh boy that looks like modules

* oh shit research

* testos passo

* so much shit holy fuck

* fuckit we SHIP

* last minute snags

* should've gotten me on a better day
2023-08-12 16:39:58 -05:00

126 lines
4.6 KiB
C#

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;
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);
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)
{
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 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"));
}
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;
}
}
}
[ByRefEvent]
public record struct ArmorExamineEvent(FormattedMessage Msg);