959 lines
28 KiB
Go
959 lines
28 KiB
Go
package logic
|
|
|
|
//const TableRanking = "ranking"
|
|
//
|
|
//// RankingScore 竞技场分数
|
|
//type RankingScore struct {
|
|
// CopyType uint32 `bson:"copy_type"`
|
|
// CopyId uint32 `bson:"copy_id"`
|
|
// Duration int64 `bson:"duration"`
|
|
// MaxDepth uint32 `bson:"max_depth"`
|
|
// MaxScore int32 `bson:"max_score"`
|
|
//
|
|
// RankIndex uint32 `bson:"-"`
|
|
//}
|
|
//
|
|
//// RankingPlayer 竞技场玩家
|
|
//type RankingPlayer struct {
|
|
// PlayerId uint64 `bson:"_id"`
|
|
// Name string `bson:"name"`
|
|
// Avatar string `bson:"avatar"`
|
|
// Capacity uint64 `bson:"capacity"`
|
|
// RigHead uint32 `bson:"rig_head"`
|
|
// RigHeadStar uint32 `bson:"rig_head_star"`
|
|
// RigBody uint32 `bson:"rig_body"`
|
|
// RigBodyStar uint32 `bson:"rig_body_star"`
|
|
// RigTail uint32 `bson:"rig_tail"`
|
|
// RigTailStar uint32 `bson:"rig_tail_star"`
|
|
// RigEquips proto.Equips `bson:"rig_equips"`
|
|
// RigPendants proto.Pendants `bson:"rig_pendants"`
|
|
// RigAttrs proto.Attrs `bson:"rig_attrs"`
|
|
// Scores map[uint32]*RankingScore `bson:"scores"`
|
|
//}
|
|
//
|
|
//// RankingSeason 竞技场赛季
|
|
//type RankingSeason struct {
|
|
// Id uint64 `bson:"_id"`
|
|
// CopyType uint32 `bson:"copy_type"`
|
|
// Season uint32 `bson:"season"`
|
|
// BeginTime int64 `bson:"begin_time"`
|
|
// EndTime int64 `bson:"end_time"`
|
|
// Players map[uint64]*RankingPlayer `bson:"players"`
|
|
//}
|
|
//
|
|
//func newRankingPlayer(player *Player) *RankingPlayer {
|
|
// var rankingPlayer = &RankingPlayer{
|
|
// PlayerId: player.PlayerId,
|
|
// Name: player.Role.Name,
|
|
// Avatar: player.Role.Avatar,
|
|
// Capacity: player.RigAttrsCapacity(),
|
|
// RigAttrs: player.Rig.Attrs,
|
|
// Scores: map[uint32]*RankingScore{},
|
|
// }
|
|
//
|
|
// var copoment *PlayerRigComponent
|
|
// copoment = player.RigComponent[player.Rig.Head]
|
|
// if copoment != nil {
|
|
// rankingPlayer.RigHead = copoment.Id
|
|
// rankingPlayer.RigHeadStar = copoment.StarId
|
|
// }
|
|
//
|
|
// copoment = player.RigComponent[player.Rig.Body]
|
|
// if copoment != nil {
|
|
// rankingPlayer.RigBody = copoment.Id
|
|
// rankingPlayer.RigBodyStar = copoment.StarId
|
|
// }
|
|
//
|
|
// copoment = player.RigComponent[player.Rig.Tail]
|
|
// if copoment != nil {
|
|
// rankingPlayer.RigTail = copoment.Id
|
|
// rankingPlayer.RigTailStar = copoment.StarId
|
|
// }
|
|
//
|
|
// for i := range player.Rig.Equips {
|
|
// var equip = player.RigEquip[player.Rig.Equips[i]]
|
|
// if equip != nil {
|
|
// rankingPlayer.RigEquips[i] = equip.Id
|
|
// }
|
|
// }
|
|
// for i := range player.Rig.Pendants {
|
|
// var pendant = player.RigPendant[player.Rig.Pendants[i]]
|
|
// if pendant != nil {
|
|
// rankingPlayer.RigPendants[i] = pendant.Id
|
|
// }
|
|
// }
|
|
//
|
|
// return rankingPlayer
|
|
//}
|
|
//
|
|
//func (this *RankingPlayer) Update(player *Player) {
|
|
// this.Name = player.Role.Name
|
|
// this.Avatar = player.Role.Avatar
|
|
// this.Capacity = player.RigAttrsCapacity()
|
|
// this.RigAttrs = player.Rig.Attrs
|
|
//
|
|
// var copoment *PlayerRigComponent
|
|
// copoment = player.RigComponent[player.Rig.Head]
|
|
// if copoment != nil {
|
|
// this.RigHead = copoment.Id
|
|
// this.RigHeadStar = copoment.StarId
|
|
// }
|
|
//
|
|
// copoment = player.RigComponent[player.Rig.Body]
|
|
// if copoment != nil {
|
|
// this.RigBody = copoment.Id
|
|
// this.RigBodyStar = copoment.StarId
|
|
// }
|
|
//
|
|
// copoment = player.RigComponent[player.Rig.Tail]
|
|
// if copoment != nil {
|
|
// this.RigTail = copoment.Id
|
|
// this.RigTailStar = copoment.StarId
|
|
// }
|
|
//
|
|
// for i := range player.Rig.Equips {
|
|
// var equip = player.RigEquip[player.Rig.Equips[i]]
|
|
// if equip != nil {
|
|
// this.RigEquips[i] = equip.Id
|
|
// }
|
|
// }
|
|
// for i := range player.Rig.Pendants {
|
|
// var pendant = player.RigPendant[player.Rig.Pendants[i]]
|
|
// if pendant != nil {
|
|
// this.RigPendants[i] = pendant.Id
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//// ArenaRanking 排名
|
|
//type ArenaRanking struct {
|
|
// score *RankingScore
|
|
// player *RankingPlayer
|
|
//}
|
|
//
|
|
//type SortFunc func(i, j int) bool
|
|
//type RankFunc func(ranking []*ArenaRanking) SortFunc
|
|
//
|
|
//// ArenaRankings 排行榜
|
|
//type ArenaRankings struct {
|
|
// rankFunc RankFunc
|
|
// rankings []*ArenaRanking
|
|
//}
|
|
//
|
|
//type rewardPlayer struct {
|
|
// copyId uint32
|
|
// playerId uint64
|
|
// rankIndex uint32
|
|
//}
|
|
//
|
|
//func newRankings(rankFunc RankFunc) *ArenaRankings {
|
|
// return &ArenaRankings{rankFunc: rankFunc}
|
|
//}
|
|
//
|
|
//func (this *ArenaRankings) rank() {
|
|
// sort.Slice(this.rankings, this.rankFunc(this.rankings))
|
|
// for i, rank := range this.rankings {
|
|
// rank.score.RankIndex = uint32(i + 1)
|
|
// }
|
|
//}
|
|
//
|
|
//func (this *ArenaRankings) add(player *RankingPlayer, score *RankingScore) *ArenaRanking {
|
|
// var ranking = &ArenaRanking{score: score, player: player}
|
|
// this.rankings = append(this.rankings, ranking)
|
|
// return ranking
|
|
//}
|
|
//
|
|
//type ArenaSeason interface {
|
|
// GetPlayer(playerId uint64) *RankingPlayer
|
|
// GetRanking(copyId, num uint32) []*ArenaRanking
|
|
// SavePlayer(player *Player, copyId uint32, duration int64, maxDepth uint32, maxScore int32) uint32
|
|
//}
|
|
//
|
|
//type baseArenaSeason struct {
|
|
// locker sync.RWMutex
|
|
// manager *ArenaManager
|
|
//}
|
|
//
|
|
//type CopyMainRanking struct {
|
|
// *RankingSeason
|
|
//
|
|
// baseArenaSeason
|
|
//
|
|
// rankings *ArenaRankings
|
|
//}
|
|
//
|
|
//func copyMainlineRankFunc(ranking []*ArenaRanking) SortFunc {
|
|
// return func(i, j int) bool {
|
|
// if ranking[i].score.CopyId == ranking[j].score.CopyId {
|
|
// return ranking[i].score.Duration < ranking[j].score.Duration
|
|
// } else {
|
|
// return ranking[i].score.CopyId > ranking[j].score.CopyId
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//func newCopyMainRanking(season *RankingSeason, manager *ArenaManager) *CopyMainRanking {
|
|
// var copyMainlineRanking = &CopyMainRanking{RankingSeason: season, baseArenaSeason: baseArenaSeason{manager: manager}, rankings: &ArenaRankings{rankFunc: copyMainlineRankFunc}}
|
|
// for _, player := range copyMainlineRanking.Players {
|
|
// for _, score := range player.Scores {
|
|
// copyMainlineRanking.rankings.add(player, score)
|
|
// break
|
|
// }
|
|
// }
|
|
//
|
|
// copyMainlineRanking.rankings.rank()
|
|
// return copyMainlineRanking
|
|
//}
|
|
//
|
|
//func (this *CopyMainRanking) GetPlayer(playerId uint64) *RankingPlayer {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// return this.Players[playerId]
|
|
//}
|
|
//
|
|
//func (this *CopyMainRanking) GetRanking(_, num uint32) []*ArenaRanking {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
//
|
|
// if uint32(len(this.rankings.rankings)) <= num {
|
|
// return this.rankings.rankings
|
|
// }
|
|
// return this.rankings.rankings[:num]
|
|
//}
|
|
//
|
|
//func (this *CopyMainRanking) SavePlayer(player *Player, copyId uint32, duration int64, maxDepth uint32, maxScore int32) uint32 {
|
|
//
|
|
// var score *RankingScore
|
|
// var rankings *ArenaRankings
|
|
// var rankingPlayer *RankingPlayer
|
|
//
|
|
// this.locker.Lock()
|
|
// rankingPlayer = this.Players[player.PlayerId]
|
|
// if rankingPlayer == nil {
|
|
// rankingPlayer = newRankingPlayer(player)
|
|
// this.Players[rankingPlayer.PlayerId] = rankingPlayer
|
|
// } else {
|
|
// rankingPlayer.Update(player)
|
|
// }
|
|
//
|
|
// rankings = this.rankings
|
|
// if this.rankings == nil {
|
|
// rankings = newRankings(copyMainlineRankFunc)
|
|
// this.rankings = rankings
|
|
// }
|
|
//
|
|
// score = rankingPlayer.Scores[0]
|
|
// if score == nil {
|
|
// score = &RankingScore{
|
|
// CopyType: this.CopyType,
|
|
// CopyId: copyId,
|
|
// Duration: duration,
|
|
// }
|
|
// rankingPlayer.Scores[0] = score
|
|
//
|
|
// rankings.add(rankingPlayer, score)
|
|
// rankings.rank()
|
|
// } else {
|
|
// if copyId > score.CopyId {
|
|
// score.CopyId = copyId
|
|
// score.Duration = duration
|
|
// rankings.rank()
|
|
// }
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// _, err := this.manager.mongoClient.Collection(TableRanking).UpdateByID(this.manager.mongoClient.Context(), this.Id, bson.M{"$set": bson.M{fmt.Sprint("players.", rankingPlayer.PlayerId): rankingPlayer}})
|
|
// if err != nil {
|
|
// this.manager.logger.Errorf("Failed to save arena player info, playerId: %d, error: %v", player.PlayerId, err)
|
|
// }
|
|
//
|
|
// return score.RankIndex
|
|
//}
|
|
//
|
|
//type CopySpeedSeason struct {
|
|
// *RankingSeason
|
|
//
|
|
// baseArenaSeason
|
|
//
|
|
// rankings map[uint32]*ArenaRankings
|
|
//}
|
|
//
|
|
//func copySpeedRankFunc(ranking []*ArenaRanking) SortFunc {
|
|
// return func(i, j int) bool {
|
|
// if ranking[i].score.MaxScore == ranking[j].score.MaxScore {
|
|
// return ranking[i].score.Duration < ranking[j].score.Duration
|
|
// } else {
|
|
// return ranking[i].score.MaxScore > ranking[j].score.MaxScore
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//func newCopySpeedSeason(season *RankingSeason, manager *ArenaManager) *CopySpeedSeason {
|
|
// var copySpeedSeason = &CopySpeedSeason{RankingSeason: season, baseArenaSeason: baseArenaSeason{manager: manager}, rankings: map[uint32]*ArenaRankings{}}
|
|
// for _, player := range copySpeedSeason.Players {
|
|
// for _, score := range player.Scores {
|
|
// var rankings = copySpeedSeason.rankings[score.CopyId]
|
|
// if rankings == nil {
|
|
// rankings = &ArenaRankings{rankFunc: copySpeedRankFunc}
|
|
// copySpeedSeason.rankings[score.CopyId] = rankings
|
|
// }
|
|
//
|
|
// rankings.add(player, score)
|
|
// }
|
|
// }
|
|
// for _, rankings := range copySpeedSeason.rankings {
|
|
// rankings.rank()
|
|
// }
|
|
// return copySpeedSeason
|
|
//}
|
|
//
|
|
//func (this *CopySpeedSeason) GetPlayer(playerId uint64) *RankingPlayer {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// return this.Players[playerId]
|
|
//}
|
|
//
|
|
//func (this *CopySpeedSeason) GetRanking(copyId, num uint32) []*ArenaRanking {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
//
|
|
// var rankings = this.rankings[copyId]
|
|
// if rankings == nil {
|
|
// return nil
|
|
// }
|
|
// if uint32(len(rankings.rankings)) <= num {
|
|
// return rankings.rankings
|
|
// }
|
|
// return rankings.rankings[:num]
|
|
//}
|
|
//
|
|
//func (this *CopySpeedSeason) SavePlayer(player *Player, copyId uint32, duration int64, maxDepth uint32, maxScore int32) uint32 {
|
|
//
|
|
// var score *RankingScore
|
|
// var rankings *ArenaRankings
|
|
// var rankingPlayer *RankingPlayer
|
|
//
|
|
// this.locker.Lock()
|
|
// rankingPlayer = this.Players[player.PlayerId]
|
|
// if rankingPlayer == nil {
|
|
// rankingPlayer = newRankingPlayer(player)
|
|
// this.Players[rankingPlayer.PlayerId] = rankingPlayer
|
|
// } else {
|
|
// rankingPlayer.Update(player)
|
|
// }
|
|
//
|
|
// rankings = this.rankings[copyId]
|
|
// if rankings == nil {
|
|
// rankings = newRankings(copySpeedRankFunc)
|
|
// this.rankings[copyId] = rankings
|
|
// }
|
|
//
|
|
// score = rankingPlayer.Scores[copyId]
|
|
// if score == nil {
|
|
// score = &RankingScore{
|
|
// CopyType: this.CopyType,
|
|
// CopyId: copyId,
|
|
// Duration: duration,
|
|
// MaxDepth: maxDepth,
|
|
// MaxScore: maxScore,
|
|
// }
|
|
// rankingPlayer.Scores[score.CopyId] = score
|
|
//
|
|
// rankings.add(rankingPlayer, score)
|
|
// rankings.rank()
|
|
// } else {
|
|
// if maxDepth > score.MaxDepth {
|
|
// score.MaxDepth = maxDepth
|
|
// }
|
|
// if maxScore > score.MaxScore {
|
|
// score.MaxScore = maxScore
|
|
// rankings.rank()
|
|
// } else if maxScore == score.MaxScore {
|
|
// if duration < score.Duration {
|
|
// score.Duration = duration
|
|
// rankings.rank()
|
|
// }
|
|
// }
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// _, err := this.manager.mongoClient.Collection(TableRanking).UpdateByID(this.manager.mongoClient.Context(), this.Id, bson.M{"$set": bson.M{fmt.Sprint("players.", player.PlayerId): rankingPlayer}})
|
|
// if err != nil {
|
|
// this.manager.logger.Errorf("Failed to save arena player info, playerId: %d, error: %v", player.PlayerId, err)
|
|
// }
|
|
//
|
|
// return score.RankIndex
|
|
//}
|
|
//
|
|
//func (this *CopySpeedSeason) settle(now *GameTime) {
|
|
// var copyPlayers [][]*rewardPlayer
|
|
// this.locker.Lock()
|
|
// for copyId, rankings := range this.rankings {
|
|
// var players []*rewardPlayer
|
|
// for _, ranking := range rankings.rankings {
|
|
// var player = &rewardPlayer{copyId: copyId, playerId: ranking.player.PlayerId, rankIndex: ranking.score.RankIndex}
|
|
// players = append(players, player)
|
|
// }
|
|
// copyPlayers = append(copyPlayers, players)
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// go this.doSettle(now, copyPlayers)
|
|
//}
|
|
//
|
|
//func (this *CopySpeedSeason) doSettle(now *GameTime, copyPlayers [][]*rewardPlayer) {
|
|
// for _, players := range copyPlayers {
|
|
// for _, player := range players {
|
|
// var copySpeedTable = this.manager.tables.CopySpeed.Get(int(player.copyId))
|
|
// if copySpeedTable == nil {
|
|
// continue
|
|
// }
|
|
//
|
|
// var copySpeedRewardTable = this.manager.tables.CopySpeedRewardExtend.CalcReward(copySpeedTable.Id, 1, int(player.rankIndex))
|
|
// if copySpeedRewardTable == nil {
|
|
// continue
|
|
// }
|
|
//
|
|
// this.manager.playerManager.PlayerMailSend(
|
|
// player.playerId,
|
|
// true,
|
|
// proto.MailTypeNormal,
|
|
// util.IntegerToString(copySpeedTable.MailTitle),
|
|
// util.IntegerToString(copySpeedTable.MailMail),
|
|
// []string{util.IntegerToString(player.rankIndex)},
|
|
// util.NumbersConvert2(copySpeedRewardTable.ItemList, uint32(0)),
|
|
// util.NumbersConvert2(copySpeedRewardTable.NumList, uint32(0)),
|
|
// now.Timestamp,
|
|
// )
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//type CopyArenaSeason struct {
|
|
// *RankingSeason
|
|
//
|
|
// baseArenaSeason
|
|
//
|
|
// dayId int64
|
|
//
|
|
// rankings *ArenaRankings
|
|
// robots map[uint64]*RankingPlayer
|
|
//}
|
|
//
|
|
//func copyArenaRankFunc(ranking []*ArenaRanking) SortFunc {
|
|
// return func(i, j int) bool {
|
|
// return ranking[i].score.MaxScore > ranking[j].score.MaxScore
|
|
// }
|
|
//}
|
|
//
|
|
//func newCopyArenaRobotPlayer(copyArenaRobotTable *data.CopyArenaRobot, attributeConfigTables []*data.AttributeConfig) *RankingPlayer {
|
|
// var robotPlayer = &RankingPlayer{
|
|
// PlayerId: uint64(copyArenaRobotTable.Id),
|
|
// Name: util.IntegerToString(copyArenaRobotTable.Name),
|
|
// Avatar: strconv.Itoa(copyArenaRobotTable.Avatar),
|
|
// RigHead: uint32(copyArenaRobotTable.RigHead),
|
|
// RigHeadStar: uint32(copyArenaRobotTable.RigHeadStar),
|
|
// RigBody: uint32(copyArenaRobotTable.RigBody),
|
|
// RigBodyStar: uint32(copyArenaRobotTable.RigBodyStar),
|
|
// RigTail: uint32(copyArenaRobotTable.RigTail),
|
|
// RigTailStar: uint32(copyArenaRobotTable.RigTailStar),
|
|
// Scores: map[uint32]*RankingScore{},
|
|
// }
|
|
//
|
|
// for j := range copyArenaRobotTable.RigEquips {
|
|
// if j >= proto.EquipNum {
|
|
// break
|
|
// }
|
|
// robotPlayer.RigEquips[j] = uint32(copyArenaRobotTable.RigEquips[j])
|
|
// }
|
|
//
|
|
// for j := range copyArenaRobotTable.RigPendants {
|
|
// if j >= proto.PendantNum {
|
|
// break
|
|
// }
|
|
// robotPlayer.RigPendants[j] = uint32(copyArenaRobotTable.RigPendants[j])
|
|
// }
|
|
//
|
|
// robotPlayer.RigAttrs[proto.AttrTypeMoveSpeed] = float64(copyArenaRobotTable.AttrValue0)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeEnergy] = float64(copyArenaRobotTable.AttrValue1)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeEnergyRecover] = float64(copyArenaRobotTable.AttrValue2)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeAccelerateEnergy] = float64(copyArenaRobotTable.AttrValue3)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeAttack] = float64(copyArenaRobotTable.AttrValue4)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeHardAttack] = float64(copyArenaRobotTable.AttrValue5)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeMonsterAttack] = float64(copyArenaRobotTable.AttrValue6)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeCritRate] = float64(copyArenaRobotTable.AttrValue7)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeCritDamageBonus] = float64(copyArenaRobotTable.AttrValue8)
|
|
// robotPlayer.RigAttrs[proto.AttrTypeAttackSpeed] = float64(copyArenaRobotTable.AttrValue9)
|
|
//
|
|
// robotPlayer.Capacity = rigAttrsCapacity(robotPlayer.RigAttrs, attributeConfigTables)
|
|
//
|
|
// return robotPlayer
|
|
//}
|
|
//
|
|
//func newCopyArenaSeason(season *RankingSeason, manager *ArenaManager, now *GameTime) *CopyArenaSeason {
|
|
// var copyArenaSeason = &CopyArenaSeason{RankingSeason: season, baseArenaSeason: baseArenaSeason{manager: manager}, dayId: now.Days, rankings: &ArenaRankings{rankFunc: copyArenaRankFunc}, robots: map[uint64]*RankingPlayer{}}
|
|
// for _, player := range copyArenaSeason.Players {
|
|
// for _, score := range player.Scores {
|
|
// copyArenaSeason.rankings.add(player, score)
|
|
// break
|
|
// }
|
|
// }
|
|
//
|
|
// var copyArenaTable = manager.tables.CopyArena.Get(1)
|
|
// if copyArenaTable != nil {
|
|
// var copyArenaRobotTables = manager.tables.CopyArenaRobot.List()
|
|
// for i, copyArenaRobotTable := range copyArenaRobotTables {
|
|
// if i >= copyArenaTable.RobotNum {
|
|
// break
|
|
// }
|
|
//
|
|
// var robotPlayer = newCopyArenaRobotPlayer(copyArenaRobotTable, manager.tables.AttributeConfig.List())
|
|
//
|
|
// var score = &RankingScore{
|
|
// CopyType: copyArenaSeason.CopyType,
|
|
// CopyId: uint32(copyArenaTable.Id),
|
|
// MaxScore: int32(copyArenaRobotTable.Score),
|
|
// }
|
|
//
|
|
// robotPlayer.Scores[score.CopyId] = score
|
|
//
|
|
// copyArenaSeason.rankings.add(robotPlayer, score)
|
|
// copyArenaSeason.robots[robotPlayer.PlayerId] = robotPlayer
|
|
// }
|
|
// }
|
|
//
|
|
// copyArenaSeason.rankings.rank()
|
|
// return copyArenaSeason
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) GetPlayer(playerId uint64) *RankingPlayer {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// if playerId < 1000000000 {
|
|
// return this.robots[playerId]
|
|
// } else {
|
|
// return this.Players[playerId]
|
|
// }
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) GetRanking(copyId, num uint32) []*ArenaRanking {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
//
|
|
// if this.rankings == nil {
|
|
// return nil
|
|
// }
|
|
// if uint32(len(this.rankings.rankings)) <= num {
|
|
// return this.rankings.rankings
|
|
// }
|
|
// return this.rankings.rankings[:num]
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) SavePlayer(player *Player, copyId uint32, _ int64, _ uint32, maxScore int32) uint32 {
|
|
//
|
|
// var score *RankingScore
|
|
// var rankings *ArenaRankings
|
|
// var rankingPlayer *RankingPlayer
|
|
//
|
|
// this.locker.Lock()
|
|
// rankingPlayer = this.Players[player.PlayerId]
|
|
// if rankingPlayer == nil {
|
|
// rankingPlayer = newRankingPlayer(player)
|
|
// this.Players[rankingPlayer.PlayerId] = rankingPlayer
|
|
// } else {
|
|
// rankingPlayer.Update(player)
|
|
// }
|
|
//
|
|
// rankings = this.rankings
|
|
// if this.rankings == nil {
|
|
// rankings = newRankings(copyArenaRankFunc)
|
|
// this.rankings = rankings
|
|
// }
|
|
//
|
|
// score = rankingPlayer.Scores[copyId]
|
|
// if score == nil {
|
|
// score = &RankingScore{
|
|
// CopyType: this.CopyType,
|
|
// CopyId: copyId,
|
|
// MaxScore: maxScore,
|
|
// }
|
|
// rankingPlayer.Scores[score.CopyId] = score
|
|
//
|
|
// rankings.add(rankingPlayer, score)
|
|
// rankings.rank()
|
|
// } else {
|
|
// score.MaxScore = maxScore
|
|
// rankings.rank()
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// _, err := this.manager.mongoClient.Collection(TableRanking).UpdateByID(this.manager.mongoClient.Context(), this.Id, bson.M{"$set": bson.M{fmt.Sprint("players.", player.PlayerId): rankingPlayer}})
|
|
// if err != nil {
|
|
// this.manager.logger.Errorf("Failed to save arena player info, playerId: %d, error: %v", player.PlayerId, err)
|
|
// }
|
|
//
|
|
// return score.RankIndex
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) DefendRecord(defenderId uint64, score int32, attacker *RankingPlayer) {
|
|
// this.manager.playerManager.PlayerDefendRecord(defenderId, true, score, attacker)
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) Matches(player *Player, copyId uint32, num int, excludeIds []uint64) []uint64 {
|
|
//
|
|
// var rankIndex uint32
|
|
// var minScore, maxScore int32
|
|
// var matches = map[uint64]struct{}{}
|
|
//
|
|
// var copyArenaTable = this.manager.tables.CopyArena.Get(int(copyId))
|
|
// if copyArenaTable == nil {
|
|
// return nil
|
|
// }
|
|
//
|
|
// if copyArenaTable.InitialIntegral <= 100 {
|
|
// minScore, maxScore = 0, 300
|
|
// } else {
|
|
// minScore, maxScore = int32(copyArenaTable.InitialIntegral)-100, int32(copyArenaTable.InitialIntegral)+200
|
|
// }
|
|
//
|
|
// this.locker.Lock()
|
|
// var rankingPlayer = this.Players[player.PlayerId]
|
|
// if rankingPlayer != nil {
|
|
// var score = rankingPlayer.Scores[copyId]
|
|
// if score != nil {
|
|
// rankIndex = score.RankIndex
|
|
// if score.MaxScore <= 100 {
|
|
// minScore, maxScore = 0, 300
|
|
// } else {
|
|
// minScore, maxScore = score.MaxScore-100, score.MaxScore+200
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// for _, ranking := range this.rankings.rankings {
|
|
// if ranking.player.PlayerId == player.PlayerId {
|
|
// continue
|
|
// }
|
|
// if ranking.score.MaxScore >= minScore && ranking.score.MaxScore < maxScore {
|
|
// matches[ranking.player.PlayerId] = struct{}{}
|
|
// }
|
|
// }
|
|
//
|
|
// if len(matches) < num {
|
|
// var minRank = int(rankIndex) - 10
|
|
// var maxRank = int(rankIndex) + 10
|
|
// if minRank < 0 {
|
|
// minRank = 0
|
|
// maxRank = 20
|
|
// }
|
|
// if maxRank > len(this.rankings.rankings) {
|
|
// maxRank = len(this.rankings.rankings)
|
|
// minRank = len(this.rankings.rankings) - 20
|
|
// }
|
|
//
|
|
// for i, ranking := range this.rankings.rankings {
|
|
// if ranking.player.PlayerId == player.PlayerId {
|
|
// continue
|
|
// }
|
|
// if i >= minRank && i < maxRank {
|
|
// matches[ranking.player.PlayerId] = struct{}{}
|
|
// }
|
|
// }
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// if len(matches) > len(excludeIds)+num {
|
|
// for _, excludeId := range excludeIds {
|
|
// delete(matches, excludeId)
|
|
// }
|
|
// }
|
|
//
|
|
// return util.RandomSelect(util.MapKeys(matches), num)
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) settle(now *GameTime, tipe int) {
|
|
// var players []*rewardPlayer
|
|
// this.locker.Lock()
|
|
// for _, ranking := range this.rankings.rankings {
|
|
// if ranking.player.PlayerId > 999999999 {
|
|
// players = append(players, &rewardPlayer{copyId: ranking.score.CopyId, playerId: ranking.player.PlayerId, rankIndex: ranking.score.RankIndex})
|
|
// }
|
|
// }
|
|
// this.locker.Unlock()
|
|
//
|
|
// go this.doSettle(now, tipe, players)
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) doSettle(now *GameTime, tipe int, players []*rewardPlayer) {
|
|
// this.doReward(now, tipe, players)
|
|
//}
|
|
//
|
|
//func (this *CopyArenaSeason) doReward(now *GameTime, tipe int, players []*rewardPlayer) {
|
|
// for _, player := range players {
|
|
// var copyArenaTable = this.manager.tables.CopyArena.Get(int(player.copyId))
|
|
// if copyArenaTable == nil {
|
|
// continue
|
|
// }
|
|
//
|
|
// var copySpeedRewardTable = this.manager.tables.CopyArenaRewardExtend.CalcReward(copyArenaTable.Id, tipe, int(player.rankIndex))
|
|
// if copySpeedRewardTable == nil {
|
|
// continue
|
|
// }
|
|
//
|
|
// var mailTitle, mailContent = copyArenaTable.MailTitle, copyArenaTable.MailMail
|
|
// if tipe == 1 {
|
|
// mailTitle, mailContent = copyArenaTable.WeeklyTitle, copyArenaTable.WeeklyMail
|
|
// }
|
|
//
|
|
// this.manager.playerManager.PlayerMailSend(
|
|
// player.playerId,
|
|
// true,
|
|
// proto.MailTypeNormal,
|
|
// util.IntegerToString(mailTitle),
|
|
// util.IntegerToString(mailContent),
|
|
// []string{util.IntegerToString(player.rankIndex)},
|
|
// util.NumbersConvert2(copySpeedRewardTable.ItemList, uint32(0)),
|
|
// util.NumbersConvert2(copySpeedRewardTable.NumList, uint32(0)),
|
|
// now.Timestamp,
|
|
// )
|
|
// }
|
|
//}
|
|
//
|
|
//type ArenaManager struct {
|
|
// manager
|
|
//
|
|
// closed bool
|
|
// locker sync.RWMutex
|
|
//
|
|
// tables *data.Tables
|
|
// mongoClient *db.MongoClient
|
|
// playerManager *PlayerManager
|
|
//
|
|
// copyMainRanking *CopyMainRanking
|
|
// copySpeedSeason *CopySpeedSeason
|
|
// copyArenaSeason *CopyArenaSeason
|
|
//}
|
|
//
|
|
//func NewArenaManager(svr server.Server, dataTables *data.Tables, mongoClient *db.MongoClient) *ArenaManager {
|
|
// return &ArenaManager{manager: manager{logger: svr.Logger(), server: svr}, tables: dataTables, mongoClient: mongoClient}
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) Init() (err error) {
|
|
// if this.playerManager == nil {
|
|
// return errors.Error("'playerManager' is nil")
|
|
// }
|
|
//
|
|
// var season *RankingSeason
|
|
// var now = NewGameTime(-1)
|
|
//
|
|
// season, err = this.queryArenaSeason(proto.CopyTypeMainline, nil)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
//
|
|
// if season == nil {
|
|
// season, err = this.newArenaSeason(proto.CopyTypeMainline, nil)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// }
|
|
//
|
|
// this.copyMainRanking = newCopyMainRanking(season, this)
|
|
//
|
|
// season, err = this.queryArenaSeason(proto.CopyTypeSpeed, now)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
//
|
|
// if season == nil {
|
|
// season, err = this.newArenaSeason(proto.CopyTypeSpeed, now)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// }
|
|
//
|
|
// this.copySpeedSeason = newCopySpeedSeason(season, this)
|
|
//
|
|
// season, err = this.queryArenaSeason(proto.CopyTypeArena, now)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
//
|
|
// if season == nil {
|
|
// season, err = this.newArenaSeason(proto.CopyTypeArena, now)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// }
|
|
//
|
|
// this.copyArenaSeason = newCopyArenaSeason(season, this, now)
|
|
//
|
|
// go this.tick()
|
|
// return nil
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) Close() error {
|
|
// this.closed = true
|
|
// return nil
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) SetTables(tables *data.Tables) {
|
|
// this.tables = tables
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) queryArenaSeason(copyType proto.CopyType, now *GameTime) (*RankingSeason, error) {
|
|
// var seasonNo int64
|
|
// if now != nil {
|
|
// seasonNo = now.Weeks
|
|
// }
|
|
//
|
|
// var season = &RankingSeason{Id: util.Compose2uint32(uint32(copyType), uint32(seasonNo))}
|
|
// var err = this.mongoClient.Collection(TableRanking).FindOne(this.mongoClient.Context(), bson.M{"_id": season.Id}).Decode(season)
|
|
// if err != nil {
|
|
// if err != mongo.ErrNoDocuments {
|
|
// return nil, err
|
|
// }
|
|
// return nil, nil
|
|
// }
|
|
// return season, nil
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) newArenaSeason(copyType proto.CopyType, now *GameTime) (*RankingSeason, error) {
|
|
// var beginTime, endTime int64
|
|
// var seasonNo int64
|
|
// if now != nil {
|
|
// seasonNo = now.Weeks
|
|
// }
|
|
// switch copyType {
|
|
// case proto.CopyTypeMainline:
|
|
// beginTime, endTime = 0, 0
|
|
// case proto.CopyTypeSpeed:
|
|
// beginTime, endTime = this.copySpeedSeasonTime()
|
|
// case proto.CopyTypeArena:
|
|
// beginTime, endTime = this.copyArenaSeasonTime()
|
|
// default:
|
|
// return nil, errors.Error("error copy type, copyType: ", copyType)
|
|
// }
|
|
//
|
|
// var season = &RankingSeason{
|
|
// Id: util.Compose2uint32(uint32(copyType), uint32(seasonNo)),
|
|
// CopyType: uint32(copyType),
|
|
// Season: uint32(seasonNo),
|
|
// BeginTime: beginTime,
|
|
// EndTime: endTime,
|
|
// Players: map[uint64]*RankingPlayer{},
|
|
// }
|
|
//
|
|
// _, err := this.mongoClient.Collection(TableRanking).InsertOne(this.mongoClient.Context(), season)
|
|
// if err != nil {
|
|
// return nil, err
|
|
// }
|
|
//
|
|
// return season, nil
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) copySpeedSeasonTime() (int64, int64) {
|
|
// var weekBeginTime = util.WeekBeginTime()
|
|
// return weekBeginTime + GameDailyResetTime, weekBeginTime + util.WeekTotalSeconds - 7200
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) copyArenaSeasonTime() (int64, int64) {
|
|
// var weekBeginTime = util.WeekBeginTime()
|
|
// return weekBeginTime + GameDailyResetTime, weekBeginTime + util.WeekTotalSeconds - 7200
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) tick() {
|
|
// var ticker = time.NewTicker(time.Second)
|
|
// defer ticker.Stop()
|
|
// for {
|
|
// t, ok := <-ticker.C
|
|
// if !ok || this.closed {
|
|
// return
|
|
// }
|
|
//
|
|
// var now = NewGameTime(t.Unix())
|
|
//
|
|
// this.checkCopySpeedSeasonChange(now)
|
|
// this.checkCopyArenaSeasonChange(now)
|
|
// }
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) checkCopySpeedSeasonChange(now *GameTime) {
|
|
// var copySpeedSeason = this.CopySpeedSeason()
|
|
// if copySpeedSeason != nil {
|
|
// if copySpeedSeason.Season == uint32(now.Weeks) {
|
|
// return
|
|
// }
|
|
//
|
|
// this.locker.Lock()
|
|
// this.copySpeedSeason = nil
|
|
// this.locker.Unlock()
|
|
//
|
|
// //Do weekly settlement
|
|
// copySpeedSeason.settle(now)
|
|
// }
|
|
//
|
|
// var season, err = this.newArenaSeason(proto.CopyTypeSpeed, now)
|
|
// if err != nil {
|
|
// this.logger.Error("copy speed new season failed, error: ", err)
|
|
// return
|
|
// }
|
|
//
|
|
// copySpeedSeason = newCopySpeedSeason(season, this)
|
|
//
|
|
// this.locker.Lock()
|
|
// this.copySpeedSeason = copySpeedSeason
|
|
// this.locker.Unlock()
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) checkCopyArenaSeasonChange(now *GameTime) {
|
|
// var copyArenaSeason = this.CopyArenaSeason()
|
|
// if copyArenaSeason != nil {
|
|
// if now.Days != copyArenaSeason.dayId {
|
|
// copyArenaSeason.dayId = now.Days
|
|
// //Do daily settlement
|
|
// copyArenaSeason.settle(now, 0)
|
|
// }
|
|
// if copyArenaSeason.Season == uint32(now.Weeks) {
|
|
// return
|
|
// }
|
|
//
|
|
// this.locker.Lock()
|
|
// this.copyArenaSeason = nil
|
|
// this.locker.Unlock()
|
|
//
|
|
// //Do weekly settlement
|
|
// copyArenaSeason.settle(now, 1)
|
|
// }
|
|
//
|
|
// var season, err = this.newArenaSeason(proto.CopyTypeArena, now)
|
|
// if err != nil {
|
|
// this.logger.Error("copy arena new season failed, error: ", err)
|
|
// return
|
|
// }
|
|
//
|
|
// copyArenaSeason = newCopyArenaSeason(season, this, now)
|
|
//
|
|
// this.locker.Lock()
|
|
// this.copyArenaSeason = copyArenaSeason
|
|
// this.locker.Unlock()
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) CopyMainRanking() *CopyMainRanking {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// return this.copyMainRanking
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) CopySpeedSeason() *CopySpeedSeason {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// return this.copySpeedSeason
|
|
//}
|
|
//
|
|
//func (this *ArenaManager) CopyArenaSeason() *CopyArenaSeason {
|
|
// this.locker.RLock()
|
|
// defer this.locker.RUnlock()
|
|
// return this.copyArenaSeason
|
|
//}
|