From a379391dd3d2e6c4198eaaca17044701a4f5b6fb Mon Sep 17 00:00:00 2001 From: AnturK Date: Tue, 15 May 2018 07:34:37 +0200 Subject: [PATCH] Cleans up touch spells (#37715) * Cleans up touch spells * Silent param * Oh god i'm blind. --- code/modules/spells/spell.dm | 54 +++++++++---------- code/modules/spells/spell_types/godhand.dm | 13 ++--- .../spells/spell_types/touch_attacks.dm | 49 ++++++++++------- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/code/modules/spells/spell.dm b/code/modules/spells/spell.dm index ee02bd524f..89e513fd60 100644 --- a/code/modules/spells/spell.dm +++ b/code/modules/spells/spell.dm @@ -144,7 +144,6 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th var/smoke_spread = 0 //1 - harmless, 2 - harmful var/smoke_amt = 0 //cropped at 10 - var/critfailchance = 0 var/centcom_cancast = 1 //Whether or not the spell should be allowed on z2 action_icon = 'icons/mob/actions/actions_spells.dmi' @@ -153,7 +152,6 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th base_action = /datum/action/spell_action/spell /obj/effect/proc_holder/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(player_lock) if(!user.mind || !(src in user.mind.spell_list) && !(src in user.mob_spell_list)) to_chat(user, "You shouldn't have this spell! Something's wrong.") @@ -168,15 +166,8 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th return 0 if(!skipcharge) - switch(charge_type) - if("recharge") - if(charge_counter < charge_max) - to_chat(user, still_recharging_msg) - return 0 - if("charges") - if(!charge_counter) - to_chat(user, "[name] has no charges left.") - return 0 + if(!charge_check(user)) + return 0 if(user.stat && !stat_allowed) to_chat(user, "Not when you're incapacitated.") @@ -236,6 +227,20 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th action.UpdateButtonIcon() return 1 +/obj/effect/proc_holder/spell/proc/charge_check(mob/user, silent = FALSE) + switch(charge_type) + if("recharge") + if(charge_counter < charge_max) + if(!silent) + to_chat(user, still_recharging_msg) + return FALSE + if("charges") + if(!charge_counter) + if(!silent) + to_chat(user, "[name] has no charges left.") + return FALSE + return TRUE + /obj/effect/proc_holder/spell/proc/invocation(mob/user = usr) //spelling the spell out and setting it on recharge/reducing charges amount switch(invocation_type) if("shout") @@ -297,10 +302,7 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th recharging = TRUE if(sound) playMagSound() - if(prob(critfailchance)) - critfail(targets) - else - cast(targets,user=user) + cast(targets,user=user) after_cast(targets) if(action) action.UpdateButtonIcon() @@ -349,9 +351,6 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th /obj/effect/proc_holder/spell/proc/cast(list/targets,mob/user = usr) return -/obj/effect/proc_holder/spell/proc/critfail(list/targets) - return - /obj/effect/proc_holder/spell/proc/revert_cast(mob/user = usr) //resets recharge or readds a charge switch(charge_type) if("recharge") @@ -500,25 +499,20 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th /obj/effect/proc_holder/spell/proc/can_cast(mob/user = usr) if(((!user.mind) || !(src in user.mind.spell_list)) && !(src in user.mob_spell_list)) - return 0 + return FALSE - switch(charge_type) - if("recharge") - if(charge_counter < charge_max) - return 0 - if("charges") - if(!charge_counter) - return 0 + if(!charge_check(user,TRUE)) + return FALSE if(user.stat && !stat_allowed) - return 0 + return FALSE if(!ishuman(user)) if(clothes_req || human_req) - return 0 + return FALSE if(nonabstract_req && (isbrain(user) || ispAI(user))) - return 0 - return 1 + return FALSE + return TRUE /obj/effect/proc_holder/spell/self //Targets only the caster. Good for buffs and heals, but probably not wise for fireballs (although they usually fireball themselves anyway, honke) range = -1 //Duh diff --git a/code/modules/spells/spell_types/godhand.dm b/code/modules/spells/spell_types/godhand.dm index 2def02b4c0..bf402b7a6a 100644 --- a/code/modules/spells/spell_types/godhand.dm +++ b/code/modules/spells/spell_types/godhand.dm @@ -13,10 +13,7 @@ throwforce = 0 throw_range = 0 throw_speed = 0 - -/obj/item/melee/touch_attack/Initialize() - attached_spell = loc - . = ..() + var/charges = 1 /obj/item/melee/touch_attack/attack(mob/target, mob/living/carbon/user) if(!iscarbon(user)) //Look ma, no hands @@ -29,13 +26,13 @@ /obj/item/melee/touch_attack/afterattack(atom/target, mob/user, proximity) user.say(catchphrase) playsound(get_turf(user), on_use_sound,50,1) - if(attached_spell) - attached_spell.attached_hand = null - qdel(src) + charges-- + if(charges <= 0) + qdel(src) /obj/item/melee/touch_attack/Destroy() if(attached_spell) - attached_spell.attached_hand = null + attached_spell.on_hand_destroy(src) return ..() /obj/item/melee/touch_attack/disintegrate diff --git a/code/modules/spells/spell_types/touch_attacks.dm b/code/modules/spells/spell_types/touch_attacks.dm index 2000d8daea..0ffe02cec2 100644 --- a/code/modules/spells/spell_types/touch_attacks.dm +++ b/code/modules/spells/spell_types/touch_attacks.dm @@ -1,37 +1,46 @@ /obj/effect/proc_holder/spell/targeted/touch - var/hand_path = "/obj/item/melee/touch_attack" + var/hand_path = /obj/item/melee/touch_attack var/obj/item/melee/touch_attack/attached_hand = null invocation_type = "none" //you scream on connecting, not summoning include_user = 1 range = -1 -/obj/effect/proc_holder/spell/targeted/touch/Click(mob/user = usr) - if(attached_hand) - qdel(attached_hand) +/obj/effect/proc_holder/spell/targeted/touch/proc/remove_hand(recharge = FALSE) + QDEL_NULL(attached_hand) + if(recharge) charge_counter = charge_max - attached_hand = null - to_chat(user, "You draw the power out of your hand.") - return FALSE - ..() + +/obj/effect/proc_holder/spell/targeted/touch/proc/on_hand_destroy(obj/item/melee/touch_attack/hand) + if(hand != attached_hand) + CRASH("Incorrect touch spell hand.") + //Start recharging. + attached_hand = null + recharging = TRUE + action.UpdateButtonIcon() /obj/effect/proc_holder/spell/targeted/touch/cast(list/targets,mob/user = usr) + if(!QDELETED(attached_hand)) + remove_hand(TRUE) + to_chat(user, "You draw the power out of your hand.") + return + for(var/mob/living/carbon/C in targets) if(!attached_hand) - if(!ChargeHand(C)) - return FALSE - while(attached_hand) - charge_counter = 0 - stoplag(1) + if(ChargeHand(C)) + recharging = FALSE + return -/obj/effect/proc_holder/spell/targeted/touch/can_cast(mob/user = usr) - return ..() && attached_hand +/obj/effect/proc_holder/spell/targeted/touch/charge_check(mob/user,silent = FALSE) + if(!QDELETED(attached_hand)) //Charge doesn't matter when putting the hand away. + return TRUE + else + return ..() /obj/effect/proc_holder/spell/targeted/touch/proc/ChargeHand(mob/living/carbon/user) attached_hand = new hand_path(src) + attached_hand.attached_spell = src if(!user.put_in_hands(attached_hand)) - qdel(attached_hand) - charge_counter = charge_max - attached_hand = null + remove_hand(TRUE) to_chat(user, "Your hands are full!") return FALSE to_chat(user, "You channel the power of the spell to your hand.") @@ -41,7 +50,7 @@ /obj/effect/proc_holder/spell/targeted/touch/disintegrate name = "Disintegrate" desc = "This spell charges your hand with vile energy that can be used to violently explode victims." - hand_path = "/obj/item/melee/touch_attack/disintegrate" + hand_path = /obj/item/melee/touch_attack/disintegrate school = "evocation" charge_max = 600 @@ -53,7 +62,7 @@ /obj/effect/proc_holder/spell/targeted/touch/flesh_to_stone name = "Flesh to Stone" desc = "This spell charges your hand with the power to turn victims into inert statues for a long period of time." - hand_path = "/obj/item/melee/touch_attack/fleshtostone" + hand_path = /obj/item/melee/touch_attack/fleshtostone school = "transmutation" charge_max = 600