Files
Bubberstation/code/game/objects/items/dna_probe.dm
MrMelbert ff6b41aa07 Afterattack is dead, long live Afterattack (#83818)
## About The Pull Request

- Afterattack is a very simple proc now: All it does is this, and all
it's used for is for having a convenient place to put effects an item
does after a successful attack (IE, the attack was not blocked)


![image](https://github.com/tgstation/tgstation/assets/51863163/1e70f7be-0990-4827-a60a-0c9dd0e0ee49)

- An overwhelming majority of afterattack implementations have been
moved to `interact_with_atom` or the new `ranged_interact_with_atom`

I have manually tested many of the refactored procs but there was 200+
so it's kinda hard

## Why It's Good For The Game

Afterattack is one of the worst parts of the attack chain, as it
simultaneously serves as a way of doing random interactions NOT AT ALL
related to attacks (despite the name) while ALSO serving as the defacto
way to do a ranged interaction with an item

This means careless coders (most of them) may throw stuff in afterattack
without realizing how wide reaching it is, which causes bugs. By making
two well defined, separate procs for handing adjacent vs ranged
interactions, it becomes WAY WAY WAY more easy to develop for.

If you want to do something when you click on something else and you're
adjacent, use `interact_with_atom`
If you want to do something when you click on something else and you're
not adjacent, use 'ranged_interact_with_atom`

This does result in some instances of boilerplate as shown here:


![image](https://github.com/tgstation/tgstation/assets/51863163/a7e469dd-115e-4e5b-88e0-0c664619c878)

But I think it's acceptable, feel free to oppose if you don't I'm sure
we can think of another solution

~~Additionally it makes it easier to implement swing combat. That's a
bonus I guess~~

## Changelog

🆑 Melbert
refactor: Over 200 item interactions have been refactored to use a
newer, easier-to-use system. Report any oddities with using items on
other objects you may see (such as surgery, reagent containers like cups
and spray bottles, or construction devices), especially using something
at range (such as guns or chisels)
refactor: Item-On-Modsuit interactions have changed slightly. While on
combat mode, you will attempt to "use" the item on the suit instead of
inserting it into the suit's storage. This means being on combat mode
while the suit's panel is open will block you from inserting items
entirely via click (but other methods such as hotkey, clicking on the
storage boxes, and mousedrop will still work).
refactor: The detective's scanner will now be inserted into storage
items if clicked normally, and will scan the storage item if on combat
mode
/🆑
2024-06-11 21:58:09 -07:00

140 lines
5.9 KiB
Plaintext

#define DNA_PROBE_SCAN_PLANTS (1<<0)
#define DNA_PROBE_SCAN_ANIMALS (1<<1)
#define DNA_PROBE_SCAN_HUMANS (1<<2)
/**
* DNA Probe
*
* Used for scanning DNA, and can be uploaded to a DNA vault.
*/
/obj/item/dna_probe
name = "DNA Sampler"
desc = "Can be used to take chemical and genetic samples of pretty much anything. Needs to be linked with a DNA vault first."
icon = 'icons/obj/medical/syringe.dmi'
inhand_icon_state = "sampler"
lefthand_file = 'icons/mob/inhands/equipment/medical_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/medical_righthand.dmi'
icon_state = "sampler"
item_flags = NOBLUDGEON
///Whether we have Carp DNA
var/carp_dna_loaded = FALSE
///What sources of DNA this sampler can extract from.
var/allowed_scans = DNA_PROBE_SCAN_PLANTS | DNA_PROBE_SCAN_ANIMALS | DNA_PROBE_SCAN_HUMANS
///List of all Animal DNA scanned with this sampler.
var/list/stored_dna_animal = list()
///List of all Plant DNA scanned with this sampler.
var/list/stored_dna_plants = list()
///List of all Human DNA scanned with this sampler.
var/list/stored_dna_human = list()
///weak ref to the dna vault
var/datum/weakref/dna_vault_ref
/obj/item/dna_probe/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(istype(interacting_with, /obj/machinery/dna_vault) && !dna_vault_ref?.resolve())
try_linking_vault(interacting_with, user)
else
scan_dna(interacting_with, user)
return ITEM_INTERACT_BLOCKING
/obj/item/dna_probe/proc/try_linking_vault(atom/target, mob/user)
var/obj/machinery/dna_vault/our_vault = dna_vault_ref?.resolve()
if(!our_vault)
dna_vault_ref = WEAKREF(target)//linking the dna vault with the probe
balloon_alert(user, "vault linked")
playsound(src, 'sound/machines/terminal_success.ogg', 50)
return
/obj/item/dna_probe/proc/scan_dna(atom/target, mob/user)
var/obj/machinery/dna_vault/our_vault = dna_vault_ref?.resolve()
if(!our_vault)
playsound(user, 'sound/machines/buzz-sigh.ogg', 50)
balloon_alert(user, "need database!")
return
if((allowed_scans & DNA_PROBE_SCAN_PLANTS) && istype(target, /obj/machinery/hydroponics))
var/obj/machinery/hydroponics/hydro_tray = target
if(!hydro_tray.myseed)
return
if(our_vault.plant_dna[hydro_tray.myseed.type])
to_chat(user, span_notice("Plant data is already present in vault storage."))
return
if(stored_dna_plants[hydro_tray.myseed.type])
to_chat(user, span_notice("Plant data already present in local storage."))
return
if(hydro_tray.plant_status != HYDROTRAY_PLANT_HARVESTABLE) // So it's bit harder.
to_chat(user, span_alert("Plant needs to be ready to harvest to perform full data scan.")) //Because space dna is actually magic
return .
stored_dna_plants[hydro_tray.myseed.type] = TRUE
playsound(src, 'sound/misc/compiler-stage2.ogg', 50)
balloon_alert(user, "data added")
else if((allowed_scans & DNA_PROBE_SCAN_HUMANS) && ishuman(target))
var/mob/living/carbon/human/human_target = target
if(our_vault.human_dna[human_target.dna.unique_identity])
to_chat(user, span_notice("Humanoid data already present in vault storage."))
return
if(stored_dna_human[human_target.dna.unique_identity])
to_chat(user, span_notice("Humanoid data already present in local storage."))
return
if(!(human_target.mob_biotypes & MOB_ORGANIC))
to_chat(user, span_alert("No compatible DNA detected."))
return .
stored_dna_human[human_target.dna.unique_identity] = TRUE
playsound(src, 'sound/misc/compiler-stage2.ogg', 50)
balloon_alert(user, "data added")
else if((allowed_scans & DNA_PROBE_SCAN_ANIMALS) && isliving(target))
var/static/list/non_simple_animals = typecacheof(list(/mob/living/carbon/alien))
if(isanimal_or_basicmob(target) || is_type_in_typecache(target, non_simple_animals) || ismonkey(target))
var/mob/living/living_target = target
if(our_vault.animal_dna[living_target.type])
to_chat(user, span_notice("Animal data already present in vault storage."))
return
if(stored_dna_animal[living_target.type])
to_chat(user, span_notice("Animal data already present in local storage."))
return
if(!(living_target.mob_biotypes & MOB_ORGANIC))
to_chat(user, span_alert("No compatible DNA detected."))
return .
stored_dna_animal[living_target.type] = TRUE
playsound(src, 'sound/misc/compiler-stage2.ogg', 50)
balloon_alert(user, "data added")
#define CARP_MIX_DNA_TIMER (15 SECONDS)
///Used for scanning carps, and then turning yourself into one.
/obj/item/dna_probe/carp_scanner
name = "Carp DNA Sampler"
desc = "Can be used to take chemical and genetic samples of animals."
/obj/item/dna_probe/carp_scanner/examine_more(mob/user)
. = ..()
. = list(span_notice("Using this on a Space Carp will harvest its DNA. Use it in-hand once complete to mutate it with yourself."))
/obj/item/dna_probe/carp_scanner/scan_dna(atom/target, mob/user)
if(istype(target, /mob/living/basic/carp))
carp_dna_loaded = TRUE
playsound(src, 'sound/misc/compiler-stage2.ogg', 50)
balloon_alert(user, "dna scanned")
else
return ..()
/obj/item/dna_probe/carp_scanner/attack_self(mob/user, modifiers)
. = ..()
if(!carp_dna_loaded)
to_chat(user, span_notice("Space carp DNA is required to use the self-mutation mechanism!"))
return
to_chat(user, span_notice("You pull out the needle from [src] and flip the switch, and start injecting yourself with it."))
if(!do_after(user, CARP_MIX_DNA_TIMER))
return
var/mob/living/basic/space_dragon/new_dragon = user.change_mob_type(/mob/living/basic/space_dragon, location = loc, delete_old_mob = TRUE)
new_dragon.add_filter("anger_glow", 3, list("type" = "outline", "color" = COLOR_CARP_RIFT_RED, "size" = 5))
new_dragon.add_movespeed_modifier(/datum/movespeed_modifier/dragon_rage)
priority_announce("A large organic energy flux has been recorded near of [station_name()], please stand-by.", "Lifesign Alert")
qdel(src)
#undef CARP_MIX_DNA_TIMER
#undef DNA_PROBE_SCAN_PLANTS
#undef DNA_PROBE_SCAN_ANIMALS
#undef DNA_PROBE_SCAN_HUMANS