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

Ninja invisibility rework (And consolidates /datum/action cooldowns to a single place) #11628

Closed
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
119 changes: 69 additions & 50 deletions code/datums/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@
var/button_icon_state = "default" //And this is the state for the action icon
var/mob/owner

var/has_cooldown_timer = FALSE
/// The time at which the cooldown timer will end
VAR_PRIVATE/cooldown_timer_end = 0
/// Overlay currently applied to this action
VAR_PRIVATE/mutable_appearance/timer_overlay

/// Timer icon file
VAR_PROTECTED/timer_icon = 'icons/effects/cooldown.dmi'
/// Icon state for the timer icon
VAR_PROTECTED/timer_icon_state_active = "second"

/// Set this to disable auto-processing on cooldown for things that add custom behaviours like spells.
/// Avoid this if possible.
var/override_cooldown_behaviour = FALSE

/datum/action/New(Target)
link_to(Target)
Expand Down Expand Up @@ -66,9 +78,6 @@
M.client.screen += button
button.locked = M.client.prefs.read_player_preference(/datum/preference/toggle/buttons_locked) || button.id ? M.client.prefs.action_buttons_screen_locs["[name]_[button.id]"] : FALSE //even if it's not defaultly locked we should remember we locked it before
button.moved = button.id ? M.client.prefs.action_buttons_screen_locs["[name]_[button.id]"] : FALSE
var/obj/effect/proc_holder/spell/spell_proc_holder = button.linked_action.target
if(istype(spell_proc_holder) && spell_proc_holder.text_overlay)
M.client.images += spell_proc_holder.text_overlay
M.update_action_buttons()
else
Remove(owner)
Expand Down Expand Up @@ -101,6 +110,8 @@
/datum/action/proc/IsAvailable()
if(!owner)
return FALSE
if (cooldown_timer_end && world.time < cooldown_timer_end)
return FALSE
if((check_flags & AB_CHECK_HANDS_BLOCKED) && HAS_TRAIT(owner, TRAIT_HANDS_BLOCKED))
return FALSE
if((check_flags & AB_CHECK_INCAPACITATED) && HAS_TRAIT(owner, TRAIT_INCAPACITATED))
Expand All @@ -113,6 +124,9 @@
return FALSE
return TRUE

/datum/action/process(delta_time)
UpdateButtonIcon(TRUE, FALSE)

/datum/action/proc/UpdateButtonIcon(status_only = FALSE, force = FALSE)
if(!button)
return FALSE
Expand All @@ -132,8 +146,13 @@
if(button.icon_state != background_icon_state)
button.icon_state = background_icon_state
ApplyIcon(button, force)
if(cooldown_timer_end)
if (cooldown_timer_end >= world.time)
update_cooldown_icon()
else
finish_cooldown()
if(!IsAvailable())
button.color = has_cooldown_timer ? rgb(219, 219, 219, 255) : transparent_when_unavailable ? rgb(128,0,0,128) : rgb(128,0,0)
button.color = cooldown_timer_end ? rgb(219, 219, 219, 255) : transparent_when_unavailable ? rgb(128,0,0,128) : rgb(128,0,0)
else
button.color = rgb(255,255,255,255)
return TRUE
Expand All @@ -143,11 +162,53 @@
current_button.cut_overlays()
current_button.add_overlay(mutable_appearance(icon_icon, button_icon_state))
current_button.button_icon_state = button_icon_state
update_cooldown_icon(TRUE)

/datum/action/proc/OnUpdatedIcon()
SIGNAL_HANDLER
UpdateButtonIcon()

//===Timer animation===

/datum/action/proc/set_cooldown(duration)
if(!button)
return

cooldown_timer_end = world.time + duration
if (!timer_overlay)
timer_overlay = mutable_appearance(timer_icon, timer_icon_state_active)
timer_overlay.alpha = 180
timer_overlay.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
timer_overlay.maptext_width = 64
timer_overlay.maptext_height = 64
timer_overlay.maptext_x = -8
timer_overlay.maptext_y = -6

UpdateButtonIcon(TRUE, FALSE)

if (!override_cooldown_behaviour)
START_PROCESSING(SSprocessing, src)

/datum/action/proc/update_cooldown_icon(force = FALSE)
if(!button || !timer_overlay)
return
var/new_maptext = "<center><span class='chatOverhead' style='font-weight: bold;color: #eeeeee;'>[FLOOR((cooldown_timer_end - world.time)/10, 1)]</span></center>"
if (new_maptext != timer_overlay.maptext || force)
button.cut_overlay(timer_overlay)
timer_overlay.maptext = new_maptext
button.add_overlay(timer_overlay)

/datum/action/proc/finish_cooldown()
if(!button || !cooldown_timer_end)
return
button.cut_overlay(timer_overlay)
QDEL_NULL(timer_overlay)
cooldown_timer_end = null
UpdateButtonIcon(TRUE, FALSE)

if (!override_cooldown_behaviour)
STOP_PROCESSING(SSprocessing, src)

