Files
Bubberstation/code/datums/components/splattercasting.dm
san7890 ccef887efe Lints Against Unmanaged Local Defines (#74333)
# MAINTAINER - USE THE BUTTON THAT SAYS "MERGE MASTER" THEN SET THE PR
TO AUTO-MERGE! IT'S MUCH EASIER FOR ME TO FIX THINGS BEFORE THEY SKEW
RATHER THAN AFTER THE FACT.

## About The Pull Request

Hey there,

This took a while to do, but here's the gist:

Python file now regexes every file in `/code` except for those that have
some valid reason to be tacking on more global defines. Some of those
reasons are simply just that I don't have the time right now (doing what
you see in this PR took a few hours) to refactor and parse what should
belong and what should be thrown out. For the time being though, this PR
will at least _halt_ people making the mistake of not `#undef`ing any
files they `#define` "locally", or within the scope of a file.

Most people forget to do this and this leads to a lot of mess later on
due to how many variables can be unmanaged on the global level. I've
made this mistake, you've made this mistake, it's a common thing. Let's
automatically check for it so it can be fixed no-stress.

Scenarios this PR corrects:

* Forgetting to undef a define but undeffing others.
* Not undeffing any defines in your file.
* Earmarking a define as a "file local" define, but not defining it.
* Having a define be a "file local" define, but having it be used
elsewhere.
* Having a "local" define not even be in the file that it only shows up
in.
* Having a completely unused define*

(* I kept some of these because they seemed important... Others were
junked.)
## Why It's Good For The Game

If you wanna use it across multiple files, no reason to not make it a
global define (maybe there's a few reasons but let's assume that this is
the 95% case).

Let me know if you don't like how I re-arranged some of the defines and
how you'd rather see it be implemented, and I'd be happy to do that.
This was mostly just "eh does it need it or not" sorta stuff.

I used a pretty cool way to detect if we should use the standardized
GitHub "error" output, you can see the results of that here
https://github.com/san7890/bruhstation/actions/runs/4549766579/jobs/8022186846#step:7:792
## Changelog
Nothing that really concerns players.

(I fixed up all this stuff using vscode, no regexes beyond what you see
in the python script. sorry downstreams)
2023-03-29 10:17:03 -07:00

100 lines
4.0 KiB
Plaintext

///how much we multiply cooldown (deciseconds) by to get the amount of blood to remove.
///BLOOD_VOLUME_NORMAL is 560, expensive spells max out at around 60 seconds which is 600 deciseconds
///removing 9/10ths of the cooldown from that puts us at 540 deciseconds, mult by 0.5 gives 270 blood taken
///one second is worth 5 blood, roughly half of your normal amount of blood taken for a huge spell, seems fair
#define COOLDOWN_TO_BLOOD_RATIO 0.5
/**
* # splattercasting component!
*
* Component that makes casted spells cost blood from the user and dramatically lowers their cooldown.
*/
/datum/component/splattercasting
/datum/component/splattercasting/Initialize()
if(!iscarbon(parent))
return COMPONENT_INCOMPATIBLE
/datum/component/splattercasting/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_SPECIES_LOSS, PROC_REF(on_species_change))
RegisterSignal(parent, COMSIG_MOB_SPELL_PROJECTILE, PROC_REF(on_spell_projectile))
RegisterSignal(parent, COMSIG_MOB_BEFORE_SPELL_CAST, PROC_REF(on_before_spell_cast))
RegisterSignal(parent, COMSIG_MOB_AFTER_SPELL_CAST, PROC_REF(on_after_spell_cast))
/datum/component/splattercasting/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, list(COMSIG_SPECIES_LOSS, COMSIG_MOB_SPELL_PROJECTILE, COMSIG_MOB_BEFORE_SPELL_CAST, COMSIG_MOB_AFTER_SPELL_CAST))
///signal sent when a spell casts a projectile
/datum/component/splattercasting/proc/on_species_change(mob/living/carbon/source, datum/species/lost_species)
SIGNAL_HANDLER
qdel(src)
///signal sent when the parent casts a spell that has a projectile
/datum/component/splattercasting/proc/on_spell_projectile(mob/living/carbon/source, datum/action/cooldown/spell/spell, atom/cast_on, obj/projectile/to_fire)
SIGNAL_HANDLER
if(spell.school == SCHOOL_SANGUINE)
//already has blood themed projectiles
return
playsound(source, 'sound/effects/wounds/splatter.ogg', 60, TRUE, -1)
to_fire.color = "#ff7070"
to_fire.name = "blood-[to_fire.name]"
to_fire.set_light(2, 2, LIGHT_COLOR_BLOOD_MAGIC, TRUE)
///signal sent before parent casts a spell
/datum/component/splattercasting/proc/on_before_spell_cast(mob/living/carbon/source, datum/action/cooldown/spell/spell, atom/cast_on)
SIGNAL_HANDLER
var/changed_spell = FALSE
if(!(spell.spell_requirements & SPELL_REQUIRES_NO_ANTIMAGIC))
spell.spell_requirements |= SPELL_REQUIRES_NO_ANTIMAGIC
changed_spell = TRUE
if(!(spell.antimagic_flags & MAGIC_RESISTANCE_HOLY))
spell.antimagic_flags |= MAGIC_RESISTANCE_HOLY
changed_spell = TRUE
if(changed_spell)
//we changed some kind of antimagic so we should check if the new version of the spell is still valid.
//since can_cast_spell has already been checked before "before spell cast" only antimagic check should fail
if(!spell.can_cast_spell(feedback = TRUE))
return SPELL_CANCEL_CAST
///signal sent after parent casts a spell
/datum/component/splattercasting/proc/on_after_spell_cast(mob/living/carbon/source, datum/action/cooldown/spell/spell, atom/cast_on)
SIGNAL_HANDLER
if(spell.school == SCHOOL_SANGUINE)
//allows for sanguine spells that work specially with blood to not interact with splattercasting.
//might sound weird, but maybe in the future we'll have a spell that adds blood to the user when it hits a target
//we wouldn't want that to cost blood.
return
//normal cooldown spell has
var/cooldown_remaining = spell.next_use_time - world.time
//how much we discount, we make the spell cost 1/10th of its actual cooldown
var/new_cooldown = cooldown_remaining / 10
//convert how much cooldown that spell saved into blood cost
var/blood_cost = (cooldown_remaining - new_cooldown ) * COOLDOWN_TO_BLOOD_RATIO
spell.StartCooldown(new_cooldown)
source.blood_volume -= blood_cost
var/cost_desc
switch(blood_cost)
if(1 to 50)
cost_desc = "trickle"
if(51 to 100)
cost_desc = "stream"
if(101 to 200)
cost_desc = "river"
if(201 to INFINITY)
cost_desc = "torrent"
to_chat(source, span_danger("You feel a [cost_desc] of your blood drained into the spell you just cast."))
#undef COOLDOWN_TO_BLOOD_RATIO