activity

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TickerMark = "ACTIVITY_SYSTEM_TICKER"
)

Variables

This section is empty.

Functions

func HasActivity added in v0.0.3

func HasActivity(activityId int64) bool

HasActivity 检查活动是否存在

func Register added in v0.0.3

func Register[PlayerID comparable, ActivityData, PlayerData any](activity *Activity[PlayerID, ActivityData, PlayerData])

Register 注册活动

func SetOffsetTime added in v0.0.3

func SetOffsetTime(time *offset.Time)

SetOffsetTime 设置活动的时间偏移时间

func SetTicker added in v0.0.3

func SetTicker(t *timer.Ticker)

SetTicker 通过指定特定的定时器取代默认的定时器

  • 当传入的定时器为 nil 时,将使用默认的定时器

Types

type Activity

type Activity[PlayerID comparable, ActivityData, PlayerData any] struct {
	// contains filtered or unexported fields
}

Activity 活动

func Get added in v0.0.3

func Get[PlayerID comparable, ActivityData, PlayerData any](activityId int64) *Activity[PlayerID, ActivityData, PlayerData]

Get 获取活动

func NewActivity added in v0.0.3

func NewActivity[PlayerID comparable, ActivityData, PlayerData any](id int64, period times.Period, options ...Option[PlayerID, ActivityData, PlayerData]) *Activity[PlayerID, ActivityData, PlayerData]

NewActivity 创建一个新的活动

  • id: 活动 ID
  • period: 活动周期

func (*Activity[PlayerID, ActivityData, PlayerData]) ChangeAfterShowTime added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeAfterShowTime(afterShow time.Time)

ChangeAfterShowTime 修改活动结束后的展示时间

func (*Activity[PlayerID, ActivityData, PlayerData]) ChangeBeforeShowTime added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeBeforeShowTime(beforeShow time.Time)

ChangeBeforeShowTime 修改活动开始前的展示时间

func (*Activity[PlayerID, ActivityData, PlayerData]) ChangeTime added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeTime(period times.Period)

ChangeTime 修改活动时间

func (*Activity[PlayerID, ActivityData, PlayerData]) GetActivityData added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetActivityData() ActivityData

GetActivityData 获取活动数据

func (*Activity[PlayerID, ActivityData, PlayerData]) GetEnd added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetEnd() time.Time

GetEnd 获取活动结束时间

func (*Activity[PlayerID, ActivityData, PlayerData]) GetPeriod added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetPeriod() times.Period

GetPeriod 获取活动周期

func (*Activity[PlayerID, ActivityData, PlayerData]) GetPlayerData

func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetPlayerData(playerId PlayerID) PlayerData

GetPlayerData 获取玩家数据

func (*Activity[PlayerID, ActivityData, PlayerData]) GetStart added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetStart() time.Time

GetStart 获取活动开始时间

func (*Activity[PlayerID, ActivityData, PlayerData]) IsInvalid added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsInvalid() bool

IsInvalid 判断活动是否无效

func (*Activity[PlayerID, ActivityData, PlayerData]) IsOpen

func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsOpen() bool

IsOpen 判断活动是否开启

func (*Activity[PlayerID, ActivityData, PlayerData]) IsShow added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsShow() bool

IsShow 判断活动是否展示

  • 活动展示时,活动并非一定开启。常用于活动的预告和结束后的成果展示
  • 当活动没有设置展示时间时,活动展示与活动开启一致
  • 如果活动仅设置了活动开始前的展示时间,则活动展示将从开始前的展示时间持续到活动结束
  • 如果活动仅设置了活动结束后的展示时间,则活动展示将从活动开始持续到结束后的展示时间

func (*Activity[PlayerID, ActivityData, PlayerData]) IsShowAndOpen added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsShowAndOpen() bool

IsShowAndOpen 判断活动是否展示并开启

func (*Activity[PlayerID, ActivityData, PlayerData]) Join

func (slf *Activity[PlayerID, ActivityData, PlayerData]) Join(playerId PlayerID)

Join 设置玩家加入活动

  • 通常玩家应该在上线的时候加入活动

func (*Activity[PlayerID, ActivityData, PlayerData]) Leave

func (slf *Activity[PlayerID, ActivityData, PlayerData]) Leave(playerId PlayerID)

Leave 设置玩家离开活动

  • 当玩家离开活动时,玩家的活动数据将会被清除

func (*Activity[PlayerID, ActivityData, PlayerData]) OnNewDayEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnNewDayEvent()

func (*Activity[PlayerID, ActivityData, PlayerData]) OnPlayerJoinEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerJoinEvent(playerId PlayerID)

func (*Activity[PlayerID, ActivityData, PlayerData]) OnPlayerLeaveEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerLeaveEvent(playerId PlayerID)

func (*Activity[PlayerID, ActivityData, PlayerData]) OnPlayerNewDayEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerNewDayEvent(playerId PlayerID)

func (*Activity[PlayerID, ActivityData, PlayerData]) OnStartEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStartEvent()

func (*Activity[PlayerID, ActivityData, PlayerData]) OnStartShowEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStartShowEvent()

func (*Activity[PlayerID, ActivityData, PlayerData]) OnStopEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStopEvent()

func (*Activity[PlayerID, ActivityData, PlayerData]) OnStopShowEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStopShowEvent()

func (*Activity[PlayerID, ActivityData, PlayerData]) RegNewDayEvent

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegNewDayEvent(handle NewDayEventHandle[PlayerID, ActivityData, PlayerData])

