<commit_before>/obj/machinery/iv_drip
	name = "\improper IV drip"
	icon = 'icons/obj/iv_drip.dmi'
	anchored = 0
	density = 1


/obj/machinery/iv_drip/var/mob/living/carbon/human/attached = null
/obj/machinery/iv_drip/var/mode = "give" // mode can be "give" or "take"
/obj/machinery/iv_drip/var/obj/item/weapon/reagent_containers/beaker = null

/obj/machinery/iv_drip/update_icon()
	if(src.attached)
		icon_state = "hooked"
	else
		icon_state = ""

	overlays = null

	if(beaker)
		var/datum/reagents/reagents = beaker.reagents
		if(reagents.total_volume)
			var/image/filling = image('icons/obj/iv_drip.dmi', src, "reagent")

			var/percent = round((reagents.total_volume / beaker.volume) * 100)
			switch(percent)
				if(0 to 9)		filling.icon_state = "reagent0"
				if(10 to 24) 	filling.icon_state = "reagent10"
				if(25 to 49)	filling.icon_state = "reagent25"
				if(50 to 74)	filling.icon_state = "reagent50"
				if(75 to 79)	filling.icon_state = "reagent75"
				if(80 to 90)	filling.icon_state = "reagent80"
				if(91 to INFINITY)	filling.icon_state = "reagent100"

			filling.icon += mix_color_from_reagents(reagents.reagent_list)
			overlays += filling

/obj/machinery/iv_drip/MouseDrop(over_object, src_location, over_location)
	..()

	if(attached)
		visible_message("[src.attached] is detached from \the [src]")
		src.attached = null
		src.update_icon()
		return

	if(in_range(src, usr) && ishuman(over_object) && get_dist(over_object, src) <= 1)
		visible_message("[usr] attaches \the [src] to \the [over_object].")
		src.attached = over_object
		src.update_icon()


/obj/machinery/iv_drip/attackby(obj/item/weapon/W as obj, mob/user as mob)
	if (istype(W, /obj/item/weapon/reagent_containers))
		if(!isnull(src.beaker))
			user << "There is already a reagent container loaded!"
			return

		user.drop_item()
		W.loc = src
		src.beaker = W
		user << "You attach \the [W] to \the [src]."
		src.update_icon()
		return
	else
		return ..()


/obj/machinery/iv_drip/process()
	set background = 1

	..()

	if(src.attached)
		if(!(get_dist(src, src.attached) <= 1))
			visible_message("The needle is ripped out of [src.attached], doesn't that hurt?")
			src.attached:apply_damage(3, BRUTE, pick("r_arm", "l_arm"))
			src.attached = null
			src.update_icon()
			return

	if(src.attached && src.beaker)
		// Give blood
		if(mode == "give" && src.beaker.volume > 0)
			var/transfer_amount = REAGENTS_METABOLISM
			if(istype(src.beaker, /obj/item/weapon/reagent_containers/blood))
				// speed up transfer on blood packs
				transfer_amount = 4
			src.beaker.reagents.trans_to(src.attached, transfer_amount)
			update_icon()

		// Take blood
		else if(mode == "take")
			var/amount = beaker.reagents.maximum_volume - beaker.reagents.total_volume
			amount = min(amount, 4)
			// If the beaker is full, ping
			if(amount == 0)
				if(prob(5)) visible_message("\The [src] pings.")
				return

			var/mob/living/carbon/human/T = attached

			if(!istype(T)) return
			var/datum/reagent/B = new /datum/reagent/blood
			if(!T.dna)
				return
			if(NOCLONE in T.mutations)
				return
			// If the human is losing too much blood, beep.
			if(T.vessel.get_reagent_amount("blood") < BLOOD_VOLUME_SAFE) if(prob(5))
				visible_message("\The [src] beeps loudly.")
			if(T.vessel.get_reagent_amount("blood") < amount)
				return
			B.holder = beaker
			B.volume = amount
			//set reagent data
			B.data["donor"] = T

			if(T.virus2)
				B.data["virus2"] = T.virus2.getcopy()

			B.data["blood_DNA"] = copytext(T.dna.unique_enzymes,1,0)
			if(T.resistances && T.resistances.len)
				B.data["resistances"] = T.resistances.Copy()

			B.data["blood_type"] = copytext(T.dna.b_type,1,0)

			var/list/temp_chem = list()
			for(var/datum/reagent/R in T.reagents.reagent_list)
				temp_chem += R.name
				temp_chem[R.name] = R.volume
			B.data["trace_chem"] = list2params(temp_chem)
			B.data["antibodies"] = T.antibodies

			T.vessel.remove_reagent("blood",amount) // Removes blood if human

			beaker.reagents.reagent_list += B
			beaker.reagents.update_total()
			beaker.on_reagent_change()
			beaker.reagents.handle_reactions()

