From ab0f7d9d728db0b2312e5d6ec33aa3a0b0ae4313 Mon Sep 17 00:00:00 2001 From: Vonsant Date: Wed, 7 Aug 2024 23:26:15 +0300 Subject: [PATCH] PacifiedZone --- .../PacifiedZoneGeneratorComponent.cs | 32 ++++++ .../PacifiedlZoneGeneratorSystem.cs | 94 ++++++++++++++++++ .../_NF/Entities/Markers/pacified_zone.yml | 77 ++++++++++++++ .../_NF/Markers/pacifiedzone.rsi/meta.json | 14 +++ .../pacifiedzone.rsi/pacified_zone.png | Bin 0 -> 840 bytes 5 files changed, 217 insertions(+) create mode 100644 Content.Server/_NF/PacifiedZone/PacifiedZoneGeneratorComponent.cs create mode 100644 Content.Server/_NF/PacifiedZone/PacifiedlZoneGeneratorSystem.cs create mode 100644 Resources/Prototypes/_NF/Entities/Markers/pacified_zone.yml create mode 100644 Resources/Textures/_NF/Markers/pacifiedzone.rsi/meta.json create mode 100644 Resources/Textures/_NF/Markers/pacifiedzone.rsi/pacified_zone.png diff --git a/Content.Server/_NF/PacifiedZone/PacifiedZoneGeneratorComponent.cs b/Content.Server/_NF/PacifiedZone/PacifiedZoneGeneratorComponent.cs new file mode 100644 index 000000000000..aa2185145582 --- /dev/null +++ b/Content.Server/_NF/PacifiedZone/PacifiedZoneGeneratorComponent.cs @@ -0,0 +1,32 @@ +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Content.Shared.Containers.ItemSlots; +using Robust.Server.GameObjects; +using Content.Shared.Roles; +using Content.Shared.Roles.Jobs; + +namespace Content.Server._NF.PacifiedZone +{ + [RegisterComponent] + public sealed partial class PacifiedZoneGeneratorComponent : Component + { + public List OldListEntities = new(); + public List IntermediateListEntities = new(); + + [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] + public TimeSpan NextUpdate; + + /// + /// The interval at which this component updates. + /// + [DataField] + public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1); + + [DataField("radius")] + public int Radius = 5; + + [DataField("rolesImmun")] + public List> RolesImmun = new(); + } +} \ No newline at end of file diff --git a/Content.Server/_NF/PacifiedZone/PacifiedlZoneGeneratorSystem.cs b/Content.Server/_NF/PacifiedZone/PacifiedlZoneGeneratorSystem.cs new file mode 100644 index 000000000000..863e61f2365d --- /dev/null +++ b/Content.Server/_NF/PacifiedZone/PacifiedlZoneGeneratorSystem.cs @@ -0,0 +1,94 @@ +using Robust.Server.GameObjects; +using Robust.Shared.Timing; +using Content.Shared.Humanoid; +using Content.Shared.CombatMode.Pacification; +using Content.Shared.Mind; +using Content.Shared.Roles; +using Content.Shared.Roles.Jobs; + + +namespace Content.Server._NF.PacifiedZone +{ + public sealed class PacifiedZoneGeneratorSystem : EntitySystem + { + [Dependency] private readonly UserInterfaceSystem _userInterface = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IEntityManager _entMan = default!; + [Dependency] private readonly SharedMindSystem _mindSystem = default!; + [Dependency] private readonly SharedJobSystem _jobSystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnComponentInit); + } + + private void OnComponentInit(EntityUid uid, PacifiedZoneGeneratorComponent component, ComponentInit args) + { + foreach (var humanoid_uid in _lookup.GetEntitiesInRange(Transform(uid).Coordinates, component.Radius)) + { + if (TryComp(humanoid_uid, out var pacifComp)) + continue; + + if (!_mindSystem.TryGetMind(humanoid_uid, out var mindId, out var mind)) + continue; + + _jobSystem.MindTryGetJobId(mindId, out var jobId); + + if (jobId != null) + if (component.RolesImmun.Contains(jobId!.Value)) + continue; + + AddComp(humanoid_uid); + component.OldListEntities.Add(_entMan.GetNetEntity(humanoid_uid)); + } + + component.NextUpdate = _gameTiming.CurTime + component.UpdateInterval; + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var gen_query = AllEntityQuery(); + while (gen_query.MoveNext(out var gen_uid, out var component)) + { + var query = _lookup.GetEntitiesInRange(Transform(gen_uid).Coordinates, component.Radius); + foreach (var humanoid_uid in query) + { + if (!_mindSystem.TryGetMind(humanoid_uid, out var mindId, out var mind)) + continue; + + _jobSystem.MindTryGetJobId(mindId, out var jobId); + + if (jobId != null) + if (component.RolesImmun.Contains(jobId!.Value)) + continue; + + if (component.OldListEntities.Contains(_entMan.GetNetEntity(humanoid_uid))) + { + component.IntermediateListEntities.Add(_entMan.GetNetEntity(humanoid_uid)); + component.OldListEntities.Remove(_entMan.GetNetEntity(humanoid_uid)); + } + else + { + AddComp(humanoid_uid); + component.IntermediateListEntities.Add(_entMan.GetNetEntity(humanoid_uid)); + } + } + + foreach (var humanoid_net_uid in component.OldListEntities) + { + RemComp(GetEntity(humanoid_net_uid)); + } + + component.OldListEntities.Clear(); + component.OldListEntities.AddRange(component.IntermediateListEntities); + component.IntermediateListEntities.Clear(); + + component.NextUpdate += component.UpdateInterval; + } + } + } +} \ No newline at end of file diff --git a/Resources/Prototypes/_NF/Entities/Markers/pacified_zone.yml b/Resources/Prototypes/_NF/Entities/Markers/pacified_zone.yml new file mode 100644 index 000000000000..2672b4cc1fa5 --- /dev/null +++ b/Resources/Prototypes/_NF/Entities/Markers/pacified_zone.yml @@ -0,0 +1,77 @@ +- type: entity + parent: MarkerBase + id: PacifiedZone10 + name: Pacified zone + description: It's just a NanoTrasen miracle... + suffix: 10 + components: + - type: Sprite + sprite: _NF/Markers/pacifiedzone.rsi + state: pacified_zone + - type: PacifiedZoneGenerator + radius: 10 + rolesImmun: + - Bailiff + - Brigmedic + - Cadet + - Deputy + - DetectiveNF + - SeniorOfficer + - Sheriff + - SecurityGuard + - StationRepresentative + - StationTrafficController +- type: entity + parent: PacifiedZone10 + id: PacifiedZone20 + suffix: 20 + components: + - type: PacifiedZoneGenerator + radius: 20 + rolesImmun: + - Bailiff + - Brigmedic + - Cadet + - Deputy + - DetectiveNF + - SeniorOfficer + - Sheriff + - SecurityGuard + - StationRepresentative + - StationTrafficController +- type: entity + parent: PacifiedZone10 + id: PacifiedZone50 + suffix: 50 + components: + - type: PacifiedZoneGenerator + radius: 50 + rolesImmun: + - Bailiff + - Brigmedic + - Cadet + - Deputy + - DetectiveNF + - SeniorOfficer + - Sheriff + - SecurityGuard + - StationRepresentative + - StationTrafficController +- type: entity + parent: PacifiedZone10 + id: PacifiedZone100 + suffix: 100 + components: + - type: PacifiedZoneGenerator + radius: 100 + rolesImmun: + - Bailiff + - Brigmedic + - Cadet + - Deputy + - DetectiveNF + - SeniorOfficer + - Sheriff + - SecurityGuard + - StationRepresentative + - StationTrafficController \ No newline at end of file diff --git a/Resources/Textures/_NF/Markers/pacifiedzone.rsi/meta.json b/Resources/Textures/_NF/Markers/pacifiedzone.rsi/meta.json new file mode 100644 index 000000000000..5f5dac2752e2 --- /dev/null +++ b/Resources/Textures/_NF/Markers/pacifiedzone.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Made by BeatusCrow(github/discord 1153000512325681183)", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "pacified_zone" + } + ] +} \ No newline at end of file diff --git a/Resources/Textures/_NF/Markers/pacifiedzone.rsi/pacified_zone.png b/Resources/Textures/_NF/Markers/pacifiedzone.rsi/pacified_zone.png new file mode 100644 index 0000000000000000000000000000000000000000..afbff623fb9b7a126814866d48d8ae5f3750505b GIT binary patch literal 840 zcmV-O1GoH%P)Px&0!c(cR9JgP@4=MYg@vZemj^nZPsZYRmz;)3#hfW0nKp_!BtKGr$ z)Fc2PUA&Zx*g62*H#_)z`d3=dyHWl=JvAxrmpGqj1ONb9?G84|*T}6d0s#M2*V&r7 z&ahFwMj;V1(FDNLly{@1qu|e0sX=Q$sjppbboL{u&TXpb^^qV{CBeZ#Mh4kf@fx)2If@XBE$?> zf-)&hV$>?}fm;FqB+F}(2sINLj(`9_^HrG08L=uv6{8a&4vb%c3LUvh#O4jrYZ0h{ zQKH$n9gP4}!Hoh#Wk5W4_U;|7j9&md`($|y2X0AA9wz<307WRmT=C(Hk6~m*C{}*h z=tm}Ckk4)`0z~Mdx94UxmLn1{O!R#P6cRC%-kG~Fm0XSf>||SNTm}+g&&~3UuMdDf zKi+au?{FpXy_*WJ)$ZWx&YUGvcm#CYDzTkfee*pO>DkFP*#4`#2KFv|BcCni1Fs4*|_aVo_C|XC)~U6k;&vhL_9DN>K_pi5wh7G)aws?k~OD= zL=5R-SH#O#UyM-$kkVeSKOmdk0TIEnEU6!m?gb*b@7Hj1bBk*ATyhKqy4=9JnD(Wm zWh^W_hiykNKmQE7yPsfL7Uz}(q*9yw)*_HI8)Dt9sj6AjkK}wG69E9W9l`$oH@+?% z0gD=dN)7;4x_HU&462YG#b#Bj=L9TkMT_Wn(+Sw--6(y0VGpz?q-|&n?d%^dHovnf SPuti40000