RegNewDayEvent 注册新的一天事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegPlayerJoinEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerJoinEvent(handle PlayerJoinEventHandle[PlayerID, ActivityData, PlayerData])

RegPlayerJoinEvent 注册玩家加入活动事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegPlayerLeaveEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerLeaveEvent(handle PlayerLeaveEventHandle[PlayerID, ActivityData, PlayerData])

RegPlayerLeaveEvent 注册玩家离开活动事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegPlayerNewDayEvent

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerNewDayEvent(handle PlayerNewDayEventHandle[PlayerID, ActivityData, PlayerData])

RegPlayerNewDayEvent 注册玩家新的一天事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegStartEvent

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStartEvent(handle StartEventHandle[PlayerID, ActivityData, PlayerData])

RegStartEvent 注册活动开始事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegStartShowEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStartShowEvent(handle StartShowEventHandle[PlayerID, ActivityData, PlayerData])

RegStartShowEvent 注册活动开始展示事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegStopEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStopEvent(handle StopEventHandle[PlayerID, ActivityData, PlayerData])

RegStopEvent 注册活动结束事件

func (*Activity[PlayerID, ActivityData, PlayerData]) RegStopShowEvent added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStopShowEvent(handle StopShowEventHandle[PlayerID, ActivityData, PlayerData])

RegStopShowEvent 注册活动结束展示事件

func (*Activity[PlayerID, ActivityData, PlayerData]) Register added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) Register()

Register 将该活动进行注册

func (*Activity[PlayerID, ActivityData, PlayerData]) StoreData added in v0.0.3

func (slf *Activity[PlayerID, ActivityData, PlayerData]) StoreData(handle func(data *Data[PlayerID, ActivityData, PlayerData]))

StoreData 通过特定的存储函数存储活动数据

type Data added in v0.0.3

type Data[PlayerID comparable, ActivityData any, PlayerData any] struct {
	Data             ActivityData            // 活动全局数据
	PlayerData       map[PlayerID]PlayerData // 活动玩家数据
	LastNewDay       int64                   // 最后触发新的一天的时间戳
	PlayerLastNewDay map[PlayerID]int64      // 玩家最后触发新的一天的时间戳
}

Data 活动数据信息

type NewDayEventHandle

type NewDayEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData])

type NoneData added in v0.0.3

type NoneData struct{}

NoneData 空数据活动

type Option

type Option[PlayerID comparable, ActivityData, PlayerData any] func(activity *Activity[PlayerID, ActivityData, PlayerData])

func WithActivityData added in v0.0.3

func WithActivityData[PlayerID comparable, ActivityData, PlayerData any](data ActivityData) Option[PlayerID, ActivityData, PlayerData]

WithActivityData 通过指定活动全局数据的方式来创建活动

  • 该活动数据将会被作为活动的全局数据
  • 默认情况下活动本身不包含任何数据

func WithAfterShowTime added in v0.0.3

func WithAfterShowTime[PlayerID comparable, ActivityData, PlayerData any](showTime time.Duration) Option[PlayerID, ActivityData, PlayerData]

WithAfterShowTime 通过指定活动结束后的展示时间的方式来创建活动

func WithBeforeShowTime added in v0.0.3

func WithBeforeShowTime[PlayerID comparable, ActivityData, PlayerData any](showTime time.Duration) Option[PlayerID, ActivityData, PlayerData]

WithBeforeShowTime 通过指定活动开始前的展示时间的方式来创建活动

func WithData

func WithData[PlayerID comparable, ActivityData, PlayerData any](data *Data[PlayerID, ActivityData, PlayerData]) Option[PlayerID, ActivityData, PlayerData]

WithData 通过指定活动数据的方式来创建活动

func WithLastNewDay added in v0.0.3

func WithLastNewDay[PlayerID comparable, ActivityData, PlayerData any](lastNewDay int64) Option[PlayerID, ActivityData, PlayerData]

WithLastNewDay 通过指定活动最后触发新的一天的时间戳的方式来创建活动

func WithPlayerDataLoadHandle added in v0.0.3

func WithPlayerDataLoadHandle[PlayerID comparable, ActivityData, PlayerData any](handle func(activity *Activity[PlayerID, ActivityData, PlayerData], playerId PlayerID) PlayerData) Option[PlayerID, ActivityData, PlayerData]

WithPlayerDataLoadHandle 通过指定玩家数据加载函数的方式来创建活动

  • 该函数将会在玩家数据加载时被调用
  • 活动中的玩家数据将会被按需加载,只有在玩家加入活动时才会被加载

func WithPlayerLastNewDay added in v0.0.3

func WithPlayerLastNewDay[PlayerID comparable, ActivityData, PlayerData any](playerLastNewDay map[PlayerID]int64) Option[PlayerID, ActivityData, PlayerData]

WithPlayerLastNewDay 通过指定玩家最后触发新的一天的时间戳的方式来创建活动

type PlayerJoinEventHandle added in v0.0.3

type PlayerJoinEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData], playerId PlayerID)

type PlayerLeaveEventHandle added in v0.0.3

type PlayerLeaveEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData], playerId PlayerID)

type PlayerNewDayEventHandle

type PlayerNewDayEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData], playerId PlayerID)

type StartEventHandle

type StartEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData])

type StartShowEventHandle added in v0.0.3

type StartShowEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData])

type StopEventHandle added in v0.0.3

type StopEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData])

type StopShowEventHandle added in v0.0.3

type StopShowEventHandle[PlayerID comparable, Data, PlayerData any] func(activity *Activity[PlayerID, Data, PlayerData])

Jump to

Keyboard shortcuts

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