add: new modules, sprite visuals, client and shared logic

This commit is contained in:
CaYpeN1
2024-03-20 21:07:17 +05:00
parent ff681c54d8
commit 796a1f3d5d
18 changed files with 187 additions and 46 deletions

View File

@@ -5,38 +5,34 @@ using Robust.Client.GameObjects;
namespace Content.Client._White.WeaponsModules; namespace Content.Client._White.WeaponsModules;
public sealed partial class WeaponModulesVisuals : EntitySystem public sealed partial class WeaponModulesVisuals : VisualizerSystem<WeaponModulesVisualsComponent>
{ {
private void Initialize()
[Dependency] private readonly PointLightSystem _lightSystem = default!;
protected override void OnAppearanceChange(EntityUid uid, WeaponModulesVisualsComponent component, ref AppearanceChangeEvent args)
{ {
base.Initialize(); base.OnAppearanceChange(uid, component, ref args);
SubscribeLocalEvent<WeaponModulesVisualsComponent, ComponentInit>(ComponentInit); if(args.Sprite == null)
SubscribeLocalEvent<WeaponModulesVisualsComponent, AppearanceChangeEvent>(onModuleVisualChange); return;
}
private void ComponentInit(EntityUid uid, WeaponModulesVisualsComponent component, ComponentInit args) args.Sprite.LayerSetVisible(ModuleVisualState.Module, false);
{
if (!TryComp<SpriteComponent>(uid, out var sprite)) return;
if (sprite.LayerMapTryGet(ModuleVisualState.Laser, out _)) if (AppearanceSystem.TryGetData<string>(uid, ModuleVisualState.Module, out var module, args.Component) && module.Length != 0 && module != "none")
{ {
sprite.LayerSetState(ModuleVisualState.Laser, $"laser"); args.Sprite.LayerSetState(ModuleVisualState.Module, module);
sprite.LayerSetVisible(ModuleVisualState.Laser, false); args.Sprite.LayerSetVisible(ModuleVisualState.Module, true);
}
if (AppearanceSystem.TryGetData(uid, Modules.Light, out var data, args.Component))
{
if (TryComp<PointLightComponent>(uid, out var pointLightComponent))
{
if(!pointLightComponent.Enabled)
return;
_lightSystem.SetMask("/Textures/White/Effects/LightMasks/lightModule.png", pointLightComponent!);
}
} }
} }
private void onModuleVisualChange(EntityUid uid, WeaponModulesVisualsComponent component, ref AppearanceChangeEvent args)
{
var sprite = args.Sprite;
if (sprite == null) return;
if (sprite.LayerMapTryGet(ModuleVisualState.Laser, out _))
{
sprite.LayerSetVisible(ModuleVisualState.Laser, true);
sprite.LayerSetState(ModuleVisualState.Laser, $"laser");
}
}
} }

View File

