mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-20 03:30:01 +01:00
* destroy proc holder pt1 - change proc_holder/spell to action/cooldown/spell - docs all the spell vars, renames some of them - removes some useless vars - start with pointed spells, as they're easy * kill proc_holder pt2 - kill a buncha vars and replace it with flags - convert a ton over - general code improvements * kill proc_holders pt3 - convert a good few more spells - rename some signals - handle statpanel - better docs * kiill proc_holder pt4: - restructure the file system of action.dm, separating a good amount of item actions and miscellaneous garbage into files where they belong slightly better. Also splits off item actions, cooldown actions, innate actions, etc. into their own files, overlal making it much better to work with - converts touch attacks to actions - converts blood crawl, jaunt subtype * kills proc_holder pt5 - clears up some icon issues so all the currently converted pages don't have errors - shapeshift - some more action cleanup * kills proc_holder pt5.5: - some documentation - reworks feedback to prevent oversight with teleports and stuff * kills proc_holder pt6: - converted cult spells - converted magic missile - converted mime spells - chipped away at the errors - removed some vars which were too general, replaced them with more locally applicable vars. for example "range" which could mean "projectile range" or "aoe radius" or whatever - instead of having a broad net which everyone applies to in a confusing matter, instead lets each spell delegate on their own. - merged magic/spell and magic/aoe, as the comment intended - more unified behavior for spell levelling * kill proc_holders pt 6.5: - replacing a buncha old proc_holders that have been updated to reduce some errors. sub 900 baby * kills proc_holder pt 6.75: - minor fixes * kills proc_holder pt7: - cuts down on some errors - refactors some wiz events * kills proc_holder pt 7.5: - malf ranged modules - some minor errors * kills proc_holder pt 7.75: - mor eminor error handling, cleaning up changes * kill proc_holder pt8: - refactors spell book - refactors spell implant - some more minor error fixing * kill proc_holder pt 8.5: - scan ability * Adds some robust documentation * kill proc_holder pt9: - converts some / most mutations over * kill proc_holder pt10: - sort out all the granters - refactor them slightly - fix some compile errors * Some set-unset sanity - going to need to test removing Share() * Removes transfer actions. It doesn't seem to do anything. - Transfer_actions was called when current = new_character so locially speaking the early return in Grant() should cause it to NOOP. Test this in the future though * Removes sharing from actions, docs actions better * Some better documentation for spell and spell components * Kills proc_holder pt11: - Finally finishes ALL THE SPELLS IN THE SPELL FOLDER - Fixes some more errors * kills proc_holder pt11.5: - minor error fixing and sanity * Method of sharing actions. Can be improved in the future, needs testing * Implements a way to update the stat panel entry for a spell. Also gets rid of VV stuff, as you can update the bigflags directly in VV now. * Curse of madness bug I put in. * kills proc_holder pt12: - sub 500 errors! - converts cytology mobs - converts and refactors spiders slightly - some minor fixing around the place as usual * kill proc_holder pt13 - Finishes heretic spells - Sub 300 errors! - some touch refactoring to account for mansus grasp * kills proc_holder pt14: - revenant - minor bugfixing for heretic stuff * kills proc_holder pt14.5: - some missed stuff for revenant + heretic * kills proc_holder pt15: - alien abilities - more minor fixing - sub 100 errors. The end is nigh * kill proc_holder pt16? 17: - Finishes cult spells - sub 50 errors! - refactors the way charge works - renames / moves some signals * kills proc_holder pt final: - sdql spells - no more errors! * Bugfixes round 1 * Various bugfixing - documentation done - give spell works - can cast spell gives feedback conditionally - is available takes into account casting ability * Some accidental reversions + fixes * Unit tests * Completely refactors jaunting - All bloodcrawling is now handled on the action itself instead of across various living procs - slaughter demons have their own blood crawls - jaunting dummies don't have side effects on destroy() anymore * Wizard spell logging and even more refactoring
163 lines
7.2 KiB
Plaintext
163 lines
7.2 KiB
Plaintext
/// This provides different types of magic resistance on an object
|
|
/datum/component/anti_magic
|
|
/// 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
|
|
var/charges
|
|
/// The inventory slot the object must be located at in order to activate
|
|
var/inventory_flags
|
|
/// The proc that is triggered when an object has been drained a antimagic charge
|
|
var/datum/callback/drain_antimagic
|
|
/// The proc that is triggered when the object is depleted of charges
|
|
var/datum/callback/expiration
|
|
/// If we have already sent a notification message to the mob picking up an antimagic item
|
|
var/casting_restriction_alert = FALSE
|
|
|
|
/**
|
|
* 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
|
|
)
|
|
|
|
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/block_receiving_magic, override = TRUE)
|
|
RegisterSignal(parent, COMSIG_MOB_RESTRICT_MAGIC, .proc/restrict_casting_magic, override = TRUE)
|
|
to_chat(parent, span_warning("Magic seems to flee from you. You are immune to spells but are unable to cast magic."))
|
|
else
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
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/Destroy(force, silent)
|
|
QDEL_NULL(drain_antimagic)
|
|
QDEL_NULL(expiration)
|
|
return ..()
|
|
|
|
/datum/component/anti_magic/proc/on_equip(datum/source, mob/equipper, slot)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!(inventory_flags & slot)) //Check that the slot is valid for antimagic
|
|
UnregisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC)
|
|
UnregisterSignal(equipper, COMSIG_MOB_RESTRICT_MAGIC)
|
|
equipper.update_action_buttons()
|
|
return
|
|
RegisterSignal(equipper, COMSIG_MOB_RECEIVE_MAGIC, .proc/block_receiving_magic, override = TRUE)
|
|
RegisterSignal(equipper, COMSIG_MOB_RESTRICT_MAGIC, .proc/restrict_casting_magic, override = TRUE)
|
|
equipper.update_action_buttons()
|
|
|
|
if(!casting_restriction_alert)
|
|
// 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)
|
|
to_chat(equipper, span_warning("[parent] is interfering with your ability to cast magic!"))
|
|
casting_restriction_alert = TRUE
|
|
break
|
|
|
|
/datum/component/anti_magic/proc/on_drop(datum/source, mob/user)
|
|
SIGNAL_HANDLER
|
|
|
|
UnregisterSignal(user, COMSIG_MOB_RECEIVE_MAGIC)
|
|
UnregisterSignal(user, COMSIG_MOB_RESTRICT_MAGIC)
|
|
user.update_action_buttons()
|
|
casting_restriction_alert = FALSE
|
|
|
|
/datum/component/anti_magic/proc/block_receiving_magic(mob/living/carbon/user, casted_magic_flags, charge_cost, list/protection_was_used)
|
|
SIGNAL_HANDLER
|
|
|
|
// if any protection sources exist in our list then we already blocked the magic
|
|
if(!istype(user) || protection_was_used.len)
|
|
return
|
|
|
|
// disclaimer - All anti_magic sources will be drained a charge_cost
|
|
if(casted_magic_flags & antimagic_flags)
|
|
var/mutable_appearance/antimagic_effect
|
|
var/antimagic_color
|
|
// im a programmer not shakesphere to the future grammar nazis that come after me for this
|
|
var/visible_subject = ismob(parent) ? "[user.p_they()]" : "[parent]"
|
|
var/self_subject = ismob(parent) ? "you" : "[parent]"
|
|
|
|
if(casted_magic_flags & antimagic_flags & MAGIC_RESISTANCE)
|
|
user.visible_message(
|
|
span_warning("[user] pulses red as [visible_subject] absorbs magic energy!"),
|
|
span_userdanger("An intense magical aura pulses around [self_subject] as it dissipates into the air!"),
|
|
)
|
|
antimagic_effect = mutable_appearance('icons/effects/effects.dmi', "shield-red", MOB_SHIELD_LAYER)
|
|
antimagic_color = LIGHT_COLOR_BLOOD_MAGIC
|
|
playsound(user, 'sound/magic/magic_block.ogg', 50, TRUE)
|
|
else if(casted_magic_flags & antimagic_flags & MAGIC_RESISTANCE_HOLY)
|
|
user.visible_message(
|
|
span_warning("[user] starts to glow as [visible_subject] emits a halo of light!"),
|
|
span_userdanger("A feeling of warmth washes over [self_subject] as rays of light surround your body and protect you!"),
|
|
)
|
|
antimagic_effect = mutable_appearance('icons/effects/genetics.dmi', "servitude", -MUTATIONS_LAYER)
|
|
antimagic_color = LIGHT_COLOR_HOLY_MAGIC
|
|
playsound(user, 'sound/magic/magic_block_holy.ogg', 50, TRUE)
|
|
else if(casted_magic_flags & antimagic_flags & MAGIC_RESISTANCE_MIND)
|
|
user.visible_message(
|
|
span_warning("[user] forehead shines as [visible_subject] repulses magic from their mind!"),
|
|
span_userdanger("A feeling of cold splashes on [self_subject] as your forehead reflects magic usering your mind!"),
|
|
)
|
|
antimagic_effect = mutable_appearance('icons/effects/genetics.dmi', "telekinesishead", MOB_SHIELD_LAYER)
|
|
antimagic_color = LIGHT_COLOR_DARK_BLUE
|
|
playsound(user, 'sound/magic/magic_block_mind.ogg', 50, TRUE)
|
|
|
|
user.mob_light(_range = 2, _color = antimagic_color, _duration = 5 SECONDS)
|
|
user.add_overlay(antimagic_effect)
|
|
addtimer(CALLBACK(user, /atom/proc/cut_overlay, antimagic_effect), 50)
|
|
|
|
if(ismob(parent))
|
|
return COMPONENT_MAGIC_BLOCKED
|
|
|
|
var/has_limited_charges = !(charges == INFINITY)
|
|
var/charge_was_drained = charge_cost > 0
|
|
if(has_limited_charges && charge_was_drained)
|
|
protection_was_used += parent
|
|
drain_antimagic?.Invoke(user, parent)
|
|
charges -= charge_cost
|
|
if(charges <= 0)
|
|
expiration?.Invoke(user, parent)
|
|
qdel(src)
|
|
return COMPONENT_MAGIC_BLOCKED
|
|
return NONE
|
|
|
|
/// 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)
|
|
if(HAS_TRAIT(user, TRAIT_ANTIMAGIC_NO_SELFBLOCK)) // this trait bypasses magic casting restrictions
|
|
return NONE
|
|
return COMPONENT_MAGIC_BLOCKED
|
|
|
|
return NONE
|