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
+1 -1
View File
@@ -31,7 +31,7 @@
RegisterSignal(target, COMSIG_MOVABLE_IMPACT, PROC_REF(on_throw_impact))
RegisterSignal(target, COMSIG_ATOM_ON_Z_IMPACT, PROC_REF(on_z_impact))
if(shatters_as_weapon)
RegisterSignal(target, COMSIG_ITEM_POST_ATTACK_ATOM, PROC_REF(on_post_attack_atom))
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_post_attack_atom))
/datum/element/can_shatter/Detach(datum/target)
. = ..()
+10 -7
View File
@@ -17,18 +17,21 @@
src.break_chance = break_chance
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
RegisterSignal(target, COMSIG_ITEM_TOOL_ACTED, PROC_REF(on_tool_use))
/datum/element/easily_fragmented/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_ITEM_AFTERATTACK)
UnregisterSignal(target, list(COMSIG_ITEM_AFTERATTACK, COMSIG_ITEM_TOOL_ACTED))
/datum/element/easily_fragmented/proc/on_afterattack(datum/source, atom/target, mob/user, proximity_flag, click_parameters)
/datum/element/easily_fragmented/proc/on_afterattack(datum/source, atom/target, mob/user, click_parameters)
SIGNAL_HANDLER
try_break(source, user)
var/obj/item/item = source
/datum/element/easily_fragmented/proc/on_tool_use(datum/source, atom/target, mob/user, tool_type, result)
SIGNAL_HANDLER
try_break(source, user)
/datum/element/easily_fragmented/proc/try_break(obj/item/source, mob/user)
if(prob(break_chance))
user.visible_message(span_danger("[user]'s [item.name] snap[item.p_s()] into tiny pieces in [user.p_their()] hand."))
item.deconstruct(disassembled = FALSE)
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
user.visible_message(span_danger("[user]'s [source.name] snap[source.p_s()] into tiny pieces in [user.p_their()] hand."))
source.deconstruct(disassembled = FALSE)
+8 -9
View File
@@ -15,7 +15,7 @@
if(!istype(target, /obj/item/ammo_casing))
return ELEMENT_INCOMPATIBLE
src.amount_allowed = amount_allowed
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
RegisterSignal(target, COMSIG_ITEM_INTERACTING_WITH_ATOM, PROC_REF(handle_interaction))
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine_before_dip))
/datum/element/envenomable_casing/Detach(datum/target)
@@ -23,28 +23,29 @@
UnregisterSignal(target, list(COMSIG_ITEM_AFTERATTACK, COMSIG_ATOM_EXAMINE))
///signal called on the parent attacking an item
/datum/element/envenomable_casing/proc/on_afterattack(obj/item/ammo_casing/casing, atom/target, mob/user, proximity_flag, click_parameters)
/datum/element/envenomable_casing/proc/handle_interaction(obj/item/ammo_casing/casing, mob/user, atom/target, click_parameters)
SIGNAL_HANDLER
if(!is_reagent_container(target))
return
return NONE
var/obj/item/reagent_containers/venom_container = target
if(!casing.loaded_projectile)
user.balloon_alert(user, "casing is already spent!")
return
return ITEM_INTERACT_BLOCKING
if(!(venom_container.reagent_flags & OPENCONTAINER))
user.balloon_alert(user, "open the container!")
return
return ITEM_INTERACT_BLOCKING
var/datum/reagent/venom_applied = venom_container.reagents.get_master_reagent()
if(!venom_applied)
return
return ITEM_INTERACT_BLOCKING
var/amount_applied = min(venom_applied.volume, amount_allowed)
casing.loaded_projectile.AddElement(/datum/element/venomous, venom_applied.type, amount_applied)
to_chat(user, span_notice("You coat [casing] in [venom_applied]."))
venom_container.reagents.remove_reagent(venom_applied.type, amount_applied)
///stops further poison application
UnregisterSignal(casing, COMSIG_ITEM_AFTERATTACK)
UnregisterSignal(casing, COMSIG_ITEM_INTERACTING_WITH_ATOM)
RegisterSignal(casing, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine_after_dip), override = TRUE)
return ITEM_INTERACT_SUCCESS
///signal called on parent being examined while not coated
/datum/element/envenomable_casing/proc/on_examine_before_dip(obj/item/ammo_casing/casing, mob/user, list/examine_list)
@@ -55,5 +56,3 @@
/datum/element/envenomable_casing/proc/on_examine_after_dip(obj/item/ammo_casing/casing, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_warning("It's coated in some kind of chemical...")
+8 -10
View File
@@ -10,29 +10,27 @@
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
dunk_amount = amount_per_dunk
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(get_dunked))
RegisterSignal(target, COMSIG_ITEM_INTERACTING_WITH_ATOM, PROC_REF(get_dunked))
/datum/element/dunkable/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_ITEM_AFTERATTACK)
UnregisterSignal(target, COMSIG_ITEM_INTERACTING_WITH_ATOM)
/datum/element/dunkable/proc/get_dunked(datum/source, atom/target, mob/user, proximity_flag)
/datum/element/dunkable/proc/get_dunked(datum/source, mob/user, atom/target, params)
SIGNAL_HANDLER
if(!proximity_flag) // if the user is not adjacent to the container
return
var/obj/item/reagent_containers/container = target // the container we're trying to dunk into
if(istype(container) && container.reagent_flags & DUNKABLE) // container should be a valid target for dunking
. = COMPONENT_AFTERATTACK_PROCESSED_ITEM
if(istype(container) && (container.reagent_flags & DUNKABLE)) // container should be a valid target for dunking
if(!container.is_drainable())
to_chat(user, span_warning("[container] is unable to be dunked in!"))
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
var/obj/item/I = source // the item that has the dunkable element
if(container.reagents.trans_to(I, dunk_amount, transferred_by = user)) //if reagents were transferred, show the message
to_chat(user, span_notice("You dunk \the [I] into \the [container]."))
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_SUCCESS
if(!container.reagents.total_volume)
to_chat(user, span_warning("[container] is empty!"))
else
to_chat(user, span_warning("[I] is full!"))
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
return NONE
+1 -4
View File
@@ -30,13 +30,10 @@
return ..()
/// triggered after an item attacks something
/datum/element/knockback/proc/item_afterattack(obj/item/source, atom/target, mob/user, proximity_flag, click_parameters)
/datum/element/knockback/proc/item_afterattack(obj/item/source, atom/target, mob/user, click_parameters)
SIGNAL_HANDLER
if(!proximity_flag)
return
do_knockback(target, user, get_dir(source, target))
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
/// triggered after a hostile simplemob attacks something
/datum/element/knockback/proc/hostile_attackingtarget(mob/living/simple_animal/hostile/attacker, atom/target, success)
+1 -4
View File
@@ -126,12 +126,9 @@
* - [user][/mob/living]: The mob using the source to strike the target
* - proximity: Whether the strike was in melee range so you can't eat lights from cameras
*/
/datum/element/light_eater/proc/on_afterattack(obj/item/source, atom/target, mob/living/user, proximity)
/datum/element/light_eater/proc/on_afterattack(obj/item/source, atom/target, mob/living/user)
SIGNAL_HANDLER
if(!proximity)
return NONE
eat_lights(target, source)
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
/**
* Called when a source object is used to block a thrown object, projectile, or attack
@@ -8,22 +8,22 @@
. = ..()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
RegisterSignal(target, COMSIG_ITEM_INTERACTING_WITH_ATOM, PROC_REF(divert_interaction))
/datum/element/openspace_item_click_handler/Detach(datum/source)
UnregisterSignal(source, COMSIG_ITEM_AFTERATTACK)
UnregisterSignal(source, COMSIG_ITEM_INTERACTING_WITH_ATOM)
return ..()
//Invokes the proctype with a turf above as target.
/datum/element/openspace_item_click_handler/proc/on_afterattack(obj/item/source, atom/target, mob/user, proximity_flag, click_parameters)
/datum/element/openspace_item_click_handler/proc/divert_interaction(obj/item/source, mob/user, atom/target, click_parameters)
SIGNAL_HANDLER
if(target.z == user.z)
return
return NONE
var/turf/checked_turf = get_turf(target)
while(!isnull(checked_turf))
checked_turf = GET_TURF_ABOVE(checked_turf)
if(checked_turf?.z == user.z)
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item, handle_openspace_click), checked_turf, user, user.CanReach(checked_turf, source), click_parameters)
if(checked_turf?.z == user.z && user.CanReach(checked_turf, source))
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item, handle_openspace_click), checked_turf, user, click_parameters)
break
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
+7 -10
View File
@@ -36,19 +36,16 @@ clamping the Knockback_Force value below. */
else
return default_speed
/datum/element/selfknockback/proc/Item_SelfKnockback(obj/item/I, atom/attacktarget, mob/usertarget, proximity_flag)
/datum/element/selfknockback/proc/Item_SelfKnockback(obj/item/I, atom/attacktarget, mob/usertarget)
SIGNAL_HANDLER
if(isturf(attacktarget) && !attacktarget.density)
return
if(proximity_flag || (get_dist(attacktarget, usertarget) <= I.reach))
var/knockback_force = Get_Knockback_Force(clamp(CEILING((I.force / 10), 1), 1, 5))
var/knockback_speed = Get_Knockback_Speed(clamp(knockback_force, 1, 5))
var/knockback_force = Get_Knockback_Force(clamp(CEILING((I.force / 10), 1), 1, 5))
var/knockback_speed = Get_Knockback_Speed(clamp(knockback_force, 1, 5))
var/target_angle = get_angle(attacktarget, usertarget)
var/move_target = get_ranged_target_turf(usertarget, angle2dir(target_angle), knockback_force)
usertarget.throw_at(move_target, knockback_force, knockback_speed)
usertarget.visible_message(span_warning("[usertarget] gets thrown back by the force of \the [I] impacting \the [attacktarget]!"), span_warning("The force of \the [I] impacting \the [attacktarget] sends you flying!"))
var/target_angle = get_angle(attacktarget, usertarget)
var/move_target = get_ranged_target_turf(usertarget, angle2dir(target_angle), knockback_force)
usertarget.throw_at(move_target, knockback_force, knockback_speed)
usertarget.visible_message(span_warning("[usertarget] gets thrown back by the force of \the [I] impacting \the [attacktarget]!"), span_warning("The force of \the [I] impacting \the [attacktarget] sends you flying!"))
/datum/element/selfknockback/proc/Projectile_SelfKnockback(obj/projectile/P)
SIGNAL_HANDLER