Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor JobBlock code #634

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Content.Shared.Players;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Roles;
using Content.Shared._NC.Roles; // Nuclear 14
using Robust.Client;
using Robust.Client.Player;
using Content.Client.Preferences; // Nuclear 14
Expand All @@ -23,7 +22,7 @@ public sealed partial class JobRequirementsManager : ISharedPlaytimeManager
[Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly IClientPreferencesManager _clientPreferences = default!; // Nuclear 14
[Dependency] private readonly IClientPreferencesManager _clientPreferences = default!; // Nuclear 14

private readonly Dictionary<string, TimeSpan> _roles = new();
private readonly List<string> _roleBans = new();
Expand Down
6 changes: 0 additions & 6 deletions Content.Shared/Roles/JobPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Shared._NC.Roles; // Nuclear 14
using Content.Shared.Access;
using Content.Shared.Customization.Systems;
using Content.Shared.Players.PlayTimeTracking;
Expand Down Expand Up @@ -47,11 +46,6 @@ public sealed partial class JobPrototype : IPrototype
[DataField("requirements")]
public List<CharacterRequirement>? Requirements;

// Nuclear 14 start
[DataField("jobBlockForSpecies")]
public HashSet<JobBlockAbstract>? JobBlockForSpecies;
// Nuclear 14 end

[DataField("joinNotifyCrew")]
public bool JoinNotifyCrew { get; private set; } = false;

Expand Down
73 changes: 32 additions & 41 deletions Content.Shared/_NC/Roles/JobBlockForSpecies.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Players.PlayTimeTracking;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared._NC.Roles
using Robust.Shared.Utility;
using Content.Shared.CCVar;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;

namespace Content.Shared.Customization.Systems;

/// <summary>
/// Checking for a list of prohibited species
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class JobBlockForSpeciesRequirement : CharacterRequirement
{
[ImplicitDataDefinitionForInheritors]
public abstract partial class JobBlockAbstract { }

[UsedImplicitly]
public sealed partial class JobBlockForSpecie : JobBlockAbstract
{
[DataField("nameSpecie")]
public string? NameSpecie { get; set; }

[DataField("inverted")]
public bool Inverted { get; set; }
}
[DataField(required: true)]
public string[] Species { get; set; } = Array.Empty<string>();

public static class JobBlockForSpecies
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted, IPrototype prototype,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason, int depth = 0)
{
public static bool TryRequirementMet(
JobBlockAbstract jobBlockAbstract,
string species,
[NotNullWhen(false)] out string? reason)
if (Species.Any(species => string.Equals(species, profile.Species, StringComparison.OrdinalIgnoreCase)))
{
reason = null;

if (jobBlockAbstract is not JobBlockForSpecie jobBlockForSpecie)
{
reason = string.Empty;
return false;
}

if (jobBlockForSpecie.Inverted)
{
return true;
}

if (string.Equals(jobBlockForSpecie.NameSpecie, species, StringComparison.OrdinalIgnoreCase))
{
reason = Loc.GetString("role-timer-race-ban");
return false;
}

return true;
reason = FormattedMessage.FromMarkup(Loc.GetString("role-timer-race-ban"));
return false;
}

reason = null;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodMidwest
min: 3600 # 1 hour
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSMidKnightGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -20,11 +24,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodMidwest
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSMidKnightGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodMidwest
min: 36000 # 10 hours
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSMidPaladinCommanderGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -20,11 +24,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodMidwest
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSMidPaladinCommanderGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodMidwest
min: 18000 # 5 hours
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSMidPaladinGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -21,11 +25,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodMidwest
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSMidPaladinGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodMidwest
min: 3600 # 1 hour
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSMidScribeGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -21,11 +25,6 @@
factions:
- BrotherhoodMidwest
- type: CPRTraining
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSMidScribeGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
requirements:
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodWashington
min: 36000 # 10 hours
min: 36000 # 10 hours'
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
weight: 10
startingGear: BoSWashingtonCommanderGear
alwaysUseSpawner: true
Expand All @@ -23,11 +27,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodWashington
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSWashingtonCommanderGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
name: job-name-bos-washington-initiate
description: job-description-bos-washington-initiate
playTimeTracker: BoSWashingtonInitiate
requirements:
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSWashingtonInitiateGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -17,11 +22,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodWashington
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSWashingtonInitiateGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodWashington
min: 3600 # 1 hour as BoSWashingtonInitiate
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSWashingtonKnightGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -22,11 +26,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodWashington
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSWashingtonKnightGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodWashington
min: 18000 # 5 hours
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSWashingtonPaladinGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -24,11 +28,6 @@
- type: NpcFactionMember
factions:
- BrotherhoodWashington
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSWashingtonPaladinGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- !type:CharacterDepartmentTimeRequirement
department: BrotherhoodWashington
min: 3600 # 1 hour as BoSWashingtonInitiate
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: BoSWashingtonScribeGear
alwaysUseSpawner: true
icon: "JobIconScientist"
Expand All @@ -22,11 +26,6 @@
factions:
- BrotherhoodWashington
- type: CPRTraining
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: BoSWashingtonScribeGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- !type:CharacterDepartmentTimeRequirement
department: Vault
min: 36000 # 10 hours
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
playTimeTracker: Overseer
weight: 20
startingGear: OverseerGear
Expand All @@ -23,11 +27,6 @@
- type: NpcFactionMember
factions:
- Vault
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: OverseerGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
name: job-name-vault-doctor
description: job-description-vault-doctor
playTimeTracker: VaultDoctor
requirements:
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: VaultDoctorGear
alwaysUseSpawner: true
icon: "JobIconMedicalDoctor"
Expand All @@ -17,11 +22,6 @@
factions:
- Vault
- type: CPRTraining
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: VaultDoctorGear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
name: job-name-vault-dweller
description: job-description-vault-dweller
playTimeTracker: VaultDweller
requirements:
- !type:JobBlockForSpeciesRequirement
species:
- Ghoul
- GhoulGlowing
startingGear: VaultDwellerGear
alwaysUseSpawner: true
icon: "JobIconPassenger"
Expand All @@ -15,11 +20,6 @@
- type: NpcFactionMember
factions:
- Vault
jobBlockForSpecies:
- !type:JobBlockForSpecie
nameSpecie: Ghoul
- !type:JobBlockForSpecie
nameSpecie: GhoulGlowing

- type: startingGear
id: VaultDwellerGear
Expand Down
Loading
Loading