change components, remake system

This commit is contained in:
CaYpeN1
2024-03-22 16:27:51 +05:00
parent 2b8d88d707
commit 4b79f1e2e0
14 changed files with 239 additions and 161 deletions

View File

@@ -1,16 +1,17 @@
using Content.Client.Weapons.Ranged.Components;
using Content.Shared._White.WeaponModules;
using Content.Shared.Rounding;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Client.GameObjects;
namespace Content.Client._White.WeaponsModules;
public sealed partial class WeaponModulesVisuals : VisualizerSystem<WeaponModulesVisualsComponent>
public sealed partial class WeaponModulesVisuals : VisualizerSystem<WeaponModulesComponent>
{
[Dependency] private readonly PointLightSystem _lightSystem = default!;
protected override void OnAppearanceChange(EntityUid uid, WeaponModulesVisualsComponent component, ref AppearanceChangeEvent args)
protected override void OnAppearanceChange(EntityUid uid, WeaponModulesComponent component, ref AppearanceChangeEvent args)
{
base.OnAppearanceChange(uid, component, ref args);

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,13 @@
namespace Content.Server._White.WeaponModules;
using Robust.Shared.Audio;
namespace Content.Server._White.WeaponModules;
/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class SilencerModuleComponent : Component
public sealed partial class SilencerModuleComponent : Shared._White.WeaponModules.WeaponModulesComponent
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public SoundSpecifier? OldSoundGunshot;
}

View File

@@ -1,11 +0,0 @@
namespace Content.Server._White.WeaponModules;
/// <summary>
/// Base Module Component
/// </summary>
[RegisterComponent]
public partial class WeaponModulesComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public List<EntityUid> Modules = new();
}

View File

