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

* start of space ninja midround antag

* suit has powercell, can be upgraded only (not replaced with equal or worse battery)

* add doorjacking to ninja gloves, power cell, doorjack objective (broken), tweaks

* 💀

* add basic suit power display that uses stamina rsi

* add draining apc/sub/smes - no wires yet

* add research downloading

* ninja starts implanted, move some stuff to yaml

* add Automated field to OnUseTimerTrigger

* implement spider charge and objective

* fix client crash when taking suit off, some refactor

* add survive condition and tweak locale

* add comms console icon for objective

* add calling in a threat - currently revenant and dragon

* combine all glove abilities

* locale

* spark sounds when draining, refactoring

* toggle is actually toggle now

* prevent crash if disabling stealth with outline

* add antag ctrl for ninja, hopefully show greentext

* fix greentext and some other things

* disabling gloves if taken off or suit taken off

* basic energy katana, change ninja loadout

* recallable katana, refactoring

* start of dash - not done yet

* katana dashing ability

* merge upstream + compiling, make AutomatedTimer its own component

* docs and stuff

* partial refactor of glove abilities, still need to move handling

* make dooremaggedevent by ref

* move bunch of stuff to shared - broken

* clean ninja antag verb

* doc

* mark rule config fields as required

* fix client crash

* wip systems refactor

* big refactor of systems

* fuck

* make TryDoElectrocution callable from shared

* finish refactoring?

* no guns

* start with internals on

* clean up glove abilities, add range check

* create soap, in place of ninja throwing stars

* add emp suit ability

* able to eat chefs stolen food in space

* stuff, tell client when un/cloaked but there is bug with gloves

* fix prediction breaking gloves on client

* ninja soap despawns after a minute

* ninja spawns outside the station now, with gps + station coords to navigate

* add cooldown to stun ability

* cant use glove abilities in combat mode

* require empty hand to use glove abilities

* use ghost role spawner

* Update Content.Server/Ninja/Systems/NinjaSuitSystem.cs

Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>

* some review changes

* show powercell charge on examine

* new is needed

* address some reviews

* ninja starts with jetpack, i hope

* partial feedback

* uhh

* pro

* remove pirate from threats list

* use doafter refactor

* pro i gave skeleton jetpack

* some stuff

* use auto gen state

* mr handy

* use EntityQueryEnumerator

* cleanup

* spider charge target anti-troll

* mmmmmm

---------

Co-authored-by: deltanedas <deltanedas@laptop>
Co-authored-by: deltanedas <user@zenith>
Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>
This commit is contained in:
deltanedas
2023-04-17 07:33:27 +00:00
committed by GitHub
parent 0e6b273f1f
commit c1cda0dbf8
78 changed files with 2697 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.GameTicking.Rules;
using Content.Server.Mind.Components;
using Content.Server.Ninja.Systems;
using Content.Server.Zombies;
using Content.Shared.Administration;
using Content.Shared.Database;
@@ -14,6 +15,7 @@ public sealed partial class AdminVerbSystem
{
[Dependency] private readonly ZombifyOnDeathSystem _zombify = default!;
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
[Dependency] private readonly NinjaSystem _ninja = default!;
[Dependency] private readonly NukeopsRuleSystem _nukeopsRule = default!;
[Dependency] private readonly PiratesRuleSystem _piratesRule = default!;
@@ -102,5 +104,21 @@ public sealed partial class AdminVerbSystem
};
args.Verbs.Add(pirate);
Verb spaceNinja = new()
{
Text = "Make space ninja",
Category = VerbCategory.Antag,
Icon = new SpriteSpecifier.Rsi(new ResourcePath("/Textures/Objects/Weapons/Melee/energykatana.rsi"), "icon"),
Act = () =>
{
if (targetMindComp.Mind == null || targetMindComp.Mind.Session == null)
return;
_ninja.MakeNinja(targetMindComp.Mind);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-make-space-ninja"),
};
args.Verbs.Add(spaceNinja);
}
}

View File

@@ -266,6 +266,8 @@ public sealed class DoorSystem : SharedDoorSystem
{
SetState(uid, DoorState.Emagging, door);
PlaySound(uid, door.SparkSound, AudioParams.Default.WithVolume(8), args.UserUid, false);
var emagged = new DoorEmaggedEvent(args.UserUid);
RaiseLocalEvent(uid, ref emagged);
args.Handled = true;
}
}
@@ -300,3 +302,12 @@ public sealed class DoorSystem : SharedDoorSystem
}
}
public sealed class PryFinishedEvent : EntityEventArgs { }
public sealed class PryCancelledEvent : EntityEventArgs { }
/// <summary>
/// Event raised when a door is emagged, either with an emag or a Space Ninja's doorjack ability.
/// Used to track doors for ninja's objective.
/// </summary>
[ByRefEvent]
public readonly record struct DoorEmaggedEvent(EntityUid UserUid);

