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
/🆑
This commit is contained in:
MrMelbert
2024-06-11 21:58:09 -07:00
committed by GitHub
parent efe3f3dfef
commit ff6b41aa07
235 changed files with 3211 additions and 3231 deletions
@@ -26,20 +26,23 @@
held_gibtonite.forceMove(src)
addtimer(CALLBACK(src, PROC_REF(release_gibtonite)), GIBTONITE_GOLEM_HOLD_TIME, TIMER_DELETE_ME)
/obj/item/gibtonite_hand/afterattack(atom/target, mob/living/user, flag, params)
. = ..()
/obj/item/gibtonite_hand/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
return ranged_interact_with_atom(interacting_with, user, modifiers)
/obj/item/gibtonite_hand/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if (!held_gibtonite)
to_chat(user, span_warning("[src] fizzles, it was a dud!"))
qdel(src)
return TRUE | AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
playsound(src, 'sound/weapons/sonic_jackhammer.ogg', 50, TRUE)
held_gibtonite.forceMove(get_turf(src))
held_gibtonite.det_time = 2 SECONDS
held_gibtonite.GibtoniteReaction(user, "A [src] has targeted [target] with a thrown and primed")
held_gibtonite.throw_at(target, range = 10, speed = 3, thrower = user)
held_gibtonite.GibtoniteReaction(user, "A [src] has targeted [interacting_with] with a thrown and primed")
held_gibtonite.throw_at(interacting_with, range = 10, speed = 3, thrower = user)
held_gibtonite = null
qdel(src)
return TRUE | AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_SUCCESS
/// Called when you can't hold it in any longer and just drop it on the ground
/obj/item/gibtonite_hand/proc/release_gibtonite()
@@ -69,15 +72,17 @@
/// How accurate are you?
var/teleport_vary = 2
/obj/item/bluespace_finger/afterattack(atom/target, mob/living/user, flag, params)
. = ..()
var/turf/target_turf = get_turf(target)
/obj/item/bluespace_finger/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
return ranged_interact_with_atom(interacting_with, user, modifiers)
/obj/item/bluespace_finger/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
var/turf/target_turf = get_turf(interacting_with)
if (get_dist(target_turf, get_turf(src)) > teleport_range)
balloon_alert(user, "too far!")
return TRUE | AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
if (target_turf.is_blocked_turf(exclude_mobs = TRUE))
balloon_alert(user, "no room!")
return TRUE | AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
var/obj/effect/temp_visual/teleport_golem/landing_indicator = new(target_turf)
user.add_filter(BLUESPACE_GLOW_FILTER, 2, list("type" = "outline", "color" = COLOR_BRIGHT_BLUE, "alpha" = 0, "size" = 1))
@@ -89,7 +94,7 @@
qdel(landing_indicator)
user.remove_filter(BLUESPACE_GLOW_FILTER)
if (!did_teleport)
return
return ITEM_INTERACT_BLOCKING
var/list/valid_landing_tiles = list(target_turf)
for (var/turf/potential_landing in oview(teleport_vary, target_turf))
@@ -101,6 +106,7 @@
telefrag.Knockdown(2 SECONDS)
do_teleport(user, final_destination, asoundin = 'sound/effects/phasein.ogg', no_effects = TRUE)
qdel(src)
return ITEM_INTERACT_SUCCESS
#undef GIBTONITE_GOLEM_HOLD_TIME
#undef BLUESPACE_GLOW_FILTER
+2 -3
View File
@@ -63,9 +63,8 @@ GLOBAL_LIST_INIT(rod_recipes, list ( \
slapcraft_recipes = slapcraft_recipe_list,\
)
/obj/item/stack/rods/handle_openspace_click(turf/target, mob/user, proximity_flag, click_parameters)
if(proximity_flag)
target.attackby(src, user, click_parameters)
/obj/item/stack/rods/handle_openspace_click(turf/target, mob/user, click_parameters)
target.attackby(src, user, click_parameters)
/obj/item/stack/rods/get_main_recipes()
. = ..()
+8 -12
View File
@@ -341,20 +341,16 @@ GLOBAL_LIST_INIT(plastitaniumglass_recipes, list(
if(T && is_station_level(T.z))
SSblackbox.record_feedback("tally", "station_mess_destroyed", 1, name)
/obj/item/shard/afterattack(atom/A as mob|obj, mob/user, proximity)
. = ..()
if(!proximity || !(src in user))
/obj/item/shard/afterattack(atom/target, mob/user, click_parameters)
if(!iscarbon(user) || !user.is_holding(src))
return
if(isturf(A))
var/mob/living/carbon/jab = user
if(jab.get_all_covered_flags() & HANDS)
return
if(istype(A, /obj/item/storage))
return
var/hit_hand = ((user.active_hand_index % 2 == 0) ? "r_" : "l_") + "arm"
if(ishuman(user))
var/mob/living/carbon/human/H = user
if(!H.gloves && !HAS_TRAIT(H, TRAIT_PIERCEIMMUNE)) // golems, etc
to_chat(H, span_warning("[src] cuts into your hand!"))
H.apply_damage(force*0.5, BRUTE, hit_hand, attacking_item = src)
to_chat(user, span_warning("[src] cuts into your hand!"))
jab.apply_damage(force * 0.5, BRUTE, user.get_active_hand(), attacking_item = src)
/obj/item/shard/attackby(obj/item/item, mob/user, params)
if(istype(item, /obj/item/lightreplacer))
@@ -223,31 +223,31 @@ GLOBAL_LIST_INIT(metal_recipes, list ( \
user.put_in_inactive_hand(new_item)
return ITEM_INTERACT_SUCCESS
/obj/item/stack/sheet/iron/afterattack_secondary(atom/target, mob/user, proximity_flag, click_parameters)
if(isopenturf(target))
var/turf/open/build_on = target
if(!user.Adjacent(build_on))
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(isgroundlessturf(build_on))
user.balloon_alert(user, "can't place it here!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(build_on.is_blocked_turf())
user.balloon_alert(user, "something is blocking the tile!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(get_amount() < 2)
user.balloon_alert(user, "not enough material!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(!do_after(user, 4 SECONDS, build_on))
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(build_on.is_blocked_turf())
user.balloon_alert(user, "something is blocking the tile!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(!use(2))
user.balloon_alert(user, "not enough material!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
new/obj/structure/girder/displaced(build_on)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
return SECONDARY_ATTACK_CONTINUE_CHAIN
/obj/item/stack/sheet/iron/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
if(!isopenturf(interacting_with))
return NONE
var/turf/open/build_on = interacting_with
if(!user.Adjacent(build_on))
return ITEM_INTERACT_BLOCKING
if(isgroundlessturf(build_on))
user.balloon_alert(user, "can't place it here!")
return ITEM_INTERACT_BLOCKING
if(build_on.is_blocked_turf())
user.balloon_alert(user, "something is blocking the tile!")
return ITEM_INTERACT_BLOCKING
if(get_amount() < 2)
user.balloon_alert(user, "not enough material!")
return ITEM_INTERACT_BLOCKING
if(!do_after(user, 4 SECONDS, build_on))
return ITEM_INTERACT_BLOCKING
if(build_on.is_blocked_turf())
user.balloon_alert(user, "something is blocking the tile!")
return ITEM_INTERACT_BLOCKING
if(!use(2))
user.balloon_alert(user, "not enough material!")
return ITEM_INTERACT_BLOCKING
new/obj/structure/girder/displaced(build_on)
return ITEM_INTERACT_SUCCESS
/*
* Plasteel
+7 -12
View File
@@ -39,18 +39,13 @@
. = ..()
. += "[span_notice("You could rip a piece off by using an empty hand.")]"
/obj/item/stack/sticky_tape/afterattack(obj/item/target, mob/living/user, proximity)
if(!proximity)
return
if(!istype(target))
return
. |= AFTERATTACK_PROCESSED_ITEM
/obj/item/stack/sticky_tape/interact_with_atom(obj/item/target, mob/living/user, list/modifiers)
if(!isitem(target))
return NONE
if(target.embedding && target.embedding == conferred_embed)
to_chat(user, span_warning("[target] is already coated in [src]!"))
return .
return ITEM_INTERACT_BLOCKING
user.visible_message(span_notice("[user] begins wrapping [target] with [src]."), span_notice("You begin wrapping [target] with [src]."))
playsound(user, 'sound/items/duct_tape_rip.ogg', 50, TRUE)
@@ -63,11 +58,11 @@
to_chat(user, span_notice("You turn [target] into [O] with [src]."))
QDEL_NULL(target)
user.put_in_hands(O)
return .
return ITEM_INTERACT_SUCCESS
if(target.embedding && target.embedding == conferred_embed)
to_chat(user, span_warning("[target] is already coated in [src]!"))
return .
return ITEM_INTERACT_BLOCKING
target.embedding = conferred_embed
target.updateEmbedding()
@@ -78,7 +73,7 @@
var/obj/item/grenade/sticky_bomb = target
sticky_bomb.sticky = TRUE
return .
return ITEM_INTERACT_SUCCESS
/obj/item/stack/sticky_tape/super
name = "super sticky tape"
@@ -101,9 +101,8 @@
playsound(target_plating, 'sound/weapons/genhit.ogg', 50, TRUE)
return target_plating
/obj/item/stack/tile/handle_openspace_click(turf/target, mob/user, proximity_flag, click_parameters)
if(proximity_flag)
target.attackby(src, user, click_parameters)
/obj/item/stack/tile/handle_openspace_click(turf/target, mob/user, click_parameters)
target.attackby(src, user, click_parameters)
//Grass
/obj/item/stack/tile/grass
+32 -26
View File
@@ -102,26 +102,29 @@
/obj/item/delivery/can_be_package_wrapped()
return FALSE
/obj/item/stack/package_wrap/afterattack(obj/target, mob/user, proximity)
. = ..()
if(!proximity)
return
if(!istype(target))
return
if(target.anchored)
return
/obj/item/stack/package_wrap/storage_insert_on_interaction(datum/storage, atom/storage_holder, mob/user)
if(isitem(storage_holder))
// Don't insert if the target can be wrapped
var/obj/item/item = storage_holder
return !item.can_be_package_wrapped()
return TRUE
if(isitem(target))
. |= AFTERATTACK_PROCESSED_ITEM
var/obj/item/item = target
/obj/item/stack/package_wrap/interact_with_atom(obj/interacting_with, mob/living/user, list/modifiers)
if(!isobj(interacting_with))
return NONE
if(interacting_with.anchored)
return NONE
if(isitem(interacting_with))
var/obj/item/item = interacting_with
if(!item.can_be_package_wrapped())
balloon_alert(user, "can't be wrapped!")
return
return ITEM_INTERACT_BLOCKING
if(user.is_holding(item))
if(!user.dropItemToGround(item))
return
return ITEM_INTERACT_BLOCKING
else if(!isturf(item.loc))
return
return ITEM_INTERACT_BLOCKING
if(use(1))
var/obj/item/delivery/small/parcel = new(get_turf(item.loc))
if(user.Adjacent(item))
@@ -135,15 +138,17 @@
size = min(size, 5)
parcel.base_icon_state = "deliverypackage[size]"
parcel.update_icon()
else
return ITEM_INTERACT_BLOCKING
else if(istype(target, /obj/structure/closet))
var/obj/structure/closet/closet = target
else if(istype(interacting_with, /obj/structure/closet))
var/obj/structure/closet/closet = interacting_with
if(closet.opened)
balloon_alert(user, "can't wrap while open!")
return
return ITEM_INTERACT_BLOCKING
if(!closet.delivery_icon) //no delivery icon means unwrappable closet (e.g. body bags)
balloon_alert(user, "can't wrap!")
return
return ITEM_INTERACT_BLOCKING
if(use(3))
var/obj/item/delivery/big/parcel = new(get_turf(closet.loc))
parcel.base_icon_state = closet.delivery_icon
@@ -154,13 +159,13 @@
closet.add_fingerprint(user)
else
balloon_alert(user, "not enough paper!")
return
return ITEM_INTERACT_BLOCKING
else if(istype(target, /obj/machinery/portable_atmospherics))
var/obj/machinery/portable_atmospherics/portable_atmospherics = target
else if(istype(interacting_with, /obj/machinery/portable_atmospherics))
var/obj/machinery/portable_atmospherics/portable_atmospherics = interacting_with
if(portable_atmospherics.anchored)
balloon_alert(user, "can't wrap while anchored!")
return
return ITEM_INTERACT_BLOCKING
if(use(3))
var/obj/item/delivery/big/parcel = new(get_turf(portable_atmospherics.loc))
parcel.base_icon_state = "deliverybox"
@@ -171,14 +176,15 @@
portable_atmospherics.add_fingerprint(user)
else
balloon_alert(user, "not enough paper!")
return
return ITEM_INTERACT_BLOCKING
else
balloon_alert(user, "can't wrap!")
return
return ITEM_INTERACT_BLOCKING
user.visible_message(span_notice("[user] wraps [target]."))
user.log_message("has used [name] on [key_name(target)]", LOG_ATTACK, color="blue")
user.visible_message(span_notice("[user] wraps [interacting_with]."))
user.log_message("has used [name] on [key_name(interacting_with)]", LOG_ATTACK, color="blue")
return ITEM_INTERACT_SUCCESS
/obj/item/stack/package_wrap/use(used, transfer = FALSE, check = TRUE)
var/turf/T = get_turf(src)