From 84bee81790fbe0571562978a3edc5b828f82c676 Mon Sep 17 00:00:00 2001 From: nemvar Date: Sat, 7 Sep 2019 16:12:01 +0200 Subject: [PATCH] Unscrambles melee_attack_chain --- code/_onclick/item_attack.dm | 41 +++++++++++-------- code/game/objects/items/RPD.dm | 2 +- code/game/objects/items/teleportation.dm | 2 +- .../clock_items/replica_fabricator.dm | 4 +- code/modules/hydroponics/hydroitemdefines.dm | 22 +++++----- code/modules/mining/equipment/resonator.dm | 2 +- .../reagents/reagent_containers/borghydro.dm | 6 +-- code/modules/research/stock_parts.dm | 2 +- 8 files changed, 44 insertions(+), 37 deletions(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index 42998dfc0ea..84f072cedfd 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -1,19 +1,26 @@ - +/** + *This is the proc that handles the order of an item_attack. + *The order of procs called is: + *tool_act on the target. If it returns TRUE, the chain will be stopped. + *pre_attack() on src. If this returns TRUE, the chain will be stopped. + *attackby on the target. If it returns TRUE, the chain will be stopped. + *and lastly + *afterattack. The return value does not matter. + */ /obj/item/proc/melee_attack_chain(mob/user, atom/target, params) - if(!tool_attack_chain(user, target) && pre_attack(target, user, params)) - // Return 1 in attackby() to prevent afterattack() effects (when safely moving items for example) - var/resolved = target.attackby(src, user, params) - if(!resolved && target && !QDELETED(src)) - afterattack(target, user, 1, params) // 1: clicking something Adjacent - - -//Checks if the item can work as a tool, calling the appropriate tool behavior on the target -/obj/item/proc/tool_attack_chain(mob/user, atom/target) - if(!tool_behaviour) - return FALSE - - return target.tool_act(user, src, tool_behaviour) - + if(tool_behaviour && target.tool_act(user, src, tool_behaviour)) + return + if(pre_attack(target, user, params)) + return + if(target.attackby(src,user, params)) + return + if(QDELETED(src)) + stack_trace("An item got deleted while performing an item attack and did not stop melee_attack_chain.") + return + if(QDELETED(target)) + stack_trace("The target of an item attack got deleted and melee_attack_chain was not stopped.") + return + afterattack(target, user, TRUE, params) // Called when the item is in the active hand, and clicked; alternately, there is an 'activate held object' verb or you can hit pagedown. /obj/item/proc/attack_self(mob/user) @@ -23,8 +30,8 @@ /obj/item/proc/pre_attack(atom/A, mob/living/user, params) //do stuff before attackby! if(SEND_SIGNAL(src, COMSIG_ITEM_PRE_ATTACK, A, user, params) & COMPONENT_NO_ATTACK) - return FALSE - return TRUE //return FALSE to avoid calling attackby after this proc does stuff + return TRUE + return FALSE //return TRUE to avoid calling attackby after this proc does stuff // No comment /atom/proc/attackby(obj/item/W, mob/user, params) diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm index 738d0970171..6df5f8acd3e 100644 --- a/code/game/objects/items/RPD.dm +++ b/code/game/objects/items/RPD.dm @@ -367,7 +367,7 @@ GLOBAL_LIST_INIT(fluid_duct_recipes, list( make_pipe_whitelist = typecacheof(list(/obj/structure/lattice, /obj/structure/girder, /obj/item/pipe, /obj/structure/window, /obj/structure/grille)) var/can_make_pipe = (isturf(A) || is_type_in_typecache(A, make_pipe_whitelist)) - . = FALSE + . = TRUE if((mode&DESTROY_MODE) && istype(A, /obj/item/pipe) || istype(A, /obj/structure/disposalconstruct) || istype(A, /obj/structure/c_transit_tube) || istype(A, /obj/structure/c_transit_tube_pod) || istype(A, /obj/item/pipe_meter)) to_chat(user, "You start destroying a pipe...") diff --git a/code/game/objects/items/teleportation.dm b/code/game/objects/items/teleportation.dm index 4b7299318d3..49c00f103be 100644 --- a/code/game/objects/items/teleportation.dm +++ b/code/game/objects/items/teleportation.dm @@ -139,7 +139,7 @@ /obj/item/hand_tele/pre_attack(atom/target, mob/user, params) if(try_dispel_portal(target, user)) - return FALSE + return TRUE return ..() /obj/item/hand_tele/proc/try_dispel_portal(atom/target, mob/user) diff --git a/code/modules/antagonists/clockcult/clock_items/replica_fabricator.dm b/code/modules/antagonists/clockcult/clock_items/replica_fabricator.dm index 29ad8e2e39a..b5d4c1a1120 100644 --- a/code/modules/antagonists/clockcult/clock_items/replica_fabricator.dm +++ b/code/modules/antagonists/clockcult/clock_items/replica_fabricator.dm @@ -68,8 +68,8 @@ /obj/item/clockwork/replica_fabricator/pre_attack(atom/target, mob/living/user, params) if(!target || !user || !is_servant_of_ratvar(user) || istype(target, /obj/item/storage)) - return TRUE - return fabricate(target, user) + return FALSE + return !fabricate(target, user) //A note here; return values are for if we CAN BE PUT ON A TABLE, not IF WE ARE SUCCESSFUL, unless no_table_check is TRUE /obj/item/clockwork/replica_fabricator/proc/fabricate(atom/target, mob/living/user, silent, no_table_check) diff --git a/code/modules/hydroponics/hydroitemdefines.dm b/code/modules/hydroponics/hydroitemdefines.dm index c89f35c8477..6d55d9c15eb 100644 --- a/code/modules/hydroponics/hydroitemdefines.dm +++ b/code/modules/hydroponics/hydroitemdefines.dm @@ -144,17 +144,17 @@ /obj/item/scythe/pre_attack(atom/A, mob/living/user, params) if(swiping || !istype(A, /obj/structure/spacevine) || get_turf(A) == get_turf(user)) return ..() - else - var/turf/user_turf = get_turf(user) - var/dir_to_target = get_dir(user_turf, get_turf(A)) - swiping = TRUE - var/static/list/scythe_slash_angles = list(0, 45, 90, -45, -90) - for(var/i in scythe_slash_angles) - var/turf/T = get_step(user_turf, turn(dir_to_target, i)) - for(var/obj/structure/spacevine/V in T) - if(user.Adjacent(V)) - melee_attack_chain(user, V) - swiping = FALSE + var/turf/user_turf = get_turf(user) + var/dir_to_target = get_dir(user_turf, get_turf(A)) + swiping = TRUE + var/static/list/scythe_slash_angles = list(0, 45, 90, -45, -90) + for(var/i in scythe_slash_angles) + var/turf/T = get_step(user_turf, turn(dir_to_target, i)) + for(var/obj/structure/spacevine/V in T) + if(user.Adjacent(V)) + melee_attack_chain(user, V) + swiping = FALSE + return TRUE // ************************************* // Nutrient defines for hydroponics diff --git a/code/modules/mining/equipment/resonator.dm b/code/modules/mining/equipment/resonator.dm index 8fc88d65a14..e724dad76b5 100644 --- a/code/modules/mining/equipment/resonator.dm +++ b/code/modules/mining/equipment/resonator.dm @@ -45,7 +45,7 @@ /obj/item/resonator/pre_attack(atom/target, mob/user, params) if(check_allowed_items(target, 1)) CreateResonance(target, user) - return TRUE + . = ..() //resonance field, crushes rock, damages mobs /obj/effect/temp_visual/resonance diff --git a/code/modules/reagents/reagent_containers/borghydro.dm b/code/modules/reagents/reagent_containers/borghydro.dm index ee24757f55f..f555f83f6e7 100644 --- a/code/modules/reagents/reagent_containers/borghydro.dm +++ b/code/modules/reagents/reagent_containers/borghydro.dm @@ -363,10 +363,10 @@ to the arm are passed onto a stored beaker, if one exists. */ stored = container RegisterSignal(stored, COMSIG_OBJ_UPDATE_ICON, .proc/update_icon) update_icon() - return + return TRUE if(stored) stored.melee_attack_chain(user, A, params) - return + return TRUE . = ..() /obj/item/borg_beaker_holder/attackby(obj/item/W, mob/user, params) @@ -374,5 +374,5 @@ to the arm are passed onto a stored beaker, if one exists. */ W.melee_attack_chain(user, stored, params) return . = ..() - + #undef C2NAMEREAGENT diff --git a/code/modules/research/stock_parts.dm b/code/modules/research/stock_parts.dm index 78a497dacf8..15d740cf26d 100644 --- a/code/modules/research/stock_parts.dm +++ b/code/modules/research/stock_parts.dm @@ -21,7 +21,7 @@ If you create T5+ please take a pass at gene_modder.dm [L40]. Max_values MUST fi if(works_from_distance) user.Beam(T, icon_state = "rped_upgrade", time = 5) T.exchange_parts(user, src) - return FALSE + return TRUE return ..() /obj/item/storage/part_replacer/afterattack(obj/machinery/T, mob/living/user, adjacent, params)