//Presets for item actions
/datum/action/item_action
check_flags = AB_CHECK_HANDS_BLOCKED|AB_CHECK_INCAPACITATED|AB_CHECK_CONSCIOUS
Expand Down Expand Up @@ -189,6 +250,7 @@
I.plane = FLOAT_PLANE //^ what that guy said
current_button.cut_overlays()
current_button.add_overlay(I)
update_cooldown_icon(TRUE)
I.layer = old_layer
I.plane = old_plane
current_button.appearance_cache = I.appearance
Expand Down Expand Up @@ -587,6 +649,7 @@
/datum/action/spell_action
check_flags = NONE
background_icon_state = "bg_spell"
override_cooldown_behaviour = TRUE

/datum/action/spell_action/New(Target)
..()
Expand Down Expand Up @@ -659,51 +722,6 @@
/datum/action/innate/proc/Deactivate()
return

//Preset for an action with a cooldown

/datum/action/cooldown
check_flags = NONE
transparent_when_unavailable = FALSE
var/cooldown_time = 0
var/next_use_time = 0

/datum/action/cooldown/New()
..()
button.maptext = ""
button.maptext_x = 8
button.maptext_y = 0
button.maptext_width = 24
button.maptext_height = 12

/datum/action/cooldown/IsAvailable()
return next_use_time <= world.time

/datum/action/cooldown/proc/StartCooldown()
next_use_time = world.time + cooldown_time
button.maptext = MAPTEXT("<b>[round(cooldown_time/10, 0.1)]</b>")
UpdateButtonIcon()
START_PROCESSING(SSfastprocess, src)

/datum/action/cooldown/process()
if(!owner)
button.maptext = ""
return PROCESS_KILL
var/timeleft = max(next_use_time - world.time, 0)
if(timeleft == 0)
button.maptext = ""
UpdateButtonIcon()
return PROCESS_KILL
else
button.maptext = MAPTEXT("<b>[round(timeleft/10, 0.1)]</b>")

/datum/action/cooldown/Grant(mob/M)
..()
if(owner)
UpdateButtonIcon()
if(next_use_time > world.time)
START_PROCESSING(SSfastprocess, src)


//Stickmemes
/datum/action/item_action/stickmen
name = "Summon Stick Minions"
Expand Down Expand Up @@ -816,6 +834,7 @@
target.plane = FLOAT_PLANE //^ what that guy said
current_button.cut_overlays()
current_button.add_overlay(target)
update_cooldown_icon(TRUE)
target.layer = old_layer
target.plane = old_plane
current_button.appearance_cache = target.appearance
30 changes: 7 additions & 23 deletions code/modules/mob/living/carbon/human/species_types/psyphoza.dm
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,9 @@
if(!(locate(/datum/action/change_psychic_auto) in owner.actions))
auto_action = new(src)
auto_action.Grant(M)
///Start auto timer
addtimer(CALLBACK(src, PROC_REF(auto_sense)), auto_cooldown)

/datum/action/item_action/organ_action/psychic_highlight/IsAvailable()
if(has_cooldown_timer)
return FALSE
return ..()

/datum/action/item_action/organ_action/psychic_highlight/Trigger()
. = ..()
if(has_cooldown_timer || !owner || !check_head())
if(!..() || !owner || !check_head())
return
//Reveal larger area of sense
dim_overlay()
Expand All @@ -209,14 +201,8 @@
if(BS)
for(var/mob/living/L in urange(9, owner, 1))
BS.highlight_object(L, "mob", L.dir)
has_cooldown_timer = TRUE
UpdateButtonIcon()
addtimer(CALLBACK(src, PROC_REF(finish_cooldown)), cooldown + sense_time)

/datum/action/item_action/organ_action/psychic_highlight/UpdateButtonIcon(status_only = FALSE, force = FALSE)
. = ..()
if(!IsAvailable())
button.color = transparent_when_unavailable ? rgb(128,0,0,128) : rgb(128,0,0) //Overwrite this line from the original to support my fucked up use
set_cooldown(cooldown + sense_time)
return TRUE

/datum/action/item_action/organ_action/psychic_highlight/proc/remove()
owner?.clear_fullscreen("psychic_highlight")
Expand All @@ -231,14 +217,11 @@
if(!QDELETED(auto_action))
qdel(auto_action)

/datum/action/item_action/organ_action/psychic_highlight/proc/auto_sense()
/datum/action/item_action/organ_action/psychic_highlight/finish_cooldown()
. = ..()
// Auto-retrigger
if(auto_sense)
Trigger()
addtimer(CALLBACK(src, PROC_REF(auto_sense)), auto_cooldown)

/datum/action/item_action/organ_action/psychic_highlight/proc/finish_cooldown()
has_cooldown_timer = FALSE
UpdateButtonIcon()

//Allows user to see images through walls - mostly for if this action is added to something without xray
/datum/action/item_action/organ_action/psychic_highlight/proc/toggle_eyes_fowards()
Expand Down Expand Up @@ -464,6 +447,7 @@
/datum/action/change_psychic_auto/Trigger()
. = ..()
psychic_action?.auto_sense = !psychic_action?.auto_sense
psychic_action?.Trigger()
UpdateButtonIcon()

