Documentation ¶
Overview ¶
Package cooldown provides default implementation for SetCD, SetCDWithDelay, ResetActionCooldown, ReduceActionCooldown, ActionReady,
Index ¶
- type Character
- func (c *Character) ActionReady(a action.Action, p map[string]int) bool
- func (c *Character) ActionStam(a action.Action, p map[string]int) float64
- func (c *Character) Charges(a action.Action) int
- func (c *Character) Condition(fields []string) (any, error)
- func (c *Character) Cooldown(a action.Action) int
- func (c *Character) Dash(p map[string]int) action.ActionInfo
- func (c *Character) Jump(p map[string]int) action.ActionInfo
- func (c *Character) ReduceActionCooldown(a action.Action, v int)
- func (c *Character) ResetActionCooldown(a action.Action)
- func (c *Character) SetCD(a action.Action, dur int)
- func (h *Character) SetCDWithDelay(a action.Action, dur int, delay int)
- func (c *Character) SetNumCharges(a action.Action, num int)
- func (c *Character) Snapshot(a *combat.AttackInfo) combat.Snapshot
- func (c *Character) Walk(p map[string]int) action.ActionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Character ¶
type Character struct { *character.CharWrapper Core *core.Core ActionCD []int AvailableCDCharge []int // contains filtered or unexported fields }
func NewWithWrapper ¶
func NewWithWrapper(c *core.Core, w *character.CharWrapper) *Character
func (*Character) ActionReady ¶
func (*Character) ActionStam ¶
ActionStam provides default implementation for stam cost for charge and dash character should override this though
func (*Character) ReduceActionCooldown ¶
func (*Character) ResetActionCooldown ¶
func (*Character) SetCD ¶
SetCD takes two parameters:
- a action.Action: this is the action type we are triggering the cooldown for
- dur: duration in frames that the cooldown should last for
It is assumed that AvailableCDCharges[a] > 0 (otherwise action should not have been allowed)
SetCD works by adding the cooldown duration to a queue. This is because when there are multiple charges, the game will first finish recharging the first charge before starting the full cooldown for the second charge.
When a cooldown is added to queue for the first time, a queue worker is started. This queue worker will check back at the cooldown specified for the first queued item, and if the queued cooldown did not change, it will increment the number of charges by 1, and reschedule itself to check back for the next item in queue
Sometimes, the queued cooldown gets adjusted via ReduceActionCooldown or ResetActionCooldown. When this happens, the initial queued worker will check back at the wrong time. To prevent this, we use cdQueueWorkerStartedAt[a] which tracks the frame the worker started at. So when ReduceActionCooldown or ResetActionCooldown gets called, we start a new worker, updating cdQueueWorkerStartedAt[a] to represent the new worker start frame. This way the old worker can check this value first and then gracefully exit if it no longer matches its starting frame