Get your clicks out of my movement code

This commit is contained in:
Aronai Sieyes
2020-04-30 15:40:41 -04:00
parent 03e2c9b5a5
commit 99fa98f437
15 changed files with 24 additions and 29 deletions

View File

@@ -51,7 +51,7 @@
CtrlClickOn(A) CtrlClickOn(A)
return return
if(control_disabled || !canClick()) if(control_disabled || !checkClickCooldown())
return return
if(aiCamera.in_camera_mode) if(aiCamera.in_camera_mode)

View File

@@ -38,10 +38,10 @@
* mob/RangedAttack(atom,params) - used only ranged, only used for tk and laser eyes but could be changed * 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) /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 return
next_click = world.time + 1 setClickCooldown(1)
if(client && client.buildmode) if(client && client.buildmode)
build_click(src, client.buildmode, params, A) build_click(src, client.buildmode, params, A)
@@ -69,9 +69,6 @@
face_atom(A) // change direction to face what you clicked on face_atom(A) // change direction to face what you clicked on
if(!canClick()) // in the year 2000...
return
if(istype(loc, /obj/mecha)) if(istype(loc, /obj/mecha))
if(!locate(/turf) in list(A, A.loc)) // Prevents inventory from being drilled if(!locate(/turf) in list(A, A.loc)) // Prevents inventory from being drilled
return return
@@ -156,12 +153,12 @@
return 1 return 1
/mob/proc/setClickCooldown(var/timeout) /mob/proc/setClickCooldown(var/timeout)
next_move = max(world.time + timeout, next_move) next_click = max(world.time + timeout, next_click)
/mob/proc/canClick() /mob/proc/checkClickCooldown()
if(config.no_click_cooldown || next_move <= world.time) if(next_click > world.time && !config.no_click_cooldown)
return 1 return FALSE
return 0 return TRUE
// Default behavior: ignore double clicks, the second click that makes the doubleclick call already calls for a normal click // 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) /mob/proc/DblClickOn(var/atom/A, var/params)

View File

@@ -35,7 +35,7 @@
if(stat || lockdown || weakened || stunned || paralysis) if(stat || lockdown || weakened || stunned || paralysis)
return return
if(!canClick()) if(!checkClickCooldown())
return return
face_atom(A) // change direction to face what you clicked on face_atom(A) // change direction to face what you clicked on

View File

@@ -123,7 +123,7 @@
if(modifiers["shift"]) if(modifiers["shift"])
moved = 0 moved = 0
return 1 return 1
if(usr.next_move >= world.time) // Is this needed ? if(!usr.checkClickCooldown())
return return
owner.Trigger() owner.Trigger()
return 1 return 1

View File

@@ -54,7 +54,7 @@
/obj/screen/item_action/Click() /obj/screen/item_action/Click()
if(!usr || !owner) if(!usr || !owner)
return 1 return 1
if(!usr.canClick()) if(!usr.checkClickCooldown())
return return
if(usr.stat || usr.restrained() || usr.stunned || usr.lying) if(usr.stat || usr.restrained() || usr.stunned || usr.lying)
@@ -85,7 +85,7 @@
name = "storage" name = "storage"
/obj/screen/storage/Click() /obj/screen/storage/Click()
if(!usr.canClick()) if(!usr.checkClickCooldown())
return 1 return 1
if(usr.stat || usr.paralysis || usr.stunned || usr.weakened) if(usr.stat || usr.paralysis || usr.stunned || usr.weakened)
return 1 return 1
@@ -494,7 +494,7 @@
/obj/screen/inventory/Click() /obj/screen/inventory/Click()
// At this point in client Click() code we have passed the 1/10 sec check and little else // 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 // We don't even know if it's a middle click
if(!usr.canClick()) if(!usr.checkClickCooldown())
return 1 return 1
if(usr.stat || usr.paralysis || usr.stunned || usr.weakened) if(usr.stat || usr.paralysis || usr.stunned || usr.weakened)
return 1 return 1

View File

@@ -31,7 +31,7 @@
if(client.buildmode) if(client.buildmode)
build_click(src, client.buildmode, params, A) build_click(src, client.buildmode, params, A)
return return
if(!canClick()) return if(!checkClickCooldown()) return
setClickCooldown(4) setClickCooldown(4)
// You are responsible for checking config.ghost_interaction when you override this function // You are responsible for checking config.ghost_interaction when you override this function
// Not all of them require checking, see below // Not all of them require checking, see below

