item.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package proto
  2. // Item.Type
  3. const (
  4. _ = iota //无效值
  5. Item_Gold // 1=金币
  6. Item_Chip // 2=钻石
  7. Item_Vitality // 3=活跃度
  8. Item_Decoration // 4=装扮类
  9. Item_Speaker // 5=大喇叭
  10. Item_Consume // 6=其他消耗品
  11. Item_VirtualGift // 7=虚拟礼物
  12. Item_Addminutes // 8=充值话费
  13. Item_Physical // 9=实物道具
  14. Item_GiftCard // 10=购物卡
  15. Item_Cash // 11=现金
  16. Item_BattlePassExp // 12=battlepass经验
  17. Item_MatchTicket // 13=比赛门票
  18. Item_CashCoupon // 14=现金券(用来提现)
  19. Item_Vip // 15=vip时长
  20. )
  21. // sub type
  22. const (
  23. Item_Decoration_Invalid = iota
  24. Item_Decoration_HeadFrame // 1=头像框
  25. Item_Decoration_ChatBubble // 2=聊天气泡
  26. Item_Decoration_AudioRoomDataCard // 3=语聊房资料卡
  27. Item_Decoration_AudioRoomBackground // 4=语聊房背景
  28. Item_Decoration_EntryEffects // 5=进场特效
  29. Item_Decoration_CardBack // 6=牌背
  30. Item_Decoration_PokerTable // 7=牌桌
  31. Item_Decoration_Dice // 8=骰子
  32. Item_Decoration_Chessman // 9=棋子
  33. Item_Decoration_Chessboard // 10=棋盘
  34. Item_Decoration_FishCannon // 11=炮台
  35. )
  36. type Item struct {
  37. Id int // 道具ID
  38. ActiveId int // 限时道具使用ID(BaseId)
  39. Type int // 道具类型
  40. Name string // 道具名称
  41. Desc string // 道具描述,获取来源描述
  42. Start int `json:",omitempty"` // 开始时间戳 秒 0表示无时效
  43. Duration int `json:",omitempty"` // 持续时间 秒
  44. Value int `json:",omitempty"` // 如果是时效道具,可折算成金币
  45. IsShow int // 是否在背包显示
  46. IsGift int // 是否允许赠送(0=不允许赠送 1=允许赠送)
  47. ShowPrice int // 显示(出售)价格
  48. IconUrl string `json:",omitempty"` // 自定义Icon或动画资源
  49. DecorationType int `json:",omitempty"` // 是否装扮类型
  50. EffectInfo
  51. }
  52. // 实体道具
  53. type ItemPack struct {
  54. ItemId int `json:",omitempty"`
  55. Count int `json:",omitempty"`
  56. Day int `json:",omitempty"`
  57. }
  58. type ItemFirstCharge struct {
  59. BuyDayIndex int
  60. ProductId string
  61. ShopType int
  62. BasePrice float64
  63. Items []ItemPack
  64. }
  65. type UserItem struct {
  66. ItemId int // 道具ID
  67. Count int // 道具数量
  68. Start int // 开始时间戳 秒 0表示还未开始使用
  69. Duration int // 持续时间 秒
  70. }
  71. func GroupItems(items []ItemPack) []ItemPack {
  72. mapItems := make(map[int]int)
  73. for _, v := range items {
  74. mapItems[v.ItemId] += v.Count
  75. }
  76. var ret []ItemPack
  77. for itemId, count := range mapItems {
  78. ret = append(ret, ItemPack{ItemId: itemId, Count: count})
  79. }
  80. return ret
  81. }
  82. // 获取item 的额外数量
  83. func GetItemExtraCount(items []ItemPack, itemId int) int {
  84. for _, v := range items {
  85. if v.ItemId == itemId {
  86. return v.Count
  87. }
  88. }
  89. return 0
  90. }
  91. type GiftCard struct {
  92. ItemId int // 存在不同面额
  93. Key string // 兑换码
  94. UserId int // 持有者ID
  95. OperateStatus int // 操作状态
  96. ActivateTime int64 // 激活时间,0表示未被激活
  97. }