diff --git a/bin/json/game_cominitial.json b/bin/json/game_cominitial.json new file mode 100644 index 000000000..e2e622314 --- /dev/null +++ b/bin/json/game_cominitial.json @@ -0,0 +1,72 @@ +[ + { + "index": "1", + "var": [ + { + "a": "hero", + "t": "25001", + "n": 1 + } + ] + }, + { + "index": "2", + "var": [ + { + "a": "item", + "t": "1", + "n": 1 + } + ] + }, + { + "index": "3", + "var": [ + { + "a": "attr", + "t": "gold", + "n": 50000 + } + ] + }, + { + "index": "4", + "var": [ + { + "a": "hero", + "t": "24003", + "n": 1 + } + ] + }, + { + "index": "5", + "var": [ + { + "a": "hero", + "t": "25004", + "n": 1 + } + ] + }, + { + "index": "6", + "var": [ + { + "a": "hero", + "t": "35002", + "n": 1 + } + ] + }, + { + "index": "7", + "var": [ + { + "a": "item", + "t": "2", + "n": 1 + } + ] + } +] \ No newline at end of file diff --git a/modules/comp_configure.go b/modules/comp_configure.go index fefa87d15..0ecc8a2c4 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -1,6 +1,7 @@ package modules import ( + "fmt" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" @@ -9,7 +10,8 @@ import ( ) const ( - game_global = "game_global.json" + game_global = "game_global.json" + game_cominitial = "game_cominitial.json" ) ///配置管理基础组件 @@ -21,6 +23,7 @@ type MCompConfigure struct { func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) err = this.LoadConfigure(game_global, cfg.NewGame_global) + err = this.LoadConfigure(game_cominitial, cfg.NewGame_comInitial) return } @@ -47,8 +50,9 @@ func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) } //全局配置 + func (this *MCompConfigure) GetGlobalConf(key string) string { - if v, err := this.GetConfigure(game_global); err != nil { + if v, err := this.GetConfigure(game_cominitial); err != nil { log.Errorf("get global conf err:%v", err) return "" } else { @@ -67,3 +71,19 @@ func (this *MCompConfigure) GetGlobalConf(key string) string { } return "" } + +func (this *MCompConfigure) GetGlobalInitConf() (configure *cfg.Game_comInitial, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_cominitial); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_comInitial); !ok { + err = fmt.Errorf("%T no is *cfg.Game_comInitial", v) + return + } + } + return +} diff --git a/modules/user/api_create.go b/modules/user/api_create.go index c8da375d7..82c78c417 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -3,7 +3,6 @@ package user import ( "go_dreamfactory/comm" "go_dreamfactory/pb" - "go_dreamfactory/utils" "github.com/spf13/cast" "google.golang.org/protobuf/proto" @@ -76,15 +75,21 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c } //初始化英雄卡 - if val := this.module.configure.GetGlobalConf("init_hero"); val != "" { - defaultHero := utils.TrInt32(val) - err = this.hero.CreateHeroes(session.GetUserId(), defaultHero...) - if err != nil { - code = pb.ErrorCode_HeroInitCreat - return - } - } + if val, err := this.module.configure.GetGlobalInitConf(); err == nil { + for _, v := range val.GetDataList() { + code = this.module.DispenseRes(session, v.Var, false) + if code != pb.ErrorCode_Success { + this.module.Errorf("资源发放失败,%v", code) + } + } + //defaultHero := utils.TrInt32(val) + // err = this.hero.CreateHeroes(session.GetUserId(), defaultHero...) + // if err != nil { + // code = pb.ErrorCode_HeroInitCreat + // return + // } + } //初始化用户设置 this.module.modelSetting.InitSetting(session.GetUserId()) diff --git a/sys/configure/structs/game.comInitial.go b/sys/configure/structs/game.comInitial.go new file mode 100644 index 000000000..7b3e7d1ab --- /dev/null +++ b/sys/configure/structs/game.comInitial.go @@ -0,0 +1,42 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +package cfg + +type Game_comInitial struct { + _dataMap map[string]*Game_comInitialData + _dataList []*Game_comInitialData +} + +func NewGame_comInitial(_buf []map[string]interface{}) (*Game_comInitial, error) { + _dataList := make([]*Game_comInitialData, 0, len(_buf)) + dataMap := make(map[string]*Game_comInitialData) + for _, _ele_ := range _buf { + if _v, err2 := NewGame_comInitialData(_ele_); err2 != nil { + return nil, err2 + } else { + _dataList = append(_dataList, _v) + dataMap[_v.Index] = _v + } + } + return &Game_comInitial{_dataList:_dataList, _dataMap:dataMap}, nil +} + +func (table *Game_comInitial) GetDataMap() map[string]*Game_comInitialData { + return table._dataMap +} + +func (table *Game_comInitial) GetDataList() []*Game_comInitialData { + return table._dataList +} + +func (table *Game_comInitial) Get(key string) *Game_comInitialData { + return table._dataMap[key] +} + + diff --git a/sys/configure/structs/game.comInitialData.go b/sys/configure/structs/game.comInitialData.go new file mode 100644 index 000000000..5439f9597 --- /dev/null +++ b/sys/configure/structs/game.comInitialData.go @@ -0,0 +1,40 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +package cfg + +import "errors" + +type Game_comInitialData struct { + Index string + Var []*Game_atn +} + +func (Game_comInitialData) GetTypeId() int { + return 1849654857 +} + +func NewGame_comInitialData(_buf map[string]interface{}) (_v *Game_comInitialData, err error) { + _v = &Game_comInitialData{} + { var _ok_ bool; if _v.Index, _ok_ = _buf["index"].(string); !_ok_ { err = errors.New("index error"); return } } + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["var"].([]interface{}); !_ok_ { err = errors.New("var error"); return } + + _v.Var = make([]*Game_atn, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ *Game_atn + { var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = NewGame_atn(_x_); err != nil { return } } + _v.Var = append(_v.Var, _list_v_) + } + } + + return +}