mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
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 🆑 code: Converted pills and patches into interact_with_atom /🆑
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user