basemodulecomponent & sharedgunsystem

This commit is contained in:
CaYpeN1
2024-03-22 19:36:18 +05:00
parent 5f610860f5
commit 3dbd027b52
9 changed files with 89 additions and 65 deletions

View File

@@ -18,32 +18,33 @@ public sealed class WeaponModulesSystem : EntitySystem
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<Shared._White.WeaponModules.LightModuleComponent, EntGotInsertedIntoContainerMessage>(LightModuleOnInsert); SubscribeLocalEvent<LightModuleComponent, EntGotInsertedIntoContainerMessage>(LightModuleOnInsert);
SubscribeLocalEvent<Shared._White.WeaponModules.LightModuleComponent, EntGotRemovedFromContainerMessage>(LightModuleOnEject); SubscribeLocalEvent<LightModuleComponent, EntGotRemovedFromContainerMessage>(LightModuleOnEject);
SubscribeLocalEvent<Shared._White.WeaponModules.LaserModuleComponent, EntGotInsertedIntoContainerMessage>(LaserModuleOnInsert); SubscribeLocalEvent<LaserModuleComponent, EntGotInsertedIntoContainerMessage>(LaserModuleOnInsert);
SubscribeLocalEvent<Shared._White.WeaponModules.LaserModuleComponent, EntGotRemovedFromContainerMessage>(LaserModuleOnEject); SubscribeLocalEvent<LaserModuleComponent, EntGotRemovedFromContainerMessage>(LaserModuleOnEject);
SubscribeLocalEvent<Shared._White.WeaponModules.FlameHiderModuleComponent, EntGotInsertedIntoContainerMessage>(FlameHiderModuleOnInsert); SubscribeLocalEvent<FlameHiderModuleComponent, EntGotInsertedIntoContainerMessage>(FlameHiderModuleOnInsert);
SubscribeLocalEvent<Shared._White.WeaponModules.FlameHiderModuleComponent, EntGotRemovedFromContainerMessage>(FlameHiderModuleOnEject); SubscribeLocalEvent<FlameHiderModuleComponent, EntGotRemovedFromContainerMessage>(FlameHiderModuleOnEject);
SubscribeLocalEvent<SilencerModuleComponent, EntGotInsertedIntoContainerMessage>(SilencerModuleOnInsert); SubscribeLocalEvent<SilencerModuleComponent, EntGotInsertedIntoContainerMessage>(SilencerModuleOnInsert);
SubscribeLocalEvent<SilencerModuleComponent, EntGotRemovedFromContainerMessage>(SilencerModuleOnEject); SubscribeLocalEvent<SilencerModuleComponent, EntGotRemovedFromContainerMessage>(SilencerModuleOnEject);
SubscribeLocalEvent<Shared._White.WeaponModules.AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert); SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
SubscribeLocalEvent<Shared._White.WeaponModules.AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject); SubscribeLocalEvent<AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject);
} }
#region InsertModules #region InsertModules
private void LightModuleOnInsert(EntityUid module, Shared._White.WeaponModules.LightModuleComponent component, EntGotInsertedIntoContainerMessage args) private void LightModuleOnInsert(EntityUid module, LightModuleComponent component, EntGotInsertedIntoContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(!weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Add(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
@@ -58,15 +59,16 @@ public sealed class WeaponModulesSystem : EntitySystem
_lightSystem.SetEnabled(weapon, true, light); _lightSystem.SetEnabled(weapon, true, light);
} }
private void LaserModuleOnInsert(EntityUid module, Shared._White.WeaponModules.LaserModuleComponent component, EntGotInsertedIntoContainerMessage args) private void LaserModuleOnInsert(EntityUid module, LaserModuleComponent component, EntGotInsertedIntoContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(!weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Add(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
@@ -74,21 +76,22 @@ public sealed class WeaponModulesSystem : EntitySystem
_gunSystem.setProjectileSpeed(weapon, 35.5F); _gunSystem.setProjectileSpeed(weapon, 35.5F);
} }
private void FlameHiderModuleOnInsert(EntityUid module, Shared._White.WeaponModules.FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args) private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(!weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Add(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent);
component.UseEffect = true; weaponModulesComponent.UseEffect = true;
Dirty(module, component); Dirty(module, weaponModulesComponent);
} }
private void SilencerModuleOnInsert(EntityUid module, SilencerModuleComponent component, EntGotInsertedIntoContainerMessage args) private void SilencerModuleOnInsert(EntityUid module, SilencerModuleComponent component, EntGotInsertedIntoContainerMessage args)
@@ -96,10 +99,11 @@ public sealed class WeaponModulesSystem : EntitySystem
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(!weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Add(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
if (!TryComp<GunComponent>(weapon, out var gunComp)) return; if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
@@ -107,21 +111,22 @@ public sealed class WeaponModulesSystem : EntitySystem
component.OldSoundGunshot = gunComp.SoundGunshot; component.OldSoundGunshot = gunComp.SoundGunshot;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent);
component.UseEffect = true; weaponModulesComponent.UseEffect = true;
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg")); _gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
Dirty(module, component); Dirty(module, weaponModulesComponent);
} }
private void AcceleratorModuleOnInsert(EntityUid module, Shared._White.WeaponModules.AcceleratorModuleComponent component, EntGotInsertedIntoContainerMessage args) private void AcceleratorModuleOnInsert(EntityUid module, AcceleratorModuleComponent component, EntGotInsertedIntoContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(!weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Add(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
@@ -131,51 +136,58 @@ public sealed class WeaponModulesSystem : EntitySystem
#endregion #endregion
#region EjectModules #region EjectModules
private void LightModuleOnEject(EntityUid module, Shared._White.WeaponModules.LightModuleComponent component, EntGotRemovedFromContainerMessage args) private void LightModuleOnEject(EntityUid module, LightModuleComponent component, EntGotRemovedFromContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Remove(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_lightSystem.TryGetLight(weapon, out var light); _lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetRadius(weapon, 0F, light);
_lightSystem.SetEnabled(weapon, false, light); _lightSystem.SetEnabled(weapon, false, light);
} }
private void LaserModuleOnEject(EntityUid module, Shared._White.WeaponModules.LaserModuleComponent component, EntGotRemovedFromContainerMessage args) private void LaserModuleOnEject(EntityUid module, LaserModuleComponent component, EntGotRemovedFromContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Remove(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 25F); _gunSystem.setProjectileSpeed(weapon, 25F);
} }
private void FlameHiderModuleOnEject(EntityUid module, Shared._White.WeaponModules.FlameHiderModuleComponent component, EntGotRemovedFromContainerMessage args) private void FlameHiderModuleOnEject(EntityUid module, FlameHiderModuleComponent component, EntGotRemovedFromContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Remove(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
component.UseEffect = false; weaponModulesComponent.UseEffect = false;
Dirty(module, component); Dirty(module, weaponModulesComponent);
} }
private void SilencerModuleOnEject(EntityUid module, SilencerModuleComponent component, EntGotRemovedFromContainerMessage args) private void SilencerModuleOnEject(EntityUid module, SilencerModuleComponent component, EntGotRemovedFromContainerMessage args)
@@ -183,31 +195,36 @@ public sealed class WeaponModulesSystem : EntitySystem
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Remove(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
component.UseEffect = false; weaponModulesComponent.UseEffect = false;
_gunSystem.setSound(weapon, component.OldSoundGunshot!); _gunSystem.setSound(weapon, component.OldSoundGunshot!);
Dirty(module, component); Dirty(module, weaponModulesComponent);
} }
private void AcceleratorModuleOnEject(EntityUid module, Shared._White.WeaponModules.AcceleratorModuleComponent component, EntGotRemovedFromContainerMessage args) private void AcceleratorModuleOnEject(EntityUid module, AcceleratorModuleComponent component, EntGotRemovedFromContainerMessage args)
{ {
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner; EntityUid weapon = args.Container.Owner;
if (!TryComp<WeaponModulesComponent>(weapon, out var weaponModulesComponent)) return;
if(weaponModulesComponent.Modules.Contains(module))
weaponModulesComponent.Modules.Remove(module);
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return; if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent); _appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setFireRate(weapon, component.OldFireRate); _gunSystem.setFireRate(weapon, component.OldFireRate);
} }
#endregion #endregion
} }

