-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
Content.Server/_NF/PacifiedZone/PacifiedZoneGeneratorComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NetEntity> OldListEntities = new(); | ||
public List<NetEntity> IntermediateListEntities = new(); | ||
|
||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] | ||
public TimeSpan NextUpdate; | ||
|
||
/// <summary> | ||
/// The interval at which this component updates. | ||
/// </summary> | ||
[DataField] | ||
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1); | ||
|
||
[DataField("radius")] | ||
public int Radius = 5; | ||
|
||
[DataField("rolesImmun")] | ||
public List<ProtoId<JobPrototype>> RolesImmun = new(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
Content.Server/_NF/PacifiedZone/PacifiedlZoneGeneratorSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PacifiedZoneGeneratorComponent, ComponentInit>(OnComponentInit); | ||
} | ||
|
||
private void OnComponentInit(EntityUid uid, PacifiedZoneGeneratorComponent component, ComponentInit args) | ||
{ | ||
foreach (var humanoid_uid in _lookup.GetEntitiesInRange<HumanoidAppearanceComponent>(Transform(uid).Coordinates, component.Radius)) | ||
{ | ||
if (TryComp<PacifiedComponent>(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<PacifiedComponent>(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<PacifiedZoneGeneratorComponent>(); | ||
while (gen_query.MoveNext(out var gen_uid, out var component)) | ||
{ | ||
var query = _lookup.GetEntitiesInRange<HumanoidAppearanceComponent>(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<PacifiedComponent>(humanoid_uid); | ||
component.IntermediateListEntities.Add(_entMan.GetNetEntity(humanoid_uid)); | ||
} | ||
} | ||
|
||
foreach (var humanoid_net_uid in component.OldListEntities) | ||
{ | ||
RemComp<PacifiedComponent>(GetEntity(humanoid_net_uid)); | ||
} | ||
|
||
component.OldListEntities.Clear(); | ||
component.OldListEntities.AddRange(component.IntermediateListEntities); | ||
component.IntermediateListEntities.Clear(); | ||
|
||
component.NextUpdate += component.UpdateInterval; | ||
} | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Resources/Prototypes/_NF/Entities/Markers/pacified_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.