oh boy
This commit is contained in:
@@ -1,38 +1,3 @@
|
||||
/*
|
||||
Click code cleanup
|
||||
~Sayu
|
||||
*/
|
||||
|
||||
// 1 decisecond click delay (above and beyond mob/next_move)
|
||||
//This is mainly modified by click code, to modify click delays elsewhere, use next_move and changeNext_move()
|
||||
/mob/var/next_click = 0
|
||||
|
||||
// THESE DO NOT EFFECT THE BASE 1 DECISECOND DELAY OF NEXT_CLICK
|
||||
/mob/var/next_move_adjust = 0 //Amount to adjust action/click delays by, + or -
|
||||
/mob/var/next_move_modifier = 1 //Value to multiply action/click delays by
|
||||
|
||||
|
||||
//Delays the mob's next click/action by num deciseconds
|
||||
// eg: 10-3 = 7 deciseconds of delay
|
||||
// eg: 10*0.5 = 5 deciseconds of delay
|
||||
// DOES NOT EFFECT THE BASE 1 DECISECOND DELAY OF NEXT_CLICK
|
||||
|
||||
/mob/proc/timeToNextMove()
|
||||
return max(0, next_move - world.time)
|
||||
|
||||
/mob/proc/changeNext_move(num)
|
||||
next_move = world.time + ((num+next_move_adjust)*next_move_modifier)
|
||||
|
||||
/mob/living/changeNext_move(num)
|
||||
last_click_move = next_move
|
||||
var/mod = next_move_modifier
|
||||
var/adj = next_move_adjust
|
||||
for(var/i in status_effects)
|
||||
var/datum/status_effect/S = i
|
||||
mod *= S.nextmove_modifier()
|
||||
adj += S.nextmove_adjust()
|
||||
next_move = world.time + ((num + adj)*mod)
|
||||
|
||||
/*
|
||||
Before anything else, defer these calls to a per-mobtype handler. This allows us to
|
||||
remove istype() spaghetti code, but requires the addition of other handler procs to simplify it.
|
||||
|
||||
@@ -90,13 +90,6 @@
|
||||
return
|
||||
duration = world.time + original_duration
|
||||
|
||||
//clickdelay/nextmove modifiers!
|
||||
/datum/status_effect/proc/nextmove_modifier()
|
||||
return 1
|
||||
|
||||
/datum/status_effect/proc/nextmove_adjust()
|
||||
return 0
|
||||
|
||||
////////////////
|
||||
// ALERT HOOK //
|
||||
////////////////
|
||||
|
||||
59
code/modules/mob/clickdelay.dm
Normal file
59
code/modules/mob/clickdelay.dm
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* CLICKDELAY HANDLING SYSTEM
|
||||
* How this works is mobs can never do actions until their next_action is at or below world.time, but things can specify extra cooldown
|
||||
* to check for either from the time of last_action or from the end of next_action.
|
||||
*
|
||||
* Clickdelay should always be checked via [CheckActionCooldown()], never manually!
|
||||
*/
|
||||
|
||||
/mob
|
||||
// CLICKDELAY AND RELATED
|
||||
/// Last time we clicked. No clicking twice in one tick, please! This should be directly set and checked.
|
||||
var/last_click = 0
|
||||
|
||||
/// Generic clickdelay variable. Marks down the last world.time we did something that should cause or impact generic clickdelay. This should be directly set. This should only be checked using [CheckActionCooldown()].
|
||||
var/last_action = 0
|
||||
/// Generic clickdelay variable. Next world.time we should be able to do something that respects generic clickdelay. This should be set using [DelayNextAction()] This should only be checked using [CheckActionCooldown()].
|
||||
var/next_action = 0
|
||||
/// Simple modification variable added to next action on adjust. This should only be manually modified via addition.
|
||||
var/next_action_adjust = 0
|
||||
/// Simple modification variable multiplied to next action modifier on adjust. This should only be manually modified using multipliers.
|
||||
var/next_action_mult = 1
|
||||
/// Simple modification variable added to amount when checking time since last action using [CheckActionCooldown()]. This should only be manually modified via addition.
|
||||
var/last_action_adjust = 0
|
||||
/// Simple modification variable multiplied to amount when checking time since last action using [CheckActionCooldown()]. This should only be manually modified using multipliers.
|
||||
var/last_action_mult = 1
|
||||
|
||||
/// Special clickdelay variable for resisting. Last time we did a special action like resisting. This should be directly set. This should only be checked using [CheckResistCooldown()].
|
||||
var/last_resist = 0
|
||||
/// How long we should wait before allowing another resist. This should only be manually modified using multipliers.
|
||||
var/resist_cooldown = 10
|
||||
|
||||
/**
|
||||
* Applies a delay to next_action before we can do our next action.
|
||||
*
|
||||
* @params
|
||||
* * amount - Amount to delay by
|
||||
* * ignore_mod - ignores next action adjust and mult
|
||||
*/
|
||||
/mob/proc/DelayNextAction(amount, ignore_mod = FALSE)
|
||||
next_action = max(next_action, world.time + (ignore_mod? amount : (amount * next_action_mult + next_action_adjust)))
|
||||
|
||||
/**
|
||||
* Checks if we can do another action.
|
||||
* Returns TRUE if we can and FALSE if we cannot.
|
||||
*
|
||||
* @params
|
||||
* * cooldown - Time required since last action. Defaults to 0.5
|
||||
* * from_next_action - Defaults to FALSE. Should we check from the tail end of next_action instead of last_action?
|
||||
* * ignore_mod - Defaults to FALSE. Ignore all adjusts and multipliers. Do not use this unless you know what you are doing and have a good reason.
|
||||
* * ignore_next_action - Defaults to FALSE. Ignore next_action and only care about cooldown param and everything else. Generally unused.
|
||||
*/
|
||||
/mob/proc/CheckActionCooldown(cooldown = 0.5, from_next_action = FALSE, ignore_mod = FALSE, ignore_next_action = FALSE)
|
||||
return (ignore_next_action || (world.time >= next_action)) && (world.time >= ((from_next_action? next_action : last_action) + max(0, ignore_mod? cooldown : (cooldown * last_action_mult + last_action_adjust))))
|
||||
|
||||
/**
|
||||
* Checks if we can resist again.
|
||||
*/
|
||||
/mob/proc/CheckResistCooldown()
|
||||
return (world.time >= (last_resist + resist_cooldown))
|
||||
Reference in New Issue
Block a user