From 3f30b6d8ee1fd7e070f8111398acd5a4876033a6 Mon Sep 17 00:00:00 2001 From: Xander3359 <66163761+Xander3359@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:35:09 -0400 Subject: [PATCH 1/4] fix input locking melee --- code/__HELPERS/mobs.dm | 2 +- code/_onclick/ai.dm | 4 ++-- code/_onclick/click.dm | 8 +++----- code/_onclick/item_attack.dm | 5 ++++- code/datums/elements/directional_attack.dm | 6 +++--- code/modules/mob/mob_defines.dm | 19 +++++++++++++------ 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/code/__HELPERS/mobs.dm b/code/__HELPERS/mobs.dm index 154ce017c8f6e..265fb605d0a49 100644 --- a/code/__HELPERS/mobs.dm +++ b/code/__HELPERS/mobs.dm @@ -52,7 +52,7 @@ /proc/get_playable_species() return GLOB.roundstart_species -//some additional checks as a callback for for do_afters that want to break on losing health or on the mob taking action +///some additional checks as a callback for for do_afters that want to break on losing health or on the mob taking action /mob/proc/break_do_after_checks(list/checked_health, check_clicks, selected_zone_check) if(check_clicks && next_move > world.time) return FALSE diff --git a/code/_onclick/ai.dm b/code/_onclick/ai.dm index c497504c73357..348d99b4f3df4 100644 --- a/code/_onclick/ai.dm +++ b/code/_onclick/ai.dm @@ -32,9 +32,9 @@ /mob/living/silicon/ai/ClickOn(atom/A, location, params) - if(world.time <= next_click) + if(world.time <= last_click) return - next_click = world.time + 1 + last_click = world.time + 1 if(SEND_SIGNAL(src, COMSIG_MOB_CLICKON, A, params) & COMSIG_MOB_CLICK_CANCELED) return diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index a596bc18f3af5..207623d033d0c 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -2,12 +2,11 @@ * Delays the mob's next click/action by num deciseconds * eg: 10 - 3 = 7 deciseconds of delay * eg: 10 * 0.5 = 5 deciseconds of delay - * DOES NOT EFFECT THE BASE 1 DECISECOND DELAY OF NEXT_CLICK + * DOES NOT EFFECT THE BASE 1 DECISECOND DELAY OF last_click */ /mob/proc/changeNext_move(num) next_move = world.time + ((num + next_move_adjust) * next_move_modifier) - /* Before anything else, defer these calls to a per-mobtype handler. This allows us to remove istype() spaghetti code, but requires the addition of other handler procs to simplify it. @@ -47,10 +46,9 @@ * * mob/RangedAttack(atom, params) - used only ranged, only used for tk and laser eyes but could be changed */ /mob/proc/ClickOn(atom/A, location, params) - - if(world.time <= next_click) + if(world.time <= last_click) return - next_click = world.time + 1 + last_click = world.time + 1 if(check_click_intercept(params, A)) return diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index 7ba947e7233c7..f01fca25457ef 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -54,6 +54,8 @@ /atom/proc/attackby(obj/item/I, mob/user, params) SIGNAL_HANDLER_DOES_SLEEP + if(user.last_attack > world.time) + return TRUE add_fingerprint(user, "attackby", I) if(SEND_SIGNAL(src, COMSIG_ATOM_ATTACKBY, I, user, params) & COMPONENT_NO_AFTERATTACK) return TRUE @@ -168,7 +170,8 @@ . = ..() if(.) return TRUE - user.changeNext_move(I.attack_speed) + user.last_attack = world.time + I.attack_speed + //user.changeNext_move(I.attack_speed) return I.attack(src, user) diff --git a/code/datums/elements/directional_attack.dm b/code/datums/elements/directional_attack.dm index 4b130aa2962c3..e719df7e18d8b 100644 --- a/code/datums/elements/directional_attack.dm +++ b/code/datums/elements/directional_attack.dm @@ -33,11 +33,11 @@ var/turf/turf_to_check = get_step(source, angle_to_dir(Get_Angle(source, clicked_atom))) if(!turf_to_check || !source.Adjacent(turf_to_check)) return - + var/mob/target_mob = locate() in turf_to_check if(!target_mob || source.faction == target_mob.faction) return - + //This is here to undo the +1 the click on the distant turf adds so we can click the mob near us - source.next_click = world.time - 1 + source.last_click = world.time - 1 INVOKE_ASYNC(source, TYPE_PROC_REF(/mob, ClickOn), target_mob, turf_to_check, click_params) diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index bf03e6b9cd394..15bc1f9179fa3 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -34,20 +34,27 @@ var/feet_blood_color var/datum/skills/skills + //Clicking vars + ///integer, stores `world.time + 1` every time you click + var/last_click = 0 + ///integer, stores the time of whenever changeNext_move() gets ran + var/next_move = 0 + ///integer, stores world.time + attack_speed whenever attack is ran + var/last_attack = 0 + ///Amount to adjust action/click delays by, + or - + var/next_move_adjust = 0 + //Value to multiply action/click delays by + var/next_move_modifier = 1 + //Movement ///List of movement speed modifiers applying to this mob. Lazy list, see mob_movespeed.dm var/list/movespeed_modification ///The calculated mob speed slowdown based on the modifiers list. var/cached_multiplicative_slowdown - var/next_click = 0 - var/next_move = 0 ///Amount added during the next movement_delay(), then is reset. var/next_move_slowdown = 0 - ///Amount to adjust action/click delays by, + or - - var/next_move_adjust = 0 - //Value to multiply action/click delays by - var/next_move_modifier = 1 + var/last_move_intent var/area/lastarea var/old_x = 0 From 119dd08751cd8fe579c754e985d8384c349eb14b Mon Sep 17 00:00:00 2001 From: Xander3359 <66163761+Xander3359@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:40:43 -0400 Subject: [PATCH 2/4] some formatting + remove my commented out code --- code/_onclick/item_attack.dm | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index f01fca25457ef..cc7d7f444848e 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -11,11 +11,11 @@ return afterattack(target, user, TRUE, params) // TRUE: clicking something Adjacent -//Called before any other attack proc. +///Called before any other attack proc. /obj/item/proc/preattack(atom/target, mob/user, params) return FALSE -//Checks if the item can work as a tool, calling the appropriate tool behavior on the target +///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) switch(tool_behaviour) if(TOOL_CROWBAR) @@ -37,7 +37,6 @@ if(TOOL_FULTON) return target.fulton_act(user, src) - ///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) SEND_SIGNAL(src, COMSIG_ITEM_ATTACK_SELF, user) @@ -86,11 +85,9 @@ user.do_attack_animation(O, used_item = src) return O.attacked_by(src, user) - /atom/movable/proc/attacked_by(obj/item/attacking_item, mob/living/user, def_zone) return FALSE - /obj/attacked_by(obj/item/attacking_item, mob/living/user, def_zone) user.visible_message(span_warning("[user] hits [src] with [attacking_item]!"), span_warning("You hit [src] with [attacking_item]!"), visible_message_flags = COMBAT_MESSAGE) @@ -99,7 +96,6 @@ take_damage(power, attacking_item.damtype, MELEE, blame_mob = user) return TRUE - /obj/attack_powerloader(mob/living/user, obj/item/powerloader_clamp/attached_clamp) . = ..() if(.) @@ -124,7 +120,6 @@ span_notice("You grab [attached_clamp.loaded] with [attached_clamp].")) /mob/living/attacked_by(obj/item/attacking_item, mob/living/user, def_zone) - var/message_verb = "attacked" if(LAZYLEN(attacking_item.attack_verb)) message_verb = pick(attacking_item.attack_verb) @@ -165,24 +160,22 @@ return TRUE - /mob/living/attackby(obj/item/I, mob/living/user, params) . = ..() if(.) return TRUE user.last_attack = world.time + I.attack_speed - //user.changeNext_move(I.attack_speed) return I.attack(src, user) - -// has_proximity is TRUE if this afterattack was called on something adjacent, in your square, or on your person. -// Click parameters is the params string from byond Click() code, see that documentation. +/** + * has_proximity is TRUE if this afterattack was called on something adjacent, in your square, or on your person. + * Click parameters is the params string from byond Click() code, see that documentation. +*/ /obj/item/proc/afterattack(atom/target, mob/user, has_proximity, click_parameters) SEND_SIGNAL(src, COMSIG_ITEM_AFTERATTACK, target, user, has_proximity, click_parameters) SEND_SIGNAL(user, COMSIG_MOB_ITEM_AFTERATTACK, target, user, has_proximity, click_parameters) return - /obj/item/proc/attack(mob/living/M, mob/living/user) if(SEND_SIGNAL(src, COMSIG_ITEM_ATTACK, M, user) & COMPONENT_ITEM_NO_ATTACK) return FALSE @@ -275,9 +268,6 @@ return FALSE return FALSE - - - /////////////// ///RIGHT CLICK CODE FROM HERE /// @@ -311,14 +301,15 @@ user.changeNext_move(I.attack_speed_alternate) return I.attack_alternate(src, user) -// has_proximity is TRUE if this afterattack was called on something adjacent, in your square, or on your person. -// Click parameters is the params string from byond Click() code, see that documentation. +/** + * has_proximity is TRUE if this afterattack was called on something adjacent, in your square, or on your person. + * Click parameters is the params string from byond Click() code, see that documentation. +*/ /obj/item/proc/afterattack_alternate(atom/target, mob/user, has_proximity, click_parameters) SEND_SIGNAL(src, COMSIG_ITEM_AFTERATTACK_ALTERNATE, target, user, has_proximity, click_parameters) SEND_SIGNAL(user, COMSIG_MOB_ITEM_AFTERATTACK_ALTERNATE, target, user, has_proximity, click_parameters) return - /** * attack_alternate * From c32550fce0f7b63d561a06fef444b93e215f0135 Mon Sep 17 00:00:00 2001 From: Xander3359 <66163761+Xander3359@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:18:41 -0400 Subject: [PATCH 3/4] next_click instead of last_click --- code/_onclick/ai.dm | 4 ++-- code/_onclick/click.dm | 6 +++--- code/datums/elements/directional_attack.dm | 2 +- code/modules/mob/mob_defines.dm | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/code/_onclick/ai.dm b/code/_onclick/ai.dm index 348d99b4f3df4..c497504c73357 100644 --- a/code/_onclick/ai.dm +++ b/code/_onclick/ai.dm @@ -32,9 +32,9 @@ /mob/living/silicon/ai/ClickOn(atom/A, location, params) - if(world.time <= last_click) + if(world.time <= next_click) return - last_click = world.time + 1 + next_click = world.time + 1 if(SEND_SIGNAL(src, COMSIG_MOB_CLICKON, A, params) & COMSIG_MOB_CLICK_CANCELED) return diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 207623d033d0c..86e3d613b8da1 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -2,7 +2,7 @@ * Delays the mob's next click/action by num deciseconds * eg: 10 - 3 = 7 deciseconds of delay * eg: 10 * 0.5 = 5 deciseconds of delay - * DOES NOT EFFECT THE BASE 1 DECISECOND DELAY OF last_click + * DOES NOT EFFECT THE BASE 1 DECISECOND DELAY OF next_click */ /mob/proc/changeNext_move(num) next_move = world.time + ((num + next_move_adjust) * next_move_modifier) @@ -46,9 +46,9 @@ * * mob/RangedAttack(atom, params) - used only ranged, only used for tk and laser eyes but could be changed */ /mob/proc/ClickOn(atom/A, location, params) - if(world.time <= last_click) + if(world.time <= next_click) return - last_click = world.time + 1 + next_click = world.time + 1 if(check_click_intercept(params, A)) return diff --git a/code/datums/elements/directional_attack.dm b/code/datums/elements/directional_attack.dm index e719df7e18d8b..700deac01662f 100644 --- a/code/datums/elements/directional_attack.dm +++ b/code/datums/elements/directional_attack.dm @@ -39,5 +39,5 @@ return //This is here to undo the +1 the click on the distant turf adds so we can click the mob near us - source.last_click = world.time - 1 + source.next_click = world.time - 1 INVOKE_ASYNC(source, TYPE_PROC_REF(/mob, ClickOn), target_mob, turf_to_check, click_params) diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index 15bc1f9179fa3..b544c1398ece4 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -35,8 +35,8 @@ var/datum/skills/skills //Clicking vars - ///integer, stores `world.time + 1` every time you click - var/last_click = 0 + ///integer, stores the time at which you can click again + var/next_click = 0 ///integer, stores the time of whenever changeNext_move() gets ran var/next_move = 0 ///integer, stores world.time + attack_speed whenever attack is ran From f1b9f0c981c382aa231f4fe351435fc6bc14720c Mon Sep 17 00:00:00 2001 From: Xander3359 <66163761+Xander3359@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:22:09 -0400 Subject: [PATCH 4/4] next_attack --- code/_onclick/item_attack.dm | 4 ++-- code/modules/mob/mob_defines.dm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm index 2442d401e752a..05586df3f4934 100644 --- a/code/_onclick/item_attack.dm +++ b/code/_onclick/item_attack.dm @@ -56,7 +56,7 @@ /atom/proc/attackby(obj/item/attacking_item, mob/user, params) SIGNAL_HANDLER_DOES_SLEEP - if(user.last_attack > world.time) + if(user.next_attack > world.time) return TRUE add_fingerprint(user, "attackby", attacking_item) if(SEND_SIGNAL(src, COMSIG_ATOM_ATTACKBY, attacking_item, user, params) & COMPONENT_NO_AFTERATTACK) @@ -167,7 +167,7 @@ . = ..() if(.) return TRUE - user.last_attack = world.time + I.attack_speed + user.next_attack = world.time + I.attack_speed return I.attack(src, user) /** diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index e04c6ed143eea..a697fbe4e14f3 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -40,7 +40,7 @@ ///integer, stores the time of whenever changeNext_move() gets ran var/next_move = 0 ///integer, stores world.time + attack_speed whenever attack is ran - var/last_attack = 0 + var/next_attack = 0 ///Amount to adjust action/click delays by, + or - var/next_move_adjust = 0 //Value to multiply action/click delays by