View File

@@ -262,16 +262,8 @@ namespace Content.Server.Electrocution
}
}
/// <param name="uid">Entity being electrocuted.</param>
/// <param name="sourceUid">Source entity of the electrocution.</param>
/// <param name="shockDamage">How much shock damage the entity takes.</param>
/// <param name="time">How long the entity will be stunned.</param>
/// <param name="refresh">Should <paramref>time</paramref> be refreshed (instead of accumilated) if the entity is already electrocuted?</param>
/// <param name="siemensCoefficient">How insulated the entity is from the shock. 0 means completely insulated, and 1 means no insulation.</param>
/// <param name="statusEffects">Status effects to apply to the entity.</param>
/// <param name="ignoreInsulation">Should the electrocution bypass the Insulated component?</param>
/// <returns>Whether the entity <see cref="uid"/> was stunned by the shock.</returns>
public bool TryDoElectrocution(
/// <inheritdoc/>
public override bool TryDoElectrocution(
EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
{

View File

@@ -0,0 +1,9 @@
namespace Content.Server.Explosion.Components;
/// <summary>
/// Disallows starting the timer by hand, must be stuck or triggered by a system.
/// </summary>
[RegisterComponent]
public sealed class AutomatedTimerComponent : Component
{
}

View File

@@ -141,7 +141,7 @@ public sealed partial class TriggerSystem
private void OnTimerUse(EntityUid uid, OnUseTimerTriggerComponent component, UseInHandEvent args)
{
if (args.Handled)
if (args.Handled || HasComp<AutomatedTimerComponent>(uid))
return;
HandleTimerTrigger(

View File

@@ -0,0 +1,66 @@
using Content.Server.Objectives;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.GameTicking.Rules.Configurations;
/// <summary>
/// Configuration for the Space Ninja antag.
/// </summary>
public sealed class NinjaRuleConfiguration : StationEventRuleConfiguration
{
/// <summary>
/// List of objective prototype ids to add
/// </summary>
[DataField("objectives", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<ObjectivePrototype>))]
public readonly List<string> Objectives = new();
// TODO: move to job and use job???
/// <summary>
/// List of implants to inject on spawn
/// </summary>
[DataField("implants", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
public readonly List<string> Implants = new();
/// <summary>
/// List of threats that can be called in
/// </summary>
[DataField("threats", required: true)]
public readonly List<Threat> Threats = new();
/// <summary>
/// Sound played when making the player a ninja via antag control or ghost role
/// </summary>
[DataField("greetingSound", customTypeSerializer: typeof(SoundSpecifierTypeSerializer))]
public SoundSpecifier? GreetingSound = new SoundPathSpecifier("/Audio/Misc/ninja_greeting.ogg");
/// <summary>
/// Distance that the ninja spawns from the station's half AABB radius
/// </summary>
[DataField("spawnDistance")]
public float SpawnDistance = 20f;
}
/// <summary>
/// A threat that can be called in to the station by a ninja hacking a communications console.
/// Generally some kind of mid-round antag, though you could make it call in scrubber backflow if you wanted to.
/// You wouldn't do that, right?
/// </summary>
[DataDefinition]
public sealed class Threat
{
/// <summary>
/// Locale id for the announcement to be made from CentCom.
/// </summary>
[DataField("announcement")]
public readonly string Announcement = default!;
/// <summary>
/// The game rule for the threat to be added, it should be able to work when added mid-round otherwise this will do nothing.
/// </summary>
[DataField("rule", customTypeSerializer: typeof(PrototypeIdSerializer<GameRulePrototype>))]
public readonly string Rule = default!;
}

View File

@@ -0,0 +1,13 @@
namespace Content.Server.Ninja.Components;
/// <summary>
/// Used by space ninja to indicate what station grid to head towards.
/// </summary>
[RegisterComponent]
public sealed class NinjaStationGridComponent : Component
{
/// <summary>
/// The grid uid being targeted.
/// </summary>
public EntityUid Grid;
}

View File

@@ -0,0 +1,36 @@
using Content.Server.Communications;
using Content.Server.DoAfter;
using Content.Server.Power.Components;
using Content.Shared.DoAfter;
using Content.Shared.Interaction.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems;
namespace Content.Server.Ninja.Systems;
public sealed class NinjaGlovesSystem : SharedNinjaGlovesSystem
{
protected override void OnDrain(EntityUid uid, NinjaDrainComponent comp, InteractionAttemptEvent args)
{
if (!GloveCheck(uid, args, out var gloves, out var user, out var target)
|| !HasComp<PowerNetworkBatteryComponent>(target))
return;
// nicer for spam-clicking to not open apc ui, and when draining starts, so cancel the ui action
args.Cancel();
var doAfterArgs = new DoAfterArgs(user, comp.DrainTime, new DrainDoAfterEvent(), target: target, used: uid, eventTarget: uid)
{
BreakOnUserMove = true,
MovementThreshold = 0.5f,
CancelDuplicate = false
};
_doAfter.TryStartDoAfter(doAfterArgs);
}
protected override bool IsCommsConsole(EntityUid uid)
{
return HasComp<CommunicationsConsoleComponent>(uid);
}
}

View File

@@ -0,0 +1,148 @@
using Content.Server.Emp;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.PowerCell;
using Content.Shared.Actions;
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems;
using Content.Shared.Popups;
using Robust.Shared.Containers;
namespace Content.Server.Ninja.Systems;
public sealed class NinjaSuitSystem : SharedNinjaSuitSystem
{
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly new NinjaSystem _ninja = default!;
[Dependency] private readonly PopupSystem _popups = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
// TODO: maybe have suit activation stuff
SubscribeLocalEvent<NinjaSuitComponent, ContainerIsInsertingAttemptEvent>(OnSuitInsertAttempt);
SubscribeLocalEvent<NinjaSuitComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<NinjaSuitComponent, TogglePhaseCloakEvent>(OnTogglePhaseCloak);
SubscribeLocalEvent<NinjaSuitComponent, CreateSoapEvent>(OnCreateSoap);
SubscribeLocalEvent<NinjaSuitComponent, RecallKatanaEvent>(OnRecallKatana);
SubscribeLocalEvent<NinjaSuitComponent, NinjaEmpEvent>(OnEmp);
}
protected override void NinjaEquippedSuit(EntityUid uid, NinjaSuitComponent comp, EntityUid user, NinjaComponent ninja)
{
base.NinjaEquippedSuit(uid, comp, user, ninja);
_ninja.SetSuitPowerAlert(user);
}
// TODO: if/when battery is in shared, put this there too
private void OnSuitInsertAttempt(EntityUid uid, NinjaSuitComponent comp, ContainerIsInsertingAttemptEvent args)
{
// 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();
}
}
private void OnExamined(EntityUid uid, NinjaSuitComponent comp, ExaminedEvent args)
{
// TODO: make this also return the uid of the battery
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
RaiseLocalEvent(battery.Owner, args);
}
protected override void UserUnequippedSuit(EntityUid uid, NinjaSuitComponent comp, EntityUid user)
{
base.UserUnequippedSuit(uid, comp, user);
// remove power indicator
_ninja.SetSuitPowerAlert(user);
}
private void OnTogglePhaseCloak(EntityUid uid, NinjaSuitComponent comp, TogglePhaseCloakEvent args)
{
args.Handled = true;
var user = args.Performer;
// need 1 second of charge to turn on stealth
var chargeNeeded = SuitWattage(comp);
if (!comp.Cloaked && (!_ninja.GetNinjaBattery(user, out var battery) || battery.CurrentCharge < chargeNeeded || _useDelay.ActiveDelay(uid)))
{
_popups.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
return;
}
comp.Cloaked = !comp.Cloaked;
SetCloaked(args.Performer, comp.Cloaked);
RaiseNetworkEvent(new SetCloakedMessage()
{
User = user,
Cloaked = comp.Cloaked
});
}
private void OnCreateSoap(EntityUid uid, NinjaSuitComponent comp, CreateSoapEvent args)
{
args.Handled = true;
var user = args.Performer;
if (!_ninja.TryUseCharge(user, comp.SoapCharge) || _useDelay.ActiveDelay(uid))
{
_popups.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
return;
}
// try to put soap in hand, otherwise it goes on the ground
var soap = Spawn(comp.SoapPrototype, Transform(user).Coordinates);
_hands.TryPickupAnyHand(user, soap);
}
private void OnRecallKatana(EntityUid uid, NinjaSuitComponent comp, RecallKatanaEvent args)
{
args.Handled = true;
var user = args.Performer;
if (!TryComp<NinjaComponent>(user, out var ninja) || ninja.Katana == null)
return;
// 1% charge per tile
var katana = ninja.Katana.Value;
var coords = _transform.GetWorldPosition(katana);
var distance = (_transform.GetWorldPosition(user) - coords).Length;
var chargeNeeded = (float) distance * 3.6f;
if (!_ninja.TryUseCharge(user, chargeNeeded) || _useDelay.ActiveDelay(uid))
{
_popups.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
return;
}
// TODO: teleporting into belt slot
var message = _hands.TryPickupAnyHand(user, katana)
? "ninja-katana-recalled"
: "ninja-hands-full";
_popups.PopupEntity(Loc.GetString(message), user, user);
}
private void OnEmp(EntityUid uid, NinjaSuitComponent comp, NinjaEmpEvent args)
{
args.Handled = true;
var user = args.Performer;
if (!_ninja.TryUseCharge(user, comp.EmpCharge) || _useDelay.ActiveDelay(uid))
{
_popups.PopupEntity(Loc.GetString("ninja-no-power"), user, user);
return;
}
// I don't think this affects the suit battery, but if it ever does in the future add a blacklist for it
var coords = Transform(user).MapPosition;
_emp.EmpPulse(coords, comp.EmpRange, comp.EmpConsumption);
}
}

View File

@@ -0,0 +1,314 @@
using Content.Server.Administration.Commands;
using Content.Server.Body.Systems;
using Content.Server.Chat.Managers;
using Content.Server.Chat.Systems;
using Content.Server.Doors.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Configurations;
using Content.Server.Ghost.Roles.Events;
using Content.Server.Mind.Components;
using Content.Server.Ninja.Components;
using Content.Server.Objectives;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.PowerCell;
using Content.Server.Traitor;
using Content.Server.Warps;
using Content.Shared.Alert;
using Content.Shared.Doors.Components;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems;
using Content.Shared.Roles;
using Content.Shared.Popups;
using Content.Shared.PowerCell.Components;
using Content.Shared.Rounding;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;
namespace Content.Server.Ninja.Systems;
public sealed class NinjaSystem : SharedNinjaSystem
{
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IChatManager _chatMan = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly SharedSubdermalImplantSystem _implants = default!;
[Dependency] private readonly InternalsSystem _internals = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly PopupSystem _popups = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NinjaComponent, ComponentStartup>(OnNinjaStartup);
SubscribeLocalEvent<NinjaComponent, GhostRoleSpawnerUsedEvent>(OnNinjaSpawned);
SubscribeLocalEvent<NinjaComponent, MindAddedMessage>(OnNinjaMindAdded);
SubscribeLocalEvent<DoorComponent, DoorEmaggedEvent>(OnDoorEmagged);
}
public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<NinjaComponent>();
while (query.MoveNext(out var uid, out var ninja))
{
UpdateNinja(uid, ninja, frameTime);
}
}
/// <summary>
/// Turns the player into a space ninja
/// </summary>
public void MakeNinja(Mind.Mind mind)
{
if (mind.OwnedEntity == null)
return;
// prevent double ninja'ing
var user = mind.OwnedEntity.Value;
if (HasComp<NinjaComponent>(user))
return;
AddComp<NinjaComponent>(user);
SetOutfitCommand.SetOutfit(user, "SpaceNinjaGear", EntityManager);
GreetNinja(mind);
}
/// <summary>
/// Returns the space ninja spawn gamerule's config
/// </summary>
public NinjaRuleConfiguration RuleConfig()
{
return (NinjaRuleConfiguration) _proto.Index<GameRulePrototype>("SpaceNinjaSpawn").Configuration;
}
/// <summary>
/// Update the alert for the ninja's suit power indicator.
/// </summary>
public void SetSuitPowerAlert(EntityUid uid, NinjaComponent? comp = null)
{
if (!Resolve(uid, ref comp, false) || comp.Deleted || comp.Suit == null)
{
_alerts.ClearAlert(uid, AlertType.SuitPower);
return;
}
if (GetNinjaBattery(uid, out var battery))
{
var severity = ContentHelpers.RoundToLevels(MathF.Max(0f, battery.CurrentCharge), battery.MaxCharge, 7);
_alerts.ShowAlert(uid, AlertType.SuitPower, (short) severity);
}
else
{
_alerts.ClearAlert(uid, AlertType.SuitPower);
}
}
/// <summary>
/// Set the station grid on an entity, either ninja spawner or the ninja itself.
/// Used to tell a ghost that takes ninja role where the station is.
/// </summary>
public void SetNinjaStationGrid(EntityUid uid, EntityUid grid)
{
var station = EnsureComp<NinjaStationGridComponent>(uid);
station.Grid = grid;
}
/// <summary>
/// Get the battery component in a ninja's suit, if it's worn.
/// </summary>
public bool GetNinjaBattery(EntityUid user, [NotNullWhen(true)] out BatteryComponent? battery)
{
if (TryComp<NinjaComponent>(user, out var ninja)
&& ninja.Suit != null
&& _powerCell.TryGetBatteryFromSlot(ninja.Suit.Value, out battery))
{
return true;
}
battery = null;
return false;
}
public override bool TryUseCharge(EntityUid user, float charge)
{
return GetNinjaBattery(user, out var battery) && battery.TryUseCharge(charge);
}
public override void CallInThreat(NinjaComponent comp)
{
base.CallInThreat(comp);
var config = RuleConfig();
if (config.Threats.Count == 0)
return;
var threat = _random.Pick(config.Threats);
if (_proto.TryIndex<GameRulePrototype>(threat.Rule, out var rule))
{
_gameTicker.AddGameRule(rule);
_chat.DispatchGlobalAnnouncement(Loc.GetString(threat.Announcement), playSound: false, colorOverride: Color.Red);
}
else
{
Logger.Error($"Threat gamerule does not exist: {threat.Rule}");
}
}
public override void TryDrainPower(EntityUid user, NinjaDrainComponent drain, EntityUid target)
{
if (!GetNinjaBattery(user, out var suitBattery))
// took suit off or something, ignore draining
return;
if (!TryComp<BatteryComponent>(target, out var battery) || !TryComp<PowerNetworkBatteryComponent>(target, out var pnb))
return;
if (suitBattery.IsFullyCharged)
{
_popups.PopupEntity(Loc.GetString("ninja-drain-full"), user, user, PopupType.Medium);
return;
}
if (MathHelper.CloseToPercent(battery.CurrentCharge, 0))
{
_popups.PopupEntity(Loc.GetString("ninja-drain-empty", ("battery", target)), user, user, PopupType.Medium);
return;
}
var available = battery.CurrentCharge;
var required = suitBattery.MaxCharge - suitBattery.CurrentCharge;
// higher tier storages can charge more
var maxDrained = pnb.MaxSupply * drain.DrainTime;
var input = Math.Min(Math.Min(available, required / drain.DrainEfficiency), maxDrained);
if (battery.TryUseCharge(input))
{
var output = input * drain.DrainEfficiency;
suitBattery.CurrentCharge += output;
_popups.PopupEntity(Loc.GetString("ninja-drain-success", ("battery", target)), user, user);
// TODO: spark effects
_audio.PlayPvs(drain.SparkSound, target);
}
}
private void OnNinjaStartup(EntityUid uid, NinjaComponent comp, ComponentStartup args)
{
var config = RuleConfig();
// start with internals on, only when spawned by event. antag control ninja won't do this due to component add order.
_internals.ToggleInternals(uid, uid, true);
// inject starting implants
var coords = Transform(uid).Coordinates;
foreach (var id in config.Implants)
{
var implant = Spawn(id, coords);
if (!TryComp<SubdermalImplantComponent>(implant, out var implantComp))
return;
_implants.ForceImplant(uid, implant, implantComp);
}
// choose spider charge detonation point
// currently based on warp points, something better could be done (but would likely require mapping work)
var warps = new List<EntityUid>();
var query = EntityQueryEnumerator<WarpPointComponent>();
while (query.MoveNext(out var warpUid, out var warp))
{
// won't be asked to detonate the nuke disk or singularity
if (warp.Location != null && !HasComp<PhysicsComponent>(warpUid))
warps.Add(warpUid);
}
if (warps.Count > 0)
comp.SpiderChargeTarget = _random.Pick(warps);
}
private void OnNinjaSpawned(EntityUid uid, NinjaComponent comp, GhostRoleSpawnerUsedEvent args)
{
// inherit spawner's station grid
if (TryComp<NinjaStationGridComponent>(args.Spawner, out var station))
SetNinjaStationGrid(uid, station.Grid);
}
private void OnNinjaMindAdded(EntityUid uid, NinjaComponent comp, MindAddedMessage args)
{
if (TryComp<MindComponent>(uid, out var mind) && mind.Mind != null)
GreetNinja(mind.Mind);
}
private void GreetNinja(Mind.Mind mind)
{
if (!mind.TryGetSession(out var session))
return;
var config = RuleConfig();
var role = new TraitorRole(mind, _proto.Index<AntagPrototype>("SpaceNinja"));
mind.AddRole(role);
_traitorRule.Traitors.Add(role);
foreach (var objective in config.Objectives)
{
AddObjective(mind, objective);
}
_audio.PlayGlobal(config.GreetingSound, Filter.Empty().AddPlayer(session), false, AudioParams.Default);
_chatMan.DispatchServerMessage(session, Loc.GetString("ninja-role-greeting"));
if (TryComp<NinjaStationGridComponent>(mind.OwnedEntity, out var station))
{
var gridPos = _transform.GetWorldPosition(station.Grid);
var ninjaPos = _transform.GetWorldPosition(mind.OwnedEntity.Value);
var vector = gridPos - ninjaPos;
var direction = vector.GetDir();
var position = $"({(int) gridPos.X}, {(int) gridPos.Y})";
var msg = Loc.GetString("ninja-role-greeting-direction", ("direction", direction), ("position", position));
_chatMan.DispatchServerMessage(session, msg);
}
}
private void OnDoorEmagged(EntityUid uid, DoorComponent door, ref DoorEmaggedEvent args)
{
// make sure it's a ninja doorjacking it
if (TryComp<NinjaComponent>(args.UserUid, out var ninja))
ninja.DoorsJacked++;
}
private void UpdateNinja(EntityUid uid, NinjaComponent ninja, float frameTime)
{
if (ninja.Suit == null || !TryComp<NinjaSuitComponent>(ninja.Suit, out var suit))
return;
float wattage = _suit.SuitWattage(suit);
SetSuitPowerAlert(uid, ninja);
if (!TryUseCharge(uid, wattage * frameTime))
{
// ran out of power, reveal ninja
_suit.RevealNinja(ninja.Suit.Value, suit, uid);
}
}
private void AddObjective(Mind.Mind mind, string name)
{
if (_proto.TryIndex<ObjectivePrototype>(name, out var objective))
mind.TryAddObjective(objective);
else
Logger.Error($"Ninja has unknown objective prototype: {name}");
}
}

View File

@@ -0,0 +1,64 @@
using Content.Server.Explosion.EntitySystems;
using Content.Server.Sticky.Events;
using Content.Server.Popups;
using Content.Shared.Interaction;
using Content.Shared.Ninja.Components;
using Robust.Shared.GameObjects;
namespace Content.Server.Ninja.Systems;
public sealed class SpiderChargeSystem : EntitySystem
{
[Dependency] private readonly NinjaSystem _ninja = default!;
[Dependency] private readonly PopupSystem _popups = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpiderChargeComponent, BeforeRangedInteractEvent>(BeforePlant);
SubscribeLocalEvent<SpiderChargeComponent, EntityStuckEvent>(OnStuck);
SubscribeLocalEvent<SpiderChargeComponent, TriggerEvent>(OnExplode);
}
private void BeforePlant(EntityUid uid, SpiderChargeComponent comp, BeforeRangedInteractEvent args)
{
var user = args.User;
if (!TryComp<NinjaComponent>(user, out var ninja))
{
_popups.PopupEntity(Loc.GetString("spider-charge-not-ninja"), user, user);
args.Handled = true;
return;
}
// allow planting anywhere if there is no target, which should never happen
if (ninja.SpiderChargeTarget != null)
{
// assumes warp point still exists
var target = Transform(ninja.SpiderChargeTarget.Value).MapPosition;
var coords = args.ClickLocation.ToMap(EntityManager, _transform);
if (!coords.InRange(target, comp.Range))
{
_popups.PopupEntity(Loc.GetString("spider-charge-too-far"), user, user);
args.Handled = true;
return;
}
}
}
private void OnStuck(EntityUid uid, SpiderChargeComponent comp, EntityStuckEvent args)
{
comp.Planter = args.User;
}
private void OnExplode(EntityUid uid, SpiderChargeComponent comp, TriggerEvent args)
{
if (comp.Planter == null || !TryComp<NinjaComponent>(comp.Planter, out var ninja))
return;
// assumes the target was destroyed, that the charge wasn't moved somehow
_ninja.DetonateSpiderCharge(ninja);
}
}

View File

@@ -0,0 +1,64 @@
using Content.Server.Objectives.Interfaces;
using Content.Shared.Ninja.Components;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class DoorjackCondition : IObjectiveCondition
{
private Mind.Mind? _mind;
private int _target;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
{
// TODO: clamp to number of doors on station incase its somehow a shittle or something
return new DoorjackCondition {
_mind = mind,
_target = IoCManager.Resolve<IRobustRandom>().Next(15, 40)
};
}
public string Title => Loc.GetString("objective-condition-doorjack-title", ("count", _target));
public string Description => Loc.GetString("objective-condition-doorjack-description", ("count", _target));
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ResourcePath("Objects/Tools/emag.rsi"), "icon");
public float Progress
{
get
{
var entMan = IoCManager.Resolve<IEntityManager>();
if (_mind?.OwnedEntity == null
|| !entMan.TryGetComponent<NinjaComponent>(_mind.OwnedEntity, out var ninja))
return 0f;
// prevent divide-by-zero
if (_target == 0)
return 1f;
return (float) ninja.DoorsJacked / (float) _target;
}
}
public float Difficulty => 1.5f;
public bool Equals(IObjectiveCondition? other)
{
return other is DoorjackCondition cond && Equals(_mind, cond._mind) && _target == cond._target;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is DoorjackCondition cond && cond.Equals(this);
}
public override int GetHashCode()
{
return HashCode.Combine(_mind?.GetHashCode() ?? 0, _target);
}
}

