Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Small bible / bullet catcher component code cleanup #2275

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions code/datums/components/bullet_intercepting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
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
src.block_chance = block_chance
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))
Expand Down Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions code/modules/library/bibles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,32 @@ 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"
if (!GLOB.bible_icon_state)
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)
. = ..()
Expand Down
Loading