/datum/action/change_psychic_auto/IsAvailable()
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/simple_animal/hostile/goose.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
var/vomiting = FALSE
var/vomitCoefficient = 1
var/vomitTimeBonus = 0
var/datum/action/cooldown/vomit/goosevomit
var/datum/action/vomit/goosevomit

/mob/living/simple_animal/hostile/retaliate/goose/vomit/Initialize(mapload)
. = ..()
Expand Down Expand Up @@ -178,14 +178,13 @@
if (tasty)
feed(tasty)

/datum/action/cooldown/vomit
/datum/action/vomit
name = "Vomit"
check_flags = AB_CHECK_CONSCIOUS
button_icon_state = "vomit"
icon_icon = 'icons/mob/animal.dmi'
cooldown_time = 250

/datum/action/cooldown/vomit/Trigger()
/datum/action/vomit/Trigger()
if(!..())
return FALSE
if(!istype(owner, /mob/living/simple_animal/hostile/retaliate/goose/vomit))
Expand All @@ -195,6 +194,7 @@
vomit.vomit_prestart(vomit.vomitTimeBonus + 25)
vomit.vomitCoefficient = 1
vomit.vomitTimeBonus = 0
set_cooldown(25 SECONDS)
return TRUE

#undef GOOSE_SATIATED
9 changes: 4 additions & 5 deletions code/modules/mob/living/simple_animal/hostile/space_dragon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
/// Whether space dragon is swallowing a body currently
var/is_swallowing = FALSE
/// The cooldown ability to use wing gust
var/datum/action/cooldown/gust_attack/gust
var/datum/action/gust_attack/gust
/// The ability to make your sprite smaller
var/datum/action/small_sprite/space_dragon/small_sprite
/// The color of the space dragon.
Expand Down Expand Up @@ -456,15 +456,14 @@
var/link = FOLLOW_LINK(S, src)
to_chat(S, "[link] [rendered]")

/datum/action/cooldown/gust_attack
/datum/action/gust_attack
name = "Gust Attack"
desc = "Use your wings to knock back foes with gusts of air, pushing them away and stunning them. Using this too often will leave you vulnerable for longer periods of time."
background_icon_state = "bg_default"
icon_icon = 'icons/hud/actions/actions_space_dragon.dmi'
button_icon_state = "gust_attack"
cooldown_time = 5 SECONDS // the ability takes up around 2-3 seconds

/datum/action/cooldown/gust_attack/Trigger()
/datum/action/gust_attack/Trigger()
if(!..() || !istype(owner, /mob/living/simple_animal/hostile/space_dragon))
return FALSE
var/mob/living/simple_animal/hostile/space_dragon/S = owner
Expand All @@ -474,7 +473,7 @@
S.icon_state = "spacedragon_gust"
S.update_dragon_overlay()
S.useGust(TRUE)
StartCooldown()
set_cooldown(5 SECONDS)
return TRUE

#undef DARKNESS_THRESHOLD
10 changes: 10 additions & 0 deletions code/modules/ninja/energy_katana.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@

/obj/item/energy_katana/afterattack(atom/target, mob/user, proximity_flag, click_parameters)
. = ..()
if (ishuman(user))
var/mob/living/carbon/human/human_user = user
if(istype(human_user.wear_suit, /obj/item/clothing/suit/space/space_ninja))
var/obj/item/clothing/suit/space/space_ninja/ninja_suit = human_user.wear_suit
if (ninja_suit.stealth)
ninja_suit.cancel_stealth()
else
return
else
return
if(dash_toggled)
jaunt.Teleport(user, target)
if(proximity_flag && (isobj(target) || issilicon(target)))
Expand Down
10 changes: 9 additions & 1 deletion code/modules/ninja/suit/n_suit_verbs/ninja_stealth.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Contents:

*/

#define STEALTH_COOLDOWN 30 SECONDS

/obj/item/clothing/suit/space/space_ninja/proc/toggle_stealth()
var/mob/living/carbon/human/U = affecting
Expand All @@ -14,6 +15,10 @@ Contents:
if(stealth)
cancel_stealth()
else
var/datum/action/item_action/ninja_stealth/stealth_action = locate() in actions
if (!stealth_action.IsAvailable())
U.balloon_alert(U, "Stealth not ready.")
return
if(cell.charge <= 0)
to_chat(U, "<span class='warning'>You don't have enough power to enable Stealth!</span>")
return
Expand All @@ -32,12 +37,15 @@ Contents:
animate(U, alpha = 255, time = 15)
U.visible_message("<span class='warning'>[U.name] appears from thin air!</span>", \
"<span class='notice'>You are now visible.</span>")
var/datum/action/item_action/ninja_stealth/stealth_action = locate() in actions
stealth_action.set_cooldown(STEALTH_COOLDOWN)
return 1
return 0


/obj/item/clothing/suit/space/space_ninja/proc/stealth()
if(!s_busy)
toggle_stealth()
else
to_chat(affecting, "<span class='danger'>Stealth does not appear to work!</span>")

#undef STEALTH_COOLDOWN
Loading
Loading