From 33d5ba788b231630960f030cbc56b86755bf1e93 Mon Sep 17 00:00:00 2001
From: silicons <2003111+silicons@users.noreply.github.com>
Date: Fri, 24 Jul 2020 20:19:18 -0700
Subject: [PATCH] aight
---
code/__DEFINES/_flags/return_values.dm | 7 +++-
code/_onclick/click.dm | 8 ++++-
code/_onclick/item_attack.dm | 32 ++++++++++++++++---
code/_onclick/other_mobs.dm | 12 ++++---
code/_onclick/right_click.dm | 10 ++++--
code/modules/clothing/gloves/miscellaneous.dm | 4 +--
code/modules/ninja/suit/gloves.dm | 1 +
7 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/code/__DEFINES/_flags/return_values.dm b/code/__DEFINES/_flags/return_values.dm
index dd15ff6268..1bcb54bdb7 100644
--- a/code/__DEFINES/_flags/return_values.dm
+++ b/code/__DEFINES/_flags/return_values.dm
@@ -2,11 +2,16 @@
/// The attack is from a parry counterattack.
#define ATTACKCHAIN_PARRY_COUNTERATTACK (1<<0)
-// melee_attack_chain(), attackby(), pre_attack(), afterattack(), and tool_act() return values.
+// melee_attack_chain(), attackby(), pre_attack(), afterattack(), and tool_act(), attack() and **anything that is called by ClickOn()** return values.
/// Stop the attack chain if still in melee_attack_chain()
#define STOP_ATTACK_PROC_CHAIN (1<<0)
/// This attack should discard last_action instead of flushing (storing) it). You should probably know what you're doing if you use this considering this is how clickdelay is enforced.
#define DISCARD_LAST_ACTION (1<<1)
+/// There are a number of "safety nets" intended to default-handle clickdelay. Return this flag to bypass ALL of them. Be sure
+/// you know EXACTLY what you are doing!
+#define NO_AUTO_CLICKDELAY_HANDLING (1<<2)
+/// Only used with UnarmedAttack(). Interrupts unarmed attack from progressing.
+#define INTERRUPT_UNARMED_ATTACK (1<<3)
// UnarmedAttack() flags
/// Attack is from a parry counterattack
diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm
index 116b9c7db7..ff6a03582c 100644
--- a/code/_onclick/click.dm
+++ b/code/_onclick/click.dm
@@ -107,6 +107,9 @@
. = W.melee_attack_chain(src, A, params)
return !(. & DISCARD_LAST_ACTION)
else
+ . = UnarmedAttack(A)
+ if(!(. & NO_AUTO_CLICKDELAY_HANDLING))
+ DelayNextAction(CLICK_CD_MELEE)
return UnarmedAttack(A)? TRUE : FALSE
//Can't reach anything else in lockers or other weirdness
@@ -119,7 +122,10 @@
. = W.melee_attack_chain(src, A, params)
return !(. & DISCARD_LAST_ACTION)
else
- return UnarmedAttack(A, 1)? TRUE : FALSE
+ . = UnarmedAttack(A)
+ if(!(. & NO_AUTO_CLICKDELAY_HANDLING))
+ DelayNextAction(CLICK_CD_MELEE)
+ return UnarmedAttack(A)? TRUE : FALSE
else
if(W)
W.ranged_attack_chain(src, A, params)
diff --git a/code/_onclick/item_attack.dm b/code/_onclick/item_attack.dm
index e595a744ad..951c3615f9 100644
--- a/code/_onclick/item_attack.dm
+++ b/code/_onclick/item_attack.dm
@@ -59,7 +59,20 @@
if(. & STOP_ATTACK_PROC_CHAIN)
return
. |= I.attack(src, user, attackchain_flags, damage_multiplier)
+ if(!(. & NO_AUTO_CLICKDELAY_HANDLING)) // SAFETY NET - unless the proc tells us we should not handle this, give them the basic melee cooldown!
+ I.ApplyAttackCooldown(user, src)
+/**
+ * Called when someone uses us to attack a mob in melee combat.
+ *
+ * This proc respects CheckAttackCooldown() default clickdelay handling.
+ *
+ * @params
+ * * mob/living/M - target
+ * * mob/living/user - attacker
+ * * attackchain_Flags - see [code/__DEFINES/_flags/return_values.dm]
+ * * damage_multiplier - what to multiply the damage by
+ */
/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)
return
@@ -80,7 +93,6 @@
user.do_attack_animation(M)
M.attacked_by(src, user, attackchain_flags, damage_multiplier)
- ApplyAttackCooldown(user, M)
log_combat(user, M, "attacked", src.name, "(INTENT: [uppertext(user.a_intent)]) (DAMTYPE: [uppertext(damtype)])")
add_fingerprint(user)
@@ -97,7 +109,6 @@
return
user.do_attack_animation(O)
O.attacked_by(src, user)
- ApplyAttackCooldown(user, O)
var/weight = getweight(user, STAM_COST_ATTACK_OBJ_MULT)
if(weight)
user.adjustStaminaLossBuffered(weight)//CIT CHANGE - makes attacking things cause stamina loss
@@ -124,7 +135,7 @@
if(!(SKILL_TRAIN_ATTACK_OBJ in I.used_skills[skill]))
continue
user.mind.auto_gain_experience(skill, I.skill_gain)
-
+ I.ApplyAttackCooldown(user, src)
if(totitemdamage)
visible_message("[user] has hit [src] with [I]!", null, null, COMBAT_MESSAGE_RANGE)
//only witnesses close by and the victim see a hit message.
@@ -190,9 +201,20 @@
var/datum/skill/S = GLOB.skill_datums[skill]
user.mind.auto_gain_experience(skill, I.skill_gain*S.item_skill_gain_multi)
-// Proximity_flag is 1 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.
+/**
+ * Called after attacking something if the melee attack chain isn't interrupted before.
+ * Also called when clicking on something with an item without being in melee range
+ *
+ * WARNING: This does not automatically check clickdelay if not in a melee attack! Be sure to account for this!
+ *
+ * @params
+ * * target - The thing we clicked
+ * * user - mob of person clicking
+ * * proximity_flag - are we in melee range/doing it in a melee attack
+ * * click_parameters - mouse control parameters, check BYOND ref.
+ */
/obj/item/proc/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
+ SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(src, COMSIG_ITEM_AFTERATTACK, target, user, proximity_flag, click_parameters)
SEND_SIGNAL(user, COMSIG_MOB_ITEM_AFTERATTACK, target, user, proximity_flag, click_parameters)
diff --git a/code/_onclick/other_mobs.dm b/code/_onclick/other_mobs.dm
index bca8280a89..f911756f65 100644
--- a/code/_onclick/other_mobs.dm
+++ b/code/_onclick/other_mobs.dm
@@ -20,15 +20,17 @@
// If the gloves do anything, have them return 1 to stop
// normal attack_hand() here.
var/obj/item/clothing/gloves/G = gloves // not typecast specifically enough in defines
- if(proximity && istype(G) && (. = G.Touch(A,1)))
- return
+ if(proximity && istype(G))
+ . |= G.Touch(A, TRUE)
+ if(. & INTERRUPT_UNARMED_ATTACK)
+ return
- var/override = 0
+ . = NONE
for(var/datum/mutation/human/HM in dna.mutations)
- override += HM.on_attack_hand(A, proximity, intent, flags)
+ . |= HM.on_attack_hand(A, proximity, intent, flags)
- if(override)
+ if(. & INTERRUPT_UNARMED_ATTACK)
return
SEND_SIGNAL(src, COMSIG_HUMAN_MELEE_UNARMED_ATTACK, A)
diff --git a/code/_onclick/right_click.dm b/code/_onclick/right_click.dm
index b4a8d48915..e5a3bd8345 100644
--- a/code/_onclick/right_click.dm
+++ b/code/_onclick/right_click.dm
@@ -40,7 +40,10 @@
return !(. & DISCARD_LAST_ACTION)
else
if(!AltUnarmedAttack(A))
- return UnarmedAttack(A, 1)? TRUE : FALSE
+ . = UnarmedAttack(A)
+ if(!(. & NO_AUTO_CLICKDELAY_HANDLING))
+ DelayNextAction(CLICK_CD_MELEE)
+ return UnarmedAttack(A)? TRUE : FALSE
//Can't reach anything else in lockers or other weirdness
if(!loc.AllowClick())
@@ -53,7 +56,10 @@
return !(. & DISCARD_LAST_ACTION)
else
if(!AltUnarmedAttack(A,1))
- return UnarmedAttack(A, 1)? TRUE : FALSE
+ . = UnarmedAttack(A)
+ if(!(. & NO_AUTO_CLICKDELAY_HANDLING))
+ DelayNextAction(CLICK_CD_MELEE)
+ return UnarmedAttack(A)? TRUE : FALSE
else
if(W)
if(!W.altafterattack(A, src, FALSE, params))
diff --git a/code/modules/clothing/gloves/miscellaneous.dm b/code/modules/clothing/gloves/miscellaneous.dm
index c9b5551789..f30fa02879 100644
--- a/code/modules/clothing/gloves/miscellaneous.dm
+++ b/code/modules/clothing/gloves/miscellaneous.dm
@@ -109,7 +109,7 @@
if(warcry)
M.say("[warcry]", ignore_spam = TRUE, forced = TRUE)
- return FALSE
+ return NO_AUTO_CLICKDELAY_HANDLING
/obj/item/clothing/gloves/fingerless/pugilist/rapid/AltClick(mob/user)
var/input = stripped_input(user,"What do you want your battlecry to be? Max length of 6 characters.", ,"", 7)
@@ -137,7 +137,7 @@
else
M.SetNextAction(CLICK_CD_RAPID)
- return FALSE
+ return NO_AUTO_CLICKDELAY_HANDLING
/obj/item/clothing/gloves/botanic_leather
name = "botanist's leather gloves"
diff --git a/code/modules/ninja/suit/gloves.dm b/code/modules/ninja/suit/gloves.dm
index dbe4c80579..a06b753402 100644
--- a/code/modules/ninja/suit/gloves.dm
+++ b/code/modules/ninja/suit/gloves.dm
@@ -67,6 +67,7 @@
to_chat(H, "Gained [DisplayEnergy(.)] of energy from [A].")
else
to_chat(H, "\The [A] has run dry of energy, you must find another source!")
+ . = INTERRUPT_UNARMED_ATTACK
else
. = FALSE //as to not cancel attack_hand()