ninja 2 electric boogaloo (#15534)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-09-10 07:20:27 +01:00
committed by GitHub
parent 25c8a03276
commit 24810d916b
153 changed files with 3892 additions and 78 deletions

View File

@@ -0,0 +1,38 @@
using Content.Shared.Ninja.Systems;
using Robust.Shared.Audio;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for draining power from APCs/substations/SMESes, when ProviderUid is set to a battery cell.
/// Does not rely on relay, simply being on the user and having BatteryUid set is enough.
/// </summary>
[RegisterComponent, Access(typeof(SharedBatteryDrainerSystem))]
public sealed partial class BatteryDrainerComponent : Component
{
/// <summary>
/// The powercell entity to drain power into.
/// Determines whether draining is possible.
/// </summary>
[DataField("batteryUid"), ViewVariables(VVAccess.ReadWrite)]
public EntityUid? BatteryUid;
/// <summary>
/// Conversion rate between joules in a device and joules added to battery.
/// Should be very low since powercells store nothing compared to even an APC.
/// </summary>
[DataField("drainEfficiency"), ViewVariables(VVAccess.ReadWrite)]
public float DrainEfficiency = 0.001f;
/// <summary>
/// Time that the do after takes to drain charge from a battery, in seconds
/// </summary>
[DataField("drainTime"), ViewVariables(VVAccess.ReadWrite)]
public float DrainTime = 1f;
/// <summary>
/// Sound played after the doafter ends.
/// </summary>
[DataField("sparkSound")]
public SoundSpecifier SparkSound = new SoundCollectionSpecifier("sparks");
}

View File

@@ -0,0 +1,33 @@
using Content.Shared.Actions;
using Content.Shared.Ninja.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
/// <summary>
/// Adds an action to dash, teleport to clicked position, when this item is held.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(DashAbilitySystem))]
public sealed partial class DashAbilityComponent : Component
{
/// <summary>
/// The action id for dashing.
/// </summary>
[DataField("dashAction", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string DashAction = string.Empty;
[DataField("dashActionEntity")]
public EntityUid? DashActionEntity;
/// <summary>
/// Sound played when using dash action.
/// </summary>
[DataField("blinkSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier BlinkSound = new SoundPathSpecifier("/Audio/Magic/blink.ogg")
{
Params = AudioParams.Default.WithVolume(5f)
};
}
public sealed partial class DashEvent : WorldTargetActionEvent { }

View File

@@ -0,0 +1,28 @@
using Content.Shared.Ninja.Systems;
using Content.Shared.Tag;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for emagging things on click.
/// No charges but checks against a whitelist.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(EmagProviderSystem))]
public sealed partial class EmagProviderComponent : Component
{
/// <summary>
/// The tag that marks an entity as immune to emagging.
/// </summary>
[DataField("emagImmuneTag", customTypeSerializer: typeof(PrototypeIdSerializer<TagPrototype>))]
public string EmagImmuneTag = "EmagImmune";
/// <summary>
/// Whitelist that entities must be on to work.
/// </summary>
[DataField("whitelist"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public EntityWhitelist? Whitelist = null;
}

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for a Space Ninja's katana, controls ninja related dash logic.
/// Requires a ninja with a suit for abilities to work.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class EnergyKatanaComponent : Component
{
}

View File

@@ -0,0 +1,45 @@
using Content.Shared.DoAfter;
using Content.Shared.Ninja.Systems;
using Content.Shared.Toggleable;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for toggling glove powers.
/// Powers being enabled is controlled by User not being null.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedNinjaGlovesSystem))]
public sealed partial class NinjaGlovesComponent : Component
{
/// <summary>
/// Entity of the ninja using these gloves, usually means enabled
/// </summary>
[DataField("user"), AutoNetworkedField]
public EntityUid? User;
/// <summary>
/// The action id for toggling ninja gloves abilities
/// </summary>
[DataField("toggleAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string ToggleAction = "ActionToggleNinjaGloves";
[DataField("toggleActionEntity")]
public EntityUid? ToggleActionEntity;
/// <summary>
/// The whitelist used for the emag provider to emag airlocks only (not regular doors).
/// </summary>
[DataField("doorjackWhitelist")]
public EntityWhitelist DoorjackWhitelist = new()
{
Components = new[] {"Airlock"}
};
}

View File

@@ -0,0 +1,125 @@
using Content.Shared.Actions;
using Content.Shared.Ninja.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for ninja suit abilities and power consumption.
/// As an implementation detail, dashing with katana is a suit action which isn't ideal.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedNinjaSuitSystem))]
public sealed partial class NinjaSuitComponent : Component
{
/// <summary>
/// Battery charge used passively, in watts. Will last 1000 seconds on a small-capacity power cell.
/// </summary>
[DataField("passiveWattage")]
public float PassiveWattage = 0.36f;
/// <summary>
/// Battery charge used while cloaked, stacks with passive. Will last 200 seconds while cloaked on a small-capacity power cell.
/// </summary>
[DataField("cloakWattage")]
public float CloakWattage = 1.44f;
/// <summary>
/// Sound played when a ninja is hit while cloaked.
/// </summary>
[DataField("revealSound")]
public SoundSpecifier RevealSound = new SoundPathSpecifier("/Audio/Effects/chime.ogg");
/// <summary>
/// How long to disable all abilities for when revealed.
/// This adds a UseDelay to the ninja so it should not be set by anything else.
/// </summary>
[DataField("disableTime")]
public TimeSpan DisableTime = TimeSpan.FromSeconds(5);
/// <summary>
/// The action id for creating throwing stars.
/// </summary>
[DataField("createThrowingStarAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string CreateThrowingStarAction = "ActionCreateThrowingStar";
[DataField("createThrowingStarActionEntity")]
public EntityUid? CreateThrowingStarActionEntity;
/// <summary>
/// Battery charge used to create a throwing star. Can do it 25 times on a small-capacity power cell.
/// </summary>
[DataField("throwingStarCharge")]
public float ThrowingStarCharge = 14.4f;
/// <summary>
/// Throwing star item to create with the action
/// </summary>
[DataField("throwingStarPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string ThrowingStarPrototype = "ThrowingStarNinja";
/// <summary>
/// The action id for recalling a bound energy katana
/// </summary>
[DataField("recallKatanaAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string RecallKatanaAction = "ActionRecallKatana";
[DataField("recallKatanaActionEntity")]
public EntityUid? RecallKatanaActionEntity;
/// <summary>
/// Battery charge used per tile the katana teleported.
/// Uses 1% of a default battery per tile.
/// </summary>
[DataField("recallCharge")]
public float RecallCharge = 3.6f;
/// <summary>
/// The action id for creating an EMP burst
/// </summary>
[DataField("empAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string EmpAction = "ActionNinjaEmp";
[DataField("empActionEntity")]
public EntityUid? EmpActionEntity;
/// <summary>
/// Battery charge used to create an EMP burst. Can do it 2 times on a small-capacity power cell.
/// </summary>
[DataField("empCharge")]
public float EmpCharge = 180f;
/// <summary>
/// Range of the EMP in tiles.
/// </summary>
[DataField("empRange")]
public float EmpRange = 6f;
/// <summary>
/// Power consumed from batteries by the EMP
/// </summary>
[DataField("empConsumption")]
public float EmpConsumption = 100000f;
/// <summary>
/// How long the EMP effects last for, in seconds
/// </summary>
[DataField("empDuration")]
public float EmpDuration = 60f;
}
public sealed partial class CreateThrowingStarEvent : InstantActionEvent
{
}
public sealed partial class RecallKatanaEvent : InstantActionEvent
{
}
public sealed partial class NinjaEmpEvent : InstantActionEvent
{
}

View File

@@ -0,0 +1,38 @@
using Content.Shared.Ninja.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component placed on a mob to make it a space ninja, able to use suit and glove powers.
/// Contains ids of all ninja equipment and the game rule.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedSpaceNinjaSystem))]
public sealed partial class SpaceNinjaComponent : Component
{
/// <summary>
/// The ninja game rule that spawned this ninja.
/// </summary>
[DataField("rule")]
public EntityUid? Rule;
/// <summary>
/// Currently worn suit
/// </summary>
[DataField("suit"), AutoNetworkedField]
public EntityUid? Suit;
/// <summary>
/// Currently worn gloves
/// </summary>
[DataField("gloves"), AutoNetworkedField]
public EntityUid? Gloves;
/// <summary>
/// Bound katana, set once picked up and never removed
/// </summary>
[DataField("katana"), AutoNetworkedField]
public EntityUid? Katana;
}

View File

@@ -0,0 +1,19 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for the Space Ninja's unique Spider Charge.
/// Only this component detonating can trigger the ninja's objective.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class SpiderChargeComponent : Component
{
/// Range for planting within the target area
[DataField("range")]
public float Range = 10f;
/// The ninja that planted this charge
[DataField("planter")]
public EntityUid? Planter = null;
}

View File

@@ -0,0 +1,67 @@
using Content.Shared.Ninja.Systems;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for stunning mobs on click outside of harm mode.
/// Knocks them down for a bit and deals shock damage.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedStunProviderSystem))]
public sealed partial class StunProviderComponent : Component
{
/// <summary>
/// The powercell entity to take power from.
/// Determines whether stunning is possible.
/// </summary>
[DataField("batteryUid"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public EntityUid? BatteryUid;
/// <summary>
/// Joules required in the battery to stun someone. Defaults to 10 uses on a small battery.
/// </summary>
[DataField("stunCharge"), ViewVariables(VVAccess.ReadWrite)]
public float StunCharge = 36.0f;
/// <summary>
/// Shock damage dealt when stunning someone
/// </summary>
[DataField("stunDamage"), ViewVariables(VVAccess.ReadWrite)]
public int StunDamage = 5;
/// <summary>
/// Time that someone is stunned for, stacks if done multiple times.
/// </summary>
[DataField("stunTime"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan StunTime = TimeSpan.FromSeconds(3);
/// <summary>
/// How long stunning is disabled after stunning something.
/// </summary>
[DataField("cooldown"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan Cooldown = TimeSpan.FromSeconds(1);
/// <summary>
/// Locale string to popup when there is no power
/// </summary>
[DataField("noPowerPopup", required: true), ViewVariables(VVAccess.ReadWrite)]
public string NoPowerPopup = string.Empty;
/// <summary>
/// Whitelist for what counts as a mob.
/// </summary>
[DataField("whitelist")]
public EntityWhitelist Whitelist = new()
{
Components = new[] {"Stamina"}
};
/// <summary>
/// When someone can next be stunned.
/// Essentially a UseDelay unique to this component.
/// </summary>
[DataField("nextStun", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextStun = TimeSpan.Zero;
}

View File

@@ -0,0 +1,118 @@
using Content.Shared.Actions;
using Content.Shared.Charges.Components;
using Content.Shared.Charges.Systems;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Ninja.Components;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Timing;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Handles dashing logic including charge consumption and checking attempt events.
/// </summary>
public sealed class DashAbilitySystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedChargesSystem _charges = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DashAbilityComponent, GetItemActionsEvent>(OnGetItemActions);
SubscribeLocalEvent<DashAbilityComponent, DashEvent>(OnDash);
}
private void OnGetItemActions(EntityUid uid, DashAbilityComponent comp, GetItemActionsEvent args)
{
var ev = new AddDashActionEvent(args.User);
RaiseLocalEvent(uid, ev);
if (ev.Cancelled)
return;
args.AddAction(ref comp.DashActionEntity, comp.DashAction);
}
/// <summary>
/// Handle charges and teleport to a visible location.
/// </summary>
private void OnDash(EntityUid uid, DashAbilityComponent comp, DashEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var user = args.Performer;
args.Handled = true;
var ev = new DashAttemptEvent(user);
RaiseLocalEvent(uid, ev);
if (ev.Cancelled)
return;
if (!_hands.IsHolding(user, uid, out var _))
{
_popup.PopupClient(Loc.GetString("dash-ability-not-held", ("item", uid)), user, user);
return;
}
TryComp<LimitedChargesComponent>(uid, out var charges);
if (_charges.IsEmpty(uid, charges))
{
_popup.PopupClient(Loc.GetString("dash-ability-no-charges", ("item", uid)), user, user);
return;
}
var origin = Transform(user).MapPosition;
var target = args.Target.ToMap(EntityManager, _transform);
// prevent collision with the user duh
if (!_interaction.InRangeUnobstructed(origin, target, 0f, CollisionGroup.Opaque, uid => uid == user))
{
// can only dash if the destination is visible on screen
_popup.PopupClient(Loc.GetString("dash-ability-cant-see", ("item", uid)), user, user);
return;
}
_transform.SetCoordinates(user, args.Target);
_transform.AttachToGridOrMap(user);
_audio.PlayPredicted(comp.BlinkSound, user, user);
if (charges != null)
_charges.UseCharge(uid, charges);
}
}
/// <summary>
/// Raised on the item before adding the dash action
/// </summary>
public sealed class AddDashActionEvent : CancellableEntityEventArgs
{
public EntityUid User;
public AddDashActionEvent(EntityUid user)
{
User = user;
}
}
/// <summary>
/// Raised on the item before dashing is done.
/// </summary>
public sealed class DashAttemptEvent : CancellableEntityEventArgs
{
public EntityUid User;
public DashAttemptEvent(EntityUid user)
{
User = user;
}
}

View File

@@ -0,0 +1,72 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Emag.Systems;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Ninja.Components;
using Content.Shared.Tag;
using Content.Shared.Whitelist;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Handles emagging whitelisted objects when clicked.
/// </summary>
public sealed class EmagProviderSystem : EntitySystem
{
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
[Dependency] private readonly TagSystem _tags = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmagProviderComponent, BeforeInteractHandEvent>(OnBeforeInteractHand);
}
/// <summary>
/// Emag clicked entities that are on the whitelist.
/// </summary>
private void OnBeforeInteractHand(EntityUid uid, EmagProviderComponent comp, BeforeInteractHandEvent args)
{
// TODO: change this into a generic check event thing
if (args.Handled || !_gloves.AbilityCheck(uid, args, out var target))
return;
// only allowed to emag entities on the whitelist
if (comp.Whitelist != null && !comp.Whitelist.IsValid(target, EntityManager))
return;
// only allowed to emag non-immune entities
if (_tags.HasTag(target, comp.EmagImmuneTag))
return;
var handled = _emag.DoEmagEffect(uid, target);
if (!handled)
return;
_adminLogger.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(uid):player} emagged {ToPrettyString(target):target}");
var ev = new EmaggedSomethingEvent(target);
RaiseLocalEvent(uid, ref ev);
args.Handled = true;
}
/// <summary>
/// Set the whitelist for emagging something outside of yaml.
/// </summary>
public void SetWhitelist(EntityUid uid, EntityWhitelist? whitelist, EmagProviderComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.Whitelist = whitelist;
Dirty(uid, comp);
}
}
/// <summary>
/// Raised on the player when emagging something.
/// </summary>
[ByRefEvent]
public record struct EmaggedSomethingEvent(EntityUid Target);

View File

@@ -0,0 +1,47 @@
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// System for katana binding and dash events. Recalling is handled by the suit.
/// </summary>
public sealed class EnergyKatanaSystem : EntitySystem
{
[Dependency] private readonly SharedSpaceNinjaSystem _ninja = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnergyKatanaComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<EnergyKatanaComponent, AddDashActionEvent>(OnAddDashAction);
SubscribeLocalEvent<EnergyKatanaComponent, DashAttemptEvent>(OnDashAttempt);
}
/// <summary>
/// When equipped by a ninja, try to bind it.
/// </summary>
private void OnEquipped(EntityUid uid, EnergyKatanaComponent comp, GotEquippedEvent args)
{
// check if user isnt a ninja or already has a katana bound
var user = args.Equipee;
if (!TryComp<SpaceNinjaComponent>(user, out var ninja) || ninja.Katana != null)
return;
// bind it since its unbound
_ninja.BindKatana(user, uid, ninja);
}
private void OnAddDashAction(EntityUid uid, EnergyKatanaComponent comp, AddDashActionEvent args)
{
if (!HasComp<SpaceNinjaComponent>(args.User))
args.Cancel();
}
private void OnDashAttempt(EntityUid uid, EnergyKatanaComponent comp, DashAttemptEvent args)
{
if (!TryComp<SpaceNinjaComponent>(args.User, out var ninja) || ninja.Katana != uid)
args.Cancel();
}
}

View File

@@ -0,0 +1,69 @@
using Content.Shared.Ninja.Components;
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Basic draining prediction and API, all real logic is handled serverside.
/// </summary>
public abstract class SharedBatteryDrainerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BatteryDrainerComponent, DoAfterAttemptEvent<DrainDoAfterEvent>>(OnDoAfterAttempt);
SubscribeLocalEvent<BatteryDrainerComponent, DrainDoAfterEvent>(OnDoAfter);
}
/// <summary>
/// Cancel any drain doafters if the battery is removed or gets filled.
/// </summary>
protected virtual void OnDoAfterAttempt(EntityUid uid, BatteryDrainerComponent comp, DoAfterAttemptEvent<DrainDoAfterEvent> args)
{
if (comp.BatteryUid == null)
{
args.Cancel();
}
}
/// <summary>
/// Drain power from a power source (on server) and repeat if it succeeded.
/// Client will predict always succeeding since power is serverside.
/// </summary>
private void OnDoAfter(EntityUid uid, BatteryDrainerComponent comp, DrainDoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Target == null)
return;
// repeat if there is still power to drain
args.Repeat = TryDrainPower(uid, comp, args.Target.Value);
}
/// <summary>
/// Attempt to drain as much power as possible into the powercell.
/// Client always predicts this as succeeding since power is serverside and it can only fail once, when the powercell is filled or the target is emptied.
/// </summary>
protected virtual bool TryDrainPower(EntityUid uid, BatteryDrainerComponent comp, EntityUid target)
{
return true;
}
/// <summary>
/// Sets the battery field on the drainer.
/// </summary>
public void SetBattery(EntityUid uid, EntityUid? battery, BatteryDrainerComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.BatteryUid = battery;
}
}
/// <summary>
/// DoAfter event for <see cref="BatteryDrainerComponent"/>.
/// </summary>
[Serializable, NetSerializable]
public sealed partial class DrainDoAfterEvent : SimpleDoAfterEvent { }

View File

@@ -0,0 +1,116 @@
using Content.Shared.Actions;
using Content.Shared.CombatMode;
using Content.Shared.Communications;
using Content.Shared.Doors.Components;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Popups;
using Content.Shared.Research.Components;
using Content.Shared.Timing;
using Content.Shared.Toggleable;
using Robust.Shared.Timing;
using System.Diagnostics.CodeAnalysis;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Provides the toggle action and handles examining and unequipping.
/// </summary>
public abstract class SharedNinjaGlovesSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
[Dependency] protected readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] protected readonly SharedInteractionSystem Interaction = default!;
[Dependency] private readonly SharedSpaceNinjaSystem _ninja = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaGlovesComponent, GetItemActionsEvent>(OnGetItemActions);
SubscribeLocalEvent<NinjaGlovesComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<NinjaGlovesComponent, GotUnequippedEvent>(OnUnequipped);
}
/// <summary>
/// Disable glove abilities and show the popup if they were enabled previously.
/// </summary>
public void DisableGloves(EntityUid uid, NinjaGlovesComponent? comp = null)
{
// already disabled?
if (!Resolve(uid, ref comp) || comp.User == null)
return;
var user = comp.User.Value;
comp.User = null;
Dirty(uid, comp);
Appearance.SetData(uid, ToggleVisuals.Toggled, false);
Popup.PopupClient(Loc.GetString("ninja-gloves-off"), user, user);
RemComp<BatteryDrainerComponent>(user);
RemComp<EmagProviderComponent>(user);
RemComp<StunProviderComponent>(user);
RemComp<ResearchStealerComponent>(user);
RemComp<CommsHackerComponent>(user);
}
/// <summary>
/// Adds the toggle action when equipped.
/// </summary>
private void OnGetItemActions(EntityUid uid, NinjaGlovesComponent comp, GetItemActionsEvent args)
{
if (HasComp<SpaceNinjaComponent>(args.User))
args.AddAction(ref comp.ToggleActionEntity, comp.ToggleAction);
}
/// <summary>
/// Show if the gloves are enabled when examining.
/// </summary>
private void OnExamined(EntityUid uid, NinjaGlovesComponent comp, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
args.PushText(Loc.GetString(comp.User != null ? "ninja-gloves-examine-on" : "ninja-gloves-examine-off"));
}
/// <summary>
/// Disable gloves when unequipped and clean up ninja's gloves reference
/// </summary>
private void OnUnequipped(EntityUid uid, NinjaGlovesComponent comp, GotUnequippedEvent args)
{
if (comp.User != null)
{
var user = comp.User.Value;
Popup.PopupClient(Loc.GetString("ninja-gloves-off"), user, user);
DisableGloves(uid, comp);
}
}
// TODO: generic event thing
/// <summary>
/// GloveCheck but for abilities stored on the player, skips some checks.
/// Intended to be more generic, doesn't require the user to be a ninja or have any ninja equipment.
/// </summary>
public bool AbilityCheck(EntityUid uid, BeforeInteractHandEvent args, out EntityUid target)
{
target = args.Target;
return _timing.IsFirstTimePredicted
&& !_combatMode.IsInCombatMode(uid)
&& !_useDelay.ActiveDelay(uid)
&& TryComp<HandsComponent>(uid, out var hands)
&& hands.ActiveHandEntity == null
&& Interaction.InRangeUnobstructed(uid, target);
}
}

View File

@@ -0,0 +1,139 @@
using Content.Shared.Actions;
using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Timing;
using Robust.Shared.Audio;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// Handles (un)equipping and provides some API functions.
/// </summary>
public abstract class SharedNinjaSuitSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
[Dependency] protected readonly SharedSpaceNinjaSystem _ninja = default!;
[Dependency] protected readonly StealthClothingSystem StealthClothing = default!;
[Dependency] protected readonly UseDelaySystem UseDelay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaSuitComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<NinjaSuitComponent, GetItemActionsEvent>(OnGetItemActions);
SubscribeLocalEvent<NinjaSuitComponent, AddStealthActionEvent>(OnAddStealthAction);
SubscribeLocalEvent<NinjaSuitComponent, GotUnequippedEvent>(OnUnequipped);
}
/// <summary>
/// Call the shared and serverside code for when a ninja equips the suit.
/// </summary>
private void OnEquipped(EntityUid uid, NinjaSuitComponent comp, GotEquippedEvent args)
{
var user = args.Equipee;
if (!TryComp<SpaceNinjaComponent>(user, out var ninja))
return;
NinjaEquippedSuit(uid, comp, user, ninja);
}
/// <summary>
/// Add all the actions when a suit is equipped by a ninja.
/// </summary>
private void OnGetItemActions(EntityUid uid, NinjaSuitComponent comp, GetItemActionsEvent args)
{
if (!HasComp<SpaceNinjaComponent>(args.User))
return;
args.AddAction(ref comp.RecallKatanaActionEntity, comp.RecallKatanaAction);
args.AddAction(ref comp.CreateThrowingStarActionEntity, comp.CreateThrowingStarAction);
args.AddAction(ref comp.EmpActionEntity, comp.EmpAction);
}
/// <summary>
/// Only add stealth clothing's toggle action when equipped by a ninja.
/// </summary>
private void OnAddStealthAction(EntityUid uid, NinjaSuitComponent comp, AddStealthActionEvent args)
{
if (!HasComp<SpaceNinjaComponent>(args.User))
args.Cancel();
}
/// <summary>
/// Call the shared and serverside code for when anyone unequips a suit.
/// </summary>
private void OnUnequipped(EntityUid uid, NinjaSuitComponent comp, GotUnequippedEvent args)
{
UserUnequippedSuit(uid, comp, args.Equipee);
}
/// <summary>
/// Called when a suit is equipped by a space ninja.
/// In the future it might be changed to an explicit activation toggle/verb like gloves are.
/// </summary>
protected virtual void NinjaEquippedSuit(EntityUid uid, NinjaSuitComponent comp, EntityUid user, SpaceNinjaComponent ninja)
{
// mark the user as wearing this suit, used when being attacked among other things
_ninja.AssignSuit(user, uid, ninja);
// initialize phase cloak, but keep it off
StealthClothing.SetEnabled(uid, user, false);
}
/// <summary>
/// Force uncloaks the user and disables suit abilities.
/// </summary>
public void RevealNinja(EntityUid uid, EntityUid user, NinjaSuitComponent? comp = null, StealthClothingComponent? stealthClothing = null)
{
if (!Resolve(uid, ref comp, ref stealthClothing))
return;
if (!StealthClothing.SetEnabled(uid, user, false, stealthClothing))
return;
// previously cloaked, disable abilities for a short time
_audio.PlayPredicted(comp.RevealSound, uid, user);
// all abilities check for a usedelay on the ninja
var useDelay = EnsureComp<UseDelayComponent>(user);
useDelay.Delay = comp.DisableTime;
UseDelay.BeginDelay(user, useDelay);
}
// TODO: modify PowerCellDrain
/// <summary>
/// Returns the power used by a suit
/// </summary>
public float SuitWattage(EntityUid uid, NinjaSuitComponent? suit = null)
{
if (!Resolve(uid, ref suit))
return 0f;
float wattage = suit.PassiveWattage;
if (TryComp<StealthClothingComponent>(uid, out var stealthClothing) && stealthClothing.Enabled)
wattage += suit.CloakWattage;
return wattage;
}
/// <summary>
/// Called when a suit is unequipped, not necessarily by a space ninja.
/// In the future it might be changed to also have explicit deactivation via toggle.
/// </summary>
protected virtual void UserUnequippedSuit(EntityUid uid, NinjaSuitComponent comp, EntityUid user)
{
if (!TryComp<SpaceNinjaComponent>(user, out var ninja))
return;
// mark the user as not wearing a suit
_ninja.AssignSuit(user, null, ninja);
// disable glove abilities
if (ninja.Gloves != null && TryComp<NinjaGlovesComponent>(ninja.Gloves.Value, out var gloves))
_gloves.DisableGloves(ninja.Gloves.Value, gloves);
}
}

View File

@@ -0,0 +1,89 @@
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;
/// <summary>
/// Provides shared ninja API, handles being attacked revealing ninja and stops guns from shooting.
/// </summary>
public abstract class SharedSpaceNinjaSystem : EntitySystem
{
[Dependency] protected readonly SharedNinjaSuitSystem _suit = default!;
[Dependency] protected readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpaceNinjaComponent, AttackedEvent>(OnNinjaAttacked);
SubscribeLocalEvent<SpaceNinjaComponent, ShotAttemptedEvent>(OnShotAttempted);
}
/// <summary>
/// Set the ninja's worn suit entity
/// </summary>
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);
}
/// <summary>
/// Set the ninja's worn gloves entity
/// </summary>
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);
}
/// <summary>
/// Bind a katana entity to a ninja, letting it be recalled and dash.
/// </summary>
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);
}
/// <summary>
/// Gets the user's battery and tries to use some charge from it, returning true if successful.
/// Serverside only.
/// </summary>
public virtual bool TryUseCharge(EntityUid user, float charge)
{
return false;
}
/// <summary>
/// Handle revealing ninja if cloaked when attacked.
/// </summary>
private void OnNinjaAttacked(EntityUid uid, SpaceNinjaComponent comp, AttackedEvent args)
{
if (comp.Suit != null && TryComp<StealthClothingComponent>(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
{
_suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing);
}
}
/// <summary>
/// Require ninja to fight with HONOR, no guns!
/// </summary>
private void OnShotAttempted(EntityUid uid, SpaceNinjaComponent comp, ref ShotAttemptedEvent args)
{
_popup.PopupClient(Loc.GetString("gun-disabled"), uid, uid);
args.Cancel();
}
}

View File

@@ -0,0 +1,32 @@
using Content.Shared.Ninja.Components;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// All interaction logic is implemented serverside.
/// This is in shared for API and access.
/// </summary>
public abstract class SharedStunProviderSystem : EntitySystem
{
/// <summary>
/// Set the battery field on the stun provider.
/// </summary>
public void SetBattery(EntityUid uid, EntityUid? battery, StunProviderComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.BatteryUid = battery;
}
/// <summary>
/// Set the no power popup field on the stun provider.
/// </summary>
public void SetNoPowerPopup(EntityUid uid, string popup, StunProviderComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
comp.NoPowerPopup = popup;
}
}