From d14e999abfa348e05760e31ecde666b6ad82da22 Mon Sep 17 00:00:00 2001 From: BeatusCrow Date: Tue, 16 Jul 2024 11:17:29 +0300 Subject: [PATCH] add peaceful zone --- .../PeacefulZoneGeneratorComponent.cs | 32 ++++++ .../PeacefulZoneGeneratorSystem.cs | 94 ++++++++++++++++++ Resources/Locale/ru-RU/_NF/PeacefulZone.ftl | 2 + Resources/Prototypes/_NF/peaceful_zone.yml | 22 ++++ .../Textures/_NF/peacefulzone.rsi/meta.json | 14 +++ .../_NF/peacefulzone.rsi/peaceful_zone.png | Bin 0 -> 894 bytes 6 files changed, 164 insertions(+) create mode 100644 Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorComponent.cs create mode 100644 Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorSystem.cs create mode 100644 Resources/Locale/ru-RU/_NF/PeacefulZone.ftl create mode 100644 Resources/Prototypes/_NF/peaceful_zone.yml create mode 100644 Resources/Textures/_NF/peacefulzone.rsi/meta.json create mode 100644 Resources/Textures/_NF/peacefulzone.rsi/peaceful_zone.png diff --git a/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorComponent.cs b/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorComponent.cs new file mode 100644 index 00000000000..0d3bcccfacc --- /dev/null +++ b/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorComponent.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.PeacefulZone +{ + [RegisterComponent] + public sealed partial class PeacefulZoneGeneratorComponent : 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(); + } +} diff --git a/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorSystem.cs b/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorSystem.cs new file mode 100644 index 00000000000..60316693961 --- /dev/null +++ b/Content.Server/_NF/PeacefulZone/PeacefulZoneGeneratorSystem.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.PeacefulZone +{ + public sealed class PeacefulZoneGeneratorSystem : 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, PeacefulZoneGeneratorComponent 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; + } + } + } +} diff --git a/Resources/Locale/ru-RU/_NF/PeacefulZone.ftl b/Resources/Locale/ru-RU/_NF/PeacefulZone.ftl new file mode 100644 index 00000000000..02f1060564f --- /dev/null +++ b/Resources/Locale/ru-RU/_NF/PeacefulZone.ftl @@ -0,0 +1,2 @@ +peaceful-zone-name = Мирная зона +peaceful-zone-description = Волшебство NT творит чудеса... diff --git a/Resources/Prototypes/_NF/peaceful_zone.yml b/Resources/Prototypes/_NF/peaceful_zone.yml new file mode 100644 index 00000000000..009c86b004a --- /dev/null +++ b/Resources/Prototypes/_NF/peaceful_zone.yml @@ -0,0 +1,22 @@ +- type: entity + parent: MarkerBase + id: PeacefulZone + name: peaceful-zone-name + description: peaceful-zone-description + components: + - type: Sprite + sprite: _NF/peacefulzone.rsi + state: peaceful_zone + - type: PeacefulZoneGenerator + radius: 300 # this is the value chosen by Kmin + rolesImmun: + - Bailiff + - Brigmedic + - Cadet + - Deputy + - DetectiveNF + - SeniorOfficer + - Sheriff + - SecurityGuard + - StationRepresentative + - StationTrafficController diff --git a/Resources/Textures/_NF/peacefulzone.rsi/meta.json b/Resources/Textures/_NF/peacefulzone.rsi/meta.json new file mode 100644 index 00000000000..f18168bfd55 --- /dev/null +++ b/Resources/Textures/_NF/peacefulzone.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Made by BeatusCrow(github/discord)", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "peaceful_zone" + } + ] +} diff --git a/Resources/Textures/_NF/peacefulzone.rsi/peaceful_zone.png b/Resources/Textures/_NF/peacefulzone.rsi/peaceful_zone.png new file mode 100644 index 0000000000000000000000000000000000000000..783c4128f2d417d5a8c45e63e57b102f2d925788 GIT binary patch literal 894 zcmV-^1A+XBP)nir&m5p zkhX*W+1W7{0GD#@5^ z2mXjl^4&%|AA6OT^cKv~+2Tl6+bi|x3CO__t7R;R7EQB#T;#{2#*E&4ZR$6cMc3)L z{u^&*#0Cb3+8#m_L|Y+0L-yiRi+$AuUXFMI9moq_>(B?8iQ2204SUj3PlWjsosD&NRw-0L4BcgF#H0dfx2@B_kma+={}e{ zxqx7_r$j*-ywl$DJj!C}5SCri_B|ArqDv|umWW3lv#03ywFMY8gY(K@uC#gehr@5J>n0f01d8-O5qQr01XuCzIJl=`JsKm_gp|P-T$)y zJjWZ?oqtZJ0UzA&{=@rw@?zrzDj_-nj14axpeswpynA_#c!1)k#y>Yw+M5r~dgS=> z!+k`v4Qs4DdK%)jO21AGUwy7)qoC*F4=bVHB z?7KbfVW<$@H77@qrOf8CaYJ3H;*R9{s&MW4*|F!hF4XoEqcE!SC)*f2Ily=P3&hd9 U{%0E{p#T5?07*qoM6N<$g0teIU;qFB literal 0 HcmV?d00001