]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Job contraband rework (#33385)
authorJohn <35928781+sporkyz@users.noreply.github.com>
Tue, 21 Jan 2025 09:51:27 +0000 (04:51 -0500)
committerGitHub <noreply@github.com>
Tue, 21 Jan 2025 09:51:27 +0000 (10:51 +0100)
* contraband system rework to allow restriction by job, not just department

* Fixing detective trenchcoat inheritance

* removing unnecessary using declarations

* trying to fix testing error by re-adding diagnostics using declaration

* removing unecessary dependency, making allowedJobs nullable

* Adding all of slarti's requested changes except for the hacky job icon method fix

* removing accidental whitespace

* choosing to use the non-localized version because we're comparing the string against the AllowedJobs field, and the contraband classes that fill that field are written in english

* removing unneeded using dec, fixing nesting logic problem

* didn't remove the old nesting, doing that now

* using localized job title and localizing the allowed jobs string, removing usages of JobTitle field. Also networked the _jobTitle field instead.

* rewrite some stuff

* fixes

* fix energy pen

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
16 files changed:
Content.Shared/Access/Components/IdCardComponent.cs
Content.Shared/Contraband/ContrabandComponent.cs
Content.Shared/Contraband/ContrabandSeverityPrototype.cs
Content.Shared/Contraband/ContrabandSystem.cs
Resources/Prototypes/Entities/Clothing/Belt/belts.yml
Resources/Prototypes/Entities/Clothing/Ears/headsets.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/coats.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/vests.yml
Resources/Prototypes/Entities/Clothing/Shoes/specific.yml
Resources/Prototypes/Entities/Objects/Devices/encryption_keys.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/shotgun.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml
Resources/Prototypes/Entities/Objects/Weapons/Melee/e_sword.yml
Resources/Prototypes/Entities/Objects/base_contraband.yml
Resources/Prototypes/contraband_severities.yml

index e80ced646438bd4f20e4f889bab264a472b48f58..3b8322671bebb0ec51687dada33f35cbe1918614 100644 (file)
@@ -22,6 +22,8 @@ public sealed partial class IdCardComponent : Component
     [Access(typeof(SharedIdCardSystem), typeof(SharedPdaSystem), typeof(SharedAgentIdCardSystem), Other = AccessPermissions.ReadWrite)]
     public LocId? JobTitle;
 
+    [DataField]
+    [AutoNetworkedField]
     private string? _jobTitle;
 
     [Access(typeof(SharedIdCardSystem), typeof(SharedPdaSystem), typeof(SharedAgentIdCardSystem), Other = AccessPermissions.ReadWriteExecute)]
index a4ce652f2f56845107376889d6c26273b6921e25..f758d91f0cd8329280bf8a84505581bea9f6c3b7 100644 (file)
@@ -24,5 +24,13 @@ public sealed partial class ContrabandComponent : Component
     /// </summary>
     [DataField]
     [AutoNetworkedField]
-    public HashSet<ProtoId<DepartmentPrototype>>? AllowedDepartments = ["Security"];
+    public HashSet<ProtoId<DepartmentPrototype>> AllowedDepartments = new();
+
+    /// <summary>
+    ///     Which jobs is this item restricted to?
+    ///     If empty, no jobs are allowed to use this beyond the allowed departments.
+    /// </summary>
+    [DataField]
+    [AutoNetworkedField]
+    public HashSet<ProtoId<JobPrototype>> AllowedJobs = new();
 }
index c1ab4b8292ec99ffc877645fffa49960830623c4..094275a6fd39890aa12d74ab0ed5fe931debdcc3 100644 (file)
@@ -19,8 +19,8 @@ public sealed partial class ContrabandSeverityPrototype : IPrototype
     public LocId ExamineText;
 
     /// <summary>
-    /// When examining the contraband, should this take into account the viewer's departments?
+    /// When examining the contraband, should this take into account the viewer's departments and job?
     /// </summary>
     [DataField]
-    public bool ShowDepartments;
+    public bool ShowDepartmentsAndJobs;
 }
