Skip to content

Commit

Permalink
ЦК v2 (#928)
Browse files Browse the repository at this point in the history
* v2

* фикс

* Update BKCCSecure.yml
  • Loading branch information
Rxup authored Nov 22, 2024
1 parent 30c0251 commit 5cb5033
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Content.Server/Backmen/Arrivals/Centcomm/CentComEventId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Backmen.Arrivals.CentComm;

public enum CentComEventId : int
{
Noop = 0,
AddWorker,
AddOperator,
AddSecurity,
AddCargo
}
7 changes: 7 additions & 0 deletions Content.Server/Backmen/Arrivals/Centcomm/CentCommEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.Backmen.Arrivals.CentComm;

public sealed class CentCommEvent(EntityUid station,CentComEventId eventId) : HandledEntityEventArgs
{
public EntityUid Station { get; } = station;
public CentComEventId EventId { get; } = eventId;
}
101 changes: 101 additions & 0 deletions Content.Server/Backmen/Arrivals/Centcomm/CentCommSpawnSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Content.Server.Spawners.Components;
using Content.Server.Station.Components;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.Backmen.Arrivals.CentComm;

public sealed class CentCommSpawnSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StationCentCommDirectorComponent, CentCommEvent>(OnCentCommEvent);
}

private void OnCentCommEvent(Entity<StationCentCommDirectorComponent> ent, ref CentCommEvent args)
{
if(args.Handled)
return;

switch (args.EventId)
{
case CentComEventId.AddWorker:
args.Handled = true;

AddWorker(args.Station);
break;
case CentComEventId.AddOperator:
args.Handled = true;

AddOperator(args.Station);
break;
case CentComEventId.AddSecurity:
args.Handled = true;

AddSecurity(args.Station);
break;
case CentComEventId.AddCargo:
args.Handled = true;

AddCargo(args.Station);
break;
default:
return;
}
}

private void SpawnEntity(EntityUid station, string protoId)
{
var point = FindSpawnPoint(station);
if (point == null)
{
Log.Warning($"Can't find spawn point for {station}");
return;
}
Spawn(protoId, point.Value);
}

[ValidatePrototypeId<EntityPrototype>]
private const string WorkerProto = "SpawnPointCMBKCCAssistant";
private void AddWorker(EntityUid station) => SpawnEntity(station, WorkerProto);

[ValidatePrototypeId<EntityPrototype>]
private const string OperatorProto = "SpawnPointCMBKCCOperator";
private void AddOperator(EntityUid station) => SpawnEntity(station, OperatorProto);

[ValidatePrototypeId<EntityPrototype>]
private const string SecurityProto = "SpawnPointCMBKCCSecOfficer";
private void AddSecurity(EntityUid station) => SpawnEntity(station, SecurityProto);

[ValidatePrototypeId<EntityPrototype>]
private const string CargoProto = "SpawnPointCMBKCCCargo";
private void AddCargo(EntityUid station) => SpawnEntity(station, CargoProto);

