game_sync/ranksrv/rank/customaward.go

100 lines
2.5 KiB
Go

package rank
import (
"math/rand"
"time"
"github.com/jinzhu/now"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/module"
"mongo.games.com/game/common"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
"mongo.games.com/game/protocol/rank"
"mongo.games.com/game/ranksrv/com"
"mongo.games.com/game/srvdata"
)
var CustomAwardMgrInstance = com.NewListMgr[*model.CustomLogAward](
func() int64 {
return int64(model.GameParamData.CustomAwardUpdateTime)
},
func(platform string, index int32) ([]*model.CustomLogAward, error) {
// 当天数据
startTs := now.BeginningOfDay().Unix()
endTs := startTs + 24*int64(time.Hour.Seconds())
logger.Logger.Tracef("load custom award platform:%s startTs:%v endTs:%v", platform, startTs, endTs)
ret, err := model.CustomLogAwardFind(platform, startTs, endTs)
return ret, err
})
var CustomAwardMgrSingle = &CustomAwardMgr{}
type CustomAwardMgr struct {
updateTime time.Time
}
func (c *CustomAwardMgr) ModuleName() string {
return "customaward"
}
func (c *CustomAwardMgr) Init() {
}
func (c *CustomAwardMgr) Update() {
nowTime := time.Now()
if nowTime.Unix() < c.updateTime.Unix() {
return
}
c.updateTime = nowTime.Add(time.Duration(common.RandInt(model.GameParamData.CustomAwardMinAddTime, model.GameParamData.CustomAwardMaxAddTime)) * time.Second)
// 随机添加假数据
for k := range com.PlatformConfigSingleton.Platforms {
for _, vv := range com.ConfigMgrInst.GetConfig(k).RoomConfig {
if vv.GetOn() == common.Off {
continue
}
var awards []*model.Item
var items []*rank.Item
for _, item := range vv.GetReward() {
awards = append(awards, &model.Item{
ItemId: item.ItemId,
ItemNum: item.ItemNum,
ObtainTime: nowTime.Unix(),
})
items = append(items, &rank.Item{
Id: item.ItemId,
N: item.ItemNum,
})
}
name := ""
if len(srvdata.PBDB_NameMgr.Datas.GetArr()) > 0 {
n := rand.Intn(len(srvdata.PBDB_NameMgr.Datas.GetArr()))
name = srvdata.PBDB_NameMgr.Datas.GetArr()[n].Name
}
id := common.RandInt(20000000, 99999999)
mq.Write(&model.CustomLogAward{
Platform: k,
CycleId: "",
SnId: int32(id),
Name: name,
Awards: awards,
StartTs: nowTime.Add(-time.Minute * 8).Unix(),
EndTs: nowTime.Unix(),
Price: vv.GetPrice(),
ImageURL: vv.GetImageURI(),
})
break
}
}
}
func (c *CustomAwardMgr) Shutdown() {
module.UnregisteModule(c)
}
func init() {
module.RegisteModule(CustomAwardMgrSingle, time.Second*5, 0)
}