1 Star 0 Fork 0

liuxuezhan / mylib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ActivityLogic.go 27.25 KB
一键复制 编辑 原始数据 按行查看 历史
liuxuezhan 提交于 2020-12-19 16:15 . 'ok'
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
package ActivityManager
import (
"fmt"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
"gitee.com/liuxuezhan/mylib/ActivityServer/CSV"
"gitee.com/liuxuezhan/mylib/ActivityServer/DB"
"gitee.com/liuxuezhan/mylib/ActivityServer/rpcClient"
proto "gitee.com/liuxuezhan/mylib/Protocol"
"gitee.com/liuxuezhan/mylib/Utils/wlog"
"gitee.com/liuxuezhan/mylib/Utils/wsort"
"gitee.com/liuxuezhan/mylib/common"
"gitee.com/liuxuezhan/mylib/wtime"
)
/// 活动实例
type ActivityInstance struct {
ActivityBase
Contents map[uint32] /*contentID*/ *ActivityContents
ScoreData map[uint64] /*userID*/ *ActivityScoreUser
sortTime uint64
sync.RWMutex
}
var MapActivityInstance = make(map[uint32]*ActivityInstance)
func (o *ActivityInstance) makeFullData() *proto.ST_ActivityInfo_PB {
fuData := o.ActivityBase.makeFullData()
for _, de := range o.Contents {
fuData.DeData = append(fuData.DeData, de.DeData)
}
for _, sc := range o.ScoreData {
fuData.ScUser = append(fuData.ScUser, sc.ScData)
}
return fuData
}
func (o *ActivityInstance) init(csvData *CSV.CF_Activity_DataEntry) bool {
o.Lock()
defer o.Unlock()
if csvData == nil {
return false
}
o.activityType = uint32(csvData.ActivityType)
o.csvData = csvData
if !o.parseConfig() {
wlog.Error("Activity Init FAILED, Type", o.activityType)
return false
}
//if !o.parseContentConfig(0) {
// wlog.Error("Activity Parse Content FAILED, Type", o.activityType)
// return false
//}
wlog.Info("Activity Init SUCCESS, Type", o.activityType)
return true
}
func (o *ActivityInstance) start(params []interface{}) {
if o.asset.GetActivityId() == 100001 || o.asset.GetActivityId() == 100002 {
return
}
o.Lock()
defer o.Unlock()
// wlog.Info(".................................Activity start run...............[ID, serial]", o.csvData.ID, o.asset.GetNumber())
groupID := getNextActivityGroupId(o.config.GroupRateList, o.csvData.Random == 1, o.asset.GetGroupId())
if groupID == 0 {
wlog.Error("activity group id err", groupID)
return
}
if !o.parseContentConfig(groupID) {
return
}
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.GroupId = proto.SetUint32(groupID)
o.Contents = make(map[uint32]*ActivityContents)
o.ScoreData = make(map[uint64]*ActivityScoreUser)
ManagerInstance.runActivity(o)
DB.ScoreNormalObj.DeleteDatasNotSerial(o.GetIndex(), o.asset.GetNumber())
svrType := rpcClient.OneServer
if o.GetCSVData().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)
// wlog.Info("-------------------------------------------------------------------------")
// wlog.Info("ContentID: ", o.asset.GetGroupId())
// wlog.Info("Contents: ", o.config.ContentConfig)
}
func (o *ActivityInstance) updateStage(params []interface{}) {
if o.asset.GetActivityId() == 100001 || o.asset.GetActivityId() == 100002 {
return
}
o.Lock()
defer o.Unlock()
now := wtime.GetNow()
//if now < o.asset.GetStagetEndTime() && o.asset.GetStagetEndTime() != 0 {
// wlog.Error("Time not come BUT Ticked ", o.csvData.ID, o.asset.GetStage())
// return
//}
newStage := ^uint32(0)
switch o.asset.GetStage() { /// 当前阶段 到 下一阶段 的 节点
case uint32(ActivityStage_AS_CloseStage):
ManagerInstance.setTimeFunction(o.GetID(), o.asset.GetServerID(), 1, []interface{}{}, o.start)
return
case uint32(proto.ActivityStage_AS_NoticeStage):
newStage = uint32(proto.ActivityStage_AS_PrepareStage)
case uint32(proto.ActivityStage_AS_PrepareStage):
newStage = uint32(proto.ActivityStage_AS_ProcessingStage)
case uint32(proto.ActivityStage_AS_ProcessingStage):
/// 生成排行榜
o.checkToplist(true)
/// 根据排名给玩家发奖励做在游戏服务器
newStage = uint32(proto.ActivityStage_AS_RewerdStage)
case uint32(proto.ActivityStage_AS_RewerdStage):
newStage = uint32(proto.ActivityStage_AS_StopStaget)
case uint32(proto.ActivityStage_AS_StopStaget): /// 在这里会下发通知
if o.csvData.Cycle == 1 {
ManagerInstance.setTimeFunction(o.GetID(), o.asset.GetServerID(), 1, []interface{}{}, o.start)
return
}
ManagerInstance.setTimeFunction(o.GetID(), o.asset.GetServerID(), 1, []interface{}{}, o.stop)
//o.stop([]interface{}{serverID})
return
default:
break
wlog.Error("Error Stage for Activity: ", o.GetID(), o.asset.GetServerID())
}
if newStage == ActivityStage_AS_CloseStage {
return
}
o.asset.Stage = proto.SetUint32(newStage)
tmps := strings.Split(o.asset.GetTime(), "|")
v := common.StringToUint64(tmps[newStage])
o.asset.StageStartTime = proto.SetUint64(now)
o.asset.StagetEndTime = proto.SetUint64(now + v)
// wlog.Info("...........................nowTime,endTime,ID", now, o.asset.GetStagetEndTime(), o.csvData.ID)
wlog.Error("ST_Activity_PB update2: ", o.idx, o.asset.GetServerID(), o.asset.GetActivityId(), o.asset.GetStage(), o.asset.GetStageStartTime(), o.asset.GetStagetEndTime())
/// 阶段更新
svType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svType = rpcClient.AllServer
}
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_Update)),
ActivityID: proto.SetUint32(o.asset.GetActivityId()),
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()),
}
newData := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- newData
if v <= 0 {
v = 1
}
ManagerInstance.setTimeFunction(o.GetID(), o.asset.GetServerID(), v, []interface{}{}, o.updateStage)
}
func (o *ActivityInstance) UpdateStage2(ActivityType uint32) {
now_next := uint64(Get_StartTime(ActivityType, int64(wtime.GetNow())).Unix())
o.Lock()
defer o.Unlock()
send := false
now := wtime.GetNow()
end_next := uint64(Get_StartTime(o.activityType, int64(o.asset.GetStagetEndTime())).Unix())
if end_next > now_next {
end_next = now_next
}
wlog.Info(o.asset.GetActivityId(), o.asset.GetServerID(), o.asset.GetNumber(),
proto.ActivityStage(o.GetAssetData().GetStage()),
time.Unix(int64(o.GetAssetData().GetStageStartTime()), 0).Format(time.RFC3339),
time.Unix(int64(o.GetAssetData().GetStagetEndTime()), 0).Format(time.RFC3339))
if o.asset.GetStagetEndTime() > end_next {
o.asset.StagetEndTime = proto.SetUint64(end_next)
send = true
}
//时间段修正
if o.asset.GetStageStartTime() > o.asset.GetStagetEndTime() {
o.asset.StageStartTime = proto.SetUint64(o.asset.GetStagetEndTime())
send = true
}
//当前时间修正
if o.asset.GetStageStartTime() > now {
o.asset.StageStartTime = proto.SetUint64(now)
send = true
}
for now >= o.asset.GetStagetEndTime() && o.asset.GetStage() != uint32(proto.ActivityStage_AS_StopStaget) {
o.Update_Stage(now_next)
send = true
}
if send {
o.SendStage(uint32(proto.ActivityDataType_ADT_Update))
}
}
func (o *ActivityInstance) Update_Stage(now_next uint64) {
now := wtime.GetNow()
end_next := uint64(Get_StartTime(o.activityType, int64(o.asset.GetStagetEndTime())).Unix())
if end_next > now_next {
end_next = now_next
}
wlog.Info("processActivityScore next->", o.asset.GetActivityId(), time.Unix(int64(o.asset.GetStagetEndTime()), 0).Format(time.RFC3339), time.Unix(int64(end_next), 0).Format(time.RFC3339))
if o.asset.GetStagetEndTime() > end_next {
o.asset.StagetEndTime = proto.SetUint64(end_next)
}
//时间段修正
if o.asset.GetStageStartTime() > o.asset.GetStagetEndTime() {
o.asset.StageStartTime = proto.SetUint64(o.asset.GetStagetEndTime())
}
//当前时间修正
if o.asset.GetStageStartTime() > now {
o.asset.StageStartTime = proto.SetUint64(now)
}
switch o.asset.GetStage() { /// 当前阶段结束
case uint32(proto.ActivityStage_AS_NoticeStage):
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_PrepareStage))
a := o.asset.GetStagetEndTime()
b := uint64(a + o.config.StageTime[o.asset.GetStage()])
o.asset.StageStartTime = proto.SetUint64(a)
o.asset.StagetEndTime = proto.SetUint64(b)
case uint32(proto.ActivityStage_AS_PrepareStage):
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_ProcessingStage))
a := o.asset.GetStagetEndTime()
b := uint64(a + o.config.StageTime[o.asset.GetStage()])
o.asset.StageStartTime = proto.SetUint64(a)
o.asset.StagetEndTime = proto.SetUint64(b)
case uint32(proto.ActivityStage_AS_ProcessingStage):
/// 生成排行榜
o.checkToplist(true)
/// 根据排名给玩家发奖励做在游戏服务器
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_RewerdStage))
a := o.asset.GetStagetEndTime()
b := uint64(a + o.config.StageTime[o.asset.GetStage()])
o.asset.StageStartTime = proto.SetUint64(a)
o.asset.StagetEndTime = proto.SetUint64(b)
o.SendStage(uint32(proto.ActivityDataType_ADT_Update))
case uint32(proto.ActivityStage_AS_RewerdStage), uint32(ActivityStage_AS_CloseStage):
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_StopStaget))
a := o.asset.GetStagetEndTime()
b := uint64(end_next)
if a < b {
o.asset.StageStartTime = proto.SetUint64(a)
o.asset.StagetEndTime = proto.SetUint64(b)
} else {
o.asset.StageStartTime = proto.SetUint64(b)
o.asset.StagetEndTime = proto.SetUint64(b)
}
case uint32(proto.ActivityStage_AS_StopStaget):
groupID := getNextActivityGroupId(o.config.GroupRateList, o.csvData.Random == 1, o.asset.GetGroupId())
if groupID == 0 {
wlog.Error("processActivityScore:", o.asset.GetGroupId())
return
}
if !o.parseContentConfig(groupID) {
wlog.Error("processActivityScore:", groupID)
return
}
o.asset.GroupId = proto.SetUint32(groupID)
o.asset.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_NoticeStage))
a := o.asset.GetStagetEndTime()
b := uint64(a + o.config.StageTime[uint32(proto.ActivityStage_AS_NoticeStage)])
o.asset.StageStartTime = proto.SetUint64(a)
o.asset.StagetEndTime = proto.SetUint64(b)
o.Contents = make(map[uint32]*ActivityContents)
o.ScoreData = make(map[uint64]*ActivityScoreUser)
// o.loadScoreData()
o.asset.Number = proto.SetUint32(o.asset.GetNumber() + 1)
default:
wlog.Error("Error Stage for Activity: ", o.GetID(), o.asset.GetServerID())
return
}
/*
wlog.Info("processActivityScore new->", o.asset.GetServerID(), o.asset.GetActivityId(), o.asset.GetNumber(),
proto.ActivityStage(o.GetAssetData().GetStage()),
time.Unix(int64(o.GetAssetData().GetStageStartTime()), 0).Format(time.RFC3339),
time.Unix(int64(o.GetAssetData().GetStagetEndTime()), 0).Format(time.RFC3339))
*/
}
func (o *ActivityInstance) SendStage(tp uint32) {
// 阶段更新
svType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svType = rpcClient.AllServer
}
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(tp),
ActivityID: proto.SetUint32(o.asset.GetActivityId()),
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()),
}
newData := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- newData
}
func (o *ActivityInstance) stop(params []interface{}) {
if o.asset.GetActivityId() == 100001 || o.asset.GetActivityId() == 100002 {
return
}
o.Lock()
defer o.Unlock()
wlog.Info("Activity Go End............................", o.GetID())
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)
svType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svType = rpcClient.AllServer
}
newData := &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 <- newData
}
/// 这个函数,asset里面可能有排行榜数据,但是应该专门从数据库load一次。
func (o *ActivityInstance) reload(idx uint32, asset *proto.ST_Activity_PB /*, now uint64*/) {
o.Lock()
defer o.Unlock()
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)
o.loadScoreData()
o.parseContentConfig(o.asset.GetGroupId())
}
func (o *ActivityInstance) loadScoreData() {
o.Contents = make(map[uint32]*ActivityContents)
o.ScoreData = make(map[uint64]*ActivityScoreUser)
// 把o.Total的数据放进去
if o.asset.GetTotalList() != nil {
for _, sc := range o.asset.TotalList.GetScores() {
o.ScoreData[sc.GetUid()] = &ActivityScoreUser{
ScData: &proto.ST_ActivityScore_User{
Uid: proto.SetUint64(sc.GetUid()),
BaMember: &proto.ST_MemberInfo_Base{
UID: proto.SetUint64(sc.GetUid()),
Name: proto.SetString(sc.GetName()),
Luid: proto.SetUint64(sc.GetLuid()),
Lname: proto.SetString(sc.GetLname()),
Llname: proto.SetString(sc.GetLlname()),
},
BaScore: &proto.ST_ActivityScore_Base{
UID: proto.SetUint64(sc.GetUid()),
Score: proto.SetUint32(sc.GetScore()),
Content: proto.SetUint32(o.asset.TotalList.GetContentID()),
RankOrder: proto.SetUint32(sc.GetRankOrder()),
ScoreLevel: proto.SetUint32(0),
},
},
Dirty: true,
}
}
o.setDirty(true)
o.asset.TotalList = nil
o.Contents[o.asset.TotalList.GetContentID()] = &ActivityContents{
DeData: &proto.ST_ActivityContent_PB{
ContentID: proto.SetUint32(o.asset.TotalList.GetContentID()),
},
}
}
deDatas := make([]*proto.ST_ActivityContent_PB, 0)
DB.LoadActivityDetails(o.idx, &deDatas)
for _, v := range deDatas {
o.Contents[v.GetContentID()] = &ActivityContents{DeData: v, Dirty: false}
}
scDatas := make([]*proto.ST_ActivityScore_User, 0)
DB.LoadActivityScores(o.idx, o.asset.GetNumber(), &scDatas)
for _, v := range scDatas {
_, ok := o.Contents[v.BaScore.GetContent()]
if !ok {
// wlog.Error("Parse ScoreData Error while LOADing...[content, user]", v.BaScore.GetContent(), v.GetUid())
continue
}
// 不再放到detail里面了
o.ScoreData[v.GetUid()] = &ActivityScoreUser{ScData: v, Dirty: false}
}
}
func (o *ActivityInstance) parseContentConfig(gID uint32) bool {
o.config.ContentConfig = make(map[uint32]*ActivityContentConfig)
for _, v := range CSV.CSV_ActivityContent.GetIDList() {
conf := CSV.CSV_ActivityContent.GetEntryPtr(v)
if uint32(conf.ActivityGroup) != gID {
continue
}
confContent := &ActivityContentConfig{
LevelLimit: make([]uint32, 0),
ScoreID: make([]int64, 0),
ScoreRewards: make([]*scoreConfig, 0),
RankRewards: make(map[int64]int64),
}
confContent.ScoreID = common.ParseStringToInt64List(conf.ScoreID)
scoreLevels := common.ParseStringToInt64List(conf.StageScoreGoal)
scoreRewards := common.ParseStringToInt64List(conf.StageRewardValue)
if len(scoreLevels) != len(scoreRewards) {
panic("StageRewardValue err LEN")
return false
}
for i := 0; i < len(scoreLevels); i++ {
//confContent.ScoreRewards[scoreLevels[i]] = scoreRewards[i]
confContent.ScoreRewards = append(confContent.ScoreRewards, &scoreConfig{
Score: uint32(scoreLevels[i]),
Reward: uint32(scoreRewards[i]),
})
}
if conf.RankRewardValue != "" {
for _, v := range common.ParseStringToVector3(conf.RankRewardValue) {
confContent.RankRewards[int64(v.GetX())] = int64(v.GetY())
}
}
tmp := strings.Split(conf.BaseLevelSegement, " ")
if len(tmp) != 2 {
panic("BaseLevelSegement err ")
return false
}
confContent.LevelLimit = append(confContent.LevelLimit, common.StringToUint32(tmp[0]), common.StringToUint32(tmp[1]))
o.config.ContentConfig[uint32(v)] = confContent
}
return true
}
func (o *ActivityInstance) UpdateScoreData(data *proto.ST_GS2AS_ActivityScore) {
//wlog.Info("ActivityNormal Update Score.........")
if o.asset.GetStage() != uint32(proto.ActivityStage_AS_ProcessingStage) {
return /// 不是阶段,不上分
}
if data.GetScData() == nil {
return
}
svType := rpcClient.OneServer
if o.asset.GetServerID() == 0 {
svType = rpcClient.AllServer
}
deData, ok := o.Contents[data.GetContentID()]
if !ok { /// 新Content角色,先创建De
newDE := &proto.ST_ActivityContent_PB{
ContentID: proto.SetUint32(data.GetContentID()),
//Scores: make([]*proto.ST_ActivityScore_PB, 0),
}
o.Contents[data.GetContentID()] = &ActivityContents{DeData: newDE}
//o.asset.Detail = append(o.asset.Detail, newDE) // asset里面不增加东西了
deData = o.Contents[data.GetContentID()]
o.setDirty(true)
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_Detail)),
ActivityID: proto.SetUint32(data.GetActiID()),
FuData: &proto.ST_ActivityInfo_PB{
DeData: make([]*proto.ST_ActivityContent_PB, 0),
},
DataVer: proto.SetUint64(atomic.AddUint64(&DataVer, 1)),
Time: proto.SetString(o.asset.GetTime()),
}
newMSG.FuData.DeData = append(newMSG.FuData.DeData, proto.Clone(deData.DeData).(*proto.ST_ActivityContent_PB))
deChan := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- deChan
}
/// deTail
scUser, ok := o.ScoreData[data.ScData.GetUid()]
if !ok {
newSC := proto.Clone(data.GetScData()).(*proto.ST_ActivityScore_User)
o.ScoreData[data.ScData.GetUid()] = &ActivityScoreUser{ScData: newSC}
//deData.DeData.Scores = append(deData.DeData.Scores, newSC)
scUser = o.ScoreData[data.ScData.GetUid()]
scUser.SetDirty(true)
} else {
if data.ScData.BaScore.GetScore() <= scUser.ScData.BaScore.GetScore() {
return
}
/// 把玩家数据更新了
scUser.ScData.BaScore.Score = proto.SetUint32(data.ScData.BaScore.GetScore())
scUser.SetDirty(true)
}
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_ScUser)),
ActivityID: proto.SetUint32(data.GetActiID()),
FuData: &proto.ST_ActivityInfo_PB{
ScUser: make([]*proto.ST_ActivityScore_User, 0),
},
DataVer: proto.SetUint64(atomic.AddUint64(&DataVer, 1)),
Time: proto.SetString(o.asset.GetTime()),
}
newMSG.FuData.ScUser = append(newMSG.FuData.ScUser, proto.Clone(scUser.ScData).(*proto.ST_ActivityScore_User))
scChan := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- scChan
/// 积分阶段更新
confContent, ok := o.config.ContentConfig[deData.DeData.GetContentID()]
if ok {
oldLv := scUser.ScData.BaScore.GetScoreLevel()
newLv := calcScoreLevel(scUser.ScData.BaScore.GetScore(), confContent)
if newLv <= oldLv {
return
}
//wlog.Info("User ScoreLevel.............................", o.GetID())
scUser.ScData.BaScore.ScoreLevel = proto.SetUint32(newLv)
newMSG := &proto.ST_AS2GS_Activity_ScoreLevel{
ActiID: proto.SetUint32(o.GetID()),
UserID: proto.SetUint64(scUser.ScData.GetUid()),
Old: proto.SetUint32(oldLv),
New: proto.SetUint32(newLv),
}
lvChan := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.asset.GetServerID(),
ServerType: svType,
}
rpcClient.BroadChan <- lvChan
}
}
func (o *ActivityInstance) detailToDoc(de *ActivityContents) (string, interface{}) {
doc := &DB.ActivityDetailDocument{}
doc.ID = fmt.Sprintf("%d|%d", o.GetID(), de.DeData.GetContentID())
doc.IDx = o.GetIndex()
doc.ContentID = de.DeData.GetContentID()
doc.Detail = proto.Marshal(de.DeData)
de.SetDirty(false)
return doc.ID, doc
}
func (o *ActivityInstance) checkSave(exit bool) {
if o.isDirty {
doc := o.assetToDoc()
o.setDirty(false)
DB.UpsertActivityData(o.GetIndex(), doc)
}
for _, de := range o.Contents {
if !de.Dirty {
continue
}
_ID, deDoc := o.detailToDoc(de)
DB.UpsertActivityDetailData(_ID, o.GetIndex(), de.DeData.GetContentID(), deDoc)
}
for uid, sc := range o.ScoreData {
if !sc.Dirty {
continue
}
sc.SetDirty(false)
scDoc := &DB.NormalScoreDocument{}
scDoc.ID = fmt.Sprintf("%d|%d", o.GetID(), uid)
scDoc.ContentID = sc.ScData.BaScore.GetContent()
scDoc.SerialID = o.asset.GetNumber()
scDoc.UserID = uid
scDoc.ScoreData = proto.Marshal(sc.ScData)
scDoc.ActivityIdx = o.GetIndex()
DB.UpsertActivityScoreNormal(scDoc.ID, o.GetIndex(), uid, scDoc)
}
}
func (o *ActivityInstance) checkToplist(on bool) {
if !on && wtime.GetNow() < o.sortTime {
wlog.Warning("Not Time CheckTopList")
return
}
type rankStruct struct {
scoreMap map[uint64] /*uID*/ uint64
datasMap map[uint64] /*uID*/ *proto.ST_ActivityScore_User
rankList []*proto.ST_ActivityScore_User
}
svrType := rpcClient.OneServer
if o.csvData.CrossService == 1 {
svrType = rpcClient.AllServer
}
rankTables := make(map[uint32] /*contentID*/ *rankStruct)
//wlog.Info("rankData size......................[actiID,size]", o.GetID(), len(o.ScoreData))
for _, sc := range o.ScoreData {
if sc.ScData.BaScore.GetScore() <= 0 {
continue
}
// 把玩家归类到不同的content的组里面
contentID := sc.ScData.BaScore.GetContent()
if o.csvData.ExtraFlag&int64(proto.ActivityFlags_AF_OneTopList) != 0 {
contentID = o.asset.GetActivityId()
}
tabData, ok := rankTables[contentID]
if !ok {
rankTables[contentID] = &rankStruct{
scoreMap: make(map[uint64]uint64),
datasMap: make(map[uint64]*proto.ST_ActivityScore_User),
rankList: make([]*proto.ST_ActivityScore_User, 0),
}
tabData = rankTables[contentID]
}
tabData.scoreMap[sc.ScData.GetUid()] = uint64(sc.ScData.BaScore.GetScore())
tabData.datasMap[sc.ScData.GetUid()] = sc.ScData
}
// 给每个Content排行
//wlog.Info("rankTable size......................[actiID,size]", o.GetID(), len(rankTables))
for cID, rTab := range rankTables {
sortItems := wsort.NewMapSorter(rTab.scoreMap)
sort.Sort(sort.Reverse(sortItems))
for k, v := range sortItems {
scData, ok := rTab.datasMap[v.Key]
if !ok {
continue
}
scData.BaScore.RankOrder = proto.SetUint32(uint32(k) + 1)
rTab.rankList = append(rTab.rankList, scData)
if sc, ok := o.ScoreData[v.Key]; ok {
sc.SetDirty(true)
}
}
newMSG := &proto.ST_AS2GS_ActivityRank{
ActiID: proto.SetUint32(o.asset.GetActivityId()),
RankData: &proto.ST_ActivityRank_PB{
ContentID: proto.SetUint32(cID),
UserScore: rTab.rankList,
LeagueScore: make([]*proto.ST_ActivityRank_League, 0),
LeagueUser: make([]*proto.ST_ActivityRank_LeagueUser, 0),
NextFresh: proto.SetUint64(o.sortTime),
},
Reward: proto.SetBool(on),
}
newChan := &rpcClient.ChanData{
ServerID: o.asset.GetServerID(),
ServerType: svrType,
MsgData: newMSG,
}
rpcClient.BroadChan <- newChan
}
}
func ActivityLogic_updateStage() {
DB.ActivityObj.Range(false, func(o *proto.ST_Activity_PB) bool {
csvData := CSV.CSV_Activity.GetEntryPtr(int64(o.GetActivityId()))
if csvData == nil {
return false
}
if o.GetStage() == uint32(proto.ActivityStage_AS_OffStage) {
return true
}
if csvData.LogicType != int64(proto.ActivityLogicType_ALT_UserTaskRank) &&
csvData.LogicType != int64(proto.ActivityLogicType_ALT_LeagueTaskRank) &&
csvData.LogicType != int64(proto.ActivityLogicType_ALT_DailyTask) {
return false
}
if o.GetStagetEndTime() < o.GetStageStartTime() {
o.StagetEndTime = proto.SetUint64(o.GetStageStartTime())
}
now := wtime.GetNow()
if now < o.GetStageStartTime() {
o.StagetEndTime = proto.SetUint64(o.GetStagetEndTime() - o.GetStageStartTime() + now)
o.StageStartTime = proto.SetUint64(now)
}
if csvData.OpenType == int64(proto.ActivityOpenType_AOT_Stop) {
o.Stage = proto.SetUint32(uint32(proto.ActivityStage_AS_OffStage))
}
if now >= o.GetStagetEndTime() {
tmps := strings.Split(o.GetTime(), "|")
newStage := uint32(proto.ActivityStage_AS_OffStage)
switch o.GetStage() {
case uint32(proto.ActivityStage_AS_OffStage):
case uint32(proto.ActivityStage_AS_InitStage):
newStage = uint32(proto.ActivityStage_AS_NoticeStage)
case uint32(proto.ActivityStage_AS_NoticeStage):
newStage = uint32(proto.ActivityStage_AS_PrepareStage)
case uint32(proto.ActivityStage_AS_PrepareStage):
newStage = uint32(proto.ActivityStage_AS_ProcessingStage)
case uint32(proto.ActivityStage_AS_ProcessingStage):
newStage = uint32(proto.ActivityStage_AS_RewerdStage)
case uint32(proto.ActivityStage_AS_RewerdStage):
newStage = uint32(proto.ActivityStage_AS_StopStaget)
case uint32(proto.ActivityStage_AS_StopStaget):
if csvData.Cycle == 1 {
newStage = uint32(proto.ActivityStage_AS_NoticeStage)
} else {
newStage = uint32(proto.ActivityStage_AS_OffStage)
}
o.Number = proto.SetUint32(o.GetNumber() + 1)
default:
wlog.Error("Error Stage for Activity: ")
}
o.Stage = proto.SetUint32(newStage)
if newStage == uint32(proto.ActivityStage_AS_OffStage) {
} else {
o.StageStartTime = proto.SetUint64(now)
if newStage == uint32(proto.ActivityStage_AS_StopStaget) {
now = wtime.GetTodayZeroClock()
}
o.StagetEndTime = proto.SetUint64(now + common.StringToUint64(tmps[newStage]))
}
SendStage2(o)
}
return true
})
}
func SendStage2(o *proto.ST_Activity_PB) {
/// 阶段更新
wlog.Info(o.GetActivityId(), o.GetServerID(), o.GetNumber(),
proto.ActivityStage(o.GetStage()),
time.Unix(int64(o.GetStageStartTime()), 0).Format(time.RFC3339),
time.Unix(int64(o.GetStagetEndTime()), 0).Format(time.RFC3339))
newMSG := &proto.ST_AS2GS_ActivityUpdate{
Tp: proto.SetUint32(uint32(proto.ActivityDataType_ADT_Update)),
ActivityID: proto.SetUint32(o.GetActivityId()),
FuData: &proto.ST_ActivityInfo_PB{
BaData: proto.Clone(o).(*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.GetTime()),
}
newData := &rpcClient.ChanData{
MsgData: newMSG,
ServerID: o.GetServerID(),
ServerType: rpcClient.OneServer,
}
rpcClient.BroadChan <- newData
wlog.Info("Stage Update, To Send............................")
}
1
https://gitee.com/liuxuezhan/mylib.git
git@gitee.com:liuxuezhan/mylib.git
liuxuezhan
mylib
mylib
v1.1.3

搜索帮助

53164aa7 5694891 3bd8fe86 5694891