@@ -1,4 +1,4 @@
using System.Numerics; using Content.Client._White.WeaponsModules;
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems; using Content.Shared.Weapons.Ranged.Systems;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -15,6 +15,7 @@ public sealed class WeaponModulesSystem : EntitySystem
[Dependency] private readonly SharedGunSystem _gunSystem = default!; [Dependency] private readonly SharedGunSystem _gunSystem = default!;
SoundSpecifier? oldSoundGunshot; SoundSpecifier? oldSoundGunshot;
private float oldFireRate;
public override void Initialize() public override void Initialize()
{ {
@@ -34,6 +35,7 @@ public sealed class WeaponModulesSystem : EntitySystem
TryComp<GunComponent>(weapon, out var gunComp); TryComp<GunComponent>(weapon, out var gunComp);
oldSoundGunshot = gunComp!.SoundGunshot; oldSoundGunshot = gunComp!.SoundGunshot;
oldFireRate = gunComp.FireRate;
insertModules(module, comp); insertModules(module, comp);
moduleEffect(module, weapon); moduleEffect(module, weapon);
@@ -74,38 +76,51 @@ public sealed class WeaponModulesSystem : EntitySystem
if(comp.Modules.Contains("SilencerModule")) break; if(comp.Modules.Contains("SilencerModule")) break;
comp.Modules.Add("SilencerModule"); comp.Modules.Add("SilencerModule");
break; break;
case "AcceleratorModule":
if(comp.Modules.Contains("AcceleratorModule")) break;
comp.Modules.Add("AcceleratorModule");
break;
} }
} }
private void moduleEffect(string module, EntityUid weapon) private void moduleEffect(string module, EntityUid weapon)
{ {
TryComp<AppearanceComponent>(weapon, out var appearanceComponent);
switch (module) switch (module)
{ {
case "LightModule" when HasComp<PointLightComponent>(weapon):
{
_lightSystem.SetEnabled(weapon, true);
break;
}
case "LightModule": case "LightModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "light", appearanceComponent);
_lightSystem.EnsureLight(weapon);
_lightSystem.TryGetLight(weapon, out var light); _lightSystem.TryGetLight(weapon, out var light);
_lightSystem.EnsureLight(weapon).Offset = new Vector2(0, -1); Appearance.SetData(weapon, Modules.Light, "none", appearanceComponent);
_lightSystem.SetRadius(weapon, 2F, light);
_lightSystem.SetRadius(weapon, 4F, light);
_lightSystem.SetEnabled(weapon, true, light);
break; break;
case "LaserModule": case "LaserModule":
_gunSystem.setProjectileSpeed(weapon, 40F); Appearance.SetData(weapon, ModuleVisualState.Module, "laser", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 35.5F);
break; break;
case "FlameHiderModule": case "FlameHiderModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent);
_gunSystem.setUseEffect(weapon, true); _gunSystem.setUseEffect(weapon, true);
break; break;
case "SilencerModule": case "SilencerModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent);
_gunSystem.setUseEffect(weapon, true); _gunSystem.setUseEffect(weapon, true);
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg")); _gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
break; break;
case "AcceleratorModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "accelerator", appearanceComponent);
_gunSystem.setFireRate(weapon, 7.5F);
break;
} }
} }
@@ -128,35 +143,46 @@ public sealed class WeaponModulesSystem : EntitySystem
case "SilencerModule": case "SilencerModule":
comp.Modules.Remove("SilencerModule"); comp.Modules.Remove("SilencerModule");
break; break;
case "AcceleratorModule":
comp.Modules.Remove("AcceleratorModule");
break;
} }
} }
private void removeModuleEffect(string module, EntityUid weapon) private void removeModuleEffect(string module, EntityUid weapon)
{ {
TryComp<AppearanceComponent>(weapon, out var appearanceComponent);
switch (module) switch (module)
{ {
case "LightModule": case "LightModule":
if (!HasComp<PointLightComponent>(weapon)) Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
break;
_lightSystem.TryGetLight(weapon, out var light); _lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetEnabled(weapon, false, light); _lightSystem.SetEnabled(weapon, false, light);
break; break;
case "LaserModule": case "LaserModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
if (!HasComp<GunComponent>(weapon)) if (!HasComp<GunComponent>(weapon))
break; break;
_gunSystem.setProjectileSpeed(weapon, 25F); _gunSystem.setProjectileSpeed(weapon, 25F);
break; break;
case "FlameHiderModule": case "FlameHiderModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false); _gunSystem.setUseEffect(weapon, false);
break; break;
case "SilencerModule": case "SilencerModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false); _gunSystem.setUseEffect(weapon, false);
_gunSystem.setSound(weapon, oldSoundGunshot!); _gunSystem.setSound(weapon, oldSoundGunshot!);
break; break;
case "AcceleratorModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setFireRate(weapon, oldFireRate);
break;
} }
} }
} }

View File

