From dcedf89c70b450e9ee53fbb0ae7b0fcd9d15928e Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:02:07 -0500 Subject: [PATCH] Fixes being able to punch yourself (#79033) ## About The Pull Request Fixes #79031 Fixes #79042 I forgot some logic here when making the human override. Not the cleanest way to do it but it'll suffice. ## Changelog :cl: Melbert fix: You can punch yourself again /:cl: --- code/_onclick/other_mobs.dm | 4 +- code/datums/mutations/hulk.dm | 2 +- .../mob/living/carbon/human/human_defense.dm | 9 ++--- code/modules/mob/living/living_defense.dm | 2 +- .../organs/internal/cyberimp/augments_arms.dm | 2 +- code/modules/unit_tests/combat.dm | 39 +++++++++++++++++++ 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/code/_onclick/other_mobs.dm b/code/_onclick/other_mobs.dm index ce281bb4ecf..edbfe5b3251 100644 --- a/code/_onclick/other_mobs.dm +++ b/code/_onclick/other_mobs.dm @@ -40,7 +40,7 @@ if(sigreturn & COMPONENT_SKIP_ATTACK) return FALSE - if(!can_unarmed_attack(attack_target)) + if(!can_unarmed_attack()) return FALSE sigreturn = SEND_SIGNAL(src, COMSIG_LIVING_UNARMED_ATTACK, attack_target, proximity_flag, modifiers) @@ -55,7 +55,7 @@ /mob/living/carbon/human/UnarmedAttack(atom/attack_target, proximity_flag, list/modifiers) // Humans can always check themself regardless of having their hands blocked or w/e - if(src == attack_target) + if(src == attack_target && !combat_mode && HAS_TRAIT(src, TRAIT_HANDS_BLOCKED)) check_self_for_injuries() return TRUE diff --git a/code/datums/mutations/hulk.dm b/code/datums/mutations/hulk.dm index 788b885bbce..73198e8afb2 100644 --- a/code/datums/mutations/hulk.dm +++ b/code/datums/mutations/hulk.dm @@ -39,7 +39,7 @@ if(!source.combat_mode || !proximity || LAZYACCESS(modifiers, RIGHT_CLICK)) return NONE if(!source.can_unarmed_attack()) - return COMPONENT_CANCEL_ATTACK_CHAIN + return COMPONENT_SKIP_ATTACK if(!target.attack_hulk(owner)) return NONE diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm index 6a2bc8dc33d..c2f90bb3fe4 100644 --- a/code/modules/mob/living/carbon/human/human_defense.dm +++ b/code/modules/mob/living/carbon/human/human_defense.dm @@ -256,14 +256,13 @@ if(try_inject(user, affecting, injection_flags = INJECT_TRY_SHOW_ERROR_MESSAGE))//Thick suits can stop monkey bites. if(..()) //successful monkey bite, this handles disease contraction. - var/obj/item/bodypart/arm/active_arm = user.get_active_hand() - var/damage = rand(active_arm.unarmed_damage_low, active_arm.unarmed_damage_high) + var/obj/item/bodypart/head/monkey_mouth = user.get_bodypart(BODY_ZONE_HEAD) + var/damage = HAS_TRAIT(user, TRAIT_PERFECT_ATTACKER) ? monkey_mouth.unarmed_damage_high : rand(monkey_mouth.unarmed_damage_low, monkey_mouth.unarmed_damage_high) if(!damage) - return + return FALSE if(check_shields(user, damage, "the [user.name]")) return FALSE - if(stat != DEAD) - apply_damage(damage, BRUTE, affecting, run_armor_check(affecting, MELEE)) + apply_damage(damage, BRUTE, affecting, run_armor_check(affecting, MELEE)) return TRUE /mob/living/carbon/human/attack_alien(mob/living/carbon/alien/adult/user, list/modifiers) diff --git a/code/modules/mob/living/living_defense.dm b/code/modules/mob/living/living_defense.dm index cfc2208a1bc..2beca6093a2 100644 --- a/code/modules/mob/living/living_defense.dm +++ b/code/modules/mob/living/living_defense.dm @@ -329,7 +329,7 @@ to_chat(user, span_warning("You can't bite with your mouth covered!")) return FALSE user.do_attack_animation(src, ATTACK_EFFECT_BITE) - if (prob(75)) + if (HAS_TRAIT(user, TRAIT_PERFECT_ATTACKER) || prob(75)) log_combat(user, src, "attacked") playsound(loc, 'sound/weapons/bite.ogg', 50, TRUE, -1) visible_message(span_danger("[user.name] bites [src]!"), \ diff --git a/code/modules/surgery/organs/internal/cyberimp/augments_arms.dm b/code/modules/surgery/organs/internal/cyberimp/augments_arms.dm index 142cf8d5143..486284b8b6d 100644 --- a/code/modules/surgery/organs/internal/cyberimp/augments_arms.dm +++ b/code/modules/surgery/organs/internal/cyberimp/augments_arms.dm @@ -412,7 +412,7 @@ if(dna?.check_mutation(/datum/mutation/human/hulk)) //NO HULK return NONE if(!source.can_unarmed_attack()) - return COMPONENT_CANCEL_ATTACK_CHAIN + return COMPONENT_SKIP_ATTACK var/mob/living/living_target = target source.changeNext_move(CLICK_CD_MELEE) diff --git a/code/modules/unit_tests/combat.dm b/code/modules/unit_tests/combat.dm index 3302eca9c74..d645df98cbf 100644 --- a/code/modules/unit_tests/combat.dm +++ b/code/modules/unit_tests/combat.dm @@ -99,3 +99,42 @@ TEST_ASSERT_EQUAL(victim.loc.x, run_loc_floor_bottom_left.x + 2, "Victim was moved after being pushed against a wall") TEST_ASSERT(victim.has_status_effect(/datum/status_effect/incapacitating/knockdown), "Victim was not knocked down after being pushed against a wall") TEST_ASSERT_EQUAL(victim.get_active_held_item(), null, "Victim didn't drop toolbox after being pushed against a wall") + +/// Tests you can punch yourself +/datum/unit_test/self_punch + +/datum/unit_test/self_punch/Run() + var/mob/living/carbon/human/dummy = allocate(/mob/living/carbon/human/consistent) + ADD_TRAIT(dummy, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS) + dummy.set_combat_mode(TRUE) + dummy.ClickOn(dummy) + TEST_ASSERT_NOTEQUAL(dummy.getBruteLoss(), 0, "Dummy took no brute damage after self-punching") + +/// Tests handcuffed (HANDS_BLOCKED) mobs cannot punch +/datum/unit_test/handcuff_punch + +/datum/unit_test/handcuff_punch/Run() + var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent) + ADD_TRAIT(attacker, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS) + ADD_TRAIT(attacker, TRAIT_HANDS_BLOCKED, TRAIT_SOURCE_UNIT_TESTS) + attacker.set_combat_mode(TRUE) + attacker.ClickOn(victim) + TEST_ASSERT_EQUAL(victim.getBruteLoss(), 0, "Victim took brute damage from being punched by a handcuffed attacker") + attacker.next_move = -1 + attacker.next_click = -1 + attacker.ClickOn(attacker) + TEST_ASSERT_EQUAL(attacker.getBruteLoss(), 0, "Attacker took brute damage from self-punching while handcuffed") + +/// Tests handcuffed (HANDS_BLOCKED) monkeys can still bite despite being cuffed +/datum/unit_test/handcuff_bite + +/datum/unit_test/handcuff_bite/Run() + var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human/consistent) + ADD_TRAIT(attacker, TRAIT_PERFECT_ATTACKER, TRAIT_SOURCE_UNIT_TESTS) + ADD_TRAIT(attacker, TRAIT_HANDS_BLOCKED, TRAIT_SOURCE_UNIT_TESTS) + attacker.set_combat_mode(TRUE) + attacker.set_species(/datum/species/monkey) + attacker.ClickOn(victim) + TEST_ASSERT_NOTEQUAL(victim.getBruteLoss(), 0, "Victim took no brute damage from being bit by a handcuffed monkey, which is incorrect, as it's a bite attack")