Files
Bubberstation/code/modules/detectivework/evidence.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

106 lines
3.5 KiB
Plaintext

//CONTAINS: Evidence bags
/obj/item/evidencebag
name = "evidence bag"
desc = "An empty evidence bag."
icon = 'icons/obj/storage/storage.dmi'
icon_state = "evidenceobj"
inhand_icon_state = ""
w_class = WEIGHT_CLASS_TINY
/obj/item/evidencebag/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(interacting_with == loc)
return NONE
evidencebagEquip(interacting_with, user)
return ITEM_INTERACT_SUCCESS
/obj/item/evidencebag/attackby(obj/item/I, mob/user, params)
if(evidencebagEquip(I, user))
return 1
/obj/item/evidencebag/Exited(atom/movable/gone, direction)
. = ..()
cut_overlays()
update_weight_class(initial(w_class))
icon_state = initial(icon_state)
desc = initial(desc)
/obj/item/evidencebag/proc/evidencebagEquip(obj/item/I, mob/user)
if(!istype(I) || I.anchored)
return
if(loc.atom_storage && I.atom_storage)
to_chat(user, span_warning("No matter what way you try, you can't get [I] to fit inside [src]."))
return TRUE //begone infinite storage ghosts, begone from me
if(HAS_TRAIT(I, TRAIT_NO_STORAGE_INSERT))
to_chat(user, span_warning("No matter what way you try, you can't get [I] to fit inside [src]."))
return TRUE
if(istype(I, /obj/item/evidencebag))
to_chat(user, span_warning("You find putting an evidence bag in another evidence bag to be slightly absurd."))
return TRUE //now this is podracing
if(loc in I.get_all_contents()) // fixes tg #39452, evidence bags could store their own location, causing I to be stored in the bag while being present inworld still, and able to be teleported when removed.
to_chat(user, span_warning("You find putting [I] in [src] while it's still inside it quite difficult!"))
return
if(I.w_class > WEIGHT_CLASS_NORMAL)
to_chat(user, span_warning("[I] won't fit in [src]!"))
return
if(contents.len)
to_chat(user, span_warning("[src] already has something inside it!"))
return
if(!isturf(I.loc)) //If it isn't on the floor. Do some checks to see if it's in our hands or a box. Otherwise give up.
if(I.loc.atom_storage) //in a container.
I.loc.atom_storage.remove_single(user, I, src)
if(!user.is_holding(I) || HAS_TRAIT(I, TRAIT_NODROP))
return
if(QDELETED(I))
return
user.visible_message(span_notice("[user] puts [I] into [src]."), span_notice("You put [I] inside [src]."),\
span_hear("You hear a rustle as someone puts something into a plastic bag."))
icon_state = "evidence"
var/mutable_appearance/in_evidence = new(I)
in_evidence.plane = FLOAT_PLANE
in_evidence.layer = FLOAT_LAYER
in_evidence.pixel_x = 0
in_evidence.pixel_y = 0
add_overlay(in_evidence)
add_overlay("evidence") //should look nicer for transparent stuff. not really that important, but hey.
desc = "An evidence bag containing [I]. [I.desc]"
I.forceMove(src)
update_weight_class(I.w_class)
return 1
/obj/item/evidencebag/attack_self(mob/user)
if(contents.len)
var/obj/item/I = contents[1]
user.visible_message(span_notice("[user] takes [I] out of [src]."), span_notice("You take [I] out of [src]."),\
span_hear("You hear someone rustle around in a plastic bag, and remove something."))
cut_overlays() //remove the overlays
user.put_in_hands(I)
update_weight_class(WEIGHT_CLASS_TINY)
icon_state = "evidenceobj"
desc = "An empty evidence bag."
else
to_chat(user, span_notice("[src] is empty."))
icon_state = "evidenceobj"
return
/obj/item/storage/box/evidence
name = "evidence bag box"
desc = "A box claiming to contain evidence bags."
/obj/item/storage/box/evidence/PopulateContents()
for(var/i in 1 to 6)
new /obj/item/evidencebag(src)