From 2250c07da4923880ad70f67e9bfaa6697e54e136 Mon Sep 17 00:00:00 2001
From: meixiongfeng <766881921@qq.com>
Date: Thu, 21 Jul 2022 20:23:04 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E8=A7=92=E8=8E=B7=E5=BE=97=E9=81=93?=
=?UTF-8?q?=E5=85=B7=E6=8C=89=E9=85=8D=E7=BD=AE=E8=A1=A8=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=A1=AB=E5=85=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
bin/json/game_cominitial.json | 72 ++++++++++++++++++++
modules/comp_configure.go | 24 ++++++-
modules/user/api_create.go | 23 ++++---
sys/configure/structs/game.comInitial.go | 42 ++++++++++++
sys/configure/structs/game.comInitialData.go | 40 +++++++++++
5 files changed, 190 insertions(+), 11 deletions(-)
create mode 100644 bin/json/game_cominitial.json
create mode 100644 sys/configure/structs/game.comInitial.go
create mode 100644 sys/configure/structs/game.comInitialData.go
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
+}