View File

@@ -0,0 +1,64 @@
using Content.Server.Objectives.Interfaces;
using Content.Shared.Ninja.Components;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class DownloadCondition : IObjectiveCondition
{
private Mind.Mind? _mind;
private int _target;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
{
// TODO: clamp to number of research nodes in tree so easily maintainable
return new DownloadCondition {
_mind = mind,
_target = IoCManager.Resolve<IRobustRandom>().Next(5, 10)
};
}
public string Title => Loc.GetString("objective-condition-download-title", ("count", _target));
public string Description => Loc.GetString("objective-condition-download-description");
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ResourcePath("Structures/Machines/server.rsi"), "server");
public float Progress
{
get
{
// prevent divide-by-zero
if (_target == 0)
return 1f;
var entMan = IoCManager.Resolve<IEntityManager>();
if (_mind?.OwnedEntity == null
|| !entMan.TryGetComponent<NinjaComponent>(_mind.OwnedEntity, out var ninja))
return 0f;
return (float) ninja.DownloadedNodes.Count / (float) _target;
}
}
public float Difficulty => 2.5f;
public bool Equals(IObjectiveCondition? other)
{
return other is DownloadCondition cond && Equals(_mind, cond._mind) && _target == cond._target;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is DownloadCondition cond && cond.Equals(this);
}
public override int GetHashCode()
{
return HashCode.Combine(_mind?.GetHashCode() ?? 0, _target);
}
}

