From 066bcd821642358f99d82737d24de7fb1b9ebfdd Mon Sep 17 00:00:00 2001 From: Mechoid Date: Sat, 9 Dec 2023 09:33:16 -0800 Subject: [PATCH] Chunk and effect code cleanliness lifemerger now utilizes a timer&callback instead of spawn() --- code/modules/blob2/overmind/chunks.dm | 6 +- .../modules/xenoarcheaology/effects/disarm.dm | 2 +- .../xenoarcheaology/effects/lifemerger.dm | 79 ++++++++++--------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/code/modules/blob2/overmind/chunks.dm b/code/modules/blob2/overmind/chunks.dm index 00ee5723b7d..ac39c24b3ec 100644 --- a/code/modules/blob2/overmind/chunks.dm +++ b/code/modules/blob2/overmind/chunks.dm @@ -66,7 +66,7 @@ /obj/item/blob_chunk/afterattack(var/atom/target, var/mob/user, var/proximity) if(proximity && Adjacent(target)) user.visible_message(SPAN_WARNING("[user] holds \the [src] toward [target].")) - if(istype(target, /mob/living) && do_after(user, 3 SECONDS, target)) + if(isliving(target) && do_after(user, 3 SECONDS, target)) var/mob/living/L = target user.visible_message(SPAN_WARNING("[bicon(src)] \the [src] inflates slighty, before it releases a puff of gas toward [L].")) @@ -93,7 +93,7 @@ name = "weakened [name]" desc += " It can no longer reproduce." - if(C && C.overmind) + if(C?.overmind) return TRUE return @@ -107,7 +107,7 @@ /datum/component/artifact_master/blob/do_setup() ..() - if(holder && istype(holder, /obj/item/blob_chunk)) + if(istype(holder, /obj/item/blob_chunk)) var/obj/item/blob_chunk/type_source = holder for(var/datum/artifact_effect/AE in my_effects) diff --git a/code/modules/xenoarcheaology/effects/disarm.dm b/code/modules/xenoarcheaology/effects/disarm.dm index 26e0566afef..5ad598d6356 100644 --- a/code/modules/xenoarcheaology/effects/disarm.dm +++ b/code/modules/xenoarcheaology/effects/disarm.dm @@ -6,7 +6,7 @@ effect_color = "#e17ceb" /datum/artifact_effect/uncommon/disarmament/proc/disarm(var/mob/living/L) - if(L.is_sentient()) + if(istype(L) && L.is_sentient()) var/obj/item/Item = L.get_active_hand() if(istype(Item)) to_chat(L, SPAN_WARNING("Something forces you to drop \the [Item].")) diff --git a/code/modules/xenoarcheaology/effects/lifemerger.dm b/code/modules/xenoarcheaology/effects/lifemerger.dm index fca600d25e2..8db8ef2b9da 100644 --- a/code/modules/xenoarcheaology/effects/lifemerger.dm +++ b/code/modules/xenoarcheaology/effects/lifemerger.dm @@ -3,6 +3,7 @@ effect_color = "#3b1f3b" effect_type = EFFECT_ENERGY var/list/active_beams + var/merging = FALSE /datum/artifact_effect/extreme/lifemerger/DoEffectTouch() mergelife() @@ -22,7 +23,7 @@ var/turf/T = get_turf(holder) var/list/nearby_mobs = list() - for(var/mob/living/L in oview(world.view, T)) + for(var/mob/living/L in view(world.view, T) - holder) if(L.stat != DEAD) nearby_mobs |= L @@ -48,39 +49,43 @@ "A bright beam beam lashes out from [bicon(get_master_holder())] \the [get_master_holder()] at \the [L]!") var/datum/beam/drain_beam = holder.Beam(L, icon_state = "medbeam", time = 3 SECONDS * nearby_mobs.len) active_beams |= drain_beam - - spawn(2 SECONDS * nearby_mobs.len) - listclearnulls(active_beams) // Clear nulls from mobs leaving the range. - if(active_beams.len >= 2) // Work with remaining beams to find still-valid targets, if we still have 2 or more. - var/list/remaining_mobs = list() - var/brute_avg = 0 - var/burn_avg = 0 - var/oxy_avg = 0 - var/tox_avg = 0 - for(var/datum/beam/Beam in active_beams) // Find remaining beams' targets and their damage values. - if(Beam.target in nearby_mobs) - remaining_mobs |= Beam.target - var/mob/living/L = Beam.target - brute_avg += L.getBruteLoss() - burn_avg += L.getFireLoss() - oxy_avg += L.getOxyLoss() - tox_avg += L.getToxLoss() - - if(remaining_mobs.len) // Average by the number of remaining mobs. - brute_avg /= remaining_mobs.len - burn_avg /= remaining_mobs.len - oxy_avg /= remaining_mobs.len - tox_avg /= remaining_mobs.len - - for(var/mob/living/L in remaining_mobs) // Adjust brute, burn, oxy, and tox of remaining mobs to the average - L.adjustBruteLoss(brute_avg - L.getBruteLoss()) - L.adjustFireLoss(burn_avg - L.getFireLoss()) - L.adjustOxyLoss(oxy_avg - L.getOxyLoss()) - L.adjustToxLoss(tox_avg - L.getToxLoss()) - - L.add_modifier(/datum/modifier/berserk_exhaustion, remaining_mobs.len * 2 SECONDS) - - for(var/datum/beam/Beam in active_beams) // Cull the beams. - Beam.End() - - listclearnulls(active_beams) // Cull the nulls. + if(!merging) // Don't add a ton of timers if this procs faster than 2 seconds, just average every 2. + merging = TRUE + addtimer(CALLBACK(src, .proc/averagelife), 2 SECONDS) + +/datum/artifact_effect/extreme/lifemerger/proc/averagelife() + listclearnulls(active_beams) // Clear nulls from mobs leaving the range. + if(active_beams.len >= 2) // Work with remaining beams to find still-valid targets, if we still have 2 or more. + var/list/remaining_mobs = list() + var/brute_avg = 0 + var/burn_avg = 0 + var/oxy_avg = 0 + var/tox_avg = 0 + for(var/datum/beam/Beam in active_beams) // Find remaining beams' targets and their damage values. + if(isliving(Beam.target)) + remaining_mobs |= Beam.target + var/mob/living/L = Beam.target + brute_avg += L.getBruteLoss() + burn_avg += L.getFireLoss() + oxy_avg += L.getOxyLoss() + tox_avg += L.getToxLoss() + + if(remaining_mobs.len) // Average by the number of remaining mobs. + brute_avg /= remaining_mobs.len + burn_avg /= remaining_mobs.len + oxy_avg /= remaining_mobs.len + tox_avg /= remaining_mobs.len + + for(var/mob/living/L in remaining_mobs) // Adjust brute, burn, oxy, and tox of remaining mobs to the average + L.adjustBruteLoss(brute_avg - L.getBruteLoss()) + L.adjustFireLoss(burn_avg - L.getFireLoss()) + L.adjustOxyLoss(oxy_avg - L.getOxyLoss()) + L.adjustToxLoss(tox_avg - L.getToxLoss()) + + L.add_modifier(/datum/modifier/berserk_exhaustion, remaining_mobs.len * 2 SECONDS) + + for(var/datum/beam/Beam in active_beams) // Cull the beams. + Beam.End() + + listclearnulls(active_beams) // Cull the nulls. + merging = FALSE // We're done!