index e6931f2860a1793e7507579ed1dbee02fa1e1eba..811ea5356757c99505d28b3047f28a3187ec3635 100644 (file)
@@ -40,6 +40,7 @@ public sealed class ContrabandSystem : EntitySystem
 
         contraband.Severity = other.Severity;
         contraband.AllowedDepartments = other.AllowedDepartments;
+        contraband.AllowedJobs = other.AllowedJobs;
         Dirty(uid, contraband);
     }
 
@@ -54,11 +55,15 @@ public sealed class ContrabandSystem : EntitySystem
 
         using (args.PushGroup(nameof(ContrabandComponent)))
         {
+            // TODO shouldn't department prototypes have a localized name instead of just using the ID for this?
+            var localizedDepartments = ent.Comp.AllowedDepartments.Select(p => Loc.GetString($"department-{p.Id}"));
+            var localizedJobs = ent.Comp.AllowedJobs.Select(p => _proto.Index(p).LocalizedName);
+
             var severity = _proto.Index(ent.Comp.Severity);
-            if (severity.ShowDepartments && ent.Comp is { AllowedDepartments: not null })
+            if (severity.ShowDepartmentsAndJobs)
             {
-                // TODO shouldn't department prototypes have a localized name instead of just using the ID for this?
-                var list = ContentLocalizationManager.FormatList(ent.Comp.AllowedDepartments.Select(p => Loc.GetString($"department-{p.Id}")).ToList());
+                //creating a combined list of jobs and departments for the restricted text
+                var list = ContentLocalizationManager.FormatList(localizedDepartments.Concat(localizedJobs).ToList());
 
                 // department restricted text
                 args.PushMarkup(Loc.GetString("contraband-examine-text-Restricted-department", ("departments", list)));
@@ -69,23 +74,30 @@ public sealed class ContrabandSystem : EntitySystem
             }
 
             // text based on ID card
-            List<ProtoId<DepartmentPrototype>>? departments = null;
+            List<ProtoId<DepartmentPrototype>> departments = new();
+            var jobId = "";
+
             if (_id.TryFindIdCard(args.Examiner, out var id))
             {
                 departments = id.Comp.JobDepartments;
+                if (id.Comp.LocalizedJobTitle is not null)
+                {
+                    jobId = id.Comp.LocalizedJobTitle;
+                }
             }
 
-            // either its fully restricted, you have no departments, or your departments dont intersect with the restricted departments
-            if (ent.Comp.AllowedDepartments is null
-                || departments is null
-                || !departments.Intersect(ent.Comp.AllowedDepartments).Any())
+            // for the jobs we compare the localized string in case you use an agent ID or custom job name that is not a prototype
+            if (departments.Intersect(ent.Comp.AllowedDepartments).Any()
+                || localizedJobs.Contains(jobId))
+            {
+                // you are allowed to use this!
+                args.PushMarkup(Loc.GetString("contraband-examine-text-in-the-clear"));
+            }
+            else
             {
+                // straight to jail!
                 args.PushMarkup(Loc.GetString("contraband-examine-text-avoid-carrying-around"));
-                return;
             }
-
-            // otherwise fine to use :tm:
-            args.PushMarkup(Loc.GetString("contraband-examine-text-in-the-clear"));
         }
     }
 }
index 621f30dbb3509872446182c31d0b404d091f87c1..77f53f9417a317ca394e824ee038a26fa3d299f5 100644 (file)
 # Belts without visualizers
 
 - type: entity
-  parent: [ClothingBeltAmmoProviderBase, BaseRestrictedContraband]
+  parent: [ClothingBeltAmmoProviderBase, BaseSecurityBartenderContraband]
   id: ClothingBeltBandolier
   name: bandolier
   description: A bandolier for holding shotgun ammunition.
index 817f83ec927ae6a791f19d4a095f87eb45e1f543..ca9d0e89a1c86fcdf9074d662d9788cde5eb798f 100644 (file)
       - EncryptionKeyCommon
 
 - type: entity
-  parent: [ClothingHeadset, BaseRestrictedContraband]
+  parent: [ClothingHeadset, BaseSecurityLawyerContraband]
   id: ClothingHeadsetSecurity
   name: security headset
   description: This is used by your elite security force.
