From c8f5791557131c35952a2c5527fbd4c71d349f1a Mon Sep 17 00:00:00 2001 From: Emmett Gaines Date: Thu, 5 Jul 2018 04:26:14 -0400 Subject: [PATCH] Converts antimagic from GetComponent to a signal --- code/__DEFINES/components.dm | 12 +++++++ code/datums/components/anti_magic.dm | 52 +++++++++------------------- code/modules/mob/living/living.dm | 7 ++++ code/modules/mob/mob.dm | 10 ++++++ 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index 7c00573089..cca2814966 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -98,6 +98,18 @@ #define COMSIG_MOVABLE_THROW "movable_throw" //from base of atom/movable/throw_at(): (datum/thrownthing, spin) #define COMSIG_MOVABLE_Z_CHANGED "movable_ztransit" //from base of atom/movable/onTransitZ(): (old_z, new_z) +<<<<<<< HEAD +======= +// /mob Signals +#define COMSIG_MOB_RECEIVE_MAGIC "mob_receive_magic" //from base of mob/anti_magic_check(): (magic, holy, protection_sources) + #define COMPONENT_BLOCK_MAGIC 1 + +// /mob/living signals +#define COMSIG_LIVING_RESIST "living_resist" //from base of mob/living/resist() (/mob/living) +#define COMSIG_LIVING_IGNITED "living_ignite" //from base of mob/living/IgniteMob() (/mob/living) +#define COMSIG_LIVING_EXTINGUISHED "living_extinguished" //from base of mob/living/ExtinguishMob() (/mob/living) + +>>>>>>> 3167e2b... Rewrites the antimagic component to properly use signals (#38649) // /mob/living/carbon signals #define COMSIG_CARBON_SOUNDBANG "carbon_soundbang" //from base of mob/living/carbon/soundbang_act(): (list(intensity)) diff --git a/code/datums/components/anti_magic.dm b/code/datums/components/anti_magic.dm index be4e08eaca..cc703e12dc 100644 --- a/code/datums/components/anti_magic.dm +++ b/code/datums/components/anti_magic.dm @@ -1,44 +1,26 @@ /datum/component/anti_magic - var/active = TRUE var/magic = FALSE var/holy = FALSE /datum/component/anti_magic/Initialize(_magic = FALSE, _holy = FALSE) + if(isitem(parent)) + RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/on_equip) + RegisterSignal(parent, COMSIG_ITEM_DROPPED, .proc/on_drop) + else if(ismob(parent)) + RegisterSignal(parent, COMSIG_MOB_RECEIVE_MAGIC, .proc/can_protect) + else + return COMPONENT_INCOMPATIBLE + magic = _magic holy = _holy -/datum/component/anti_magic/proc/can_protect(_magic = TRUE, _holy = FALSE) - if(!active) - return FALSE +/datum/component/anti_magic/proc/on_equip(mob/equipper, slot) + RegisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC, .proc/can_protect, TRUE) + +/datum/component/anti_magic/proc/on_drop(mob/user) + UnregisterSignal(user, COMSIG_MOB_RECEIVE_MAGIC) + +/datum/component/anti_magic/proc/can_protect(_magic, _holy, list/protection_sources) if((_magic && magic) || (_holy && holy)) - return TRUE - return FALSE - -/mob/proc/anti_magic_check(magic = TRUE, holy = FALSE) - if(!magic && !holy) - return - var/list/obj/item/item_list = list() - item_list |= held_items - for(var/obj/O in item_list) - GET_COMPONENT_FROM(anti_magic, /datum/component/anti_magic, O) - if(!anti_magic) - continue - if(anti_magic.can_protect(magic, holy)) - return O - -/mob/living/anti_magic_check(magic = TRUE, holy = FALSE) - if(!magic && !holy) - return - - if((magic && has_trait(TRAIT_ANTIMAGIC)) || (holy && has_trait(TRAIT_HOLY))) - return src - - var/list/obj/item/item_list = list() - item_list |= get_equipped_items(TRUE) - item_list |= held_items - for(var/obj/O in item_list) - GET_COMPONENT_FROM(anti_magic, /datum/component/anti_magic, O) - if(!anti_magic) - continue - if(anti_magic.can_protect(magic, holy)) - return O \ No newline at end of file + protection_sources += parent + return COMPONENT_BLOCK_MAGIC diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 71999fa7a5..afc83c48b7 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -911,6 +911,13 @@ apply_effect((amount*RAD_MOB_COEFFICIENT)/max(1, (radiation**2)*RAD_OVERDOSE_REDUCTION), EFFECT_IRRADIATE, blocked) +/mob/living/anti_magic_check(magic = TRUE, holy = FALSE) + . = ..() + if(.) + return + if((magic && has_trait(TRAIT_ANTIMAGIC)) || (holy && has_trait(TRAIT_HOLY))) + return src + /mob/living/proc/fakefireextinguish() return diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 3dd6129ea3..68a6c07ffe 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -689,6 +689,16 @@ mob_spell_list -= S qdel(S) +/mob/proc/anti_magic_check(magic = TRUE, holy = FALSE) + if(!magic && !holy) + return + var/list/protection_sources = list() + if(SEND_SIGNAL(src, COMSIG_MOB_RECEIVE_MAGIC, magic, holy, protection_sources) & COMPONENT_BLOCK_MAGIC) + if(protection_sources.len) + return pick(protection_sources) + else + return src + //You can buckle on mobs if you're next to them since most are dense /mob/buckle_mob(mob/living/M, force = FALSE, check_loc = TRUE) if(M.buckled)