task

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnRefreshTaskConditionEvent added in v0.2.9

func OnRefreshTaskConditionEvent(taskType string, trigger any, condition Condition)

OnRefreshTaskConditionEvent 触发特定任务类型的刷新任务条件事件

func OnRefreshTaskCounterEvent added in v0.2.9

func OnRefreshTaskCounterEvent(taskType string, trigger any, count int64)

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

type Condition map[any]any

Condition 任务条件

func Cond added in v0.2.9

func Cond(k, v any) Condition

Cond 创建任务条件

func (Condition) Cond added in v0.2.9

func (slf Condition) Cond(k, v any) Condition

Cond 创建任务条件

func (Condition) GetAny added in v0.2.9

func (slf Condition) GetAny(key any) any

GetAny 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetBool added in v0.2.9

func (slf Condition) GetBool(key any) bool

GetBool 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetByte added in v0.2.9

func (slf Condition) GetByte(key any) byte

GetByte 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetBytes added in v0.2.9

func (slf Condition) GetBytes(key any) []byte

GetBytes 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetDuration added in v0.2.9

func (slf Condition) GetDuration(key any) time.Duration

GetDuration 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetFloat32 added in v0.2.9

func (slf Condition) GetFloat32(key any) float32

GetFloat32 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetFloat64 added in v0.2.9

func (slf Condition) GetFloat64(key any) float64

GetFloat64 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetInt added in v0.2.9

func (slf Condition) GetInt(key any) int

GetInt 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetInt16 added in v0.2.9

func (slf Condition) GetInt16(key any) int16

GetInt16 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetInt32 added in v0.2.9

func (slf Condition) GetInt32(key any) int32

GetInt32 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetInt64 added in v0.2.9

func (slf Condition) GetInt64(key any) int64

GetInt64 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetInt8 added in v0.2.9

func (slf Condition) GetInt8(key any) int8

GetInt8 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetRune added in v0.2.9

func (slf Condition) GetRune(key any) rune

GetRune 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetRunes added in v0.2.9

func (slf Condition) GetRunes(key any) []rune

GetRunes 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetString added in v0.2.9

func (slf Condition) GetString(key any) string

GetString 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetTime added in v0.2.9

func (slf Condition) GetTime(key any) time.Time

GetTime 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetUint added in v0.2.9

func (slf Condition) GetUint(key any) uint

GetUint 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetUint16 added in v0.2.9

func (slf Condition) GetUint16(key any) uint16

GetUint16 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetUint32 added in v0.2.9

func (slf Condition) GetUint32(key any) uint32

GetUint32 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetUint64 added in v0.2.9

func (slf Condition) GetUint64(key any) uint64

GetUint64 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

func (Condition) GetUint8 added in v0.2.9

func (slf Condition) GetUint8(key any) uint8

GetUint8 获取特定类型的任务条件值,该值必须与预期类型一致,否则返回零值

type Option

type Option func(task *Task)

Option 任务选项

func WithCondition added in v0.2.9

func WithCondition(condition Condition) Option

WithCondition 设置任务完成条件,当满足条件时,任务状态为完成

  • 任务条件值需要变更时可通过 Task.AssignConditionValueAndRefresh 方法变更
  • 当多次设置该选项时,后面的设置会覆盖之前的设置

func WithCounter added in v0.2.9

func WithCounter(counter int64, initCount ...int64) Option

WithCounter 设置任务计数器,当计数器达到要求时,任务状态为完成

  • 一些场景下,任务计数器可能会溢出,此时可通过 WithOverflowCounter 设置可溢出的任务计数器
  • 当多次设置该选项时,后面的设置会覆盖之前的设置
  • 如果需要初始化计数器的值,可通过 initCount 参数设置

func WithDeadline added in v0.2.9

func WithDeadline(deadline time.Time) Option

WithDeadline 设置任务截止时间,超过截至时间并且任务未完成时,任务状态为失败

func WithLimitedDuration added in v0.2.9

func WithLimitedDuration(start time.Time, duration time.Duration) Option

WithLimitedDuration 设置任务限时,超过限时时间并且任务未完成时,任务状态为失败

func WithOverflowCounter added in v0.2.9

func WithOverflowCounter(counter int64, initCount ...int64) Option

WithOverflowCounter 设置可溢出的任务计数器,当计数器达到要求时,任务状态为完成

  • 当多次设置该选项时,后面的设置会覆盖之前的设置
  • 如果需要初始化计数器的值,可通过 initCount 参数设置

func WithType added in v0.2.9

func WithType(taskType string) Option

WithType 设置任务类型

type RefreshTaskConditionEventHandler added in v0.2.9

type RefreshTaskConditionEventHandler[Trigger any] func(taskType string, trigger Trigger, condition Condition) // 刷新任务条件事件处理函数

type RefreshTaskCounterEventHandler added in v0.2.9

type RefreshTaskCounterEventHandler[Trigger any] func(taskType string, trigger Trigger, count int64) // 刷新任务计数器事件处理函数

type Status added in v0.2.9

type Status byte
const (
	StatusAccept   Status = iota + 1 // 已接受
	StatusFailed                     // 已失败
	StatusComplete                   // 已完成
	StatusReward                     // 已领取奖励
)

func (Status) String added in v0.2.9

func (slf Status) String() string

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 NewTask

func NewTask(options ...Option) *Task

NewTask 生成任务

func (*Task) AssignConditionValueAndRefresh added in v0.2.9

func (slf *Task) AssignConditionValueAndRefresh(key, value any) *Task

AssignConditionValueAndRefresh 分配条件值并刷新任务状态

func (*Task) AssignConditionValueAndRefreshByCondition added in v0.2.9

func (slf *Task) AssignConditionValueAndRefreshByCondition(condition Condition) *Task

AssignConditionValueAndRefreshByCondition 分配条件值并刷新任务状态

func (*Task) DecrementCounter added in v0.2.9

func (slf *Task) DecrementCounter(decr int64) *Task

DecrementCounter 减少计数器的值,当 decr 为负数时,计数器的值不会发生变化

func (*Task) IncrementCounter added in v0.2.9

func (slf *Task) IncrementCounter(incr int64) *Task

IncrementCounter 增加计数器的值,当 incr 为负数时,计数器的值不会发生变化

  • 如果需要溢出计数器,可通过 WithOverflowCounter 设置可溢出的任务计数器

func (*Task) IsComplete added in v0.2.9

func (slf *Task) IsComplete() bool

IsComplete 判断任务是否已完成

func (*Task) IsFailed added in v0.2.9

func (slf *Task) IsFailed() bool

IsFailed 判断任务是否已失败

func (*Task) IsReward added in v0.2.9

func (slf *Task) IsReward() bool

IsReward 判断任务是否已领取奖励

func (*Task) ReceiveReward added in v0.2.9

func (slf *Task) ReceiveReward() bool

ReceiveReward 领取任务奖励,当任务状态为已完成时,才能领取奖励,此时返回 true,并且任务状态变更为已领取奖励

func (*Task) ResetStatus added in v0.2.9

func (slf *Task) ResetStatus() *Task

ResetStatus 重置任务状态

  • 该函数会将任务状态重置为已接受状态后,再刷新任务状态
  • 当任务条件变更,例如任务计数要求为 10,已经完成的情况下,将任务计数要求变更为 5 或 20,此时任务状态由于是已完成或已领取状态,不会自动刷新,需要调用该函数刷新任务状态

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL