room_collect.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package room
  2. import (
  3. "bet24.com/servers/common"
  4. "bet24.com/servers/micros/audioroom/handler/config"
  5. pb "bet24.com/servers/micros/audioroom/proto"
  6. "bet24.com/servers/micros/audioroom/transaction/database"
  7. item "bet24.com/servers/micros/item_inventory/proto"
  8. )
  9. // 加载收集奖励
  10. func (this *Room) loadCollect() {
  11. list := database.GetCollectList(this.RoomId)
  12. for i, _ := range list {
  13. this.collectList = append(this.collectList, &list[i])
  14. }
  15. return
  16. }
  17. // 添加收集点数
  18. func (this *Room) AddCollect(point int) {
  19. if point <= 0 {
  20. return
  21. }
  22. // 今天日索引
  23. dayIndex := common.GetDayIndex(common.GetTimeStamp())
  24. for _, v := range this.collectList {
  25. if v.DayIndex != dayIndex {
  26. continue
  27. }
  28. v.Points += point
  29. // TODO:更新数据库
  30. go database.UpdateCollect(this.RoomId, v)
  31. return
  32. }
  33. info := &pb.RoomCollect{
  34. DayIndex: dayIndex,
  35. Points: point,
  36. Ratio: 0,
  37. Award: nil,
  38. Status: 0,
  39. }
  40. this.collectList = append(this.collectList, info)
  41. // TODO:更新数据库
  42. go database.UpdateCollect(this.RoomId, info)
  43. return
  44. }
  45. // 获取收集奖励
  46. func (this *Room) GetCollect() *pb.RoomCollect {
  47. // 今天日索引
  48. dayIndex := common.GetDayIndex(common.GetTimeStamp())
  49. upgradeInfo := config.Mgr.GetUpgradeInfo(this.Level, true)
  50. for _, v := range this.collectList {
  51. if v.DayIndex != dayIndex-1 {
  52. continue
  53. }
  54. // 低于显示点数条件
  55. if v.Points < config.Mgr.GetRoomConfig().CollectShowPoint {
  56. return v
  57. }
  58. // 已完成、已领取,直接返回
  59. if v.Status == pb.CollectStatus_Complete || v.Status == pb.CollectStatus_Awarded {
  60. return v
  61. }
  62. v.Status = pb.CollectStatus_Complete
  63. v.Ratio = upgradeInfo.Ratio
  64. amount := float64(v.Points) * (v.Ratio / 100.00)
  65. v.Award = append(v.Award, item.ItemPack{
  66. ItemId: item.Item_Chip,
  67. Count: int(amount),
  68. })
  69. // TODO:存入数据库
  70. go database.UpdateCollect(this.RoomId, v)
  71. return v
  72. }
  73. // 初始化数据
  74. info := &pb.RoomCollect{
  75. DayIndex: dayIndex - 1,
  76. Points: 0,
  77. Ratio: upgradeInfo.Ratio,
  78. Award: nil,
  79. Status: 0,
  80. }
  81. this.collectList = append(this.collectList, info)
  82. return info
  83. }
  84. // 领取收集奖励
  85. func (this *Room) GiftCollect(userId int) (retCode int, message string, items []item.ItemPack) {
  86. // 判断是否是管理员
  87. if this.UserId != userId {
  88. retCode, message = 11, "not homeowner"
  89. return
  90. }
  91. // 今天日索引
  92. dayIndex := common.GetDayIndex(common.GetTimeStamp())
  93. for _, v := range this.collectList {
  94. if v.DayIndex != dayIndex-1 {
  95. continue
  96. }
  97. // 活动中
  98. if v.Status == pb.CollectStatus_Active {
  99. retCode, message = 12, "collecting"
  100. return
  101. }
  102. // 判断是否已经领取
  103. if v.Status == pb.CollectStatus_Awarded {
  104. retCode, message = 13, "already received"
  105. return
  106. }
  107. // 设置为领取
  108. v.Status = pb.CollectStatus_Awarded
  109. // 统计收集的钻石总数
  110. for _, a := range v.Award {
  111. if a.ItemId != item.Item_Chip {
  112. continue
  113. }
  114. this.CollectDiamond += a.Count
  115. }
  116. go func() {
  117. // TODO:保存数据库
  118. database.UpdateCollect(this.RoomId, v)
  119. database.UpdateExtInfo(this.RoomId, &this.RoomExtInfo)
  120. // 给道具
  121. item.AddItems(this.UserId, v.Award, "语音房收集", common.LOGTYPE_AUDIOROOM_COLLECT)
  122. }()
  123. // 返回
  124. retCode, message, items = 1, "success", v.Award
  125. return
  126. }
  127. retCode, message = 14, "not data"
  128. return
  129. }