From 407427b31b27dd5db97ff338b45d2e20dff4fed0 Mon Sep 17 00:00:00 2001 From: CaYpeN1 Date: Mon, 18 Mar 2024 01:25:09 +0500 Subject: [PATCH] add: base system + light module --- .../WeaponModules/WeaponModulesComponent.cs | 11 ++ .../WeaponModules/WeaponModulesSystem.cs | 96 ++++++++++++++++++ .../Objects/Weapons/Guns/Rifles/rifles.yml | 17 +++- .../Objects/Weapons/Guns/Modules/modules.yml | 32 ++++++ Resources/Prototypes/White/tags.yml | 3 + .../Objects/Weapons/modules.rsi/light.png | Bin 0 -> 2788 bytes .../Objects/Weapons/modules.rsi/meta.json | 14 +++ 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 Content.Server/_White/WeaponModules/WeaponModulesComponent.cs create mode 100644 Content.Server/_White/WeaponModules/WeaponModulesSystem.cs create mode 100644 Resources/Prototypes/White/Entities/Objects/Weapons/Guns/Modules/modules.yml create mode 100644 Resources/Textures/White/Objects/Weapons/modules.rsi/light.png create mode 100644 Resources/Textures/White/Objects/Weapons/modules.rsi/meta.json diff --git a/Content.Server/_White/WeaponModules/WeaponModulesComponent.cs b/Content.Server/_White/WeaponModules/WeaponModulesComponent.cs new file mode 100644 index 0000000000..479e8a858d --- /dev/null +++ b/Content.Server/_White/WeaponModules/WeaponModulesComponent.cs @@ -0,0 +1,11 @@ +namespace Content.Server._White.WeaponModules; + +/// +/// This is used for... +/// +[RegisterComponent] +public sealed partial class WeaponModulesComponent : Component +{ + [ViewVariables(VVAccess.ReadWrite)] + public List Modules = new(); +} diff --git a/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs new file mode 100644 index 0000000000..bb9114489a --- /dev/null +++ b/Content.Server/_White/WeaponModules/WeaponModulesSystem.cs @@ -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(OnInsert); + SubscribeLocalEvent(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(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(target)) + break; + + _lightSystem.TryGetLight(target, out var light); + _lightSystem.SetEnabled(target, false, light); + break; + } + } +} diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 82c0770c7f..9baf951015 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -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 diff --git a/Resources/Prototypes/White/Entities/Objects/Weapons/Guns/Modules/modules.yml b/Resources/Prototypes/White/Entities/Objects/Weapons/Guns/Modules/modules.yml new file mode 100644 index 0000000000..be8ce29fbd --- /dev/null +++ b/Resources/Prototypes/White/Entities/Objects/Weapons/Guns/Modules/modules.yml @@ -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 \ No newline at end of file diff --git a/Resources/Prototypes/White/tags.yml b/Resources/Prototypes/White/tags.yml index 466a1ddb17..73d3311562 100644 --- a/Resources/Prototypes/White/tags.yml +++ b/Resources/Prototypes/White/tags.yml @@ -54,3 +54,6 @@ - type: Tag id: MindSlave + +- type: Tag + id: BaseModule diff --git a/Resources/Textures/White/Objects/Weapons/modules.rsi/light.png b/Resources/Textures/White/Objects/Weapons/modules.rsi/light.png new file mode 100644 index 0000000000000000000000000000000000000000..347e76a4b29de686039962bc0cebb13ea3efb4a1 GIT binary patch literal 2788 zcmVuJ@VVD_U zC<6{NG_fI~0ue<-1QkJoA_k0xBC#Thg@9ne9*`iQ#9$OrQF$}6R&?d%y_c8YA7_1Q zpS|}zXYYO1x&V;8{kgn!SPFnNo`4_X z6{c}T{8k*B#$jdxfFg<9uYy1K45IaYvHg`_dOZM)Sy63ve6hvv1)yUy0P^?0*fb9UASvow z`@mQCp^4`uNg&9uGcn1|&Nk+9SjOUl{-OWr@Hh0;_l(8q{wNRKos+;6rV8ldy0Owz z(}jF`W(JeRp&R{qi2rfmU!TJ;gp(Kmm5I1s5m_f-n#TRsj}B0%?E` zvOzxB2#P=n*a3EfYETOrKoe*ICqM@{4K9Go;5xVgZi5G41dM~{UdP z6d+Yd3o?MrAqM0Kc|iV92owdyL5UC#5<>aVCa44|hpM4Es0sQWIt5*Tu0n&*J!lk~ zf_{hI!w5`*sjxDv4V%CW*ah~3!{C*0BD@;TgA3v9a1~q+AA{TB3-ERLHar49hi4Ih z5D^-ph8Q6X#0?2VqLBoIkE}zAkxHZUgRb+f=natP#6>iMMoK->`~sRLq)(kHo*Vn{;LcG6+e zdD1=7D>9j^O?D{Qg|tCDK{ym)H7&wDr6*;uGTJg8GHjVb znL{!cWyUB7MT6o-VNo_w8Yq`2<5Ub)hw4L3rj}5@qxMs0WMyP6Wy582WNT#4$d1qu znl{acmP#w5ouJ*Jy_Zv#bCKi7ZIf$}8dZdVy&)LYdbX%I9R8VMQ|8r>Q*nyQ)sn)#Z|n)kKvS`4iutvy=3T65Yu+7a4Yv^%sX zb>ww?bn(=Yu(!=O6^iuTp>)p_Y^{w=i^lS773}6Fm1Fpe-gF!>I zp{*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