12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package gmdata
- import (
- "encoding/json"
- "fmt"
- "leafstalk/log"
- "os"
- )
- // LimitGiftItem 礼包详情
- type LimitGiftItem struct {
- Id int32 `json:"id"` // 礼包ID
- Type int64 `json:"type"` // 礼包类型
- TypeName string `json:"typeName"` // 礼包类型名称
- Value []int `json:"value"` // 类型值
- ValueStr string `json:"-"` // 类型值
- Award [][]int64 `json:"award"` // 礼包奖励
- MaxPayCount int64 `json:"triggerCounter"` // 最大购买次数
- Price []int64 `json:"price"` // 价格 [购买方式,对应价格,_原价]
- Time int64 `json:"time"` // 开启后倒计时
- Cd int64 `json:"cd"` // cd过后才能刷新下一个礼包
- }
- var (
- LimitGiftList []*LimitGiftItem
- )
- // LoadLimitGift 加载配置信息
- func LoadLimitGift(confPath string) {
- var typeMap = make(map[int64]string)
- typeMap = map[int64]string{
- 1001: "登录",
- 1002: "冒险等级",
- 1003: "角色激活",
- 1004: "角色突破",
- 1005: "角色升星",
- 1006: "首次通关",
- 1007: "闯关失败",
- 1008: "品质装备",
- }
- // 任务列表
- loadLimitGiftFile(confPath+"/"+"LimitGift.json", &LimitGiftList)
- for _, v := range LimitGiftList {
- v.TypeName = fmt.Sprintf("%v(%v)", typeMap[v.Type], v.Type)
- bytes1, _ := json.Marshal(v.Value)
- v.ValueStr = string(bytes1)
- }
- }
- func loadLimitGiftFile(filePath string, val interface{}) {
- ptrFile, err := os.Open(filePath)
- if err != nil {
- log.Fatalln("读取json文件失败", err)
- }
- defer ptrFile.Close()
- decoder := json.NewDecoder(ptrFile)
- if err = decoder.Decode(&val); err != nil {
- log.Fatalln("loadLimitGiftFile Decoder failed ", filePath, err.Error())
- }
- }
- // GetLimitGift 获取指定礼包
- func GetLimitGift(id int32) *LimitGiftItem {
- for _, v := range LimitGiftList {
- if v.Id == id {
- return v
- }
- }
- return nil
- }
|