View File

@@ -0,0 +1,73 @@
using Content.Server.Objectives.Interfaces;
using Content.Server.Warps;
using Content.Shared.Ninja.Components;
using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class SpiderChargeCondition : IObjectiveCondition
{
private Mind.Mind? _mind;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
{
return new SpiderChargeCondition {
_mind = mind
};
}
public string Title
{
get
{
var entMan = IoCManager.Resolve<IEntityManager>();
if (_mind?.OwnedEntity == null
|| !entMan.TryGetComponent<NinjaComponent>(_mind.OwnedEntity, out var ninja)
|| ninja.SpiderChargeTarget == null
|| !entMan.TryGetComponent<WarpPointComponent>(ninja.SpiderChargeTarget, out var warp)
|| warp.Location == null)
// if you are funny and microbomb then press c, you get this
return Loc.GetString("objective-condition-spider-charge-no-target");
return Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location));
}
}
public string Description => Loc.GetString("objective-condition-spider-charge-description");
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ResourcePath("Objects/Weapons/Bombs/spidercharge.rsi"), "icon");
public float Progress
{
get
{
var entMan = IoCManager.Resolve<IEntityManager>();
if (_mind?.OwnedEntity == null
|| !entMan.TryGetComponent<NinjaComponent>(_mind.OwnedEntity, out var ninja))
return 0f;
return ninja.SpiderChargeDetonated ? 1f : 0f;
}
}
public float Difficulty => 2.5f;
public bool Equals(IObjectiveCondition? other)
{
return other is SpiderChargeCondition cond && Equals(_mind, cond._mind);
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is SpiderChargeCondition cond && cond.Equals(this);
}
public override int GetHashCode()
{
return _mind?.GetHashCode() ?? 0;
}
}

