From c4ae453aedf16f9edb64c736e59b97f4bc8a2673 Mon Sep 17 00:00:00 2001 From: Joan Lung Date: Fri, 10 Feb 2017 02:25:32 -0500 Subject: [PATCH] Unfastening objects will now check constantly during the do_after (#23881) * Unfastening objects will now check constantly during the do_after for if you can * . --- .../game/gamemodes/clock_cult/clock_structure.dm | 10 ++++++---- .../clock_structures/clockwork_obelisk.dm | 5 +++-- .../clock_cult/clock_structures/ocular_warden.dm | 8 +++++--- code/game/machinery/machinery.dm | 16 ++++++++++------ code/modules/power/singularity/collector.dm | 5 +++-- code/modules/power/singularity/emitter.dm | 7 ++++--- .../modules/power/singularity/field_generator.dm | 5 +++-- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/code/game/gamemodes/clock_cult/clock_structure.dm b/code/game/gamemodes/clock_cult/clock_structure.dm index 0cd51b624e4..9a009ed0e80 100644 --- a/code/game/gamemodes/clock_cult/clock_structure.dm +++ b/code/game/gamemodes/clock_cult/clock_structure.dm @@ -72,9 +72,10 @@ . *= min(max_integrity/max(obj_integrity, 1), 4) . = round(., 0.01) -/obj/structure/destructible/clockwork/can_be_unfasten_wrench(mob/user) +/obj/structure/destructible/clockwork/can_be_unfasten_wrench(mob/user, silent) if(anchored && obj_integrity <= round(max_integrity * 0.25, 1)) - user << "[src] is too damaged to unsecure!" + if(!silent) + user << "[src] is too damaged to unsecure!" return FAILED_UNFASTEN return ..() @@ -158,9 +159,10 @@ var/powered = total_accessable_power() return powered == PROCESS_KILL ? 25 : powered //make sure we don't accidentally return the arbitrary PROCESS_KILL define -/obj/structure/destructible/clockwork/powered/can_be_unfasten_wrench(mob/user) +/obj/structure/destructible/clockwork/powered/can_be_unfasten_wrench(mob/user, silent) if(active) - user << "[src] needs to be disabled before it can be unsecured!" + if(!silent) + user << "[src] needs to be disabled before it can be unsecured!" return FAILED_UNFASTEN return ..() diff --git a/code/game/gamemodes/clock_cult/clock_structures/clockwork_obelisk.dm b/code/game/gamemodes/clock_cult/clock_structures/clockwork_obelisk.dm index caae687cd49..a52cf68ebfc 100644 --- a/code/game/gamemodes/clock_cult/clock_structures/clockwork_obelisk.dm +++ b/code/game/gamemodes/clock_cult/clock_structures/clockwork_obelisk.dm @@ -25,9 +25,10 @@ if(is_servant_of_ratvar(user) || isobserver(user)) user << "It requires [hierophant_cost]W to broadcast over the Hierophant Network, and [gateway_cost]W to open a Spatial Gateway." -/obj/structure/destructible/clockwork/powered/clockwork_obelisk/can_be_unfasten_wrench(mob/user) +/obj/structure/destructible/clockwork/powered/clockwork_obelisk/can_be_unfasten_wrench(mob/user, silent) if(active) - user << "[src] is currently sustaining a gateway!" + if(!silent) + user << "[src] is currently sustaining a gateway!" return FAILED_UNFASTEN return ..() diff --git a/code/game/gamemodes/clock_cult/clock_structures/ocular_warden.dm b/code/game/gamemodes/clock_cult/clock_structures/ocular_warden.dm index 665ef9c2fce..f2768588c68 100644 --- a/code/game/gamemodes/clock_cult/clock_structures/ocular_warden.dm +++ b/code/game/gamemodes/clock_cult/clock_structures/ocular_warden.dm @@ -32,14 +32,16 @@ /obj/structure/destructible/clockwork/ocular_warden/hulk_damage() return 25 -/obj/structure/destructible/clockwork/ocular_warden/can_be_unfasten_wrench(mob/user) +/obj/structure/destructible/clockwork/ocular_warden/can_be_unfasten_wrench(mob/user, silent) if(anchored) if(obj_integrity <= max_integrity * 0.25) - user << "[src] is too damaged to unsecure!" + if(!silent) + user << "[src] is too damaged to unsecure!" return FAILED_UNFASTEN else for(var/obj/structure/destructible/clockwork/ocular_warden/W in orange(3, src)) - user << "You sense another ocular warden too near this location. Activating this one this close would cause them to fight." + if(!silent) + user << "You sense another ocular warden too near this location. Activating this one this close would cause them to fight." return FAILED_UNFASTEN return SUCCESSFUL_UNFASTEN diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index 8722bcc0745..117a4e9e8e7 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -356,13 +356,13 @@ Class Procs: return 1 return 0 -/obj/proc/can_be_unfasten_wrench(mob/user) +/obj/proc/can_be_unfasten_wrench(mob/user, silent) //if we can unwrench this object; returns SUCCESSFUL_UNFASTEN and FAILED_UNFASTEN, which are both TRUE, or CANT_UNFASTEN, which isn't. if(!isfloorturf(loc) && !anchored) user << "[src] needs to be on the floor to be secured!" return FAILED_UNFASTEN return SUCCESSFUL_UNFASTEN -/obj/proc/default_unfasten_wrench(mob/user, obj/item/weapon/wrench/W, time = 20) +/obj/proc/default_unfasten_wrench(mob/user, obj/item/weapon/wrench/W, time = 20) //try to unwrench an object in a WONDERFUL DYNAMIC WAY if(istype(W) && !(flags & NODECONSTRUCT)) var/can_be_unfasten = can_be_unfasten_wrench(user) if(!can_be_unfasten || can_be_unfasten == FAILED_UNFASTEN) @@ -372,10 +372,7 @@ Class Procs: playsound(loc, W.usesound, 50, 1) var/prev_anchored = anchored //as long as we're the same anchored state and we're either on a floor or are anchored, toggle our anchored state - if(!time || (do_after(user, time*W.toolspeed, target = src) && anchored == prev_anchored)) - can_be_unfasten = can_be_unfasten_wrench(user) - if(!can_be_unfasten || can_be_unfasten == FAILED_UNFASTEN) - return can_be_unfasten + if(!time || do_after(user, time*W.toolspeed, target = src, extra_checks = CALLBACK(src, .proc/unfasten_wrench_check, prev_anchored, user))) user << "You [anchored ? "un" : ""]secure [src]." anchored = !anchored playsound(loc, 'sound/items/Deconstruct.ogg', 50, 1) @@ -383,6 +380,13 @@ Class Procs: return FAILED_UNFASTEN return CANT_UNFASTEN +/obj/proc/unfasten_wrench_check(prev_anchored, mob/user) //for the do_after, this checks if unfastening conditions are still valid + if(anchored != prev_anchored) + return FALSE + if(can_be_unfasten_wrench(user, TRUE) != SUCCESSFUL_UNFASTEN) //if we aren't explicitly successful, cancel the fuck out + return FALSE + return TRUE + /obj/machinery/proc/exchange_parts(mob/user, obj/item/weapon/storage/part_replacer/W) if(!istype(W)) return diff --git a/code/modules/power/singularity/collector.dm b/code/modules/power/singularity/collector.dm index 0ae72ec94c0..39338ac1473 100644 --- a/code/modules/power/singularity/collector.dm +++ b/code/modules/power/singularity/collector.dm @@ -53,9 +53,10 @@ var/global/list/rad_collectors = list() return ..() -/obj/machinery/power/rad_collector/can_be_unfasten_wrench(mob/user) +/obj/machinery/power/rad_collector/can_be_unfasten_wrench(mob/user, silent) if(loaded_tank) - user << "Remove the plasma tank first!" + if(!silent) + user << "Remove the plasma tank first!" return FAILED_UNFASTEN return ..() diff --git a/code/modules/power/singularity/emitter.dm b/code/modules/power/singularity/emitter.dm index efa688e8880..22d8204098f 100644 --- a/code/modules/power/singularity/emitter.dm +++ b/code/modules/power/singularity/emitter.dm @@ -128,7 +128,7 @@ return 1 /obj/machinery/power/emitter/attack_animal(mob/living/simple_animal/M) - if(ismegafauna(M)) + if(ismegafauna(M) && anchored) state = 0 anchored = FALSE M.visible_message("[M] rips [src] free from its moorings!") @@ -217,9 +217,10 @@ A.starting = loc A.fire() -/obj/machinery/power/emitter/can_be_unfasten_wrench(mob/user) +/obj/machinery/power/emitter/can_be_unfasten_wrench(mob/user, silent) if(state == EM_WELDED) - user << "[src] is welded to the floor!" + if(!silent) + user << "[src] is welded to the floor!" return FAILED_UNFASTEN return ..() diff --git a/code/modules/power/singularity/field_generator.dm b/code/modules/power/singularity/field_generator.dm index f68c00a6876..c81bca881b8 100644 --- a/code/modules/power/singularity/field_generator.dm +++ b/code/modules/power/singularity/field_generator.dm @@ -77,9 +77,10 @@ field_generator power level display else user << "The [src] needs to be firmly secured to the floor first!" -/obj/machinery/field/generator/can_be_unfasten_wrench(mob/user) +/obj/machinery/field/generator/can_be_unfasten_wrench(mob/user, silent) if(state == FG_WELDED) - user << "[src] is welded to the floor!" + if(!silent) + user << "[src] is welded to the floor!" return FAILED_UNFASTEN return ..()