index 2412dd9d5c3291b517309326bf61a4462053840f..cdb938030db0b7782cc12b51a313400d1ac83b59 100644 (file)
@@ -1,11 +1,12 @@
 # Numbers for armor here largely taken from /tg/.
 # NOTE: Half of the kind of armor you're probably thinking of is in vests.yml. These should probably be merged some day.
 
-#Basic armor vest
+#Basic armor vest for inheritance
 - type: entity
   parent: [ClothingOuterBaseMedium, AllowSuitStorageClothing, BaseRestrictedContraband]
-  id: ClothingOuterArmorBasic
+  id: ClothingOuterArmorBase
   name: armor vest
+  abstract: true
   description: A standard Type I armored vest that provides decent protection against most types of damage.
   components:
   - type: Sprite
   - type: ExplosionResistance
     damageCoefficient: 0.90
 
+#Standard armor vest, allowed for security and bartenders
+- type: entity
+  parent: [ BaseSecurityBartenderContraband, ClothingOuterArmorBase]
+  id: ClothingOuterArmorBasic
+
 #Alternate / slim basic armor vest
 - type: entity
   parent: ClothingOuterArmorBasic
@@ -58,7 +64,7 @@
   - type: GroupExamine
 
 - type: entity
-  parent: ClothingOuterArmorBasic
+  parent: ClothingOuterArmorBase
   id: ClothingOuterArmorBulletproof
   name: bulletproof vest
   description: A Type III heavy bulletproof vest that excels in protecting the wearer against traditional projectile weaponry and explosives to a minor extent.
@@ -78,7 +84,7 @@
     damageCoefficient: 0.80
 
 - type: entity
-  parent: ClothingOuterArmorBasic
+  parent: ClothingOuterArmorBase
   id: ClothingOuterArmorReflective
   name: reflective vest
   description: An armored vest with advanced shielding to protect against energy weapons.
index f2dfe7c6e74967938b78a3cac978c61b0650c5aa..e2db7ebd94cb637506fabf584139f64822891a6c 100644 (file)
@@ -10,7 +10,7 @@
     sprite: Clothing/OuterClothing/Coats/bomber.rsi
 
 - type: entity
-  parent: [ClothingOuterStorageBase, AllowSuitStorageClothing, ClothingOuterArmorBasic]
+  parent: [ClothingOuterStorageBase, AllowSuitStorageClothing, ClothingOuterArmorBase]
   id: ClothingOuterCoatDetective
   name: detective trenchcoat
   description: An 18th-century multi-purpose trenchcoat. Someone who wears this means serious business.
index 994e86b548cc8c39ac3f34d2e576c5ddc143fba0..accd24dd3cc0d7d88c59cdcf99e932f4378d675e 100644 (file)
@@ -42,7 +42,7 @@
 
 #Detective's vest
 - type: entity
-  parent: [ClothingOuterArmorBasic, BaseRestrictedContraband]
+  parent: [ClothingOuterArmorBase, BaseRestrictedContraband]
   id: ClothingOuterVestDetective
   name: detective's vest
   description: A hard-boiled private investigator's armored vest.
index 3a17dcde371b4e789303a97e3635a96e2626735d..a5c32928dabd3f72ebdc591e4ca3838ae6c5f9e6 100644 (file)
     sprite: Clothing/Shoes/Specific/cult.rsi
 
 - type: entity
-  parent: ClothingShoesBase
+  parent: [ ClothingShoesBase, BaseJanitorContraband ]
   id: ClothingShoesGaloshes
   name: galoshes
   description: Rubber boots.
index 7393532654dea6948042a642cadfc5ec722cba8f..2d23885bcac4aac92b1ea6a6a5534a88738a855c 100644 (file)
     - state: robotics_label
 
 - type: entity
-  parent: [ EncryptionKey, BaseSecurityContraband ]
+  parent: [ EncryptionKey, BaseSecurityLawyerContraband ]
   id: EncryptionKeySecurity
   name: security encryption key
   description: An encryption key used by security.
index dd00440eec014f18e888aa4e6995083917db8ac6..a2b9fb27373cf671d41f7293c8e09fd837939cb2 100644 (file)
@@ -22,7 +22,7 @@
 - type: entity
   id: ShellShotgunBeanbag
   name: shell (.50 beanbag)
