* item toggle refactoring and some new systems * add ToggleClothing component/system * unhardcode magboots gravity logic * make magboots and speedboots use ItemToggle and stuff * remove now useless clothing components * update client/server magboots systems * add note to use ItemToggledEvent in ToggleActionEvent doc * refactor PowerCellDraw to use ItemToggle for ui open/close control * add TryUseCharges, refactor charges system * update magboot trigger code * make borg use ItemToggle, network SelectedModule instead of now removed Activated * add AccessToggle for borg * the giga ninja refactor * update ninja yml * update ItemToggle usage for some stuff * fix activatableui requires power * random fixing * yaml fixing * nuke ItemToggleDisarmMalus * make defib use ItemToggle * make things that use power not turn on if missing use charge * pro * fix sound prediction * bruh * proximity detector use ItemToggle * oop * big idiot syndrome * fix ninja spawn rule and make it generic * fix ninja spawn rule yml * move loading profiles into AntagLoadProfileRule * more ninja refactor * ninja yml fixes * the dreaded copy paste ops * remove useless NinjaRuleComponent and ue AntagSelection for greeting * fix invisibility * move IsCompleted to SharedObjectivesSystem * ability fixes * oop fix powercell instantly draining itself * sentient speedboots gaming * make reflect use ItemToggle * fix other test * loadprofilerule moved into its own pr * remove conflict with dragon refactor * remove all GenericAntag code from ninja * ) * probably * remove old enabled * great language bravo vince * GREAT LANGUAGE * who made this language * because it stinks * reparent blood-red magboots to magboots probbbly works * most of the review stuff * hasGrav doesnt mean what i thought it did * make health analyzer use itemtoggle, not fail test * fix mag/speed boots being wacky * UNTROLL * add ItemToggle to the random health analyzers * a * remove unused obsolete borg func * untrolling * :trollface: * fix test * fix * g * untroll --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
132 lines
4.8 KiB
C#
132 lines
4.8 KiB
C#
using Content.Server.Emp;
|
|
using Content.Server.Ninja.Events;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.PowerCell;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Ninja.Components;
|
|
using Content.Shared.Ninja.Systems;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.PowerCell.Components;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server.Ninja.Systems;
|
|
|
|
/// <summary>
|
|
/// Handles power cell upgrading and actions.
|
|
/// </summary>
|
|
public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
|
|
{
|
|
[Dependency] private readonly EmpSystem _emp = default!;
|
|
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
|
[Dependency] private readonly SpaceNinjaSystem _ninja = default!;
|
|
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<NinjaSuitComponent, ContainerIsInsertingAttemptEvent>(OnSuitInsertAttempt);
|
|
SubscribeLocalEvent<NinjaSuitComponent, EmpAttemptEvent>(OnEmpAttempt);
|
|
SubscribeLocalEvent<NinjaSuitComponent, RecallKatanaEvent>(OnRecallKatana);
|
|
SubscribeLocalEvent<NinjaSuitComponent, NinjaEmpEvent>(OnEmp);
|
|
}
|
|
|
|
protected override void NinjaEquipped(Entity<NinjaSuitComponent> ent, Entity<SpaceNinjaComponent> user)
|
|
{
|
|
base.NinjaEquipped(ent, user);
|
|
|
|
_ninja.SetSuitPowerAlert(user);
|
|
}
|
|
|
|
// TODO: if/when battery is in shared, put this there too
|
|
// TODO: or put MaxCharge in shared along with powercellslot
|
|
private void OnSuitInsertAttempt(EntityUid uid, NinjaSuitComponent comp, ContainerIsInsertingAttemptEvent args)
|
|
{
|
|
// this is for handling battery upgrading, not stopping actions from being added
|
|
// if another container like ActionsContainer is specified, don't handle it
|
|
if (TryComp<PowerCellSlotComponent>(uid, out var slot) && args.Container.ID != slot.CellSlotId)
|
|
return;
|
|
|
|
// no power cell for some reason??? allow it
|
|
if (!_powerCell.TryGetBatteryFromSlot(uid, 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<BatteryComponent>(args.EntityUid, out var inserting) || inserting.MaxCharge <= battery.MaxCharge)
|
|
args.Cancel();
|
|
|
|
// 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;
|
|
|
|
var ev = new NinjaBatteryChangedEvent(args.EntityUid, uid);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
RaiseLocalEvent(user, ref ev);
|
|
}
|
|
|
|
private void OnEmpAttempt(EntityUid uid, NinjaSuitComponent comp, EmpAttemptEvent args)
|
|
{
|
|
// ninja suit (battery) is immune to emp
|
|
// powercell relays the event to suit
|
|
args.Cancel();
|
|
}
|
|
|
|
protected override void UserUnequippedSuit(Entity<NinjaSuitComponent> ent, Entity<SpaceNinjaComponent> user)
|
|
{
|
|
base.UserUnequippedSuit(ent, user);
|
|
|
|
// remove power indicator
|
|
_ninja.SetSuitPowerAlert(user);
|
|
}
|
|
|
|
private void OnRecallKatana(Entity<NinjaSuitComponent> ent, ref RecallKatanaEvent args)
|
|
{
|
|
var (uid, comp) = ent;
|
|
var user = args.Performer;
|
|
if (!_ninja.NinjaQuery.TryComp(user, out var ninja) || ninja.Katana == null)
|
|
return;
|
|
|
|
args.Handled = true;
|
|
|
|
var katana = ninja.Katana.Value;
|
|
var coords = _transform.GetWorldPosition(katana);
|
|
var distance = (_transform.GetWorldPosition(user) - coords).Length();
|
|
var chargeNeeded = distance * comp.RecallCharge;
|
|
if (!_ninja.TryUseCharge(user, chargeNeeded))
|
|
{
|
|
Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
|
|
return;
|
|
}
|
|
|
|
if (CheckDisabled(ent, user))
|
|
return;
|
|
|
|
// TODO: teleporting into belt slot
|
|
var message = _hands.TryPickupAnyHand(user, katana)
|
|
? "ninja-katana-recalled"
|
|
: "ninja-hands-full";
|
|
Popup.PopupEntity(Loc.GetString(message), user, user);
|
|
}
|
|
|
|
private void OnEmp(Entity<NinjaSuitComponent> ent, ref NinjaEmpEvent args)
|
|
{
|
|
var (uid, comp) = ent;
|
|
args.Handled = true;
|
|
|
|
var user = args.Performer;
|
|
if (!_ninja.TryUseCharge(user, comp.EmpCharge))
|
|
{
|
|
Popup.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
|
|
return;
|
|
}
|
|
|
|
if (CheckDisabled(ent, user))
|
|
return;
|
|
|
|
var coords = _transform.GetMapCoordinates(user);
|
|
_emp.EmpPulse(coords, comp.EmpRange, comp.EmpConsumption, comp.EmpDuration);
|
|
}
|
|
}
|