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 d1f58f2e3ce..656c90d77bb 100644 --- a/code/modules/library/bibles.dm +++ b/code/modules/library/bibles.dm @@ -77,29 +77,24 @@ 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,\ ) -/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" @@ -107,7 +102,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) . = ..()