Fix some dashes breaking permanently (heirophant staff and ninja sword) (#68195)

* Fix dashing sometimes breaking, with additional code improvement to go along with it.
This commit is contained in:
MrMelbert
2022-07-08 12:45:28 -04:00
committed by GitHub
parent 4207c735d5
commit 4e96e7750d
2 changed files with 56 additions and 50 deletions
+42 -27
View File
@@ -1,34 +1,36 @@
/// Actions that you can use to dash (teleport) to places in view.
/datum/action/innate/dash
name = "Dash"
desc = "Teleport to the targeted location."
icon_icon = 'icons/mob/actions/actions_items.dmi'
button_icon_state = "jetboot"
/// How many dash charges do we have?
var/current_charges = 1
/// How many dash charges can we hold?
var/max_charges = 1
var/charge_rate = 250
var/obj/item/dashing_item
/// How long does it take to get a dash charge back?
var/charge_rate = 25 SECONDS
/// What sound do we play on dash?
var/dash_sound = 'sound/magic/blink.ogg'
/// What sound do we play on recharge?
var/recharge_sound = 'sound/magic/charge.ogg'
/// What effect does our beam use?
var/beam_effect = "blur"
/// How long does our beam last?
var/beam_length = 2 SECONDS
/// What effect should we play when we phase in (at the teleport target turf)
var/phasein = /obj/effect/temp_visual/dir_setting/ninja/phase
/// What effect should we play when we phase out (at the source turf)
var/phaseout = /obj/effect/temp_visual/dir_setting/ninja/phase/out
/datum/action/innate/dash/Grant(mob/user, obj/dasher)
. = ..()
dashing_item = dasher
/datum/action/innate/dash/Destroy()
dashing_item = null
return ..()
/datum/action/innate/dash/IsAvailable()
if(current_charges > 0)
return TRUE
else
return FALSE
return ..() && (current_charges > 0)
/datum/action/innate/dash/Activate()
var/obj/item/dashing_item = target
if(!istype(dashing_item))
return
dashing_item.attack_self(owner) //Used to toggle dash behavior in the dashing item
/// Teleports user to target using do_teleport. Returns TRUE if teleport successful, FALSE otherwise.
@@ -39,23 +41,36 @@
var/turf/current_turf = get_turf(user)
var/turf/target_turf = get_turf(target)
if(target in view(user.client.view, user))
if(!do_teleport(user, target_turf, no_effects = TRUE))
user.balloon_alert(user, "dash blocked by location!")
return FALSE
var/obj/spot1 = new phaseout(current_turf, user.dir)
var/obj/spot2 = new phasein(target_turf, user.dir)
spot1.Beam(spot2,beam_effect, time = beam_length)
playsound(target_turf, dash_sound, 25, TRUE)
current_charges--
owner.update_action_buttons_icon()
addtimer(CALLBACK(src, .proc/charge), charge_rate)
return TRUE
if(!(target in view(user.client.view, user)))
user.balloon_alert(user, "out of view!")
return FALSE
return FALSE
if(!do_teleport(user, target_turf, no_effects = TRUE))
user.balloon_alert(user, "dash blocked!")
return FALSE
// Note: It's possible do_teleport, for whatever reason,
// caused our owner to be unassigned by this point.
// (Such as dropping our item after landing.)
var/obj/spot_one = new phaseout(current_turf, user.dir)
var/obj/spot_two = new phasein(target_turf, user.dir)
spot_one.Beam(spot_two, beam_effect, time = beam_length)
playsound(target_turf, dash_sound, 25, TRUE)
current_charges--
addtimer(CALLBACK(src, .proc/charge), charge_rate)
owner?.update_action_buttons_icon()
return TRUE
/// Callback for [/proc/teleport] to increment our charges after use.
/datum/action/innate/dash/proc/charge()
current_charges = clamp(current_charges + 1, 0, max_charges)
var/obj/item/dashing_item = target
if(!istype(dashing_item))
return
if(recharge_sound)
playsound(dashing_item, recharge_sound, 50, TRUE)
+14 -23
View File
@@ -20,33 +20,26 @@
var/dist = get_dist(user, target)
if(dist > HIEROPHANT_BLINK_RANGE)
user.balloon_alert(user, "destination out of range!")
return
return FALSE
var/turf/target_turf = get_turf(target)
if(target_turf.is_blocked_turf_ignore_climbable())
user.balloon_alert(user, "destination blocked!")
return
return FALSE
. = ..()
if(!current_charges)
var/obj/item/hierophant_club/club = src.target
if(istype(club))
club.blink_charged = FALSE
club.update_appearance()
var/obj/item/hierophant_club/club = target
if(!istype(club))
return
club.update_appearance(UPDATE_ICON_STATE)
/datum/action/innate/dash/hierophant/charge()
. = ..()
var/obj/item/hierophant_club/club = target
if(istype(club))
club.blink_charged = TRUE
club.update_appearance()
current_charges = clamp(current_charges + 1, 0, max_charges)
if(recharge_sound)
playsound(dashing_item, recharge_sound, 50, TRUE)
if(!owner)
if(!istype(club))
return
owner.update_action_buttons_icon()
to_chat(owner, span_notice("[src] now has [current_charges]/[max_charges] charges."))
club.update_appearance(UPDATE_ICON_STATE)
/obj/item/hierophant_club
name = "hierophant club"
@@ -74,16 +67,14 @@
var/datum/action/innate/dash/hierophant/blink
/// Whether the blink ability is activated. IF TRUE, left clicking a location will blink to it. If FALSE, this is disabled.
var/blink_activated = TRUE
/// Whether the blink is charged. Set and unset by the blink action. Used as part of setting the appropriate icon states.
var/blink_charged = TRUE
/obj/item/hierophant_club/Initialize(mapload)
. = ..()
blink = new(src)
/obj/item/hierophant_club/Destroy()
. = ..()
QDEL_NULL(blink)
return ..()
/obj/item/hierophant_club/ComponentInitialize()
. = ..()
@@ -120,7 +111,7 @@
blink.teleport(user, target)
/obj/item/hierophant_club/update_icon_state()
icon_state = inhand_icon_state = "hierophant_club[blink_charged ? "_ready":""][(!QDELETED(beacon)) ? "":"_beacon"]"
icon_state = inhand_icon_state = "hierophant_club[blink?.current_charges > 0 ? "_ready":""][(!QDELETED(beacon)) ? "":"_beacon"]"
return ..()
/obj/item/hierophant_club/ui_action_click(mob/user, action)