|
|
@@ -10,7 +10,7 @@ import (
|
|
|
"sort"
|
|
|
)
|
|
|
|
|
|
-//远航试炼
|
|
|
+// 远航试炼
|
|
|
const (
|
|
|
YuanHangTrialViewMaxNum = 200 //最大客户端可视列表数量
|
|
|
|
|
|
@@ -59,7 +59,7 @@ func (this *yuanHangTrialList) binarySearch(leftIndex, rightIndex int, findVal u
|
|
|
return middle
|
|
|
}
|
|
|
|
|
|
-//minheap
|
|
|
+// minheap
|
|
|
type TrailItemMinHeap struct {
|
|
|
ItemList []*serverproto.YuanHangTrialData
|
|
|
}
|
|
|
@@ -84,7 +84,7 @@ func (h *TrailItemMinHeap) Pop() (ret interface{}) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-////
|
|
|
+// //
|
|
|
type YuanHangTrialManager struct {
|
|
|
trailItemMinHeap *TrailItemMinHeap
|
|
|
tailItemLeftList *TrailItemMinHeap //超过200后的存储列表(排序)
|
|
|
@@ -111,31 +111,33 @@ func newYuanHangTrialManager() *YuanHangTrialManager {
|
|
|
cacheFightRoleInfoList: map[uint64]*serverproto.FightRoleInfo{},
|
|
|
dbChangeTrialItemList: set.New(set.NonThreadSafe),
|
|
|
}
|
|
|
- mag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 1000)
|
|
|
+ mag.updateTimer = util.NewDurationTimer(util.GetCurrentTime(), 3000)
|
|
|
heap.Init(mag.trailItemMinHeap)
|
|
|
heap.Init(mag.tailItemLeftList)
|
|
|
|
|
|
return mag
|
|
|
}
|
|
|
func (this *YuanHangTrialManager) Update(ms uint64) {
|
|
|
- if !this.bInit {
|
|
|
- if this.initTrialDataFromDB() {
|
|
|
- this.bInit = true
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+ //if !this.bInit {
|
|
|
+ // if this.initTrialDataFromDB() {
|
|
|
+ // this.bInit = true
|
|
|
+ // }
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //util.InfoF("notifyList Trial5:%v", this.notifyList)
|
|
|
if !this.updateTimer.IsStart() || !this.updateTimer.IsExpired(ms) {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ this.initTrialDataFromDB()
|
|
|
+ //util.InfoF("notifyList Trial1:%v", this.notifyList)
|
|
|
this.refreshViewList(ms)
|
|
|
-
|
|
|
+ //util.InfoF("notifyList Trial2:%v", this.notifyList)
|
|
|
//save change uid
|
|
|
this.saveItemData()
|
|
|
-
|
|
|
+ //util.InfoF("notifyList Trial3:%v", this.notifyList)
|
|
|
//notify list
|
|
|
if len(this.notifyList) > 0 {
|
|
|
+ util.InfoF("notifyList Trial4:%v", this.notifyList)
|
|
|
ssNotifyMsg := &serverproto.SSCrossYuanHangTrialViewNtf{}
|
|
|
ssNotifyMsg.TrialViewList = append(ssNotifyMsg.TrialViewList, this.notifyList...)
|
|
|
SendAllZoneSocial(ssNotifyMsg)
|
|
|
@@ -144,7 +146,7 @@ func (this *YuanHangTrialManager) Update(ms uint64) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//服务器启动时数据初始化
|
|
|
+// 服务器启动时数据初始化
|
|
|
func (this *YuanHangTrialManager) initTrialDataFromDB() bool {
|
|
|
tmpItemList, bOk := GetTrialItemFromRedis()
|
|
|
if !bOk {
|
|
|
@@ -156,13 +158,28 @@ func (this *YuanHangTrialManager) initTrialDataFromDB() bool {
|
|
|
})
|
|
|
|
|
|
for idx := 0; idx < len(tmpItemList); idx++ {
|
|
|
- if idx < YuanHangTrialViewMaxNum {
|
|
|
- heap.Push(this.trailItemMinHeap, tmpItemList[idx])
|
|
|
- } else {
|
|
|
- heap.Push(this.tailItemLeftList, tmpItemList[idx])
|
|
|
+ if _, ok := this.trialItemMapList[tmpItemList[idx].Uid]; ok {
|
|
|
+ continue
|
|
|
}
|
|
|
+ //if idx < YuanHangTrialViewMaxNum {
|
|
|
+ // heap.Push(this.trailItemMinHeap, tmpItemList[idx])
|
|
|
+ //} else {
|
|
|
+ heap.Push(this.tailItemLeftList, tmpItemList[idx])
|
|
|
+ //}
|
|
|
+ util.InfoF("addtrailItem info=%v", tmpItemList[idx])
|
|
|
this.trialItemMapList[tmpItemList[idx].Uid] = tmpItemList[idx]
|
|
|
}
|
|
|
+
|
|
|
+ list, _ := GetBeChallengeFromRedis()
|
|
|
+ if list == nil || len(list) == 0 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ //通知被挑战者
|
|
|
+ util.InfoF("addBeChallengeLog list=%v", list)
|
|
|
+ for _, v := range list {
|
|
|
+ SendZoneSocial(v, 0)
|
|
|
+ }
|
|
|
+
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
@@ -295,7 +312,7 @@ func (this *YuanHangTrialManager) getFightRoleInfo(uid uint64) *serverproto.Figh
|
|
|
return fightInfo
|
|
|
}
|
|
|
|
|
|
-//获取远航可视列表
|
|
|
+// 获取远航可视列表
|
|
|
func (this *YuanHangTrialManager) GetTrialViewList(bViewList bool, uidTrialInfo uint64) ([]*serverproto.YuanHangTrialData, *serverproto.YuanHangTrialData) {
|
|
|
if uidTrialInfo > 0 {
|
|
|
if item, ok := this.trialItemMapList[uidTrialInfo]; ok {
|
|
|
@@ -314,7 +331,7 @@ func (this *YuanHangTrialManager) GetTrialViewList(bViewList bool, uidTrialInfo
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
-//发起远航试炼
|
|
|
+// 发起远航试炼
|
|
|
// @trialType 远航类型 (1,2,3,4,5...)
|
|
|
func (this *YuanHangTrialManager) YuanHangTrial(fromZone int32, uid uint64, trialType int32, endTimeStamp uint64,
|
|
|
fightInfo *serverproto.FightRoleInfo, durationTime int32) *serverproto.YuanHangTrialData {
|
|
|
@@ -332,7 +349,7 @@ func (this *YuanHangTrialManager) YuanHangTrial(fromZone int32, uid uint64, tria
|
|
|
return addTrialItem
|
|
|
}
|
|
|
|
|
|
-//非正常情况下不调用该接口
|
|
|
+// 非正常情况下不调用该接口
|
|
|
func (this *YuanHangTrialManager) YuanHangTrialForceSelf(ssMsg *serverproto.SSCrossYuanHangTrialSelfReq, fromZone int32) {
|
|
|
_, ok := this.trialItemMapList[ssMsg.SelfUid]
|
|
|
if !ok {
|
|
|
@@ -352,9 +369,9 @@ func (this *YuanHangTrialManager) YuanHangTrialForceSelf(ssMsg *serverproto.SSCr
|
|
|
SetFightInfoToRedis(ssMsg.SelfUid, ssMsg.SelfFightInfo)
|
|
|
}
|
|
|
|
|
|
-//飞艇信息
|
|
|
-//trialUid 飞艇对应玩家
|
|
|
-//trialUidEndTime 当前玩家飞艇对应的结束时间
|
|
|
+// 飞艇信息
|
|
|
+// trialUid 飞艇对应玩家
|
|
|
+// trialUidEndTime 当前玩家飞艇对应的结束时间
|
|
|
func (this *YuanHangTrialManager) GetTrialInfo(trialUid, trialUidEndTime uint64) (serverproto.ErrorCode, *serverproto.YuanHangTrialData) {
|
|
|
trialItem, ok := this.trialItemMapList[trialUid]
|
|
|
if !ok {
|
|
|
@@ -417,7 +434,7 @@ func (this *YuanHangTrialManager) GetChallengeTrialItem(selfUid, challengeUid, c
|
|
|
return serverproto.ErrorCode_ERROR_OK
|
|
|
}
|
|
|
|
|
|
-//挑战结果通知
|
|
|
+// 挑战结果通知
|
|
|
func (this *YuanHangTrialManager) ChallengeTrialItemResult(selfUid, challengeUid, challengeUidEndTime uint64,
|
|
|
selfNickName string, selfZone int32, bWin bool, fightInfo *serverproto.FightRoleInfo, ssAckMsg *serverproto.SSCrossYuanHangTrialChallengeResultAck) serverproto.ErrorCode {
|
|
|
|
|
|
@@ -473,7 +490,7 @@ func (this *YuanHangTrialManager) UpdateRankScore(uid, rankScore uint64) {
|
|
|
UpdateTrialRankScore(uid, rankScore)
|
|
|
}
|
|
|
|
|
|
-//远航试炼排行榜
|
|
|
+// 远航试炼排行榜
|
|
|
func (this *YuanHangTrialManager) GetTrialRankList(uid uint64, startIdx int32,
|
|
|
ssAckMsg *serverproto.SSCrossYuanHangTrialRankListAck) {
|
|
|
selfRank, selfScore, totalRank, rankList := GetTrialRankList(uid, startIdx)
|
|
|
@@ -505,5 +522,9 @@ func (this *YuanHangTrialManager) addBeChallengeLog(trialItem *serverproto.YuanH
|
|
|
}
|
|
|
|
|
|
util.InfoF("uid=%v addBeChallengeLog trialType=%v beAttackedUid=%v realZone=%v", targetPlayerUid, trialItem.TrialType, trialItem.Uid, trialItem.FromRealZone)
|
|
|
- SendZoneSocial(logNtf, trialItem.FromRealZone)
|
|
|
+ //SendZoneSocial(logNtf, trialItem.FromRealZone)
|
|
|
+ err := SetBeChallengeToRedis(trialItem.Uid, logNtf.LogData, trialItem.FromRealZone)
|
|
|
+ if err != nil {
|
|
|
+ util.ErrorF("uid=%v addBeChallengeLog error:%v", err)
|
|
|
+ }
|
|
|
}
|