From da34941fae1473a64405c49290a9f62e7806dc28 Mon Sep 17 00:00:00 2001 From: Nathan Winters <100448493+CinnamonSnowball@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:39:25 +0100 Subject: [PATCH] Minor pill/patch application refactor (#23958) * Refactor pill/patch application * I will come back to this --- .../mob/living/carbon/alien/alien_base.dm | 19 ---- code/modules/mob/living/carbon/carbon.dm | 94 +++++-------------- .../reagents/reagent_containers/patch.dm | 36 ++++--- .../reagents/reagent_containers/pill.dm | 33 +++++-- 4 files changed, 75 insertions(+), 107 deletions(-) diff --git a/code/modules/mob/living/carbon/alien/alien_base.dm b/code/modules/mob/living/carbon/alien/alien_base.dm index 8d2a727019e..97559889b95 100644 --- a/code/modules/mob/living/carbon/alien/alien_base.dm +++ b/code/modules/mob/living/carbon/alien/alien_base.dm @@ -260,25 +260,6 @@ and carry the owner just to make sure*/ . = ..() ADD_TRAIT(src, TRAIT_IMMOBILIZED, LYING_DOWN_TRAIT) //Xenos can't crawl -/mob/living/carbon/alien/consume_patch_or_pill(obj/item/reagent_containers/medicine, mob/user) - var/apply_method = "swallow" - var/how_many_reagents = medicine.reagents.total_volume - var/reagent_application = REAGENT_INGEST - if(ispatch(medicine)) - apply_method = "apply" - how_many_reagents = clamp(medicine.reagents.total_volume, 0.1, 2) - reagent_application = REAGENT_TOUCH - - visible_message("[user] attempts to force [src] to [apply_method] [medicine].") - if(!do_after(user, 5 SECONDS, TRUE, src)) // You try feeding a xenomorph a pill - return - - visible_message("[user] forces [src] to [apply_method] [medicine].") - var/fraction = min(1 / medicine.reagents.total_volume, 1) - medicine.reagents.reaction(src, reagent_application, fraction) - medicine.reagents.trans_to(src, how_many_reagents) - return TRUE - /mob/living/carbon/alien/update_stat(reason) if(health <= HEALTH_THRESHOLD_CRIT && stat == CONSCIOUS) KnockOut() diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index 2acca034a2a..5a688ee701d 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -1159,26 +1159,22 @@ GLOBAL_LIST_INIT(ventcrawl_machinery, list(/obj/machinery/atmospherics/unary/ven return TRUE /mob/living/carbon/proc/eat(obj/item/food/to_eat, mob/user, bitesize_override) - if(ispill(to_eat) || ispatch(to_eat)) // We first have to know if it's either a pill or a patch, only then can we check if it's a food item - return consume_patch_or_pill(to_eat, user) - - if(!isfood(to_eat)) + if(!istype(to_eat)) return FALSE - var/obj/item/food/food = to_eat // It's not a patch or a pill so it must be food var/fullness = nutrition + 10 - if(istype(food, /obj/item/food/snacks)) - for(var/datum/reagent/consumable/C in reagents.reagent_list) //we add the nutrition value of what we're currently digesting + if(istype(to_eat, /obj/item/food/snacks)) + for(var/datum/reagent/consumable/C in reagents.reagent_list) // We add the nutrition value of what we're currently digesting fullness += C.nutriment_factor * C.volume / (C.metabolization_rate * metabolism_efficiency) if(user == src) - if(!selfFeed(food, fullness)) + if(!selfFeed(to_eat, fullness)) return FALSE else - if(!forceFed(food, user, fullness)) + if(!forceFed(to_eat, user, fullness)) return FALSE - consume(food, bitesize_override) + consume(to_eat, bitesize_override) SSticker.score.score_food_eaten++ return TRUE @@ -1203,25 +1199,22 @@ GLOBAL_LIST_INIT(ventcrawl_machinery, list(/obj/machinery/atmospherics/unary/ven return TRUE /mob/living/carbon/proc/selfFeed(obj/item/food/to_eat, fullness) - if(ispill(to_eat)) - to_chat(src, "You swallow [to_eat].") - else if(ispatch(to_eat)) - to_chat(src, "You apply [to_eat].") - else - if(to_eat.junkiness && satiety < -150 && nutrition > NUTRITION_LEVEL_STARVING + 50) - to_chat(src, "You don't feel like eating any more junk food at the moment.") - return FALSE - if(fullness <= 50) - to_chat(src, "You hungrily chew out a piece of [to_eat] and gobble it!") - else if(fullness > 50 && fullness < 150) - to_chat(src, "You hungrily begin to eat [to_eat].") - else if(fullness > 150 && fullness < 500) - to_chat(src, "You take a bite of [to_eat].") - else if(fullness > 500 && fullness < 600) - to_chat(src, "You unwillingly chew a bit of [to_eat].") - else if(fullness > (600 * (1 + overeatduration / 2000))) // The more you eat - the more you can eat - to_chat(src, "You cannot force any more of [to_eat] to go down your throat.") - return FALSE + if(to_eat.junkiness && satiety < -150 && nutrition > NUTRITION_LEVEL_STARVING + 50) + to_chat(src, "You don't feel like eating any more junk food at the moment.") + return FALSE + + if(fullness <= 50) + to_chat(src, "You hungrily chew out a piece of [to_eat] and gobble it!") + else if(fullness > 50 && fullness < 150) + to_chat(src, "You hungrily begin to eat [to_eat].") + else if(fullness > 150 && fullness < 500) + to_chat(src, "You take a bite of [to_eat].") + else if(fullness > 500 && fullness < 600) + to_chat(src, "You unwillingly chew a bit of [to_eat].") + else if(fullness > (600 * (1 + overeatduration / 2000))) // The more you eat - the more you can eat + to_chat(src, "You cannot force any more of [to_eat] to go down your throat.") + return FALSE + return TRUE /mob/living/carbon/proc/selfDrink(obj/item/reagent_containers/drinks/toDrink, mob/user) @@ -1245,7 +1238,7 @@ GLOBAL_LIST_INIT(ventcrawl_machinery, list(/obj/machinery/atmospherics/unary/ven /*TO DO - If/when stomach organs are introduced, override this at the human level sending the item to the stomach so that different stomachs can handle things in different ways VB*/ /mob/living/carbon/proc/consume(obj/item/food/to_eat, bitesize_override) - var/this_bite = bitesize_override ? bitesize_override : to_eat.bitesize + var/this_bite = bitesize_override || to_eat.bitesize if(!to_eat.reagents) return if(satiety > -200) @@ -1258,47 +1251,6 @@ so that different stomachs can handle things in different ways VB*/ to_eat.reagents.reaction(src, REAGENT_INGEST, fraction) to_eat.reagents.trans_to(src, this_bite) -/mob/living/carbon/proc/consume_patch_or_pill(obj/item/reagent_containers/medicine, mob/user) // medicine = patch or pill - // The reason why this is bundled up is to avoid 2 procs that will be practically identical - if(!medicine.reagents.total_volume) - return TRUE // Doesn't have reagents, would be fine to use up - - if(!dna.species.dietflags) // You will not feed the IPC - to_chat(user, "You cannot feed [src] [medicine]!") - return FALSE - - var/apply_method = "swallow" - var/reagent_application = REAGENT_INGEST - var/requires_mouth = TRUE - var/instant = FALSE - var/how_many_reagents = medicine.reagents.total_volume - - if(ispatch(medicine)) - apply_method = "apply" - reagent_application = REAGENT_TOUCH - requires_mouth = FALSE - how_many_reagents = clamp(medicine.reagents.total_volume, 0.1, 2) // Patches aren't that good at transporting reagents into the bloodstream - var/obj/item/reagent_containers/patch/patch = medicine - if(patch.instant_application) - instant = TRUE - - if(user != src && !instant) - if(requires_mouth && !get_organ("head")) - to_chat(user, "You cannot feed [src] [medicine]!") - return FALSE - visible_message("[user] attempts to force [src] to [apply_method] [medicine].") - if(!do_after(user, 3 SECONDS, TRUE, src, TRUE)) - return FALSE - forceFedAttackLog(medicine, user) - visible_message("[user] forces [src] to [apply_method] [medicine].") - else - to_chat(user, "You [apply_method] [medicine].") - - var/fraction = min(1 / medicine.reagents.total_volume, 1) - medicine.reagents.reaction(src, reagent_application, fraction) - medicine.reagents.trans_to(src, how_many_reagents) - return TRUE - /mob/living/carbon/get_access() . = ..() diff --git a/code/modules/reagents/reagent_containers/patch.dm b/code/modules/reagents/reagent_containers/patch.dm index a0f33f2ed62..779b8b38988 100644 --- a/code/modules/reagents/reagent_containers/patch.dm +++ b/code/modules/reagents/reagent_containers/patch.dm @@ -12,22 +12,36 @@ var/instant_application = FALSE var/needs_to_apply_reagents = TRUE -/obj/item/reagent_containers/patch/attack(mob/living/carbon/M, mob/user, def_zone) - return apply(M, user) +/obj/item/reagent_containers/patch/attack(mob/living/carbon/C, mob/user) + return apply(C, user) /obj/item/reagent_containers/patch/attack_self(mob/user) return apply(user, user) -/obj/item/reagent_containers/patch/proc/apply(mob/living/carbon/M, mob/user) - if(!istype(M)) +/obj/item/reagent_containers/patch/proc/apply(mob/living/carbon/C, mob/user) + if(!istype(C)) return FALSE - if(M.eat(src, user)) - if(user.get_active_hand() == src) - user.drop_item() // Only drop if they're holding the patch directly - forceMove(M) - LAZYADD(M.processing_patches, src) - return TRUE - return FALSE + + if(ismachineperson(C)) + to_chat(user, "[user == C ? "You" : C] can't use [src]!") + return FALSE + + if(user == C) + to_chat(user, "You apply [src].") + else + if(!instant_application) + C.visible_message("[user] attempts to force [C] to apply [src].") + if(!do_after(user, 3 SECONDS, TRUE, C, TRUE)) + return FALSE + + C.forceFedAttackLog(src, user) + C.visible_message("[user] forces [C] to apply [src].") + + if(user.get_active_hand() == src) + user.drop_item() // Only drop if they're holding the patch directly + forceMove(C) + LAZYADD(C.processing_patches, src) + return TRUE /obj/item/reagent_containers/patch/styptic name = "brute patch" diff --git a/code/modules/reagents/reagent_containers/pill.dm b/code/modules/reagents/reagent_containers/pill.dm index 2c843596059..20bed700156 100644 --- a/code/modules/reagents/reagent_containers/pill.dm +++ b/code/modules/reagents/reagent_containers/pill.dm @@ -18,16 +18,37 @@ if(!icon_state) icon_state = "pill[rand(1, 20)]" -/obj/item/reagent_containers/pill/proc/apply(mob/living/carbon/M, mob/user, def_zone) - if(!istype(M)) +/obj/item/reagent_containers/pill/proc/apply(mob/living/carbon/C, mob/user) + if(!istype(C)) return FALSE - if(M.eat(src, user)) + + if(!reagents.total_volume) qdel(src) return TRUE - return FALSE -/obj/item/reagent_containers/pill/attack(mob/living/carbon/M, mob/user, def_zone) - return apply(M, user) + if(ishuman(C)) + var/mob/living/carbon/human/H = C + if(!H.check_has_mouth()) + to_chat(user, "[user == H ? "You" : H] can't ingest [src]!") + return FALSE + + if(user == C) + to_chat(user, "You swallow [src].") + else + C.visible_message("[user] attempts to force [C] to swallow [src].") + if(!do_after(user, 3 SECONDS, TRUE, C, TRUE)) + return FALSE + + C.forceFedAttackLog(src, user) + C.visible_message("[user] forces [C] to swallow [src].") + + reagents.reaction(C, REAGENT_INGEST) + reagents.trans_to(C, reagents.total_volume) + qdel(src) + return TRUE + +/obj/item/reagent_containers/pill/attack(mob/living/carbon/C, mob/user) + return apply(C, user) /obj/item/reagent_containers/pill/attack_self(mob/user) return apply(user, user)