From e50eb495df70fff50fb7c50c5d2c5e6131e8ffdb Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Mon, 27 Jan 2020 16:30:23 -0700 Subject: [PATCH 1/3] pre attack refactor --- code/_onclick/item_attack.dm | 40 ++++++++++--------- code/game/objects/items/RPD.dm | 2 +- code/game/objects/items/teleportation.dm | 2 +- .../clock_items/replica_fabricator.dm | 4 +- code/modules/mining/equipment/resonator.dm | 2 +- code/modules/research/stock_parts.dm | 2 +- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index cda19dbaac..2c22df63c5 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -1,19 +1,23 @@ - +/** + *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) || QDELETED(target)) + attack_qdeleted(target, user, TRUE, params) + 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 +27,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) @@ -112,7 +116,7 @@ send_item_attack_message(I, user) if(I.force) apply_damage(totitemdamage, I.damtype) //CIT CHANGE - replaces I.force with totitemdamage - if(I.damtype == BRUTE && !HAS_TRAIT(src, TRAIT_NOMARROW)) + if(I.damtype == BRUTE && !HAS_TRAIT(src, TRAIT_NOMARROW)) if(prob(33)) I.add_mob_blood(src) var/turf/location = get_turf(src) diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm index 8df1ae49de..8059e59145 100644 --- a/code/game/objects/items/RPD.dm +++ b/code/game/objects/items/RPD.dm @@ -344,7 +344,7 @@ GLOBAL_LIST_INIT(transit_tube_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 8c0f315ca3..add2d12ee6 100644 --- a/code/game/objects/items/teleportation.dm +++ b/code/game/objects/items/teleportation.dm @@ -138,7 +138,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 501bcdc1c4..7be9ef039b 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 ..() + 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/mining/equipment/resonator.dm b/code/modules/mining/equipment/resonator.dm index f63b459f10..133cb41c33 100644 --- a/code/modules/mining/equipment/resonator.dm +++ b/code/modules/mining/equipment/resonator.dm @@ -46,7 +46,7 @@ /obj/item/resonator/pre_attack(atom/target, mob/user, params) if(check_allowed_items(target, 1)) CreateResonance(target, user) - return TRUE + return ..() //resonance field, crushes rock, damages mobs /obj/effect/temp_visual/resonance diff --git a/code/modules/research/stock_parts.dm b/code/modules/research/stock_parts.dm index e29cf28f34..e5b66cd90d 100644 --- a/code/modules/research/stock_parts.dm +++ b/code/modules/research/stock_parts.dm @@ -22,7 +22,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) From 28697a375f654f92237b277218f04f94cfbb3df7 Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Mon, 27 Jan 2020 17:43:21 -0700 Subject: [PATCH 2/3] Update item_attack.dm --- code/_onclick/item_attack.dm | 1 - 1 file changed, 1 deletion(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index 2c22df63c5..3f11c8a2f2 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -15,7 +15,6 @@ if(target.attackby(src,user, params)) return if(QDELETED(src) || QDELETED(target)) - attack_qdeleted(target, user, TRUE, params) return afterattack(target, user, TRUE, params) From 3a655d71d4030745ef260ce442953fce20d24678 Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Mon, 10 Feb 2020 04:19:52 -0700 Subject: [PATCH 3/3] fix --- code/modules/awaymissions/capture_the_flag.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/modules/awaymissions/capture_the_flag.dm b/code/modules/awaymissions/capture_the_flag.dm index 3562350473..1344ee0ad3 100644 --- a/code/modules/awaymissions/capture_the_flag.dm +++ b/code/modules/awaymissions/capture_the_flag.dm @@ -470,7 +470,7 @@ /obj/item/claymore/ctf/pre_attack(atom/target, mob/user, params) if(!is_ctf_target(target)) - return FALSE + return TRUE return ..() /obj/item/claymore/ctf/dropped()