From 428a153ddbe0664f8eba274df6771fc1174b5c71 Mon Sep 17 00:00:00 2001 From: CaYpeN1 Date: Mon, 25 Mar 2024 14:27:01 +0500 Subject: [PATCH] tweak: main values to components, rework methods --- .../WeaponModules/WeaponModulesSystem.cs | 82 +++++++------------ .../AcceleratorModuleComponent.cs | 3 + .../WeaponModules/LaserModuleComponent.cs | 3 + .../WeaponModules/LightModuleComponent.cs | 3 + .../Objects/Weapons/Guns/Rifles/rifles.yml | 2 - .../Objects/Weapons/Guns/SMGs/smgs.yml | 2 - .../Objects/Weapons/Guns/Modules/modules.yml | 10 +-- 7 files changed, 43 insertions(+), 62 deletions(-) diff --git a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs index a399034b20..f70a4dbaf3 100644 --- a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs +++ b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs @@ -2,6 +2,7 @@ using Content.Shared._White.WeaponModules; using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Systems; +using Linguini.Syntax.Ast; using Robust.Server.GameObjects; using Robust.Shared.Containers; @@ -33,35 +34,37 @@ public sealed class WeaponModulesSystem : EntitySystem SubscribeLocalEvent(AcceleratorModuleOnInsert); SubscribeLocalEvent(AcceleratorModuleOnEject); } - private bool TryInsertModule(EntityUid module, EntityUid weapon, EntGotInsertedIntoContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent) + private bool TryInsertModule(EntityUid module, EntityUid weapon, BaseModuleComponent component, EntGotInsertedIntoContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent) { - if (TryComp(weapon, out var weaponModulesComponents) && ModulesSlot == args.Container.ID) + if (!TryComp(weapon, out var weaponModulesComponents) || !TryComp(weapon, out var appearanceComponent) || ModulesSlot != args.Container.ID) { - if(!weaponModulesComponents.Modules.Contains(module)) - weaponModulesComponents.Modules.Add(module); - weaponModulesComponent = weaponModulesComponents; - return true; + weaponModulesComponent = null; + appearanceComponent = null; + return false; } + + if(!weaponModulesComponents.Modules.Contains(module)) + weaponModulesComponents.Modules.Add(module); + _appearanceSystem.SetData(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); weaponModulesComponent = weaponModulesComponents; - return false; + + return true; } private bool TryEjectModule(EntityUid module, EntityUid weapon, EntGotRemovedFromContainerMessage args, [NotNullWhen(true)] out WeaponModulesComponent? weaponModulesComponent) { - if (TryComp(weapon, out var weaponModulesComponents) && ModulesSlot == args.Container.ID) + if (!TryComp(weapon, out var weaponModulesComponents) || !TryComp(weapon, out var appearanceComponent) || ModulesSlot != args.Container.ID) { - if(weaponModulesComponents.Modules.Contains(module)) - weaponModulesComponents.Modules.Remove(module); - weaponModulesComponent = weaponModulesComponents; - return true; + weaponModulesComponent = null; + appearanceComponent = null; + return false; } - weaponModulesComponent = weaponModulesComponents; - return false; - } - private void SetAppearance(EntityUid weapon, Enum key, string value, AppearanceComponent appearanceComponent) - { - _appearanceSystem.SetData(weapon, key, value, appearanceComponent); + if(weaponModulesComponents.Modules.Contains(module)) + weaponModulesComponents.Modules.Remove(module); + _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); + weaponModulesComponent = weaponModulesComponents; + return true; } #region InsertModules @@ -69,19 +72,17 @@ public sealed class WeaponModulesSystem : EntitySystem { EntityUid weapon = args.Container.Owner; - if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent)) + if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent)) return; if(!TryComp(weapon, out var appearanceComponent)) return; - SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); - _lightSystem.EnsureLight(weapon); _lightSystem.TryGetLight(weapon, out var light); _appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent); - _lightSystem.SetRadius(weapon, 4F, light); + _lightSystem.SetRadius(weapon, component.Radius, light); _lightSystem.SetEnabled(weapon, true, light); } @@ -89,28 +90,23 @@ public sealed class WeaponModulesSystem : EntitySystem { EntityUid weapon = args.Container.Owner; - if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent)) + if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; if (!TryComp(weapon, out var gunComp)) return; component.OldProjectileSpeed = gunComp.ProjectileSpeed; - SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); - _gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + 15F); + _gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed + component.ProjectileSpeedAdd); } private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args) { EntityUid weapon = args.Container.Owner; - if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent)) + if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); weaponModulesComponent.UseEffect = true; Dirty(module, weaponModulesComponent); } @@ -119,15 +115,13 @@ public sealed class WeaponModulesSystem : EntitySystem { EntityUid weapon = args.Container.Owner; - if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent)) + if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; if (!TryComp(weapon, out var gunComp)) return; component.OldSoundGunshot = gunComp.SoundGunshot; - SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); weaponModulesComponent.UseEffect = true; _gunSystem.SetSound(weapon, component.NewSoundGunshot); @@ -138,17 +132,14 @@ public sealed class WeaponModulesSystem : EntitySystem { EntityUid weapon = args.Container.Owner; - if(!TryInsertModule(module, weapon, args, out var weaponModulesComponent)) + if(!TryInsertModule(module, weapon, component, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - if (!TryComp(weapon, out var gunComp)) return; component.OldFireRate = gunComp.FireRate; - SetAppearance(weapon, ModuleVisualState.Module, component.AppearanceValue, appearanceComponent); - _gunSystem.SetFireRate(weapon, component.OldFireRate + 2F); + _gunSystem.SetFireRate(weapon, component.OldFireRate + component.FireRateAdd); } #endregion @@ -160,9 +151,6 @@ public sealed class WeaponModulesSystem : EntitySystem if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent); _lightSystem.TryGetLight(weapon, out var light); _lightSystem.SetRadius(weapon, 0F, light); _lightSystem.SetEnabled(weapon, false, light); @@ -175,9 +163,6 @@ public sealed class WeaponModulesSystem : EntitySystem if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent); _gunSystem.SetProjectileSpeed(weapon, component.OldProjectileSpeed); } @@ -188,9 +173,6 @@ public sealed class WeaponModulesSystem : EntitySystem if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent); weaponModulesComponent.UseEffect = false; Dirty(module, weaponModulesComponent); } @@ -202,9 +184,6 @@ public sealed class WeaponModulesSystem : EntitySystem if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent); weaponModulesComponent.UseEffect = false; _gunSystem.SetSound(weapon, component.OldSoundGunshot!); Dirty(module, weaponModulesComponent); @@ -217,9 +196,6 @@ public sealed class WeaponModulesSystem : EntitySystem if(!TryEjectModule(module, weapon, args, out var weaponModulesComponent)) return; - if(!TryComp(weapon, out var appearanceComponent)) return; - - SetAppearance(weapon, ModuleVisualState.Module, "none", appearanceComponent); _gunSystem.SetFireRate(weapon, component.OldFireRate); } #endregion diff --git a/Content.Shared/_White/WeaponModules/AcceleratorModuleComponent.cs b/Content.Shared/_White/WeaponModules/AcceleratorModuleComponent.cs index 389c84c198..bd6d877ad5 100644 --- a/Content.Shared/_White/WeaponModules/AcceleratorModuleComponent.cs +++ b/Content.Shared/_White/WeaponModules/AcceleratorModuleComponent.cs @@ -8,4 +8,7 @@ public sealed partial class AcceleratorModuleComponent : BaseModuleComponent { [ViewVariables(VVAccess.ReadWrite), DataField] public float OldFireRate; + + [ViewVariables(VVAccess.ReadWrite), DataField] + public float FireRateAdd = 2.4F; } diff --git a/Content.Shared/_White/WeaponModules/LaserModuleComponent.cs b/Content.Shared/_White/WeaponModules/LaserModuleComponent.cs index 3f8404931b..f048d99832 100644 --- a/Content.Shared/_White/WeaponModules/LaserModuleComponent.cs +++ b/Content.Shared/_White/WeaponModules/LaserModuleComponent.cs @@ -8,4 +8,7 @@ public sealed partial class LaserModuleComponent : BaseModuleComponent { [ViewVariables(VVAccess.ReadWrite), DataField] public float OldProjectileSpeed; + + [ViewVariables(VVAccess.ReadWrite), DataField] + public float ProjectileSpeedAdd = 15F; } diff --git a/Content.Shared/_White/WeaponModules/LightModuleComponent.cs b/Content.Shared/_White/WeaponModules/LightModuleComponent.cs index b90bbfe04c..fb05d387e4 100644 --- a/Content.Shared/_White/WeaponModules/LightModuleComponent.cs +++ b/Content.Shared/_White/WeaponModules/LightModuleComponent.cs @@ -8,4 +8,7 @@ public sealed partial class LightModuleComponent : BaseModuleComponent { [ViewVariables(VVAccess.ReadWrite), DataField] public bool Enabled; + + [ViewVariables(VVAccess.ReadWrite), DataField] + public float Radius = 4F; } diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 2a160f2936..9f71109abf 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -119,7 +119,6 @@ magState: mag steps: 1 zeroVisible: true - - type: WeaponModulesVisuals - type: PointLight enabled: false autoRot: true @@ -225,7 +224,6 @@ magState: mag steps: 1 zeroVisible: true - - type: WeaponModulesVisuals - type: PointLight enabled: false autoRot: true diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml index 1332894437..7e968d088b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml @@ -166,7 +166,6 @@ magState: mag steps: 1 zeroVisible: true - - type: WeaponModulesVisuals - type: PointLight enabled: false autoRot: true @@ -286,7 +285,6 @@ magState: mag steps: 6 zeroVisible: true - - type: WeaponModulesVisuals - type: PointLight enabled: false autoRot: true diff --git a/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/Modules/modules.yml b/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/Modules/modules.yml index cca40c558e..c4adde47a5 100644 --- a/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/Modules/modules.yml +++ b/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/Modules/modules.yml @@ -23,7 +23,7 @@ # modules - type: entity id: LightModule - description: Light module for rifles (lector, CV, drozd, WT). + description: Light module for rifles (lecter, CV, drozd, WT). name: "light module" parent: BaseModule components: @@ -36,7 +36,7 @@ - type: entity id: LaserModule - description: Laser module for rifles (lector, CV, drozd, WT). + description: Laser module for rifles (lecter, CV, drozd, WT). name: "laser module" parent: BaseModule components: @@ -49,7 +49,7 @@ - type: entity id: FlameHiderModule - description: Flame Hider module for rifles (lector, CV, drozd, WT). + description: Flame Hider module for rifles (lecter, CV, drozd, WT). name: "flamehider module" parent: BaseModule components: @@ -62,7 +62,7 @@ - type: entity id: SilencerModule - description: Silencer module for rifles (lector, CV, drozd, WT). + description: Silencer module for rifles (lecter, CV, drozd, WT). name: "silencer module" parent: BaseModule components: @@ -75,7 +75,7 @@ - type: entity id: AcceleratorModule - description: Accelerator module for rifles (lector, CV, drozd, WT). + description: Accelerator module for rifles (lecter, CV, drozd, WT). name: "accelerator module" parent: BaseModule components: