108 lines
2.8 KiB
Go
108 lines
2.8 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/goserver/srvlib"
|
|
"mongo.games.com/goserver/srvlib/action"
|
|
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/model"
|
|
"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)
|
|
com.LogChannelSingleton.WriteLog(&model.CustomLogAward{
|
|
Platform: k,
|
|
CycleId: "",
|
|
SnId: int32(id),
|
|
Name: name,
|
|
Awards: awards,
|
|
StartTs: nowTime.Add(-time.Minute * 8).Unix(),
|
|
EndTs: nowTime.Unix(),
|
|
})
|
|
// 通知获奖
|
|
pack := &rank.UserAward{
|
|
Snid: int32(id),
|
|
Name: name,
|
|
Awards: items,
|
|
Ts: nowTime.Unix(),
|
|
}
|
|
action.BroadcastMessage(common.GetSelfAreaId(), srvlib.GateServerType, int(rank.Rank_PACKET_SCRoomAwardOne), pack, nil)
|
|
logger.Logger.Tracef("BroadcastMessage UserAward: %v", pack)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func (c *CustomAwardMgr) Shutdown() {
|
|
module.UnregisteModule(c)
|
|
}
|
|
|
|
func init() {
|
|
module.RegisteModule(CustomAwardMgrSingle, time.Second*5, 0)
|
|
}
|