From 4e82d53c6fbce3f3a374a6bbff3fab1908a3bc10 Mon Sep 17 00:00:00 2001
From: nemvar <47324920+nemvar@users.noreply.github.com>
Date: Tue, 23 Jul 2019 11:43:23 +0200
Subject: [PATCH] Reworked electrocute_act to fit my fantasy while squashing
some bugs. (#45291)
* Reworked electrocute_act
This still isn't perfect, ideally this would use flags and stuff but I don't have the energy for a change of that size.
* Removes spec_electrocute_act and makes the species siemens_coeff actually work.
* Readds the secondary shock
---
code/__DEFINES/components.dm | 2 +-
.../mob/living/carbon/carbon_defense.dm | 45 +++++++----------
.../mob/living/carbon/human/human_defense.dm | 50 ++++++++-----------
.../mob/living/carbon/human/species.dm | 3 --
code/modules/mob/living/living_defense.dm | 27 ++++++----
.../reagents/pyrotechnic_reagents.dm | 12 +++++
6 files changed, 67 insertions(+), 72 deletions(-)
diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm
index fe84895fcc4..e4a6f7aabf5 100644
--- a/code/__DEFINES/components.dm
+++ b/code/__DEFINES/components.dm
@@ -170,7 +170,7 @@
#define COMSIG_LIVING_RESIST "living_resist" //from base of mob/living/resist() (/mob/living)
#define COMSIG_LIVING_IGNITED "living_ignite" //from base of mob/living/IgniteMob() (/mob/living)
#define COMSIG_LIVING_EXTINGUISHED "living_extinguished" //from base of mob/living/ExtinguishMob() (/mob/living)
-#define COMSIG_LIVING_ELECTROCUTE_ACT "living_electrocute_act" //from base of mob/living/electrocute_act(): (shock_damage)
+#define COMSIG_LIVING_ELECTROCUTE_ACT "living_electrocute_act" //from base of mob/living/electrocute_act(): (shock_damage, source, siemens_coeff, safety, override, tesla_shock, illusion, stun)
#define COMSIG_LIVING_MINOR_SHOCK "living_minor_shock" //sent by stuff like stunbatons and tasers: ()
#define COMSIG_LIVING_REVIVE "living_revive" //from base of mob/living/revive() (full_heal, admin_revive)
#define COMSIG_PROCESS_BORGCHARGER_OCCUPANT "living_charge" //sent from borg recharge stations: (amount, repairs)
diff --git a/code/modules/mob/living/carbon/carbon_defense.dm b/code/modules/mob/living/carbon/carbon_defense.dm
index d3af7ea214e..ea3d81fe5cf 100644
--- a/code/modules/mob/living/carbon/carbon_defense.dm
+++ b/code/modules/mob/living/carbon/carbon_defense.dm
@@ -209,47 +209,36 @@
var/obj/item/organ/O = X
O.emp_act(severity)
-/mob/living/carbon/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = 0, override = 0, tesla_shock = 0, illusion = 0, stun = TRUE)
- if(tesla_shock && (flags_1 & TESLA_IGNORE_1))
- return FALSE
- if(HAS_TRAIT(src, TRAIT_SHOCKIMMUNE))
- return FALSE
- shock_damage *= siemens_coeff
- if(dna && dna.species)
- shock_damage *= dna.species.siemens_coeff
- if(shock_damage<1 && !override)
- return 0
- if(reagents.has_reagent(/datum/reagent/teslium))
- shock_damage *= 1.5 //If the mob has teslium in their body, shocks are 50% more damaging!
- if(illusion)
- adjustStaminaLoss(shock_damage)
- else
- take_overall_damage(0,shock_damage)
- visible_message(
- "[src] was shocked by \the [source]!", \
- "You feel a powerful shock coursing through your body!", \
- "You hear a heavy electrical crack." \
- )
+///Adds to the parent by also adding functionality to propagate shocks through pulling and doing some fluff effects.
+/mob/living/carbon/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = FALSE, override = FALSE, tesla_shock = FALSE, illusion = FALSE, stun = TRUE)
+ . = ..()
+ //Pulling
if(iscarbon(pulling) && !illusion && source != pulling)
var/mob/living/carbon/C = pulling
C.electrocute_act(shock_damage*0.75, src, 1, 0, override, 0, illusion, stun)
if(iscarbon(pulledby) && !illusion && source != pulledby)
var/mob/living/carbon/C = pulledby
C.electrocute_act(shock_damage*0.75, src, 1, 0, override, 0, illusion, stun)
- jitteriness += 1000 //High numbers for violent convulsions
+ //Stun
+ var/should_stun = (!tesla_shock || siemens_coeff > 0.5) && stun
+ if(should_stun)
+ Paralyze(40)
+ //Jitter and other fluff.
+ jitteriness += 1000
do_jitter_animation(jitteriness)
stuttering += 2
- if((!tesla_shock || (tesla_shock && siemens_coeff > 0.5)) && stun)
- Paralyze(40)
- spawn(20)
- jitteriness = max(jitteriness - 990, 10) //Still jittery, but vastly less
- if((!tesla_shock || (tesla_shock && siemens_coeff > 0.5)) && stun)
- Paralyze(60)
+ addtimer(CALLBACK(src, .proc/secondary_shock, should_stun), 20)
if(override)
return override
else
return shock_damage
+///Called slightly after electrocute act to reduce jittering and apply a secondary stun.
+/mob/living/carbon/proc/secondary_shock(should_stun)
+ jitteriness = max(jitteriness - 990, 10)
+ if(should_stun)
+ Paralyze(60)
+
/mob/living/carbon/proc/help_shake_act(mob/living/carbon/M)
if(on_fire)
to_chat(M, "You can't put [p_them()] out with just your bare hands!")
diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm
index 0b1c831a9f3..6111fd83108 100644
--- a/code/modules/mob/living/carbon/human/human_defense.dm
+++ b/code/modules/mob/living/carbon/human/human_defense.dm
@@ -439,43 +439,35 @@
apply_damage(5, BRUTE, affecting, run_armor_check(affecting, "melee"))
-//Added a safety check in case you want to shock a human mob directly through electrocute_act.
-/mob/living/carbon/human/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = 0, override = 0, tesla_shock = 0, illusion = 0, stun = TRUE)
- if(tesla_shock)
- var/total_coeff = 1
- if(gloves)
- var/obj/item/clothing/gloves/G = gloves
- if(G.siemens_coefficient <= 0)
- total_coeff -= 0.5
+///Calculates the siemens coeff based on clothing and species, can also restart hearts.
+/mob/living/carbon/human/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = FALSE, override = 0, tesla_shock = FALSE, illusion = FALSE, stun = TRUE)
+ //Calculates the siemens coeff based on clothing. Completely ignores the arguments
+ if(tesla_shock) //I hate this entire block. This gets the siemens_coeff for tesla shocks
+ if(gloves && gloves.siemens_coefficient <= 0)
+ siemens_coeff -= 0.5
if(wear_suit)
- var/obj/item/clothing/suit/S = wear_suit
- if(S.siemens_coefficient <= 0)
- total_coeff -= 0.95
- else if(S.siemens_coefficient == (-1))
- total_coeff -= 1
- siemens_coeff = total_coeff
- if(flags_1 & TESLA_IGNORE_1)
- siemens_coeff = 0
- else if(!safety)
- var/gloves_siemens_coeff = 1
+ if(wear_suit.siemens_coefficient == -1)
+ siemens_coeff -= 1
+ else if(wear_suit.siemens_coefficient <= 0)
+ siemens_coeff -= 0.95
+ siemens_coeff = max(siemens_coeff, 0)
+ else if(!safety) //This gets the siemens_coeff for all non tesla shocks
if(gloves)
- var/obj/item/clothing/gloves/G = gloves
- gloves_siemens_coeff = G.siemens_coefficient
- siemens_coeff = gloves_siemens_coeff
+ siemens_coeff *= gloves.siemens_coefficient
+ siemens_coeff *= physiology.siemens_coeff
+ siemens_coeff *= dna.species.siemens_coeff
+ . = ..()
+ //Don't go further if the shock was blocked/too weak.
+ if(!.)
+ return
//Note we both check that the user is in cardiac arrest and can actually heartattack
//If they can't, they're missing their heart and this would runtime
if(undergoing_cardiac_arrest() && can_heartattack() && !illusion)
if(shock_damage * siemens_coeff >= 1 && prob(25))
var/obj/item/organ/heart/heart = getorganslot(ORGAN_SLOT_HEART)
- heart.beating = TRUE
- if(stat == CONSCIOUS)
+ if(heart.Restart() && stat == CONSCIOUS)
to_chat(src, "You feel your heart beating again!")
- siemens_coeff *= physiology.siemens_coeff
-
- dna.species.spec_electrocute_act(src, shock_damage,source,siemens_coeff,safety,override,tesla_shock, illusion, stun)
- . = ..(shock_damage,source,siemens_coeff,safety,override,tesla_shock, illusion, stun)
- if(.)
- electrocution_animation(40)
+ electrocution_animation(40)
/mob/living/carbon/human/emag_act(mob/user)
.=..()
diff --git a/code/modules/mob/living/carbon/human/species.dm b/code/modules/mob/living/carbon/human/species.dm
index c5af69363b4..54cd1a64185 100644
--- a/code/modules/mob/living/carbon/human/species.dm
+++ b/code/modules/mob/living/carbon/human/species.dm
@@ -1156,9 +1156,6 @@ GLOBAL_LIST_EMPTY(roundstart_races)
/datum/species/proc/spec_emag_act(mob/living/carbon/human/H, mob/user)
return
-/datum/species/proc/spec_electrocute_act(mob/living/carbon/human/H, shock_damage, obj/source, siemens_coeff = 1, safety = 0, override = 0, tesla_shock = 0, illusion = 0, stun = TRUE)
- return
-
/datum/species/proc/help(mob/living/carbon/human/user, mob/living/carbon/human/target, datum/martial_art/attacker_style)
if(!((target.health < 0 || HAS_TRAIT(target, TRAIT_FAKEDEATH)) && !(target.mobility_flags & MOBILITY_STAND)))
target.help_shake_act(user)
diff --git a/code/modules/mob/living/living_defense.dm b/code/modules/mob/living/living_defense.dm
index 0a17b5b694e..18b7a3539b4 100644
--- a/code/modules/mob/living/living_defense.dm
+++ b/code/modules/mob/living/living_defense.dm
@@ -319,21 +319,26 @@
take_bodypart_damage(acidpwr * min(1, acid_volume * 0.1))
return 1
-/mob/living/proc/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = 0, tesla_shock = 0, illusion = 0, stun = TRUE)
- SEND_SIGNAL(src, COMSIG_LIVING_ELECTROCUTE_ACT, shock_damage)
+///As the name suggests, this should be called to apply electric shocks.
+/mob/living/proc/electrocute_act(shock_damage, source, siemens_coeff = 1, safety = FALSE, override = FALSE, tesla_shock = FALSE, illusion = FALSE, stun = TRUE)
+ SEND_SIGNAL(src, COMSIG_LIVING_ELECTROCUTE_ACT, shock_damage, source, siemens_coeff, safety, override, tesla_shock, illusion, stun)
+ shock_damage *= siemens_coeff
if(tesla_shock && (flags_1 & TESLA_IGNORE_1))
return FALSE
if(HAS_TRAIT(src, TRAIT_SHOCKIMMUNE))
return FALSE
- if(shock_damage > 0)
- if(!illusion)
- adjustFireLoss(shock_damage)
- visible_message(
- "[src] was shocked by \the [source]!", \
- "You feel a powerful shock coursing through your body!", \
- "You hear a heavy electrical crack." \
- )
- return shock_damage
+ if(shock_damage < 1 && !override)
+ return FALSE
+ if(!illusion)
+ adjustFireLoss(shock_damage)
+ else
+ adjustStaminaLoss(shock_damage)
+ visible_message(
+ "[src] was shocked by \the [source]!", \
+ "You feel a powerful shock coursing through your body!", \
+ "You hear a heavy electrical crack." \
+ )
+ return shock_damage
/mob/living/emp_act(severity)
. = ..()
diff --git a/code/modules/reagents/chemistry/reagents/pyrotechnic_reagents.dm b/code/modules/reagents/chemistry/reagents/pyrotechnic_reagents.dm
index aa97a629aea..c26a76523b8 100644
--- a/code/modules/reagents/chemistry/reagents/pyrotechnic_reagents.dm
+++ b/code/modules/reagents/chemistry/reagents/pyrotechnic_reagents.dm
@@ -217,6 +217,18 @@
playsound(M, "sparks", 50, 1)
..()
+/datum/reagent/teslium/on_mob_metabolize(mob/living/carbon/human/L)
+ . = ..()
+ if(!istype(L))
+ return
+ L.physiology.siemens_coeff *= 2
+
+/datum/reagent/teslium/on_mob_end_metabolize(mob/living/carbon/human/L)
+ . = ..()
+ if(!istype(L))
+ return
+ L.physiology.siemens_coeff *= 0.5
+
/datum/reagent/teslium/energized_jelly
name = "Energized Jelly"
description = "Electrically-charged jelly. Boosts jellypeople's nervous system, but only shocks other lifeforms."