Files
Bubberstation/code/datums/components/swabbing.dm
SkyratBot 6ecaa9a994 [MIRROR] Standardizes attack chain signal returns and fixes a tk bug (#1409)
* Standardizes attack chain signal returns and fixes a tk bug (#54475)

The attack chain is a bit of a mess, and the introduction of signals hasn't helped in simplifying it.

In order to take a step into untangling this, I re-ordered the attack signals to no longer be by source type and instead to be grouped more modularly, as they are all members of the attack chain and function similarly. They all share the trait of potentially ending the attack chain via a return, but had several different names for it. I joined it into one.

Additionally, fixed a tk bug reported by @ Timberpoes by adding a signal return check at the base of /mob/proc/RangedAttack

Lastly, removed the async call of /datum/mutation/human/telekinesis/proc/on_ranged_attack, which was added as a lazy patch to appease the linter complaining about a sleep on a signal handler (namely in /obj/singularity/attack_tk). Fixed the problem using timers.

Also cleaned some code here and there.

* Standardizes attack chain signal returns and fixes a tk bug

Co-authored-by: Rohesie <rohesie@gmail.com>
2020-10-21 07:39:32 +02:00

129 lines
4.7 KiB
Plaintext

/*!
This component is used in vat growing to swab for microbiological samples which can then be mixed with reagents in a petridish to create a culture plate.
*/
/datum/component/swabbing
///The current datums on the swab
var/list/swabbed_items
///Can we swab objs?
var/can_swab_objs
///Can we swab turfs?
var/can_swab_turfs
///Can we swab mobs?
var/can_swab_mobs
///Callback for update_icon()
var/datum/callback/update_icons
///Callback for update_overlays()
var/datum/callback/update_overlays
/datum/component/swabbing/Initialize(can_swab_objs = TRUE, can_swab_turfs = TRUE, can_swab_mobs = FALSE, datum/callback/update_icons, datum/callback/update_overlays, swab_time = 1 SECONDS, max_items = 3)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
RegisterSignal(parent, COMSIG_ITEM_PRE_ATTACK, .proc/try_to_swab)
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/examine)
RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, .proc/handle_overlays)
RegisterSignal(parent, COMSIG_ATOM_UPDATE_ICON, .proc/handle_icon)
src.can_swab_objs = can_swab_objs
src.can_swab_turfs = can_swab_turfs
src.can_swab_mobs = can_swab_mobs
src.update_icons = update_icons
src.update_overlays = update_overlays
/datum/component/swabbing/Destroy()
. = ..()
for(var/swabbed in swabbed_items)
qdel(swabbed)
QDEL_NULL(update_icons)
QDEL_NULL(update_overlays)
///Changes examine based on your sample
/datum/component/swabbing/proc/examine(datum/source, mob/user, list/examine_list)
if(LAZYLEN(swabbed_items))
examine_list += "<span class='nicegreen'>There is a microbiological sample on [parent]!</span>"
examine_list += "<span class='notice'>You can see the following micro-organisms:</span>\n"
for(var/i in swabbed_items)
var/datum/biological_sample/samp = i
for(var/organism in samp.micro_organisms)
var/datum/micro_organism/MO = organism
examine_list += MO.get_details()
///Ran when you attack an object, tries to get a swab of the object. if a swabbable surface is found it will run behavior and hopefully
/datum/component/swabbing/proc/try_to_swab(datum/source, atom/target, mob/user, params)
set waitfor = FALSE //This prevents do_after() from making this proc not return it's value.
if(istype(target, /obj/structure/table))//help how do i do this less shitty
return NONE //idk bro pls send help
if(istype(target, /obj/item/petri_dish))
if(!LAZYLEN(swabbed_items))
return NONE
var/obj/item/petri_dish/dish = target
if(dish.sample)
return
var/datum/biological_sample/deposited_sample
for(var/i in swabbed_items) //Typed in case there is a non sample on the swabbing tool because someone was fucking with swabbable element
if(!istype(i, /datum/biological_sample/))
stack_trace("Non biological sample being swabbed, no bueno.")
continue
var/datum/biological_sample/sample = i
//Collapse the samples into one sample; one gooey mess essentialy.
if(!deposited_sample)
deposited_sample = sample
else
deposited_sample.Merge(sample)
dish.deposit_sample(user, deposited_sample)
LAZYCLEARLIST(swabbed_items)
var/obj/item/I = parent
I.update_icon()
return COMPONENT_CANCEL_ATTACK_CHAIN
if(!can_swab(target))
return NONE //Just do the normal attack.
. = COMPONENT_CANCEL_ATTACK_CHAIN //Point of no return. No more attacking after this.
if(LAZYLEN(swabbed_items))
to_chat(user, "<span class='warning'>You cannot collect another sample on [parent]!</span>")
return
to_chat(user, "<span class='notice'>You start swabbing [target] for samples!</span>")
if(!do_after(user, 3 SECONDS, target)) // Start swabbing boi
return
LAZYINITLIST(swabbed_items) //If it isn't initialized, initialize it. As we need to pass it by reference
if(SEND_SIGNAL(target, COMSIG_SWAB_FOR_SAMPLES, swabbed_items) == NONE) //If we found something to swab now we let the swabbed thing handle what it would do, we just sit back and relax now.
to_chat(user, "<span class='warning'>You do not manage to find a anything on [target]!</span>")
return
to_chat(user, "<span class='nicegreen'>You manage to collect a microbiological sample from [target]!</span>")
var/obj/item/parent_item = parent
parent_item.update_icon()
///Checks if the swabbing component can swab the specific object or nots
/datum/component/swabbing/proc/can_swab(atom/target)
if(isobj(target))
return can_swab_objs
if(isturf(target))
return can_swab_turfs
if(ismob(target))
return can_swab_mobs
///Handle any special overlay cases on the item itself
/datum/component/swabbing/proc/handle_overlays(datum/source, list/overlays)
update_overlays?.Invoke(overlays, swabbed_items)
///Handle any special icon cases on the item itself
/datum/component/swabbing/proc/handle_icon(datum/source)
update_icons?.Invoke(swabbed_items)