From 0b98b0409b08ef44308cf23cb4122563abf32581 Mon Sep 17 00:00:00 2001
From: silicons <2003111+silicons@users.noreply.github.com>
Date: Sat, 18 Jul 2020 18:29:09 -0700
Subject: [PATCH] sigh
---
code/_onclick/click.dm | 12 +++++----
code/_onclick/hud/alert.dm | 6 ++---
code/_onclick/item_attack.dm | 7 +++---
code/game/objects/items.dm | 11 +--------
code/game/objects/items/mop.dm | 4 +--
code/game/objects/items/signs.dm | 1 -
code/game/objects/structures/grille.dm | 8 +++---
code/game/objects/structures/holosign.dm | 2 +-
code/game/turfs/simulated/walls.dm | 11 +++++----
code/modules/mob/clickdelay.dm | 31 ++++++++++++++++++++++++
10 files changed, 60 insertions(+), 33 deletions(-)
diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm
index f476d40a70..a9bc57d520 100644
--- a/code/_onclick/click.dm
+++ b/code/_onclick/click.dm
@@ -76,7 +76,7 @@
face_atom(A)
- if(next_move > world.time) // in the year 2000...
+ if(!CheckActionCooldown())
return
if(!modifiers["catcher"] && A.IsObscured())
@@ -108,8 +108,9 @@
if(W)
W.melee_attack_chain(src, A, params)
else
- if(ismob(A))
- changeNext_move(CLICK_CD_MELEE)
+ if(ismob(A) && !CheckActionCooldown(CLICK_CD_MELEE))
+ return
+ DelayNextAction()
UnarmedAttack(A)
return
@@ -122,8 +123,9 @@
if(W)
W.melee_attack_chain(src, A, params)
else
- if(ismob(A))
- changeNext_move(CLICK_CD_MELEE)
+ if(ismob(A) && !CheckActionCooldown(CLICK_CD_MELEE))
+ return
+ DelayNextAction()
UnarmedAttack(A, 1)
else
if(W)
diff --git a/code/_onclick/hud/alert.dm b/code/_onclick/hud/alert.dm
index 11531a701e..66c75bfb58 100644
--- a/code/_onclick/hud/alert.dm
+++ b/code/_onclick/hud/alert.dm
@@ -272,7 +272,7 @@ or shoot a gun to move around via Newton's 3rd Law of Motion."
var/mob/living/L = usr
if(!istype(L) || !L.can_resist())
return
- L.changeNext_move(CLICK_CD_RESIST)
+ L.last_resist = world.time
if(CHECK_MOBILITY(L, MOBILITY_MOVE))
return L.resist_fire() //I just want to start a flame in your hearrrrrrtttttt.
@@ -600,7 +600,7 @@ so as to remain in compliance with the most up-to-date laws."
var/mob/living/L = usr
if(!istype(L) || !L.can_resist())
return
- L.changeNext_move(CLICK_CD_RESIST)
+ L.last_resist = world.time
if(CHECK_MOBILITY(L, MOBILITY_MOVE) && (L.last_special <= world.time))
return L.resist_restraints()
@@ -608,7 +608,7 @@ so as to remain in compliance with the most up-to-date laws."
var/mob/living/L = usr
if(!istype(L) || !L.can_resist())
return
- L.changeNext_move(CLICK_CD_RESIST)
+ L.last_resist = world.time
if(L.last_special <= world.time)
return L.resist_buckle()
diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm
index bef06a69e9..f0667c71f1 100644
--- a/code/_onclick/item_attack.dm
+++ b/code/_onclick/item_attack.dm
@@ -21,6 +21,7 @@
return
if(QDELETED(src) || QDELETED(target))
return
+ PostattackClickdelaySet(user, target))
afterattack(target, user, TRUE, params)
/// Like melee_attack_chain but for ranged.
@@ -41,6 +42,9 @@
/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 TRUE
+ if(!PreatackClickdelayCheck(user, A))
+ return TRUE
+ PreattackClickdelaySet(user, A)
return FALSE //return TRUE to avoid calling attackby after this proc does stuff
// No comment
@@ -55,10 +59,7 @@
/mob/living/attackby(obj/item/I, mob/living/user, params, attackchain_flags, damage_multiplier)
if(..())
return TRUE
- I.attack_delay_done = FALSE //Should be set TRUE in pre_attacked_by()
. = I.attack(src, user, attackchain_flags, damage_multiplier)
- if(!I.attack_delay_done) //Otherwise, pre_attacked_by() should handle it.
- user.changeNext_move(I.click_delay)
/obj/item/proc/attack(mob/living/M, mob/living/user, attackchain_flags = NONE, damage_multiplier = 1)
if(SEND_SIGNAL(src, COMSIG_ITEM_ATTACK, M, user) & COMPONENT_ITEM_NO_ATTACK)
diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm
index 90e232938c..75115795c6 100644
--- a/code/game/objects/items.dm
+++ b/code/game/objects/items.dm
@@ -58,15 +58,6 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb
/// How long, in deciseconds, this staggers for, if null it will autocalculate from w_class and force. Unlike total mass this supports 0 and negatives.
var/stagger_force
- /**
- * Set FALSE and then checked at the end of on mob/living/attackby(), set TRUE on living/pre_attacked_by().
- * Should it be FALSE by the end of the item/attack(), that means the item overrode the standard attack behaviour
- * and the user still needs the delay applied. We can't be using return values since that'll stop afterattack() from being triggered.
- */
- var/attack_delay_done = FALSE
- ///next_move click/attack delay of this item.
- var/click_delay = CLICK_CD_MELEE
-
var/slot_flags = 0 //This is used to determine on which slots an item can fit.
var/current_equipped_slot
pass_flags = PASSTABLE
@@ -1113,4 +1104,4 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb
jostle_pain_mult = (!isnull(embedding["jostle_pain_mult"]) ? embedding["jostle_pain_mult"] : EMBEDDED_JOSTLE_PAIN_MULTIPLIER),\
pain_stam_pct = (!isnull(embedding["pain_stam_pct"]) ? embedding["pain_stam_pct"] : EMBEDDED_PAIN_STAM_PCT),\
embed_chance_turf_mod = (!isnull(embedding["embed_chance_turf_mod"]) ? embedding["embed_chance_turf_mod"] : EMBED_CHANCE_TURF_MOD))
- return TRUE
\ No newline at end of file
+ return TRUE
diff --git a/code/game/objects/items/mop.dm b/code/game/objects/items/mop.dm
index 3a06c7d7fe..b420bfc002 100644
--- a/code/game/objects/items/mop.dm
+++ b/code/game/objects/items/mop.dm
@@ -58,7 +58,7 @@
if(T)
user.visible_message("[user] cleans \the [T] with [src].", "You clean \the [T] with [src].")
clean(T)
- user.changeNext_move(CLICK_CD_MELEE)
+ user.DelayNextAction(CLICK_CD_MELEE)
user.do_attack_animation(T, used_item = src)
if(istype(L))
L.adjustStaminaLossBuffered(stamusage)
@@ -128,4 +128,4 @@
return ..()
/obj/item/mop/advanced/cyborg
- insertable = FALSE
\ No newline at end of file
+ insertable = FALSE
diff --git a/code/game/objects/items/signs.dm b/code/game/objects/items/signs.dm
index cf7373b700..67bc28b2ea 100644
--- a/code/game/objects/items/signs.dm
+++ b/code/game/objects/items/signs.dm
@@ -40,4 +40,3 @@
user.visible_message("[user] waves around \the \"[label]\" sign.")
else
user.visible_message("[user] waves around blank sign.")
- user.changeNext_move(CLICK_CD_MELEE)
\ No newline at end of file
diff --git a/code/game/objects/structures/grille.dm b/code/game/objects/structures/grille.dm
index 20151a0bdb..936b9248e8 100644
--- a/code/game/objects/structures/grille.dm
+++ b/code/game/objects/structures/grille.dm
@@ -103,7 +103,8 @@
. = ..()
if(.)
return
- user.changeNext_move(CLICK_CD_MELEE)
+ if(!M.CheckActionCooldown(CLICK_CD_MELEE))
+ return
user.do_attack_animation(src, ATTACK_EFFECT_KICK)
user.visible_message("[user] hits [src].", null, null, COMBAT_MESSAGE_RANGE)
log_combat(user, src, "hit")
@@ -111,8 +112,9 @@
take_damage(rand(5,10), BRUTE, "melee", 1)
/obj/structure/grille/attack_alien(mob/living/user)
+ if(!M.CheckActionCooldown(CLICK_CD_MELEE))
+ return
user.do_attack_animation(src)
- user.changeNext_move(CLICK_CD_MELEE)
user.visible_message("[user] mangles [src].", null, null, COMBAT_MESSAGE_RANGE)
if(!shock(user, 70))
take_damage(20, BRUTE, "melee", 1)
@@ -134,7 +136,7 @@
. = . || (mover.pass_flags & PASSGRILLE)
/obj/structure/grille/attackby(obj/item/W, mob/user, params)
- user.changeNext_move(CLICK_CD_MELEE)
+ user.DelayNextAction(CLICK_CD_MELEE)
add_fingerprint(user)
if(istype(W, /obj/item/wirecutters))
if(!shock(user, 100))
diff --git a/code/game/objects/structures/holosign.dm b/code/game/objects/structures/holosign.dm
index c49159a992..8d2f7bcbf7 100644
--- a/code/game/objects/structures/holosign.dm
+++ b/code/game/objects/structures/holosign.dm
@@ -30,7 +30,7 @@
if(.)
return
user.do_attack_animation(src, ATTACK_EFFECT_PUNCH)
- user.changeNext_move(CLICK_CD_MELEE)
+ user.DelayNextAction(CLICK_CD_MELEE)
take_damage(5 , BRUTE, "melee", 1)
/obj/structure/holosign/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
diff --git a/code/game/turfs/simulated/walls.dm b/code/game/turfs/simulated/walls.dm
index b01a1df2c0..6ac3ca086b 100644
--- a/code/game/turfs/simulated/walls.dm
+++ b/code/game/turfs/simulated/walls.dm
@@ -113,12 +113,11 @@
return FALSE
/turf/closed/wall/attack_paw(mob/living/user)
- user.changeNext_move(CLICK_CD_MELEE)
return attack_hand(user)
-
/turf/closed/wall/attack_animal(mob/living/simple_animal/M)
- M.changeNext_move(CLICK_CD_MELEE)
+ if(!M.CheckActionCooldown(CLICK_CD_MELEE))
+ return
M.do_attack_animation(src)
if((M.environment_smash & ENVIRONMENT_SMASH_WALLS) || (M.environment_smash & ENVIRONMENT_SMASH_RWALLS))
playsound(src, 'sound/effects/meteorimpact.ogg', 100, 1)
@@ -141,13 +140,15 @@
. = ..()
if(.)
return
- user.changeNext_move(CLICK_CD_MELEE)
+ if(!M.CheckActionCooldown(CLICK_CD_MELEE))
+ return
to_chat(user, "You push the wall but nothing happens!")
playsound(src, 'sound/weapons/genhit.ogg', 25, 1)
add_fingerprint(user)
/turf/closed/wall/attackby(obj/item/W, mob/user, params)
- user.changeNext_move(CLICK_CD_MELEE)
+ if(!M.CheckActionCooldown(CLICK_CD_MELEE))
+ return
if (!user.IsAdvancedToolUser())
to_chat(user, "You don't have the dexterity to do this!")
return
diff --git a/code/modules/mob/clickdelay.dm b/code/modules/mob/clickdelay.dm
index fa549460e1..513bafaa32 100644
--- a/code/modules/mob/clickdelay.dm
+++ b/code/modules/mob/clickdelay.dm
@@ -60,3 +60,34 @@
*/
/mob/proc/CheckResistCooldown()
return (world.time >= (last_resist + resist_cooldown))
+
+/obj/item
+ // Standard clickdelay variables
+ /// Amount of time to check for from a mob's last attack, checked before an attack happens
+ var/preattack_cooldown_check = CLICK_CD_MELEE
+ /// Amount of time to delay a mob's next attack, added after an attack happens
+ var/postattack_cooldown_penalty = 0
+ /// This item bypasses any click delay mods
+ var/clickdelay_mod_bypass = FALSE
+ /// This item checks clickdelay from a user's delayed next action variable rather than the last time they attacked.
+ var/clickdelay_from_next_action = FALSE
+ /// This item ignores next action delays.
+ var/clickdelay_ignores_next_action = FALSE
+
+/**
+ * Checks if a user's clickdelay is met for a standard attack
+ */
+/obj/item/proc/PreattackClickdelayCheck(mob/user, atom/target)
+ return user.CheckActionCooldown(action_cooldown_preattack, clickdelay_from_next_action, clickdelay_mod_bypass, clickdelay_ignores_next_action)
+
+/**
+ * Called if check is successful before the attack happens.
+ */
+/obj/item/proc/PreattackClickdelaySet(mob/user, atom/target)
+ user.DelayNextAction(0, FALSe, TRUE)
+
+/**
+ * Called after a successful attack to set a mob's clickdelay.
+ */
+/obj/item/proc/PostattackClickdelaySet(mob/user, atom/target)
+ user.DelayNextAction(postattack_cooldown_penalty, clickdelay_mod_bypass, FALSE)