Documentation ¶
Index ¶
- func OnRefreshTaskConditionEvent(taskType string, trigger any, condition Condition)
- func OnRefreshTaskCounterEvent(taskType string, trigger any, count int64)
- func RegisterRefreshTaskConditionEvent[Trigger any](taskType string, handler RefreshTaskConditionEventHandler[Trigger])
- func RegisterRefreshTaskCounterEvent[Trigger any](taskType string, handler RefreshTaskCounterEventHandler[Trigger])
- type Condition
- func (slf Condition) Cond(k, v any) Condition
- func (slf Condition) GetAny(key any) any
- func (slf Condition) GetBool(key any) bool
- func (slf Condition) GetByte(key any) byte
- func (slf Condition) GetBytes(key any) []byte
- func (slf Condition) GetDuration(key any) time.Duration
- func (slf Condition) GetFloat32(key any) float32
- func (slf Condition) GetFloat64(key any) float64
- func (slf Condition) GetInt(key any) int
- func (slf Condition) GetInt16(key any) int16
- func (slf Condition) GetInt32(key any) int32
- func (slf Condition) GetInt64(key any) int64
- func (slf Condition) GetInt8(key any) int8
- func (slf Condition) GetRune(key any) rune
- func (slf Condition) GetRunes(key any) []rune
- func (slf Condition) GetString(key any) string
- func (slf Condition) GetTime(key any) time.Time
- func (slf Condition) GetUint(key any) uint
- func (slf Condition) GetUint16(key any) uint16
- func (slf Condition) GetUint32(key any) uint32
- func (slf Condition) GetUint64(key any) uint64
- func (slf Condition) GetUint8(key any) uint8
- type Option
- func WithCondition(condition Condition) Option
- func WithCounter(counter int64, initCount ...int64) Option
- func WithDeadline(deadline time.Time) Option
- func WithLimitedDuration(start time.Time, duration time.Duration) Option
- func WithOverflowCounter(counter int64, initCount ...int64) Option
- func WithType(taskType string) Option
- type RefreshTaskConditionEventHandler
- type RefreshTaskCounterEventHandler
- type Status
- type Task
- func (slf *Task) AssignConditionValueAndRefresh(key, value any) *Task
- func (slf *Task) AssignConditionValueAndRefreshByCondition(condition Condition) *Task
- func (slf *Task) DecrementCounter(decr int64) *Task
- func (slf *Task) IncrementCounter(incr int64) *Task
- func (slf *Task) IsComplete() bool
- func (slf *Task) IsFailed() bool
- func (slf *Task) IsReward() bool
- func (slf *Task) ReceiveReward() bool
- func (slf *Task) ResetStatus() *Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OnRefreshTaskConditionEvent ¶ added in v0.2.9
OnRefreshTaskConditionEvent 触发特定任务类型的刷新任务条件事件
func OnRefreshTaskCounterEvent ¶ added in v0.2.9
OnRefreshTaskCounterEvent 触发特定任务类型的刷新任务计数器事件
func RegisterRefreshTaskConditionEvent ¶ added in v0.2.9
func RegisterRefreshTaskConditionEvent[Trigger any](taskType string, handler RefreshTaskConditionEventHandler[Trigger])
RegisterRefreshTaskConditionEvent 注册特定任务类型的刷新任务条件事件处理函数
func RegisterRefreshTaskCounterEvent ¶ added in v0.2.9
func RegisterRefreshTaskCounterEvent[Trigger any](taskType string, handler RefreshTaskCounterEventHandler[Trigger])
RegisterRefreshTaskCounterEvent 注册特定任务类型的刷新任务计数器事件处理函数
Types ¶
type Condition ¶ added in v0.2.9
Condition 任务条件
func (Condition) GetDuration ¶ added in v0.2.9
GetDuration 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
func (Condition) GetFloat32 ¶ added in v0.2.9
GetFloat32 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
func (Condition) GetFloat64 ¶ added in v0.2.9
GetFloat64 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值
type Option ¶
type Option func(task *Task)
Option 任务选项
func WithCondition ¶ added in v0.2.9
WithCondition 设置任务完成条件,当满足条件时,任务状态为完成
- 任务条件值需要变更时可通过 Task.AssignConditionValueAndRefresh 方法变更
- 当多次设置该选项时,后面的设置会覆盖之前的设置
func WithCounter ¶ added in v0.2.9
WithCounter 设置任务计数器,当计数器达到要求时,任务状态为完成
- 一些场景下,任务计数器可能会溢出,此时可通过 WithOverflowCounter 设置可溢出的任务计数器
- 当多次设置该选项时,后面的设置会覆盖之前的设置
- 如果需要初始化计数器的值,可通过 initCount 参数设置
func WithDeadline ¶ added in v0.2.9
WithDeadline 设置任务截止时间,超过截至时间并且任务未完成时,任务状态为失败
func WithLimitedDuration ¶ added in v0.2.9
WithLimitedDuration 设置任务限时,超过限时时间并且任务未完成时,任务状态为失败
func WithOverflowCounter ¶ added in v0.2.9
WithOverflowCounter 设置可溢出的任务计数器,当计数器达到要求时,任务状态为完成
- 当多次设置该选项时,后面的设置会覆盖之前的设置
- 如果需要初始化计数器的值,可通过 initCount 参数设置
type RefreshTaskConditionEventHandler ¶ added in v0.2.9
type RefreshTaskCounterEventHandler ¶ added in v0.2.9
type Task ¶
type Task struct { Type string `json:"type,omitempty"` // 任务类型 Status Status `json:"status,omitempty"` // 任务状态 Cond Condition `json:"cond,omitempty"` // 任务条件 CondValue map[any]any `json:"cond_value,omitempty"` // 任务条件值 Counter int64 `json:"counter,omitempty"` // 任务要求计数器 CurrCount int64 `json:"curr_count,omitempty"` // 任务当前计数 CurrOverflow bool `json:"curr_overflow,omitempty"` // 任务当前计数是否允许溢出 Deadline time.Time `json:"deadline,omitempty"` // 任务截止时间 StartTime time.Time `json:"start_time,omitempty"` // 任务开始时间 LimitedDuration time.Duration `json:"limited_duration,omitempty"` // 任务限时 }
Task 是对任务信息进行描述和处理的结构体
func (*Task) AssignConditionValueAndRefresh ¶ added in v0.2.9
AssignConditionValueAndRefresh 分配条件值并刷新任务状态
func (*Task) AssignConditionValueAndRefreshByCondition ¶ added in v0.2.9
AssignConditionValueAndRefreshByCondition 分配条件值并刷新任务状态
func (*Task) DecrementCounter ¶ added in v0.2.9
DecrementCounter 减少计数器的值,当 decr 为负数时,计数器的值不会发生变化
func (*Task) IncrementCounter ¶ added in v0.2.9
IncrementCounter 增加计数器的值,当 incr 为负数时,计数器的值不会发生变化
- 如果需要溢出计数器,可通过 WithOverflowCounter 设置可溢出的任务计数器
func (*Task) ReceiveReward ¶ added in v0.2.9
ReceiveReward 领取任务奖励,当任务状态为已完成时,才能领取奖励,此时返回 true,并且任务状态变更为已领取奖励
func (*Task) ResetStatus ¶ added in v0.2.9
ResetStatus 重置任务状态
- 该函数会将任务状态重置为已接受状态后,再刷新任务状态
- 当任务条件变更,例如任务计数要求为 10,已经完成的情况下,将任务计数要求变更为 5 或 20,此时任务状态由于是已完成或已领取状态,不会自动刷新,需要调用该函数刷新任务状态