|
17 | 17 | var/alcohol_tolerance = ALCOHOL_RATE |
18 | 18 | /// modifier to toxpwr for liver and toxin damage taken |
19 | 19 | var/toxLethality = LIVER_DEFAULT_TOX_LETHALITY |
| 20 | + /// cached list of the toxinpower of toxins |
| 21 | + var/list/cached_toxpower = list() |
| 22 | + /// whether or not the toxin process can provide a message |
| 23 | + var/provide_pain_message = FALSE |
20 | 24 |
|
21 | | -/obj/item/organ/liver/on_life() |
22 | | - var/mob/living/carbon/C = owner |
23 | | - ..() //perform general on_life() |
24 | | - if(istype(C)) |
25 | | - if(!(organ_flags & ORGAN_FAILING))//can't process reagents with a failing liver |
| 25 | +/obj/item/organ/liver/Insert(mob/living/carbon/M, special, drop_if_replaced, special_zone) |
| 26 | + . = ..() |
| 27 | + RegisterSignal(M, COMSIG_CARBON_UPDATE_TOXINS, PROC_REF(update_toxin_cache)) |
26 | 28 |
|
27 | | - var/provide_pain_message = FALSE |
28 | | - var/damage_multiplier = 1 //reduced for every toxin |
29 | | - var/list/toxpwr = list() |
| 29 | +/obj/item/organ/liver/Remove(mob/living/carbon/M, special) |
| 30 | + UnregisterSignal(M, COMSIG_CARBON_UPDATE_TOXINS) |
| 31 | + return ..() |
30 | 32 |
|
31 | | - for(var/datum/reagent/toxin/T in C.reagents.reagent_list) |
32 | | - toxpwr += T.toxpwr |
33 | | - provide_pain_message = provide_pain_message || !T.silent_toxin |
34 | | - |
35 | | - sort_list(toxpwr, cmp = /proc/cmp_numeric_dsc) //sort all toxpowers scaling from highest to lowest |
| 33 | +/obj/item/organ/liver/proc/update_toxin_cache() |
| 34 | + var/mob/living/carbon/C = owner |
| 35 | + if(!istype(C)) |
| 36 | + return |
36 | 37 |
|
37 | | - for(var/dmg in toxpwr) |
38 | | - var/real_damage = dmg * toxLethality * damage_multiplier |
39 | | - damage_multiplier *= 0.5 //reduce the damage dealt for every subsequent toxin |
40 | | - C.adjustToxLoss(real_damage) |
41 | | - if(!HAS_TRAIT(owner, TRAIT_TOXINLOVER)) //don't hurt the liver if they like toxins |
42 | | - damage += (real_damage / 2) |
| 38 | + provide_pain_message = FALSE |
| 39 | + cached_toxpower = list() |
43 | 40 |
|
44 | | - //metabolize reagents |
45 | | - C.reagents.metabolize(C, can_overdose=TRUE) |
| 41 | + for(var/datum/reagent/toxin/T in C.reagents.reagent_list) |
| 42 | + cached_toxpower += T.toxpwr |
| 43 | + provide_pain_message = provide_pain_message || !T.silent_toxin |
| 44 | + |
| 45 | + sort_list(cached_toxpower, cmp = /proc/cmp_numeric_dsc) //sort all toxpowers scaling from highest to lowest |
46 | 46 |
|
47 | | - if(provide_pain_message && damage > 10 && !HAS_TRAIT(owner, TRAIT_TOXINLOVER) && prob(damage/3))//the higher the damage the higher the probability |
48 | | - to_chat(C, span_warning("You feel a dull pain in your abdomen.")) |
49 | | - else //for when our liver's failing |
| 47 | +/obj/item/organ/liver/on_life() |
| 48 | + var/mob/living/carbon/C = owner |
| 49 | + ..() //perform general on_life() |
| 50 | + if(istype(C)) |
| 51 | + if(organ_flags & ORGAN_FAILING)//for when our liver's failing |
50 | 52 | C.reagents.end_metabolization(C, keep_liverless = TRUE) //Stops trait-based effects on reagents, to prevent permanent buffs |
51 | 53 | C.reagents.metabolize(C, can_overdose=FALSE, liverless = TRUE) |
52 | 54 | if(HAS_TRAIT(C, TRAIT_STABLELIVER)) |
53 | 55 | return |
54 | 56 | C.adjustToxLoss(4, TRUE, TRUE) |
55 | 57 | if(prob(30)) |
56 | 58 | to_chat(C, span_warning("You feel a stabbing pain in your abdomen!")) |
| 59 | + |
| 60 | + else |
| 61 | + if(length(cached_toxpower)) //deal with toxins |
| 62 | + var/damage_multiplier = 1 //reduced for every subsequent toxin |
| 63 | + |
| 64 | + for(var/dmg in cached_toxpower) |
| 65 | + var/real_damage = dmg * toxLethality * damage_multiplier |
| 66 | + damage_multiplier *= 0.5 //reduce the damage dealt for every subsequent toxin |
| 67 | + C.adjustToxLoss(real_damage) |
| 68 | + if(!HAS_TRAIT(owner, TRAIT_TOXINLOVER)) //don't hurt the liver if they like toxins |
| 69 | + damage += (real_damage / 2) |
| 70 | + |
| 71 | + //metabolize reagents |
| 72 | + C.reagents.metabolize(C, can_overdose=TRUE) |
| 73 | + |
| 74 | + if(provide_pain_message && damage > 10 && !HAS_TRAIT(owner, TRAIT_TOXINLOVER) && prob(damage/3))//the higher the damage the higher the probability |
| 75 | + to_chat(C, span_warning("You feel a dull pain in your abdomen.")) |
57 | 76 |
|
58 | 77 | if(damage > maxHealth)//cap liver damage |
59 | 78 | damage = maxHealth |
|
0 commit comments