@@ -544,6 +544,14 @@ public abstract partial class SharedGunSystem : EntitySystem
RefreshModifiers(weapon); RefreshModifiers(weapon);
} }
public void setFireRate(EntityUid weapon, float fireRate)
{
TryComp<GunComponent>(weapon, out var gunComponent);
gunComponent!.FireRate = fireRate;
RefreshModifiers(weapon);
}
public void setSound(EntityUid weapon, SoundSpecifier sound) public void setSound(EntityUid weapon, SoundSpecifier sound)
{ {
TryComp<GunComponent>(weapon, out var gunComponent); TryComp<GunComponent>(weapon, out var gunComponent);

View File

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

View File

@@ -72,7 +72,8 @@
- state: mag-0 - state: mag-0
map: [ "enum.GunVisualLayers.Mag" ] map: [ "enum.GunVisualLayers.Mag" ]
- state: laser - state: laser
map: [ "enum.ModuleVisualState.Laser" ] sprite: White/Objects/Weapons/modulesOnWeapon.rsi
map: [ "enum.ModuleVisualState.Module" ]
- type: Gun - type: Gun
fireRate: 5 fireRate: 5
soundGunshot: soundGunshot:
@@ -114,6 +115,9 @@
steps: 1 steps: 1
zeroVisible: true zeroVisible: true
- type: WeaponModulesVisuals - type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
- type: Appearance - type: Appearance
- type: entity - type: entity
@@ -172,6 +176,9 @@
map: [ "enum.GunVisualLayers.Base" ] map: [ "enum.GunVisualLayers.Base" ]
- state: mag-0 - state: mag-0
map: [ "enum.GunVisualLayers.Mag" ] map: [ "enum.GunVisualLayers.Mag" ]
- state: laser
sprite: White/Objects/Weapons/modulesOnWeapon.rsi
map: [ "enum.ModuleVisualState.Module" ]
- type: Clothing - type: Clothing
sprite: Objects/Weapons/Guns/Rifles/lecter.rsi sprite: Objects/Weapons/Guns/Rifles/lecter.rsi
- type: Gun - type: Gun
@@ -195,14 +202,25 @@
whitelist: whitelist:
tags: tags:
- CartridgeRifle - CartridgeRifle
gun_modules:
name: Modules
priority: 2
whitelist:
tags:
- BaseModule
- type: ContainerContainer - type: ContainerContainer
containers: containers:
gun_magazine: !type:ContainerSlot gun_magazine: !type:ContainerSlot
gun_chamber: !type:ContainerSlot gun_chamber: !type:ContainerSlot
gun_modules: !type:ContainerSlot
- type: MagazineVisuals - type: MagazineVisuals
magState: mag magState: mag
steps: 1 steps: 1
zeroVisible: true zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
- type: Appearance - type: Appearance
- type: entity - type: entity
@@ -229,3 +247,9 @@
whitelist: whitelist:
tags: tags:
- CartridgeRifle - CartridgeRifle
gun_modules:
name: Modules
priority: 2
whitelist:
tags:
- BaseModule

View File

@@ -117,6 +117,9 @@
map: ["enum.GunVisualLayers.Base"] map: ["enum.GunVisualLayers.Base"]
- state: mag-0 - state: mag-0
map: ["enum.GunVisualLayers.Mag"] map: ["enum.GunVisualLayers.Mag"]
- state: laser
sprite: White/Objects/Weapons/modulesOnWeapon.rsi
map: [ "enum.ModuleVisualState.Module" ]
- type: Clothing - type: Clothing
sprite: Objects/Weapons/Guns/SMGs/drozd.rsi sprite: Objects/Weapons/Guns/SMGs/drozd.rsi
- type: Gun - type: Gun
@@ -126,6 +129,7 @@
path: /Audio/Weapons/Guns/Gunshots/atreides.ogg path: /Audio/Weapons/Guns/Gunshots/atreides.ogg
availableModes: availableModes:
- FullAuto - FullAuto
- type: WeaponModules
- type: ItemSlots - type: ItemSlots
slots: slots:
gun_magazine: gun_magazine:
@@ -144,10 +148,25 @@
whitelist: whitelist:
tags: tags:
- CartridgePistol - CartridgePistol
gun_modules:
name: Modules
priority: 2
whitelist:
tags:
- BaseModule
- type: ContainerContainer
containers:
gun_magazine: !type:ContainerSlot
gun_chamber: !type:ContainerSlot
gun_modules: !type:ContainerSlot
- type: MagazineVisuals - type: MagazineVisuals
magState: mag magState: mag
steps: 1 steps: 1
zeroVisible: true zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
- type: Appearance - type: Appearance
- type: entity - type: entity
@@ -216,6 +235,9 @@
- state: mag-unshaded-0 - state: mag-unshaded-0
map: ["enum.GunVisualLayers.MagUnshaded"] map: ["enum.GunVisualLayers.MagUnshaded"]
shader: unshaded shader: unshaded
- state: laser
sprite: White/Objects/Weapons/modulesOnWeapon.rsi
map: [ "enum.ModuleVisualState.Module" ]
- type: Clothing - type: Clothing
sprite: Objects/Weapons/Guns/SMGs/wt550.rsi sprite: Objects/Weapons/Guns/SMGs/wt550.rsi
- type: ChamberMagazineAmmoProvider - type: ChamberMagazineAmmoProvider
@@ -225,6 +247,7 @@
selectedMode: FullAuto selectedMode: FullAuto
availableModes: availableModes:
- FullAuto - FullAuto
- type: WeaponModules
- type: ItemSlots - type: ItemSlots
slots: slots:
gun_magazine: gun_magazine:
@@ -243,10 +266,24 @@
whitelist: whitelist:
tags: tags:
- CartridgePistol - CartridgePistol
gun_modules:
name: Modules
priority: 2
whitelist:
tags:
- BaseModule
- type: ContainerContainer
containers:
gun_magazine: !type:ContainerSlot
gun_chamber: !type:ContainerSlot
- type: MagazineVisuals - type: MagazineVisuals
magState: mag magState: mag
steps: 6 steps: 6
zeroVisible: true zeroVisible: true
- type: WeaponModulesVisuals
- type: PointLight
enabled: false
autoRot: true
- type: Appearance - type: Appearance
# Rubber # Rubber
@@ -274,6 +311,12 @@
whitelist: whitelist:
tags: tags:
- CartridgePistol - CartridgePistol
gun_modules:
name: Modules
priority: 2
whitelist:
tags:
- BaseModule
- type: entity - type: entity
name: Vector name: Vector

View File

@@ -59,4 +59,14 @@
- type: Item - type: Item
- type: Sprite - type: Sprite
state: silencer state: silencer
- type: Appearance
- type: entity
id: AcceleratorModule
name: "accelerator module"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: accelerator
- type: Appearance - type: Appearance

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -19,9 +19,6 @@
{ {
"name": "mag-0" "name": "mag-0"
}, },
{
"name": "laser"
},
{ {
"name": "inhand-left", "name": "inhand-left",
"directions": 4 "directions": 4

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -18,6 +18,9 @@
}, },
{ {
"name": "silencer" "name": "silencer"
},
{
"name": "accelerator"
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

View File

Before

Width:  |  Height:  |  Size: 152 B

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

View File

@@ -0,0 +1,26 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "made by CaypenNow",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "laser"
},
{
"name": "light"
},
{
"name": "flamehider"
},
{
"name": "silencer"
},
{
"name": "accelerator"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B