Documentation ¶
Index ¶
- Constants
- func HasActivity(activityId int64) bool
- func Register[PlayerID comparable, ActivityData, PlayerData any](activity *Activity[PlayerID, ActivityData, PlayerData])
- func SetOffsetTime(time *offset.Time)
- func SetTicker(t *timer.Ticker)
- type Activity
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeAfterShowTime(afterShow time.Time)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeBeforeShowTime(beforeShow time.Time)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) ChangeTime(period times.Period)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetActivityData() ActivityData
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetEnd() time.Time
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetPeriod() times.Period
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetPlayerData(playerId PlayerID) PlayerData
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetStart() time.Time
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsInvalid() bool
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsOpen() bool
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsShow() bool
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) IsShowAndOpen() bool
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) Join(playerId PlayerID)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) Leave(playerId PlayerID)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnNewDayEvent()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerJoinEvent(playerId PlayerID)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerLeaveEvent(playerId PlayerID)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnPlayerNewDayEvent(playerId PlayerID)
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStartEvent()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStartShowEvent()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStopEvent()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) OnStopShowEvent()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegNewDayEvent(handle NewDayEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerJoinEvent(handle PlayerJoinEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerLeaveEvent(handle PlayerLeaveEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegPlayerNewDayEvent(handle PlayerNewDayEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStartEvent(handle StartEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStartShowEvent(handle StartShowEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStopEvent(handle StopEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) RegStopShowEvent(handle StopShowEventHandle[PlayerID, ActivityData, PlayerData])
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) Register()
- func (slf *Activity[PlayerID, ActivityData, PlayerData]) StoreData(handle func(data *Data[PlayerID, ActivityData, PlayerData]))
- type Data
- type NewDayEventHandle
- type NoneData
- type Option
- func WithActivityData[PlayerID comparable, ActivityData, PlayerData any](data ActivityData) Option[PlayerID, ActivityData, PlayerData]
- func WithAfterShowTime[PlayerID comparable, ActivityData, PlayerData any](showTime time.Duration) Option[PlayerID, ActivityData, PlayerData]
- func WithBeforeShowTime[PlayerID comparable, ActivityData, PlayerData any](showTime time.Duration) Option[PlayerID, ActivityData, PlayerData]
- func WithData[PlayerID comparable, ActivityData, PlayerData any](data *Data[PlayerID, ActivityData, PlayerData]) Option[PlayerID, ActivityData, PlayerData]
- func WithLastNewDay[PlayerID comparable, ActivityData, PlayerData any](lastNewDay int64) Option[PlayerID, ActivityData, PlayerData]
- func WithPlayerDataLoadHandle[PlayerID comparable, ActivityData, PlayerData any](...) Option[PlayerID, ActivityData, PlayerData]
- func WithPlayerLastNewDay[PlayerID comparable, ActivityData, PlayerData any](playerLastNewDay map[PlayerID]int64) Option[PlayerID, ActivityData, PlayerData]
- type PlayerJoinEventHandle
- type PlayerLeaveEventHandle
- type PlayerNewDayEventHandle
- type StartEventHandle
- type StartShowEventHandle
- type StopEventHandle
- type StopShowEventHandle
Constants ¶
const (
TickerMark = "ACTIVITY_SYSTEM_TICKER"
)
Variables ¶
This section is empty.
Functions ¶
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
SetOffsetTime 设置活动的时间偏移时间
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
ChangeAfterShowTime 修改活动结束后的展示时间
func (*Activity[PlayerID, ActivityData, PlayerData]) ChangeBeforeShowTime ¶ added in v0.0.3
ChangeBeforeShowTime 修改活动开始前的展示时间
func (*Activity[PlayerID, ActivityData, PlayerData]) ChangeTime ¶ added in v0.0.3
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]) GetPlayerData ¶
func (slf *Activity[PlayerID, ActivityData, PlayerData]) GetPlayerData(playerId PlayerID) PlayerData
GetPlayerData 获取玩家数据
func (*Activity[PlayerID, ActivityData, PlayerData]) IsShow ¶ added in v0.0.3
IsShow 判断活动是否展示
- 活动展示时,活动并非一定开启。常用于活动的预告和结束后的成果展示
- 当活动没有设置展示时间时,活动展示与活动开启一致
- 如果活动仅设置了活动开始前的展示时间,则活动展示将从开始前的展示时间持续到活动结束
- 如果活动仅设置了活动结束后的展示时间,则活动展示将从活动开始持续到结束后的展示时间
func (*Activity[PlayerID, ActivityData, PlayerData]) IsShowAndOpen ¶ added in v0.0.3
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 注册活动结束展示事件
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 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])