Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qol: recharge spell million istypes removal #5915

Merged
merged 29 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions code/__DEFINES/spells.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Spell target defines
#define SPELL_TARGET_CLOSEST 1
#define SPELL_TARGET_RANDOM 2
/// Spell target selection
#define SPELL_SELECTION_RANGE "range"
#define SPELL_SELECTION_VIEW "view"
/// Smoke spell defines
#define SMOKE_NONE 0
#define SMOKE_HARMLESS 1
#define SMOKE_COUGHING 2
#define SMOKE_SLEEPING 3
/// Recharge spell defines
#define RECHARGE_SUCCESSFUL (1<<0)
#define RECHARGE_BURNOUT (1<<1)
12 changes: 0 additions & 12 deletions code/datums/spell.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#define SPELL_TARGET_CLOSEST 1
#define SPELL_TARGET_RANDOM 2

#define SPELL_SELECTION_RANGE "range"
#define SPELL_SELECTION_VIEW "view"

#define SMOKE_NONE 0
#define SMOKE_HARMLESS 1
#define SMOKE_COUGHING 2
#define SMOKE_SLEEPING 3


/obj/effect/proc_holder
var/active = FALSE //Used by toggle based abilities.
var/ranged_mousepointer
Expand Down
4 changes: 2 additions & 2 deletions code/datums/spells/chaplain.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
school = "transmutation"
base_cooldown = 6 SECONDS
clothes_req = FALSE
selection_activated_message = "<span class='notice'>You prepare a blessing. Click on a target to start blessing.</span>"
selection_deactivated_message = "<span class='notice'>The crew will be blessed another time.</span>"
selection_activated_message = span_notice("You prepare a blessing. Click on a target to start blessing.")
selection_deactivated_message = span_notice("The crew will be blessed another time.")
cooldown_min = 2 SECONDS
action_icon_state = "shield"
need_active_overlay = TRUE
Expand Down
107 changes: 21 additions & 86 deletions code/datums/spells/charge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,31 @@


/obj/effect/proc_holder/spell/charge/cast(list/targets, mob/user = usr)
for(var/mob/living/L in targets)
var/list/hand_items = list(L.get_active_hand(),L.get_inactive_hand())
var/charged_item = null
var/burnt_out = FALSE
var/charge_result = NONE
var/atom/charge_target_name

if(L.pulling && (isliving(L.pulling)))
var/mob/living/M = L.pulling
if(LAZYLEN(M.mob_spell_list) || (M.mind && LAZYLEN(M.mind.spell_list)))
for(var/obj/effect/proc_holder/spell/spell as anything in M.mob_spell_list)
spell.cooldown_handler.revert_cast()
if(M.mind)
for(var/obj/effect/proc_holder/spell/spell as anything in M.mind.spell_list)
spell.cooldown_handler.revert_cast()
to_chat(M, "<span class='notice'>You feel raw magical energy flowing through you, it feels good!</span>")
else
to_chat(M, "<span class='notice'>You feel very strange for a moment, but then it passes.</span>")
burnt_out = TRUE
charged_item = M
break
for(var/obj/item in hand_items)
if(istype(item, /obj/item/spellbook))
if(istype(item, /obj/item/spellbook/oneuse))
var/obj/item/spellbook/oneuse/I = item
if(prob(80))
L.visible_message("<span class='warning'>[I] catches fire!</span>")
qdel(I)
else
I.used = FALSE
charged_item = I
break
else
to_chat(L, "<span class='caution'>Glowing red letters appear on the front cover...</span>")
to_chat(L, "<span class='warning'>[pick("NICE TRY BUT NO!","CLEVER BUT NOT CLEVER ENOUGH!", "SUCH FLAGRANT CHEESING IS WHY WE ACCEPTED YOUR APPLICATION!", "CUTE!", "YOU DIDN'T THINK IT'D BE THAT EASY, DID YOU?")]</span>")
burnt_out = TRUE
var/mob/living/living = targets[1]

else if(istype(item, /obj/item/book/granter))
var/obj/item/book/granter/I = item
if(prob(80))
L.visible_message("<span class='warning'>[I] catches fire!</span>")
qdel(I)
else
I.uses += 1
charged_item = I
break
if(living.pulling)
charge_target_name = living.pulling.name
charge_result = living.pulling.magic_charge_act(living)

else if(istype(item, /obj/item/gun/magic))
var/obj/item/gun/magic/I = item
if(prob(80) && !I.can_charge)
I.max_charges--
if(I.max_charges <= 0)
I.max_charges = 0
burnt_out = TRUE
I.charges = I.max_charges
if(istype(item,/obj/item/gun/magic/wand) && I.max_charges != 0)
var/obj/item/gun/magic/W = item
W.icon_state = initial(W.icon_state)
charged_item = I
break
if(!(charge_result & RECHARGE_SUCCESSFUL))
var/list/hand_items = list(living.get_active_hand(), living.get_inactive_hand())

