This commit is contained in:
Fikou
2021-12-24 12:00:24 -08:00
committed by GitHub
parent fc5c9e2900
commit 7b38dd4ff7
191 changed files with 6749 additions and 2189 deletions
+29 -18
View File
@@ -1,5 +1,5 @@
/**
* The shielded component causes the parent item to nullify a certain number of attacks against the wearer, see: shielded hardsuits.
* The shielded component causes the parent item to nullify a certain number of attacks against the wearer, see: shielded vests.
*/
/datum/component/shielded
@@ -23,6 +23,8 @@
var/shield_inhand = FALSE
/// Should the shield lose charges equal to the damage dealt by a hit?
var/lose_multiple_charges = FALSE
/// The item we use for recharging
var/recharge_path
/// The cooldown tracking when we were last hit
COOLDOWN_DECLARE(recently_hit_cd)
/// The cooldown tracking when we last replenished a charge
@@ -30,7 +32,7 @@
/// A callback for the sparks/message that play when a charge is used, see [/datum/component/shielded/proc/default_run_hit_callback]
var/datum/callback/on_hit_effects
/datum/component/shielded/Initialize(max_charges = 3, recharge_start_delay = 20 SECONDS, charge_increment_delay = 1 SECONDS, charge_recovery = 1, lose_multiple_charges = FALSE, shield_icon_file = 'icons/effects/effects.dmi', shield_icon = "shield-old", shield_inhand = FALSE, run_hit_callback)
/datum/component/shielded/Initialize(max_charges = 3, recharge_start_delay = 20 SECONDS, charge_increment_delay = 1 SECONDS, charge_recovery = 1, lose_multiple_charges = FALSE, recharge_path = null, starting_charges = null, shield_icon_file = 'icons/effects/effects.dmi', shield_icon = "shield-old", shield_inhand = FALSE, run_hit_callback)
if(!isitem(parent) || max_charges <= 0)
return COMPONENT_INCOMPATIBLE
@@ -39,12 +41,15 @@
src.charge_increment_delay = charge_increment_delay
src.charge_recovery = charge_recovery
src.lose_multiple_charges = lose_multiple_charges
src.recharge_path = recharge_path
src.shield_icon_file = shield_icon_file
src.shield_icon = shield_icon
src.shield_inhand = shield_inhand
src.on_hit_effects = run_hit_callback || CALLBACK(src, .proc/default_run_hit_callback)
current_charges = max_charges
if(isnull(starting_charges))
current_charges = max_charges
else
current_charges = starting_charges
if(recharge_start_delay)
START_PROCESSING(SSdcs, src)
@@ -62,9 +67,18 @@
RegisterSignal(parent, COMSIG_ITEM_DROPPED, .proc/lost_wearer)
RegisterSignal(parent, COMSIG_ITEM_HIT_REACT, .proc/on_hit_react)
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/check_recharge_rune)
var/atom/shield = parent
if(ismob(shield.loc))
var/mob/holder = shield.loc
if(holder.is_holding(parent) && !shield_inhand)
return
set_wearer(holder)
/datum/component/shielded/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED, COMSIG_ITEM_HIT_REACT, COMSIG_PARENT_ATTACKBY))
var/atom/shield = parent
if(shield.loc == wearer)
lost_wearer(src, wearer)
// Handle recharging, if we want to
/datum/component/shielded/process(delta_time)
@@ -96,12 +110,7 @@
if(slot == ITEM_SLOT_HANDS && !shield_inhand)
lost_wearer(source, user)
return
wearer = user
RegisterSignal(wearer, COMSIG_ATOM_UPDATE_OVERLAYS, .proc/on_update_overlays)
RegisterSignal(wearer, COMSIG_PARENT_QDELETING, .proc/lost_wearer)
if(current_charges)
wearer.update_appearance(UPDATE_ICON)
set_wearer(source, user)
/// Either we've been dropped or our wearer has been QDEL'd. Either way, they're no longer our problem
/datum/component/shielded/proc/lost_wearer(datum/source, mob/user)
@@ -112,6 +121,13 @@
wearer.update_appearance(UPDATE_ICON)
wearer = null
/datum/component/shielded/proc/set_wearer(mob/user)
wearer = user
RegisterSignal(wearer, COMSIG_ATOM_UPDATE_OVERLAYS, .proc/on_update_overlays)
RegisterSignal(wearer, COMSIG_PARENT_QDELETING, .proc/lost_wearer)
if(current_charges)
wearer.update_appearance(UPDATE_ICON)
/// Used to draw the shield overlay on the wearer
/datum/component/shielded/proc/on_update_overlays(atom/parent_atom, list/overlays)
SIGNAL_HANDLER
@@ -141,8 +157,6 @@
INVOKE_ASYNC(src, .proc/actually_run_hit_callback, owner, attack_text, current_charges)
if(!recharge_start_delay) // if recharge_start_delay is 0, we don't recharge
if(!current_charges) // obviously if someone ever adds a manual way to replenish charges, change this
qdel(src)
return
START_PROCESSING(SSdcs, src) // if we DO recharge, start processing so we can do that
@@ -158,16 +172,13 @@
if(current_charges <= 0)
owner.visible_message(span_warning("[owner]'s shield overloads!"))
/datum/component/shielded/proc/check_recharge_rune(datum/source, obj/item/wizard_armour_charge/recharge_rune, mob/living/user)
/datum/component/shielded/proc/check_recharge_rune(datum/source, obj/item/recharge_rune, mob/living/user)
SIGNAL_HANDLER
if(!istype(recharge_rune))
if(!istype(recharge_rune, recharge_path))
return
. = COMPONENT_NO_AFTERATTACK
if(!istype(parent, /obj/item/clothing/suit/space/hardsuit/shielded/wizard))
to_chat(user, span_warning("The rune can only be used on battlemage armour!"))
return
current_charges += recharge_rune.restored_charges
adjust_charge(charge_recovery)
to_chat(user, span_notice("You charge \the [parent]. It can now absorb [current_charges] hits."))
qdel(recharge_rune)