add: laser, flamehider and silencer module for rifles

This commit is contained in:
CaYpeN1
2024-03-19 10:08:18 +05:00
parent 50f526f98c
commit 47741932ed
9 changed files with 162 additions and 28 deletions

View File

@@ -1,6 +1,11 @@
using Content.Server.Light.Events; using System.Numerics;
using Content.Server.Light.Events;
using Content.Server.Lightning; using Content.Server.Lightning;
using Content.Shared.Light;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
namespace Content.Server._White.WeaponModules; namespace Content.Server._White.WeaponModules;
@@ -8,7 +13,11 @@ namespace Content.Server._White.WeaponModules;
public sealed class WeaponModulesSystem : EntitySystem public sealed class WeaponModulesSystem : EntitySystem
{ {
protected const string ModulesSlot = "gun_modules"; protected const string ModulesSlot = "gun_modules";
[Dependency] private readonly SharedPointLightSystem _lightSystem = default!; [Dependency] private readonly PointLightSystem _lightSystem = default!;
[Dependency] private readonly SharedGunSystem _gunSystem = default!;
SoundSpecifier? oldSoundGunshot;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -22,11 +31,14 @@ public sealed class WeaponModulesSystem : EntitySystem
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
string weapon = Prototype(args.Entity)!.ID; string module = Prototype(args.Entity)!.ID;
EntityUid target = args.Container.Owner; EntityUid weapon = args.Container.Owner;
insertModules(weapon, comp); TryComp<GunComponent>(weapon, out var gunComp);
moduleEffect(weapon, target); oldSoundGunshot = gunComp!.SoundGunshot;
insertModules(module, comp);
moduleEffect(module, weapon);
} }
private void OnEject(EntityUid uid, WeaponModulesComponent comp, EntRemovedFromContainerMessage args) private void OnEject(EntityUid uid, WeaponModulesComponent comp, EntRemovedFromContainerMessage args)
@@ -34,11 +46,11 @@ public sealed class WeaponModulesSystem : EntitySystem
if (ModulesSlot != args.Container.ID) if (ModulesSlot != args.Container.ID)
return; return;
string weapon = Prototype(args.Entity)!.ID; string module = Prototype(args.Entity)!.ID;
EntityUid target = args.Container.Owner; EntityUid weapon = args.Container.Owner;
removeModules(weapon, comp); removeModules(module, comp);
removeModuleEffect(weapon, target); removeModuleEffect(module, weapon);
} }
private void insertModules(string module, WeaponModulesComponent comp) private void insertModules(string module, WeaponModulesComponent comp)
@@ -49,23 +61,52 @@ public sealed class WeaponModulesSystem : EntitySystem
if(comp.Modules.Contains("LightModule")) break; if(comp.Modules.Contains("LightModule")) break;
comp.Modules.Add("LightModule"); comp.Modules.Add("LightModule");
break; break;
case "LaserModule":
if(comp.Modules.Contains("LaserModule")) break;
comp.Modules.Add("LaserModule");
break;
case "FlameHiderModule":
if(comp.Modules.Contains("FlameHiderModule")) break;
comp.Modules.Add("FlameHiderModule");
break;
case "SilencerModule":
if(comp.Modules.Contains("SilencerModule")) break;
comp.Modules.Add("SilencerModule");
break;
} }
} }
private void moduleEffect(string module, EntityUid target) private void moduleEffect(string module, EntityUid weapon)
{ {
switch (module) switch (module)
{ {
case "LightModule": case "LightModule" when HasComp<PointLightComponent>(weapon):
if (HasComp<PointLightComponent>(target))
{ {
_lightSystem.SetEnabled(target, true); _lightSystem.SetEnabled(weapon, true);
break; break;
} }
_lightSystem.TryGetLight(target, out var light); case "LightModule":
_lightSystem.EnsureLight(target);
_lightSystem.SetRadius(target, 2F, light); _lightSystem.TryGetLight(weapon, out var light);
_lightSystem.EnsureLight(weapon).Offset = new Vector2(0, -1);
_lightSystem.SetRadius(weapon, 2F, light);
break;
case "LaserModule":
_gunSystem.setProjectileSpeed(weapon, 40F);
break;
case "FlameHiderModule":
_gunSystem.setUseEffect(weapon, true);
break;
case "SilencerModule":
_gunSystem.setUseEffect(weapon, true);
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
break; break;
} }
} }
@@ -77,19 +118,46 @@ public sealed class WeaponModulesSystem : EntitySystem
case "LightModule": case "LightModule":
comp.Modules.Remove("LightModule"); comp.Modules.Remove("LightModule");
break; break;
case "LaserModule":
comp.Modules.Remove("LaserModule");
break;
case "FlameHiderModule":
comp.Modules.Remove("FlameHiderModule");
break;
case "SilencerModule":
comp.Modules.Remove("SilencerModule");
break;
} }
} }
private void removeModuleEffect(string module, EntityUid target) private void removeModuleEffect(string module, EntityUid weapon)
{ {
switch (module) switch (module)
{ {
case "LightModule": case "LightModule":
if(!HasComp<PointLightComponent>(target)) if (!HasComp<PointLightComponent>(weapon))
break; break;
_lightSystem.TryGetLight(target, out var light); _lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetEnabled(target, false, light); _lightSystem.SetEnabled(weapon, false, light);
break;
case "LaserModule":
if (!HasComp<GunComponent>(weapon))
break;
_gunSystem.setProjectileSpeed(weapon, 25F);
break;
case "FlameHiderModule":
_gunSystem.setUseEffect(weapon, false);
break;
case "SilencerModule":
_gunSystem.setUseEffect(weapon, false);
_gunSystem.setSound(weapon, oldSoundGunshot!);
break; break;
} }
} }

