You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
676 B
Go
26 lines
676 B
Go
package handler
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/denisovdennis/autohero/internal/model"
|
|
)
|
|
|
|
// consumeFreeBuffCharge attempts to consume a per-buff-type free charge.
|
|
// Returns an error if no charges remain for the given buff type.
|
|
func consumeFreeBuffCharge(hero *model.Hero, bt model.BuffType, now time.Time) error {
|
|
if hero.SubscriptionActive {
|
|
return nil
|
|
}
|
|
hero.EnsureBuffChargesPopulated(now)
|
|
return hero.ConsumeBuffCharge(bt, now)
|
|
}
|
|
|
|
// refundFreeBuffCharge restores a charge for the specific buff type after a failed activation.
|
|
func refundFreeBuffCharge(hero *model.Hero, bt model.BuffType) {
|
|
if hero.SubscriptionActive {
|
|
return
|
|
}
|
|
hero.RefundBuffCharge(bt)
|
|
}
|