Replaces HEALS_EARS_2 with a component, adds a wearertargeting parent component for future use
This commit is contained in:
committed by
CitadelStationBot
parent
e66e348d5c
commit
ec2de88a65
@@ -0,0 +1,30 @@
|
||||
// An item worn in the ear slot with this component will heal your ears each
|
||||
// Life() tick, even if normally your ears would be too damaged to heal.
|
||||
|
||||
/datum/component/earhealing
|
||||
var/mob/living/carbon/wearer
|
||||
|
||||
/datum/component/earhealing/Initialize()
|
||||
if(!isitem(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
RegisterSignal(list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED), .proc/equippedChanged)
|
||||
|
||||
/datum/component/earhealing/proc/equippedChanged(mob/living/carbon/user, slot)
|
||||
if (slot == SLOT_EARS && istype(user))
|
||||
if (!wearer)
|
||||
START_PROCESSING(SSobj, src)
|
||||
wearer = user
|
||||
else
|
||||
if (wearer)
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
wearer = null
|
||||
|
||||
/datum/component/earhealing/process()
|
||||
if (!wearer)
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
return
|
||||
if(!wearer.has_trait(TRAIT_DEAF))
|
||||
var/obj/item/organ/ears/ears = wearer.getorganslot(ORGAN_SLOT_EARS)
|
||||
if (ears)
|
||||
ears.deaf = max(ears.deaf - 1, (ears.ear_damage < UNHEALING_EAR_DAMAGE ? 0 : 1)) // Do not clear deafness while above the unhealing ear damage threshold
|
||||
ears.ear_damage = max(ears.ear_damage - 0.1, 0)
|
||||
@@ -0,0 +1,26 @@
|
||||
// A dummy parent type used for easily making components that target an item's wearer rather than the item itself.
|
||||
|
||||
/datum/component/wearertargeting
|
||||
var/datum/component/mobhook
|
||||
var/list/valid_slots = list()
|
||||
var/list/signals = list()
|
||||
var/datum/callback/callback = CALLBACK(GLOBAL_PROC, .proc/pass)
|
||||
var/mobtype = /mob/living
|
||||
|
||||
/datum/component/wearertargeting/Initialize()
|
||||
if(!isitem(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
RegisterSignal(list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED), .proc/checkMobHook)
|
||||
|
||||
/datum/component/wearertargeting/Destroy()
|
||||
QDEL_NULL(mobhook)
|
||||
return ..()
|
||||
|
||||
/datum/component/wearertargeting/proc/checkMobHook(mob/user, slot)
|
||||
if ((slot in valid_slots) && istype(user, mobtype))
|
||||
if (mobhook && mobhook.parent != user)
|
||||
QDEL_NULL(mobhook)
|
||||
if (!mobhook)
|
||||
mobhook = user.AddComponent(/datum/component/redirect, signals, callback)
|
||||
else
|
||||
QDEL_NULL(mobhook)
|
||||
Reference in New Issue
Block a user