From b2972c1d2c679c516f66fbb360311beabd064a8f Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Mon, 6 Mar 2023 22:05:12 +0300 Subject: [PATCH] Add emp grenade (#14393) --- Content.Server/Emp/EmpOnTriggerComponent.cs | 17 ++++++ Content.Server/Emp/EmpSystem.cs | 39 ++++++++++++ .../Light/EntitySystems/PoweredLightSystem.cs | 9 +++ .../Power/EntitySystems/ApcSystem.cs | 12 ++++ .../Power/EntitySystems/BatterySystem.cs | 8 +++ .../Locale/en-US/store/uplink-catalog.ftl | 3 + .../Prototypes/Catalog/uplink_catalog.yml | 10 ++++ .../Entities/Effects/emp_effects.yml | 44 ++++++++++++++ .../Objects/Weapons/Throwable/grenades.yml | 18 ++++++ .../Textures/Effects/emp.rsi/emp_disable.png | Bin 0 -> 1635 bytes .../Textures/Effects/emp.rsi/emp_pulse.png | Bin 0 -> 1563 bytes Resources/Textures/Effects/emp.rsi/meta.json | 56 ++++++++++++++++++ .../Grenades/empgrenade.rsi/equipped-BELT.png | Bin 0 -> 717 bytes .../Weapons/Grenades/empgrenade.rsi/icon.png | Bin 0 -> 288 bytes .../Weapons/Grenades/empgrenade.rsi/meta.json | 27 +++++++++ .../Grenades/empgrenade.rsi/primed.png | Bin 0 -> 445 bytes 16 files changed, 243 insertions(+) create mode 100644 Content.Server/Emp/EmpOnTriggerComponent.cs create mode 100644 Content.Server/Emp/EmpSystem.cs create mode 100644 Resources/Prototypes/Entities/Effects/emp_effects.yml create mode 100644 Resources/Textures/Effects/emp.rsi/emp_disable.png create mode 100644 Resources/Textures/Effects/emp.rsi/emp_pulse.png create mode 100644 Resources/Textures/Effects/emp.rsi/meta.json create mode 100644 Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/equipped-BELT.png create mode 100644 Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/icon.png create mode 100644 Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/meta.json create mode 100644 Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/primed.png diff --git a/Content.Server/Emp/EmpOnTriggerComponent.cs b/Content.Server/Emp/EmpOnTriggerComponent.cs new file mode 100644 index 0000000000..b3f486b895 --- /dev/null +++ b/Content.Server/Emp/EmpOnTriggerComponent.cs @@ -0,0 +1,17 @@ +namespace Content.Server.Emp; + +/// +/// Upon being triggered will EMP area around it. +/// +[RegisterComponent] +sealed class EmpOnTriggerComponent : Component +{ + [DataField("range"), ViewVariables(VVAccess.ReadWrite)] + public float Range = 1.0f; + + /// + /// How much energy will be consumed per battery in range + /// + [DataField("energyConsumption"), ViewVariables(VVAccess.ReadWrite)] + public float EnergyConsumption; +} diff --git a/Content.Server/Emp/EmpSystem.cs b/Content.Server/Emp/EmpSystem.cs new file mode 100644 index 0000000000..865f6a6947 --- /dev/null +++ b/Content.Server/Emp/EmpSystem.cs @@ -0,0 +1,39 @@ +using Content.Server.Explosion.EntitySystems; +using Robust.Shared.Map; + +namespace Content.Server.Emp; + +public sealed class EmpSystem : EntitySystem +{ + [Dependency] private readonly EntityLookupSystem _lookup = default!; + + public const string EmpPulseEffectPrototype = "EffectEmpPulse"; + public const string EmpDisabledEffectPrototype = "EffectEmpDisabled"; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleEmpTrigger); + } + + public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption) + { + foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range)) + { + var ev = new EmpPulseEvent(energyConsumption, false); + RaiseLocalEvent(uid, ref ev); + if (ev.Affected) + Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates); + } + Spawn(EmpPulseEffectPrototype, coordinates); + } + + private void HandleEmpTrigger(EntityUid uid, EmpOnTriggerComponent comp, TriggerEvent args) + { + EmpPulse(Transform(uid).Coordinates.ToMap(EntityManager), comp.Range, comp.EnergyConsumption); + args.Handled = true; + } +} + +[ByRefEvent] +public record struct EmpPulseEvent(float EnergyConsumption, bool Affected); diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index bef74772a7..545ad4d4f3 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -22,6 +22,7 @@ using Robust.Shared.Containers; using Robust.Shared.Player; using Robust.Shared.Timing; using Content.Shared.DoAfter; +using Content.Server.Emp; namespace Content.Server.Light.EntitySystems { @@ -63,6 +64,8 @@ namespace Content.Server.Light.EntitySystems SubscribeLocalEvent(OnPowerChanged); SubscribeLocalEvent(OnDoAfter); + + SubscribeLocalEvent(OnEmpPulse); } private void OnInit(EntityUid uid, PoweredLightComponent light, ComponentInit args) @@ -421,5 +424,11 @@ namespace Content.Server.Light.EntitySystems args.Handled = true; } + + private void OnEmpPulse(EntityUid uid, PoweredLightComponent component, ref EmpPulseEvent args) + { + args.Affected = true; + TryDestroyBulb(uid, component); + } } } diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index 8ce9d26ec0..d1333759bf 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -1,3 +1,4 @@ +using Content.Server.Emp; using Content.Server.Popups; using Content.Server.Power.Components; using Content.Shared.Access.Components; @@ -44,6 +45,8 @@ namespace Content.Server.Power.EntitySystems SubscribeLocalEvent(OnToolFinished); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnExamine); + + SubscribeLocalEvent(OnEmpPulse); } // Change the APC's state only when the battery state changes, or when it's first created. @@ -247,5 +250,14 @@ namespace Content.Server.Power.EntitySystems ? "apc-component-on-examine-panel-open" : "apc-component-on-examine-panel-closed")); } + + private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args) + { + if (component.MainBreakerEnabled) + { + args.Affected = true; + ApcToggleBreaker(uid, component); + } + } } } diff --git a/Content.Server/Power/EntitySystems/BatterySystem.cs b/Content.Server/Power/EntitySystems/BatterySystem.cs index a46db7dcb9..b8dc676485 100644 --- a/Content.Server/Power/EntitySystems/BatterySystem.cs +++ b/Content.Server/Power/EntitySystems/BatterySystem.cs @@ -1,4 +1,5 @@ using Content.Server.Cargo.Systems; +using Content.Server.Emp; using Content.Server.Power.Components; using Content.Shared.Examine; using Content.Shared.Rejuvenate; @@ -17,6 +18,7 @@ namespace Content.Server.Power.EntitySystems SubscribeLocalEvent(OnNetBatteryRejuvenate); SubscribeLocalEvent(OnBatteryRejuvenate); SubscribeLocalEvent(CalculateBatteryPrice); + SubscribeLocalEvent(OnEmpPulse); SubscribeLocalEvent(PreSync); SubscribeLocalEvent(PostSync); @@ -87,5 +89,11 @@ namespace Content.Server.Power.EntitySystems { args.Price += component.CurrentCharge * component.PricePerJoule; } + + private void OnEmpPulse(EntityUid uid, BatteryComponent component, ref EmpPulseEvent args) + { + args.Affected = true; + component.UseCharge(args.EnergyConsumption); + } } } diff --git a/Resources/Locale/en-US/store/uplink-catalog.ftl b/Resources/Locale/en-US/store/uplink-catalog.ftl index 71de41859a..12d15201ab 100644 --- a/Resources/Locale/en-US/store/uplink-catalog.ftl +++ b/Resources/Locale/en-US/store/uplink-catalog.ftl @@ -39,6 +39,9 @@ uplink-c4-desc = Use it to breach walls, airlocks or sabotage equipment. It can uplink-c4-bundle-name = C-4 bundle uplink-c4-bundle-desc = Because sometimes quantity is quality. Contains 8 C-4 plastic explosives. +uplink-emp-grenade-name = Emp Grenade +uplink-emp-grenade-desc = Releases electromagnetic pulses that disrupt or damage many electronic devices or drain power cells. + # Ammo uplink-pistol-magazine-name = Pistol Magazine (.35 auto) uplink-pistol-magazine-desc = Pistol magazine with 10 catridges. Compatible with Viper. diff --git a/Resources/Prototypes/Catalog/uplink_catalog.yml b/Resources/Prototypes/Catalog/uplink_catalog.yml index 2265e019fc..ba23f6988d 100644 --- a/Resources/Prototypes/Catalog/uplink_catalog.yml +++ b/Resources/Prototypes/Catalog/uplink_catalog.yml @@ -142,6 +142,16 @@ categories: - UplinkExplosives +- type: listing + id: UplinkEmpGrenade + name: uplink-emp-grenade-name + description: uplink-emp-grenade-desc + productEntity: EmpGrenade + cost: + Telecrystal: 4 + categories: + - UplinkExplosives + # Ammo - type: listing diff --git a/Resources/Prototypes/Entities/Effects/emp_effects.yml b/Resources/Prototypes/Entities/Effects/emp_effects.yml new file mode 100644 index 0000000000..c04b765dec --- /dev/null +++ b/Resources/Prototypes/Entities/Effects/emp_effects.yml @@ -0,0 +1,44 @@ +- type: entity + id: EffectEmpPulse + noSpawn: true + components: + - type: TimedDespawn + lifetime: 0.8 + - type: Sprite + netsync: false + drawdepth: Effects + noRot: true + layers: + - shader: unshaded + map: ["enum.EffectLayers.Unshaded"] + sprite: Effects/emp.rsi + state: emp_pulse + - type: EffectVisuals + - type: Tag + tags: + - HideContextMenu + - type: EmitSoundOnSpawn + sound: + path: /Audio/Effects/Lightning/lightningbolt.ogg + - type: AnimationPlayer + +- type: entity + id: EffectEmpDisabled + noSpawn: true + components: + - type: TimedDespawn + lifetime: 0.4 + - type: Sprite + netsync: false + drawdepth: Effects + noRot: true + layers: + - shader: unshaded + map: ["enum.EffectLayers.Unshaded"] + sprite: Effects/emp.rsi + state: emp_disable + - type: EffectVisuals + - type: Tag + tags: + - HideContextMenu + - type: AnimationPlayer diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml b/Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml index 016860ea27..a980fa956a 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml @@ -154,3 +154,21 @@ enum.Trigger.TriggerVisualState.Unprimed: complete - type: StaticPrice price: 25 + +- type: entity + name: emp grenade + description: Releases electromagnetic pulses that disrupt or damage many electronic devices or drain power cells. + parent: GrenadeBase + id: EmpGrenade + components: + - type: Sprite + sprite: Objects/Weapons/Grenades/empgrenade.rsi + - type: EmpOnTrigger + range: 4 + energyConsumption: 50000 + - type: DeleteOnTrigger + - type: Appearance + visuals: + - type: TimerTriggerVisualizer + countdown_sound: + path: /Audio/Effects/countdown.ogg diff --git a/Resources/Textures/Effects/emp.rsi/emp_disable.png b/Resources/Textures/Effects/emp.rsi/emp_disable.png new file mode 100644 index 0000000000000000000000000000000000000000..fe45eabc71e9fa46be2d152c82be7b80a1ad6332 GIT binary patch literal 1635 zcmV-p2AuhcP))mCF8#x=psnQ|NZhp5!T z`oH|e2A5ykf)W?NQb;n~+JF=_b9#?tbWRVDj85$VlCe|ECqJLnRZHEa-=?yc2AD+L zwFg*Z+5IPS0zeJS)B)T%r zn98jP&Y0?%nr|!$fMd8dlrdGxaGWu9c8UVvI73_i)$)63!<`YB`a;zZAYptCUVQ)w zv_;!wX=~_}blL$^WT|wNt6_e&uF*My$Y5J zp;Ks?Lb?$EWy)vSJxhkrTWJZQR|{bFh?oW*Lg>}Y!5+FZ@Q9cX;H5hQ?Nko|r%6@> z!6R;*Kp0;KHv#}UKmfsk0D=Pn1P1~L4g?S!2p~8Rz~qzyXb^xhnj!R>=;+iNLUOh$ zL~~C-$++5!XnV%3T|^TVfYgW9#{F~SZat%E{E~6C7SU>qTf2z1DFDh#ORBv#?!Oq< zV#&DHxIJ2aOHYvVMF3PoN~oP`NUJ4d4=be2J^;s%(k;K$kkOWmCBAiY2sk-i`|n}= z*+e$vEPyknY1894+8)xgnq~o91DpqZMz8aLdq|htBmkTT>~kJ)3(50H@HK zns8^pe%wMu0Jt;2&z%7(0>GUCe(nrV9|9~QhU?1uV3t4oodMzk$Q9pv7BHIAIr^Oe z;#Qs&;|q$90(vdt^@!FPo5?L zAY15sG^L6~w$S<56~MZp5#;Gl525c0ATK;xkcYdOgIzxJ3jdeH*+M&Er+?8BSH0FBSeRQcjwb44qlT-OyvYxXBYFBJffQb zdgl?&=`kK(9L7zW1>hx*@WSkyNx0wByd?~IgdZ9GK7bNU0vIumaIND*X(=<@2T-DU z2H~njU^y750|5jF z0tgNS5F7{~I1oT^Ab{XZDS+8l{4`M!01`>~K_yiz5=r<$B~c_2NywosVwEA_G*Kdn z*@v^?oj}S?S4rc~KAa6N0LyLGHN%;fVR{W`!waB<_83`e`P#?PO5evli@+AZ73Tp} z>!2iVZn-Q0;5?wu^MGqu0>F8|vCjjtQ^d5qh!rEB2kbF>*ejo%BE|!n4pLS5PXyR& z3R%a5Jt5YVsg}EyGa_!EO1{J%LxcF9+v_>s^VX`2e%u8BlZrdq>*xm*r** z=Q8`90hL^?hJ@?XFzcXu#WZP&H&vz1BwDT2cJjJerG^Y0FjM90^v7> h0$m`0;6MPu`3nXpFv8($e6;`o002ovPDHLkV1mHp=I;Oi literal 0 HcmV?d00001 diff --git a/Resources/Textures/Effects/emp.rsi/emp_pulse.png b/Resources/Textures/Effects/emp.rsi/emp_pulse.png new file mode 100644 index 0000000000000000000000000000000000000000..49f4be26ac21f6f10f2eb15d7e775be1bf716e01 GIT binary patch literal 1563 zcmZ{keLT|%9LIm#OxA8Q6G9jXd5DCJF!MC!DLKU~bRw-WCQM?@QXVRtii|lN9j8)? zJQNx#O3uT{Lkwdo&C@ZDJH1}_*WK%0ulMKsd42x>d_O53Zcd1uN;?4nKsXcZJ-0pJ zyQCzy?|4p(`L@BR1RojzAi3WKx~+#)1_0YIkRG@S z>mGH-4D=#S#t-V(-%T@nyhU8T`D$w_7+n<5A*|FS`bH$CYosb+(*MmP<}D6KE$(t+ zT-!< zj5cr%u5LI9NCos+rguU z={F{)zs}7t1Ky1)*klz@PH|tcOe-;3*6-JoH@qgNGf*H|7pGW9Ojo*{59NW^Cg#X6 z%U^1&i1MUfU3-gY50qaE$Gc;!-8=vKa-57G25ioR9#tZR*wY}pL zR(*lGi!M3!MX6yry=S@H=|a^Pu;0S&&tS(4vI;Io8w8T^8imNIfb7xaIzeKZeX~BJ zBU3miS0yk^Y5GJu?!2^qQD-(4iItltWGjv>ER?-oj+_A1VJ2V4s9ZP9G;xTU9B#IV z+H*ZKm1A-Eq20TLlu~&r@`A@eg}8kc4+=mMhJlhZJ)|Gdo+Q1(Em5bL4x3(ZByDRZ zM%foKQu%?@F_I4J97fz00Pz8<+r8U+6okJXQl?r1)>;5H)D#w>){2a}oxFTxK!PpS6fuH@c~4k@}zC%XkPJHm{RO{|`buJ&oT zaq;XEU2ltrYURhoR%f>Q*#vsHquDop+lFI~ zVkf=0Iw*jxYWY)>IwDrH7YO_>_r&M?1+)~Kv8bqW1fgzsD+qB) zwr@~lK@)LG4|7M@%QAO{M7FG^^%%5^W=%$*t&hP+Jy)_Xl_RA1t<=4}EDNS2cWsv4 zL~ub|c4}uD!6Ck_I}XZ5;gH2AWLkD9dJNT+)oJimDWLB`xm#(Ie-4fc4#a&8`?Xq5 zKsl$+;>>uC*n12IT+RdE+ literal 0 HcmV?d00001 diff --git a/Resources/Textures/Effects/emp.rsi/meta.json b/Resources/Textures/Effects/emp.rsi/meta.json new file mode 100644 index 0000000000..378759c5b4 --- /dev/null +++ b/Resources/Textures/Effects/emp.rsi/meta.json @@ -0,0 +1,56 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/e52683d3872347af447bb0ff74c420d4a4e91ea8", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "emp_disable", + "directions": 4, + "delays": [ + [ + 0.1, + 0.1, + 0.1, + 0.1 + ], + [ + 0.1, + 0.1, + 0.1, + 0.1 + ], + [ + 0.1, + 0.1, + 0.1, + 0.1 + ], + [ + 0.1, + 0.1, + 0.1, + 0.1 + ] + ] + }, + { + "name": "emp_pulse", + "delays": [ + [ + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1, + 0.1 + ] + ] + } + ] +} diff --git a/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/equipped-BELT.png b/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/equipped-BELT.png new file mode 100644 index 0000000000000000000000000000000000000000..c8d813b753bc5c4c34f28c5b0496ffaca26b5682 GIT binary patch literal 717 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEV9d>Qb`Ho)PG(@xm{>Y-xA)-y zkz@6>9j@B4A|iz+7CgGpq|veX+Cp!^m0V%5v%aXB3!w#} z0xYfqg~i{udUQUITB!7`ZT9EKyT4n{sbS3DlQ5&Np6N`|O}`_HZaEbNX4f8TpU-f& zC8#ag_uQEynY--rKCY+|4%|EI{_paw%Z>XO=QVtok$5vTac0|(teZi5H1DK73C?`T z{BVOVGgrJ;?E24>AH~eQFLJxMQ}e^Bc~S4gU+=$h;`Xu+6AJc6u8^?*yh5Kdt?TpV zpz74`4<{(NiSW+l(iYJWo)|Ud%)jrv^}m;Cb{?Ow-BmPN#`4o6-tMT0>m*l3UNrtB zvSQVp|Ic2gxVyi)+Z>otS#tL}W5(UKThm_G$?eK}%TdE$5SR1Ad(!0}yI(}}uC14M zdR?^B(hlW)eYuYO@-%em}~=vC=oi_d+OJ+ttU4v)%*9?j|7^SCa_0wy1_mY$RDzZ1 z+O3EUw%M!8j%jL}CI?l+?BVdATL{LQTjbF|u^dP%Dl1V=7 XWZ3T0CO*r6!NlO{>gTe~DWM4f&h$5x literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/icon.png b/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5f43e51ee0637a48a0eeae727eeed3ba37ffaffd GIT binary patch literal 288 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?4jBOuH;Rhv&5D0s=! z#WAE}&f9Anc@HZHuwLk%V(Bqe(ui5^kgc!*v+#wb2^^O%8!(2tG#?SloTG4a;-ip) zBPv4sH?8|%oBZZ6NAG1u*$a%a0W1nFXI__bJlvqIV4B|3_+2ikXQhdLN6V>WDU8?D zrw7$t@fN(Pyv(WjY)Zp%n7r_8IKjV%sR=mq;d1ywoK+Ex1w)cOVZ9~-gsvd huvk+nz!>Nj{?7@a%m3ZlTLAPOgQu&X%Q~loCIHZbZDjxe literal 0 HcmV?d00001 diff --git a/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/meta.json b/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/meta.json new file mode 100644 index 0000000000..889ac5cb4c --- /dev/null +++ b/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/meta.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/commit/e52683d3872347af447bb0ff74c420d4a4e91ea8", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "icon" + }, + { + "name": "primed", + "delays": [ + [ + 0.1, + 0.1 + ] + ] + }, + { + "name": "equipped-BELT", + "directions": 4 + } + ] +} diff --git a/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/primed.png b/Resources/Textures/Objects/Weapons/Grenades/empgrenade.rsi/primed.png new file mode 100644 index 0000000000000000000000000000000000000000..a11f70171fb12c11e8743cfe80ccc3becd152252 GIT binary patch literal 445 zcmV;u0Yd(XP)g952Zq nXmY@FMP&T}s^)hGJ`Ugq7rDGzO%g$!00000NkvXXu0mjfHm|g6 literal 0 HcmV?d00001