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 23:58:09 -05:00
committed by GitHub
parent efe3f3dfef
commit ff6b41aa07
235 changed files with 3211 additions and 3231 deletions
+9 -14
View File
@@ -35,26 +35,22 @@
zipline_sound = new(src)
update_appearance()
/obj/item/grapple_gun/afterattack(atom/target, mob/living/user, proximity)
. = ..()
/obj/item/grapple_gun/ranged_interact_with_atom(atom/target, mob/living/user, list/modifiers)
if(isgroundlessturf(target))
return
return NONE
if(target == user || !hooked)
return NONE
if(!lavaland_equipment_pressure_check(get_turf(user)))
user.balloon_alert(user, "gun mechanism wont work here!")
return
if(target == user || !hooked)
return
return ITEM_INTERACT_BLOCKING
if(get_dist(user, target) > 9)
user.balloon_alert(user, "too far away!")
return
return ITEM_INTERACT_BLOCKING
var/turf/attacked_atom = get_turf(target)
if(isnull(attacked_atom))
return
return ITEM_INTERACT_BLOCKING
var/list/turf_list = (get_line(user, attacked_atom) - get_turf(src))
for(var/turf/singular_turf as anything in turf_list)
@@ -66,9 +62,7 @@
break
if(user.CanReach(attacked_atom))
return
. |= AFTERATTACK_PROCESSED_ITEM
return ITEM_INTERACT_BLOCKING
var/atom/bullet = fire_projectile(/obj/projectile/grapple_hook, attacked_atom, 'sound/weapons/zipline_fire.ogg')
zipline = user.Beam(bullet, icon_state = "zipline_hook", maxdistance = 9, layer = BELOW_MOB_LAYER)
@@ -77,6 +71,7 @@
RegisterSignal(bullet, COMSIG_PREQDELETED, PROC_REF(on_grapple_fail))
zipliner = WEAKREF(user)
update_appearance()
return ITEM_INTERACT_SUCCESS
/obj/item/grapple_gun/proc/on_grapple_hit(datum/source, atom/movable/firer, atom/target, Angle)
SIGNAL_HANDLER
@@ -83,27 +83,24 @@
crusher_trophy.remove_from(src, user)
return ITEM_INTERACT_SUCCESS
/obj/item/kinetic_crusher/attack(mob/living/target, mob/living/carbon/user)
if(!HAS_TRAIT(src, TRAIT_WIELDED))
user.balloon_alert(user, "must be wielded!")
return
var/datum/status_effect/crusher_damage/crusher_damage_effect = target.has_status_effect(/datum/status_effect/crusher_damage)
if(!crusher_damage_effect)
crusher_damage_effect = target.apply_status_effect(/datum/status_effect/crusher_damage)
var/target_health = target.health
..()
for(var/obj/item/crusher_trophy/crusher_trophy as anything in trophies)
if(!QDELETED(target))
crusher_trophy.on_melee_hit(target, user)
if(!QDELETED(crusher_damage_effect) && !QDELETED(target))
crusher_damage_effect.total_damage += target_health - target.health //we did some damage, but let's not assume how much we did
/obj/item/kinetic_crusher/afterattack(mob/living/target, mob/living/user, proximity_flag, clickparams)
/obj/item/kinetic_crusher/pre_attack(atom/A, mob/living/user, params)
. = ..()
if(.)
return TRUE
if(!HAS_TRAIT(src, TRAIT_WIELDED))
user.balloon_alert(user, "must be wielded!")
return TRUE
return .
/obj/item/kinetic_crusher/afterattack(mob/living/target, mob/living/user, clickparams)
if(!isliving(target))
return
if(!proximity_flag || !isliving(target))
// Melee effect
for(var/obj/item/crusher_trophy/crusher_trophy as anything in trophies)
crusher_trophy.on_melee_hit(target, user)
if(QDELETED(target))
return
// Clear existing marks
var/valid_crusher_attack = FALSE
for(var/datum/status_effect/crusher_mark/crusher_mark_effect as anything in target.get_all_status_effect_of_id(/datum/status_effect/crusher_mark))
//this will erase ALL crusher marks, not only ones by you.
@@ -113,9 +110,8 @@
break
if(!valid_crusher_attack)
return
var/datum/status_effect/crusher_damage/crusher_damage_effect = target.has_status_effect(/datum/status_effect/crusher_damage)
if(!crusher_damage_effect)
crusher_damage_effect = target.apply_status_effect(/datum/status_effect/crusher_damage)
// Detonation effect
var/datum/status_effect/crusher_damage/crusher_damage_effect = target.has_status_effect(/datum/status_effect/crusher_damage) || target.apply_status_effect(/datum/status_effect/crusher_damage)
var/target_health = target.health
for(var/obj/item/crusher_trophy/crusher_trophy as anything in trophies)
crusher_trophy.on_mark_detonation(target, user)
@@ -128,6 +124,7 @@
var/combined_damage = detonation_damage
var/backstab_dir = get_dir(user, target)
var/def_check = target.getarmor(type = BOMB)
// Backstab bonus
if((user.dir & backstab_dir) && (target.dir & backstab_dir))
backstabbed = TRUE
combined_damage += backstab_bonus
@@ -137,24 +134,23 @@
SEND_SIGNAL(user, COMSIG_LIVING_CRUSHER_DETONATE, target, src, backstabbed)
target.apply_damage(combined_damage, BRUTE, blocked = def_check)
/obj/item/kinetic_crusher/attack_secondary(atom/target, mob/living/user, clickparams)
return SECONDARY_ATTACK_CONTINUE_CHAIN
/obj/item/kinetic_crusher/afterattack_secondary(atom/target, mob/living/user, proximity_flag, click_parameters)
/obj/item/kinetic_crusher/interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
if(!HAS_TRAIT(src, TRAIT_WIELDED))
balloon_alert(user, "wield it first!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
if(target == user)
return ITEM_INTERACT_BLOCKING
if(interacting_with == user)
balloon_alert(user, "can't aim at yourself!")
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
fire_kinetic_blast(target, user, click_parameters)
return ITEM_INTERACT_BLOCKING
fire_kinetic_blast(interacting_with, user, modifiers)
user.changeNext_move(CLICK_CD_MELEE)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
return ITEM_INTERACT_SUCCESS
/obj/item/kinetic_crusher/proc/fire_kinetic_blast(atom/target, mob/living/user, click_parameters)
/obj/item/kinetic_crusher/ranged_interact_with_atom_secondary(atom/interacting_with, mob/living/user, list/modifiers)
return interact_with_atom_secondary(interacting_with, user, modifiers)
/obj/item/kinetic_crusher/proc/fire_kinetic_blast(atom/target, mob/living/user, list/modifiers)
if(!charged)
return
var/modifiers = params2list(click_parameters)
var/turf/proj_turf = user.loc
if(!isturf(proj_turf))
return
@@ -25,27 +25,25 @@
///So you can't revive boss monsters or robots with it
var/revive_type = SENTIENCE_ORGANIC
/obj/item/lazarus_injector/afterattack(atom/target, mob/user, proximity_flag)
. = ..()
if(!loaded || !proximity_flag)
return
/obj/item/lazarus_injector/interact_with_atom(atom/target, mob/living/user, list/modifiers)
if(!loaded)
return NONE
if(SEND_SIGNAL(target, COMSIG_ATOM_ON_LAZARUS_INJECTOR, src, user) & LAZARUS_INJECTOR_USED)
return
return ITEM_INTERACT_SUCCESS
if(!isliving(target))
return
return NONE
var/mob/living/target_animal = target
if(!target_animal.compare_sentience_type(revive_type)) // Will also return false if not a basic or simple mob, which are the only two we want anyway
balloon_alert(user, "invalid creature!")
return
return ITEM_INTERACT_BLOCKING
if(target_animal.stat != DEAD)
balloon_alert(user, "it's not dead!")
return
return ITEM_INTERACT_BLOCKING
target_animal.lazarus_revive(user, malfunctioning)
expend(target_animal, user)
return ITEM_INTERACT_SUCCESS
/obj/item/lazarus_injector/proc/expend(atom/revived_target, mob/user)
user.visible_message(span_notice("[user] injects [revived_target] with [src], reviving it."))
@@ -8,24 +8,21 @@
desc = "Inject certain types of monster organs with this stabilizer to prevent their rapid decay."
w_class = WEIGHT_CLASS_TINY
/obj/item/mining_stabilizer/afterattack(obj/item/organ/target_organ, mob/user, proximity)
. = ..()
if (!proximity)
return
. |= AFTERATTACK_PROCESSED_ITEM
var/obj/item/organ/internal/monster_core/target_core = target_organ
if (!istype(target_core, /obj/item/organ/internal/monster_core))
/obj/item/mining_stabilizer/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!isorgan(interacting_with))
return NONE
var/obj/item/organ/internal/monster_core/target_core = interacting_with
if (!istype(target_core))
balloon_alert(user, "invalid target!")
return .
return ITEM_INTERACT_BLOCKING
if (!target_core.preserve())
balloon_alert(user, "organ decayed!")
return .
return ITEM_INTERACT_BLOCKING
balloon_alert(user, "organ stabilized")
qdel(src)
return .
return ITEM_INTERACT_SUCCESS
/**
* Useful organs which drop as loot from a mining creature.
@@ -135,12 +132,9 @@
icon_state = initial(icon_state)
return ..()
/obj/item/organ/internal/monster_core/afterattack(atom/target, mob/user, proximity_flag)
. = ..()
if (!proximity_flag)
return
try_apply(target, user)
return . | AFTERATTACK_PROCESSED_ITEM
/obj/item/organ/internal/monster_core/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
try_apply(interacting_with, user)
return ITEM_INTERACT_SUCCESS
/obj/item/organ/internal/monster_core/attack_self(mob/user)
if (!user.can_perform_action(src, FORBID_TELEKINESIS_REACH|ALLOW_RESTING))
+21 -22
View File
@@ -51,36 +51,33 @@ GLOBAL_LIST_EMPTY(total_extraction_beacons)
beacon_ref = WEAKREF(chosen_beacon)
balloon_alert(user, "linked!")
/obj/item/extraction_pack/afterattack(atom/movable/thing, mob/living/carbon/human/user, proximity_flag, params)
. = ..()
. |= AFTERATTACK_PROCESSED_ITEM
/obj/item/extraction_pack/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!ismovable(interacting_with))
return NONE
if(!isturf(interacting_with.loc)) // no extracting stuff inside other stuff
return NONE
var/atom/movable/thing = interacting_with
if(thing.anchored)
return NONE
. = ITEM_INTERACT_BLOCKING
var/obj/structure/extraction_point/beacon = beacon_ref?.resolve()
if(isnull(beacon))
balloon_alert(user, "not linked")
balloon_alert(user, "not linked!")
beacon_ref = null
return
return .
if(!can_use_indoors)
var/area/area = get_area(thing)
if(!area.outdoors)
balloon_alert(user, "not outdoors")
return
if(!proximity_flag || !istype(thing))
return
balloon_alert(user, "not outdoors!")
return .
if(!safe_for_living_creatures && check_for_living_mobs(thing))
to_chat(user, span_warning("[src] is not safe for use with living creatures, they wouldn't survive the trip back!"))
balloon_alert(user, "not safe!")
return
if(!isturf(thing.loc)) // no extracting stuff inside other stuff
return
if(thing.anchored || (thing.move_resist > max_force_fulton))
return .
if(thing.move_resist > max_force_fulton)
balloon_alert(user, "too heavy!")
return
return .
balloon_alert_to_viewers("attaching...")
playsound(thing, 'sound/items/zip.ogg', vol = 50, vary = TRUE)
if(isliving(thing))
@@ -89,11 +86,12 @@ GLOBAL_LIST_EMPTY(total_extraction_beacons)
to_chat(thing, span_userdanger("You are being extracted! Stand still to proceed."))
if(!do_after(user, 5 SECONDS, target = thing))
return
return .
balloon_alert_to_viewers("extracting!")
if(loc == user)
user.back?.atom_storage?.attempt_insert(src, user, force = STORAGE_SOFT_LOCKED)
if(loc == user && ishuman(user))
var/mob/living/carbon/human/human_user = user
human_user.back?.atom_storage?.attempt_insert(src, user, force = STORAGE_SOFT_LOCKED)
uses_left--
if(uses_left <= 0)
@@ -180,6 +178,7 @@ GLOBAL_LIST_EMPTY(total_extraction_beacons)
qdel(holder_obj)
if(uses_left <= 0)
qdel(src)
return ITEM_INTERACT_SUCCESS
/obj/item/fulton_core
name = "extraction beacon assembly kit"
+52 -44
View File
@@ -99,14 +99,14 @@
blink_activated = !blink_activated
to_chat(user, span_notice("You [blink_activated ? "enable" : "disable"] the blink function on [src]."))
/obj/item/hierophant_club/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
. = ..()
. |= AFTERATTACK_PROCESSED_ITEM
/obj/item/hierophant_club/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
// If our target is the beacon and the hierostaff is next to the beacon, we're trying to pick it up.
if((target == beacon) && target.Adjacent(src))
return
if(interacting_with == beacon)
return NONE
if(blink_activated)
blink.teleport(user, target)
blink.teleport(user, interacting_with)
return ITEM_INTERACT_SUCCESS
return NONE
/obj/item/hierophant_club/update_icon_state()
icon_state = inhand_icon_state = "hierophant_club[blink?.current_charges > 0 ? "_ready":""][(!QDELETED(beacon)) ? "":"_beacon"]"
@@ -795,40 +795,43 @@
var/timer = 0
var/static/list/banned_turfs = typecacheof(list(/turf/open/space, /turf/closed))
/obj/item/lava_staff/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
. = ..()
/obj/item/lava_staff/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
return interact_with_atom(interacting_with, user, modifiers)
/obj/item/lava_staff/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(timer > world.time)
return
. |= AFTERATTACK_PROCESSED_ITEM
if(is_type_in_typecache(target, banned_turfs))
return
if(target in view(user.client.view, get_turf(user)))
var/turf/open/T = get_turf(target)
if(!istype(T))
return
if(!islava(T))
var/obj/effect/temp_visual/lavastaff/L = new /obj/effect/temp_visual/lavastaff(T)
L.alpha = 0
animate(L, alpha = 255, time = create_delay)
user.visible_message(span_danger("[user] points [src] at [T]!"))
timer = world.time + create_delay + 1
if(do_after(user, create_delay, target = T))
var/old_name = T.name
if(T.TerraformTurf(turf_type, flags = CHANGETURF_INHERIT_AIR))
user.visible_message(span_danger("[user] turns \the [old_name] into [transform_string]!"))
message_admins("[ADMIN_LOOKUPFLW(user)] fired the lava staff at [ADMIN_VERBOSEJMP(T)]")
user.log_message("fired the lava staff at [AREACOORD(T)].", LOG_ATTACK)
timer = world.time + create_cooldown
playsound(T,'sound/magic/fireball.ogg', 200, TRUE)
else
timer = world.time
qdel(L)
else
return NONE
if(is_type_in_typecache(interacting_with, banned_turfs))
return NONE
if(!(interacting_with in view(user.client.view, get_turf(user))))
return NONE
var/turf/open/T = get_turf(interacting_with)
if(!istype(T))
return NONE
if(!islava(T))
var/obj/effect/temp_visual/lavastaff/L = new /obj/effect/temp_visual/lavastaff(T)
L.alpha = 0
animate(L, alpha = 255, time = create_delay)
user.visible_message(span_danger("[user] points [src] at [T]!"))
timer = world.time + create_delay + 1
if(do_after(user, create_delay, target = T))
var/old_name = T.name
if(T.TerraformTurf(reset_turf_type, flags = CHANGETURF_INHERIT_AIR))
user.visible_message(span_danger("[user] turns \the [old_name] into [reset_string]!"))
timer = world.time + reset_cooldown
if(T.TerraformTurf(turf_type, flags = CHANGETURF_INHERIT_AIR))
user.visible_message(span_danger("[user] turns \the [old_name] into [transform_string]!"))
message_admins("[ADMIN_LOOKUPFLW(user)] fired the lava staff at [ADMIN_VERBOSEJMP(T)]")
user.log_message("fired the lava staff at [AREACOORD(T)].", LOG_ATTACK)
timer = world.time + create_cooldown
playsound(T,'sound/magic/fireball.ogg', 200, TRUE)
else
timer = world.time
qdel(L)
else
var/old_name = T.name
if(T.TerraformTurf(reset_turf_type, flags = CHANGETURF_INHERIT_AIR))
user.visible_message(span_danger("[user] turns \the [old_name] into [reset_string]!"))
timer = world.time + reset_cooldown
playsound(T,'sound/magic/fireball.ogg', 200, TRUE)
return ITEM_INTERACT_SUCCESS
/obj/effect/temp_visual/lavastaff
icon_state = "lavastaff_warn"
@@ -1028,23 +1031,27 @@
affected_weather.wind_down()
user.log_message("has dispelled a storm at [AREACOORD(user_turf)].", LOG_GAME)
/obj/item/storm_staff/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
. = ..()
. |= AFTERATTACK_PROCESSED_ITEM
/obj/item/storm_staff/ranged_interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
return thunder_blast(interacting_with, user) ? ITEM_INTERACT_SUCCESS : ITEM_INTERACT_BLOCKING
/obj/item/storm_staff/afterattack(atom/target, mob/user, click_parameters)
thunder_blast(target, user)
/obj/item/storm_staff/proc/thunder_blast(atom/target, mob/user)
if(!thunder_charges)
balloon_alert(user, "needs to charge!")
return
return FALSE
var/turf/target_turf = get_turf(target)
var/area/target_area = get_area(target)
if(!target_turf || !target_area || (is_type_in_list(target_area, excluded_areas)))
balloon_alert(user, "can't bolt here!")
return
return FALSE
if(target_turf in targeted_turfs)
balloon_alert(user, "already targeted!")
return
return FALSE
if(HAS_TRAIT(user, TRAIT_PACIFISM))
balloon_alert(user, "you don't want to harm!")
return
return FALSE
var/power_boosted = FALSE
for(var/datum/weather/weather as anything in SSweather.processing)
if(weather.stage != MAIN_STAGE)
@@ -1060,6 +1067,7 @@
thunder_charges--
addtimer(CALLBACK(src, PROC_REF(recharge)), thunder_charge_time)
user.log_message("fired the staff of storms at [AREACOORD(target_turf)].", LOG_ATTACK)
return TRUE
/obj/item/storm_staff/proc/recharge(mob/user)
thunder_charges = min(thunder_charges + 1, max_thunder_charges)
+11 -13
View File
@@ -646,20 +646,18 @@ GLOBAL_LIST_INIT(sand_recipes, list(\
continue
target_airlock.lock()
/obj/item/coin/eldritch/afterattack(atom/target_atom, mob/user, proximity)
. = ..()
if(!proximity)
return
/obj/item/coin/eldritch/interact_with_atom(atom/interacting_with, mob/living/user, list/modifiers)
if(!istype(interacting_with, /obj/machinery/door/airlock))
return NONE
if(!IS_HERETIC(user))
var/mob/living/living_user = user
living_user.adjustBruteLoss(5)
living_user.adjustFireLoss(5)
return
if(istype(target_atom, /obj/machinery/door/airlock))
var/obj/machinery/door/airlock/target_airlock = target_atom
to_chat(user, span_warning("You insert [src] into the airlock."))
target_airlock.emag_act(user, src)
qdel(src)
user.adjustBruteLoss(5)
user.adjustFireLoss(5)
return ITEM_INTERACT_BLOCKING
var/obj/machinery/door/airlock/target_airlock = interacting_with
to_chat(user, span_warning("You insert [src] into the airlock."))
target_airlock.emag_act(user, src)
qdel(src)
return ITEM_INTERACT_SUCCESS
#undef GIBTONITE_QUALITY_HIGH
#undef GIBTONITE_QUALITY_LOW