From 6fef7fefeac829ba26df2a856f7f46e8570d91dd Mon Sep 17 00:00:00 2001 From: AnturK Date: Wed, 25 Mar 2015 21:44:19 +0100 Subject: [PATCH] - adds LoS obstacle check - some sanity checks - Removes the blowback, now the spell just fizzles harmlessly --- code/datums/spell.dm | 29 ++++++++++++++++++++++++++++- code/datums/spells/lightning.dm | 25 +++++++++++++------------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/code/datums/spell.dm b/code/datums/spell.dm index 71a8b0db2df..587d5f1c646 100644 --- a/code/datums/spell.dm +++ b/code/datums/spell.dm @@ -1,3 +1,6 @@ +#define TARGET_CLOSEST 1 +#define TARGET_RANDOM 2 + /obj/effect/proc_holder var/panel = "Debug"//What panel the proc holder needs to go on. @@ -246,6 +249,7 @@ var/list/spells = typesof(/obj/effect/proc_holder/spell) //needed for the badmin var/target_ignore_prev = 1 //only important if max_targets > 1, affects if the spell can be cast multiple times at one person from one cast var/include_user = 0 //if it includes usr in the target list var/random_target = 0 // chooses random viable target instead of asking the caster + var/random_target_priority = TARGET_CLOSEST // if random_target is enabled how it will pick the target /obj/effect/proc_holder/spell/aoe_turf //affects all turfs in view or range (depends) var/inner_radius = -1 //for all your ring spell needs @@ -274,7 +278,18 @@ var/list/spells = typesof(/obj/effect/proc_holder/spell) //needed for the badmin if(!random_target) M = input("Choose the target for the spell.", "Targeting") as mob in possible_targets else - M = pick(possible_targets) + switch(random_target_priority) + if(TARGET_RANDOM) + M = pick(possible_targets) + if(TARGET_CLOSEST) + for(var/mob/living/L in possible_targets) + if(M) + if(get_dist(user,L) < get_dist(user,M)) + if(los_check(user,L)) + M = L + else + if(los_check(user,L)) + M = L if(M in view_or_range(range, user, selection_type)) targets += M else @@ -320,4 +335,16 @@ var/list/spells = typesof(/obj/effect/proc_holder/spell) //needed for the badmin /obj/effect/proc_holder/spell/proc/can_be_cast_by(mob/caster) if((human_req || clothes_req) && !ishuman(caster)) return 0 + return 1 + +/obj/effect/proc_holder/spell/targeted/proc/los_check(mob/A,mob/B) + //Checks for obstacles from A to B + var/obj/dummy = new(A.loc) + dummy.pass_flags |= PASSTABLE + for(var/turf/turf in getline(A,B)) + for(var/atom/movable/AM in turf) + if(!AM.CanPass(dummy,turf,1)) + qdel(dummy) + return 0 + qdel(dummy) return 1 \ No newline at end of file diff --git a/code/datums/spells/lightning.dm b/code/datums/spells/lightning.dm index bda59d916b5..197e72fcda4 100644 --- a/code/datums/spells/lightning.dm +++ b/code/datums/spells/lightning.dm @@ -13,12 +13,6 @@ var/energy = 0 var/ready = 0 -/obj/effect/bolt - name = "Lightning bolt" - icon = 'icons/effects/effects.dmi' - icon_state = "lightning" - luminosity = 3 - /obj/effect/proc_holder/spell/targeted/lightning/Click() if(!ready) if(cast_check()) @@ -39,9 +33,15 @@ if(energy >= 100 && ready) Discharge() +/obj/effect/proc_holder/spell/targeted/lightning/revert_cast(mob/user = usr) + user << "No target found in range." + ready = 0 + energy = 0 + ..() + /obj/effect/proc_holder/spell/targeted/lightning/proc/Discharge(mob/user = usr) var/mob/living/M = user - M.electrocute_act(25,"Lightning Bolt") + //M.electrocute_act(25,"Lightning Bolt") M << "You lose control over the spell." energy = 0 ready = 0 @@ -49,14 +49,13 @@ /obj/effect/proc_holder/spell/targeted/lightning/cast(list/targets, mob/user = usr) - if(!targets.len) - user << "No target found in range." - return var/mob/living/carbon/target = targets[1] - if(!(target in oview(range))) + if(get_dist(user,target)>range) user << "They are too far away!" + ready = 0 + energy = 0 return user.Beam(target,icon_state="lightning",icon='icons/effects/effects.dmi',time=5) @@ -81,9 +80,11 @@ current.electrocute_act(25,"Lightning Bolt") var/list/possible_targets = new for(var/mob/living/M in view_or_range(range,target,"view")) - if(user == M || target == M) // || origin == M ? Not sure double shockings is good or not + if(user == M || target == M && los_check(current,M)) // || origin == M ? Not sure double shockings is good or not continue possible_targets += M + if(!possible_targets.len) + return var/mob/living/next = pick(possible_targets) if(next) Bolt(current,next,bolt_energy-6,user) // 5 max bounces \ No newline at end of file