# Conflicts: # Content.Client/Administration/AdminNameOverlay.cs # Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml # Content.Client/Guidebook/Controls/GuideReagentReaction.xaml # Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs # Content.Client/SubFloor/SubFloorHideSystem.cs # Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs # Content.Server/Antag/AntagSelectionSystem.cs # Content.Server/Cloning/CloningSystem.cs # Content.Server/GameTicking/Rules/Components/ParadoxCloneRuleComponent.cs # Content.Server/GameTicking/Rules/ParadoxCloneRuleSystem.cs # Content.Server/Roles/ParadoxCloneRoleComponent.cs # Content.Shared.Database/LogType.cs # Content.Shared/CCVar/CCVars.Interface.cs # Content.Shared/Cloning/CloningEvents.cs # Content.Shared/Cloning/CloningSettingsPrototype.cs # Content.Shared/Humanoid/NamingSystem.cs # Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs # Content.Shared/Light/Components/SunShadowCycleComponent.cs # Content.Shared/Storage/StorageComponent.cs # Resources/Changelog/Admin.yml # Resources/Changelog/Changelog.yml # Resources/Credits/GitHub.txt # Resources/Locale/en-US/paradox-clone/role.ftl # Resources/Maps/bagel.yml # Resources/Maps/loop.yml # Resources/Prototypes/Chemistry/mixing_types.yml # Resources/Prototypes/Datasets/Names/last.yml # Resources/Prototypes/Entities/Effects/puddle.yml # Resources/Prototypes/Entities/Mobs/Player/clone.yml # Resources/Prototypes/Entities/Mobs/Species/base.yml # Resources/Prototypes/Entities/Objects/Deliveries/deliveries_tables.yml # Resources/Prototypes/Entities/Objects/Devices/pda.yml # Resources/Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml # Resources/Prototypes/GameRules/events.yml # Resources/Prototypes/Maps/Pools/default.yml # Resources/Prototypes/Objectives/paradoxClone.yml # Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml # Resources/Textures/Clothing/Eyes/Glasses/jensen.rsi/equipped-EYES-arachnid.png
123 lines
4.7 KiB
C#
123 lines
4.7 KiB
C#
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<CoefficientQueryEvent>>(OnCoefficientQuery);
|
|
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
|
|
SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
|
|
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the total Damage reduction value of all equipment caught by the relay.
|
|
/// </summary>
|
|
/// <param name="ent">The item that's being relayed to</param>
|
|
/// <param name="args">The event, contains the running count of armor percentage as a coefficient</param>
|
|
private void OnCoefficientQuery(Entity<ArmorComponent> ent, ref InventoryRelayedEvent<CoefficientQueryEvent> args)
|
|
{
|
|
foreach (var armorCoefficient in ent.Comp.Modifiers.Coefficients)
|
|
{
|
|
args.Args.DamageModifiers.Coefficients[armorCoefficient.Key] = args.Args.DamageModifiers.Coefficients.TryGetValue(armorCoefficient.Key, out var coefficient) ? coefficient * armorCoefficient.Value : armorCoefficient.Value;
|
|
}
|
|
}
|
|
|
|
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 || !component.ShowArmorOnExamine)
|
|
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.AddMarkupOrThrow(Loc.GetString("armor-examine"));
|
|
|
|
foreach (var coefficientArmor in armorModifiers.Coefficients)
|
|
{
|
|
msg.PushNewline();
|
|
|
|
var armorType = Loc.GetString("armor-damage-type-" + coefficientArmor.Key.ToLower());
|
|
msg.AddMarkupOrThrow(Loc.GetString("armor-coefficient-value",
|
|
("type", armorType),
|
|
("value", MathF.Round((1f - coefficientArmor.Value) * 100, 1))
|
|
));
|
|
}
|
|
|
|
foreach (var flatArmor in armorModifiers.FlatReduction)
|
|
{
|
|
msg.PushNewline();
|
|
|
|
var armorType = Loc.GetString("armor-damage-type-" + flatArmor.Key.ToLower());
|
|
msg.AddMarkupOrThrow(Loc.GetString("armor-reduction-value",
|
|
("type", armorType),
|
|
("value", flatArmor.Value)
|
|
));
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
//CP14 public armor edit API
|
|
public void EditArmorCoefficients(EntityUid uid, DamageModifierSet modifiers, ArmorComponent? armor = null)
|
|
{
|
|
if (!Resolve(uid, ref armor))
|
|
return;
|
|
|
|
//Merge old and new coefficients
|
|
foreach (var (armorType, coefficient) in modifiers.Coefficients)
|
|
{
|
|
if (!armor.Modifiers.Coefficients.ContainsKey(armorType))
|
|
armor.Modifiers.Coefficients[armorType] = 1;
|
|
|
|
armor.Modifiers.Coefficients[armorType] += coefficient;
|
|
}
|
|
|
|
//Merge old and new flat reductions
|
|
foreach (var (armorType, reduction) in modifiers.FlatReduction)
|
|
{
|
|
if (!armor.Modifiers.FlatReduction.ContainsKey(armorType))
|
|
armor.Modifiers.FlatReduction[armorType] = 0;
|
|
|
|
armor.Modifiers.FlatReduction[armorType] += reduction;
|
|
}
|
|
}
|
|
//CP14 public armor edit API end
|
|
}
|