-  parent: BaseShellShotgun
+  parent: [ BaseShellShotgun, BaseSecurityBartenderContraband ]
   components:
   - type: Tag
     tags:
@@ -55,7 +55,7 @@
 - type: entity
   id: ShellShotgunFlare
   name: shell (.50 flare)
-  parent: BaseShellShotgun
+  parent: [ BaseShellShotgun, BaseSecurityBartenderContraband ]
   components:
   - type: Tag
     tags:
index 58cf9eaed3e6752631c734798ce646b8e8e9cb85..a927d880ef9d55771786a2ad9d588eeeaa6eb2fc 100644 (file)
 
 - type: entity
   name: double-barreled shotgun
-  parent: [BaseWeaponShotgun, BaseGunWieldable, BaseMinorContraband]
+  parent: [BaseWeaponShotgun, BaseGunWieldable, BaseSecurityBartenderContraband]
   id: WeaponShotgunDoubleBarreled
   description: An immortal classic. Uses .50 shotgun shells.
   components:
 
 - type: entity
   name: sawn-off shotgun
-  parent: BaseWeaponShotgun
+  parent: [ BaseWeaponShotgun, BaseSecurityBartenderContraband ]
   id: WeaponShotgunSawn
   description: Groovy! Uses .50 shotgun shells.
   components:
index 59a27ccf0cc87defe117d53e92d3e6cbe3868b1e..2e576e6a50332df900d1356e1f3c7efd236d52a8 100644 (file)
       doAfterDuration: 4.0
     - type: Contraband
       severity: Syndicate
-      allowedDepartments: null
   - type: Sprite
     sprite: Objects/Weapons/Melee/e_dagger.rsi
     layers:
index 6f44767c9f11e766e06df376cc22997720cc6bdb..84df2f8b37ed77095e2a9659712c0d7f95181db8 100644 (file)
@@ -5,8 +5,6 @@
   components:
   - type: Contraband
     severity: Syndicate
-    # no one should be carrying this around visibly!
-    allowedDepartments: null
 
 # minor contraband not departmentally restricted -- improvised weapons etc
 - type: entity
@@ -15,8 +13,6 @@
   components:
   - type: Contraband
     severity: Minor
-    # according to space law no dept is authorized to have
-    allowedDepartments: null
 
 # major contraband, for things like guns or weaponry that don't belong to any department and aren't syndicate specific
 - type: entity
@@ -25,7 +21,6 @@
   components:
   - type: Contraband
     severity: Major
-    allowedDepartments: null
 
 # minor contraband by default restricted to security only
 - type: entity
   - type: Contraband
     allowedDepartments: [ Medical, Science ]
 
+# contraband restricted by job by some degree
+- type: entity
+  id: BaseSecurityBartenderContraband
+  parent: BaseRestrictedContraband
+  abstract: true
+  components:
+  - type: Contraband
+    allowedDepartments: [ Security ]
+    allowedJobs: [ Bartender ]
+
+- type: entity
+  id: BaseSecurityLawyerContraband
+  parent: BaseRestrictedContraband
+  abstract: true
+  components:
+  - type: Contraband
+    allowedDepartments: [ Security ]
+    allowedJobs: [ Lawyer ]
+
+- type: entity
+  id: BaseJanitorContraband
+  parent: BaseRestrictedContraband
+  abstract: true
+  components:
+  - type: Contraband
+    allowedJobs: [ Janitor ]
+
 # for ~objective items
 - type: entity
   id: BaseGrandTheftContraband
index 54f5cd62ef6be2aef9565129d534202e2b4ee7f9..c103af5e0a6a0d97bc079e0d69c71ffbb5251e9b 100644 (file)
@@ -14,7 +14,7 @@
 - type: contrabandSeverity
   id: Restricted
   examineText: contraband-examine-text-Restricted
-  showDepartments: true
+  showDepartmentsAndJobs: true
 
 # Having this as a regular crew member is considered grand theft. (nuke disk, captain's gear, objective items, etc)
 - type: contrabandSeverity