data.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package proto
  2. import (
  3. "bet24.com/servers/common"
  4. item "bet24.com/servers/micros/item_inventory/proto"
  5. task "bet24.com/servers/micros/task/proto"
  6. )
  7. const (
  8. UsageLevel = 1 // 使用等级
  9. MaxLevel = 3 // 黄金 等级3(最高等级)
  10. )
  11. const (
  12. _ = iota // 0=无效
  13. BadgeType_Achievement // 1=成就徽章
  14. BadgeType_Honor // 2=荣誉徽章
  15. )
  16. const (
  17. Action_Recharge = iota + 1000 // 1000=充值
  18. Action_Game_Kill // 1001=游戏击杀
  19. Action_Game_CallPoints // 1002=累计叫分次数
  20. Action_AudioRoom_RoomGrade // 1003=语聊房房间等级
  21. Action_AudioRoom_SendGivingDiamond // 1004=赠送的礼物价值钻石
  22. Action_AudioRoom_SendGivingNum // 1005=赠送礼物数量
  23. Action_AudioRoom_ReceiveGivingDiamond // 1006=收到礼物价值钻石
  24. Action_AudioRoom_ReceiveGivingNum // 1007=收到礼物数量
  25. Action_Ranking // 1008=排行榜
  26. Action_PropConsumeGold // 1009=购买道具消耗金币
  27. Action_CompleteTheTask // 1010=完成任务
  28. Action_SignInCount // 1011=签到次数
  29. Action_ConsumeGold = task.TaskAction_fire // 5=消耗金币
  30. Action_Game_WinTimes = task.TaskAction_wingame // 3=胜利次数
  31. Action_Match_ChampionTimes = task.TaskAction_matchchampion // 23=冠军次数、赛事冠军次数
  32. Action_NoviceGuide = task.TaskAction_novice_guidance // 25=新手引导
  33. Action_CollectGold = task.TaskAction_earn // 2=赢金
  34. )
  35. // 徽章
  36. type Badge struct {
  37. BadgeId int // 徽章ID
  38. BadgeName string // 徽章名称
  39. BadgeType int // 徽章类型(1=成就徽章,2=荣誉徽章)
  40. Action int // 触发动作
  41. Levels []Badge_Level // 徽章等级
  42. BadgeScope // 适用范围
  43. Duration int // 持续时间【秒】(0=不限制)
  44. Model int // 显示的模式(0:所有,1:语聊房,2:...)
  45. IsShow bool // 是否显示
  46. IsCollection bool // 是否收集进度
  47. }
  48. // 等级信息
  49. type Badge_Level struct {
  50. Level int `json:",omitempty"` // 徽章等级
  51. Exps int `json:",omitempty"` // 经验值
  52. Points int `json:",omitempty"` // 徽章点数(用于排行榜),荣耀徽章始终为0
  53. }
  54. // 适用范围
  55. type BadgeScope struct {
  56. GameNames []string `json:",omitempty"` // 游戏名
  57. ItemIds []int `json:",omitempty"` // 道具id
  58. GiftIds []int `json:",omitempty"` // 礼物id
  59. TaskIds []int `json:",omitempty"` // 任务id
  60. Ranks []RankInfo `json:",omitempty"` // 榜单
  61. }
  62. // 应用调用时传入参数
  63. type Scope struct {
  64. GameName string `json:",omitempty"` // 游戏名
  65. Items []item.ItemPack `json:",omitempty"` // 实体道具
  66. GiftId int `json:",omitempty"` // 礼物ID
  67. TaskId int `json:",omitempty"` // 任务id
  68. RankCrdate string `json:",omitempty"` // 榜单的创建开始日期
  69. RankInfo // 榜单
  70. }
  71. // 是否使用
  72. func (b *Badge) IsApplicative(param Scope) bool {
  73. for _, v := range b.GameNames {
  74. if v == param.GameName {
  75. return true
  76. }
  77. }
  78. return false
  79. }
  80. // 榜单信息
  81. type RankInfo struct {
  82. Type int `json:",omitempty"` // 榜单类型
  83. Rank int `json:",omitempty"` // 榜单名次
  84. Score int `json:",omitempty"` // 分数
  85. }
  86. // 用户徽章
  87. type UserBadge struct {
  88. BadgeId int // 徽章ID
  89. Badge_Level // 等级经验(从数据库获取重新计算等级)
  90. Times int `json:",omitempty"` // 获取次数
  91. Position int `json:",omitempty"` // 位置
  92. Wearable bool // 是否可佩戴
  93. ExpiresTime int `json:",omitempty"` // 到期时间戳
  94. ObtainDate string `json:",omitempty"` // 徽章多个等级的获得日期
  95. UnlockTime []int `json:",omitempty"` // 每个徽章的解锁时间,多个
  96. Crdate string // 创建时间
  97. }
  98. // 徽章是否过期
  99. func (ub *UserBadge) IsExpires() bool {
  100. return ub.ExpiresTime <= common.GetTimeStamp()
  101. }
  102. // 是否能佩戴
  103. func (ub *UserBadge) IsWearable() bool {
  104. if ub.ExpiresTime > 0 {
  105. return ub.ExpiresTime > common.GetTimeStamp()
  106. }
  107. return ub.Level >= UsageLevel
  108. }
  109. // 徽章位置
  110. type BadgePosition struct {
  111. Position int // 穿戴的位置(返回结果集始终是从小到大排列)【-1:展示类,0以上是是佩戴的位置】
  112. BadgeId int // 徽章的id
  113. Level int // 徽章的等级
  114. }
  115. // 获取等级
  116. func GetLevel(exps int, levels []Badge_Level) (int, map[int]int) {
  117. var level int
  118. lvPoints := make(map[int]int, 0)
  119. for k, v := range levels {
  120. lvPoints[levels[k].Level] = levels[k].Points
  121. if v.Exps <= exps {
  122. level = levels[k].Level
  123. }
  124. }
  125. return level, lvPoints
  126. }
  127. // 检查排名分
  128. func CheckRankingScore(sysRank []RankInfo, param RankInfo) bool {
  129. for _, r := range sysRank {
  130. if r.Score > 0 && param.Score >= r.Score {
  131. return true
  132. }
  133. if r.Type == 0 {
  134. continue
  135. }
  136. if r.Type == param.Type && r.Rank == param.Rank {
  137. return true
  138. }
  139. }
  140. return false
  141. }
  142. // 游戏匹配
  143. func GameMatch(sysIds []int, id int) bool {
  144. for _, s := range sysIds {
  145. if s == id {
  146. return true
  147. }
  148. }
  149. return false
  150. }
  151. // 礼物id匹配
  152. func GiftIdMatch(sysIds []int, items []item.ItemPack) bool {
  153. for _, v := range sysIds {
  154. for _, i := range items {
  155. if v == i.ItemId {
  156. return true
  157. }
  158. }
  159. }
  160. return false
  161. }