View File

@@ -0,0 +1,46 @@
using Content.Server.Objectives.Interfaces;
using JetBrains.Annotations;
using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions
{
[UsedImplicitly]
[DataDefinition]
public sealed class SurviveCondition : IObjectiveCondition
{
private Mind.Mind? _mind;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
{
return new SurviveCondition {_mind = mind};
}
public string Title => Loc.GetString("objective-condition-survive-title");
public string Description => Loc.GetString("objective-condition-survive-description");
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ResourcePath("Clothing/Head/Helmets/spaceninja.rsi"), "icon");
public float Difficulty => 0.5f;
public float Progress => (_mind?.CharacterDeadIC ?? true) ? 0f : 1f;
public bool Equals(IObjectiveCondition? other)
{
return other is SurviveCondition condition && Equals(_mind, condition._mind);
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((SurviveCondition) obj);
}
public override int GetHashCode()
{
return (_mind != null ? _mind.GetHashCode() : 0);
}
}
}

View File

@@ -0,0 +1,54 @@
using Content.Server.Objectives.Interfaces;
using Content.Shared.Ninja.Components;
using Robust.Shared.Utility;
namespace Content.Server.Objectives.Conditions;
[DataDefinition]
public sealed class TerrorCondition : IObjectiveCondition
{
private Mind.Mind? _mind;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
{
return new TerrorCondition {_mind = mind};
}
public string Title => Loc.GetString("objective-condition-terror-title");
public string Description => Loc.GetString("objective-condition-terror-description");
public SpriteSpecifier Icon => new SpriteSpecifier.Rsi(new ResourcePath("Structures/Machines/computers.rsi"), "comm_icon");
public float Progress
{
get
{
var entMan = IoCManager.Resolve<IEntityManager>();
if (_mind?.OwnedEntity == null
|| !entMan.TryGetComponent<NinjaComponent>(_mind.OwnedEntity, out var ninja))
return 0f;
return ninja.CalledInThreat ? 1f : 0f;
}
}
public float Difficulty => 2.75f;
public bool Equals(IObjectiveCondition? other)
{
return other is TerrorCondition cond && Equals(_mind, cond._mind);
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj is TerrorCondition cond && cond.Equals(this);
}
public override int GetHashCode()
{
return _mind?.GetHashCode() ?? 0;
}
}

