From 37c64b69a50df1beed1101e92b0feb198675522c Mon Sep 17 00:00:00 2001 From: Moony Date: Sun, 14 Aug 2022 16:14:46 -0500 Subject: [PATCH] Lock non-newbies out of intern roles. (#10598) * Lock non-newbies out of intern roles. * Remove from service worker as it doesn't gate anything. --- Content.Shared/Roles/JobRequirements.cs | 83 +++++++++++++++---- Resources/Locale/en-US/job/role-timers.ftl | 3 + .../Jobs/Engineering/technical_assistant.yml | 5 ++ .../Roles/Jobs/Medical/medical_intern.yml | 5 ++ .../Roles/Jobs/Security/security_cadet.yml | 5 ++ 5 files changed, 83 insertions(+), 18 deletions(-) diff --git a/Content.Shared/Roles/JobRequirements.cs b/Content.Shared/Roles/JobRequirements.cs index 8658c7e959..83c9989d50 100644 --- a/Content.Shared/Roles/JobRequirements.cs +++ b/Content.Shared/Roles/JobRequirements.cs @@ -12,6 +12,7 @@ namespace Content.Shared.Roles [ImplicitDataDefinitionForInheritors] public abstract class JobRequirement { + [DataField("inverted")] public bool Inverted; } [UsedImplicitly] @@ -104,24 +105,53 @@ namespace Content.Shared.Roles var deptDiff = deptRequirement.Time.TotalMinutes - playtime.TotalMinutes; - if (deptDiff <= 0) - return true; + if (!deptRequirement.Inverted) + { + if (deptDiff <= 0) + return true; - reason = Loc.GetString( - "role-timer-department-insufficient", - ("time", deptDiff), - ("department", Loc.GetString(deptRequirement.Department))); - return false; + reason = Loc.GetString( + "role-timer-department-insufficient", + ("time", deptDiff), + ("department", Loc.GetString(deptRequirement.Department))); + return false; + } + else + { + if (deptDiff <= 0) + { + reason = Loc.GetString( + "role-timer-department-too-high", + ("time", -deptDiff), + ("department", Loc.GetString(deptRequirement.Department))); + return false; + } + + return true; + } case OverallPlaytimeRequirement overallRequirement: var overallTime = playTimes.GetValueOrDefault(PlayTimeTrackingShared.TrackerOverall); var overallDiff = overallRequirement.Time.TotalMinutes - overallTime.TotalMinutes; - if (overallDiff <= 0 || overallTime >= overallRequirement.Time) - return true; + if (!overallRequirement.Inverted) + { + if (overallDiff <= 0 || overallTime >= overallRequirement.Time) + return true; - reason = Loc.GetString("role-timer-overall-insufficient", ("time", overallDiff)); - return false; + reason = Loc.GetString("role-timer-overall-insufficient", ("time", overallDiff)); + return false; + } + else + { + if (overallDiff <= 0 || overallTime >= overallRequirement.Time) + { + reason = Loc.GetString("role-timer-overall-too-high", ("time", -overallDiff)); + return false; + } + + return true; + } case RoleTimeRequirement roleRequirement: proto = roleRequirement.Role; @@ -129,14 +159,31 @@ namespace Content.Shared.Roles playTimes.TryGetValue(proto, out var roleTime); var roleDiff = roleRequirement.Time.TotalMinutes - roleTime.TotalMinutes; - if (roleDiff <= 0) - return true; + if (!roleRequirement.Inverted) + { + if (roleDiff <= 0) + return true; - reason = Loc.GetString( - "role-timer-role-insufficient", - ("time", roleDiff), - ("job", Loc.GetString(proto))); - return false; + reason = Loc.GetString( + "role-timer-role-insufficient", + ("time", roleDiff), + ("job", Loc.GetString(proto))); + return false; + } + else + { + if (roleDiff <= 0) + { + reason = Loc.GetString( + "role-timer-role-too-high", + ("time", -roleDiff), + ("job", Loc.GetString(proto))); + return false; + } + + + return true; + } default: throw new NotImplementedException(); } diff --git a/Resources/Locale/en-US/job/role-timers.ftl b/Resources/Locale/en-US/job/role-timers.ftl index 1cecd41fbc..f897ec369c 100644 --- a/Resources/Locale/en-US/job/role-timers.ftl +++ b/Resources/Locale/en-US/job/role-timers.ftl @@ -1,5 +1,8 @@ role-timer-department-insufficient = Require {TOSTRING($time, "0")} more minutes in {$department} department. +role-timer-department-too-high = Requires {TOSTRING($time, "0")} fewer minutes in {$department} department. (Are you trying to play a trainee role?) role-timer-overall-insufficient = Require {TOSTRING($time, "0")} more minutes of playtime. +role-timer-overall-too-high = Require {TOSTRING($time, "0")} fewer minutes of playtime. (Are you trying to play a trainee role?) role-timer-role-insufficient = Require {TOSTRING($time, "0")} more minutes with {$job} for this role. +role-timer-role-too-high = Require {TOSTRING($time, "0")} fewer minutes with {$job} for this role. (Are you trying to play a trainee role?) role-timer-locked = Locked (hover for details) diff --git a/Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml b/Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml index 2d64eb79b1..fb025ccb0d 100644 --- a/Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml +++ b/Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml @@ -2,6 +2,11 @@ id: TechnicalAssistant name: job-name-assistant playTimeTracker: JobTechnicalAssistant + requirements: + - !type:DepartmentTimeRequirement + department: Engineering + time: 1800 + inverted: true # stop playing intern if you're good at engineering! startingGear: TechnicalAssistantGear icon: "TechnicalAssistant" supervisors: job-supervisors-engineering diff --git a/Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml b/Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml index d15e35d6f2..6c911db5ec 100644 --- a/Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml +++ b/Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml @@ -2,6 +2,11 @@ id: MedicalIntern name: job-name-intern playTimeTracker: JobMedicalIntern + requirements: + - !type:DepartmentTimeRequirement + department: Medical + time: 1800 + inverted: true # stop playing intern if you're good at med! startingGear: MedicalInternGear icon: "MedicalIntern" supervisors: job-supervisors-medicine diff --git a/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml b/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml index 5064fa4887..8f82d4ad42 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml @@ -2,6 +2,11 @@ id: SecurityCadet name: job-name-cadet playTimeTracker: JobSecurityCadet + requirements: + - !type:DepartmentTimeRequirement + department: Security + time: 1800 + inverted: true # stop playing intern if you're good at security! startingGear: SecurityCadetGear icon: "SecurityCadet" supervisors: job-supervisors-security