From 6117a6416737a08fb2d80dcd85dc0ad85dca3d6e Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 22 Nov 2022 17:18:40 +0100 Subject: [PATCH] [MIRROR] Refactor monkey spec_unarmedattack [MDB IGNORE] (#17653) * Refactor monkey spec_unarmedattack (#71361) ## About The Pull Request Refactors how the named proc works, the code was very soulful and I've fixed that ## Why It's Good For The Game Squeaky clean code Resolves https://github.com/tgstation/tgstation/issues/71269, kinda * Refactor monkey spec_unarmedattack Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com> --- .../carbon/human/species_types/monkeys.dm | 87 ++++++++++++------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/code/modules/mob/living/carbon/human/species_types/monkeys.dm b/code/modules/mob/living/carbon/human/species_types/monkeys.dm index 6342cc01788..142aafa3dda 100644 --- a/code/modules/mob/living/carbon/human/species_types/monkeys.dm +++ b/code/modules/mob/living/carbon/human/species_types/monkeys.dm @@ -1,3 +1,5 @@ +#define MONKEY_SPEC_ATTACK_BITE_MISS_CHANCE 25 + /datum/species/monkey name = "Monkey" id = SPECIES_MONKEY @@ -75,38 +77,63 @@ C.dna.remove_mutation(/datum/mutation/human/race) /datum/species/monkey/spec_unarmedattack(mob/living/carbon/human/user, atom/target, modifiers) - if(HAS_TRAIT(user, TRAIT_HANDS_BLOCKED)) - if(!iscarbon(target)) + // If our hands are not blocked, dont try to bite them + if(!HAS_TRAIT(user, TRAIT_HANDS_BLOCKED)) + // if we aren't an advanced tool user, we call attack_paw and cancel the preceeding attack chain + if(!ISADVANCEDTOOLUSER(user)) + target.attack_paw(user, modifiers) return TRUE - var/mob/living/carbon/victim = target - if(user.is_muzzled()) - return TRUE - var/obj/item/bodypart/affecting = null - if(ishuman(victim)) - var/mob/living/carbon/human/human_victim = victim - affecting = human_victim.get_bodypart(human_victim.get_random_valid_zone(even_weights = TRUE)) - var/armor = victim.run_armor_check(affecting, MELEE) - if(prob(25)) - victim.visible_message(span_danger("[user]'s bite misses [victim]!"), - span_danger("You avoid [user]'s bite!"), span_hear("You hear jaws snapping shut!"), COMBAT_MESSAGE_RANGE, user) - to_chat(user, span_danger("Your bite misses [victim]!")) - return TRUE - var/obj/item/bodypart/head/mouth = user.get_bodypart(BODY_ZONE_HEAD) - victim.apply_damage(rand(mouth.unarmed_damage_low, mouth.unarmed_damage_high), BRUTE, affecting, armor) - victim.visible_message(span_danger("[name] bites [victim]!"), - span_userdanger("[name] bites you!"), span_hear("You hear a chomp!"), COMBAT_MESSAGE_RANGE, name) - to_chat(user, span_danger("You bite [victim]!")) - if(armor >= 2) - return TRUE - for(var/datum/disease/bite_infection as anything in user.diseases) - if(bite_infection.spread_flags & (DISEASE_SPREAD_SPECIAL | DISEASE_SPREAD_NON_CONTAGIOUS)) - continue - victim.ForceContractDisease(bite_infection) + return ..() + + // this shouldn't even be possible, but I'm sure the check was here for a reason + if(!iscarbon(target)) + stack_trace("HEY LISTEN! We are performing a species spec_unarmed attack with a non-carbon user. How did you fuck this up?") return TRUE - if(!ISADVANCEDTOOLUSER(user)) - target.attack_paw(user, modifiers) + var/mob/living/carbon/victim = target + if(user.is_muzzled()) + return TRUE // cannot bite them if we're muzzled + + var/obj/item/bodypart/affecting + if(ishuman(victim)) + var/mob/living/carbon/human/human_victim = victim + affecting = human_victim.get_bodypart(human_victim.get_random_valid_zone(even_weights = TRUE)) + var/armor = victim.run_armor_check(affecting, MELEE) + + if(prob(MONKEY_SPEC_ATTACK_BITE_MISS_CHANCE)) + victim.visible_message( + span_danger("[user]'s bite misses [victim]!"), + span_danger("You avoid [user]'s bite!"), + span_hear("You hear jaws snapping shut!"), + COMBAT_MESSAGE_RANGE, + user, + ) + to_chat(user, span_danger("Your bite misses [victim]!")) return TRUE - return ..() + + var/obj/item/bodypart/head/mouth = user.get_bodypart(BODY_ZONE_HEAD) + if(!mouth) // check for them having a head, ala HARS + return TRUE + + var/damage_roll = rand(mouth.unarmed_damage_low, mouth.unarmed_damage_high) + victim.apply_damage(damage_roll, BRUTE, affecting, armor) + + victim.visible_message( + span_danger("[name] bites [victim]!"), + span_userdanger("[name] bites you!"), + span_hear("You hear a chomp!"), + COMBAT_MESSAGE_RANGE, + name, + ) + to_chat(user, span_danger("You bite [victim]!")) + + if(armor >= 2) // if they have basic armor on the limb we bit, don't spread diseases + return TRUE + for(var/datum/disease/bite_infection as anything in user.diseases) + if(bite_infection.spread_flags & (DISEASE_SPREAD_SPECIAL | DISEASE_SPREAD_NON_CONTAGIOUS)) + continue // ignore diseases that have special spread logic, or are not contagious + victim.ForceContractDisease(bite_infection) + + return TRUE /datum/species/monkey/check_roundstart_eligible() if(check_holidays(MONKEYDAY)) @@ -231,3 +258,5 @@ /obj/item/organ/internal/brain/primate/get_attacking_limb(mob/living/carbon/human/target) return owner.get_bodypart(BODY_ZONE_HEAD) + +#undef MONKEY_SPEC_ATTACK_BITE_MISS_CHANCE