using Content.Shared.Clothing.Components;
using Content.Shared.Ninja.Components;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Popups;
namespace Content.Shared.Ninja.Systems;
///
/// Provides shared ninja API, handles being attacked revealing ninja and stops guns from shooting.
///
public abstract class SharedSpaceNinjaSystem : EntitySystem
{
[Dependency] protected readonly SharedNinjaSuitSystem _suit = default!;
[Dependency] protected readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnNinjaAttacked);
SubscribeLocalEvent(OnShotAttempted);
}
///
/// Set the ninja's worn suit entity
///
public void AssignSuit(EntityUid uid, EntityUid? suit, SpaceNinjaComponent? comp = null)
{
if (!Resolve(uid, ref comp) || comp.Suit == suit)
return;
comp.Suit = suit;
Dirty(uid, comp);
}
///
/// Set the ninja's worn gloves entity
///
public void AssignGloves(EntityUid uid, EntityUid? gloves, SpaceNinjaComponent? comp = null)
{
if (!Resolve(uid, ref comp) || comp.Gloves == gloves)
return;
comp.Gloves = gloves;
Dirty(uid, comp);
}
///
/// Bind a katana entity to a ninja, letting it be recalled and dash.
///
public void BindKatana(EntityUid uid, EntityUid? katana, SpaceNinjaComponent? comp = null)
{
if (!Resolve(uid, ref comp) || comp.Katana == katana)
return;
comp.Katana = katana;
Dirty(uid, comp);
}
///
/// Gets the user's battery and tries to use some charge from it, returning true if successful.
/// Serverside only.
///
public virtual bool TryUseCharge(EntityUid user, float charge)
{
return false;
}
///
/// Handle revealing ninja if cloaked when attacked.
///
private void OnNinjaAttacked(EntityUid uid, SpaceNinjaComponent comp, AttackedEvent args)
{
if (comp.Suit != null && TryComp(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
{
_suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing);
}
}
///
/// Require ninja to fight with HONOR, no guns!
///
private void OnShotAttempted(EntityUid uid, SpaceNinjaComponent comp, ref ShotAttemptedEvent args)
{
_popup.PopupClient(Loc.GetString("gun-disabled"), uid, uid);
args.Cancel();
}
}