mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Finishes off remaining anti_magic_check and uses the proper version (#20583)
* Replaces last instances of antimagic check with can_block_magic * Updates antimagic component * Fixes 2 issues I caused * Fixes charge_cost * finishes le port * Uses right icons
This commit is contained in:
@@ -1,49 +1,131 @@
|
||||
/// This provides different types of magic resistance on an object
|
||||
/datum/component/anti_magic
|
||||
var/magic = FALSE
|
||||
var/holy = FALSE
|
||||
var/psychic = FALSE
|
||||
var/allowed_slots = ~ITEM_SLOT_BACKPACK
|
||||
var/charges = INFINITY
|
||||
var/blocks_self = TRUE
|
||||
var/datum/callback/reaction
|
||||
var/datum/callback/expire
|
||||
/// A bitflag with the types of magic resistance on the object
|
||||
var/antimagic_flags
|
||||
/// The amount of times the object can protect the user from magic
|
||||
/// Set to INFINITY to have, well, infinite charges.
|
||||
var/charges
|
||||
/// The inventory slot the object must be located at in order to activate
|
||||
var/inventory_flags
|
||||
/// The callback invoked when we have been drained a antimagic charge
|
||||
var/datum/callback/drain_antimagic
|
||||
/// The callback invoked when twe have been depleted of all charges
|
||||
var/datum/callback/expiration
|
||||
/// Whether we should, on equipping, alert the caster that this item can block any of their spells
|
||||
/// This changes between true and false on equip and drop, don't set it outright to something
|
||||
var/alert_caster_on_equip = TRUE
|
||||
|
||||
/**
|
||||
* Adds magic resistances to an object
|
||||
*
|
||||
* Magic resistance will prevent magic from affecting the user if it has the correct resistance
|
||||
* against the type of magic being used
|
||||
*
|
||||
* args:
|
||||
* * antimagic_flags (optional) A bitflag with the types of magic resistance on the object
|
||||
* * charges (optional) The amount of times the object can protect the user from magic
|
||||
* * inventory_flags (optional) The inventory slot the object must be located at in order to activate
|
||||
* * drain_antimagic (optional) The proc that is triggered when an object has been drained a antimagic charge
|
||||
* * expiration (optional) The proc that is triggered when the object is depleted of charges
|
||||
* *
|
||||
* antimagic bitflags: (see code/__DEFINES/magic.dm)
|
||||
* * MAGIC_RESISTANCE - Default magic resistance that blocks normal magic (wizard, spells, staffs)
|
||||
* * MAGIC_RESISTANCE_MIND - Tinfoil hat magic resistance that blocks mental magic (telepathy, abductors, jelly people)
|
||||
* * MAGIC_RESISTANCE_HOLY - Holy magic resistance that blocks unholy magic (revenant, cult, vampire, voice of god)
|
||||
**/
|
||||
/datum/component/anti_magic/Initialize(
|
||||
antimagic_flags = MAGIC_RESISTANCE,
|
||||
charges = INFINITY,
|
||||
inventory_flags = ~ITEM_SLOT_BACKPACK, // items in a backpack won't activate, anywhere else is fine
|
||||
datum/callback/drain_antimagic,
|
||||
datum/callback/expiration,
|
||||
)
|
||||
|
||||
/datum/component/anti_magic/Initialize(_magic = FALSE, _holy = FALSE, _psychic = FALSE, _allowed_slots, _charges, _blocks_self = TRUE, datum/callback/_reaction, datum/callback/_expire)
|
||||
if(isitem(parent))
|
||||
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(on_equip))
|
||||
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(on_drop))
|
||||
else if(ismob(parent))
|
||||
RegisterSignal(parent, COMSIG_MOB_RECEIVE_MAGIC, PROC_REF(protect))
|
||||
register_antimagic_signals(parent)
|
||||
else
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
magic = _magic
|
||||
holy = _holy
|
||||
psychic = _psychic
|
||||
if(_allowed_slots)
|
||||
allowed_slots = _allowed_slots
|
||||
if(!isnull(_charges))
|
||||
charges = _charges
|
||||
blocks_self = _blocks_self
|
||||
reaction = _reaction
|
||||
expire = _expire
|
||||
src.antimagic_flags = antimagic_flags
|
||||
src.charges = charges
|
||||
src.inventory_flags = inventory_flags
|
||||
src.drain_antimagic = drain_antimagic
|
||||
src.expiration = expiration
|
||||
|
||||
/datum/component/anti_magic/proc/on_equip(datum/source, mob/equipper, slot)
|
||||
if(!CHECK_BITFIELD(allowed_slots, slot)) //Check that the slot is valid for antimagic
|
||||
UnregisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC)
|
||||
/datum/component/anti_magic/Destroy(force, silent)
|
||||
drain_antimagic = null
|
||||
expiration = null
|
||||
return ..()
|
||||
|
||||
/datum/component/anti_magic/proc/register_antimagic_signals(datum/on_what)
|
||||
RegisterSignal(on_what, COMSIG_MOB_RECEIVE_MAGIC, PROC_REF(block_receiving_magic), override = TRUE)
|
||||
RegisterSignal(on_what, COMSIG_MOB_RESTRICT_MAGIC, PROC_REF(restrict_casting_magic), override = TRUE)
|
||||
|
||||
/datum/component/anti_magic/proc/unregister_antimagic_signals(datum/on_what)
|
||||
UnregisterSignal(on_what, list(COMSIG_MOB_RECEIVE_MAGIC, COMSIG_MOB_RESTRICT_MAGIC))
|
||||
|
||||
/datum/component/anti_magic/proc/on_equip(atom/movable/source, mob/equipper, slot)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(!(inventory_flags & slot)) //Check that the slot is valid for antimagic
|
||||
unregister_antimagic_signals(equipper)
|
||||
return
|
||||
RegisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC, PROC_REF(protect), TRUE)
|
||||
|
||||
/datum/component/anti_magic/proc/on_drop(datum/source, mob/user)
|
||||
UnregisterSignal(user, COMSIG_MOB_RECEIVE_MAGIC)
|
||||
register_antimagic_signals(equipper)
|
||||
if(!alert_caster_on_equip)
|
||||
return
|
||||
|
||||
/datum/component/anti_magic/proc/protect(datum/source, mob/user, _magic, _holy, _psychic, chargecost, self, list/protection_sources)
|
||||
if(((_magic && magic) || (_holy && holy) || (_psychic && psychic)) && (!self || blocks_self))
|
||||
protection_sources += parent
|
||||
reaction?.Invoke(user, chargecost)
|
||||
charges -= chargecost
|
||||
// Check to see if we have any spells that are blocked due to antimagic
|
||||
for(var/datum/action/cooldown/spell/magic_spell in equipper.actions)
|
||||
if(!(magic_spell.spell_requirements & SPELL_REQUIRES_NO_ANTIMAGIC))
|
||||
continue
|
||||
|
||||
if(!(antimagic_flags & magic_spell.antimagic_flags))
|
||||
continue
|
||||
|
||||
to_chat(equipper, span_warning("[parent] is interfering with your ability to cast magic!"))
|
||||
alert_caster_on_equip = FALSE
|
||||
break
|
||||
|
||||
/datum/component/anti_magic/proc/on_drop(atom/movable/source, mob/user)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
// Reset alert
|
||||
if(source.loc != user)
|
||||
alert_caster_on_equip = TRUE
|
||||
unregister_antimagic_signals(user)
|
||||
|
||||
/datum/component/anti_magic/proc/block_receiving_magic(mob/living/carbon/source, casted_magic_flags, charge_cost, list/antimagic_sources)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
// We do not block this type of magic, good day
|
||||
if(!(casted_magic_flags & antimagic_flags))
|
||||
return NONE
|
||||
|
||||
// We have already blocked this spell
|
||||
if(parent in antimagic_sources)
|
||||
return NONE
|
||||
|
||||
// Block success! Add this parent to the list of antimagic sources
|
||||
antimagic_sources += parent
|
||||
|
||||
if((charges != INFINITY) && charge_cost > 0)
|
||||
drain_antimagic?.Invoke(source, parent)
|
||||
charges -= charge_cost
|
||||
if(charges <= 0)
|
||||
expire?.Invoke(user)
|
||||
qdel(src)
|
||||
expiration?.Invoke(source, parent)
|
||||
qdel(src) // no more antimagic
|
||||
|
||||
return COMPONENT_MAGIC_BLOCKED
|
||||
|
||||
/// cannot cast magic with the same type of antimagic present
|
||||
/datum/component/anti_magic/proc/restrict_casting_magic(mob/user, magic_flags)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(magic_flags & antimagic_flags)
|
||||
return COMPONENT_MAGIC_BLOCKED
|
||||
|
||||
return NONE
|
||||
|
||||
@@ -378,7 +378,7 @@
|
||||
|
||||
/datum/status_effect/belligerent/proc/do_movement_toggle(force_damage)
|
||||
var/number_legs = owner.get_num_legs(FALSE)
|
||||
if(iscarbon(owner) && !is_servant_of_ratvar(owner) && !owner.anti_magic_check(chargecost = 0) && number_legs)
|
||||
if(iscarbon(owner) && !is_servant_of_ratvar(owner) && !owner.can_block_magic(charge_cost = 0) && number_legs)
|
||||
if(force_damage || owner.m_intent != MOVE_INTENT_WALK)
|
||||
if(GLOB.ratvar_awakens)
|
||||
owner.Paralyze(20)
|
||||
@@ -467,7 +467,7 @@
|
||||
owner.remove_status_effect(/datum/status_effect/drowsiness)
|
||||
owner.remove_status_effect(/datum/status_effect/confusion)
|
||||
severity = 0
|
||||
else if(!owner.anti_magic_check(chargecost = 0) && owner.stat != DEAD && severity)
|
||||
else if(!owner.can_block_magic(charge_cost = 0) && owner.stat != DEAD && severity)
|
||||
var/static/hum = get_sfx('sound/effects/screech.ogg') //same sound for every proc call
|
||||
if(owner.getToxLoss() > MANIA_DAMAGE_TO_CONVERT)
|
||||
if(is_eligible_servant(owner))
|
||||
|
||||
Reference in New Issue
Block a user