limitgift.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package gmdata
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "leafstalk/log"
  6. "os"
  7. )
  8. // LimitGiftItem 礼包详情
  9. type LimitGiftItem struct {
  10. Id int32 `json:"id"` // 礼包ID
  11. Type int64 `json:"type"` // 礼包类型
  12. TypeName string `json:"typeName"` // 礼包类型名称
  13. Value []int `json:"value"` // 类型值
  14. ValueStr string `json:"-"` // 类型值
  15. Award [][]int64 `json:"award"` // 礼包奖励
  16. MaxPayCount int64 `json:"triggerCounter"` // 最大购买次数
  17. Price []int64 `json:"price"` // 价格 [购买方式,对应价格,_原价]
  18. Time int64 `json:"time"` // 开启后倒计时
  19. Cd int64 `json:"cd"` // cd过后才能刷新下一个礼包
  20. }
  21. var (
  22. LimitGiftList []*LimitGiftItem
  23. )
  24. // LoadLimitGift 加载配置信息
  25. func LoadLimitGift(confPath string) {
  26. var typeMap = make(map[int64]string)
  27. typeMap = map[int64]string{
  28. 1001: "登录",
  29. 1002: "冒险等级",
  30. 1003: "角色激活",
  31. 1004: "角色突破",
  32. 1005: "角色升星",
  33. 1006: "首次通关",
  34. 1007: "闯关失败",
  35. 1008: "品质装备",
  36. }
  37. // 任务列表
  38. loadLimitGiftFile(confPath+"/"+"LimitGift.json", &LimitGiftList)
  39. for _, v := range LimitGiftList {
  40. v.TypeName = fmt.Sprintf("%v(%v)", typeMap[v.Type], v.Type)
  41. bytes1, _ := json.Marshal(v.Value)
  42. v.ValueStr = string(bytes1)
  43. }
  44. }
  45. func loadLimitGiftFile(filePath string, val interface{}) {
  46. ptrFile, err := os.Open(filePath)
  47. if err != nil {
  48. log.Fatalln("读取json文件失败", err)
  49. }
  50. defer ptrFile.Close()
  51. decoder := json.NewDecoder(ptrFile)
  52. if err = decoder.Decode(&val); err != nil {
  53. log.Fatalln("loadLimitGiftFile Decoder failed ", filePath, err.Error())
  54. }
  55. }
  56. // GetLimitGift 获取指定礼包
  57. func GetLimitGift(id int32) *LimitGiftItem {
  58. for _, v := range LimitGiftList {
  59. if v.Id == id {
  60. return v
  61. }
  62. }
  63. return nil
  64. }