@@ -1,10 +1,13 @@
using System.Linq;
using Content.Client._White.WeaponsModules;
using Content.Shared._White.Chemistry;
using Content.Shared._White.WeaponModules;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
namespace Content.Server._White.WeaponModules;
@@ -15,130 +18,200 @@ public sealed class WeaponModulesSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
[Dependency] private readonly SharedGunSystem _gunSystem = default!;
SoundSpecifier? oldSoundGunshot;
private float oldFireRate;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WeaponModulesComponent, EntInsertedIntoContainerMessage>(OnInsert);
SubscribeLocalEvent<WeaponModulesComponent, EntRemovedFromContainerMessage>(OnEject);
SubscribeLocalEvent<LightModuleComponent, EntGotInsertedIntoContainerMessage>(LightModuleOnInsert);
SubscribeLocalEvent<LightModuleComponent, EntGotRemovedFromContainerMessage>(LightModuleOnEject);
SubscribeLocalEvent<LaserModuleComponent, EntGotInsertedIntoContainerMessage>(LaserModuleOnInsert);
SubscribeLocalEvent<LaserModuleComponent, EntGotRemovedFromContainerMessage>(LaserModuleOnEject);
SubscribeLocalEvent<FlameHiderModuleComponent, EntGotInsertedIntoContainerMessage>(FlameHiderModuleOnInsert);
SubscribeLocalEvent<FlameHiderModuleComponent, EntGotRemovedFromContainerMessage>(FlameHiderModuleOnEject);
SubscribeLocalEvent<SilencerModuleComponent, EntGotInsertedIntoContainerMessage>(SilencerModuleOnInsert);
SubscribeLocalEvent<SilencerModuleComponent, EntGotRemovedFromContainerMessage>(SilencerModuleOnEject);
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotInsertedIntoContainerMessage>(AcceleratorModuleOnInsert);
SubscribeLocalEvent<AcceleratorModuleComponent, EntGotRemovedFromContainerMessage>(AcceleratorModuleOnEject);
}
private void OnInsert(EntityUid uid, WeaponModulesComponent comp, EntInsertedIntoContainerMessage args)
#region InsertModules
private void LightModuleOnInsert(EntityUid module, LightModuleComponent component, EntGotInsertedIntoContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
EntityUid module = args.Entity;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner;
if (TryComp<GunComponent>(weapon, out var gunComp))
{
oldSoundGunshot = gunComp.SoundGunshot;
oldFireRate = gunComp.FireRate;
}
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
InsertModules(module, comp);
ModuleEffect(module, weapon);
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "light", appearanceComponent);
_lightSystem.EnsureLight(weapon);
_lightSystem.TryGetLight(weapon, out var light);
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
_lightSystem.SetRadius(weapon, 4F, light);
_lightSystem.SetEnabled(weapon, true, light);
}
private void OnEject(EntityUid uid, WeaponModulesComponent comp, EntRemovedFromContainerMessage args)
private void LaserModuleOnInsert(EntityUid module, LaserModuleComponent component, EntGotInsertedIntoContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
EntityUid module = args.Entity;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner;
RemoveModules(module, comp);
RemoveModuleEffect(module, weapon);
}
private void InsertModules(EntityUid module, WeaponModulesComponent comp)
{
if(!comp.Modules.Contains(module))
comp.Modules.Add(module);
}
private void ModuleEffect(EntityUid module, EntityUid weapon)
{
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
switch (module)
{
case "LightModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "light", appearanceComponent);
_lightSystem.EnsureLight(weapon);
_lightSystem.TryGetLight(weapon, out var light);
_appearanceSystem.SetData(weapon, Modules.Light, "none", appearanceComponent);
_lightSystem.SetRadius(weapon, 4F, light);
_lightSystem.SetEnabled(weapon, true, light);
break;
case "LaserModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "laser", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 35.5F);
break;
case "FlameHiderModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent);
_gunSystem.setUseEffect(weapon, true);
break;
case "SilencerModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent);
_gunSystem.setUseEffect(weapon, true);
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
break;
case "AcceleratorModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "accelerator", appearanceComponent);
_gunSystem.setFireRate(weapon, 7.5F);
break;
}
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "laser", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 35.5F);
}
private void RemoveModules(EntityUid module, WeaponModulesComponent comp)
private void FlameHiderModuleOnInsert(EntityUid module, FlameHiderModuleComponent component, EntGotInsertedIntoContainerMessage args)
{
if(comp.Modules.Contains(module))
comp.Modules.Remove(module);
}
if (ModulesSlot != args.Container.ID)
return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner;
private void RemoveModuleEffect(EntityUid module, EntityUid weapon)
{
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
switch (module)
{
case "LightModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetEnabled(weapon, false, light);
break;
case "LaserModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 25F);
break;
case "FlameHiderModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false);
break;
case "SilencerModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false);
_gunSystem.setSound(weapon, oldSoundGunshot!);
break;
case "AcceleratorModule":
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setFireRate(weapon, oldFireRate);
break;
}
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent);
component.UseEffect = true;
Dirty(module, component);
}
private void SilencerModuleOnInsert(EntityUid module, SilencerModuleComponent component, EntGotInsertedIntoContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
if (!TryComp<GunComponent>(weapon, out var gunComp)) return;
component.OldSoundGunshot = gunComp.SoundGunshot;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent);
component.UseEffect = true;
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
Dirty(module, component);
}
private void AcceleratorModuleOnInsert(EntityUid module, AcceleratorModuleComponent component, EntGotInsertedIntoContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(!component.Modules.Contains(module))
component.Modules.Add(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "accelerator", appearanceComponent);
_gunSystem.setFireRate(weapon, 7.5F);
}
#endregion
#region EjectModules
private void LightModuleOnEject(EntityUid module, LightModuleComponent component, EntGotRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetEnabled(weapon, false, light);
}
private void LaserModuleOnEject(EntityUid module, LaserModuleComponent component, EntGotRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 25F);
}
private void FlameHiderModuleOnEject(EntityUid module, FlameHiderModuleComponent component, EntGotRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
component.UseEffect = false;
Dirty(module, component);
}
private void SilencerModuleOnEject(EntityUid module, SilencerModuleComponent component, EntGotRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
component.UseEffect = false;
_gunSystem.setSound(weapon, component.OldSoundGunshot!);
Dirty(module, component);
}
private void AcceleratorModuleOnEject(EntityUid module, AcceleratorModuleComponent component, EntGotRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
if(component.Modules.Contains(module))
component.Modules.Remove(module);
EntityUid weapon = args.Container.Owner;
if(!TryComp<AppearanceComponent>(weapon, out var appearanceComponent)) return;
_appearanceSystem.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setFireRate(weapon, component.OldFireRate);
}
#endregion
}

