add: base system + light module

This commit is contained in:
CaYpeN1
2024-03-18 01:25:09 +05:00
parent 0377fc7091
commit 407427b31b
7 changed files with 172 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
namespace Content.Server._White.WeaponModules;
/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class WeaponModulesComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public List<string?> Modules = new();
}

View File

@@ -0,0 +1,96 @@
using Content.Server.Light.Events;
using Content.Server.Lightning;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
namespace Content.Server._White.WeaponModules;
public sealed class WeaponModulesSystem : EntitySystem
{
protected const string ModulesSlot = "gun_modules";
[Dependency] private readonly SharedPointLightSystem _lightSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WeaponModulesComponent, EntInsertedIntoContainerMessage>(OnInsert);
SubscribeLocalEvent<WeaponModulesComponent, EntRemovedFromContainerMessage>(OnEject);
}
private void OnInsert(EntityUid uid, WeaponModulesComponent comp, EntInsertedIntoContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
string weapon = Prototype(args.Entity)!.ID;
EntityUid target = args.Container.Owner;
insertModules(weapon, comp);
moduleEffect(weapon, target);
}
private void OnEject(EntityUid uid, WeaponModulesComponent comp, EntRemovedFromContainerMessage args)
{
if (ModulesSlot != args.Container.ID)
return;
string weapon = Prototype(args.Entity)!.ID;
EntityUid target = args.Container.Owner;
removeModules(weapon, comp);
removeModuleEffect(weapon, target);
}
private void insertModules(string module, WeaponModulesComponent comp)
{
switch (module)
{
case "LightModule":
if(comp.Modules.Contains("LightModule")) break;
comp.Modules.Add("LightModule");
break;
}
}
private void moduleEffect(string module, EntityUid target)
{
switch (module)
{
case "LightModule":
if (HasComp<PointLightComponent>(target))
{
_lightSystem.SetEnabled(target, true);
break;
}
_lightSystem.TryGetLight(target, out var light);
_lightSystem.EnsureLight(target);
_lightSystem.SetRadius(target, 2F, light);
break;
}
}
private void removeModules(string module, WeaponModulesComponent comp)
{
switch (module)
{
case "LightModule":
comp.Modules.Remove("LightModule");
break;
}
}
private void removeModuleEffect(string module, EntityUid target)
{
switch (module)
{
case "LightModule":
if(!HasComp<PointLightComponent>(target))
break;
_lightSystem.TryGetLight(target, out var light);
_lightSystem.SetEnabled(target, false, light);
break;
}
}
}

View File

@@ -15,6 +15,7 @@
- Back
- suitStorage
- type: AmmoCounter
- type: WeaponModules
- type: Gun
fireRate: 5
selectedMode: FullAuto
@@ -32,7 +33,7 @@
startingItem: MagazineLightRifle
insertSound: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
ejectSound: /Audio/Weapons/Guns/MagOut/batrifle_magout.ogg
priority: 2
priority: 3
whitelist:
tags:
- MagazineLightRifle
@@ -43,10 +44,17 @@
whitelist:
tags:
- CartridgeLightRifle
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: StaticPrice
price: 500
@@ -88,10 +96,17 @@
whitelist:
tags:
- CartridgeLightRifle
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

View File

@@ -0,0 +1,32 @@
- type: entity
id: BaseModule
parent: BaseItem
abstract: true
components:
- type: Sprite
sprite: White/Objects/Weapons/modules.rsi
- type: Tag
tags:
- BaseModule
- type: Item
sprite: White/Objects/Weapons/modules.rsi
size: Small
shape:
- 0,0,1,1
layers:
- state: base
map: ["enum.GunVisualLayers.Base"]
- state: mag-1
map: ["enum.GunVisualLayers.Mag"]
- type: Appearance
# modules
- type: entity
id: LightModule
name: "light module for rifle"
parent: BaseModule
components:
- type: Item
- type: Sprite
state: light
- type: Appearance

View File

@@ -54,3 +54,6 @@
- type: Tag
id: MindSlave
- type: Tag
id: BaseModule

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Maked by CaypenNow",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "light"
}
]
}