add: laser, flamehider and silencer module for rifles
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
using Content.Server.Light.Events;
|
||||
using System.Numerics;
|
||||
using Content.Server.Light.Events;
|
||||
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.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server._White.WeaponModules;
|
||||
@@ -8,7 +13,11 @@ namespace Content.Server._White.WeaponModules;
|
||||
public sealed class WeaponModulesSystem : EntitySystem
|
||||
{
|
||||
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()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -22,11 +31,14 @@ public sealed class WeaponModulesSystem : EntitySystem
|
||||
if (ModulesSlot != args.Container.ID)
|
||||
return;
|
||||
|
||||
string weapon = Prototype(args.Entity)!.ID;
|
||||
EntityUid target = args.Container.Owner;
|
||||
string module = Prototype(args.Entity)!.ID;
|
||||
EntityUid weapon = args.Container.Owner;
|
||||
|
||||
insertModules(weapon, comp);
|
||||
moduleEffect(weapon, target);
|
||||
TryComp<GunComponent>(weapon, out var gunComp);
|
||||
oldSoundGunshot = gunComp!.SoundGunshot;
|
||||
|
||||
insertModules(module, comp);
|
||||
moduleEffect(module, weapon);
|
||||
}
|
||||
|
||||
private void OnEject(EntityUid uid, WeaponModulesComponent comp, EntRemovedFromContainerMessage args)
|
||||
@@ -34,11 +46,11 @@ public sealed class WeaponModulesSystem : EntitySystem
|
||||
if (ModulesSlot != args.Container.ID)
|
||||
return;
|
||||
|
||||
string weapon = Prototype(args.Entity)!.ID;
|
||||
EntityUid target = args.Container.Owner;
|
||||
string module = Prototype(args.Entity)!.ID;
|
||||
EntityUid weapon = args.Container.Owner;
|
||||
|
||||
removeModules(weapon, comp);
|
||||
removeModuleEffect(weapon, target);
|
||||
removeModules(module, comp);
|
||||
removeModuleEffect(module, weapon);
|
||||
}
|
||||
|
||||
private void insertModules(string module, WeaponModulesComponent comp)
|
||||
@@ -49,23 +61,52 @@ public sealed class WeaponModulesSystem : EntitySystem
|
||||
if(comp.Modules.Contains("LightModule")) break;
|
||||
comp.Modules.Add("LightModule");
|
||||
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)
|
||||
{
|
||||
case "LightModule":
|
||||
if (HasComp<PointLightComponent>(target))
|
||||
{
|
||||
_lightSystem.SetEnabled(target, true);
|
||||
break;
|
||||
}
|
||||
case "LightModule" when HasComp<PointLightComponent>(weapon):
|
||||
{
|
||||
_lightSystem.SetEnabled(weapon, true);
|
||||
break;
|
||||
}
|
||||
|
||||
_lightSystem.TryGetLight(target, out var light);
|
||||
_lightSystem.EnsureLight(target);
|
||||
_lightSystem.SetRadius(target, 2F, light);
|
||||
case "LightModule":
|
||||
|
||||
_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;
|
||||
}
|
||||
}
|
||||
@@ -77,19 +118,46 @@ public sealed class WeaponModulesSystem : EntitySystem
|
||||
case "LightModule":
|
||||
comp.Modules.Remove("LightModule");
|
||||
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)
|
||||
{
|
||||
case "LightModule":
|
||||
if(!HasComp<PointLightComponent>(target))
|
||||
if (!HasComp<PointLightComponent>(weapon))
|
||||
break;
|
||||
|
||||
_lightSystem.TryGetLight(target, out var light);
|
||||
_lightSystem.SetEnabled(target, false, light);
|
||||
_lightSystem.TryGetLight(weapon, out var 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,12 @@ 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>
|
||||
|
||||
@@ -475,7 +475,9 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
|
||||
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);
|
||||
if (attemptEv.Cancelled)
|
||||
return;
|
||||
@@ -534,8 +536,31 @@ public abstract partial class SharedGunSystem : EntitySystem
|
||||
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>
|
||||
/// Used for animated effects on the client.
|
||||
/// </summary>
|
||||
|
||||
BIN
Resources/Audio/White/Weapons/Modules/silence.ogg
Normal file
BIN
Resources/Audio/White/Weapons/Modules/silence.ogg
Normal file
Binary file not shown.
@@ -12,7 +12,7 @@
|
||||
sprite: White/Objects/Weapons/modules.rsi
|
||||
size: Small
|
||||
shape:
|
||||
- 0,0,1,1
|
||||
- 0,0,0,0
|
||||
layers:
|
||||
- state: base
|
||||
map: ["enum.GunVisualLayers.Base"]
|
||||
@@ -23,10 +23,40 @@
|
||||
# modules
|
||||
- type: entity
|
||||
id: LightModule
|
||||
name: "light module for rifle"
|
||||
name: "light module"
|
||||
parent: BaseModule
|
||||
components:
|
||||
- type: Item
|
||||
- type: Sprite
|
||||
state: light
|
||||
- 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 |
BIN
Resources/Textures/White/Objects/Weapons/modules.rsi/laser.png
Normal file
BIN
Resources/Textures/White/Objects/Weapons/modules.rsi/laser.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -9,6 +9,11 @@
|
||||
"states": [
|
||||
{
|
||||
"name": "light"
|
||||
},
|
||||
{
|
||||
"name": "laser"
|
||||
}, {
|
||||
"name": "flamehider"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
Reference in New Issue
Block a user