mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +03:00
# Description Title, it replaces the eshield in the BSO's loadout. I had to tweak the values to be a little less... extreme. Also made EMP immune untill somebody ports the eshield changes fully, as right now, the eshield is emp immune, so why would the greatshield be disabled by it. Also, added a way to smart-equip the shield from your belt, if you've already taken out the mace (which can also be put in the belt slot by itself just like a stun baton.) --- <details><summary><h1>Media</h1></summary> <p> [Video of the stamina damage of the mace, and the shield health & recharge.](https://github.com/user-attachments/assets/8b98dda2-e7ab-4b4d-be41-6f0c247b3e10) </p> </details> --- # Changelog 🆑 BramvanZijp - add: Added the BSO's Greatshield and Atrocity (Mace) as a primary weapon option. - remove: The Energy Shield has been removed from the BSO's loadout. --------- Signed-off-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit d1cc81ca03a35ecd5cf38d280b20b54c1bc63536)
99 lines
4.1 KiB
C#
99 lines
4.1 KiB
C#
using Content.Server.Power.Components;
|
|
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.PowerCell;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Item.ItemToggle;
|
|
using Content.Shared.Item.ItemToggle.Components;
|
|
using Content.Shared.PowerCell.Components;
|
|
|
|
namespace Content.Server._White.Blocking;
|
|
|
|
public sealed class RechargeableBlockingSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly BatterySystem _battery = default!;
|
|
[Dependency] private readonly ItemToggleSystem _itemToggle = default!;
|
|
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<RechargeableBlockingComponent, ExaminedEvent>(OnExamined);
|
|
SubscribeLocalEvent<RechargeableBlockingComponent, DamageChangedEvent>(OnDamageChanged);
|
|
SubscribeLocalEvent<RechargeableBlockingComponent, ItemToggleActivateAttemptEvent>(AttemptToggle);
|
|
SubscribeLocalEvent<RechargeableBlockingComponent, ChargeChangedEvent>(OnChargeChanged);
|
|
SubscribeLocalEvent<RechargeableBlockingComponent, PowerCellChangedEvent>(OnPowerCellChanged);
|
|
}
|
|
|
|
private void OnExamined(EntityUid uid, RechargeableBlockingComponent component, ExaminedEvent args)
|
|
{
|
|
if (!component.Discharged)
|
|
{
|
|
_powerCell.OnBatteryExamined(uid, null, args);
|
|
return;
|
|
}
|
|
|
|
args.PushMarkup(Loc.GetString("rechargeable-blocking-discharged"));
|
|
args.PushMarkup(Loc.GetString("rechargeable-blocking-remaining-time", ("remainingTime", GetRemainingTime(uid))));
|
|
}
|
|
|
|
private int GetRemainingTime(EntityUid uid)
|
|
{
|
|
if (!_battery.TryGetBatteryComponent(uid, out var batteryComponent, out var batteryUid)
|
|
|| !TryComp<BatterySelfRechargerComponent>(batteryUid, out var recharger)
|
|
|| recharger is not { AutoRechargeRate: > 0, AutoRecharge: true })
|
|
return 0;
|
|
|
|
return (int) MathF.Round((batteryComponent.MaxCharge - batteryComponent.CurrentCharge) /
|
|
recharger.AutoRechargeRate);
|
|
}
|
|
|
|
private void OnDamageChanged(EntityUid uid, RechargeableBlockingComponent component, DamageChangedEvent args)
|
|
{
|
|
if (!_battery.TryGetBatteryComponent(uid, out var batteryComponent, out var batteryUid)
|
|
|| !_itemToggle.IsActivated(uid)
|
|
|| args.DamageDelta == null)
|
|
return;
|
|
|
|
var batteryUse = Math.Min(args.DamageDelta.GetTotal().Float(), batteryComponent.CurrentCharge);
|
|
_battery.TryUseCharge(batteryUid.Value, batteryUse, batteryComponent);
|
|
}
|
|
|
|
private void AttemptToggle(EntityUid uid, RechargeableBlockingComponent component, ref ItemToggleActivateAttemptEvent args)
|
|
{
|
|
if (!component.Discharged)
|
|
return;
|
|
|
|
args.Popup = Loc.GetString("rechargeable-blocking-remaining-time-popup",
|
|
("remainingTime", GetRemainingTime(uid)));
|
|
args.Cancelled = true;
|
|
}
|
|
|
|
private void OnChargeChanged(EntityUid uid, RechargeableBlockingComponent component, ChargeChangedEvent args) => CheckCharge(uid, component);
|
|
|
|
private void OnPowerCellChanged(EntityUid uid, RechargeableBlockingComponent component, PowerCellChangedEvent args) => CheckCharge(uid, component);
|
|
|
|
private void CheckCharge(EntityUid uid, RechargeableBlockingComponent component)
|
|
{
|
|
if (!_battery.TryGetBatteryComponent(uid, out var battery, out _))
|
|
return;
|
|
|
|
BatterySelfRechargerComponent? recharger;
|
|
if (battery.CurrentCharge < 1)
|
|
{
|
|
if (TryComp(uid, out recharger))
|
|
recharger.AutoRechargeRate = component.DischargedRechargeRate;
|
|
|
|
component.Discharged = true;
|
|
_itemToggle.TryDeactivate(uid, predicted: false);
|
|
return;
|
|
}
|
|
|
|
if (battery.CurrentCharge < (battery.MaxCharge - 0.01)) // Auto recharge sometimes does not FULLY recharge, this compensates for that
|
|
return;
|
|
|
|
component.Discharged = false;
|
|
if (TryComp(uid, out recharger))
|
|
recharger.AutoRechargeRate = component.ChargedRechargeRate;
|
|
}
|
|
}
|