Rewrites the antimagic component to properly use signals (#38649)

It's been updated to make use of the signal refactor and other code cleaned up. As a free side benefit I also made it work if applied to mobs directly.
This commit is contained in:
Emmett Gaines
2018-07-05 04:26:14 -04:00
committed by yogstation13-bot
parent 526e2927e1
commit b4ea1c1487
4 changed files with 38 additions and 35 deletions

View File

@@ -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)

View File

@@ -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
protection_sources += parent
return COMPONENT_BLOCK_MAGIC

View File

@@ -869,6 +869,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

View File

@@ -683,6 +683,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)