View File

@@ -179,6 +179,12 @@ public sealed partial class GunComponent : Component
[DataField] [DataField]
public bool ResetOnHandSelected = true; public bool ResetOnHandSelected = true;
/// <summary>
/// For flamehider module | WD EDIT
/// </summary>
[DataField, AutoNetworkedField]
public bool canUseEffect;
/// <summary> /// <summary>
/// The base value for how fast the projectile moves. /// The base value for how fast the projectile moves.
/// </summary> /// </summary>

View File

@@ -475,7 +475,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)
{ {
var attemptEv = new GunMuzzleFlashAttemptEvent(); TryComp<GunComponent>(gun, out var gunComponent); // WD EDIT
var attemptEv = new GunMuzzleFlashAttemptEvent(gunComponent!.canUseEffect); // WD EDIT
RaiseLocalEvent(gun, ref attemptEv); RaiseLocalEvent(gun, ref attemptEv);
if (attemptEv.Cancelled) if (attemptEv.Cancelled)
return; return;
@@ -534,8 +536,31 @@ public abstract partial class SharedGunSystem : EntitySystem
Dirty(gun); Dirty(gun);
} }
protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null); public void setProjectileSpeed(EntityUid weapon, float projectileSpeed)
{
TryComp<GunComponent>(weapon, out var gunComponent);
gunComponent!.ProjectileSpeed = projectileSpeed;
RefreshModifiers(weapon);
}
public void setSound(EntityUid weapon, SoundSpecifier sound)
{
TryComp<GunComponent>(weapon, out var gunComponent);
gunComponent!.SoundGunshot = sound;
RefreshModifiers(weapon);
}
public void setUseEffect(EntityUid weapon, bool state)
{
TryComp<GunComponent>(weapon, out var gunComponent);
gunComponent!.canUseEffect = state;
RefreshModifiers(weapon);
}
protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null);
/// <summary> /// <summary>
/// Used for animated effects on the client. /// Used for animated effects on the client.
/// </summary> /// </summary>

Binary file not shown.

View File

@@ -12,7 +12,7 @@
sprite: White/Objects/Weapons/modules.rsi sprite: White/Objects/Weapons/modules.rsi
size: Small size: Small
shape: shape:
- 0,0,1,1 - 0,0,0,0
layers: layers:
- state: base - state: base
map: ["enum.GunVisualLayers.Base"] map: ["enum.GunVisualLayers.Base"]
@@ -23,10 +23,40 @@
# modules # modules
- type: entity - type: entity
id: LightModule id: LightModule
name: "light module for rifle" name: "light module"
parent: BaseModule parent: BaseModule
components: components:
- type: Item - type: Item
- type: Sprite - type: Sprite
state: light state: light
- type: Appearance - type: Appearance
- type: entity
id: LaserModule
name: "laser module"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: laser
- type: Appearance
- type: entity
id: FlameHiderModule
name: "flamehider module"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: flamehider
- type: Appearance
- type: entity
id: SilencerModule
name: "silencer module"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: flamehider
- type: Appearance

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -9,6 +9,11 @@
"states": [ "states": [
{ {
"name": "light" "name": "light"
},
{
"name": "laser"
}, {
"name": "flamehider"
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB