mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
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:
committed by
yogstation13-bot
parent
526e2927e1
commit
b4ea1c1487
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user