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
@@ -103,6 +103,10 @@
|
|||||||
#define COMSIG_MOVABLE_THROW "movable_throw" //from base of atom/movable/throw_at(): (datum/thrownthing, spin)
|
#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)
|
#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
|
// /mob/living signals
|
||||||
#define COMSIG_LIVING_RESIST "living_resist" //from base of mob/living/resist() (/mob/living)
|
#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_IGNITED "living_ignite" //from base of mob/living/IgniteMob() (/mob/living)
|
||||||
|
|||||||
@@ -1,44 +1,26 @@
|
|||||||
/datum/component/anti_magic
|
/datum/component/anti_magic
|
||||||
var/active = TRUE
|
|
||||||
var/magic = FALSE
|
var/magic = FALSE
|
||||||
var/holy = FALSE
|
var/holy = FALSE
|
||||||
|
|
||||||
/datum/component/anti_magic/Initialize(_magic = FALSE, _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
|
magic = _magic
|
||||||
holy = _holy
|
holy = _holy
|
||||||
|
|
||||||
/datum/component/anti_magic/proc/can_protect(_magic = TRUE, _holy = FALSE)
|
/datum/component/anti_magic/proc/on_equip(mob/equipper, slot)
|
||||||
if(!active)
|
RegisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC, .proc/can_protect, TRUE)
|
||||||
return FALSE
|
|
||||||
|
/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))
|
if((_magic && magic) || (_holy && holy))
|
||||||
return TRUE
|
protection_sources += parent
|
||||||
return FALSE
|
return COMPONENT_BLOCK_MAGIC
|
||||||
|
|
||||||
/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
|
|
||||||
|
|||||||
@@ -869,6 +869,13 @@
|
|||||||
|
|
||||||
apply_effect((amount*RAD_MOB_COEFFICIENT)/max(1, (radiation**2)*RAD_OVERDOSE_REDUCTION), EFFECT_IRRADIATE, blocked)
|
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()
|
/mob/living/proc/fakefireextinguish()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -683,6 +683,16 @@
|
|||||||
mob_spell_list -= S
|
mob_spell_list -= S
|
||||||
qdel(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
|
//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)
|
/mob/buckle_mob(mob/living/M, force = FALSE, check_loc = TRUE)
|
||||||
if(M.buckled)
|
if(M.buckled)
|
||||||
|
|||||||
Reference in New Issue
Block a user