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;
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);
SubscribeLocalEvent<WeaponModulesVisualsComponent, AppearanceChangeEvent>(onModuleVisualChange);
}
if(args.Sprite == null)
return;
private void ComponentInit(EntityUid uid, WeaponModulesVisualsComponent component, ComponentInit args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite)) return;
args.Sprite.LayerSetVisible(ModuleVisualState.Module, false);
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");
sprite.LayerSetVisible(ModuleVisualState.Laser, false);
args.Sprite.LayerSetState(ModuleVisualState.Module, module);
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.Systems;
using Robust.Server.GameObjects;
@@ -15,6 +15,7 @@ public sealed class WeaponModulesSystem : EntitySystem
[Dependency] private readonly SharedGunSystem _gunSystem = default!;
SoundSpecifier? oldSoundGunshot;
private float oldFireRate;
public override void Initialize()
{
@@ -34,6 +35,7 @@ public sealed class WeaponModulesSystem : EntitySystem
TryComp<GunComponent>(weapon, out var gunComp);
oldSoundGunshot = gunComp!.SoundGunshot;
oldFireRate = gunComp.FireRate;
insertModules(module, comp);
moduleEffect(module, weapon);
@@ -74,38 +76,51 @@ public sealed class WeaponModulesSystem : EntitySystem
if(comp.Modules.Contains("SilencerModule")) break;
comp.Modules.Add("SilencerModule");
break;
case "AcceleratorModule":
if(comp.Modules.Contains("AcceleratorModule")) break;
comp.Modules.Add("AcceleratorModule");
break;
}
}
private void moduleEffect(string module, EntityUid weapon)
{
TryComp<AppearanceComponent>(weapon, out var appearanceComponent);
switch (module)
{
case "LightModule" when HasComp<PointLightComponent>(weapon):
{
_lightSystem.SetEnabled(weapon, true);
break;
}
case "LightModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "light", appearanceComponent);
_lightSystem.EnsureLight(weapon);
_lightSystem.TryGetLight(weapon, out var light);
_lightSystem.EnsureLight(weapon).Offset = new Vector2(0, -1);
_lightSystem.SetRadius(weapon, 2F, light);
Appearance.SetData(weapon, Modules.Light, "none", appearanceComponent);
_lightSystem.SetRadius(weapon, 4F, light);
_lightSystem.SetEnabled(weapon, true, light);
break;
case "LaserModule":
_gunSystem.setProjectileSpeed(weapon, 40F);
Appearance.SetData(weapon, ModuleVisualState.Module, "laser", appearanceComponent);
_gunSystem.setProjectileSpeed(weapon, 35.5F);
break;
case "FlameHiderModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "flamehider", appearanceComponent);
_gunSystem.setUseEffect(weapon, true);
break;
case "SilencerModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "silencer", appearanceComponent);
_gunSystem.setUseEffect(weapon, true);
_gunSystem.setSound(weapon, new SoundPathSpecifier("/Audio/White/Weapons/Modules/silence.ogg"));
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":
comp.Modules.Remove("SilencerModule");
break;
case "AcceleratorModule":
comp.Modules.Remove("AcceleratorModule");
break;
}
}
private void removeModuleEffect(string module, EntityUid weapon)
{
TryComp<AppearanceComponent>(weapon, out var appearanceComponent);
switch (module)
{
case "LightModule":
if (!HasComp<PointLightComponent>(weapon))
break;
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_lightSystem.TryGetLight(weapon, out var light);
_lightSystem.SetEnabled(weapon, false, light);
break;
case "LaserModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
if (!HasComp<GunComponent>(weapon))
break;
_gunSystem.setProjectileSpeed(weapon, 25F);
break;
case "FlameHiderModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false);
break;
case "SilencerModule":
Appearance.SetData(weapon, ModuleVisualState.Module, "none", appearanceComponent);
_gunSystem.setUseEffect(weapon, false);
_gunSystem.setSound(weapon, oldSoundGunshot!);
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);
}
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)
{
TryComp<GunComponent>(weapon, out var gunComponent);

View File

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

View File

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

View File

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

View File

@@ -59,4 +59,14 @@
- type: Item
- type: Sprite
state: silencer
- type: Appearance
- type: entity
id: AcceleratorModule
name: "accelerator module"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: accelerator
- 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": "laser"
},
{
"name": "inhand-left",
"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": "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