From a0a008f6e4b6e003e318d18b891e520ac471d780 Mon Sep 17 00:00:00 2001 From: NovaBot <154629622+NovaBot13@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:54:59 -0500 Subject: [PATCH] [MIRROR] Small bible / bullet catcher component code cleanup (#1291) * Small bible / bullet catcher component code cleanup (#81835) ## About The Pull Request Saw this weird use of storing a component in a var when it didn't really need to be so I just refactored it a little bit. * Small bible / bullet catcher component code cleanup --------- Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- code/datums/components/bullet_intercepting.dm | 14 ++++++++++---- code/modules/library/bibles.dm | 14 ++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/code/datums/components/bullet_intercepting.dm b/code/datums/components/bullet_intercepting.dm index c176de54b94..32e757c1823 100644 --- a/code/datums/components/bullet_intercepting.dm +++ b/code/datums/components/bullet_intercepting.dm @@ -12,8 +12,10 @@ var/mob/wearer /// Callback called when we catch a projectile var/datum/callback/on_intercepted + /// Number of things we can block before we delete ourself (stop being able to block) + var/block_charges = INFINITY -/datum/component/bullet_intercepting/Initialize(block_chance = 2, block_type = BULLET, active_slots, datum/callback/on_intercepted) +/datum/component/bullet_intercepting/Initialize(block_chance = 2, block_type = BULLET, active_slots, datum/callback/on_intercepted, block_charges = INFINITY) . = ..() if (!isitem(parent)) return COMPONENT_INCOMPATIBLE @@ -21,6 +23,7 @@ src.block_type = block_type src.active_slots = active_slots src.on_intercepted = on_intercepted + src.block_charges = block_charges RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(on_parent_equipped)) RegisterSignal(parent, COMSIG_ITEM_PRE_UNEQUIP, PROC_REF(on_unequipped)) @@ -55,11 +58,14 @@ /// Called when wearer is shot, check if we're going to block the hit /datum/component/bullet_intercepting/proc/on_wearer_shot(mob/living/victim, list/signal_args, obj/projectile/bullet) SIGNAL_HANDLER - if (victim != wearer || victim.stat == DEAD || bullet.armor_flag != block_type ) - return + if (victim != wearer || victim.stat == DEAD || bullet.armor_flag != block_type) + return NONE if (!prob(block_chance)) - return + return NONE on_intercepted?.Invoke(victim, bullet) + block_charges-- + if (block_charges <= 0) + qdel(src) return PROJECTILE_INTERRUPT_HIT /// Called when wearer is deleted, stop tracking them diff --git a/code/modules/library/bibles.dm b/code/modules/library/bibles.dm index 6a5d1b1d5c4..04c95d5088f 100644 --- a/code/modules/library/bibles.dm +++ b/code/modules/library/bibles.dm @@ -77,30 +77,25 @@ GLOBAL_LIST_INIT(bibleitemstates, list( unique = TRUE /// Deity this bible is related to var/deity_name = "Space Jesus" - /// Component which catches bullets for us - var/datum/component/bullet_catcher /obj/item/book/bible/Initialize(mapload) . = ..() AddComponent(/datum/component/anti_magic, MAGIC_RESISTANCE_HOLY) - bullet_catcher = AddComponent(\ + AddComponent(\ /datum/component/bullet_intercepting,\ active_slots = ITEM_SLOT_SUITSTORE,\ on_intercepted = CALLBACK(src, PROC_REF(on_intercepted_bullet)),\ + block_charges = 1,\ ) carve_out() -/obj/item/book/bible/Destroy(force) - QDEL_NULL(bullet_catcher) - return ..() - /// Destroy the bible when it's shot by a bullet /obj/item/book/bible/proc/on_intercepted_bullet(mob/living/victim, obj/projectile/bullet) victim.add_mood_event("blessing", /datum/mood_event/blessing) playsound(victim, 'sound/magic/magic_block_holy.ogg', 50, TRUE) - victim.visible_message(span_warning("\The [src] takes \the [bullet] in [victim]'s place!")) + victim.visible_message(span_warning("[src] takes [bullet] in [victim]'s place!")) var/obj/structure/fluff/paper/stack/pages = new(get_turf(src)) - pages.dir = pick(GLOB.alldirs) + pages.setDir(pick(GLOB.alldirs)) name = "punctured bible" desc = "A memento of good luck, or perhaps divine intervention?" icon_state = "shot" @@ -108,7 +103,6 @@ GLOBAL_LIST_INIT(bibleitemstates, list( GLOB.bible_icon_state = "shot" // New symbol of your religion if you hadn't picked one atom_storage?.remove_all(get_turf(src)) QDEL_NULL(atom_storage) - QDEL_NULL(bullet_catcher) /obj/item/book/bible/examine(mob/user) . = ..()