rank.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package msg
  2. import (
  3. "leafstalk/covenant/model"
  4. )
  5. const (
  6. RankTypeCooperation1 = 1 //联合普通
  7. RankTypeCooperation2 = 2 //联合困难
  8. RankTypeCooperation3 = 3 //联合噩梦
  9. RankTypeMain = 4 //主线
  10. // 对应战区
  11. RankTypeCooperation1Area = 101
  12. RankTypeCooperation2Area = 102
  13. RankTypeCooperation3Area = 103
  14. RankTypeMainArea = 104
  15. )
  16. // 查看主线排行列表
  17. type ViewMainRank struct {
  18. PlayerId int64 `json:"userId"`
  19. RankType int64 `json:"type"` //同RankTypeXX
  20. }
  21. type ResponseViewMainRank struct {
  22. ErrCode int `json:"errCode"`
  23. Msg string `json:"msg,omitempty"`
  24. Data *ViewMainRankData `json:"data"`
  25. }
  26. type ViewMainRankData struct {
  27. List []*NormalRankItem `json:"list"`
  28. Self NormalRankItem `json:"self"`
  29. }
  30. // 查看联合排行列表
  31. type ViewCooperationRank struct {
  32. PlayerId int64 `json:"userId"`
  33. RankType int64 `json:"type"`
  34. }
  35. type ResponseViewCooperationRank struct {
  36. ErrCode int `json:"errCode"`
  37. Msg string `json:"msg,omitempty"`
  38. Data *ViewCooperationRankData `json:"data"`
  39. }
  40. type ViewCooperationRankData struct {
  41. List []*CooperationRankItem `json:"list"`
  42. }
  43. type MainRankItem struct {
  44. Score int64 `json:"score"` //积分
  45. Ts int64 `json:"ts"` //时间戳
  46. }
  47. type NormalRankItem struct {
  48. *MainRankItem
  49. Rank int64 `json:"rank"` //排行
  50. Player *model.PersonalItem `json:"players"` //单人
  51. // Score int64 `json:"score"` //积分
  52. }
  53. type ByMainScore []*NormalRankItem
  54. // 实现 sort.Interface 接口
  55. func (a ByMainScore) Len() int { return len(a) }
  56. func (a ByMainScore) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  57. func (a ByMainScore) Less(i, j int) bool {
  58. if a[i].Score > a[j].Score {
  59. return true
  60. } else if a[i].Score < a[j].Score {
  61. return false
  62. } else {
  63. return a[i].Ts < a[j].Ts
  64. }
  65. } // 降序排序
  66. type CoopRankItem struct {
  67. Score int64 `json:"score"` //积分
  68. Wave int64 `json:"wave"` //波次
  69. Ts int64 `json:"ts"` //时间戳
  70. BattleId int64 `json:"battleId,string"`
  71. }
  72. type CooperationRankItem struct {
  73. *CoopRankItem
  74. Rank int64 `json:"rank"` //排行
  75. Players []*model.PersonalItem `json:"players"` //多人一起
  76. }
  77. type ByCoopScore []*CooperationRankItem
  78. // 实现 sort.Interface 接口
  79. func (a ByCoopScore) Len() int { return len(a) }
  80. func (a ByCoopScore) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  81. func (a ByCoopScore) Less(i, j int) bool {
  82. if a[i].Score > a[j].Score {
  83. return true
  84. } else if a[i].Score < a[j].Score {
  85. return false
  86. } else {
  87. return a[i].Ts < a[j].Ts
  88. }
  89. } // 降序排序