diff --git a/code/_onclick/hud/screen_objects/clickdelay.dm b/code/_onclick/hud/screen_objects/clickdelay.dm new file mode 100644 index 0000000000..ec8f13329b --- /dev/null +++ b/code/_onclick/hud/screen_objects/clickdelay.dm @@ -0,0 +1,51 @@ +/obj/screen/action_bar + +/obj/screen/action_bar/Destroy() + STOP_PROCESSING(SSfastprocess, src) + return ..() + +/obj/screen/action_bar/proc/mark_dirty() + var/mob/living/L = hud?.mymob + if(L?.client && update_to_mob(L)) + START_PROCESSING(SSfastprocess, src) + +/obj/screen/action_bar/process() + var/mob/living/L = hud?.mymob + if(!L?.client || !update_to_mob(L)) + return PROCESS_KILL + +/obj/screen/action_bar/proc/update_to_mob(mob/living/L) + return FALSE + +/datum/hud/var/obj/screen/action_bar/clickdelay + +/obj/screen/action_bar/clickdelay + name = "click delay" + icon = 'icons/effects/progessbar.dmi' + icon_state = "prog_bar_100" + +/obj/screen/action_bar/clickdelay/update_to_mob(mob/living/L) + var/estimated = L.EstimatedNextActionTime() + var/diff = L.last_action - estimated + var/left = estimated - world.time + if(left < 0 || diff < 0) + icon_state = "prog_bar_100" + return FALSE + icon_state = "prog_bar_[round(clamp((left/diff) * 100, 0, 100), 5)]" + return TRUE + +/datum/hud/var/obj/screen/action_bar/resistdelay/resistdelay + +/obj/screen/action_bar/resistdelay + name = "resist delay" + icon = 'icons/effects/progessbar.dmi' + icon_state = "prog_bar_100" + +/obj/screen/clickdelay/proc/update_to_mob(mob/living/L) + var/diff = L.next_resist - L.last_resist + var/left = L.next_resist - world.time + if(left < 0 || diff < 0) + icon_state = "prog_bar_100" + return FALSE + icon_state = "prog_bar[round(clamp((left/diff) * 100, 0, 100), 5)]" + return TRUE diff --git a/code/modules/mob/clickdelay.dm b/code/modules/mob/clickdelay.dm index 5cecf70cfd..09bd24170a 100644 --- a/code/modules/mob/clickdelay.dm +++ b/code/modules/mob/clickdelay.dm @@ -65,7 +65,7 @@ var/attack_speed = unarmed_attack_speed var/obj/item/I = get_active_held_item() if(I) - attack_speed = I.attack_speed + attack_speed = I.GetEstimatedAttackSpeed() return max(next_action, last_action + attack_speed) /** @@ -156,3 +156,9 @@ */ /obj/item/proc/ApplyAttackCooldown(mob/user, atom/target) user.DelayNextAction(attack_unwieldlyness, clickdelay_mod_bypass, FALSE) + +/** + * Get estimated time that a user has to not attack for to use us + */ +/obj/item/proc/GetEstimatedAttackSpeed() + return attack_speed diff --git a/code/modules/projectiles/ammunition/_firing.dm b/code/modules/projectiles/ammunition/_firing.dm index 340cfc2e98..06772bd099 100644 --- a/code/modules/projectiles/ammunition/_firing.dm +++ b/code/modules/projectiles/ammunition/_firing.dm @@ -16,10 +16,6 @@ AddComponent(/datum/component/pellet_cloud, projectile_type, pellets) SEND_SIGNAL(src, COMSIG_PELLET_CLOUD_INIT, target, user, fired_from, randomspread, spread, zone_override, params, distro) - if(click_cooldown_override) - user.changeNext_move(click_cooldown_override) - else - user.changeNext_move(CLICK_CD_RANGE) user.newtonian_move(get_dir(target, user)) update_icon() return 1 diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index e8a52a778e..bdfc999f6f 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -17,6 +17,7 @@ force = 5 item_flags = NEEDS_PERMIT attack_verb = list("struck", "hit", "bashed") + attack_speed = CLICK_CD_RANGE var/fire_sound = "gunshot" var/suppressed = null //whether or not a message is displayed when fired @@ -174,9 +175,6 @@ if(firing) return var/stamloss = user.getStaminaLoss() - if(stamloss >= STAMINA_NEAR_SOFTCRIT) //The more tired you are, the less damage you do. - var/penalty = (stamloss - STAMINA_NEAR_SOFTCRIT)/(STAMINA_NEAR_CRIT - STAMINA_NEAR_SOFTCRIT)*STAM_CRIT_GUN_DELAY - user.changeNext_move(CLICK_CD_RANGE+(CLICK_CD_RANGE*penalty)) if(flag) //It's adjacent, is the user, or is on the user's person if(target in user.contents) //can't shoot stuff inside us. return @@ -243,6 +241,17 @@ to_chat(user, " [src] is lethally chambered! You don't want to risk harming anyone...") return FALSE +/obj/item/gun/CheckAttackCooldown(mob/user, atom/target) + if((user.a_intent == INTENT_HARM) && user.Adjacent(target)) //melee + return user.CheckActionCooldown(CLICK_CD_MELEE) + return user.CheckActionCooldown(get_clickcd()) + +/obj/item/gun/proc/get_clickcd() + return isnull(chambered?.click_cooldown_override)? CLICK_CD_RANGE : chambered.click_cooldown_override + +/obj/item/gun/GetEstimatedAttackSpeed() + return get_clickcd() + /obj/item/gun/proc/handle_pins(mob/living/user) if(no_pin_required) return TRUE diff --git a/tgstation.dme b/tgstation.dme index 10d1bf350f..cceae4f874 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -254,6 +254,7 @@ #include "code\_onclick\hud\robot.dm" #include "code\_onclick\hud\screen_objects.dm" #include "code\_onclick\hud\swarmer.dm" +#include "code\_onclick\hud\screen_objects\clickdelay.dm" #include "code\_onclick\hud\screen_objects\sprint.dm" #include "code\_onclick\hud\screen_objects\stamina.dm" #include "code\_onclick\hud\screen_objects\storage.dm"