mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 02:34:00 +00:00
Refactors duplicate parry code
This commit is contained in:
@@ -13,16 +13,7 @@
|
||||
|
||||
/obj/item/weapon/material/sword/handle_shield(mob/user, var/damage, atom/damage_source = null, mob/attacker = null, var/def_zone = null, var/attack_text = "the attack")
|
||||
|
||||
//parry only melee attacks
|
||||
if(istype(damage_source, /obj/item/projectile) || (attacker && get_dist(user, attacker) > 1) || user.incapacitated())
|
||||
return 0
|
||||
|
||||
//block as long as they are not directly behind us
|
||||
var/bad_arc = reverse_direction(user.dir) //arc of directions from which we cannot block
|
||||
if(!check_shield_arc(user, bad_arc, damage_source, attacker))
|
||||
return 0
|
||||
|
||||
if(prob(50))
|
||||
if(default_parry_check(user, attacker, damage_source) && prob(50))
|
||||
user.visible_message("<span class='danger'>\The [user] parries [attack_text] with \the [src]!</span>")
|
||||
playsound(user.loc, 'sound/weapons/punchmiss.ogg', 50, 1)
|
||||
return 1
|
||||
|
||||
@@ -73,19 +73,7 @@
|
||||
|
||||
//Allow a small chance of parrying melee attacks when wielded - maybe generalize this to other weapons someday
|
||||
/obj/item/weapon/material/twohanded/handle_shield(mob/user, var/damage, atom/damage_source = null, mob/attacker = null, var/def_zone = null, var/attack_text = "the attack")
|
||||
if(!wielded)
|
||||
return 0
|
||||
|
||||
//parry only melee attacks
|
||||
if(istype(damage_source, /obj/item/projectile) || (attacker && get_dist(user, attacker) > 1) || user.incapacitated())
|
||||
return 0
|
||||
|
||||
//block as long as they are not directly behind us
|
||||
var/bad_arc = reverse_direction(user.dir) //arc of directions from which we cannot block
|
||||
if(!check_shield_arc(user, bad_arc, damage_source, attacker))
|
||||
return 0
|
||||
|
||||
if(prob(15))
|
||||
if(wielded && default_parry_check(user, attacker, damage_source) && prob(15))
|
||||
user.visible_message("<span class='danger'>\The [user] parries [attack_text] with \the [src]!</span>")
|
||||
playsound(user.loc, 'sound/weapons/punchmiss.ogg', 50, 1)
|
||||
return 1
|
||||
|
||||
@@ -152,19 +152,7 @@
|
||||
icon_state = initial(icon_state)
|
||||
|
||||
/obj/item/weapon/melee/energy/sword/handle_shield(mob/user, var/damage, atom/damage_source = null, mob/attacker = null, var/def_zone = null, var/attack_text = "the attack")
|
||||
if(!active)
|
||||
return 0
|
||||
|
||||
//parry only melee attacks
|
||||
if(istype(damage_source, /obj/item/projectile) || (attacker && get_dist(user, attacker) > 1) || user.incapacitated())
|
||||
return 0
|
||||
|
||||
//block as long as they are not directly behind us
|
||||
var/bad_arc = reverse_direction(user.dir) //arc of directions from which we cannot block
|
||||
if(!check_shield_arc(user, bad_arc, damage_source, attacker))
|
||||
return 0
|
||||
|
||||
if(prob(50))
|
||||
if(active && default_parry_check(user, attacker, damage_source) && prob(50))
|
||||
user.visible_message("<span class='danger'>\The [user] parries [attack_text] with \the [src]!</span>")
|
||||
|
||||
var/datum/effect/effect/system/spark_spread/spark_system = new /datum/effect/effect/system/spark_spread()
|
||||
|
||||
@@ -1,3 +1,34 @@
|
||||
//** Shield Helpers
|
||||
//These are shared by various items that have shield-like behaviour
|
||||
|
||||
//bad_arc is the ABSOLUTE arc of directions from which we cannot block. If you want to fix it to e.g. the user's facing you will need to rotate the dirs yourself.
|
||||
/proc/check_shield_arc(mob/user, var/bad_arc, atom/damage_source = null, mob/attacker = null)
|
||||
//check attack direction
|
||||
var/attack_dir = 0 //direction from the user to the source of the attack
|
||||
if(istype(damage_source, /obj/item/projectile))
|
||||
var/obj/item/projectile/P = damage_source
|
||||
attack_dir = get_dir(get_turf(user), P.starting)
|
||||
else if(attacker)
|
||||
attack_dir = get_dir(get_turf(user), get_turf(attacker))
|
||||
else if(damage_source)
|
||||
attack_dir = get_dir(get_turf(user), get_turf(damage_source))
|
||||
|
||||
if(!(attack_dir && (attack_dir & bad_arc)))
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/proc/default_parry_check(mob/user, mob/attacker, atom/damage_source)
|
||||
//parry only melee attacks
|
||||
if(istype(damage_source, /obj/item/projectile) || (attacker && get_dist(user, attacker) > 1) || user.incapacitated())
|
||||
return 0
|
||||
|
||||
//block as long as they are not directly behind us
|
||||
var/bad_arc = reverse_direction(user.dir) //arc of directions from which we cannot block
|
||||
if(!check_shield_arc(user, bad_arc, damage_source, attacker))
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
/obj/item/weapon/shield
|
||||
name = "shield"
|
||||
var/base_block_chance = 50
|
||||
@@ -119,28 +150,6 @@
|
||||
add_fingerprint(user)
|
||||
return
|
||||
|
||||
//** Shield Helpers
|
||||
//This is here in case it is useful for things like energy swords that want to pretend they are shields
|
||||
|
||||
//bad_arc is the ABSOLUTE arc of directions from which we cannot block
|
||||
/obj/item/proc/check_shield_arc(mob/user, var/bad_arc, atom/damage_source = null, mob/attacker = null)
|
||||
//check attack direction
|
||||
var/attack_dir = 0 //direction from the user to the source of the attack
|
||||
if(istype(damage_source, /obj/item/projectile))
|
||||
var/obj/item/projectile/P = damage_source
|
||||
attack_dir = get_dir(get_turf(user), P.starting)
|
||||
else if(attacker)
|
||||
attack_dir = get_dir(get_turf(user), get_turf(attacker))
|
||||
else if(damage_source)
|
||||
attack_dir = get_dir(get_turf(user), get_turf(damage_source))
|
||||
|
||||
world << "attack_dir: [print_dir(attack_dir)]"
|
||||
|
||||
if(!(attack_dir && (attack_dir & bad_arc)))
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
/obj/item/weapon/cloaking_device
|
||||
name = "cloaking device"
|
||||
|
||||
@@ -253,19 +253,7 @@
|
||||
item_color = "red"
|
||||
|
||||
/obj/item/weapon/holo/esword/handle_shield(mob/user, var/damage, atom/damage_source = null, mob/attacker = null, var/def_zone = null, var/attack_text = "the attack")
|
||||
if(!active)
|
||||
return 0
|
||||
|
||||
//parry only melee holo attacks
|
||||
if(!istype(damage_source, /obj/item/weapon/holo) || (attacker && get_dist(user, attacker) > 1) || user.incapacitated())
|
||||
return 0
|
||||
|
||||
//block as long as they are not directly behind us
|
||||
var/bad_arc = reverse_direction(user.dir) //arc of directions from which we cannot block
|
||||
if(!check_shield_arc(user, bad_arc, damage_source, attacker))
|
||||
return 0
|
||||
|
||||
if(prob(50))
|
||||
if(active && default_parry_check(user, attacker, damage_source) && prob(50))
|
||||
user.visible_message("<span class='danger'>\The [user] parries [attack_text] with \the [src]!</span>")
|
||||
|
||||
var/datum/effect/effect/system/spark_spread/spark_system = new /datum/effect/effect/system/spark_spread()
|
||||
|
||||
Reference in New Issue
Block a user