Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Cuts the number of apply_damage copypaste procs from 3(.5) to 1, fixing a few bugs along the way #323

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@
///from base of mob/set_invis_see(): (new_invis, old_invis)
#define COMSIG_MOB_SEE_INVIS_CHANGE "mob_see_invis_change"


///from base of /mob/living/proc/apply_damage(): (damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
/// from /mob/living/proc/apply_damage(): (list/damage_mods, damage, damagetype, def_zone, sharpness, attack_direction, attacking_item)
/// allows you to add multiplicative damage modifiers to the damage mods argument to adjust incoming damage
/// not sent if the apply damage call was forced
#define COMSIG_MOB_APPLY_DAMAGE_MODIFIERS "mob_apply_damage_modifiers"
/// from base of /mob/living/proc/apply_damage(): (damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
#define COMSIG_MOB_APPLY_DAMAGE "mob_apply_damage"
///from /mob/living/proc/apply_damage(), works like above but after the damage is actually inflicted: (damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
/// from /mob/living/proc/apply_damage(): (damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
/// works like above but after the damage is actually inflicted
#define COMSIG_MOB_AFTER_APPLY_DAMAGE "mob_after_apply_damage"

///from base of /mob/living/attack_alien(): (user)
#define COMSIG_MOB_ATTACK_ALIEN "mob_attack_alien"
///from base of /mob/throw_item(): (atom/target)
Expand Down
5 changes: 4 additions & 1 deletion code/datums/components/explodable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@
detonate()

///Called when you attack a specific body part of the thing this is equipped on. Useful for exploding pants.
/datum/component/explodable/proc/explodable_attack_zone(datum/source, damage, damagetype, def_zone)
/datum/component/explodable/proc/explodable_attack_zone(datum/source, damage, damagetype, def_zone, ...)
SIGNAL_HANDLER

if(!def_zone)
return
if(damagetype != BURN) //Don't bother if it's not fire.
return
if(isbodypart(def_zone))
var/obj/item/bodypart/hitting = def_zone
def_zone = hitting.body_zone
if(!is_hitting_zone(def_zone)) //You didn't hit us! ha!
return
detonate()
Expand Down
22 changes: 12 additions & 10 deletions code/datums/components/gunpoint.dm
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,27 @@
qdel(src)

