common.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package model
  2. import (
  3. "fmt"
  4. "math"
  5. )
  6. const (
  7. MaterilaId_Coin = 2001 // 金币道具id
  8. MaterilaId_Diamond = 2002 // 钻石道具id
  9. CommonHeroTicket = 4301 // 普通抽奖劵
  10. MythHeroTicket = 4401 // 神话抽奖劵
  11. TreasuresTicket = 4501 // 宝物抽奖劵
  12. HeroCoin = 5301 // 英雄金币
  13. )
  14. const (
  15. LoginPlatAccount = "h5"
  16. LoginPlatWeiXin = "wx"
  17. LoginPlatQQ = "qq"
  18. LoginPlatTouTiao = "tt"
  19. LoginPlatMgc = "mt"
  20. LoginPlatQuick = "QuickSDK"
  21. )
  22. const (
  23. CostSourceFortLevel = 1 //联盟升级
  24. CostSourceEnterChapter = 2 //进入章节
  25. CostSourcePartRuneLevel = 3 //符文升级
  26. CostSourcePartRuneRecast = 4 //符文重铸
  27. CostSourceHeroLevel = 5 //英雄升级
  28. CostSourceTreasureLevel = 6 //宝物升级
  29. CostSourceTreasureStar = 7 //宝物升星
  30. CostSourceHeroRecruit = 8 //英雄招募
  31. CostSourceTreasureRecruit = 9 //宝物招募
  32. CostSourceEpigraphRecruit = 10 //铭文招募
  33. CostSourcePointsRecruit = 11 //积分招募
  34. CostSourceRuneDisintegration = 12 //符文分解
  35. CostSourceHeroBuy = 13 //购买英雄
  36. CostSourceHeroSkinActive = 14 //英雄皮肤兑换
  37. CostSourceAdmin = 15 //后台添加
  38. CostItemBuy = 16 //游戏货币购买道具
  39. )
  40. const (
  41. LineBit = 12
  42. LineMask = 0x0fff
  43. )
  44. func CalcDocId2(dbId int64, line int64) int64 {
  45. return (dbId << LineBit) + int64(line)
  46. }
  47. func SplitDocId(docId int64) (dbId int64, line int) {
  48. // 分离出 dbId 和 line
  49. dbId = (docId >> LineBit) & math.MaxInt64 // 这里使用右移和位与操作来提取 dbId
  50. line = int(docId & LineMask)
  51. return
  52. }
  53. type VersionControl struct {
  54. Version string `json:"version"`
  55. }
  56. type PlatGroup struct {
  57. GId int `json:"id"`
  58. Plats []string `json:"group"`
  59. ChangeItems [][]int64 `json:"change"`
  60. }
  61. // SumMaterialToSlice 材料信息切片到map的转换
  62. func SumMaterialToMap(materials [][]int64) (map[int64]int64, error) {
  63. if len(materials) == 0 {
  64. return make(map[int64]int64), nil
  65. }
  66. costMap := make(map[int64]int64)
  67. for _, v := range materials {
  68. if len(v) != 2 {
  69. return nil, fmt.Errorf("material slice must have length of 2, but got %d", len(v))
  70. }
  71. costMap[v[0]] += v[1] // 使用 += 操作符更简洁
  72. }
  73. return costMap, nil
  74. }
  75. // func ExtractLineId(docId int64) int {
  76. // return int(docId & LineMask)
  77. // }
  78. // 合并同种材料
  79. // func MergeSameMaterials(lst []*MaterialData) []*MaterialData {
  80. // ret := make([]*MaterialData, 0)
  81. // for _, v := range lst {
  82. // isOk := false
  83. // for _, vv := range ret {
  84. // if vv.ID == v.ID {
  85. // vv.Count += v.Count
  86. // isOk = true
  87. // break
  88. // }
  89. // }
  90. // if !isOk {
  91. // tmp := &MaterialData{ID: v.ID, Count: v.Count}
  92. // ret = append(ret, tmp)
  93. // }
  94. // }
  95. // return ret
  96. // }