From 99fa98f437e8d23cd59521ac5f923876d9b2b88e Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Thu, 30 Apr 2020 15:40:41 -0400 Subject: [PATCH] Get your clicks out of my movement code --- code/_onclick/ai.dm | 2 +- code/_onclick/click.dm | 17 +++++++---------- code/_onclick/cyborg.dm | 2 +- code/_onclick/hud/action.dm | 2 +- code/_onclick/hud/screen_objects.dm | 6 +++--- code/_onclick/observer.dm | 2 +- code/_onclick/rig.dm | 2 +- code/modules/ai/interfaces.dm | 6 +++--- code/modules/client/client defines.dm | 1 - code/modules/mob/living/carbon/human/human.dm | 2 +- code/modules/mob/living/living.dm | 2 +- code/modules/mob/mob.dm | 2 +- code/modules/mob/mob_defines.dm | 3 +-- code/modules/mob/mob_grab.dm | 2 +- .../projectiles/targeting/targeting_triggers.dm | 2 +- 15 files changed, 24 insertions(+), 29 deletions(-) diff --git a/code/_onclick/ai.dm b/code/_onclick/ai.dm index c5c48dbbf2c..f3ada6e48c7 100644 --- a/code/_onclick/ai.dm +++ b/code/_onclick/ai.dm @@ -51,7 +51,7 @@ CtrlClickOn(A) return - if(control_disabled || !canClick()) + if(control_disabled || !checkClickCooldown()) return if(aiCamera.in_camera_mode) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index ea40e3dc0e0..23269f5bab4 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -38,10 +38,10 @@ * mob/RangedAttack(atom,params) - used only ranged, only used for tk and laser eyes but could be changed */ /mob/proc/ClickOn(var/atom/A, var/params) - if(world.time <= next_click) // Hard check, before anything else, to avoid crashing + if(!checkClickCooldown()) // Hard check, before anything else, to avoid crashing return - next_click = world.time + 1 + setClickCooldown(1) if(client && client.buildmode) build_click(src, client.buildmode, params, A) @@ -69,9 +69,6 @@ face_atom(A) // change direction to face what you clicked on - if(!canClick()) // in the year 2000... - return - if(istype(loc, /obj/mecha)) if(!locate(/turf) in list(A, A.loc)) // Prevents inventory from being drilled return @@ -156,12 +153,12 @@ return 1 /mob/proc/setClickCooldown(var/timeout) - next_move = max(world.time + timeout, next_move) + next_click = max(world.time + timeout, next_click) -/mob/proc/canClick() - if(config.no_click_cooldown || next_move <= world.time) - return 1 - return 0 +/mob/proc/checkClickCooldown() + if(next_click > world.time && !config.no_click_cooldown) + return FALSE + return TRUE // Default behavior: ignore double clicks, the second click that makes the doubleclick call already calls for a normal click /mob/proc/DblClickOn(var/atom/A, var/params) diff --git a/code/_onclick/cyborg.dm b/code/_onclick/cyborg.dm index f8bce398a64..a9de2897e84 100644 --- a/code/_onclick/cyborg.dm +++ b/code/_onclick/cyborg.dm @@ -35,7 +35,7 @@ if(stat || lockdown || weakened || stunned || paralysis) return - if(!canClick()) + if(!checkClickCooldown()) return face_atom(A) // change direction to face what you clicked on diff --git a/code/_onclick/hud/action.dm b/code/_onclick/hud/action.dm index b5299cd77b1..c123790b51c 100644 --- a/code/_onclick/hud/action.dm +++ b/code/_onclick/hud/action.dm @@ -123,7 +123,7 @@ if(modifiers["shift"]) moved = 0 return 1 - if(usr.next_move >= world.time) // Is this needed ? + if(!usr.checkClickCooldown()) return owner.Trigger() return 1 diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm index 2c6408cf7f2..e82d3ea5f69 100644 --- a/code/_onclick/hud/screen_objects.dm +++ b/code/_onclick/hud/screen_objects.dm @@ -54,7 +54,7 @@ /obj/screen/item_action/Click() if(!usr || !owner) return 1 - if(!usr.canClick()) + if(!usr.checkClickCooldown()) return if(usr.stat || usr.restrained() || usr.stunned || usr.lying) @@ -85,7 +85,7 @@ name = "storage" /obj/screen/storage/Click() - if(!usr.canClick()) + if(!usr.checkClickCooldown()) return 1 if(usr.stat || usr.paralysis || usr.stunned || usr.weakened) return 1 @@ -494,7 +494,7 @@ /obj/screen/inventory/Click() // At this point in client Click() code we have passed the 1/10 sec check and little else // We don't even know if it's a middle click - if(!usr.canClick()) + if(!usr.checkClickCooldown()) return 1 if(usr.stat || usr.paralysis || usr.stunned || usr.weakened) return 1 diff --git a/code/_onclick/observer.dm b/code/_onclick/observer.dm index a2d3f0c92b8..88309b5074b 100644 --- a/code/_onclick/observer.dm +++ b/code/_onclick/observer.dm @@ -31,7 +31,7 @@ if(client.buildmode) build_click(src, client.buildmode, params, A) return - if(!canClick()) return + if(!checkClickCooldown()) return setClickCooldown(4) // You are responsible for checking config.ghost_interaction when you override this function // Not all of them require checking, see below diff --git a/code/_onclick/rig.dm b/code/_onclick/rig.dm index ed7a1c7e2fb..3a70c8d36de 100644 --- a/code/_onclick/rig.dm +++ b/code/_onclick/rig.dm @@ -63,7 +63,7 @@ return loc == card /mob/living/proc/HardsuitClickOn(var/atom/A, var/alert_ai = 0) - if(!can_use_rig() || !canClick()) + if(!can_use_rig() || !checkClickCooldown()) return 0 var/obj/item/weapon/rig/rig = get_rig() if(istype(rig) && !rig.offline && rig.selected_module) diff --git a/code/modules/ai/interfaces.dm b/code/modules/ai/interfaces.dm index 6cf085c52e8..787e1b4e284 100644 --- a/code/modules/ai/interfaces.dm +++ b/code/modules/ai/interfaces.dm @@ -7,12 +7,12 @@ return FALSE /mob/living/simple_mob/IAttack(atom/A) - if(!canClick()) // Still on cooldown from a "click". + if(!checkClickCooldown()) // Still on cooldown from a "click". return ATTACK_ON_COOLDOWN return attack_target(A) // This will set click cooldown. /mob/living/carbon/human/IAttack(atom/A) - if(!canClick()) // Still on cooldown from a "click". + if(!checkClickCooldown()) // Still on cooldown from a "click". return FALSE return ClickOn(A) // Except this is an actual fake "click". @@ -20,7 +20,7 @@ return FALSE /mob/living/simple_mob/IRangedAttack(atom/A) - if(!canClick()) // Still on cooldown from a "click". + if(!checkClickCooldown()) // Still on cooldown from a "click". return ATTACK_ON_COOLDOWN return shoot_target(A) diff --git a/code/modules/client/client defines.dm b/code/modules/client/client defines.dm index 527d9438fe2..1d99f83b35e 100644 --- a/code/modules/client/client defines.dm +++ b/code/modules/client/client defines.dm @@ -18,7 +18,6 @@ //OTHER// ///////// var/datum/preferences/prefs = null - //var/move_delay = 1 var/moving = null var/adminobs = null var/area = null diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 381133a2178..cb745aea2e8 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -1398,7 +1398,7 @@ set desc = "Pop a joint back into place. Extremely painful." set src in view(1) - if(!isliving(usr) || !usr.canClick()) + if(!isliving(usr) || !usr.checkClickCooldown()) return usr.setClickCooldown(20) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 48facacd984..425bf37c3e6 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -895,7 +895,7 @@ default behaviour is: set name = "Resist" set category = "IC" - if(!incapacitated(INCAPACITATION_KNOCKOUT) && canClick()) + if(!incapacitated(INCAPACITATION_KNOCKOUT) && checkClickCooldown()) setClickCooldown(20) resist_grab() if(!weakened) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 91292a4a4ae..c5238b26b0c 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -912,7 +912,7 @@ mob/proc/yank_out_object() set desc = "Remove an embedded item at the cost of bleeding and pain." set src in view(1) - if(!isliving(usr) || !usr.canClick()) + if(!isliving(usr) || !usr.checkClickCooldown()) return usr.setClickCooldown(20) diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index 27029f7e086..9091e338ab1 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -7,8 +7,7 @@ var/datum/mind/mind var/stat = 0 //Whether a mob is alive or dead. TODO: Move this to living - Nodrak - var/move_delay = null // For movement speed delays. - var/next_move = null // For click delay, despite the misleading name. + var/next_move = null // world.time when mob is next allowed to self-move. //Not in use yet var/obj/effect/organstructure/organStructure = null diff --git a/code/modules/mob/mob_grab.dm b/code/modules/mob/mob_grab.dm index 1505516631c..09469902434 100644 --- a/code/modules/mob/mob_grab.dm +++ b/code/modules/mob/mob_grab.dm @@ -239,7 +239,7 @@ return if(state == GRAB_UPGRADING) return - if(!assailant.canClick()) + if(!assailant.checkClickCooldown()) return if(world.time < (last_action + UPGRADE_COOLDOWN)) return diff --git a/code/modules/projectiles/targeting/targeting_triggers.dm b/code/modules/projectiles/targeting/targeting_triggers.dm index 3563727fc18..1b8f3fcadd1 100644 --- a/code/modules/projectiles/targeting/targeting_triggers.dm +++ b/code/modules/projectiles/targeting/targeting_triggers.dm @@ -17,7 +17,7 @@ return if(perm && (target_permissions & perm)) return - if(!owner.canClick()) + if(!owner.checkClickCooldown()) return owner.setClickCooldown(5) // Spam prevention, essentially. if(owner.a_intent == I_HELP && owner.is_preference_enabled(/datum/client_preference/safefiring))