View File

@@ -0,0 +1,81 @@
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Configurations;
using Content.Server.Ninja.Systems;
using Content.Server.StationEvents.Components;
using Content.Server.Station.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;
namespace Content.Server.StationEvents.Events;
/// <summary>
/// Event for spawning a Space Ninja mid-game.
/// </summary>
public sealed class SpaceNinjaSpawn : StationEventSystem
{
[Dependency] private readonly NinjaSystem _ninja = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override string Prototype => "SpaceNinjaSpawn";
public override void Started()
{
base.Started();
if (StationSystem.Stations.Count == 0)
{
Sawmill.Error("No stations exist, cannot spawn space ninja!");
return;
}
var station = _random.Pick(StationSystem.Stations);
if (!TryComp<StationDataComponent>(station, out var stationData))
{
Sawmill.Error("Chosen station isn't a station, cannot spawn space ninja!");
return;
}
// find a station grid
var gridUid = StationSystem.GetLargestGrid(stationData);
if (gridUid == null || !TryComp<MapGridComponent>(gridUid, out var grid))
{
Sawmill.Error("Chosen station has no grids, cannot spawn space ninja!");
return;
}
// figure out its AABB size and use that as a guide to how far ninja should be
var config = (NinjaRuleConfiguration) Configuration;
var size = grid.LocalAABB.Size.Length / 2;
var distance = size + config.SpawnDistance;
var angle = _random.NextAngle();
// position relative to station center
var location = angle.ToVec() * distance;
// create the spawner, the ninja will appear when a ghost has picked the role
var xform = Transform(gridUid.Value);
var position = _transform.GetWorldPosition(xform) + location;
var coords = new MapCoordinates(position, xform.MapID);
Sawmill.Info($"Creating ninja spawnpoint at {coords}");
var spawner = Spawn("SpawnPointGhostSpaceNinja", coords);
// tell the player where the station is when they pick the role
_ninja.SetNinjaStationGrid(spawner, gridUid.Value);
// start traitor rule incase it isn't, for the sweet greentext
var rule = _proto.Index<GameRulePrototype>("Traitor");
_ticker.StartGameRule(rule);
}
public override void Added()
{
Sawmill.Info("Added space ninja spawn rule");
}
}