View File

@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Numerics; using System.Numerics;
using Content.Shared._White.WeaponModules;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
@@ -476,6 +477,9 @@ public abstract partial class SharedGunSystem : EntitySystem
protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null) protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null)
{ {
bool cancelled = TryComp<WeaponModulesComponent>(gun, out var weaponModulesComponent) && weaponModulesComponent.UseEffect;
if(cancelled) return;
var attemptEv = new GunMuzzleFlashAttemptEvent(); var attemptEv = new GunMuzzleFlashAttemptEvent();
RaiseLocalEvent(gun, ref attemptEv); RaiseLocalEvent(gun, ref attemptEv);
if (attemptEv.Cancelled) if (attemptEv.Cancelled)

View File

@@ -4,7 +4,7 @@
/// This is used for... /// This is used for...
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class AcceleratorModuleComponent : WeaponModulesComponent public sealed partial class AcceleratorModuleComponent : BaseModuleComponent
{ {
[ViewVariables(VVAccess.ReadWrite), DataField] [ViewVariables(VVAccess.ReadWrite), DataField]
public float OldFireRate; public float OldFireRate;

View File

@@ -0,0 +1,9 @@
using Robust.Shared.GameStates;
namespace Content.Shared._White.WeaponModules;
[RegisterComponent, NetworkedComponent]
public partial class BaseModuleComponent : Component
{
}

View File

@@ -4,6 +4,6 @@
/// This is used for... /// This is used for...
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class FlameHiderModuleComponent : WeaponModulesComponent public sealed partial class FlameHiderModuleComponent : BaseModuleComponent
{ {
} }

View File

@@ -4,7 +4,7 @@
/// This is used for... /// This is used for...
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class LaserModuleComponent : WeaponModulesComponent public sealed partial class LaserModuleComponent : BaseModuleComponent
{ {
} }

View File

@@ -4,7 +4,7 @@
/// LightModuleComponent /// LightModuleComponent
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class LightModuleComponent : WeaponModulesComponent public sealed partial class LightModuleComponent : BaseModuleComponent
{ {
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public bool Enabled; public bool Enabled;

View File

@@ -6,11 +6,5 @@ public abstract class SharedWeaponModulesSystem : EntitySystem
{ {
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<WeaponModulesComponent, GunMuzzleFlashAttemptEvent>(OnMuzzleFlashEvent);
}
private void OnMuzzleFlashEvent(EntityUid weapon, WeaponModulesComponent component, ref GunMuzzleFlashAttemptEvent args)
{
args.Cancelled = component.UseEffect;
} }
} }

View File

@@ -6,7 +6,7 @@ namespace Content.Shared._White.WeaponModules;
/// This is used for... /// This is used for...
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class SilencerModuleComponent : WeaponModulesComponent public sealed partial class SilencerModuleComponent : BaseModuleComponent
{ {
[ViewVariables(VVAccess.ReadWrite), DataField] [ViewVariables(VVAccess.ReadWrite), DataField]
public SoundSpecifier? OldSoundGunshot; public SoundSpecifier? OldSoundGunshot;