Skip to content

Commit

Permalink
Chunk and effect code cleanliness
Browse files Browse the repository at this point in the history
lifemerger now utilizes a timer&callback instead of spawn()
  • Loading branch information
Mechoid committed Dec 9, 2023
1 parent f28c264 commit 066bcd8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
6 changes: 3 additions & 3 deletions code/modules/blob2/overmind/chunks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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]."))
Expand All @@ -93,7 +93,7 @@
name = "weakened [name]"
desc += " It can no longer reproduce."

if(C && C.overmind)
if(C?.overmind)
return TRUE

return
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/xenoarcheaology/effects/disarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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]."))
Expand Down
79 changes: 42 additions & 37 deletions code/modules/xenoarcheaology/effects/lifemerger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand All @@ -48,39 +49,43 @@
"<span class='danger'>A bright beam beam lashes out from [bicon(get_master_holder())] \the [get_master_holder()] at \the [L]!</span>")
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!

0 comments on commit 066bcd8

Please sign in to comment.