/
githubmirror
/
vgstation13
Обзор
Документация
Войти
/
githubmirror
/
vgstation13
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
Bleeding-Edge
code/modules/spells/spell_code.dm
869 строк
30 KB
Anthony "Shifty Rail
Refactors player preferences for modularity + SQLite Unit Test (#37615)
07 июн 2025, 16:54
Не верифицирован
07 июн 2025, 16:54
189f77c
Код
Авторство
О чём код?
var/list/spells = typesof(/spell) //needed for the badmin verb for now /spell var/name = "Spell" /// Used for feedback gathering. Not implemented var/abbreviation = "" var/desc = "A spell." parent_type = /datum /// What panel the proc holder needs to go on. var/panel = "Spells" /// Fluff. Unimplemented. var/school = "evocation" /// What kind of mob uses this spell. See 'spell_defines.dm'. Form: USER_TYPE_WIZARD, etc. var/user_type = USER_TYPE_NOUSER /// Used for what list they belong to in the spellbook. SSOFFENSIVE, SSDEFENSIVE, SSUTILITY var/specialization ///can be recharge or charges, see charge_cooldown_max and charge_counter descriptions; can also be based on the holder's vars now, use "holder_var" for that; can ALSO be made to gradually drain the charge with SP_GRADUAL ///The following are allowed: SP_RECHARGE (Recharges), SP_CHARGES (Limited uses), SP_GRADUAL (Gradually lose charges), SP_PASSIVE (Does not cast) var/charge_type = SP_RECHARGE /// Used to calculate cooldown reduction var/initial_charge_cooldown_max = 10 SECONDS /// recharge time in deciseconds if charge_type = SP_RECHARGE or starting charges if charge_type = SP_CHARGES var/charge_cooldown_max = 10 SECONDS /// can only cast spells if it equals recharge, ++ each decisecond if charge_type = SP_RECHARGE or -- each cast if charge_type = SP_CHARGES var/charge_counter = 0 /// if set, the minimum charge_counter necessary to cast SP_GRADUAL spells var/minimum_charge = 0 /// Message to display if spell is recharging. var/still_recharging_msg = "<span class='notice'>The spell is still recharging.</span>" // Time in ticks until you can't cast a spell anymore. See spell_master silence_spells() var/silenced = 0 /// How much does it cost to buy this spell from a spellbook var/price = SP_BASE_PRICE /// How much lowering the spell cooldown costs in the spellbook var/quicken_price = SP_BASE_PRICE * 0.5 /// If 0, non-refundable var/refund_price = 0 /// Type of dmg dealt. only used if charge_type equals to "holder_var" var/holder_var_type = "bruteloss" /// Amount to adjust var when spell is used, THIS VALUE IS SUBTRACTED. var/holder_var_amount = 20 /// Name of the holder var on the UI. var/holder_var_name /// Override for still recharging msg for holder variables var/insufficient_holder_msg /// if a holder var is stored on a different object or a datum var/datum/special_var_holder /// See var definition for potential flags spells. var/spell_flags = NEEDSCLOTHES //Possible spell flags: //GHOSTCAST to make ghosts be able to cast this //NEEDSCLOTHES to forbit guys without wizard garb from casting this //NEEDSHUMAN to forbid non-humans to cast this //Z2NOCAST to forbit casting this on z-level 2 (centcomm, and wizard spawn) //STATALLOWED to allow dead/unconscious guys (and ghosts) to cast this //IGNOREPREV to make each new target not overlap with the previous one //CONSTRUCT_CHECK used by construct spells - checks for nullrods //NO_BUTTON to prevent spell from showing up in the HUD //WAIT_FOR_CLICK to make the spell cast on the next target you click //For targeted spells: //INCLUDEUSER to include user in the target selection //SELECTABLE to allow selecting a target for the spell //For AOE spells: //IGNOREDENSE to ignore dense turfs in selection //IGNORESPACE to ignore space turfs in selection /// See var definition for possible spells. Implemented for golems. var/autocast_flags //Flags for making AI-controlled spellcasters' life easier //Possible flags: //AUTOCAST_NOTARGET means that the AI can't pick a target for this spell by itself - a target must be given to it /// what is uttered when the wizard casts the spell var/invocation = "HURP DURP" /// can be none, whisper, shout, and emote var/invocation_type = SP_INV_NONE /// the range of the spell; outer radius for aoe spells var/range = 7 /// whatever it says to the guy affected by it var/message = "" /// can be "range" or "view" var/selection_type = "view" /// where the spell is. Normally the user, can be an item var/atom/movable/holder /// how long the spell lasts var/duration = 0 /// Valid targets list. Can be overriden var/list/valid_targets = list(/mob/living) /// the current spell levels - total spell levels can be obtained by just adding the two values var/list/spell_levels = list(SP_SPEED = 0, SP_POWER = 0) /// maximum possible levels in each category. Total does cover both. var/list/level_max = list(SP_TOTAL = 4, SP_SPEED = 4, SP_POWER = 0) /// If set, defines how much charge_cooldown_max drops by every speed upgrade var/cooldown_reduc = 0 /// For channelled spells (cast_delay > 0), reduces the delay before the spell is active. var/delay_reduc = 0 /// minimum possible cooldown for a charging spell var/cooldown_min = 0 // Nb: currently, this does nothing, and probably hasn't since this line was written. /// Flags for what this spell is 'based' upon, for interacting with other spells var/spell_aspect_flags //Flags for what this spell is 'based' upon, for interacting with other spells //For instance, a fire-based spell would have the FIRE flag var/overlay = 0 var/overlay_icon = 'icons/obj/wizard.dmi' var/overlay_icon_state = "spell" var/overlay_lifespan = 0 /// If sparks caused by this spell spread. var/sparks_spread = 0 /// cropped at 10 var/sparks_amt = 0 /// 1 - harmless, 2 - harmful var/smoke_spread = 0 /// cropped at 10 var/smoke_amt = 0 /// probability (0-100) to call critfail() var/critfailchance = 0 /// Delay before cast var/cast_delay = 1 /// Soundfile for cast. var/cast_sound = "" /// Progress bar for longer cast sells. var/use_progress_bar = FALSE ///name of the icon-state used in generating the spell hud icon. var/hud_state = "" /// icon used for the hud. var/override_icon = "" /// Background colour used in the HUD var/override_base = "" /// Dir used var/icon_direction = SOUTH //Needs override_icon to be not null /// Button atom to cast the spell var/obj/abstract/screen/spell/connected_button /// Is the spell being cast right now, or waiting a target for WAIT_CLICK var/currently_channeled = 0 /// equals TRUE while a SP_GRADUAL spell is actively being cast var/gradual_casting = FALSE /// The holiday this spell is restricted to ! Leave empty if none. var/list/holiday_required = list() /// prevents some spells from being spamed var/block = 0 /// The animation atom to be created during the cast var/obj/delay_animation = null /// Used by NO_TURNING to memorize the user's direction and turn them around var/user_dir /////////////////////// ///SETUP AND PROCESS/// /////////////////////// /// Constructor proc /spell/New() ..() //still_recharging_msg = "<span class='notice'>[name] is still recharging.</span>" charge_counter = charge_cooldown_max initial_charge_cooldown_max = charge_cooldown_max //Let's not add charge_cooldown_max_initial to roughly 80 (at the time of this comment) spells /// Private: internal sanity check for setting holder /spell/proc/set_holder(var/new_holder) if(holder == new_holder) world.log << "[src] is trying to set its holder to the same holder!" holder = new_holder /// Private: master proc for channelled spells, recharging cooldown, etc. /spell/proc/process() spawn while(charge_counter < charge_cooldown_max) if(holder && !holder.timestopped) if(gradual_casting) if(charge_type & SP_HOLDVAR) //If the spell is both SP_GRADUAL and SP_HOLDVAR, decrement the holder var instead. if(holder.vars[holder_var_type] <= 0) holder.vars[holder_var_type] = 0 //Assumes the minimum of the holder var is 0. gradual_casting = FALSE stop_casting(null, holder) else holder.vars[holder_var_type] -= holder_var_amount else if(charge_counter <= 0) charge_counter = 0 gradual_casting = FALSE stop_casting(null, holder) else charge_counter-- else charge_counter++ if(charge_counter >= charge_cooldown_max) return sleep(1) return ///////////////// /////CASTING///// ///////////////// /// Public: what happens when you right-click on the spell icon in the HUD (example: set different targetting mode) /spell/proc/on_right_click(mob/user) return /// Public: returns the list of things the spell will use in invocation() /// Already implemented for targetted, aoe_turf, etc. Can be overriden for special target selection by the spell. /spell/proc/choose_targets(mob/user = usr) //depends on subtype - see targeted.dm, aoe_turf.dm, dumbfire.dm, or code in general folder return /// Public: helper proc for checking if a target is valid. /// Call in `choose_targets`. Automatically called by targetted/aoe_turf spells. /spell/proc/is_valid_target(atom/target, mob/user, options, bypass_range = 0) if(ismob(target)) var/mob/M = target if(user in M.get_arcane_golems()) return FALSE if(user.shares_arcane_golem_spell(M)) return FALSE if(bypass_range && istype(target, /mob/living)) return TRUE if(options) return (target in options) return ((target in view_or_range(range, user, selection_type)) && is_type_in_list(target, valid_targets)) /// Private: master proc for the full spellcode /// Selects target, does the channel check, animate, casts the spell, etc. /spell/proc/perform(mob/user = usr, skipcharge = 0, list/target_override) if(!holder) set_holder(user) //just in case var/list/targets = target_override if(before_channel(user) && !currently_channeled) return if(!targets && (spell_flags & WAIT_FOR_CLICK)) channel_spell(user, skipcharge) return if(cast_check(1, user)) if(gradual_casting) gradual_casting = FALSE stop_casting(targets, user) return else return if(!cast_check(skipcharge, user)) return if(cast_delay && !spell_do_after(user, cast_delay)) block = 0 if (delay_animation) qdel(delay_animation) delay_animation = null return block = 0 if (delay_animation) qdel(delay_animation) delay_animation = null if(before_target(user)) return if(!targets) targets = choose_targets(user) if(!cast_check(skipcharge, user)) return //Prevent queueing of spells by opening several choose target windows. if(targets && targets.len) targets = before_cast(targets, user) //applies any overlays and effects if(!targets.len) //before cast has rechecked what we can target return invocation(user, targets) user.attack_log += text("\[[time_stamp()]\] <font color='red'>[user.real_name] ([user.ckey]) cast the spell [name].</font>") INVOKE_EVENT(user, /event/spellcast, "spell" = src, "user" = user, "targets" = targets) if(prob(critfailchance)) critfail(targets, user) else . = cast(targets, user) //return 1 to prevent take_charge if(!.) take_charge(user, skipcharge) after_cast(targets) //generates the sparks, smoke, target messages etc. /// Private: This is used with the wait_for_click spell flag to prepare spells to be cast on your next click /spell/proc/channel_spell(mob/user = usr, skipcharge = 0, force_remove = 0) if(!holder) set_holder(user) //just in case if(!force_remove && !currently_channeled) if(!cast_check(skipcharge, user)) return 0 user.remove_spell_channeling() //In case we're swapping from an older spell to this new one user.register_event(/event/uattack, src, nameof(src::channeled_spell())) user.spell_channeling = src if(spell_flags & CAN_CHANNEL_RESTRAINED) user.register_event(/event/ruattack, src, nameof(src::channeled_spell())) user.spell_channeling = src connected_button.name = "(Ready) [name]" currently_channeled = 1 connected_button.add_channeling() else user.unregister_event(/event/uattack, src, nameof(src::channeled_spell())) user.unregister_event(/event/ruattack, src, nameof(src::channeled_spell())) user.spell_channeling = null currently_channeled = 0 connected_button.remove_channeling() connected_button.name = name return 1 /// Used by NO_TURNING to turn the user around /// Due to the way the code is structured (/event/uattack happens after the user has turned around) /// we have to check for the only thing that happens before turning, /event/clickon. /// but since that has no way of directly interfering with face_atom() we instead memorize the direction of the user at the time /// and then flip them around at the start of proper spellcasting. /// Unfortunately this means that the user is still technically turning around. /// The only viable solution would be restructuring click.dm code to support not turning around but that might break too many things. /// (Private) /spell/proc/memorize_user_direction(mob/user, list/modifiers, atom/target) if(holder) user_dir = holder.dir /// Private: internal master proc for channelled spells. /spell/proc/channeled_spell(atom/atom, bypassrange = 0) var/list/target = list(atom) var/mob/user = holder user.attack_delayer.delayNext(0) if(spell_flags & NO_TURNING) holder.dir = user_dir holder.update_dir() if(cast_check(1, holder) && is_valid_target(atom, user, bypass_range = bypassrange)) target = before_cast(target, user, bypassrange) //applies any overlays and effects if(!target.len) //before cast has rechecked what we can target return invocation(user, target) user.attack_log += text("\[[time_stamp()]\] <font color='red'>[user.real_name] ([user.ckey]) cast the spell [name].</font>") INVOKE_EVENT(user, /event/spellcast, "spell" = src, "user" = user, "targets" = target) if(prob(critfailchance)) critfail(target, holder) else . = cast(target, holder) after_cast(target) if(!.) //Returning 1 will prevent us from removing the channeling and taking charge channel_spell(force_remove = 1) take_charge(holder, 0) return 1 return 0 /// Public: automatically called in the master proc for channelled spells. /spell/proc/before_channel(mob/user) return /// Public: automatically called in the spell before selecting targets. /spell/proc/before_target(mob/user) return /// Public: the actual meat of the spell /spell/proc/cast(list/targets, mob/user) return /// Public: Automatically called for channelled spells when they're no longer being cast. /// Should be manually called for wizard death, etc. /spell/proc/stop_casting(list/targets, mob/user) if(gradual_casting) gradual_casting = FALSE return /// Public: the wizman has fucked up somehow /// Currently unimplemented asider from vampire code /spell/proc/critfail(list/targets, mob/user) return /// Private: handles the adjustment of the var when the spell is used. has some hardcoded types /// Should PROBABLY be reworked............. /spell/proc/adjust_var(mob/living/target = usr, varname, amount) // if(!(varname in target.vars)) world.log << "Spell [varname] of user [usr] adjusting non-numeric value on [target], aborting" return switch(varname) if("bruteloss") target.adjustBruteLoss(amount) if("fireloss") target.adjustFireLoss(amount) if("toxloss") target.adjustToxLoss(amount) if("oxyloss") target.adjustOxyLoss(amount) if("stunned") target.AdjustStunned(amount) if("knockdown") target.AdjustKnockdown(amount) if("paralysis") target.AdjustParalysis(amount) if("plasma") target.AdjustPlasma(-amount) else target.vars[varname] -= amount //I bear no responsibility for the runtimes that'll happen if you try to adjust non-numeric or even non-existant vars /////////////////////////// /////CASTING WRAPPERS////// /////////////////////////// /// Public: wrapper before casting the spell. Default behaviour is to scan view/range, check everything for `is_valid_target` /// And then return the list of targets: /spell/proc/before_cast(list/targets, user, bypass_range = 0) var/list/valid_targets = list() var/list/options = view_or_range(range,user,selection_type) for(var/atom/target in targets) // Check range again (fixes long-range EI NATH) if(!is_valid_target(target, user, options, bypass_range)) 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.setDensity(FALSE) spawn(overlay_lifespan) QDEL_NULL(spell) return valid_targets /// Public: wrapper AFTER casting the spell. /// Default behaviour: send `message` var, apply sparks, apply smoke /spell/proc/after_cast(list/targets) for(var/atom/target in targets) var/location = get_turf(target) if(istype(target,/mob/living) && message) to_chat(target, text("[message]")) if(sparks_spread) spark(location, sparks_amt, FALSE) if(smoke_spread) if(smoke_spread == 1) var/datum/effect/system/smoke_spread/smoke = new /datum/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/system/smoke_spread/bad/smoke = new /datum/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*/ /// Public: check if spell can be cast. /// Default behaviour handles cooldown, z-level check, 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) to_chat(user, "<span class='warning'>You shouldn't have this spell! Something's wrong.</span>") return 0 if(charge_type == SP_PASSIVE) to_chat(user, "<span class='notice'>This is a passive spell, you cannot cast it!</span>") return 0 if(silenced > 0) return if(user.reagents && user.reagents.has_reagent(ZOMBIEPOWDER)) to_chat(user, "<span class='warning'>You just can't seem to focus enough to do this.</span>") return 0 var/ourz = user.z if(!ourz) var/turf/T = get_turf(user) if(!T) return 0 ourz = T.z if(map.zLevels.len < ourz || !ourz) WARNING("[user] is somehow on a zlevel [(ourz > map.zLevels.len) ? "higher" : "lower"] than our zlevels list! [map.zLevels.len] level\s, [map.nameLong] - [formatJumpTo(get_turf(user))]") return 0 if(istype(map.zLevels[ourz], /datum/zLevel/centcomm) && spell_flags & Z2NOCAST) //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) to_chat(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)) to_chat(user, "Not when you're incapacitated.") return 0 if((ishuman(user) || ismonkey(user)) && !(invocation_type in list(SP_INV_EMOTE, SP_INV_NONE))) if(user.wear_mask?.is_muzzle) to_chat(user, "Mmmf mrrfff!") return 0 var/spell/passive/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 //gentling check if((is_wizard_spell()) && (holder == user)) if(user.is_gentled()) return 0 return 1 /// Private: simple helper to check if the spell is typically used by wizards /spell/proc/is_wizard_spell() if(user_type == USER_TYPE_WIZARD || USER_TYPE_SPELLBOOK) return TRUE return FALSE /// Semi-private: checks cooldown, charges, gradual. /spell/proc/check_charge(var/skipcharge, mob/user) //Arcane golems have no cooldowns on their spells if(istype(user, /mob/living/simple_animal/hostile/arcane_golem)) return 1 if(charge_type == SP_PASSIVE) return 1 if(!skipcharge) if(charge_type & SP_RECHARGE) if(charge_counter < charge_cooldown_max) to_chat(user, still_recharging_msg) return 0 if(charge_type & SP_CHARGES) if(!charge_counter) to_chat(user, "<span class='notice'>[name] has no charges left.</span>") return 0 if(charge_type & SP_HOLDVAR) if(special_var_holder) if(!(holder_var_type in special_var_holder.vars)) return 1 //ABORT if(special_var_holder.vars[holder_var_type] < holder_var_amount) to_chat(user, holder_var_recharging_msg()) return 0 else if(!(holder_var_type in user.vars)) return 1 //ABORT if(user.vars[holder_var_type] < holder_var_amount) to_chat(user, holder_var_recharging_msg()) return 0 if(charge_type & SP_GRADUAL) if(charge_counter < minimum_charge) to_chat(user, still_recharging_msg) return 0 return 1 /// Semi-private: what is sent to the user if a spell needs recharging. /// Default behaviour uses the spell `still_recharging_msg` and `insufficient_holder_msg` /spell/proc/holder_var_recharging_msg() if(insufficient_holder_msg) return insufficient_holder_msg return still_recharging_msg /// Private: takes spell charges and apply cooldown /spell/proc/take_charge(mob/user = user, var/skipcharge) if(!skipcharge) if(charge_type & SP_RECHARGE) charge_counter = 0 //doesn't start recharging until the targets selecting ends src.process() if(charge_type & SP_CHARGES) charge_counter-- //returns the charge if the targets selecting fails if(charge_type & SP_HOLDVAR) if(special_var_holder) adjust_var(special_var_holder, holder_var_type, holder_var_amount) else adjust_var(user, holder_var_type, holder_var_amount) if(charge_type & SP_GRADUAL) gradual_casting = TRUE charge_counter -= 1 process() if(charge_type & SP_PASSIVE) process() /// Semi-private: wrapper for shouting out the invocation /// Applying the spell cast, etc. /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(SP_INV_SHOUT) if(prob(50))//Auto-mute? Fuck that noise user.say(invocation) else user.say(replacetext(invocation," ","`")) if(SP_INV_WHISPER) if(prob(50)) user.whisper(invocation) else user.whisper(replacetext(invocation," ","`")) if(SP_INV_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/// ///////////////////// /// Public: checks if the spell can be improved /// Default behaviour: checks with `spell_levels` and `level_max` /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 && (upgrade_type in spell_levels) && (upgrade_type in level_max)) if(spell_levels[upgrade_type] >= level_max[upgrade_type]) return 0 return 1 /// Public: proc to be called when purchasing `SP_POWER` upgrade /spell/proc/empower_spell() return /// Public: proc to be called when purchasing `SP_SPEED` upgrade /// Default behaviour is to make it quicker (duh) /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_cooldown_max = max(cooldown_min, charge_cooldown_max - cooldown_reduc) else charge_cooldown_max = round(initial_charge_cooldown_max - spell_levels[SP_SPEED] * (initial_charge_cooldown_max - cooldown_min)/ level_max[SP_SPEED]) if(charge_cooldown_max < charge_counter) charge_counter = charge_cooldown_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 /// Private: proc displays a progress bar and acts as a `do_after` check (mob stays still, target in range, etc) /// Automatically called if the spell has a `cast_delay`. /spell/proc/spell_do_after(var/mob/user, delay, var/numticks = 5) if(!user || isnull(user)) return 0 if(numticks == 0) return 0 var/delayfraction = round(delay/numticks) var/originalstat = user.stat var/Location = user.loc var/image/progbar if(user && user.client && user.client.prefs.get_pref(/datum/preference_setting/toggle/progress_bars)) if(!progbar) progbar = image("icon" = 'icons/effects/doafter_icon.dmi', "loc" = user, "icon_state" = "prog_bar_0") progbar.pixel_z = WORLD_ICON_SIZE progbar.plane = HUD_PLANE progbar.layer = HUD_ABOVE_ITEM_LAYER progbar.appearance_flags = RESET_COLOR for (var/i = 1 to numticks) if(user && user.client && user.client.prefs.get_pref(/datum/preference_setting/toggle/progress_bars)) if(!progbar) progbar = image("icon" = 'icons/effects/doafter_icon.dmi', "loc" = user, "icon_state" = "prog_bar_0") progbar.pixel_z = WORLD_ICON_SIZE progbar.plane = HUD_PLANE progbar.layer = HUD_ABOVE_ITEM_LAYER progbar.appearance_flags = RESET_COLOR progbar.icon_state = "prog_bar_[round(((i / numticks) * 100), 10)]" user.client.images |= progbar sleep(delayfraction) if(!user || (!(spell_flags & (STATALLOWED|GHOSTCAST)) && user.stat != originalstat) || !(user.loc == Location)) if(progbar) progbar.icon_state = "prog_bar_stopped" spawn(2) if(user && user.client) user.client.images -= progbar if(progbar) progbar.loc = null return 0 if(user && user.client) user.client.images -= progbar if(progbar) progbar.loc = null return 1 /// Private: calls the relevant upgrade proc /spell/proc/apply_upgrade(upgrade_type) switch(upgrade_type) if(SP_SPEED) return quicken_spell() if(SP_POWER) return empower_spell() /// Public: how much spell points it costs to upgrade the spell /// Can override if you want a finer control over balance. Default behaviour uses `quicken_price` and `price` /spell/proc/get_upgrade_price(upgrade_type) if(upgrade_type == SP_SPEED) return quicken_price return src.price ///INFO /// Public: return texts to be displayed in the spellbook for upgrade /// Should override to have better explanation for `SP_POWER` upgrades. /spell/proc/get_upgrade_info(upgrade_type) switch(upgrade_type) if(SP_SPEED) if(spell_levels[SP_SPEED] >= level_max[SP_SPEED]) return "The spell can't be made any quicker than this!" var/formula if(cooldown_reduc) formula = min(charge_cooldown_max - cooldown_min, cooldown_reduc) else formula = round((initial_charge_cooldown_max - cooldown_min)/level_max[SP_SPEED], 1) return "Reduce this spell's cooldown by [formula/10] seconds." if(SP_POWER) if(spell_levels[SP_POWER] >= level_max[SP_POWER]) return "The spell can't be made any more powerful than this!" return "Increase this spell's power." /// Atomizes what data the spell shows, that way different spells such as pulse demon and vampire spells can have their own descriptions. /spell/proc/generate_tooltip(var/previous_data = "") var/dat = previous_data //In case you want to put some text at the top instead of bottom if(charge_type & SP_RECHARGE) dat += "<br>Cooldown: [charge_cooldown_max/10] second\s" if(charge_type & SP_CHARGES) dat += "<br>Has [charge_counter] charge\s left" if(charge_type & SP_HOLDVAR) dat += "<br>Requires [charge_type & SP_GRADUAL ? "" : "[holder_var_amount]"] " if(holder_var_name) dat += "[holder_var_name]" else dat += "[holder_var_type]" if(charge_type & SP_GRADUAL) dat += " to sustain" switch(range) if(1) dat += "<br>Range: Adjacency" if(2 to INFINITY) dat += "<br>Range: [range]" if(GLOBALCAST) dat += "<br>Range: Global" if(SELFCAST) dat += "<br>Range: Self" if(desc) dat += "<br>Desc: [desc]" return dat /// Public: return a string that gets appended to the spell on the scoreboard /spell/proc/get_scoreboard_suffix() return //////////////////// // EVENTS // //////////////////// /// Public: called by event when the mob gets the spell /spell/proc/on_added(mob/user) return /// Public: called by event when the mob loses the spell /spell/proc/on_removed(mob/user) holder = null return /// Public: called by event when the mob fucking dies /spell/proc/on_holder_death(mob/user) return /// Public: called by event when the mob switches minds /spell/proc/on_transfer(mob/user) return //////////////////// //WIZARD MOB PROCS// //////////////////// //To batch-remove wizard spells. Linked to mind.dm. /mob/proc/spellremove(var/mob/M as mob) for(var/spell/spell_to_remove in src.spell_list) remove_spell(spell_to_remove) // Does this clothing slot count as wizard garb? (Combines a few checks) /proc/is_wiz_garb(var/obj/item/clothing/C) return C && C.wizard_garb /*Checks if the wizard is wearing the proper attire. Made a proc so this is not repeated 14 (or more) times.*/ /mob/proc/wearing_wiz_garb() to_chat(src, "Silly creature, you're not a human. Only humans can cast this spell.") return 0 // Humans can wear clothes. /mob/living/carbon/human/wearing_wiz_garb() if(!is_wiz_garb(src.wear_suit)) to_chat(src, "<span class='warning'>I don't feel strong enough without my robe.</span>") return 0 if(!is_wiz_garb(src.shoes)) to_chat(src, "<span class='warning'>I don't feel strong enough without my sandals.</span>") return 0 if(!is_wiz_garb(src.head)) to_chat(src, "<span class='warning'>I don't feel strong enough without my hat.</span>") return 0 return 1 // So can monkeys (FIXME) /* /mob/living/carbon/monkey/wearing_wiz_garb() if(!is_wiz_garb(src.wear_suit)) to_chat(src, "<span class='warning'>I don't feel strong enough without my robe.</span>") return 0 if(!is_wiz_garb(src.shoes)) to_chat(src, "<span class='warning'>I don't feel strong enough without my sandals.</span>") return 0 if(!is_wiz_garb(src.head)) to_chat(src, "<span class='warning'>I don't feel strong enough without my hat.</span>") return 0 return 1 */ /// Mob wears clothing that prevents him from casting spells. /mob/proc/is_gentled() for(var/V in get_equipped_items()) if(isclothing(V)) var/obj/item/clothing/C = V if(C.gentling) to_chat(src, "<span class='warning'>You feel too humble to do that.</span>") return TRUE return FALSE