/obj/machinery/iv_drip/attack_hand(mob/user as mob)
	if(src.beaker)
		src.beaker.loc = get_turf(src)
		src.beaker = null
		update_icon()
	else
		return ..()


/obj/machinery/iv_drip/verb/toggle_mode()
	set name = "Toggle Mode"
	set src in view(1)

	if(!istype(usr, /mob/living))
		usr << "\red You can't do that."
		return

	if(mode == "give")
		mode = "take"
		usr << "The IV drip is now taking blood."
	else if(mode == "take")
		mode = "give"
		usr << "The IV drip is now giving blood."

/obj/machinery/iv_drip/examine()
	set src in view()
	..()
	if (!(usr in view(2)) && usr!=src.loc) return

	if(beaker)
		usr << "\blue Attached is \a [beaker] with:"
		if(beaker.reagents && beaker.reagents.reagent_list.len)
			for(var/datum/reagent/R in beaker.reagents.reagent_list)
				usr << "\blue [R.volume] units of [R.name]"
		else
			usr << "\blue Attached is an empty [beaker]."
	else
		usr << "\blue No chemicals are attached."

	if(attached)
		usr << "\blue [attached] is attached."<commit_msg>iv drip taking blood can't be just syringe copypaste - stupid having 50 different blood-datums of 4 in volume<commit_after>/obj/machinery/iv_drip
	name = "\improper IV drip"
	icon = 'icons/obj/iv_drip.dmi'
	anchored = 0
	density = 1


/obj/machinery/iv_drip/var/mob/living/carbon/human/attached = null
/obj/machinery/iv_drip/var/mode = "give" // mode can be "give" or "take"
/obj/machinery/iv_drip/var/obj/item/weapon/reagent_containers/beaker = null

/obj/machinery/iv_drip/update_icon()
	if(src.attached)
		icon_state = "hooked"
	else
		icon_state = ""

	overlays = null

	if(beaker)
		var/datum/reagents/reagents = beaker.reagents
		if(reagents.total_volume)
			var/image/filling = image('icons/obj/iv_drip.dmi', src, "reagent")

			var/percent = round((reagents.total_volume / beaker.volume) * 100)
			switch(percent)
				if(0 to 9)		filling.icon_state = "reagent0"
				if(10 to 24) 	filling.icon_state = "reagent10"
				if(25 to 49)	filling.icon_state = "reagent25"
				if(50 to 74)	filling.icon_state = "reagent50"
				if(75 to 79)	filling.icon_state = "reagent75"
				if(80 to 90)	filling.icon_state = "reagent80"
				if(91 to INFINITY)	filling.icon_state = "reagent100"

			filling.icon += mix_color_from_reagents(reagents.reagent_list)
			overlays += filling

/obj/machinery/iv_drip/MouseDrop(over_object, src_location, over_location)
	..()

	if(attached)
		visible_message("[src.attached] is detached from \the [src]")
		src.attached = null
		src.update_icon()
		return

	if(in_range(src, usr) && ishuman(over_object) && get_dist(over_object, src) <= 1)
		visible_message("[usr] attaches \the [src] to \the [over_object].")
		src.attached = over_object
		src.update_icon()


/obj/machinery/iv_drip/attackby(obj/item/weapon/W as obj, mob/user as mob)
	if (istype(W, /obj/item/weapon/reagent_containers))
		if(!isnull(src.beaker))
			user << "There is already a reagent container loaded!"
			return

		user.drop_item()
		W.loc = src
		src.beaker = W
		user << "You attach \the [W] to \the [src]."
		src.update_icon()
		return
	else
		return ..()


