diff --git a/Content.Server/Ninja/Systems/NinjaSuitSystem.cs b/Content.Server/Ninja/Systems/NinjaSuitSystem.cs index 244b7adf03..20674dda87 100644 --- a/Content.Server/Ninja/Systems/NinjaSuitSystem.cs +++ b/Content.Server/Ninja/Systems/NinjaSuitSystem.cs @@ -22,6 +22,9 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem [Dependency] private readonly PowerCellSystem _powerCell = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + // How much the cell score should be increased per 1 AutoRechargeRate. + private const int AutoRechargeValue = 100; + public override void Initialize() { base.Initialize(); @@ -59,15 +62,26 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem return; // no power cell for some reason??? allow it - if (!_powerCell.TryGetBatteryFromSlot(uid, out var battery)) + if (!_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery)) return; - // can only upgrade power cell, not swap to recharge instantly otherwise ninja could just swap batteries with flashlights in maints for easy power - if (!TryComp(args.EntityUid, out var inserting) || inserting.MaxCharge <= battery.MaxCharge) + if (!TryComp(args.EntityUid, out var inserting)) + { args.Cancel(); + return; + } + + var user = Transform(uid).ParentUid; + + // can only upgrade power cell, not swap to recharge instantly otherwise ninja could just swap batteries with flashlights in maints for easy power + if (GetCellScore(inserting.Owner, inserting) <= GetCellScore(battery.Owner, battery)) + { + args.Cancel(); + Popup.PopupEntity(Loc.GetString("ninja-cell-downgrade"), user, user); + return; + } // tell ninja abilities that use battery to update it so they don't use charge from the old one - var user = Transform(uid).ParentUid; if (!_ninja.IsNinja(user)) return; @@ -76,6 +90,16 @@ public sealed class NinjaSuitSystem : SharedNinjaSuitSystem RaiseLocalEvent(user, ref ev); } + // this function assigns a score to a power cell depending on the capacity, to be used when comparing which cell is better. + private float GetCellScore(EntityUid uid, BatteryComponent battcomp) + { + // if a cell is able to automatically recharge, boost the score drastically depending on the recharge rate, + // this is to ensure a ninja can still upgrade to a micro reactor cell even if they already have a medium or high. + if (TryComp(uid, out var selfcomp) && selfcomp.AutoRecharge) + return battcomp.MaxCharge + (selfcomp.AutoRechargeRate*AutoRechargeValue); + return battcomp.MaxCharge; + } + private void OnEmpAttempt(EntityUid uid, NinjaSuitComponent comp, EmpAttemptEvent args) { // ninja suit (battery) is immune to emp diff --git a/Resources/Locale/en-US/ninja/ninja-actions.ftl b/Resources/Locale/en-US/ninja/ninja-actions.ftl index f01f02a60e..b3e295b7a2 100644 --- a/Resources/Locale/en-US/ninja/ninja-actions.ftl +++ b/Resources/Locale/en-US/ninja/ninja-actions.ftl @@ -1,6 +1,8 @@ ninja-no-power = Not enough charge in suit battery! ninja-revealed = You have been revealed! ninja-suit-cooldown = The suit needs time to recuperate from the last attack. +ninja-cell-downgrade = The suit will only accept a new power cell that is better than the current one! +ninja-cell-too-large = This power source does not fit in the ninja suit! ninja-research-steal-fail = No new research nodes were stolen... ninja-research-steal-success = Stole {$count} new nodes from {THE($server)}. diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml index c90e0c98f5..a58c2a3fdd 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml @@ -187,6 +187,9 @@ name: power-cell-slot-component-slot-name-default startingItem: PowerCellSmall disableEject: true + whitelist: + tags: + - PowerCell - type: entity parent: ClothingOuterBase