锦标赛优化
This commit is contained in:
parent
41b381acd8
commit
a0baaa99df
@ -41,6 +41,7 @@ type ChampshipData struct {
|
||||
Robot map[int]*ChampshipRobot // 机器人
|
||||
PreRobot map[int]*ChampshipRobot // 机器人 备份
|
||||
ZeroTime int64
|
||||
Version int
|
||||
}
|
||||
|
||||
type ChampshipRank struct {
|
||||
@ -48,6 +49,7 @@ type ChampshipRank struct {
|
||||
Score float64
|
||||
Time int64
|
||||
Type int
|
||||
Rank int
|
||||
}
|
||||
|
||||
type ChampshipRobot struct {
|
||||
@ -96,6 +98,7 @@ func (c *ChampshipMgr) Init() {
|
||||
}
|
||||
// 注册处理函数
|
||||
c.init()
|
||||
c.version()
|
||||
now := GoUtil.Now()
|
||||
zeroTime := GoUtil.ZeroTimestamp()
|
||||
if c.getData().ZeroTime != zeroTime {
|
||||
@ -117,6 +120,34 @@ func (c *ChampshipMgr) Init() {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *ChampshipMgr) version() {
|
||||
if c.data.(*ChampshipData).Version == 0 {
|
||||
c.data.(*ChampshipData).Version = 1
|
||||
for _, v := range c.data.(*ChampshipData).Rank {
|
||||
sortChampionshipRank(v)
|
||||
}
|
||||
for _, v := range c.data.(*ChampshipData).PreRank {
|
||||
sortChampionshipRank(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sortChampionshipRank(rankList []*ChampshipRank) {
|
||||
rank := 1
|
||||
lastRank := 1
|
||||
lastScore := 0.0
|
||||
for _, v := range rankList {
|
||||
if v.Score == lastScore {
|
||||
v.Rank = lastRank
|
||||
} else {
|
||||
v.Rank = rank
|
||||
lastRank = rank
|
||||
lastScore = v.Score
|
||||
}
|
||||
rank++
|
||||
}
|
||||
}
|
||||
|
||||
// 每天零点30分通知所有在线玩家领取奖励
|
||||
func (c *ChampshipMgr) ZeroNotifyAll() (interface{}, error) {
|
||||
NotifyAllPlayerMsg(&msg.Msg{
|
||||
@ -230,6 +261,7 @@ func (c *ChampshipMgr) ai() (interface{}, error) {
|
||||
Robot.Time = now
|
||||
}
|
||||
r.Score += AddScore
|
||||
r.Score = math.Round(r.Score)
|
||||
} else {
|
||||
notify[r.Uid] = e
|
||||
}
|
||||
@ -242,6 +274,7 @@ func (c *ChampshipMgr) ai() (interface{}, error) {
|
||||
}
|
||||
return false
|
||||
})
|
||||
sortChampionshipRank(v)
|
||||
for e, r := range v {
|
||||
if r.Type == RANK_PLAYER_ROBOT {
|
||||
continue
|
||||
@ -284,7 +317,7 @@ func (c *ChampshipMgr) GetPreRankMsg(uid int) *proto.ResChampshipPreRank {
|
||||
RL := make(map[int32]*proto.ResPlayerRank, 0)
|
||||
for k, v := range RankList {
|
||||
if v.Uid == uid {
|
||||
myRank = k + 1
|
||||
myRank = v.Rank
|
||||
myScore = v.Score
|
||||
}
|
||||
if v.Type == RANK_PLAYER_ROBOT {
|
||||
@ -313,6 +346,7 @@ func (c *ChampshipMgr) GetPreRankMsg(uid int) *proto.ResChampshipPreRank {
|
||||
FurSet: int32(robot.FurSet),
|
||||
PetName: robot.PetName,
|
||||
Last: last,
|
||||
Rank: int32(v.Rank),
|
||||
}
|
||||
} else {
|
||||
simplePlayer := G_GameLogicPtr.GetSimplePlayerByUid(v.Uid)
|
||||
@ -340,6 +374,7 @@ func (c *ChampshipMgr) GetPreRankMsg(uid int) *proto.ResChampshipPreRank {
|
||||
FurSet: int32(simplePlayer.PetFur),
|
||||
PetName: simplePlayer.PetName,
|
||||
Last: last,
|
||||
Rank: int32(v.Rank),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -369,7 +404,7 @@ func (c *ChampshipMgr) GetRankMsg(uid int) *proto.ResChampshipRank {
|
||||
RL := make(map[int32]*proto.ResPlayerRank, 0)
|
||||
for k, v := range rankList {
|
||||
if v.Uid == uid {
|
||||
myRank = k + 1
|
||||
myRank = v.Rank
|
||||
myScore = v.Score
|
||||
}
|
||||
if v.Type == RANK_PLAYER_ROBOT {
|
||||
@ -398,6 +433,7 @@ func (c *ChampshipMgr) GetRankMsg(uid int) *proto.ResChampshipRank {
|
||||
FurSet: int32(robot.FurSet),
|
||||
PetName: robot.PetName,
|
||||
Last: last,
|
||||
Rank: int32(v.Rank),
|
||||
}
|
||||
} else {
|
||||
simplePlayer := G_GameLogicPtr.GetSimplePlayerByUid(v.Uid)
|
||||
@ -425,6 +461,7 @@ func (c *ChampshipMgr) GetRankMsg(uid int) *proto.ResChampshipRank {
|
||||
FurSet: int32(simplePlayer.PetFur),
|
||||
PetName: simplePlayer.PetName,
|
||||
Last: last,
|
||||
Rank: int32(v.Rank),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -531,7 +568,7 @@ func (c *ChampshipMgr) group(iszero bool) (interface{}, error) {
|
||||
ChampshipData.Robot[ChampshipData.RobotId] = v
|
||||
ChampshipData.Rank[j] = append(ChampshipData.Rank[j], &ChampshipRank{
|
||||
Uid: ChampshipData.RobotId,
|
||||
Score: v.Score,
|
||||
Score: math.Round(v.Score),
|
||||
Time: v.Time,
|
||||
Type: RANK_PLAYER_ROBOT,
|
||||
})
|
||||
@ -543,6 +580,7 @@ func (c *ChampshipMgr) group(iszero bool) (interface{}, error) {
|
||||
}
|
||||
return false
|
||||
})
|
||||
sortChampionshipRank(ChampshipData.Rank[j])
|
||||
}
|
||||
}
|
||||
|
||||
@ -635,6 +673,8 @@ func (c *ChampshipMgr) inRank(m *msg.Msg) (interface{}, error) {
|
||||
}
|
||||
return false
|
||||
})
|
||||
// 重新排序 相同分数排名相同
|
||||
sortChampionshipRank(rankList)
|
||||
ChampshipData.Rank[groupId] = rankList
|
||||
|
||||
// 收集需要通知的玩家
|
||||
@ -669,9 +709,9 @@ func (c *ChampshipMgr) getMyRank(uid int) int {
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for k, v := range rankList {
|
||||
for _, v := range rankList {
|
||||
if v.Uid == uid {
|
||||
return k + 1
|
||||
return v.Rank
|
||||
}
|
||||
}
|
||||
return 0
|
||||
@ -687,9 +727,9 @@ func (c *ChampshipMgr) unsafe_getMyRank(uid int) int {
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for k, v := range rankList {
|
||||
for _, v := range rankList {
|
||||
if v.Uid == uid {
|
||||
return k + 1
|
||||
return v.Rank
|
||||
}
|
||||
}
|
||||
return 0
|
||||
@ -707,9 +747,9 @@ func (c *ChampshipMgr) getLastMyRank(uid int) int {
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for k, v := range rankList {
|
||||
for _, v := range rankList {
|
||||
if v.Uid == uid {
|
||||
return k + 1
|
||||
return v.Rank
|
||||
}
|
||||
}
|
||||
return 0
|
||||
@ -724,9 +764,9 @@ func (c *ChampshipMgr) unsafe_getLastMyRank(uid int) int {
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for k, v := range rankList {
|
||||
for _, v := range rankList {
|
||||
if v.Uid == uid {
|
||||
return k + 1
|
||||
return v.Rank
|
||||
}
|
||||
}
|
||||
return 0
|
||||
|
||||
@ -35,6 +35,7 @@ func TestChampionshipRankReward(t *testing.T) {
|
||||
} else {
|
||||
fmt.Printf("yesterday id %d rank reward items : %v\n", yestAid, items)
|
||||
}
|
||||
player.BackChampship()
|
||||
}
|
||||
|
||||
func TestChampionshipZeroUpdate(t *testing.T) {
|
||||
|
||||
@ -4,6 +4,6 @@ import "server/game"
|
||||
|
||||
func getTestPlayer() *game.Player {
|
||||
p := new(game.Player)
|
||||
p.InitPlayer("bbb004")
|
||||
p.InitPlayer("mwh035")
|
||||
return p
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user