else if(istype(item, /obj/item/stock_parts/cell/))
var/obj/item/stock_parts/cell/C = item
if(!C.self_recharge)
if(prob(80))
C.maxcharge -= 200
if(C.maxcharge <= 1) //Div by 0 protection
C.maxcharge = 1
burnt_out = TRUE
C.charge = C.maxcharge
charged_item = C
for(var/obj/item in hand_items)
charge_target_name = item.name
charge_result = item.magic_charge_act(living)

if(charge_result & RECHARGE_SUCCESSFUL)
break

else if(item.contents)
var/obj/I = null
for(I in item.contents)
if(istype(I, /obj/item/stock_parts/cell/))
var/obj/item/stock_parts/cell/C = I
if(!C.self_recharge)
if(prob(80))
C.maxcharge -= 200
if(C.maxcharge <= 1) //Div by 0 protection
C.maxcharge = 1
burnt_out = TRUE
C.charge = C.maxcharge
item.update_icon()
charged_item = item
break
if(!charged_item)
to_chat(L, "<span class='notice'>You feel magical power surging to your hands, but the feeling rapidly fades...</span>")
else if(burnt_out)
to_chat(L, "<span class='caution'>[charged_item] doesn't seem to be reacting to the spell...</span>")
else
to_chat(L, "<span class='notice'>[charged_item] suddenly feels very warm!</span>")
if(!(charge_result & RECHARGE_SUCCESSFUL))
to_chat(user, span_notice("You feel magical power surging to your hands, but the feeling rapidly fades..."))
return

if(charge_result & RECHARGE_BURNOUT)
to_chat(user, span_caution("[charge_target_name] is reacting poorly to the spell!"))
return

to_chat(user, span_notice("[charge_target_name] suddenly feels very warm!"))
8 changes: 4 additions & 4 deletions code/datums/spells/charge_up.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
var/energy_perc = get_energy_charge() / max_charge_time
if(energy_perc < 0.5)
cooldown_handler.start_recharge((1 - energy_perc) * cooldown_handler.recharge_duration) // Shorten the cooldown based on how long it was charged for.
to_chat(user, "<span class='notice'>[stop_charging_text]</span>")
to_chat(user, span_notice("[stop_charging_text]"))
Reset(user)
return TRUE
else
to_chat(user, "<span class='danger'>[stop_charging_fail_text]</span>")
to_chat(user, span_danger("[stop_charging_fail_text]"))
return FALSE


Expand All @@ -54,7 +54,7 @@


/obj/effect/proc_holder/spell/charge_up/proc/StartChargeup(mob/user)
to_chat(user, "<span class='notice'>[start_charging_text]</span>")
to_chat(user, span_notice("[start_charging_text]"))
user.add_overlay(charge_up_overlay)
playsound(user, charge_sound, 50, FALSE, channel = charge_sound.channel)
start_time = world.time
Expand All @@ -80,7 +80,7 @@


/obj/effect/proc_holder/spell/charge_up/proc/Discharge(mob/user)
to_chat(user, "<span class='danger'>You lose control over the spell!</span>")
to_chat(user, span_danger("You lose control over the spell!"))
Reset(user)
spend_spell_cost(user)
cooldown_handler.start_recharge()
Expand Down
10 changes: 10 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,16 @@
return RCD_NO_ACT


/atom/proc/magic_charge_act(mob/user)
. = NONE

if(!contents)
return

for(var/obj/item/stock_parts/cell/cell in contents)
. |= cell.magic_charge_act(user)