View File

@@ -63,7 +63,7 @@
return loc == card return loc == card
/mob/living/proc/HardsuitClickOn(var/atom/A, var/alert_ai = 0) /mob/living/proc/HardsuitClickOn(var/atom/A, var/alert_ai = 0)
if(!can_use_rig() || !canClick()) if(!can_use_rig() || !checkClickCooldown())
return 0 return 0
var/obj/item/weapon/rig/rig = get_rig() var/obj/item/weapon/rig/rig = get_rig()
if(istype(rig) && !rig.offline && rig.selected_module) if(istype(rig) && !rig.offline && rig.selected_module)

View File

@@ -7,12 +7,12 @@
return FALSE return FALSE
/mob/living/simple_mob/IAttack(atom/A) /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_ON_COOLDOWN
return attack_target(A) // This will set click cooldown. return attack_target(A) // This will set click cooldown.
/mob/living/carbon/human/IAttack(atom/A) /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 FALSE
return ClickOn(A) // Except this is an actual fake "click". return ClickOn(A) // Except this is an actual fake "click".
@@ -20,7 +20,7 @@
return FALSE return FALSE
/mob/living/simple_mob/IRangedAttack(atom/A) /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 ATTACK_ON_COOLDOWN
return shoot_target(A) return shoot_target(A)

View File

@@ -18,7 +18,6 @@
//OTHER// //OTHER//
///////// /////////
var/datum/preferences/prefs = null var/datum/preferences/prefs = null
//var/move_delay = 1
var/moving = null var/moving = null
var/adminobs = null var/adminobs = null
var/area = null var/area = null

View File

@@ -1398,7 +1398,7 @@
set desc = "Pop a joint back into place. Extremely painful." set desc = "Pop a joint back into place. Extremely painful."
set src in view(1) set src in view(1)
if(!isliving(usr) || !usr.canClick()) if(!isliving(usr) || !usr.checkClickCooldown())
return return
usr.setClickCooldown(20) usr.setClickCooldown(20)

View File

@@ -895,7 +895,7 @@ default behaviour is:
set name = "Resist" set name = "Resist"
set category = "IC" set category = "IC"
if(!incapacitated(INCAPACITATION_KNOCKOUT) && canClick()) if(!incapacitated(INCAPACITATION_KNOCKOUT) && checkClickCooldown())
setClickCooldown(20) setClickCooldown(20)
resist_grab() resist_grab()
if(!weakened) if(!weakened)

View File

@@ -912,7 +912,7 @@ mob/proc/yank_out_object()
set desc = "Remove an embedded item at the cost of bleeding and pain." set desc = "Remove an embedded item at the cost of bleeding and pain."
set src in view(1) set src in view(1)
if(!isliving(usr) || !usr.canClick()) if(!isliving(usr) || !usr.checkClickCooldown())
return return
usr.setClickCooldown(20) usr.setClickCooldown(20)

View File

@@ -7,8 +7,7 @@
var/datum/mind/mind var/datum/mind/mind
var/stat = 0 //Whether a mob is alive or dead. TODO: Move this to living - Nodrak 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 // world.time when mob is next allowed to self-move.
var/next_move = null // For click delay, despite the misleading name.
//Not in use yet //Not in use yet
var/obj/effect/organstructure/organStructure = null var/obj/effect/organstructure/organStructure = null

View File

@@ -239,7 +239,7 @@
return return
if(state == GRAB_UPGRADING) if(state == GRAB_UPGRADING)
return return
if(!assailant.canClick()) if(!assailant.checkClickCooldown())
return return
if(world.time < (last_action + UPGRADE_COOLDOWN)) if(world.time < (last_action + UPGRADE_COOLDOWN))
return return

View File

@@ -17,7 +17,7 @@
return return
if(perm && (target_permissions & perm)) if(perm && (target_permissions & perm))
return return
if(!owner.canClick()) if(!owner.checkClickCooldown())
return return
owner.setClickCooldown(5) // Spam prevention, essentially. owner.setClickCooldown(5) // Spam prevention, essentially.
if(owner.a_intent == I_HELP && owner.is_preference_enabled(/datum/client_preference/safefiring)) if(owner.a_intent == I_HELP && owner.is_preference_enabled(/datum/client_preference/safefiring))