///If the shooter is hit by an attack, they have a 50% chance to flinch and fire. If it hit the arm holding the trigger, it's an 80% chance to fire instead
/datum/component/gunpoint/proc/flinch(attacker, damage, damagetype, def_zone)
/datum/component/gunpoint/proc/flinch(mob/living/source, damage_amount, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
SIGNAL_HANDLER

var/mob/living/shooter = parent
if(attacker == shooter)
return // somehow this wasn't checked for months but no one tried punching themselves to initiate the shot, amazing
if(!attack_direction) // No fliching from yourself
return

var/flinch_chance = 50
var/gun_hand = LEFT_HANDS
var/gun_hand = (source.get_held_index_of_item(weapon) % 2) ? BODY_ZONE_L_ARM : BODY_ZONE_R_ARM

if(shooter.held_items[RIGHT_HANDS] == weapon)
gun_hand = RIGHT_HANDS
if(isbodypart(def_zone))
var/obj/item/bodypart/hitting = def_zone
def_zone = hitting.body_zone

if((def_zone == BODY_ZONE_L_ARM && gun_hand == LEFT_HANDS) || (def_zone == BODY_ZONE_R_ARM && gun_hand == RIGHT_HANDS))
if(def_zone == gun_hand)
flinch_chance = 80

if(prob(flinch_chance))
shooter.visible_message(span_danger("[shooter] flinches!"), \
span_danger("You flinch!"))
source.visible_message(
span_danger("[source] flinches!"),
span_danger("You flinch!"),
)
INVOKE_ASYNC(src, PROC_REF(trigger_reaction))

#undef GUNPOINT_DELAY_STAGE_2
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/pinata.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
return
return COMPONENT_INCOMPATIBLE

/datum/component/pinata/proc/damage_inflicted(obj/target, damage, damage_type)
/datum/component/pinata/proc/damage_inflicted(obj/target, damage, damage_type, ...)
SIGNAL_HANDLER
if(damage < minimum_damage || damage_type == STAMINA || damage_type == OXY)
return
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/regenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
deltimer(regeneration_start_timer)

/// When you take damage, reset the cooldown and start processing
/datum/component/regenerator/proc/on_take_damage(datum/source, damage, damagetype)
/datum/component/regenerator/proc/on_take_damage(datum/source, damage, damagetype, ...)
SIGNAL_HANDLER

if (damagetype in ignore_damage_types)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/style/style.dm
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@


// Negative effects
/datum/component/style/proc/on_take_damage()
/datum/component/style/proc/on_take_damage(...)
SIGNAL_HANDLER

point_multiplier = round(max(point_multiplier - 0.3, 1), 0.1)
Expand Down
12 changes: 7 additions & 5 deletions code/datums/quirks/negative_quirks/glass_jaw.dm
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@

/datum/quirk/glass_jaw/proc/punch_out(mob/living/carbon/source, damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
SIGNAL_HANDLER
if((damagetype != BRUTE) || (def_zone != BODY_ZONE_HEAD))

if(isbodypart(def_zone))
var/obj/item/bodypart/hitting = def_zone
def_zone = hitting.body_zone
if(damagetype != BRUTE || def_zone != BODY_ZONE_HEAD)
return
var/actual_damage = damage - (damage * blocked/100)
//only roll for knockouts at 5 damage or more
if(actual_damage < 5)
if(damage < 5)
return
//blunt items are more likely to knock out, but sharp ones are still capable of doing it
if(prob(CEILING(actual_damage * (sharpness & (SHARP_EDGED|SHARP_POINTY) ? 0.65 : 1), 1)))
if(prob(CEILING(damage * (sharpness & (SHARP_EDGED|SHARP_POINTY) ? 0.65 : 1), 1)))
//don't display the message if little mac is already KO'd
if(!source.IsUnconscious())
source.visible_message(
Expand Down
64 changes: 35 additions & 29 deletions code/game/machinery/dna_infuser/organ_sets/roach_organs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
greyscale_config = /datum/greyscale_config/mutant_organ
greyscale_colors = ROACH_COLORS

/// Timer ID for resetting the damage resistance applied from attacks from behind
var/defense_timerid
/// Bodypart overlay applied to the chest the heart is in
var/datum/bodypart_overlay/simple/roach_shell/roach_shell

COOLDOWN_DECLARE(harden_effect_cd)

/obj/item/organ/internal/heart/roach/Initialize(mapload)
. = ..()
AddElement(/datum/element/noticable_organ, "has hardened, somewhat translucent skin.")
Expand All @@ -78,7 +78,8 @@

var/mob/living/carbon/human/human_owner = organ_owner

RegisterSignal(human_owner, COMSIG_MOB_APPLY_DAMAGE, PROC_REF(modify_damage))
RegisterSignal(human_owner, COMSIG_MOB_APPLY_DAMAGE_MODIFIERS, PROC_REF(modify_damage))
RegisterSignal(human_owner, COMSIG_MOB_AFTER_APPLY_DAMAGE, PROC_REF(do_block_effect))
human_owner.physiology.knockdown_mod *= 3

var/obj/item/bodypart/chest/chest = human_owner.get_bodypart(BODY_ZONE_CHEST)
Expand All @@ -92,50 +93,55 @@

var/mob/living/carbon/human/human_owner = organ_owner

UnregisterSignal(human_owner, COMSIG_MOB_APPLY_DAMAGE)
UnregisterSignal(human_owner, list(COMSIG_MOB_APPLY_DAMAGE_MODIFIERS, COMSIG_MOB_AFTER_APPLY_DAMAGE))
human_owner.physiology.knockdown_mod /= 3

if(defense_timerid)
reset_damage(human_owner)

var/obj/item/bodypart/chest/chest = human_owner.get_bodypart(BODY_ZONE_CHEST)
chest.remove_bodypart_overlay(roach_shell)
human_owner.update_body_parts()

/**
* Signal proc for [COMSIG_MOB_APPLY_DAMAGE]
* Signal proc for [COMSIG_MOB_APPLY_DAMAGE_MODIFIERS]
*
* Being hit with brute damage in the back will impart a large damage resistance bonus for a very short period.
* Adds a 0.5 modifier to attacks from the back
*/
/obj/item/organ/internal/heart/roach/proc/modify_damage(datum/source, damage, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, obj/item/attacking_item)
/obj/item/organ/internal/heart/roach/proc/modify_damage(mob/living/carbon/human/source, list/damage_mods, damage_amount, damagetype, def_zone, sharpness, attack_direction, obj/item/attacking_item)
SIGNAL_HANDLER

if(!ishuman(owner) || !attack_direction || damagetype != BRUTE || owner.stat >= UNCONSCIOUS)
if(!is_blocking(source, damage_amount, damagetype, attack_direction))
return

var/mob/living/carbon/human/human_owner = owner
// No tactical spinning
if(human_owner.flags_1 & IS_SPINNING_1)
return
damage_mods += 0.5

/**
* Signal proc for [COMSIG_MOB_AFTER_APPLY_DAMAGE]
*
* Does a special effect if we blocked damage with our back
*/
/obj/item/organ/internal/heart/roach/proc/do_block_effect(mob/living/carbon/human/source, damage_dealt, damagetype, def_zone, blocked, wound_bonus, bare_wound_bonus, sharpness, attack_direction, obj/item/attacking_item)
SIGNAL_HANDLER

// If we're lying down, or were attacked from the back, we get armor.
var/should_armor_up = (human_owner.body_position == LYING_DOWN) || (human_owner.dir & attack_direction)
if(!should_armor_up)
if(!is_blocking(source, damage_dealt, damagetype, attack_direction))
return

// Take 50% less damage from attack behind us
if(!defense_timerid)
human_owner.physiology.brute_mod /= 2
human_owner.visible_message(span_warning("[human_owner]'s back hardens against the blow!"))
playsound(human_owner, 'sound/effects/constructform.ogg', 25, vary = TRUE, extrarange = SHORT_RANGE_SOUND_EXTRARANGE)
if(COOLDOWN_FINISHED(src, harden_effect_cd))
source.visible_message(span_warning("[source]'s back hardens against the blow!"))
playsound(source, 'sound/effects/constructform.ogg', 25, vary = TRUE, extrarange = SHORT_RANGE_SOUND_EXTRARANGE)

defense_timerid = addtimer(CALLBACK(src, PROC_REF(reset_damage), owner), 5 SECONDS, TIMER_UNIQUE|TIMER_OVERRIDE)
COOLDOWN_START(src, harden_effect_cd, 5 SECONDS) // Cooldown resets EVERY time we get hit

/obj/item/organ/internal/heart/roach/proc/reset_damage(mob/living/carbon/human/human_owner)
defense_timerid = null
if(!QDELETED(human_owner))
human_owner.physiology.brute_mod *= 2
human_owner.visible_message(span_warning("[human_owner]'s back softens again."))
/// Checks if the passed mob is in a valid state to be blocking damage with the roach shell
/obj/item/organ/internal/heart/roach/proc/is_blocking(mob/living/carbon/human/blocker, damage_amount, damagetype, attack_direction)
if(damage_amount < 5 || damagetype != BRUTE || !attack_direction)
return
if(!ishuman(blocker) || blocker.stat >= UNCONSCIOUS)
return FALSE
// No tactical spinning
if(blocker.flags_1 & IS_SPINNING_1)
return FALSE
if(blocker.body_position == LYING_DOWN || (blocker.dir & attack_direction))
return TRUE
return FALSE

// Simple overlay so we can add a roach shell to guys with roach hearts
/datum/bodypart_overlay/simple/roach_shell
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/grenades/flashbang.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
living_mob.Paralyze(20)
living_mob.Knockdown(200)
living_mob.soundbang_act(1, 200, 10, 15)
if(living_mob.apply_damages(10, 10))
if(living_mob.apply_damages(brute = 10, burn = 10))
to_chat(living_mob, span_userdanger("The blast from \the [src] bruises and burns you!"))

// only checking if they're on top of the tile, cause being one tile over will be its own punishment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
return ..()

/// When we take fire damage (or... technically also cold damage, we don't differentiate), zap a nearby APC
/datum/status_effect/golem/plasma/proc/on_burned(datum/source, damage, damagetype)
/datum/status_effect/golem/plasma/proc/on_burned(datum/source, damage, damagetype, ...)
SIGNAL_HANDLER
if(damagetype != BURN)
return
Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/heretic/magic/shadow_cloak.dm
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
qdel(src)

/// Signal proc for [COMSIG_MOB_APPLY_DAMAGE], being damaged past a threshold will roll a chance to stop the effect
/datum/status_effect/shadow_cloak/proc/on_damaged(datum/source, damage, damagetype)
/datum/status_effect/shadow_cloak/proc/on_damaged(datum/source, damage, damagetype, ...)
SIGNAL_HANDLER

// Stam damage is generally bursty, so we'll half it
Expand Down
4 changes: 2 additions & 2 deletions code/modules/bitrunning/components/avatar_connection.dm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
)

/// Transfers damage from the avatar to the old_body
/datum/component/avatar_connection/proc/on_linked_damage(datum/source, damage, damage_type, def_zone, blocked, forced)
/datum/component/avatar_connection/proc/on_linked_damage(datum/source, damage, damage_type, def_zone, blocked, ...)
SIGNAL_HANDLER

var/mob/living/carbon/old_body = old_body_ref?.resolve()
Expand All @@ -123,7 +123,7 @@
if(damage > 30 && prob(30))
INVOKE_ASYNC(old_body, TYPE_PROC_REF(/mob/living, emote), "scream")

old_body.apply_damage(damage, damage_type, def_zone, blocked, forced, wound_bonus = CANT_WOUND)
old_body.apply_damage(damage, damage_type, def_zone, blocked, wound_bonus = CANT_WOUND)

if(old_body.stat > SOFT_CRIT) // KO!
full_avatar_disconnect(forced = TRUE)
Expand Down
8 changes: 4 additions & 4 deletions code/modules/bitrunning/server/util.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"health" = creature.health,
"name" = creature.name,
"pilot" = pilot,
"brute" = creature.get_current_damage_of_type(BRUTE),
"burn" = creature.get_current_damage_of_type(BURN),
"tox" = creature.get_current_damage_of_type(TOX),
"oxy" = creature.get_current_damage_of_type(OXY),
"brute" = creature.getBruteLoss(),
"burn" = creature.getFireLoss(),
"tox" = creature.getToxLoss(),
"oxy" = creature.getOxyLoss(),
))

return hosted_avatars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
return COMPONENT_CLEANED

/// When you take brute damage, schedule an explosion
/datum/status_effect/stacking/brimdust_coating/proc/on_take_damage(datum/source, damage, damagetype)
/datum/status_effect/stacking/brimdust_coating/proc/on_take_damage(datum/source, damage, damagetype, ...)
SIGNAL_HANDLER
if(damagetype != BRUTE)
return
Expand Down
4 changes: 1 addition & 3 deletions code/modules/mob/living/basic/lavaland/goliath/goliath.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@
// Goliaths can summon tentacles more frequently as they take damage, scary.
/mob/living/basic/mining/goliath/apply_damage(damage, damagetype, def_zone, blocked, forced, spread_damage, wound_bonus, bare_wound_bonus, sharpness, attack_direction, attacking_item)
. = ..()
if (!.)
return
if (damage <= 0)
if (. <= 0)
return
if (tentacles.cooldown_time > 1 SECONDS)
tentacles.cooldown_time -= 1 SECONDS
Expand Down
Loading
Loading