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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds windup autofire functionality. The future is now. (Later) #67911

Merged
merged 5 commits into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 31 additions & 3 deletions code/datums/components/fullauto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,34 @@
var/autofire_shot_delay = 0.3 SECONDS //Time between individual shots.
var/mouse_status = AUTOFIRE_MOUSEUP //This seems hacky but there can be two MouseDown() without a MouseUp() in between if the user holds click and uses alt+tab, printscreen or similar.

///windup autofire vars
///Whether the delay between shots increases over time, simulating a spooling weapon
var/windup_autofire = FALSE
///the reduction to shot delay for windup
var/current_windup_reduction = 0
///the percentage of autfire_shot_delay that is added to current_windup_reduction
var/windup_autofire_reduction_multiplier = 0.3
///How high of a reduction that current_windup_reduction can reach
var/windup_autofire_cap = 0.3
///How long it takes for weapons that have spooled-up to reset back to the original firing speed
var/windup_spindown = 3 SECONDS
///Timer for tracking the spindown reset timings
var/timerid
necromanceranne marked this conversation as resolved.
Show resolved Hide resolved
COOLDOWN_DECLARE(next_shot_cd)

/datum/component/automatic_fire/Initialize(_autofire_shot_delay)
/datum/component/automatic_fire/Initialize(autofire_shot_delay, windup_autofire, windup_autofire_reduction_multiplier, windup_autofire_cap, windup_spindown)
. = ..()
if(!isgun(parent))
return COMPONENT_INCOMPATIBLE
var/obj/item/gun = parent
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, .proc/wake_up)
if(_autofire_shot_delay)
autofire_shot_delay = _autofire_shot_delay
if(autofire_shot_delay)
src.autofire_shot_delay = autofire_shot_delay
if(windup_autofire)
src.windup_autofire = windup_autofire
src.windup_autofire_reduction_multiplier = windup_autofire_reduction_multiplier
src.windup_autofire_cap = windup_autofire_cap
src.windup_spindown = windup_spindown
if(autofire_stat == AUTOFIRE_STAT_IDLE && ismob(gun.loc))
var/mob/user = gun.loc
wake_up(src, user)
Expand Down Expand Up @@ -233,6 +251,10 @@
return FALSE
shooter.face_atom(target)
var/next_delay = autofire_shot_delay
if(windup_autofire)
next_delay = clamp(next_delay - current_windup_reduction, round(autofire_shot_delay * windup_autofire_cap), autofire_shot_delay)
current_windup_reduction = (current_windup_reduction + round(autofire_shot_delay * windup_autofire_reduction_multiplier))
timerid = addtimer(CALLBACK(src, .proc/windup_reset, FALSE), windup_spindown, TIMER_UNIQUE|TIMER_OVERRIDE|TIMER_STOPPABLE)
if(HAS_TRAIT(shooter, TRAIT_DOUBLE_TAP))
next_delay = round(next_delay * 0.5)
COOLDOWN_START(src, next_shot_cd, next_delay)
Expand All @@ -241,6 +263,12 @@
stop_autofiring()
return FALSE

/// Reset for our windup, resetting everything back to initial values after a variable set amount of time (determined by var/windup_spindown).
/datum/component/automatic_fire/proc/windup_reset(deltimer)
necromanceranne marked this conversation as resolved.
Show resolved Hide resolved
current_windup_reduction = initial(current_windup_reduction)
if(deltimer && timerid)
deltimer(timerid)

// Gun procs.

/obj/item/gun/proc/on_autofire_start(mob/living/shooter)
Expand Down