ninja 2 electric boogaloo (#15534)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using Content.Server.StationEvents.Events;
|
||||
|
||||
namespace Content.Server.StationEvents.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration component for the Space Ninja antag.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(NinjaSpawnRule))]
|
||||
public sealed partial class NinjaSpawnRuleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Distance that the ninja spawns from the station's half AABB radius
|
||||
/// </summary>
|
||||
[DataField("spawnDistance")]
|
||||
public float SpawnDistance = 20f;
|
||||
}
|
||||
51
Content.Server/StationEvents/Events/NinjaSpawnRule.cs
Normal file
51
Content.Server/StationEvents/Events/NinjaSpawnRule.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Ninja.Systems;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.StationEvents.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.StationEvents.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Event for spawning a Space Ninja mid-game.
|
||||
/// </summary>
|
||||
public sealed class NinjaSpawnRule : StationEventSystem<NinjaSpawnRuleComponent>
|
||||
{
|
||||
[Dependency] private readonly SpaceNinjaSystem _ninja = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
protected override void Started(EntityUid uid, NinjaSpawnRuleComponent comp, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
||||
{
|
||||
base.Started(uid, comp, gameRule, args);
|
||||
|
||||
if (!TryGetRandomStation(out var station))
|
||||
return;
|
||||
|
||||
var stationData = Comp<StationDataComponent>(station.Value);
|
||||
|
||||
// find a station grid
|
||||
var gridUid = StationSystem.GetLargestGrid(stationData);
|
||||
if (gridUid == null || !TryComp<MapGridComponent>(gridUid, out var grid))
|
||||
{
|
||||
Sawmill.Warning("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 size = grid.LocalAABB.Size.Length() / 2;
|
||||
var distance = size + comp.SpawnDistance;
|
||||
var angle = RobustRandom.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}");
|
||||
Spawn("SpawnPointGhostSpaceNinja", coords);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user