From d13ff9197e351d7c43583a5cf897edaa2d04d14c Mon Sep 17 00:00:00 2001 From: Zack Backmen Date: Fri, 22 Nov 2024 08:38:02 +0300 Subject: [PATCH] v2 --- .../Arrivals/Centcomm/CentComEventId.cs | 10 ++ .../Arrivals/Centcomm/CentCommEvent.cs | 7 + .../Arrivals/Centcomm/CentCommSpawnSystem.cs | 123 ++++++++++++++++++ .../Arrivals/Centcomm/FtlCentComAnnounce.cs | 8 ++ .../StationCentCommDirectorComponent.cs | 21 +++ .../Backmen/Arrivals/CentcommSystem.cs | 42 +++++- .../Entities/Stations/nanotrasen.yml | 10 ++ .../_Backmen/CentComm/BKCCAssistant.yml | 59 +++++++++ .../_Backmen/CentComm/BKCCCargo.yml | 58 +++++++++ .../_Backmen/CentComm/BKCCOperator.yml | 62 +++++++++ .../_Backmen/CentComm/BKCCSecure.yml | 56 ++++++++ 11 files changed, 451 insertions(+), 5 deletions(-) create mode 100644 Content.Server/Backmen/Arrivals/Centcomm/CentComEventId.cs create mode 100644 Content.Server/Backmen/Arrivals/Centcomm/CentCommEvent.cs create mode 100644 Content.Server/Backmen/Arrivals/Centcomm/CentCommSpawnSystem.cs create mode 100644 Content.Server/Backmen/Arrivals/Centcomm/FtlCentComAnnounce.cs create mode 100644 Content.Server/Backmen/Arrivals/Centcomm/StationCentCommDirectorComponent.cs create mode 100644 Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml create mode 100644 Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml create mode 100644 Resources/Prototypes/_Backmen/CentComm/BKCCOperator.yml create mode 100644 Resources/Prototypes/_Backmen/CentComm/BKCCSecure.yml diff --git a/Content.Server/Backmen/Arrivals/Centcomm/CentComEventId.cs b/Content.Server/Backmen/Arrivals/Centcomm/CentComEventId.cs new file mode 100644 index 00000000000..cf9449f5a44 --- /dev/null +++ b/Content.Server/Backmen/Arrivals/Centcomm/CentComEventId.cs @@ -0,0 +1,10 @@ +namespace Content.Server.Backmen.Arrivals.CentComm; + +public enum CentComEventId : int +{ + Noop = 0, + AddWorker, + AddOperator, + AddSecurity, + AddCargo +} diff --git a/Content.Server/Backmen/Arrivals/Centcomm/CentCommEvent.cs b/Content.Server/Backmen/Arrivals/Centcomm/CentCommEvent.cs new file mode 100644 index 00000000000..a8327a9cd84 --- /dev/null +++ b/Content.Server/Backmen/Arrivals/Centcomm/CentCommEvent.cs @@ -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; +} diff --git a/Content.Server/Backmen/Arrivals/Centcomm/CentCommSpawnSystem.cs b/Content.Server/Backmen/Arrivals/Centcomm/CentCommSpawnSystem.cs new file mode 100644 index 00000000000..e0d64de9b20 --- /dev/null +++ b/Content.Server/Backmen/Arrivals/Centcomm/CentCommSpawnSystem.cs @@ -0,0 +1,123 @@ +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(OnCentCommEvent); + } + + private void OnCentCommEvent(Entity 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; + } + } + + [ValidatePrototypeId] + private const string WorkerProto = "SpawnPointCMBKCCAssistant"; + private void AddWorker(EntityUid station) + { + var point = FindSpawnPoint(station); + if (point == null) + { + Log.Warning($"Can't find spawn point for {station}"); + return; + } + Spawn(WorkerProto, point.Value); + } + [ValidatePrototypeId] + private const string OperatorProto = "SpawnPointCMBKCCOperator"; + private void AddOperator(EntityUid station) + { + var point = FindSpawnPoint(station); + if (point == null) + { + Log.Warning($"Can't find spawn point for {station}"); + return; + } + Spawn(OperatorProto, point.Value); + } + [ValidatePrototypeId] + private const string SecurityProto = "SpawnPointCMBKCCSecOfficer"; + private void AddSecurity(EntityUid station) + { + var point = FindSpawnPoint(station); + if (point == null) + { + Log.Warning($"Can't find spawn point for {station}"); + return; + } + Spawn(SecurityProto, point.Value); + } + [ValidatePrototypeId] + private const string CargoProto = "SpawnPointCMBKCCCargo"; + private void AddCargo(EntityUid station) + { + var point = FindSpawnPoint(station); + if (point == null) + { + Log.Warning($"Can't find spawn point for {station}"); + return; + } + Spawn(CargoProto, point.Value); + } + + private EntityCoordinates? FindSpawnPoint(EntityUid station) + { + var stationData = CompOrNull(station); + if (stationData == null) + return null; + + var stationGrids = stationData.Grids; + + var result = new List(); + + var q = EntityQueryEnumerator(); + 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); + } +} diff --git a/Content.Server/Backmen/Arrivals/Centcomm/FtlCentComAnnounce.cs b/Content.Server/Backmen/Arrivals/Centcomm/FtlCentComAnnounce.cs new file mode 100644 index 00000000000..6f8710335f5 --- /dev/null +++ b/Content.Server/Backmen/Arrivals/Centcomm/FtlCentComAnnounce.cs @@ -0,0 +1,8 @@ +using Content.Server.Shuttles.Components; + +namespace Content.Server.Backmen.Arrivals.CentComm; + +public sealed class FtlCentComAnnounce : EntityEventArgs +{ + public Entity Source { get; set; } +} diff --git a/Content.Server/Backmen/Arrivals/Centcomm/StationCentCommDirectorComponent.cs b/Content.Server/Backmen/Arrivals/Centcomm/StationCentCommDirectorComponent.cs new file mode 100644 index 00000000000..fd8e496a6a7 --- /dev/null +++ b/Content.Server/Backmen/Arrivals/Centcomm/StationCentCommDirectorComponent.cs @@ -0,0 +1,21 @@ +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; + +namespace Content.Server.Backmen.Arrivals.CentComm; + +[RegisterComponent] +public sealed partial class StationCentCommDirectorComponent : Component +{ + /// + /// Keeps track of the internal event scheduler. + /// + [ViewVariables] + [DataField("nextEventTick", customTypeSerializer: typeof(TimeOffsetSerializer))] + public TimeSpan NextEventTick; + + /// + /// The schedule of events to occur. + /// + [ViewVariables] + [DataField("eventSchedule")] + public List<(TimeSpan timeOffset, CentComEventId eventId)> EventSchedule = new(); +} diff --git a/Content.Server/Backmen/Arrivals/CentcommSystem.cs b/Content.Server/Backmen/Arrivals/CentcommSystem.cs index 14e8a4c94f3..a3f91280a88 100644 --- a/Content.Server/Backmen/Arrivals/CentcommSystem.cs +++ b/Content.Server/Backmen/Arrivals/CentcommSystem.cs @@ -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; @@ -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 Source { get; set; } -} - public sealed class CentcommSystem : EntitySystem { [Dependency] private readonly PopupSystem _popup = default!; @@ -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; @@ -83,6 +81,40 @@ public override void Initialize() _stationCentComMapPool = _prototypeManager.Index(StationCentComMapPool); } + public override void Update(float frameTime) + { + base.Update(frameTime); + + var curTime = _gameTiming.CurTime; + + var q = EntityQueryEnumerator(); + 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) diff --git a/Resources/Prototypes/Entities/Stations/nanotrasen.yml b/Resources/Prototypes/Entities/Stations/nanotrasen.yml index 21133f99c9b..c872ec4153e 100644 --- a/Resources/Prototypes/Entities/Stations/nanotrasen.yml +++ b/Resources/Prototypes/Entities/Stations/nanotrasen.yml @@ -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 diff --git a/Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml b/Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml new file mode 100644 index 00000000000..67bec8c2040 --- /dev/null +++ b/Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml @@ -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 diff --git a/Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml b/Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml new file mode 100644 index 00000000000..bfa2bd0ac64 --- /dev/null +++ b/Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml @@ -0,0 +1,58 @@ +- type: entity + id: SpawnPointCMBKCCCargo + name: Карго ЦК + suffix: Спавнер, Директор Событий + parent: MarkerBase + components: + - type: GhostRole + allowMovement: true + allowSpeech: true + makeSentient: true + name: Карго ЦК + description: кек + rules: кек + 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 diff --git a/Resources/Prototypes/_Backmen/CentComm/BKCCOperator.yml b/Resources/Prototypes/_Backmen/CentComm/BKCCOperator.yml new file mode 100644 index 00000000000..29505565c36 --- /dev/null +++ b/Resources/Prototypes/_Backmen/CentComm/BKCCOperator.yml @@ -0,0 +1,62 @@ +- type: entity + id: SpawnPointCMBKCCOperator + name: Оператор ЦК + suffix: Спавнер, Директор Событий + parent: MarkerBase + components: + - type: GhostRole + allowMovement: true + allowSpeech: true + makeSentient: true + name: Оператор ЦК + description: Вас вызвали в этот сектор для помощи станции с целью! + rules: Вас вызвали в этот сектор для помощи станции с целью! + raffle: + settings: short + requirements: + - !type:RoleTimeRequirement + role: JobCentralCommandAssistant + time: 7200 + - !type:DepartmentTimeRequirement + department: CentCom + time: 14400 + - !type:DepartmentTimeRequirement + department: Silicons + time: 6000 + job: BKCCOperator + whitelistRequired: true + - type: GhostRoleMobSpawner + prototype: MobHumanCMBKCCOperator + - type: Sprite + sprite: Markers/jobs.rsi + layers: + - state: green + - sprite: Mobs/Animals/regalrat.rsi + state: icon + +- type: entity + name: Оператор ЦК + suffix: Директор Событий + parent: MobHumanCombine + description: Офисный клерк. + id: MobHumanCMBKCCOperator + 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: [OperatorGavna] + - type: RandomHumanoidAppearance + randomizeName: true + - type: AntagImmune + - type: Psionic + - type: DispelPower diff --git a/Resources/Prototypes/_Backmen/CentComm/BKCCSecure.yml b/Resources/Prototypes/_Backmen/CentComm/BKCCSecure.yml new file mode 100644 index 00000000000..abd3c737c76 --- /dev/null +++ b/Resources/Prototypes/_Backmen/CentComm/BKCCSecure.yml @@ -0,0 +1,56 @@ +- type: entity + id: SpawnPointCMBKCCSecOfficer + name: Охраник ЦК + suffix: Спавнер, Директор Событий + parent: MarkerBase + components: + - type: GhostRole + allowMovement: true + allowSpeech: true + makeSentient: true + name: Охраник ЦК + description: кек + rules: кек + raffle: + settings: short + requirements: + - !type:DepartmentTimeRequirement + department: Security + time: 108000 + - !type:RoleTimeRequirement + role: JobCentralCommandAssistant + time: 3600 + job: BKCCSecOfficer + - type: GhostRoleMobSpawner + prototype: MobHumanCMBKCCSecOfficer + - type: Sprite + sprite: Markers/jobs.rsi + layers: + - state: green + - sprite: Mobs/Animals/regalrat.rsi + state: icon + +- type: entity + name: Охраник ЦК + suffix: Директор Событий + parent: MobHumanCombine + description: кек + id: MobHumanCMBKCCSecOfficer + 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: [CentComPrivateOfficerGear] + - type: RandomHumanoidAppearance + randomizeName: true + - type: AntagImmune