[Revert] Reverts Ninja (#15516)

* Revert "[Antag] add space ninja as midround antag (#14069)"

This reverts commit c1cda0dbf8.

* Revert "[Fix] move ninja objectives into NinjaRole (#15490)"

This reverts commit 251f429fb3.
This commit is contained in:
keronshb
2023-04-19 03:43:09 -04:00
committed by GitHub
parent 6161f7d5f3
commit ac87effca0
81 changed files with 20 additions and 2742 deletions

View File

@@ -1,66 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Ninja.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for a Space Ninja's katana, controls its dash sound.
/// Requires a ninja with a suit for abilities to work.
/// </summary>
// basically emag but without immune tag, TODO: make the charge thing its own component and have emag use it too
[Access(typeof(EnergyKatanaSystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class EnergyKatanaComponent : Component
{
public EntityUid? Ninja = null;
/// <summary>
/// Sound played when using dash action.
/// </summary>
[DataField("blinkSound")]
public SoundSpecifier BlinkSound = new SoundPathSpecifier("/Audio/Magic/blink.ogg");
/// <summary>
/// Volume control for katana dash action.
/// </summary>
[DataField("blinkVolume")]
public float BlinkVolume = 5f;
/// <summary>
/// The maximum number of dash charges the katana can have
/// </summary>
[DataField("maxCharges"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public int MaxCharges = 3;
/// <summary>
/// The current number of dash charges on the katana
/// </summary>
[DataField("charges"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public int Charges = 3;
/// <summary>
/// Whether or not the katana automatically recharges over time.
/// </summary>
[DataField("autoRecharge"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public bool AutoRecharge = true;
/// <summary>
/// The time it takes to regain a single dash charge
/// </summary>
[DataField("rechargeDuration"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public TimeSpan RechargeDuration = TimeSpan.FromSeconds(20);
/// <summary>
/// The time when the next dash charge will be added
/// </summary>
[DataField("nextChargeTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public TimeSpan NextChargeTime = TimeSpan.MaxValue;
}
public sealed class KatanaDashEvent : WorldTargetActionEvent { }

View File

@@ -1,38 +0,0 @@
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.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedNinjaSystem))]
public sealed partial class NinjaComponent : Component
{
/// <summary>
/// Grid entity of the station the ninja was spawned around. Set if spawned naturally by the event.
/// </summary>
[ViewVariables, AutoNetworkedField]
public EntityUid? StationGrid;
/// <summary>
/// Currently worn suit
/// </summary>
[ViewVariables]
public EntityUid? Suit = null;
/// <summary>
/// Currently worn gloves
/// </summary>
[ViewVariables]
public EntityUid? Gloves = null;
/// <summary>
/// Bound katana, set once picked up and never removed
/// </summary>
[ViewVariables]
public EntityUid? Katana = null;
}

View File

@@ -1,151 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.DoAfter;
using Content.Shared.Ninja.Systems;
using Content.Shared.Tag;
using Content.Shared.Toggleable;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
using System.Threading;
namespace Content.Shared.Ninja.Components;
/// <summary>
/// Component for toggling glove powers.
/// Powers being enabled is controlled by GlovesEnabledComponent
/// </summary>
[Access(typeof(SharedNinjaGlovesSystem))]
[RegisterComponent, NetworkedComponent]
public sealed class NinjaGlovesComponent : Component
{
/// <summary>
/// Entity of the ninja using these gloves, usually means enabled
/// </summary>
[ViewVariables]
public EntityUid? User;
/// <summary>
/// The action for toggling ninja gloves abilities
/// </summary>
[DataField("toggleAction")]
public InstantAction ToggleAction = new()
{
DisplayName = "action-name-toggle-ninja-gloves",
Description = "action-desc-toggle-ninja-gloves",
Priority = -13,
Event = new ToggleActionEvent()
};
}
/// <summary>
/// Component for emagging doors on click, when gloves are enabled.
/// Only works on entities with DoorComponent.
/// </summary>
[RegisterComponent]
public sealed class NinjaDoorjackComponent : Component
{
/// <summary>
/// The tag that marks an entity as immune to doorjacking
/// </summary>
[DataField("emagImmuneTag", customTypeSerializer: typeof(PrototypeIdSerializer<TagPrototype>))]
public string EmagImmuneTag = "EmagImmune";
}
/// <summary>
/// Component for stunning mobs on click, when gloves are enabled.
/// Knocks them down for a bit and deals shock damage.
/// </summary>
[RegisterComponent]
public sealed class NinjaStunComponent : Component
{
/// <summary>
/// Joules required in the suit to stun someone. Defaults to 10 uses on a small battery.
/// </summary>
[DataField("stunCharge")]
public float StunCharge = 36.0f;
/// <summary>
/// Shock damage dealt when stunning someone
/// </summary>
[DataField("stunDamage")]
public int StunDamage = 5;
/// <summary>
/// Time that someone is stunned for, stacks if done multiple times.
/// </summary>
[DataField("stunTime")]
public TimeSpan StunTime = TimeSpan.FromSeconds(3);
}
/// <summary>
/// Component for draining power from APCs/substations/SMESes, when gloves are enabled.
/// </summary>
[RegisterComponent]
public sealed class NinjaDrainComponent : Component
{
/// <summary>
/// Conversion rate between joules in a device and joules added to suit.
/// Should be very low since powercells store nothing compared to even an APC.
/// </summary>
[DataField("drainEfficiency")]
public float DrainEfficiency = 0.001f;
/// <summary>
/// Time that the do after takes to drain charge from a battery, in seconds
/// </summary>
[DataField("drainTime")]
public float DrainTime = 1f;
[DataField("sparkSound")]
public SoundSpecifier SparkSound = new SoundCollectionSpecifier("sparks");
}
/// <summary>
/// Component for downloading research nodes from a R&D server, when gloves are enabled.
/// Requirement for greentext.
/// </summary>
[RegisterComponent]
public sealed class NinjaDownloadComponent : Component
{
/// <summary>
/// Time taken to download research from a server
/// </summary>
[DataField("downloadTime")]
public float DownloadTime = 20f;
}
/// <summary>
/// Component for hacking a communications console to call in a threat.
/// Called threat is rolled from the ninja gamerule config.
/// </summary>
[RegisterComponent]
public sealed class NinjaTerrorComponent : Component
{
/// <summary>
/// Time taken to hack the console
/// </summary>
[DataField("terrorTime")]
public float TerrorTime = 20f;
}
/// <summary>
/// DoAfter event for drain ability.
/// </summary>
[Serializable, NetSerializable]
public sealed class DrainDoAfterEvent : SimpleDoAfterEvent { }
/// <summary>
/// DoAfter event for research download ability.
/// </summary>
[Serializable, NetSerializable]
public sealed class DownloadDoAfterEvent : SimpleDoAfterEvent { }
/// <summary>
/// DoAfter event for comms console terror ability.
/// </summary>
[Serializable, NetSerializable]
public sealed class TerrorDoAfterEvent : SimpleDoAfterEvent { }

View File

@@ -1,148 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Ninja.Systems;
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;
// TODO: ResourcePath -> ResPath when thing gets merged
/// <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>
[Access(typeof(SharedNinjaSuitSystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class NinjaSuitComponent : Component
{
[ViewVariables, AutoNetworkedField]
public bool Cloaked = false;
/// <summary>
/// The action for toggling suit phase cloak ability
/// </summary>
[DataField("togglePhaseCloakAction")]
public InstantAction TogglePhaseCloakAction = new()
{
UseDelay = TimeSpan.FromSeconds(5), // have to plan un/cloaking ahead of time
DisplayName = "action-name-toggle-phase-cloak",
Description = "action-desc-toggle-phase-cloak",
Priority = -9,
Event = new TogglePhaseCloakEvent()
};
/// <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>
/// The action for creating throwing soap, in place of ninja throwing stars since embedding doesn't exist.
/// </summary>
[DataField("createSoapAction")]
public InstantAction CreateSoapAction = new()
{
UseDelay = TimeSpan.FromSeconds(10),
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Objects/Specific/Janitorial/soap.rsi"), "soap"),
ItemIconStyle = ItemActionIconStyle.NoItem,
DisplayName = "action-name-create-soap",
Description = "action-desc-create-soap",
Priority = -10,
Event = new CreateSoapEvent()
};
/// <summary>
/// Battery charge used to create a throwing soap. Can do it 25 times on a small-capacity power cell.
/// </summary>
[DataField("soapCharge")]
public float SoapCharge = 14.4f;
/// <summary>
/// Soap item to create with the action
/// </summary>
[DataField("soapPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string SoapPrototype = "SoapNinja";
/// <summary>
/// The action for recalling a bound energy katana
/// </summary>
[DataField("recallkatanaAction")]
public InstantAction RecallKatanaAction = new()
{
UseDelay = TimeSpan.FromSeconds(1),
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Objects/Weapons/Melee/energykatana.rsi"), "icon"),
ItemIconStyle = ItemActionIconStyle.NoItem,
DisplayName = "action-name-recall-katana",
Description = "action-desc-recall-katana",
Priority = -11,
Event = new RecallKatanaEvent()
};
/// <summary>
/// The action for dashing somewhere using katana
/// </summary>
[DataField("katanaDashAction")]
public WorldTargetAction KatanaDashAction = new()
{
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Objects/Magic/magicactions.rsi"), "blink"),
ItemIconStyle = ItemActionIconStyle.NoItem,
DisplayName = "action-name-katana-dash",
Description = "action-desc-katana-dash",
Priority = -12,
Event = new KatanaDashEvent(),
// doing checks manually
CheckCanAccess = false,
Range = 0f
};
/// <summary>
/// The action for creating an EMP burst
/// </summary>
[DataField("empAction")]
public InstantAction EmpAction = new()
{
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Objects/Weapons/Grenades/empgrenade.rsi"), "icon"),
ItemIconStyle = ItemActionIconStyle.BigAction,
DisplayName = "action-name-em-burst",
Description = "action-desc-em-burst",
Priority = -13,
Event = new NinjaEmpEvent()
};
/// <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;
}
public sealed class TogglePhaseCloakEvent : InstantActionEvent { }
public sealed class CreateSoapEvent : InstantActionEvent { }
public sealed class RecallKatanaEvent : InstantActionEvent { }
public sealed class NinjaEmpEvent : InstantActionEvent { }

View File

@@ -1,17 +0,0 @@
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]
public sealed class SpiderChargeComponent : Component
{
/// Range for planting within the target area
[DataField("range")]
public float Range = 10f;
/// The ninja that planted this charge
[ViewVariables]
public EntityUid? Planter = null;
}

View File

@@ -1,147 +0,0 @@
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
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>
/// System for katana dashing, recharging and what not.
/// </summary>
// TODO: move all recharging stuff into its own system and use for emag too
public sealed class EnergyKatanaSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedNinjaSystem _ninja = default!;
[Dependency] private readonly SharedPopupSystem _popups = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnergyKatanaComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<EnergyKatanaComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<NinjaSuitComponent, KatanaDashEvent>(OnDash);
SubscribeLocalEvent<EnergyKatanaComponent, EntityUnpausedEvent>(OnUnpaused);
}
private void OnEquipped(EntityUid uid, EnergyKatanaComponent comp, GotEquippedEvent args)
{
// check if already bound
if (comp.Ninja != null)
return;
// check if ninja already has a katana bound
var user = args.Equipee;
if (!TryComp<NinjaComponent>(user, out var ninja) || ninja.Katana != null)
return;
// bind it
comp.Ninja = user;
_ninja.BindKatana(ninja, uid);
}
private void OnUnpaused(EntityUid uid, EnergyKatanaComponent component, ref EntityUnpausedEvent args)
{
component.NextChargeTime += args.PausedTime;
}
private void OnExamine(EntityUid uid, EnergyKatanaComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("emag-charges-remaining", ("charges", component.Charges)));
if (component.Charges == component.MaxCharges)
{
args.PushMarkup(Loc.GetString("emag-max-charges"));
return;
}
var timeRemaining = Math.Round((component.NextChargeTime - _timing.CurTime).TotalSeconds);
args.PushMarkup(Loc.GetString("emag-recharging", ("seconds", timeRemaining)));
}
// TODO: remove and use LimitedCharges+AutoRecharge
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var comp in EntityQuery<EnergyKatanaComponent>())
{
if (!comp.AutoRecharge)
continue;
if (comp.Charges == comp.MaxCharges)
continue;
if (_timing.CurTime < comp.NextChargeTime)
continue;
ChangeCharge(comp.Owner, 1, true, comp);
}
}
public void OnDash(EntityUid suit, NinjaSuitComponent comp, KatanaDashEvent args)
{
var user = args.Performer;
args.Handled = true;
if (!TryComp<NinjaComponent>(user, out var ninja) || ninja.Katana == null)
return;
var uid = ninja.Katana.Value;
if (!TryComp<EnergyKatanaComponent>(uid, out var katana) || !_hands.IsHolding(user, uid, out var _))
{
_popups.PopupEntity(Loc.GetString("ninja-katana-not-held"), user, user);
return;
}
if (katana.Charges <= 0)
{
_popups.PopupEntity(Loc.GetString("emag-no-charges"), user, user);
return;
}
// TODO: check that target is not dense
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
_popups.PopupEntity(Loc.GetString("ninja-katana-cant-see"), user, user);
return;
}
_transform.SetCoordinates(user, args.Target);
_transform.AttachToGridOrMap(user);
_audio.PlayPvs(katana.BlinkSound, user, AudioParams.Default.WithVolume(katana.BlinkVolume));
// TODO: show the funny green man thing
ChangeCharge(uid, -1, false, katana);
}
/// <summary>
/// Changes the charge on an energy katana.
/// </summary>
public bool ChangeCharge(EntityUid uid, int change, bool resetTimer, EnergyKatanaComponent? katana = null)
{
if (!Resolve(uid, ref katana))
return false;
if (katana.Charges + change < 0 || katana.Charges + change > katana.MaxCharges)
return false;
if (resetTimer || katana.Charges == katana.MaxCharges)
katana.NextChargeTime = _timing.CurTime + katana.RechargeDuration;
katana.Charges += change;
Dirty(katana);
return true;
}
}

View File

@@ -1,256 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Administration.Logs;
using Content.Shared.CombatMode;
using Content.Shared.Damage.Components;
using Content.Shared.Database;
using Content.Shared.Doors.Components;
using Content.Shared.DoAfter;
using Content.Shared.Electrocution;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Popups;
using Content.Shared.Research.Components;
using Content.Shared.Tag;
using Content.Shared.Timing;
using Content.Shared.Toggleable;
using Robust.Shared.Network;
using Robust.Shared.Timing;
using System.Diagnostics.CodeAnalysis;
namespace Content.Shared.Ninja.Systems;
public abstract class SharedNinjaGlovesSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
[Dependency] protected readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedElectrocutionSystem _electrocution = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedNinjaSystem _ninja = default!;
[Dependency] protected readonly SharedPopupSystem Popups = default!;
[Dependency] private readonly TagSystem _tags = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaGlovesComponent, GetItemActionsEvent>(OnGetItemActions);
SubscribeLocalEvent<NinjaGlovesComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<NinjaGlovesComponent, ToggleActionEvent>(OnToggleAction);
SubscribeLocalEvent<NinjaGlovesComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<NinjaDoorjackComponent, InteractionAttemptEvent>(OnDoorjack);
SubscribeLocalEvent<NinjaStunComponent, InteractionAttemptEvent>(OnStun);
SubscribeLocalEvent<NinjaDrainComponent, InteractionAttemptEvent>(OnDrain);
SubscribeLocalEvent<NinjaDrainComponent, DrainDoAfterEvent>(OnDrainDoAfter);
SubscribeLocalEvent<NinjaDownloadComponent, InteractionAttemptEvent>(OnDownload);
SubscribeLocalEvent<NinjaDownloadComponent, DownloadDoAfterEvent>(OnDownloadDoAfter);
SubscribeLocalEvent<NinjaTerrorComponent, InteractionAttemptEvent>(OnTerror);
SubscribeLocalEvent<NinjaTerrorComponent, TerrorDoAfterEvent>(OnTerrorDoAfter);
}
/// <summary>
/// Disable glove abilities and show the popup if they were enabled previously.
/// </summary>
public void DisableGloves(NinjaGlovesComponent comp, EntityUid user)
{
if (comp.User != null)
{
comp.User = null;
Popups.PopupEntity(Loc.GetString("ninja-gloves-off"), user, user);
}
}
private void OnGetItemActions(EntityUid uid, NinjaGlovesComponent comp, GetItemActionsEvent args)
{
args.Actions.Add(comp.ToggleAction);
}
private void OnToggleAction(EntityUid uid, NinjaGlovesComponent comp, ToggleActionEvent args)
{
// client prediction desyncs it hard
if (args.Handled || !_timing.IsFirstTimePredicted)
return;
args.Handled = true;
var user = args.Performer;
// need to wear suit to enable gloves
if (!TryComp<NinjaComponent>(user, out var ninja)
|| ninja.Suit == null
|| !HasComp<NinjaSuitComponent>(ninja.Suit.Value))
{
ClientPopup(Loc.GetString("ninja-gloves-not-wearing-suit"), user);
return;
}
var enabling = comp.User == null;
var message = Loc.GetString(enabling ? "ninja-gloves-on" : "ninja-gloves-off");
ClientPopup(message, user);
if (enabling)
{
comp.User = user;
_ninja.AssignGloves(ninja, uid);
// set up interaction relay for handling glove abilities, comp.User is used to see the actual user of the events
_interaction.SetRelay(user, uid, EnsureComp<InteractionRelayComponent>(user));
}
else
{
comp.User = null;
_ninja.AssignGloves(ninja, null);
RemComp<InteractionRelayComponent>(user);
}
}
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"));
}
private void OnUnequipped(EntityUid uid, NinjaGlovesComponent comp, GotUnequippedEvent args)
{
comp.User = null;
if (TryComp<NinjaComponent>(args.Equipee, out var ninja))
_ninja.AssignGloves(ninja, null);
}
/// <summary>
/// Helper for glove ability handlers, checks gloves, range, combat mode and stuff.
/// </summary>
protected bool GloveCheck(EntityUid uid, InteractionAttemptEvent args, [NotNullWhen(true)] out NinjaGlovesComponent? gloves,
out EntityUid user, out EntityUid target)
{
if (args.Target != null && TryComp<NinjaGlovesComponent>(uid, out gloves)
&& gloves.User != null
&& !_combatMode.IsInCombatMode(gloves.User)
&& _timing.IsFirstTimePredicted
&& TryComp<HandsComponent>(gloves.User, out var hands)
&& hands.ActiveHandEntity == null)
{
user = gloves.User.Value;
target = args.Target.Value;
if (_interaction.InRangeUnobstructed(user, target))
return true;
}
gloves = null;
user = target = EntityUid.Invalid;
return false;
}
private void OnDoorjack(EntityUid uid, NinjaDoorjackComponent comp, InteractionAttemptEvent args)
{
if (!GloveCheck(uid, args, out var gloves, out var user, out var target))
return;
// only allowed to emag non-immune doors
if (!HasComp<DoorComponent>(target) || _tags.HasTag(target, comp.EmagImmuneTag))
return;
var handled = _emag.DoEmagEffect(user, target);
if (!handled)
return;
ClientPopup(Loc.GetString("ninja-doorjack-success", ("target", Identity.Entity(target, EntityManager))), user, PopupType.Medium);
_adminLogger.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(user):player} doorjacked {ToPrettyString(target):target}");
}
private void OnStun(EntityUid uid, NinjaStunComponent comp, InteractionAttemptEvent args)
{
if (!GloveCheck(uid, args, out var gloves, out var user, out var target))
return;
// short cooldown to prevent instant stunlocking
if (_useDelay.ActiveDelay(uid))
return;
// battery can't be predicted since it's serverside
if (user == target || _net.IsClient || !HasComp<StaminaComponent>(target))
return;
// take charge from battery
if (!_ninja.TryUseCharge(user, comp.StunCharge))
{
Popups.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
return;
}
// not holding hands with target so insuls don't matter
_electrocution.TryDoElectrocution(target, uid, comp.StunDamage, comp.StunTime, false, ignoreInsulation: true);
_useDelay.BeginDelay(uid);
}
// can't predict PNBC existing so only done on server.
protected virtual void OnDrain(EntityUid uid, NinjaDrainComponent comp, InteractionAttemptEvent args) { }
private void OnDrainDoAfter(EntityUid uid, NinjaDrainComponent comp, DrainDoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Target == null)
return;
_ninja.TryDrainPower(args.User, comp, args.Target.Value);
}
private void OnDownload(EntityUid uid, NinjaDownloadComponent comp, InteractionAttemptEvent args)
{
if (!GloveCheck(uid, args, out var gloves, out var user, out var target))
return;
// can only hack the server, not a random console
if (!TryComp<TechnologyDatabaseComponent>(target, out var database) || HasComp<ResearchClientComponent>(target))
return;
// fail fast if theres no tech right now
if (database.TechnologyIds.Count == 0)
{
ClientPopup(Loc.GetString("ninja-download-fail"), user);
return;
}
var doAfterArgs = new DoAfterArgs(user, comp.DownloadTime, new DownloadDoAfterEvent(), target: target, used: uid, eventTarget: uid)
{
BreakOnDamage = true,
BreakOnUserMove = true,
MovementThreshold = 0.5f,
CancelDuplicate = false
};
_doAfter.TryStartDoAfter(doAfterArgs);
args.Cancel();
}
// can't predict roles so only done on server.
protected virtual void OnDownloadDoAfter(EntityUid uid, NinjaDownloadComponent comp, DownloadDoAfterEvent args) { }
// cant predict roles for checking if already called
protected virtual void OnTerror(EntityUid uid, NinjaTerrorComponent comp, InteractionAttemptEvent args) { }
// can't predict roles or anything announcements related so only done on server.
protected virtual void OnTerrorDoAfter(EntityUid uid, NinjaTerrorComponent comp, TerrorDoAfterEvent args) { }
private void ClientPopup(string msg, EntityUid user, PopupType type = PopupType.Small)
{
if (_net.IsClient)
Popups.PopupEntity(msg, user, user, type);
}
}

View File

@@ -1,159 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Stealth;
using Content.Shared.Stealth.Components;
using Content.Shared.Timing;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Ninja.Systems;
public abstract class SharedNinjaSuitSystem : EntitySystem
{
[Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
[Dependency] protected readonly SharedNinjaSystem _ninja = default!;
[Dependency] private readonly SharedStealthSystem _stealth = default!;
[Dependency] protected readonly UseDelaySystem _useDelay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaSuitComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<NinjaSuitComponent, GetItemActionsEvent>(OnGetItemActions);
SubscribeLocalEvent<NinjaSuitComponent, ContainerIsRemovingAttemptEvent>(OnSuitRemoveAttempt);
SubscribeLocalEvent<NinjaSuitComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeNetworkEvent<SetCloakedMessage>(OnSetCloakedMessage);
}
private void OnEquipped(EntityUid uid, NinjaSuitComponent comp, GotEquippedEvent args)
{
var user = args.Equipee;
if (!TryComp<NinjaComponent>(user, out var ninja))
return;
NinjaEquippedSuit(uid, comp, user, ninja);
}
private void OnGetItemActions(EntityUid uid, NinjaSuitComponent comp, GetItemActionsEvent args)
{
args.Actions.Add(comp.TogglePhaseCloakAction);
args.Actions.Add(comp.RecallKatanaAction);
// TODO: ninja stars instead of soap, when embedding is a thing
// The cooldown should also be reduced from 10 to 1 or so
args.Actions.Add(comp.CreateSoapAction);
args.Actions.Add(comp.KatanaDashAction);
args.Actions.Add(comp.EmpAction);
}
private void OnSuitRemoveAttempt(EntityUid uid, NinjaSuitComponent comp, ContainerIsRemovingAttemptEvent args)
{
// no removing your battery idiot!!!
args.Cancel();
}
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, NinjaComponent ninja)
{
// mark the user as wearing this suit, used when being attacked among other things
_ninja.AssignSuit(ninja, uid);
// initialize phase cloak
EnsureComp<StealthComponent>(user);
SetCloaked(user, comp.Cloaked);
}
/// <summary>
/// Force uncloak the user, disables suit abilities if the bool is set.
/// </summary>
public void RevealNinja(EntityUid uid, NinjaSuitComponent comp, EntityUid user, bool disableAbilities = false)
{
if (comp.Cloaked)
{
comp.Cloaked = false;
SetCloaked(user, false);
// TODO: add the box open thing its funny
if (disableAbilities)
_useDelay.BeginDelay(uid);
}
}
/// <summary>
/// Returns the power used by a suit
/// </summary>
public float SuitWattage(NinjaSuitComponent suit)
{
float wattage = suit.PassiveWattage;
if (suit.Cloaked)
wattage += suit.CloakWattage;
return wattage;
}
/// <summary>
/// Sets the stealth effect for a ninja cloaking.
/// Does not update suit Cloaked field, has to be done yourself.
/// </summary>
protected void SetCloaked(EntityUid user, bool cloaked)
{
if (!TryComp<StealthComponent>(user, out var stealth) || stealth.Deleted)
return;
// slightly visible, but doesn't change when moving so it's ok
var visibility = cloaked ? stealth.MinVisibility + 0.25f : stealth.MaxVisibility;
_stealth.SetVisibility(user, visibility, stealth);
_stealth.SetEnabled(user, cloaked, stealth);
}
/// <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)
{
// mark the user as not wearing a suit
if (TryComp<NinjaComponent>(user, out var ninja))
{
_ninja.AssignSuit(ninja, null);
// disable glove abilities
if (ninja.Gloves != null && TryComp<NinjaGlovesComponent>(ninja.Gloves.Value, out var gloves))
_gloves.DisableGloves(gloves, user);
}
// force uncloak the user
comp.Cloaked = false;
SetCloaked(user, false);
RemComp<StealthComponent>(user);
}
private void OnSetCloakedMessage(SetCloakedMessage msg)
{
if (TryComp<NinjaComponent>(msg.User, out var ninja) && TryComp<NinjaSuitComponent>(ninja.Suit, out var suit))
{
suit.Cloaked = msg.Cloaked;
SetCloaked(msg.User, msg.Cloaked);
}
}
}
/// <summary>
/// Calls SetCloaked on the client from the server, along with updating the suit Cloaked bool.
/// </summary>
[Serializable, NetSerializable]
public sealed class SetCloakedMessage : EntityEventArgs
{
public EntityUid User;
public bool Cloaked;
}

View File

@@ -1,75 +0,0 @@
using Content.Shared.Ninja.Components;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
namespace Content.Shared.Ninja.Systems;
public abstract class SharedNinjaSystem : EntitySystem
{
[Dependency] protected readonly SharedNinjaSuitSystem _suit = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaComponent, AttackedEvent>(OnNinjaAttacked);
}
/// <summary>
/// Sets the station grid entity that the ninja was spawned near.
/// </summary>
public void SetStationGrid(NinjaComponent comp, EntityUid? grid)
{
comp.StationGrid = grid;
}
/// <summary>
/// Set the ninja's worn suit entity
/// </summary>
public void AssignSuit(NinjaComponent comp, EntityUid? suit)
{
comp.Suit = suit;
}
/// <summary>
/// Set the ninja's worn gloves entity
/// </summary>
public void AssignGloves(NinjaComponent comp, EntityUid? gloves)
{
comp.Gloves = gloves;
}
/// <summary>
/// Bind a katana entity to a ninja, letting it be recalled and dash.
/// </summary>
public void BindKatana(NinjaComponent comp, EntityUid? katana)
{
comp.Katana = katana;
}
/// <summary>
/// Drain power from a target battery into the ninja's suit battery.
/// Serverside only.
/// </summary>
public virtual void TryDrainPower(EntityUid user, NinjaDrainComponent drain, EntityUid target)
{
}
/// <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;
}
private void OnNinjaAttacked(EntityUid uid, NinjaComponent comp, AttackedEvent args)
{
if (comp.Suit != null && TryComp<NinjaSuitComponent>(comp.Suit, out var suit) && suit.Cloaked)
{
_suit.RevealNinja(comp.Suit.Value, suit, uid, true);
}
}
}