From 635f1beda41bb2dc30dad5eec82c6c9f495cdeb2 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 29 Jun 2022 14:21:11 +0200 Subject: [PATCH] [MIRROR] MULEbots uses the blood walking element (now component), fixes MULEs tracking blood infinitely [MDB IGNORE] (#14613) * MULEbots uses the blood walking element (now component), fixes MULEs tracking blood infinitely (#68047) Blood walking is a component, MULES use blood walking * MULEbots uses the blood walking element (now component), fixes MULEs tracking blood infinitely Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- code/datums/components/blood_walk.dm | 95 +++++++++++++++++++ code/datums/elements/blood_walk.dm | 56 ----------- .../mob/living/simple_animal/bot/mulebot.dm | 52 +++++----- .../living/simple_animal/heretic_monsters.dm | 4 +- .../simple_animal/hostile/giant_spider.dm | 4 +- .../hostile/megafauna/bubblegum.dm | 5 +- tgstation.dme | 2 +- 7 files changed, 129 insertions(+), 89 deletions(-) create mode 100644 code/datums/components/blood_walk.dm delete mode 100644 code/datums/elements/blood_walk.dm diff --git a/code/datums/components/blood_walk.dm b/code/datums/components/blood_walk.dm new file mode 100644 index 00000000000..0e14da29e0d --- /dev/null +++ b/code/datums/components/blood_walk.dm @@ -0,0 +1,95 @@ +///Blood walk, a component that causes you to make blood wherever you walk. +/datum/component/blood_walk + dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS + + ///How many blood pools can we create? + ///If we reach 0, we will stop leaving blood and self delete + var/blood_remaining = 0 + ///Typepath of what blood decal we create on walk + var/blood_type + ///The sound that plays when we spread blood. + var/sound_played + ///How loud will the sound be, if there is one. + var/sound_volume + ///The chance of spawning blood whenever walking + var/blood_spawn_chance + ///Should the decal face the direction of the parent + var/target_dir_change + ///Should we transfer the parent's blood DNA to created blood decal + var/transfer_blood_dna + +/datum/component/blood_walk/Initialize( + blood_type = /obj/effect/decal/cleanable/blood, + sound_played, + sound_volume = 80, + blood_spawn_chance = 100, + target_dir_change = FALSE, + transfer_blood_dna = FALSE, + max_blood = INFINITY, +) + + if(!ismovable(parent)) + return COMPONENT_INCOMPATIBLE + + src.blood_type = blood_type + src.sound_played = sound_played + src.sound_volume = sound_volume + src.blood_spawn_chance = blood_spawn_chance + src.target_dir_change = target_dir_change + src.transfer_blood_dna = transfer_blood_dna + + blood_remaining = max_blood + +/datum/component/blood_walk/RegisterWithParent() + RegisterSignal(parent, COMSIG_MOVABLE_MOVED, .proc/spread_blood) + +/datum/component/blood_walk/UnregisterFromParent() + UnregisterSignal(parent, COMSIG_MOVABLE_MOVED) + +/datum/component/blood_walk/InheritComponent( + datum/component/pricetag/new_comp, + i_am_original, + blood_type = /obj/effect/decal/cleanable/blood, + sound_played, + sound_volume = 80, + blood_spawn_chance = 100, + target_dir_change = FALSE, + transfer_blood_dna = FALSE, + max_blood = INFINITY, +) + + if(!i_am_original) + return + + if(max_blood >= INFINITY || blood_remaining >= INFINITY) + return + + // Applying a new version of the blood walk component will add the new version's step count to our's. + // We will completely disregard any other arguments passed, because we already have arguments set. + blood_remaining += max_blood + +///Spawns blood (if possible) under the source, and plays a sound effect (if any) +/datum/component/blood_walk/proc/spread_blood(datum/source) + SIGNAL_HANDLER + + var/atom/movable/movable_source = source + var/turf/current_turf = movable_source.loc + if(!isturf(current_turf)) + return + if(!prob(blood_spawn_chance)) + return + + var/obj/effect/decal/blood = new blood_type(current_turf) + if(QDELETED(blood)) // Our blood was placed on somewhere it shouldn't be and qdeleted in init. + return + + if(target_dir_change) + blood.setDir(movable_source.dir) + if(transfer_blood_dna) + blood.add_blood_DNA(GET_ATOM_BLOOD_DNA(movable_source)) + if(!isnull(sound_played)) + playsound(movable_source, sound_played, sound_volume, TRUE, 2, TRUE) + + blood_remaining = max(blood_remaining - 1, 0) + if(blood_remaining <= 0) + qdel(src) diff --git a/code/datums/elements/blood_walk.dm b/code/datums/elements/blood_walk.dm deleted file mode 100644 index 2b37bea1625..00000000000 --- a/code/datums/elements/blood_walk.dm +++ /dev/null @@ -1,56 +0,0 @@ -///Blood walk, a bespoke element that causes you to make blood wherever you walk. -/datum/element/blood_walk - element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH - id_arg_index = 2 - - ///A unique blood type we might want to spread - var/blood_type - ///The sound that plays when we spread blood. - var/sound_played - ///How loud will the sound be, if there is one. - var/sound_volume - ///The chance of spawning blood whenever walking - var/blood_spawn_chance - ///Should the decal face the direction of the target - var/target_dir_change - - -/datum/element/blood_walk/Attach( - datum/target, - blood_type = /obj/effect/decal/cleanable/blood, - sound_played, - sound_volume = 80, - blood_spawn_chance = 100, - target_dir_change = FALSE -) - . = ..() - if(!ismovable(target)) - return ELEMENT_INCOMPATIBLE - - src.blood_type = blood_type - src.sound_played = sound_played - src.sound_volume = sound_volume - src.blood_spawn_chance = blood_spawn_chance - src.target_dir_change = target_dir_change - RegisterSignal(target, COMSIG_MOVABLE_MOVED, .proc/spread_blood) - -/datum/element/blood_walk/Detach(datum/target) - . = ..() - UnregisterSignal(target, COMSIG_MOVABLE_MOVED) - -///Spawns blood (if possible) under the source, and plays a sound effect (if any) -/datum/element/blood_walk/proc/spread_blood(datum/source) - SIGNAL_HANDLER - - var/atom/movable/movable_source = source - var/turf/current_turf = movable_source.loc - if(!isturf(current_turf)) - return - if(!prob(blood_spawn_chance)) - return - - var/obj/effect/decal/blood = new blood_type(current_turf) - if (target_dir_change) - blood.setDir(movable_source.dir) - if(!isnull(sound_played)) - playsound(movable_source, sound_played, sound_volume, TRUE, 2, TRUE) diff --git a/code/modules/mob/living/simple_animal/bot/mulebot.dm b/code/modules/mob/living/simple_animal/bot/mulebot.dm index dcdf599fce5..3c412c4ebe5 100644 --- a/code/modules/mob/living/simple_animal/bot/mulebot.dm +++ b/code/modules/mob/living/simple_animal/bot/mulebot.dm @@ -52,7 +52,6 @@ var/obj/item/stock_parts/cell/cell /// Internal Powercell var/cell_move_power_usage = 1///How much power we use when we move. - var/bloodiness = 0 ///If we've run over a mob, how many tiles will we leave tracks on while moving var/num_steps = 0 ///The amount of steps we should take until we rest for a time. @@ -479,18 +478,6 @@ pathset = TRUE //Indicates the AI's custom path is initialized. start() -/mob/living/simple_animal/bot/mulebot/Move(atom/newloc, direct) //handle leaving bloody tracks. can't be done via Moved() since that can end up putting the tracks somewhere BEFORE we get bloody. - if(!bloodiness) //important to check this first since Bump() is called in the Move() -> Entered() chain - return ..() - var/atom/oldLoc = loc - . = ..() - if(!last_move || isspaceturf(oldLoc)) //if we didn't sucessfully move, or if our old location was a spaceturf. - return - var/obj/effect/decal/cleanable/blood/tracks/B = new(oldLoc) - B.add_blood_DNA(GET_ATOM_BLOOD_DNA(src)) - B.setDir(direct) - bloodiness-- - /mob/living/simple_animal/bot/mulebot/Moved() . = ..() if(has_gravity()) @@ -686,26 +673,33 @@ return ..() // when mulebot is in the same loc -/mob/living/simple_animal/bot/mulebot/proc/run_over(mob/living/carbon/human/H) - log_combat(src, H, "run over", null, "(DAMTYPE: [uppertext(BRUTE)])") - H.visible_message(span_danger("[src] drives over [H]!"), \ - span_userdanger("[src] drives over you!")) +/mob/living/simple_animal/bot/mulebot/proc/run_over(mob/living/carbon/human/crushed) + log_combat(src, crushed, "run over", addition = "(DAMTYPE: [uppertext(BRUTE)])") + crushed.visible_message( + span_danger("[src] drives over [crushed]!"), + span_userdanger("[src] drives over you!"), + ) + playsound(src, 'sound/effects/splat.ogg', 50, TRUE) - var/damage = rand(5,15) - H.apply_damage(2*damage, BRUTE, BODY_ZONE_HEAD, run_armor_check(BODY_ZONE_HEAD, MELEE)) - H.apply_damage(2*damage, BRUTE, BODY_ZONE_CHEST, run_armor_check(BODY_ZONE_CHEST, MELEE)) - H.apply_damage(0.5*damage, BRUTE, BODY_ZONE_L_LEG, run_armor_check(BODY_ZONE_L_LEG, MELEE)) - H.apply_damage(0.5*damage, BRUTE, BODY_ZONE_R_LEG, run_armor_check(BODY_ZONE_R_LEG, MELEE)) - H.apply_damage(0.5*damage, BRUTE, BODY_ZONE_L_ARM, run_armor_check(BODY_ZONE_L_ARM, MELEE)) - H.apply_damage(0.5*damage, BRUTE, BODY_ZONE_R_ARM, run_armor_check(BODY_ZONE_R_ARM, MELEE)) + var/damage = rand(5, 15) + crushed.apply_damage(2 * damage, BRUTE, BODY_ZONE_HEAD, run_armor_check(BODY_ZONE_HEAD, MELEE)) + crushed.apply_damage(2 * damage, BRUTE, BODY_ZONE_CHEST, run_armor_check(BODY_ZONE_CHEST, MELEE)) + crushed.apply_damage(0.5 * damage, BRUTE, BODY_ZONE_L_LEG, run_armor_check(BODY_ZONE_L_LEG, MELEE)) + crushed.apply_damage(0.5 * damage, BRUTE, BODY_ZONE_R_LEG, run_armor_check(BODY_ZONE_R_LEG, MELEE)) + crushed.apply_damage(0.5 * damage, BRUTE, BODY_ZONE_L_ARM, run_armor_check(BODY_ZONE_L_ARM, MELEE)) + crushed.apply_damage(0.5 * damage, BRUTE, BODY_ZONE_R_ARM, run_armor_check(BODY_ZONE_R_ARM, MELEE)) - var/turf/T = get_turf(src) - T.add_mob_blood(H) + add_mob_blood(crushed) - var/list/blood_dna = H.get_blood_dna_list() - add_blood_DNA(blood_dna) - bloodiness += 4 + var/turf/below_us = get_turf(src) + below_us.add_mob_blood(crushed) + + AddComponent(/datum/component/blood_walk, \ + blood_type = /obj/effect/decal/cleanable/blood/tracks, \ + target_dir_change = TRUE, \ + transfer_blood_dna = TRUE, \ + max_blood = 4) // player on mulebot attempted to move /mob/living/simple_animal/bot/mulebot/relaymove(mob/living/user, direction) diff --git a/code/modules/mob/living/simple_animal/heretic_monsters.dm b/code/modules/mob/living/simple_animal/heretic_monsters.dm index 91469ab0bb9..95764041976 100644 --- a/code/modules/mob/living/simple_animal/heretic_monsters.dm +++ b/code/modules/mob/living/simple_animal/heretic_monsters.dm @@ -187,7 +187,9 @@ if(!spawn_bodyparts) return - AddElement(/datum/element/blood_walk, /obj/effect/decal/cleanable/blood/tracks, target_dir_change = TRUE) + AddComponent(/datum/component/blood_walk, \ + blood_type = /obj/effect/decal/cleanable/blood/tracks, \ + target_dir_change = TRUE) allow_pulling = TRUE // Sets the hp of the head to be exactly the (length * hp), so the head is de facto the hardest to destroy. diff --git a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm index 0f02e0272cc..42cc79901f4 100644 --- a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm +++ b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm @@ -675,7 +675,9 @@ /mob/living/simple_animal/hostile/giant_spider/hunter/flesh/Initialize(mapload) . = ..() - AddElement(/datum/element/blood_walk, /obj/effect/decal/cleanable/blood/bubblegum, blood_spawn_chance = 5) + AddComponent(/datum/component/blood_walk, \ + blood_type = /obj/effect/decal/cleanable/blood/bubblegum, \ + blood_spawn_chance = 5) /mob/living/simple_animal/hostile/giant_spider/hunter/flesh/AttackingTarget() if(is_busy) diff --git a/code/modules/mob/living/simple_animal/hostile/megafauna/bubblegum.dm b/code/modules/mob/living/simple_animal/hostile/megafauna/bubblegum.dm index 06843b08914..bdb1e8ac93d 100644 --- a/code/modules/mob/living/simple_animal/hostile/megafauna/bubblegum.dm +++ b/code/modules/mob/living/simple_animal/hostile/megafauna/bubblegum.dm @@ -100,7 +100,10 @@ Difficulty: Hard RegisterSignal(src, COMSIG_BLOOD_WARP, .proc/blood_enrage) RegisterSignal(src, COMSIG_FINISHED_CHARGE, .proc/after_charge) if(spawn_blood) - AddElement(/datum/element/blood_walk, /obj/effect/decal/cleanable/blood/bubblegum, 'sound/effects/meteorimpact.ogg', 200) + AddComponent(/datum/component/blood_walk, \ + blood_type = /obj/effect/decal/cleanable/blood/bubblegum, \ + sound_played = 'sound/effects/meteorimpact.ogg', \ + sound_volume = 200) /mob/living/simple_animal/hostile/megafauna/bubblegum/Destroy() QDEL_NULL(triple_charge) diff --git a/tgstation.dme b/tgstation.dme index 389c0c4ff27..f4c5f3853a6 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -781,6 +781,7 @@ #include "code\datums\components\aura_healing.dm" #include "code\datums\components\bakeable.dm" #include "code\datums\components\beetlejuice.dm" +#include "code\datums\components\blood_walk.dm" #include "code\datums\components\bloodysoles.dm" #include "code\datums\components\boomerang.dm" #include "code\datums\components\butchering.dm" @@ -1018,7 +1019,6 @@ #include "code\datums\elements\basic_body_temp_sensitive.dm" #include "code\datums\elements\beauty.dm" #include "code\datums\elements\bed_tucking.dm" -#include "code\datums\elements\blood_walk.dm" #include "code\datums\elements\bsa_blocker.dm" #include "code\datums\elements\bump_click.dm" #include "code\datums\elements\chemical_transfer.dm"