View File

@@ -179,12 +179,6 @@ public sealed partial class GunComponent : Component
[DataField]
public bool ResetOnHandSelected = true;
/// <summary>
/// For flamehider module | WD EDIT
/// </summary>
[DataField, AutoNetworkedField]
public bool canUseEffect;
/// <summary>
/// The base value for how fast the projectile moves.
/// </summary>
@@ -237,7 +231,7 @@ public sealed partial class GunComponent : Component
// WD START
public EntityUid? Target;
[DataField("forceThrowingAngle")]
[ViewVariables(VVAccess.ReadWrite)]
public bool ForceThrowingAngle;

View File

@@ -476,9 +476,7 @@ public abstract partial class SharedGunSystem : EntitySystem
protected void MuzzleFlash(EntityUid gun, AmmoComponent component, EntityUid? user = null)
{
TryComp<GunComponent>(gun, out var gunComponent); // WD EDIT
var attemptEv = new GunMuzzleFlashAttemptEvent(gunComponent!.canUseEffect); // WD EDIT
var attemptEv = new GunMuzzleFlashAttemptEvent();
RaiseLocalEvent(gun, ref attemptEv);
if (attemptEv.Cancelled)
return;
@@ -560,14 +558,6 @@ public abstract partial class SharedGunSystem : EntitySystem
RefreshModifiers(weapon);
}
public void setUseEffect(EntityUid weapon, bool state)
{
TryComp<GunComponent>(weapon, out var gunComponent);
gunComponent!.canUseEffect = state;
RefreshModifiers(weapon);
}
// WD EDIT END
protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null);
/// <summary>

View File

@@ -0,0 +1,17 @@
using Content.Shared.Weapons.Ranged.Events;
namespace Content.Shared._White.WeaponModules;
public abstract class SharedWeaponModulesSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<WeaponModulesComponent, GunMuzzleFlashAttemptEvent>(OnMuzzleFlashEvent);
}
private void OnMuzzleFlashEvent(EntityUid weapon, WeaponModulesComponent component, ref GunMuzzleFlashAttemptEvent args)
{
args.Cancelled = component.UseEffect;
}
}

View File

@@ -0,0 +1,29 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared._White.WeaponModules;
/// <summary>
/// Base Module Component
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public partial class WeaponModulesComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public List<EntityUid> Modules = new();
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool UseEffect;
}
[Serializable, NetSerializable]
public enum ModuleVisualState : byte
{
Module
}
[Serializable, NetSerializable]
public enum Modules : byte
{
Light
}

View File

@@ -1,23 +0,0 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Client._White.WeaponsModules;
/// <inheritdoc/>
[RegisterComponent]
public sealed partial class WeaponModulesVisualsComponent : Component
{
[DataField] public string? state;
}
[Serializable, NetSerializable]
public enum ModuleVisualState : byte
{
Module
}
[Serializable, NetSerializable]
public enum Modules : byte
{
Light
}

View File

@@ -28,6 +28,7 @@
parent: BaseModule
components:
- type: Item
- type: LightModule
- type: Sprite
state: light
- type: Appearance
@@ -39,6 +40,7 @@
parent: BaseModule
components:
- type: Item
- type: LaserModule
- type: Sprite
state: laser
- type: Appearance
@@ -50,6 +52,7 @@
parent: BaseModule
components:
- type: Item
- type: FlameHiderModule
- type: Sprite
state: flamehider
- type: Appearance
@@ -61,6 +64,7 @@
parent: BaseModule
components:
- type: Item
- type: SilencerModule
- type: Sprite
state: silencer
- type: Appearance
@@ -72,6 +76,7 @@
parent: BaseModule
components:
- type: Item
- type: AcceleratorModule
- type: Sprite
state: accelerator
- type: Appearance