task

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTaskNotFinish 任务未完成
	ErrTaskNotFinish = errors.New("task not finish")
	// ErrTaskRewardReceived 任务奖励已领取
	ErrTaskRewardReceived = errors.New("task reward received")
	// ErrTaskNotStart 任务未开始
	ErrTaskNotStart = errors.New("task not start")
	// ErrTaskFail 任务失败
	ErrTaskFail = errors.New("task fail")
)

Functions

func OnRefreshTaskChildCount added in v0.0.13

func OnRefreshTaskChildCount(taskType int, key any, increase int64)

OnRefreshTaskChildCount 触发任务子计数刷新事件

func OnRefreshTaskCount added in v0.0.13

func OnRefreshTaskCount(taskType int, increase int64)

OnRefreshTaskCount 触发任务计数刷新事件

func RegRefreshTaskChildCount added in v0.0.13

func RegRefreshTaskChildCount(taskType int, handler RefreshTaskChildCountEvent)

RegRefreshTaskChildCount 注册任务子计数刷新事件

func RegRefreshTaskCount added in v0.0.13

func RegRefreshTaskCount(taskType int, handler RefreshTaskCountEvent)

RegRefreshTaskCount 注册任务计数刷新事件

Types

type Option

type Option func(task *Task)

func WithChild added in v0.0.13

func WithChild(key any, childCondition int64) Option

WithChild 通过指定子计数的方式创建任务

  • 只有当子计数与主计数均达到条件时,任务才会完成
  • 通常用于多条件的任务

func WithChildCount added in v0.0.13

func WithChildCount(key any, childCount int64) Option

WithChildCount 通过初始化子计数的方式创建任务

func WithCount added in v0.0.13

func WithCount(count int64) Option

WithCount 通过初始化计数的方式创建任务

func WithDisableNotStartGetReward added in v0.0.13

func WithDisableNotStartGetReward() Option

WithDisableNotStartGetReward 禁止未开始的任务领取奖励

func WithFront added in v0.0.13

func WithFront(fronts ...*Task) Option

WithFront 通过指定任务前置任务的方式创建任务

  • 当前置任务未完成时,当前任务不会开始计数

func WithLimitedTime added in v0.0.13

func WithLimitedTime(limitTime time.Duration) Option

WithLimitedTime 通过限时的方式创建任务

func WithOffsetTime added in v0.0.13

func WithOffsetTime(offset *offset.Time) Option

WithOffsetTime 通过指定偏移时间的方式创建任务

func WithStartTime added in v0.0.13

func WithStartTime(startTime time.Time) Option

WithStartTime 通过指定开始时间的方式创建任务

  • 只有当时间在开始时间之后,任务才会开始计数

type RefreshTaskChildCountEvent added in v0.0.13

type RefreshTaskChildCountEvent func(taskType int, key any, increase int64)

type RefreshTaskCountEvent added in v0.0.13

type RefreshTaskCountEvent func(taskType int, increase int64)

type State

type State uint16
const (
	StateAccept State = iota // 已接受
	StateFinish              // 已完成
	StateReward              // 已领取
	StateFail                // 已失败
)

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task 通用任务数据结构

func NewTask

func NewTask(id int64, taskType int, condition int64, options ...Option) *Task

NewTask 创建任务

func (*Task) AddChildCount added in v0.0.13

func (slf *Task) AddChildCount(key any, count int64)

AddChildCount 增加子计数

func (*Task) AddCount added in v0.0.13

func (slf *Task) AddCount(count int64)

AddCount 增加计数

func (*Task) FrontsIsFinish added in v0.0.13

func (slf *Task) FrontsIsFinish() bool

FrontsIsFinish 判断前置任务是否完成

func (*Task) GetCondition added in v0.0.13

func (slf *Task) GetCondition() int64

GetCondition 获取计数条件

func (*Task) GetCount added in v0.0.13

func (slf *Task) GetCount() int64

GetCount 获取计数

func (*Task) GetFronts added in v0.0.13

func (slf *Task) GetFronts() map[int64]*Task

GetFronts 获取前置任务

func (*Task) GetFrontsWithState added in v0.0.13

func (slf *Task) GetFrontsWithState(state State) map[int64]*Task

GetFrontsWithState 获取特定状态的前置任务

func (*Task) GetID added in v0.0.13

func (slf *Task) GetID() int64

GetID 获取任务ID

func (*Task) GetReward added in v0.0.13

func (slf *Task) GetReward(rewardHandle func() error) error

GetReward 获取任务奖励

  • 当任务状态为 StateFinish 时,调用 rewardHandle 函数
  • 当任务状态不为 StateFinish 或奖励函数发生错误时,返回错误

func (*Task) GetState

func (slf *Task) GetState() State

GetState 获取任务状态

func (*Task) GetType added in v0.0.13

func (slf *Task) GetType() int

GetType 获取任务类型

func (*Task) IsStart added in v0.0.13

func (slf *Task) IsStart() bool

IsStart 判断任务是否开始

func (*Task) Reset

func (slf *Task) Reset()

Reset 重置任务

func (*Task) SetChildCount added in v0.0.13

func (slf *Task) SetChildCount(key any, count int64)

SetChildCount 设置子计数

func (*Task) SetCount added in v0.0.13

func (slf *Task) SetCount(count int64)

SetCount 设置计数

Jump to

Keyboard shortcuts

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