jsonconf.go 7.76 KB
package jsonconf

import (
	"common/logger"
	"encoding/json"
	"errors"
	"io/ioutil"
	"os"
)

var (
	g_jsonconf  = new(GameConfig)
	g_otherconf = new(GameConfigEx)
)

type GameConfigEx struct {
	RedPacketConfig []RedPacketConfigDesc
}

type RedPacketConfigDesc struct {
	Id        int     `json:"id"`
	Redpacket float32 `json:"redpacket"`
}

func GetJsonConf() *GameConfig {
	return g_jsonconf
}

type RMBConfigDesc struct {
	Id        int     `json:"id"`
	Time      int     `json:"time"`
	Rmb_num   float32 `json:"rmb_num"`
	Login_day int     `json:"login_day"`
	Cat_level int     `json:"cat_level"`
}

type SignConfigDesc struct {
	Id     int `json:"id"`
	Day    int `json:"day"`
	Reward int `json:"reward"`
}

type GameConfig struct {
	AchievementConfig []Adesc     `json:"AchievementConfig"`
	Sheet2            []Sdesc     `json:"Sheet2"`
	CatConfig         []Cdesc     `json:"CatConfig"`
	CatRoomConfig     []CRdesc    `json:"CatRoomConfig"`
	RedCatConfig      []RCdesc    `json:"RedCatConfig"`
	RuleConfig        []RUdesc    `json:"RuleConfig"`
	ShopConfig        []Shopdesc  `json:"ShopConfig"`
	StoryConfig       []Shorydesc `json:"StoryConfig"`
	TaskConfig        []Adesc     `json:"TaskConfig"`
	RMBConfig         []RMBConfigDesc
	SignConfig        []SignConfigDesc
	TwistedEggConfig  []TwistedEggConfigDesc
	NewTaskConfig     []NewTaskConfigDesc
	LoveVideoConfig   []LoveVideoConfigDesc
	WorkPartTime      []WorkPartTimeDesc
}

type WorkPartTimeDesc struct {
	Id        int    `json:"id"`
	Type      int    `json:"type"`
	IsVideo   int    `json:"isVideo"`
	Time      int    `json:"time"`
	Parameter int    `json:"parameter"`
	Desc      string `json:"desc"`
	Reward    []int  `json:"reward"`
}

type LoveVideoConfigDesc struct {
	Id      int    `json:"id"`
	Content string `json:"content"`
	Reward  int    `json:"reward"`
}

type NewTaskConfigDesc struct {
	Id        int    `json:"id"`
	Type      int    `json:"type"`
	Parameter int    `json:"parameter"`
	Reward    []int  `json:"reward"`
	Desc      string `json:"desc"`
}

type TwistedEggConfigDesc struct {
	Id          int    `json:"id"`
	RewardIndex int    `json:"rewardIndex"`
	Reward      []int  `json:"reward"`
	Content     string `json:"content"`
	Weight      int    `json:"weight"`
}

type Adesc struct {
	Id        int    `json:"id"`
	Type      int    `json:"type"`
	Parameter int    `json:"parameter"`
	Desc      string `json:"desc"`
	Reward    int64  `json:"reward"`
}

type Sdesc struct {
	Id     int    `json:"1"`
	Desc   string `json:"在线x分钟"`
	Reserv string `json:"''"`
}

type Cdesc struct {
	Id       int     `json:"id"`
	Name     string  `json:"name"`
	Levelbuy int     `json:"level_buy"`
	Price    int64   `json:"price"`
	Goldget  int64   `json:"gold_get"`
	Ratio    float32 `json:"ratio"`
	Ilimit   int     `json:"increse_limit"`
	Interval float32 `json:"interval"`
	Recbuy   int     `json:"rec_buy"`
	CSNum    int     `json:"cat_stand_number"`
	Loveadd  float32 `json:"love_add"`
	Loveget  int     `json:"love_get"`
}

type CRdesc struct {
	Id     int    `json:"id"`
	Name   string `json:"name"`
	Love   int64  `json:"love"`
	Iscore int    `json:"is_core"`
	Catup  string `json:"cat_up"`
}

type RCdesc struct {
	Id       int     `json:"id"`
	Name     string  `json:"name"`
	Skin     string  `json:"skin"`
	Money    float32 `json:"money"`
	Rate     float32 `json:"rate"`
	Is37     int     `json:"is_37"`
	Descred  string  `json:"dec_red"`
	Descget  string  `json:"dec_get"`
	LeftTime int     `json:"lefttime"`
}

type RUdesc struct {
	Id        int    `json:"id"`
	Type      string `json:"type"`
	Parameter int    `json:"parameter"`
	Desc      string `json:"desc"`
}

type Shopdesc struct {
	Id           int    `json:"id"`
	Time         int    `json:"time"`
	Love         int    `json:"love"`
	Story        int    `json:"story"`
	Storyhanppen string `json:"story_hanppen"`
}

type Shorydesc struct {
	Id   int    `json:"id"`
	Time int    `json:"time"`
	Desc string `json:"desc"`
}

func file_get_contents(path string) ([]byte, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	return ioutil.ReadAll(f)
}

func GetLvRdNum(id int) (float32, error) {
	for _, v := range g_otherconf.RedPacketConfig {
		if v.Id == id {
			return v.Redpacket, nil
		}
	}
	return 0, errors.New("getcfg failed")
}

func LoadJsonConf(path string) (*GameConfig, error) {
	//pconf := &GameConfig{}
	content, err := file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return nil, err
	}

	err = json.Unmarshal([]byte(content), g_jsonconf)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return nil, err
	}

	opath := "../jsonconf/LevelRedpacketConfig.json"
	content, err = file_get_contents(opath)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_otherconf.RedPacketConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/RmbConfig.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.RMBConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/SignConfig.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.SignConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/TwistedEgg.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.TwistedEggConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/TaskConfig.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.NewTaskConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/LoveVideoConfig.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.LoveVideoConfig)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	path = "../jsonconf/WorkPartTime.json"
	content, err = file_get_contents(path)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	err = json.Unmarshal([]byte(content), &g_jsonconf.WorkPartTime)
	if err != nil {
		logger.Info("loadJsonConf failed1,err=%v", err)
		return g_jsonconf, err
	}

	logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err)
	logger.Info("loadJsonConf success g_otherconf=%v,err=%v", *g_otherconf, err)
	return g_jsonconf, err
}

func GetWorkPartTimeConfig(id int) *WorkPartTimeDesc {
	for _, v := range g_jsonconf.WorkPartTime {
		if v.Id == id {
			return &v
		}
	}
	return nil
}

func GetLoveVideoConfig(id int) *LoveVideoConfigDesc {
	for _, v := range g_jsonconf.LoveVideoConfig {
		if v.Id == id {
			return &v
		}
	}
	return nil
}

func GetTaskConfig(id int) *NewTaskConfigDesc {
	for _, v := range g_jsonconf.NewTaskConfig {
		if v.Id == id {
			return &v
		}
	}
	return nil
}

func GetTwistConfig(id int) *TwistedEggConfigDesc {
	for _, v := range g_jsonconf.TwistedEggConfig {
		if v.Id == id {
			return &v
		}
	}
	return nil
}

func GetsignConfig(id int) *SignConfigDesc {
	for _, v := range g_jsonconf.SignConfig {
		if v.Id == id {
			return &v
		}
	}
	return nil
}