From fc61d427bf84bd2c105d5fb617ac75df34580bde Mon Sep 17 00:00:00 2001 From: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Date: Tue, 26 Nov 2024 01:21:26 +0300 Subject: [PATCH] Converts pills and patches into interact_with_atom (#88157) ## About The Pull Request Title. Code maintenance, code sanity and because overriding attack() like this is bad ## Changelog :cl: code: Converted pills and patches into interact_with_atom /:cl: --- .../reagents/reagent_containers/patch.dm | 23 +++++---- .../reagents/reagent_containers/pill.dm | 50 +++++++++---------- code/modules/unit_tests/metabolizing.dm | 6 +-- code/modules/unit_tests/pills.dm | 2 +- code/modules/unit_tests/reagent_mob_expose.dm | 2 +- code/modules/unit_tests/stomach.dm | 2 +- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/code/modules/reagents/reagent_containers/patch.dm b/code/modules/reagents/reagent_containers/patch.dm index 40e203dcb34..29cfadd745b 100644 --- a/code/modules/reagents/reagent_containers/patch.dm +++ b/code/modules/reagents/reagent_containers/patch.dm @@ -11,20 +11,21 @@ self_delay = 30 // three seconds dissolvable = FALSE -/obj/item/reagent_containers/pill/patch/attack(mob/living/L, mob/user) - if(ishuman(L)) - var/obj/item/bodypart/affecting = L.get_bodypart(check_zone(user.zone_selected)) - if(!affecting) - to_chat(user, span_warning("The limb is missing!")) - return - if(!IS_ORGANIC_LIMB(affecting)) - to_chat(user, span_notice("Medicine won't work on an inorganic limb!")) - return - ..() - /obj/item/reagent_containers/pill/patch/canconsume(mob/eater, mob/user) if(!iscarbon(eater)) return FALSE + if(!ishuman(eater)) + return TRUE + var/mob/living/carbon/human/human_eater = eater + var/obj/item/bodypart/affecting = human_eater.get_bodypart(check_zone(user.zone_selected)) + if(!affecting) + to_chat(user, span_warning("The limb is missing!")) + return FALSE + + if(!IS_ORGANIC_LIMB(affecting)) + to_chat(user, span_notice("Medicine won't work on an inorganic limb!")) + return FALSE + return TRUE // Masks were stopping people from "eating" patches. Thanks, inheritance. /obj/item/reagent_containers/pill/patch/libital diff --git a/code/modules/reagents/reagent_containers/pill.dm b/code/modules/reagents/reagent_containers/pill.dm index 629e0e96937..f407a75030a 100644 --- a/code/modules/reagents/reagent_containers/pill.dm +++ b/code/modules/reagents/reagent_containers/pill.dm @@ -25,27 +25,6 @@ if(apply_type == INGEST) AddComponent(/datum/component/germ_sensitive, mapload) -/obj/item/reagent_containers/pill/attack(mob/M, mob/user, def_zone) - if(!canconsume(M, user)) - return FALSE - - if(M == user) - M.visible_message(span_notice("[user] attempts to [apply_method] [src].")) - if(self_delay) - if(!do_after(user, self_delay, M)) - return FALSE - to_chat(M, span_notice("You [apply_method] [src].")) - - else - M.visible_message(span_danger("[user] attempts to force [M] to [apply_method] [src]."), \ - span_userdanger("[user] attempts to force you to [apply_method] [src].")) - if(!do_after(user, CHEM_INTERACT_DELAY(3 SECONDS, user), M)) - return FALSE - M.visible_message(span_danger("[user] forces [M] to [apply_method] [src]."), \ - span_userdanger("[user] forces you to [apply_method] [src].")) - - return on_consumption(M, user) - ///Runs the consumption code, can be overriden for special effects /obj/item/reagent_containers/pill/proc/on_consumption(mob/consumer, mob/giver) if(icon_state == "pill4" && prob(5)) //you take the red pill - you stay in Wonderland, and I show you how deep the rabbit hole goes @@ -56,15 +35,35 @@ if(reagents.total_volume) reagents.trans_to(consumer, reagents.total_volume, transferred_by = giver, methods = apply_type) qdel(src) - return TRUE - /obj/item/reagent_containers/pill/interact_with_atom(atom/target, mob/living/user, list/modifiers) + if (ismob(target)) + var/mob/target_mob = target + if(!canconsume(target_mob, user)) + return ITEM_INTERACT_BLOCKING + if(target_mob == user) + target_mob.visible_message(span_notice("[user] attempts to [apply_method] [src].")) + if(self_delay) + if(!do_after(user, self_delay, target_mob)) + return ITEM_INTERACT_BLOCKING + to_chat(target_mob, span_notice("You [apply_method] [src].")) + else + target_mob.visible_message(span_danger("[user] attempts to force [target_mob] to [apply_method] [src]."), \ + span_userdanger("[user] attempts to force you to [apply_method] [src].")) + if(!do_after(user, CHEM_INTERACT_DELAY(3 SECONDS, user), target_mob)) + return ITEM_INTERACT_BLOCKING + target_mob.visible_message(span_danger("[user] forces [target_mob] to [apply_method] [src]."), \ + span_userdanger("[user] forces you to [apply_method] [src].")) + on_consumption(target_mob, user) + return ITEM_INTERACT_SUCCESS + if(!dissolvable || !target.is_refillable()) return NONE + if(target.is_drainable() && !target.reagents.total_volume) to_chat(user, span_warning("[target] is empty! There's nothing to dissolve [src] in.")) return ITEM_INTERACT_BLOCKING + if(target.reagents.holder_full()) to_chat(user, span_warning("[target] is full.")) return ITEM_INTERACT_BLOCKING @@ -277,10 +276,9 @@ if(prob(30)) desc = pick(descs) -/obj/item/reagent_containers/pill/maintenance/achievement/on_consumption(mob/M, mob/user) +/obj/item/reagent_containers/pill/maintenance/achievement/on_consumption(mob/consumer, mob/user) . = ..() - - M.client?.give_award(/datum/award/score/maintenance_pill, M) + consumer.client?.give_award(/datum/award/score/maintenance_pill, consumer) /obj/item/reagent_containers/pill/potassiodide name = "potassium iodide pill" diff --git a/code/modules/unit_tests/metabolizing.dm b/code/modules/unit_tests/metabolizing.dm index 53bd3277dc4..5397bc13e4f 100644 --- a/code/modules/unit_tests/metabolizing.dm +++ b/code/modules/unit_tests/metabolizing.dm @@ -28,7 +28,7 @@ // Give them enough meth to be consumed in 2 metabolizations pill.reagents.add_reagent(meth, 1.9 * initial(meth.metabolization_rate) * SSMOBS_DT) - pill.attack(user, user) + pill.interact_with_atom(user, user) user.Life(SSMOBS_DT) @@ -77,7 +77,7 @@ // Let's start with stomach metabolism pill.reagents.add_reagent(meth.type, 5) - pill.attack(pill_user, pill_user) + pill.interact_with_atom(pill_user, pill_user) // Set the metabolism efficiency to 1.0 so it transfers all reagents to the body in one go. var/obj/item/organ/stomach/pill_belly = pill_user.get_organ_slot(ORGAN_SLOT_STOMACH) @@ -105,7 +105,7 @@ // One half pill pill_two.reagents.add_reagent(meth.type, (5 * 0.5) + 1) - pill_two.attack(pill_syringe_user, pill_syringe_user) + pill_two.interact_with_atom(pill_syringe_user, pill_syringe_user) syringe.melee_attack_chain(pill_syringe_user, pill_syringe_user) // Set the metabolism efficiency to 1.0 so it transfers all reagents to the body in one go. diff --git a/code/modules/unit_tests/pills.dm b/code/modules/unit_tests/pills.dm index 234abbfe1c1..8567bf390ea 100644 --- a/code/modules/unit_tests/pills.dm +++ b/code/modules/unit_tests/pills.dm @@ -4,7 +4,7 @@ TEST_ASSERT_EQUAL(human.has_reagent(/datum/reagent/iron), FALSE, "Human somehow has iron before taking pill") - pill.attack(human, human) + pill.interact_with_atom(human, human) human.Life(SSMOBS_DT) TEST_ASSERT(human.has_reagent(/datum/reagent/iron), "Human doesn't have iron after taking pill") diff --git a/code/modules/unit_tests/reagent_mob_expose.dm b/code/modules/unit_tests/reagent_mob_expose.dm index d6ed81292a9..bf31291e365 100644 --- a/code/modules/unit_tests/reagent_mob_expose.dm +++ b/code/modules/unit_tests/reagent_mob_expose.dm @@ -50,7 +50,7 @@ TEST_ASSERT_EQUAL(human.health, 100, "Human health did not set properly") patch.reagents.add_reagent(/datum/reagent/method_patch_test, 1) patch.self_delay = 0 - patch.attack(human, human) + patch.interact_with_atom(human, human) TEST_ASSERT_EQUAL(human.health, 90, "Human health did not update after patch was applied") // INJECT diff --git a/code/modules/unit_tests/stomach.dm b/code/modules/unit_tests/stomach.dm index 5d2b948e82b..69ef7c06628 100644 --- a/code/modules/unit_tests/stomach.dm +++ b/code/modules/unit_tests/stomach.dm @@ -18,7 +18,7 @@ //Give them meth and let it kick in pill.reagents.add_reagent(meth, 1.9 * initial(meth.metabolization_rate) * SSMOBS_DT) - pill.attack(human, human) + pill.interact_with_atom(human, human) human.Life(SSMOBS_DT) TEST_ASSERT(human.reagents.has_reagent(meth), "Human body does not have meth after life tick")