private EntityCoordinates? FindSpawnPoint(EntityUid station)
{
var stationData = CompOrNull<StationDataComponent>(station);
if (stationData == null)
return null;

var stationGrids = stationData.Grids;

var result = new List<EntityCoordinates>();

var q = EntityQueryEnumerator<SpawnPointComponent,TransformComponent>();
while (q.MoveNext(out var uid, out var spawnPoint, out var transform))
{
if(spawnPoint.SpawnType != SpawnPointType.LateJoin || transform.GridUid == null)
continue;
if(!stationGrids.Contains(transform.GridUid.Value))
continue;

result.Add(transform.Coordinates);
}

return result.Count == 0 ? null : _random.Pick(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Server.Shuttles.Components;

namespace Content.Server.Backmen.Arrivals.CentComm;

public sealed class FtlCentComAnnounce : EntityEventArgs
{
public Entity<ShuttleComponent> Source { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Backmen.Arrivals.CentComm;

[RegisterComponent]
public sealed partial class StationCentCommDirectorComponent : Component
{
/// <summary>
/// Keeps track of the internal event scheduler.
/// </summary>
[ViewVariables]
[DataField("nextEventTick", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextEventTick;

/// <summary>
/// The schedule of events to occur.
/// </summary>
[ViewVariables]
[DataField("eventSchedule")]
public List<(TimeSpan timeOffset, CentComEventId eventId)> EventSchedule = new();
}
42 changes: 37 additions & 5 deletions Content.Server/Backmen/Arrivals/CentcommSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Server.Backmen.Arrivals.CentComm;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Events;
Expand Down Expand Up @@ -32,15 +33,11 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Server.Backmen.Arrivals;

public sealed class FtlCentComAnnounce : EntityEventArgs
{
public Entity<ShuttleComponent> Source { get; set; }
}

public sealed class CentcommSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
Expand All @@ -58,6 +55,7 @@ public sealed class CentcommSystem : EntitySystem
[Dependency] private readonly MetaDataSystem _metaDataSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;

public EntityUid CentComGrid { get; private set; } = EntityUid.Invalid;
public MapId CentComMap { get; private set; } = MapId.Nullspace;
Expand All @@ -83,6 +81,40 @@ public override void Initialize()
_stationCentComMapPool = _prototypeManager.Index<WeightedRandomPrototype>(StationCentComMapPool);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var curTime = _gameTiming.CurTime;

var q = EntityQueryEnumerator<StationCentCommDirectorComponent, StationSpawningComponent>();
while (q.MoveNext(out var stationUid, out var centcomDirector, out var stationSpawning))
{
if (!(centcomDirector.EventSchedule.Count > 0 && curTime >= centcomDirector.NextEventTick))
{
continue;
}

// Pop the event.
var curEvent = centcomDirector.EventSchedule[0];
centcomDirector.EventSchedule.RemoveAt(0);

// Add the next event's offset to the ticker.
if (centcomDirector.EventSchedule.Count > 0)
centcomDirector.NextEventTick = curTime + centcomDirector.EventSchedule[0].timeOffset;

Log.Info($"Running event: {curEvent}");

var ev = new CentCommEvent(stationUid, curEvent.eventId);
RaiseLocalEvent(stationUid, ev, true);
if (!ev.Handled)
{
Log.Warning($"Running event: {curEvent} is not handled");
}
}
}


private void OnLoadingMaps(LoadingMapsEvent ev)
{
if (_gameTicker.CurrentPreset?.IsMiniGame ?? false)
Expand Down
10 changes: 10 additions & 0 deletions Resources/Prototypes/Entities/Stations/nanotrasen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
categories: [ HideSpawnMenu ]
components:
- type: Transform
- type: StationCentCommDirector
eventSchedule: # 10min = 600sec
- 0: Noop # init event prevent from missfire
- 600: AddWorker #10min
- 600: AddWorker #20min
- 600: AddWorker #30min
- 600: AddOperator #40min
- 1: AddSecurity
- 1: AddSecurity
- 600: AddCargo

- type: entity
id: StandardStationArena
Expand Down
59 changes: 59 additions & 0 deletions Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
- type: entity
id: SpawnPointCMBKCCAssistant
name: Ассистент ЦК
suffix: Спавнер, Директор Событий
parent: MarkerBase
components:
- type: GhostRole
allowMovement: true
allowSpeech: true
makeSentient: true
name: Ассистент ЦК
description: Разнорабочий призванный для поддержки экипажа ЦК и для поддержки самой станции цк в текущем секторе.
rules: Вы обязаны выполнять поручения экипажа станции цк, опеспечивать станцию цк в рабочем состоянии, также запрещено покидать станцию цк!
raffle:
settings: short
requirements:
- !type:DepartmentTimeRequirement
department: Engineering
time: 108000
- !type:DepartmentTimeRequirement
department: Medical
time: 108000
- !type:DepartmentTimeRequirement
department: Civilian
time: 108000
job: BKCCAssistant
- type: GhostRoleMobSpawner
prototype: MobHumanCMBKCCAssistant
- type: Sprite
sprite: Markers/jobs.rsi
layers:
- state: green
- sprite: Mobs/Animals/regalrat.rsi
state: icon


- type: entity
name: Ассистент ЦК
suffix: Спавнер, Директор Событий
parent: MobHumanCombine
id: MobHumanCMBKCCAssistant
components:
- type: Icon
sprite: Markers/jobs.rsi
state: ai
- type: AutoImplant
implants:
- MindShieldImplant
- FreedomImplant
- type: SpecForce
actionBssActionName: ActionCentcomFtlAction
- type: NpcFactionMember
factions:
- CentralCommand
- type: Loadout
prototypes: [CentComInternGear]
- type: RandomHumanoidAppearance
randomizeName: true
- type: AntagImmune
61 changes: 61 additions & 0 deletions Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
- type: entity
id: SpawnPointCMBKCCCargo
name: Карго ЦК
suffix: Спавнер, Директор Событий
parent: MarkerBase
components:
- type: GhostRole
allowMovement: true
allowSpeech: true
makeSentient: true
name: Карго ЦК
description: A Central Command Cargo Officer responsible for managing cargo operations.
rules: |
- Maintain Central Command cargo protocols
- Coordinate with station cargo department
- Follow Central Command chain of command
raffle:
settings: short
requirements:
- !type:DepartmentTimeRequirement
department: Cargo
time: 126000
- !type:RoleTimeRequirement
role: JobCentralCommandAssistant
time: 21600
- !type:DepartmentTimeRequirement
department: CentCom
time: 43200
job: BKCCCargo
- type: GhostRoleMobSpawner
prototype: MobHumanCMBKCCCargo
- type: Sprite
sprite: Markers/jobs.rsi
layers:
- state: green
- sprite: Mobs/Animals/regalrat.rsi
state: icon

- type: entity
name: Карго ЦК
suffix: Директор Событий
parent: MobHumanCombine
id: MobHumanCMBKCCCargo
components:
- type: Icon
sprite: Markers/jobs.rsi
state: ai
- type: AutoImplant
implants:
- MindShieldImplant
- FreedomImplant
- type: SpecForce
actionBssActionName: ActionCentcomFtlAction
- type: NpcFactionMember
factions:
- CentralCommand
- type: Loadout
prototypes: [CCCargo]
- type: RandomHumanoidAppearance
randomizeName: true
- type: AntagImmune
Loading

0 comments on commit 5cb5033

Please sign in to comment.