/obj/machinery/iv_drip/process()
	set background = 1

	if(src.attached)
		if(!(get_dist(src, src.attached) <= 1))
			visible_message("The needle is ripped out of [src.attached], doesn't that hurt?")
			src.attached:apply_damage(3, BRUTE, pick("r_arm", "l_arm"))
			src.attached = null
			src.update_icon()
			return

	if(src.attached && src.beaker)
		// Give blood
		if(mode == "give" && src.beaker.volume > 0)
			var/transfer_amount = REAGENTS_METABOLISM
			if(istype(src.beaker, /obj/item/weapon/reagent_containers/blood))
				// speed up transfer on blood packs
				transfer_amount = 4
			src.beaker.reagents.trans_to(src.attached, transfer_amount)
			update_icon()

		// Take blood
		else if(mode == "take")
			var/amount = beaker.reagents.maximum_volume - beaker.reagents.total_volume
			amount = min(amount, 4)
			// If the beaker is full, ping
			if(amount == 0)
				if(prob(5)) visible_message("\The [src] pings.")
				return

			var/mob/living/carbon/human/T = attached

			if(!istype(T)) return
			var/datum/reagent/B
			for(var/datum/reagent/blood/Blood in beaker.reagents.reagent_list)
				if(Blood.data && Blood.data["blood_type"]==T.dna.b_type)
					B = Blood
					break
			if(!B) B = new /datum/reagent/blood
			if(!T.dna)
				return
			if(NOCLONE in T.mutations)
				return
			// If the human is losing too much blood, beep.
			if(T.vessel.get_reagent_amount("blood") < BLOOD_VOLUME_SAFE) if(prob(5))
				visible_message("\The [src] beeps loudly.")
			if(T.vessel.get_reagent_amount("blood") < amount)
				return
			B.holder = beaker
			B.volume += amount
			//set reagent data
			B.data["donor"] = T

			if(T.virus2)
				B.data["virus2"] = T.virus2.getcopy()

			B.data["blood_DNA"] = copytext(T.dna.unique_enzymes,1,0)
			if(T.resistances && T.resistances.len)
				if(B.data["resistances"])
					B.data["resistances"] |= T.resistances.Copy()
				else
					B.data["resistances"] = T.resistances.Copy()

			B.data["blood_type"] = copytext(T.dna.b_type,1,0)

			var/list/temp_chem = list()
			for(var/datum/reagent/R in T.reagents.reagent_list)
				temp_chem += R.name
				temp_chem[R.name] = R.volume
			B.data["trace_chem"] = list2params(temp_chem)
			B.data["antibodies"] |= T.antibodies

			T.vessel.remove_reagent("blood",amount) // Removes blood if human

			beaker.reagents.reagent_list |= B
			beaker.reagents.update_total()
			beaker.on_reagent_change()
			beaker.reagents.handle_reactions()
			update_icon()

/obj/machinery/iv_drip/attack_hand(mob/user as mob)
	if(src.beaker)
		src.beaker.loc = get_turf(src)
		src.beaker = null
		update_icon()
	else
		return ..()


/obj/machinery/iv_drip/verb/toggle_mode()
	set name = "Toggle Mode"
	set src in view(1)

	if(!istype(usr, /mob/living))
		usr << "\red You can't do that."
		return

	if(mode == "give")
		mode = "take"
		usr << "The IV drip is now taking blood."
	else if(mode == "take")
		mode = "give"
		usr << "The IV drip is now giving blood."

/obj/machinery/iv_drip/examine()
	set src in view()
	..()
	if (!(usr in view(2)) && usr!=src.loc) return

	if(mode == "take")
		usr << "The IV drip is taking blood."
	else if(mode == "give")
		usr << "The IV drip is injecting."

	if(beaker)
		usr << "\blue Attached is \a [beaker] with:"
		if(beaker.reagents && beaker.reagents.reagent_list.len)
			for(var/datum/reagent/R in beaker.reagents.reagent_list)
				usr << "\blue [R.volume] units of [R.name]"
		else
			usr << "\blue Attached is an empty [beaker]."
	else
		usr << "\blue No chemicals are attached."

	if(attached)
		usr << "\blue [attached] is attached."
{'fraction_non_alphanumeric': 0.1475838863445182, 'fraction_numerical': 0.012057201607626881, 'mean_word_length': 3.5493197278911564, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842230', 'n_tokens_mistral': 4834, 'n_tokens_neox': 4132, 'n_words': 853}