diff --git a/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs b/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs index e9f3ce4987..85eb8112af 100644 --- a/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs +++ b/Content.Client/_White/WeaponsModules/WeaponModulesVisuals.cs @@ -18,6 +18,8 @@ public sealed partial class WeaponModulesVisuals : VisualizerSystem(uid, ModuleVisualState.Module, out var module, args.Component) && module.Length != 0 && module != "none") { args.Sprite.LayerSetState(ModuleVisualState.Module, module); diff --git a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs index 10d2b22d0f..b7db9f1eed 100644 --- a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs +++ b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs @@ -33,17 +33,37 @@ public sealed class WeaponModulesSystem : EntitySystem SubscribeLocalEvent(AcceleratorModuleOnEject); } + private bool TryInsertModule(EntityUid module, EntityUid weapon, EntGotInsertedIntoContainerMessage args) + { + if (TryComp(weapon, out var weaponModulesComponent) && ModulesSlot == args.Container.ID) + { + if(!weaponModulesComponent.Modules.Contains(module)) + weaponModulesComponent.Modules.Add(module); + return true; + } + + return false; + } + + private bool TryEjectModule(EntityUid module, EntityUid weapon, EntGotRemovedFromContainerMessage args) + { + if (TryComp(weapon, out var weaponModulesComponent) && ModulesSlot == args.Container.ID) + { + if(weaponModulesComponent.Modules.Contains(module)) + weaponModulesComponent.Modules.Remove(module); + return true; + } + + return false; + } + #region InsertModules private void LightModuleOnInsert(EntityUid module, LightModuleComponent component, EntGotInsertedIntoContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(!weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Add(module); + if(!TryInsertModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -60,14 +80,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void LaserModuleOnInsert(EntityUid module, LaserModuleComponent component, EntGotInsertedIntoContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(!weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Add(module); + if(!TryInsertModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; if (!TryComp(weapon, out var gunComp)) return; @@ -80,14 +96,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(!weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Add(module); + if(!TryInsertModule(module, weapon, args) || !TryComp(weapon, out var weaponModulesComponent)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -98,14 +110,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void SilencerModuleOnInsert(EntityUid module, SilencerModuleComponent component, EntGotInsertedIntoContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(!weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Add(module); + if(!TryInsertModule(module, weapon, args) || !TryComp(weapon, out var weaponModulesComponent)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; if (!TryComp(weapon, out var gunComp)) return; @@ -121,14 +129,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void AcceleratorModuleOnInsert(EntityUid module, AcceleratorModuleComponent component, EntGotInsertedIntoContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(!weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Add(module); + if(!TryInsertModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -144,14 +148,10 @@ public sealed class WeaponModulesSystem : EntitySystem #region EjectModules private void LightModuleOnEject(EntityUid module, LightModuleComponent component, EntGotRemovedFromContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Remove(module); + if(!TryEjectModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -163,14 +163,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void LaserModuleOnEject(EntityUid module, LaserModuleComponent component, EntGotRemovedFromContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Remove(module); + if(!TryEjectModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -180,14 +176,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void FlameHiderModuleOnEject(EntityUid module, FlameHiderModuleComponent component, EntGotRemovedFromContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Remove(module); + if(!TryEjectModule(module, weapon, args) || !TryComp(weapon, out var weaponModulesComponent)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -198,14 +190,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void SilencerModuleOnEject(EntityUid module, SilencerModuleComponent component, EntGotRemovedFromContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Remove(module); + if(!TryEjectModule(module, weapon, args) || !TryComp(weapon, out var weaponModulesComponent)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; @@ -217,14 +205,10 @@ public sealed class WeaponModulesSystem : EntitySystem private void AcceleratorModuleOnEject(EntityUid module, AcceleratorModuleComponent component, EntGotRemovedFromContainerMessage args) { - if (ModulesSlot != args.Container.ID) - return; - EntityUid weapon = args.Container.Owner; - if (!TryComp(weapon, out var weaponModulesComponent)) return; - if(weaponModulesComponent.Modules.Contains(module)) - weaponModulesComponent.Modules.Remove(module); + if(!TryEjectModule(module, weapon, args)) + return; if(!TryComp(weapon, out var appearanceComponent)) return; diff --git a/Resources/Prototypes/Catalog/Fills/Lockers/security.yml b/Resources/Prototypes/Catalog/Fills/Lockers/security.yml index 0bca462d2a..2c13c0fcc6 100644 --- a/Resources/Prototypes/Catalog/Fills/Lockers/security.yml +++ b/Resources/Prototypes/Catalog/Fills/Lockers/security.yml @@ -18,6 +18,7 @@ - id: BoxMindshield - id: ClothingOuterHardsuitWarden - id: OxygenTankFilled + - id: LightModule - type: entity id: LockerWardenFilled @@ -37,6 +38,7 @@ - id: WeaponPistolMk58Nonlethal - id: MagazinePistol - id: BoxMindshield + - id: LightModule - type: entity id: LockerSecurityFilled @@ -66,6 +68,7 @@ - id: WeaponPistolMk58Nonlethal - id: SurveillanceBodyCamera - id: MagazinePistol + - id: LightModule - type: entity id: LockerBrigmedicFilled @@ -126,6 +129,7 @@ - id: VoiceRecorder - id: ClothingEyesGlassesSecurity - id: BoxZipLocks + - id: LightModule - type: entity id: ClosetBombFilled