/atom/proc/hitby(atom/movable/AM, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
if(density && !AM.has_gravity()) //thrown stuff bounces off dense stuff in no grav, unless the thrown stuff ends up inside what it hit(embedding, bola, etc...).
addtimer(CALLBACK(src, PROC_REF(hitby_react), AM), 2)
Expand Down
28 changes: 28 additions & 0 deletions code/game/gamemodes/wizard/spellbook.dm
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@
initialize()


/obj/item/spellbook/magic_charge_act(mob/user)
. = RECHARGE_SUCCESSFUL|RECHARGE_BURNOUT

to_chat(user, span_caution("Glowing red letters appear on the front cover..."))
to_chat(user, span_warning(pick("NICE TRY BUT NO!", \
"CLEVER BUT NOT CLEVER ENOUGH!", \
"SUCH FLAGRANT CHEESING IS WHY WE ACCEPTED YOUR APPLICATION!", \
"CUTE!", \
"YOU DIDN'T THINK IT'D BE THAT EASY, DID YOU?")))


/obj/item/spellbook/attackby(obj/item/I, mob/living/user, params)
if(user.a_intent == INTENT_HARM || skip_refunds)
return ..()
Expand Down Expand Up @@ -1016,6 +1027,23 @@
uses = 1
desc = "This template spellbook was never meant for the eyes of man..."


/obj/item/spellbook/oneuse/magic_charge_act(mob/user)
. = NONE

if(!used)
return

used = FALSE
. |= RECHARGE_SUCCESSFUL

if(prob(80))
visible_message(span_warning("[src] catches fire!"))
user.temporarily_remove_item_from_inventory(src)
qdel(src)
. |= RECHARGE_BURNOUT


/obj/item/spellbook/oneuse/New()
..()
name += spellname
Expand Down
25 changes: 25 additions & 0 deletions code/game/objects/items/granters/_granters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
if(reading)
to_chat(user, span_warning("You're already reading this!"))
return FALSE

if(!user.has_vision())
to_chat(user, span_warning("You are blind and can't read anything!"))
return FALSE

if(!isliving(user))
return FALSE

if(!can_learn(user))
return FALSE

Expand All @@ -40,14 +43,17 @@

on_reading_start(user)
reading = TRUE

for(var/i in 1 to pages_to_mastery)
if(!turn_page(user))
on_reading_stopped(user)
reading = FALSE
return

if(do_after(user, reading_time, user))
uses--
on_reading_finished(user)

reading = FALSE

return TRUE
Expand Down Expand Up @@ -82,6 +88,23 @@
/obj/item/book/granter/proc/can_learn(mob/living/user)
return TRUE


/obj/item/book/granter/magic_charge_act(mob/user)
. = NONE

if(uses >= initial(uses))
return

uses++
. |= RECHARGE_SUCCESSFUL

if(prob(80))
visible_message(span_warning("[src] catches fire!"))
user.temporarily_remove_item_from_inventory(src)
qdel(src)
. |= RECHARGE_BURNOUT


// Generic action giver
/obj/item/book/granter/action
/// The typepath of action that is given
Expand All @@ -92,9 +115,11 @@
/obj/item/book/granter/action/can_learn(mob/living/user)
if(!granted_action)
CRASH("Someone attempted to learn [type], which did not have an action set.")

if(locate(granted_action) in user.actions)
to_chat(user, span_warning("You already know all about [action_name]!"))
return FALSE

return TRUE

/obj/item/book/granter/action/on_reading_start(mob/living/user)
Expand Down
19 changes: 19 additions & 0 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2303,3 +2303,22 @@
/mob/living/proc/update_movespeed_damage_modifiers()
return


/mob/living/magic_charge_act(mob/user)
if(LAZYLEN(mob_spell_list))
for(var/obj/effect/proc_holder/spell/spell as anything in mob_spell_list)
if(spell.cooldown_handler.is_on_cooldown())
continue

spell.revert_cast()
. |= RECHARGE_SUCCESSFUL

if(LAZYLEN(mind?.spell_list))
for(var/obj/effect/proc_holder/spell/spell as anything in mind?.spell_list)
if(spell.cooldown_handler.is_on_cooldown())
continue

spell.revert_cast()
. |= RECHARGE_SUCCESSFUL

to_chat(src, span_notice("You feel [(. & RECHARGE_SUCCESSFUL) ? "raw magical energy flowing through you, it feels good!" : "very strange for a moment, but then it passes."]"))
28 changes: 28 additions & 0 deletions code/modules/power/cell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@
return ..()


/obj/item/stock_parts/cell/magic_charge_act(mob/user)
. = NONE

if(charge >= maxcharge)
return

if(prob(80) && adjust_maxcharge(-200))
. |= RECHARGE_BURNOUT

charge = maxcharge
. |= RECHARGE_SUCCESSFUL

update_appearance(UPDATE_ICON)


/obj/item/stock_parts/cell/proc/adjust_maxcharge(amount)
if(self_recharge)
return FALSE // SelfCharging uses static charge values ​​per tick, so we don't want it to mess up the recharge balance.

var/old_maxcharge = maxcharge
maxcharge = max(maxcharge + amount, 1)

return maxcharge != old_maxcharge


/obj/item/stock_parts/cell/vv_edit_var(var_name, var_value)
. = ..()
if(var_name == NAMEOF(src, self_recharge))
Expand Down Expand Up @@ -369,6 +394,9 @@
/obj/item/stock_parts/cell/emproof/corrupt()
return

/obj/item/stock_parts/cell/emproof/adjust_maxcharge(amount)
return FALSE

/obj/item/stock_parts/cell/ninja
name = "spider-clan power cell"
desc = "A standard ninja-suit power cell."
Expand Down
Loading