From 193e5e6eaf8fa885b1437b25832270e2dbd4fad1 Mon Sep 17 00:00:00 2001 From: Cameron Lennox Date: Sat, 8 Feb 2025 14:08:08 -0500 Subject: [PATCH] Unarmed Attack Fixes (#17078) Fixes a lot of bugs with Unarmed Attack logic. - You can not stomp while buckled now. - You can not kick while buckled now. - You can not bite while buckled now. - Fixes it so the click code can properly get to unarmed attack code now, allowing it to run it's proper checks to see if you can attack or not instead of just always returning false. - Changes some vars from 0 to FALSE where indicated. - Gets rid of some needless = FALSE when it was already on the parent - Fixes gloves increasing damage on anything other than punches. --- code/_onclick/click.dm | 56 +++++++++++-------- code/modules/holodeck/HolodeckObjects.dm | 1 + .../living/carbon/human/human_attackhand.dm | 2 +- .../carbon/human/species/species_attack.dm | 1 + .../carbon/human/species/species_attack_vr.dm | 1 + .../mob/living/carbon/human/unarmed_attack.dm | 34 +++++------ 6 files changed, 55 insertions(+), 40 deletions(-) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index f321d231f3d..3d73d62ad3a 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -79,19 +79,24 @@ var/obj/mecha/M = loc return M.click_action(A, src, params) + /// So, this entire restrained check pretty much tells the rest of the code below you are restrained. + /// Primarily, this is just so you can do unarmed attacks while restrained (bites) + /// However, if you wanted to add some special interaction to objects or anything OTHER than mobs, use 'RestrainedClickOn' instead + /// If you want some interesting restrained interaction HERE, add it here. + var/currently_restrained = FALSE if(restrained()) setClickCooldown(10) RestrainedClickOn(A) - return 1 + currently_restrained = TRUE - if(in_throw_mode && (isturf(A) || isturf(A.loc)) && throw_item(A)) + if(!currently_restrained && in_throw_mode && (isturf(A) || isturf(A.loc)) && throw_item(A)) trigger_aiming(TARGET_CAN_CLICK) throw_mode_off() return TRUE var/obj/item/W = get_active_hand() - if(W == A) // Handle attack_self + if(!currently_restrained && W == A) // Handle attack_self W.attack_self(src) trigger_aiming(TARGET_CAN_CLICK) update_inv_active_hand(0) @@ -100,7 +105,7 @@ //Atoms on your person // A is your location but is not a turf; or is on you (backpack); or is on something on you (box in backpack); sdepth is needed here because contents depth does not equate inventory storage depth. var/sdepth = A.storage_depth(src) - if((!isturf(A) && A == loc) || (sdepth != -1 && sdepth <= 1)) + if(!currently_restrained && ((!isturf(A) && A == loc) || (sdepth != -1 && sdepth <= 1))) if(W) var/resolved = W.resolve_attackby(A, src, click_parameters = params) if(!resolved && A && W) @@ -114,7 +119,7 @@ return 1 // VOREStation Addition Start: inbelly item interaction - if(isbelly(loc) && (loc == A.loc)) + if(!currently_restrained && isbelly(loc) && (loc == A.loc)) if(W) var/resolved = W.resolve_attackby(A,src) if(!resolved && A && W) @@ -133,25 +138,32 @@ // A is a turf or is on a turf, or in something on a turf (pen in a box); but not something in something on a turf (pen in a box in a backpack) sdepth = A.storage_depth_turf() if(isturf(A) || isturf(A.loc) || (sdepth != -1 && sdepth <= 1)) - if(A.Adjacent(src) || (W && W.attack_can_reach(src, A, W.reach)) ) // see adjacent.dm - if(W) - // Return 1 in attackby() to prevent afterattack() effects (when safely moving items for example) - var/resolved = W.resolve_attackby(A,src, click_parameters = params) - if(!resolved && A && W) - W.afterattack(A, src, 1, params) // 1: clicking something Adjacent - else - if(ismob(A)) // No instant mob attacking - setClickCooldown(get_attack_speed()) + if(currently_restrained) + if(ismob(A) && A.Adjacent(src)) //We are RESTRAINED (handcuffed or otherwise) and ADJACENT + setClickCooldown(get_attack_speed()) UnarmedAttack(A, 1) - trigger_aiming(TARGET_CAN_CLICK) - return - else // non-adjacent click - if(W) - W.afterattack(A, src, 0, params) // 0: not Adjacent - else - RangedAttack(A, params) + trigger_aiming(TARGET_CAN_CLICK) + return + else + if(!currently_restrained && A.Adjacent(src) || (W && W.attack_can_reach(src, A, W.reach)) ) // see adjacent.dm + if(W && !restrained()) + // Return 1 in attackby() to prevent afterattack() effects (when safely moving items for example) + var/resolved = W.resolve_attackby(A,src, click_parameters = params) + if(!resolved && A && W) + W.afterattack(A, src, 1, params) // 1: clicking something Adjacent + else + if(ismob(A)) // No instant mob attacking + setClickCooldown(get_attack_speed()) + UnarmedAttack(A, 1) + trigger_aiming(TARGET_CAN_CLICK) + return + else // non-adjacent click + if(W) + W.afterattack(A, src, 0, params) // 0: not Adjacent + else + RangedAttack(A, params) - trigger_aiming(TARGET_CAN_CLICK) + trigger_aiming(TARGET_CAN_CLICK) return 1 /mob/proc/setClickCooldown(var/timeout) diff --git a/code/modules/holodeck/HolodeckObjects.dm b/code/modules/holodeck/HolodeckObjects.dm index 5236ba41015..e7f8d445a73 100644 --- a/code/modules/holodeck/HolodeckObjects.dm +++ b/code/modules/holodeck/HolodeckObjects.dm @@ -148,6 +148,7 @@ /datum/unarmed_attack/holopugilism sparring_variant_type = /datum/unarmed_attack/holopugilism + is_punch = TRUE /datum/unarmed_attack/holopugilism/unarmed_override(var/mob/living/carbon/human/user,var/mob/living/carbon/human/target,var/zone) user.do_attack_animation(src) diff --git a/code/modules/mob/living/carbon/human/human_attackhand.dm b/code/modules/mob/living/carbon/human/human_attackhand.dm index ff745353420..6caf37d0e44 100644 --- a/code/modules/mob/living/carbon/human/human_attackhand.dm +++ b/code/modules/mob/living/carbon/human/human_attackhand.dm @@ -267,7 +267,7 @@ var/real_damage = rand_damage var/hit_dam_type = attack.damage_type real_damage += attack.get_unarmed_damage(H) - if(H.gloves) + if(H.gloves && attack.is_punch) if(istype(H.gloves, /obj/item/clothing/gloves)) var/obj/item/clothing/gloves/G = H.gloves real_damage += G.punch_force diff --git a/code/modules/mob/living/carbon/human/species/species_attack.dm b/code/modules/mob/living/carbon/human/species/species_attack.dm index d4f5912d53e..e42e14a1423 100644 --- a/code/modules/mob/living/carbon/human/species/species_attack.dm +++ b/code/modules/mob/living/carbon/human/species/species_attack.dm @@ -12,6 +12,7 @@ attack_noun = list("tendril") eye_attack_text = "a tendril" eye_attack_text_victim = "a tendril" + is_punch = TRUE /datum/unarmed_attack/claws attack_name = "claws" diff --git a/code/modules/mob/living/carbon/human/species/species_attack_vr.dm b/code/modules/mob/living/carbon/human/species/species_attack_vr.dm index 8942672c332..3608b719ca4 100644 --- a/code/modules/mob/living/carbon/human/species/species_attack_vr.dm +++ b/code/modules/mob/living/carbon/human/species/species_attack_vr.dm @@ -1,4 +1,5 @@ /datum/unarmed_attack/bite/sharp/numbing //Is using this against someone you are truly trying to fight a bad idea? Yes. Yes it is. + attack_name = "numbing bite" attack_verb = list("bit") attack_noun = list("fangs") attack_sound = 'sound/weapons/bite.ogg' diff --git a/code/modules/mob/living/carbon/human/unarmed_attack.dm b/code/modules/mob/living/carbon/human/unarmed_attack.dm index 965cd8e2f8f..aae63c65240 100644 --- a/code/modules/mob/living/carbon/human/unarmed_attack.dm +++ b/code/modules/mob/living/carbon/human/unarmed_attack.dm @@ -8,11 +8,12 @@ var/global/list/sparring_attack_cache = list() var/damage = 0 // Extra empty hand attack damage. var/attack_sound = "punch" var/miss_sound = 'sound/weapons/punchmiss.ogg' - var/shredding = 0 // Calls the old attack_alien() behavior on objects/mobs when on harm intent. + var/shredding = FALSE // Calls the old attack_alien() behavior on objects/mobs when on harm intent. var/sharp = FALSE var/edge = FALSE var/damage_type = BRUTE + var/is_punch = FALSE //If the attack benefits from the damage increase things being on your hands give. var/sparring_variant_type = /datum/unarmed_attack/light_strike var/eye_attack_text @@ -113,20 +114,21 @@ var/global/list/sparring_attack_cache = list() attack_name = "bite" attack_verb = list("bit") attack_sound = 'sound/weapons/bite.ogg' - shredding = 0 damage = 0 - sharp = FALSE - edge = FALSE + //sharp = TRUE //Enable if you want bites to make people bleed. + //germ_increase = 10 //Amount of germs each bite will give to the person. /datum/unarmed_attack/bite/event1 /datum/unarmed_attack/bite/is_usable(var/mob/living/carbon/human/user, var/mob/living/carbon/human/target, var/zone) - - if (user.is_muzzled()) - return 0 - if (user == target && (zone == BP_HEAD || zone == O_EYES || zone == O_MOUTH)) - return 0 - return TRUE + if (user.is_muzzled() || user.buckled) + return FALSE + if (user == target && ((zone == BP_GROIN && (prob(98)) || (zone == BP_HEAD || zone == O_EYES || zone == O_MOUTH)))) //biting your own groin is hard. 2% hit chance. + return FALSE + for(var/obj/item/organ/external/head/user_head in user.organs) //We have a head! + if(!user_head.dislocated && !(user_head.status & ORGAN_BROKEN)) //And it's not dislocated + return TRUE + return FALSE /datum/unarmed_attack/punch attack_name = "punch" @@ -135,6 +137,7 @@ var/global/list/sparring_attack_cache = list() eye_attack_text = "fingers" eye_attack_text_victim = "digits" damage = 0 + is_punch = TRUE /datum/unarmed_attack/punch/event1 @@ -149,7 +152,7 @@ var/global/list/sparring_attack_cache = list() if(target == user) user.visible_message(span_danger("[user] [pick(attack_verb)] [TU.himself] in the [organ]!")) - return 0 + return FALSE if(!target.lying) switch(zone) @@ -193,7 +196,7 @@ var/global/list/sparring_attack_cache = list() /datum/unarmed_attack/kick/event1 /datum/unarmed_attack/kick/is_usable(var/mob/living/carbon/human/user, var/mob/living/carbon/human/target, var/zone) - if (user.legcuffed) + if(user.legcuffed || user.buckled) return FALSE if(!(zone in list("l_leg", "r_leg", "l_foot", "r_foot", BP_GROIN))) @@ -238,7 +241,7 @@ var/global/list/sparring_attack_cache = list() /datum/unarmed_attack/stomp/is_usable(var/mob/living/carbon/human/user, var/mob/living/carbon/human/target, var/zone) - if (user.legcuffed) + if (user.legcuffed || user.buckled) return FALSE if(!istype(target)) @@ -279,7 +282,4 @@ var/global/list/sparring_attack_cache = list() attack_verb = list("tapped", "lightly struck") damage = 3 damage_type = HALLOSS - shredding = 0 - damage = 0 - sharp = FALSE - edge = FALSE + is_punch = TRUE