Files
Aurora.3/code/modules/spells/spell_code.dm
Lohikar f6dc33a465 Newmap - SMC, Openturf, Arrivals Controller, and Mine Turf Improvements (#1958)
* Replace SSingulo with SScalamity; processing cleanup
- SScalamity now handles blobs as well as singularity-types.
- Processing subtypes have been simplified to not require a stop_processing definition.

* this is probably important

* Remove cascade disabling SSgarbage

* Fixed a bug where dust() did not qdel the target mob

* Misc fixes

* Fix decals surviving break-to-plating

* Subsystem flag tweaks

* Apparently subsystems are new'd before config is.

* Fix paper icons

* Speculative fix for insane lag

* Better machinery stat

* Make organs not use SSoverlay

* Misc bugfixes & tweaks

* Nightmode fixes

* Changelog for SMC

* Port /tg/'s improved MC crash handling

* Add some more SS Recover() procs

* supply_controller -> SScargo

* More New() -> Initialize()

* pAI and robot construction overlays

* Fix cargo unit tests

* Merge the DMM Suite's atom/New() into atoms_init

* Lighting pre-baking

* Lighting initialization logging

* Fix some bad SS init orders

* Fix SSlighting logging; rename Processes to MC

* Speculative fix for insane GC lag

* Prebaked openturf/icon_smooth & fix lighting prebake

* SS init status; SSatoms LATEQDEL

* Fix bug with MC init stat panel

* Fix parallax

* Misc

* Ignore SS_NO_DISPLAY during init

* apparently this is important

* REEEEEE

* Image GC fixes; broadcaster radio-new sanity

* RCON Cleanup

* Move pAI recruiter into subsystem

* Move global solars list into sun subsystem

* Make chickens not use a global

* Demote SSdisposals to SS_BACKGROUND; garbage-debug cleanup

* Speed up space init a little

* Fix bad timer flags on floor drying

* Subsystem panic-restart verb for mins

* Explosion speedup

* Minor subsystem & MC logging tweaks

* SSopenturf improvements

* Make pipenet actually initialize (whoops)

* Minor tweaks

* Implement lighting rounding

* comments are hard okay

* Minor lattice tweaks

* Fix some timer issues & better closet init

* Timer sanity

* Request console tweaks + Storage init sanity

* Minor SSmachiner RCON improvements

* Further reduce world-start timer count

* Standardize subsystem logging

* Garbage hard delete profiling from /tg/

* Timer hang detection & recovery

* Log machines that sleep in process() and fuck up SSmachinery

* Fix an issue with external airlocks sleeping in process()

* Failsafe logging

* Minor tweaks

* Revert "Request console tweaks + Storage init sanity"

This reverts commit 98d3579e35.

* Re-implement RC changes

* Fix SQL FT saving

* Fix SSmachinery sleep in disposals

* Minor SS tweaks

* Paper fixes

* Blood drying fixes

* Merge gameticker and SSticker

* Minor global list init cleanup

* Lagcheck biogenerator & bags

* Tweak SScargo init order; RIG Initialize()

* Caching tweaks

* Remove rogue comma

* Initialize fixes

* Lighting destroy cleanup

* Fix emagging airlocks

* Initial SSicon implementation

* Tweaks & Fixes

* Fire + Air alarm queued icon updates

* Overlays + Queued icon cleanup

* Runtime & background fixes

* Kill some meaningless set statements

* Kill some image qdels

* Bump up lighting rounding val

* Fix adv. scanner destroy runtimes

* Remove unneeded icon update limiting

* Move icon smoothing into helpers

* Show a warning if DM 510 compiles without memory leak hack enabled

* Re-organize subsystems & MC defines a little

* Airlock SFX

* Log of Changes

* Make SSicon_update disable itself when not doing anything

* Fix respawn verb runtime when used early in server-init

* Add more information to MC's stat_entry()

* Replace direct refernces to gcDestroyed with QDEL* macros

* plant_controller -> SSplants

* More plant tweaks

* Add more humor to changelog

* Move parallax globals into SSparallax

* Lighting responsiveness tweaks

* Fix parallax init order & better MC init panel stat

* Make mobs GC

* More overlays + Remove intercom spawn()

* SSfast_process; make pinpointers not use spawn-recursion to process
Also made the SM Cascade beach process with SSprocessing instead of a spawn loop.

* Update changelog

* Mob GC tweaks

* Del() cleanup

* Fix insomniac ZAS connection edges

* Minor pAI cleanup

* Convert more things to SSoverlay; fix duplicated overlay in field gens

* SM Bluespace turf tweaks

* Update SSgarbage debug globals list

* Human-type qdel tweaks

* Subsystem suspension; stat_entry improvements

* SQL Statistics cleanup

* Fix runtimes with ambrosia

* More disable() -> suspend(); fix nightmode again

* Human qdel fix; minor tweaks

* Update turbolift to work with StonedMC

* Make lifts use timers instead of a subsystem

* Make SSassets start earlier

* Convert the radio controller into a subsystem

* Fix some missing CHECK_TICKs in asteroid generation

* MC stat tweaks; make shouldnt_see a typecache

* Kill some redundant debug-controller entries

* radio_controller -> SSradio

* Better SSgarbage hard-del logging from /tg/ upstream

* Logging tweaks + GELF

* Misc client caching improvements

* Slime SSoverlay

* Oven icon fixes

* Implant fixes
- Death implants will no longer spam Common on death of user.
- Death implants should handle a deleted user better.

* Holder tweaks + Welding tool Initialize()

* Fix some bad subsystem logging

* Fix suit cooling units spawning without cells

* Starlight tweaks

* Gibber infinite gib fix

* More SSoverlay stuff

* Make crates use CUT_OVERLAY_IN

* Make SSarrivals suspend instead of disable

* Make openturf use split/phased tick checks

* Speculative fix for unwet timer runtimes

* Blood overlay tweaks/fixes

* Update crusher to play nice with SMC + SSoverlay

* Openturf improvements and fixes

* Minor turbolift tweaks

* Lighting performance improvements + ChangeTurf tweaks

* this is probably important

* Fix wall weld noises on changeturf

* More ChangeTurf tweaks

* Explosion tweaks

* Pre-game lobby tweaks

* Openturf tweaks

* Prevent admins from starting the game before init finishes

* Fix Travis

* Kill an unused var

* Fix ChangeTurf runtimes on openturfs

* Fixes

* Browser datum fixes, asset caching

* Update changelog

* Changelog

* Lobby tweaks

* Ticker tweaks; kill ticker var

* Further lobby tweaks

* Cascade tweaks

* air_master -> SSair

* Reduce overhead from radio autosay

* alarm_manager -> SSalarm

* bomb_processor -> SSexplosives

* corp_regs -> SSlaw

* ZAS overlay fixes

* Small wall icon optimization

* Fix effects master

* Assembly tweaks

* Megavend fixes

* Shuttle fixes

* Camera alert performance improvements

* Fix some world.log spam from lighting overlays

* Fix some Initialize() procs

* Openspace responsiveness tweaks

* Make HE pipes animate through openturfs

* Kill a spawn
2017-05-02 14:40:40 -04:00

362 lines
12 KiB
Plaintext

var/list/spells = typesof(/spell) //needed for the badmin verb for now
/spell
var/name = "Spell"
var/desc = "A spell"
var/feedback = "" //what gets sent if this spell gets chosen by the spellbook.
parent_type = /datum
var/panel = "Spells"//What panel the proc holder needs to go on.
var/school = "evocation" //not relevant at now, but may be important later if there are changes to how spells work. the ones I used for now will probably be changed... maybe spell presets? lacking flexibility but with some other benefit?
var/charge_type = Sp_RECHARGE //can be recharge or charges, see charge_max and charge_counter descriptions; can also be based on the holder's vars now, use "holder_var" for that
var/charge_max = 100 //recharge time in deciseconds if charge_type = Sp_RECHARGE or starting charges if charge_type = Sp_CHARGES
var/charge_counter = 0 //can only cast spells if it equals recharge, ++ each decisecond if charge_type = Sp_RECHARGE or -- each cast if charge_type = Sp_CHARGES
var/still_recharging_msg = "<span class='notice'>The spell is still recharging.</span>"
var/silenced = 0 //not a binary - the length of time we can't cast this for
var/processing = 0 //are we processing already? Mainly used so that silencing a spell doesn't call process() again. (and inadvertedly making it run twice as fast)
var/holder_var_type = "bruteloss" //only used if charge_type equals to "holder_var"
var/holder_var_amount = 20 //same. The amount adjusted with the mob's var when the spell is used
var/spell_flags = NEEDSCLOTHES
var/invocation = "HURP DURP" //what is uttered when the wizard casts the spell
var/invocation_type = SpI_NONE //can be none, whisper, shout, and emote
var/range = 7 //the range of the spell; outer radius for aoe spells
var/message = "" //whatever it says to the guy affected by it
var/selection_type = "view" //can be "range" or "view"
var/atom/movable/holder //where the spell is. Normally the user, can be an item
var/duration = 0 //how long the spell lasts
var/list/spell_levels = list(Sp_SPEED = 0, Sp_POWER = 0) //the current spell levels - total spell levels can be obtained by just adding the two values
var/list/level_max = list(Sp_TOTAL = 4, Sp_SPEED = 4, Sp_POWER = 0) //maximum possible levels in each category. Total does cover both.
var/cooldown_reduc = 0 //If set, defines how much charge_max drops by every speed upgrade
var/delay_reduc = 0
var/cooldown_min = 0 //minimum possible cooldown for a charging spell
var/overlay = 0
var/overlay_icon = 'icons/obj/wizard.dmi'
var/overlay_icon_state = "spell"
var/overlay_lifespan = 0
var/sparks_spread = 0
var/sparks_amt = 0 //cropped at 10
var/smoke_spread = 0 //1 - harmless, 2 - harmful
var/smoke_amt = 0 //cropped at 10
var/critfailchance = 0
var/cast_delay = 1
var/cast_sound = ""
var/hud_state = "" //name of the icon used in generating the spell hud object
var/override_base = ""
var/obj/screen/connected_button
///////////////////////
///SETUP AND PROCESS///
///////////////////////
/spell/New()
..()
//still_recharging_msg = "<span class='notice'>[name] is still recharging.</span>"
charge_counter = charge_max
/spell/process()
if(processing)
return
processing = 1
spawn(0)
while(charge_counter < charge_max || silenced > 0)
charge_counter = min(charge_max,charge_counter+1)
silenced = max(0,silenced-1)
sleep(1)
if(connected_button)
var/obj/screen/spell/S = connected_button
if(!istype(S))
return
S.update_charge(1)
processing = 0
return
/////////////////
/////CASTING/////
/////////////////
/spell/proc/choose_targets(mob/user = usr) //depends on subtype - see targeted.dm, aoe_turf.dm, dumbfire.dm, or code in general folder
return
/spell/proc/perform(mob/user = usr, skipcharge = 0) //if recharge is started is important for the trigger spells
if(!holder)
holder = user //just in case
if(!cast_check(skipcharge, user))
return
if(cast_delay && !spell_do_after(user, cast_delay))
return
var/list/targets = choose_targets(user)
if(targets && targets.len && cast_check(1,user))
invocation(user, targets)
take_charge(user, skipcharge)
before_cast(targets) //applies any overlays and effects
user.attack_log += text("\[[time_stamp()]\] <font color='red'>[user.real_name] ([user.ckey]) cast the spell [name].</font>")
if(prob(critfailchance))
critfail(targets, user)
else
playsound(get_turf(user), cast_sound, 50, 1)
cast(targets, user)
after_cast(targets) //generates the sparks, smoke, target messages etc.
/spell/proc/cast(list/targets, mob/user) //the actual meat of the spell
return
/spell/proc/critfail(list/targets, mob/user) //the wizman has fucked up somehow
return
/spell/proc/adjust_var(mob/living/target = usr, type, amount) //handles the adjustment of the var when the spell is used. has some hardcoded types
switch(type)
if("bruteloss")
target.adjustBruteLoss(amount)
if("fireloss")
target.adjustFireLoss(amount)
if("toxloss")
target.adjustToxLoss(amount)
if("oxyloss")
target.adjustOxyLoss(amount)
if("brainloss")
target.adjustBrainLoss(amount)
if("stunned")
target.AdjustStunned(amount)
if("weakened")
target.AdjustWeakened(amount)
if("paralysis")
target.AdjustParalysis(amount)
else
target.vars[type] += amount //I bear no responsibility for the runtimes that'll happen if you try to adjust non-numeric or even non-existant vars
return
///////////////////////////
/////CASTING WRAPPERS//////
///////////////////////////
/spell/proc/before_cast(list/targets)
var/valid_targets[0]
for(var/atom/target in targets)
// Check range again (fixes long-range EI NATH)
if(!(target in view_or_range(range,usr,selection_type)))
continue
valid_targets += target
if(overlay)
var/location
if(istype(target,/mob/living))
location = target.loc
else if(istype(target,/turf))
location = target
var/obj/effect/overlay/spell = new /obj/effect/overlay(location)
spell.icon = overlay_icon
spell.icon_state = overlay_icon_state
spell.anchored = 1
spell.density = 0
spawn(overlay_lifespan)
qdel(spell)
return valid_targets
/spell/proc/after_cast(list/targets)
for(var/atom/target in targets)
var/location = get_turf(target)
if(istype(target,/mob/living) && message)
target << text("[message]")
if(sparks_spread)
spark(location, sparks_amt)
if(smoke_spread)
if(smoke_spread == 1)
var/datum/effect/effect/system/smoke_spread/smoke = new /datum/effect/effect/system/smoke_spread()
smoke.set_up(smoke_amt, 0, location) //no idea what the 0 is
smoke.start()
else if(smoke_spread == 2)
var/datum/effect/effect/system/smoke_spread/bad/smoke = new /datum/effect/effect/system/smoke_spread/bad()
smoke.set_up(smoke_amt, 0, location) //no idea what the 0 is
smoke.start()
/////////////////////
////CASTING TOOLS////
/////////////////////
/*Checkers, cost takers, message makers, etc*/
/spell/proc/cast_check(skipcharge = 0,mob/user = usr) //checks if the spell can be cast based on its settings; skipcharge is used when an additional cast_check is called inside the spell
if(!(src in user.spell_list) && holder == user)
error("[user] utilized the spell '[src]' without having it.")
user << "<span class='warning'>You shouldn't have this spell! Something's wrong.</span>"
return 0
if(silenced > 0)
return
var/turf/user_turf = get_turf(user)
if(!user_turf)
user << "<span class='warning'>You cannot cast spells in null space!</span>"
if(spell_flags & Z2NOCAST && (user_turf.z in config.admin_levels)) //Certain spells are not allowed on the centcomm zlevel
return 0
if(spell_flags & CONSTRUCT_CHECK)
for(var/turf/T in range(holder, 1))
if(findNullRod(T))
return 0
if(istype(user, /mob/living/simple_animal) && holder == user)
var/mob/living/simple_animal/SA = user
if(SA.purge)
SA << "<span class='warning'>The nullrod's power interferes with your own!</span>"
return 0
if(!src.check_charge(skipcharge, user)) //sees if we can cast based on charges alone
return 0
if(!(spell_flags & GHOSTCAST) && holder == user)
if(user.stat && !(spell_flags & STATALLOWED))
usr << "Not when you're incapacitated."
return 0
if(ishuman(user) && !(invocation_type in list(SpI_EMOTE, SpI_NONE)))
if(istype(user.wear_mask, /obj/item/clothing/mask/muzzle))
user << "Mmmf mrrfff!"
return 0
var/spell/noclothes/spell = locate() in user.spell_list
if((spell_flags & NEEDSCLOTHES) && !(spell && istype(spell)) && holder == user)//clothes check
if(!user.wearing_wiz_garb())
return 0
return 1
/spell/proc/check_charge(var/skipcharge, mob/user)
if(!skipcharge)
switch(charge_type)
if(Sp_RECHARGE)
if(charge_counter < charge_max)
user << still_recharging_msg
return 0
if(Sp_CHARGES)
if(!charge_counter)
user << "<span class='notice'>[name] has no charges left.</span>"
return 0
return 1
/spell/proc/take_charge(mob/user = user, var/skipcharge)
if(!skipcharge)
switch(charge_type)
if(Sp_RECHARGE)
charge_counter = 0 //doesn't start recharging until the targets selecting ends
src.process()
return 1
if(Sp_CHARGES)
charge_counter-- //returns the charge if the targets selecting fails
return 1
if(Sp_HOLDVAR)
adjust_var(user, holder_var_type, holder_var_amount)
return 1
return 0
return 1
/spell/proc/invocation(mob/user = usr, var/list/targets) //spelling the spell out and setting it on recharge/reducing charges amount
switch(invocation_type)
if(SpI_SHOUT)
if(prob(50))//Auto-mute? Fuck that noise
user.say(invocation)
else
user.say(replacetext(invocation," ","`"))
if(SpI_WHISPER)
if(prob(50))
user.whisper(invocation)
else
user.whisper(replacetext(invocation," ","`"))
if(SpI_EMOTE)
user.emote("me", 1, invocation) //the 1 means it's for everyone in view, the me makes it an emote, and the invocation is written accordingly.
/////////////////////
///UPGRADING PROCS///
/////////////////////
/spell/proc/can_improve(var/upgrade_type)
if(level_max[Sp_TOTAL] <= ( spell_levels[Sp_SPEED] + spell_levels[Sp_POWER] )) //too many levels, can't do it
return 0
//if(upgrade_type && spell_levels[upgrade_type] && level_max[upgrade_type])
if(upgrade_type && spell_levels[upgrade_type] >= level_max[upgrade_type])
return 0
return 1
/spell/proc/empower_spell()
if(!can_improve(Sp_POWER))
return 0
spell_levels[Sp_POWER]++
return 1
/spell/proc/quicken_spell()
if(!can_improve(Sp_SPEED))
return 0
spell_levels[Sp_SPEED]++
if(delay_reduc && cast_delay)
cast_delay = max(0, cast_delay - delay_reduc)
else if(cast_delay)
cast_delay = round( max(0, initial(cast_delay) * ((level_max[Sp_SPEED] - spell_levels[Sp_SPEED]) / level_max[Sp_SPEED] ) ) )
if(charge_type == Sp_RECHARGE)
if(cooldown_reduc)
charge_max = max(cooldown_min, charge_max - cooldown_reduc)
else
charge_max = round( max(cooldown_min, initial(charge_max) * ((level_max[Sp_SPEED] - spell_levels[Sp_SPEED]) / level_max[Sp_SPEED] ) ) ) //the fraction of the way you are to max speed levels is the fraction you lose
if(charge_max < charge_counter)
charge_counter = charge_max
var/temp = ""
name = initial(name)
switch(level_max[Sp_SPEED] - spell_levels[Sp_SPEED])
if(3)
temp = "You have improved [name] into Efficient [name]."
name = "Efficient [name]"
if(2)
temp = "You have improved [name] into Quickened [name]."
name = "Quickened [name]"
if(1)
temp = "You have improved [name] into Free [name]."
name = "Free [name]"
if(0)
temp = "You have improved [name] into Instant [name]."
name = "Instant [name]"
return temp
/spell/proc/spell_do_after(var/mob/user as mob, delay as num, var/numticks = 5)
if(!user || isnull(user))
return 0
if(numticks == 0)
return 1
var/delayfraction = round(delay/numticks)
var/Location = user.loc
var/originalstat = user.stat
for(var/i = 0, i<numticks, i++)
sleep(delayfraction)
if(!user || (!(spell_flags & (STATALLOWED|GHOSTCAST)) && user.stat != originalstat) || !(user.loc == Location))
return 0
return 1