diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index 3cd9ad70e9..b4131a0bc9 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -103,6 +103,10 @@ #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) +// /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) @@ -201,4 +205,4 @@ //Ouch my toes! #define CALTROP_BYPASS_SHOES 1 -#define CALTROP_IGNORE_WALKERS 2 +#define CALTROP_IGNORE_WALKERS 2 \ No newline at end of file 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 5db817ef8a..24627f7eec 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -894,6 +894,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 5db0c81a9f..6deffc97da 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -693,6 +693,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)