1 Star 0 Fork 0

liuxuezhan / mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
DailyTaskLogic.go 4.30 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
package ActivityManager
import (
"strings"
"sync/atomic"
"gitee.com/liuxuezhan/mylib/ActivityServer/CSV"
"gitee.com/liuxuezhan/mylib/ActivityServer/rpcClient"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
)
type DailyTaskInstance struct {
ActivityBase
}
func (o *DailyTaskInstance) parseConfig() bool {
config := &ActivityConfig{
GroupRateList: make([]*GroupRate, 0),
ContentConfig: make(map[uint32]*ActivityContentConfig),
Params: make(map[string]interface{}),
}
o.config = config
//wlog.Info("---------------------------------DailyTask Activity Config Parsed", o.csvData.ID, len(o.config.GroupRateList))
return true
}
func (o *DailyTaskInstance) init(csvData *CSV.CF_Activity_DataEntry) bool {
if csvData == nil {
return false
}
o.activityType = uint32(csvData.ActivityType)
o.csvData = csvData
if !o.parseConfig() {
wlog.Error("DailyTask Activity Init FAILED, Type", o.activityType)
return false
}
wlog.Info("DailyTask Activity Init SUCCESS, Type", o.activityType)
return true
}
func (o *DailyTaskInstance) start(params []interface{}) {
//wlog.Info("++++++++++++++++++++++++ DailyTask start run.", o.csvData.ID, o.asset.GetNumber())
now := wtime.GetNow()
tmps := strings.Split(o.asset.GetTime(), "|")
v := common.StringToUint64(tmps[int(proto.ActivityStage_AS_NoticeStage)])
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_NoticeStage))
o.asset.StageStartTime = proto.SetUint64(now)
o.asset.StagetEndTime = proto.SetUint64(now + v)
o.asset.Number = proto.SetUint32(o.asset.GetNumber() + 1)
svrType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svrType = rpcClient.AllServer
}
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_Create)),
ActivityID: proto.SetUint32(o.asset.GetActivityId()),
FuData: &proto.ST_ActivityInfo_PB{
BaData: proto.Clone(o.asset).(*proto.ST_Activity_PB),
DeData: make([]*proto.ST_ActivityContent_PB, 0),
ScUser: make([]*proto.ST_ActivityScore_User, 0),
},
DataVer: proto.SetUint64(atomic.AddUint64(&DataVer, 1)),
Time: proto.SetString(o.asset.GetTime()),
}
newData := &rpcClient.ChanData{
ServerType: svrType,
ServerID: o.asset.GetServerID(),
MsgData: newMSG,
}
rpcClient.BroadChan <- newData
ManagerInstance.setTimeFunction(o.GetID(), o.asset.GetServerID(), v, []interface{}{}, o.updateStage)
}
func (o *DailyTaskInstance) updateStage(params []interface{}) {
}
/*func (o *DailyTaskInstance)setStage(stage proto.ActivityStage) {
o.ActivityBase.setStage(stage)
v := o.config.StageTime[uint32(stage)]
if v <= 0 { v = 1 }
ManagerInstance.setTimeFunction(o.GetID(), o.GetAssetData().GetServerID(), v, []interface{}{}, o.updateStage)
}*/
func (o *DailyTaskInstance) stop(params []interface{}) {
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_StopStaget))
o.asset.StageStartTime = proto.SetUint64(wtime.GetNow())
tmps := strings.Split(o.asset.GetTime(), "|")
cost := common.StringToUint64(tmps[int(proto.ActivityStage_AS_StopStaget)])
o.asset.StagetEndTime = proto.SetUint64(wtime.GetNow() + cost)
//wlog.Info("DailyTask Go End............................", o.GetID())
svType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svType = rpcClient.AllServer
}
newChan := &rpcClient.ChanData{
MsgData: &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_Update)),
ActivityID: proto.SetUint32(o.GetID()),
FuData: &proto.ST_ActivityInfo_PB{
BaData: proto.Clone(o.GetAssetData()).(*proto.ST_Activity_PB),
},
DataVer: proto.SetUint64(atomic.AddUint64(&DataVer, 1)),
Time: proto.SetString(o.asset.GetTime()),
},
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- newChan
}
func (o *DailyTaskInstance) reload(idx uint32, asset *proto.ST_Activity_PB /*, now uint64*/) {
if asset == nil {
wlog.Error("Data not form while reloading...")
return
}
if idx == 0 {
idx = newIndex()
}
o.setDirty(true)
o.SetIndex(idx)
o.asset = proto.Clone(asset).(*proto.ST_Activity_PB)
}
func (o *DailyTaskInstance) loadScoreData() {
//o.ScoreData = make([]*proto.ST_ActivityDetail_PB, 0)
//DB.LoadDailyTaskScores(o.idx, o.asset.GetNumber(), o.ScoreData)
}
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.3

搜索帮助