Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into liwei
This commit is contained in:
commit
41e02f49bf
@ -28,5 +28,15 @@
|
||||
"index": "task_reset",
|
||||
"var": "8",
|
||||
"intr": "日/周常任务刷新时间,8点"
|
||||
},
|
||||
{
|
||||
"index": "init_gold",
|
||||
"var": "100000",
|
||||
"intr": "初始金币"
|
||||
},
|
||||
{
|
||||
"index": "init_hero",
|
||||
"var": "15001, 25001",
|
||||
"intr": "初始英雄"
|
||||
}
|
||||
]
|
@ -13,6 +13,7 @@ var (
|
||||
//hero
|
||||
heroBuilders = []*builder{
|
||||
{
|
||||
desc: "英雄列表",
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.HeroSubTypeList,
|
||||
req: &pb.HeroListReq{},
|
||||
@ -23,7 +24,7 @@ var (
|
||||
fmt.Printf("%d- %v\n", (i + 1), v)
|
||||
}
|
||||
},
|
||||
// enabled: true,
|
||||
enabled: true,
|
||||
}, {
|
||||
mainType: string(comm.ModuleHero),
|
||||
subType: hero.HeroSubTypeInfo,
|
||||
@ -61,8 +62,8 @@ var (
|
||||
ExpCardID: "62bd0b4eca37634b8230d4be",
|
||||
Amount: 1,
|
||||
},
|
||||
rsp: &pb.HeroStrengthenUplvResp{},
|
||||
enabled: true,
|
||||
rsp: &pb.HeroStrengthenUplvResp{},
|
||||
// enabled: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -68,6 +68,7 @@ func (r *Robot) Run() {
|
||||
}
|
||||
|
||||
type builder struct {
|
||||
desc string
|
||||
mainType string
|
||||
subType string
|
||||
req proto.Message
|
||||
@ -90,6 +91,7 @@ func (r *Robot) addBuilders(builders []*builder) {
|
||||
func (r *Robot) handleReq() {
|
||||
for _, b := range r.builders {
|
||||
if b.req != nil && !b.requested {
|
||||
time.Sleep(time.Second * 1)
|
||||
b.requested = true
|
||||
b.start = time.Now()
|
||||
head := &pb.UserMessage{MainType: b.mainType, SubType: b.subType}
|
||||
@ -113,7 +115,7 @@ func (r *Robot) handleRsp(msg *pb.UserMessage) {
|
||||
if b.print == nil {
|
||||
printReply(msg, b)
|
||||
} else {
|
||||
fmt.Printf("===== rsp [%s.%s] =====\n", msg.MainType, msg.SubType)
|
||||
fmt.Printf("===== %s [%s.%s] =====\n", b.desc, msg.MainType, msg.SubType)
|
||||
b.print(b.rsp)
|
||||
fmt.Println("==============================")
|
||||
}
|
||||
@ -159,15 +161,14 @@ func (r *Robot) onUserLoaded() {
|
||||
r.RunNotify()
|
||||
//user
|
||||
r.RunUser()
|
||||
|
||||
//hero
|
||||
r.RunHero()
|
||||
//friend
|
||||
// r.RunFriend()
|
||||
|
||||
//pack
|
||||
// r.RunPack()
|
||||
|
||||
//hero
|
||||
r.RunHero()
|
||||
}
|
||||
|
||||
//注册账号
|
||||
@ -198,21 +199,21 @@ func (r *Robot) AccountRegister(account string, sid int32) {
|
||||
|
||||
fmt.Printf("account:%s 注册成功", regRsp.Account)
|
||||
//登录
|
||||
loginReg := &pb.UserLoginReq{
|
||||
Account: account,
|
||||
Sid: sid,
|
||||
var user_builders = []*builder{
|
||||
{
|
||||
desc: "登录",
|
||||
mainType: "user",
|
||||
subType: "login",
|
||||
req: &pb.UserLoginReq{
|
||||
Account: account,
|
||||
Sid: sid,
|
||||
},
|
||||
rsp: &pb.UserLoginResp{},
|
||||
enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
head := &pb.UserMessage{
|
||||
MainType: "user",
|
||||
SubType: "login",
|
||||
Sec: r.BuildSecStr(),
|
||||
}
|
||||
err = r.SendToClient(head, loginReg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r.addBuilders(user_builders)
|
||||
r.handleReq()
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,9 +226,9 @@ func printReply(msg *pb.UserMessage, builder *builder) {
|
||||
} else {
|
||||
tt = time.Since(builder.start)
|
||||
}
|
||||
log.Printf("rsp [%v] [%s.%s] [%v:%v]", tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data)
|
||||
log.Printf("rsp %s [%v] [%s.%s] [%v:%v]", builder.desc, tt, m.ReqMainType, m.ReqSubType, int32(m.Code), m.Data)
|
||||
} else {
|
||||
log.Printf("rsp [%v] [%s.%s] [%v]", time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp)
|
||||
log.Printf("rsp %s [%v] [%s.%s] [%v]", builder.desc, time.Since(builder.start), msg.MainType, msg.SubType, builder.rsp)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,13 +10,14 @@ import (
|
||||
var user_builders = []*builder{
|
||||
{
|
||||
//create
|
||||
desc: "创角",
|
||||
mainType: string(comm.ModuleUser),
|
||||
subType: user.UserSubTypeCreate,
|
||||
req: &pb.UserCreateReq{ //设置请求参数
|
||||
NickName: "乐谷6301",
|
||||
},
|
||||
rsp: &pb.UserCreateRsp{},
|
||||
// enabled: true,
|
||||
rsp: &pb.UserCreateRsp{},
|
||||
enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
1
go.mod
1
go.mod
@ -21,6 +21,7 @@ require (
|
||||
github.com/rs/xid v1.3.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/smallnest/rpcx v1.7.4
|
||||
github.com/spf13/cast v1.3.1
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
|
1
go.sum
1
go.sum
@ -623,6 +623,7 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE
|
||||
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
|
||||
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
|
||||
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
|
||||
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=
|
||||
|
@ -6,6 +6,11 @@ import (
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
)
|
||||
|
||||
const (
|
||||
game_global = "game_global.json"
|
||||
)
|
||||
|
||||
///配置管理基础组件
|
||||
@ -20,6 +25,7 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
|
||||
this.ModuleCompBase.Init(service, module, comp, options)
|
||||
this.S = service.(base.IRPCXService)
|
||||
this.M = module.(IModule)
|
||||
err = this.LoadConfigure(game_global, cfg.NewGame_global)
|
||||
return
|
||||
}
|
||||
|
||||
@ -44,3 +50,25 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
|
||||
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
||||
return configure.GetConfigure(name)
|
||||
}
|
||||
|
||||
//全局配置
|
||||
func (this *MCompConfigure) GetGlobalConf(key string) string {
|
||||
if v, err := this.GetConfigure(game_global); err != nil {
|
||||
log.Errorf("get global conf err:%v", err)
|
||||
return ""
|
||||
} else {
|
||||
var (
|
||||
configure *cfg.Game_global
|
||||
ok bool
|
||||
)
|
||||
if configure, ok = v.(*cfg.Game_global); !ok {
|
||||
log.Errorf("%T no is *cfg.Game_global", v)
|
||||
return ""
|
||||
}
|
||||
|
||||
if v, ok := configure.GetDataMap()[key]; ok {
|
||||
return v.Var
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -119,14 +119,14 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
||||
}
|
||||
|
||||
//消耗一张英雄卡
|
||||
func (this *ModelHero) consumeOneHeroCard(hero *pb.DBHero, count int32) error {
|
||||
if hero == nil {
|
||||
return fmt.Errorf("hero no exist")
|
||||
func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
|
||||
for i := 0; i < int(count); i++ {
|
||||
if err := this.moduleHero.modelHero.DelListlds(uid, heroId); err != nil {
|
||||
log.Errorf("%v", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
if hero.SameCount < count {
|
||||
return fmt.Errorf("card no enough")
|
||||
}
|
||||
return this.moduleHero.modelHero.DelListlds(hero.Uid, hero.Id)
|
||||
return
|
||||
}
|
||||
|
||||
//更新英雄数据
|
||||
|
@ -58,7 +58,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
|
||||
}
|
||||
|
||||
for _, v := range curList {
|
||||
err := this.modelHero.consumeOneHeroCard(v, count)
|
||||
err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
|
||||
if err != nil {
|
||||
return pb.ErrorCode_DBError
|
||||
}
|
||||
|
@ -41,6 +41,11 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
|
||||
"name": req.NickName,
|
||||
}
|
||||
|
||||
//设置初始金币
|
||||
if val := this.module.configure.GetGlobalConf("init_gold"); val != "" {
|
||||
update["gold"] = val
|
||||
}
|
||||
|
||||
err := this.module.modelUser.Change(session.GetUserId(), update)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
@ -48,11 +53,13 @@ func (this *apiComp) Create(session comm.IUserSession, result map[string]interfa
|
||||
}
|
||||
|
||||
//初始化英雄卡
|
||||
defaultHero := []int32{15001, 25001} //TODO 从配置中读取
|
||||
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_HeroInitCreat
|
||||
return
|
||||
if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
|
||||
defaultHero := utils.TrInt32(val)
|
||||
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_HeroInitCreat
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
16
modules/user/configure.go
Normal file
16
modules/user/configure.go
Normal file
@ -0,0 +1,16 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
)
|
||||
|
||||
type configureComp struct {
|
||||
modules.MCompConfigure
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.MCompConfigure.Init(service, module, comp, options)
|
||||
return
|
||||
}
|
@ -18,6 +18,7 @@ type User struct {
|
||||
api *apiComp
|
||||
modelUser *ModelUser
|
||||
modelSession *ModelSession
|
||||
configure *configureComp
|
||||
}
|
||||
|
||||
func (this *User) GetType() core.M_Modules {
|
||||
@ -35,6 +36,7 @@ func (this *User) OnInstallComp() {
|
||||
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
|
||||
this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession)
|
||||
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
||||
}
|
||||
|
||||
//获取英雄列表
|
||||
|
@ -3,7 +3,6 @@ package configure
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -31,7 +30,6 @@ func newSys(options Options) (sys *Configure, err error) {
|
||||
configure: make(map[string]interface{}),
|
||||
fileinfos: make(map[string]*FileInfo),
|
||||
}
|
||||
err = sys.init()
|
||||
return
|
||||
}
|
||||
|
||||
@ -45,20 +43,6 @@ type Configure struct {
|
||||
fileinfos map[string]*FileInfo
|
||||
}
|
||||
|
||||
const (
|
||||
game_com = "game_com.json"
|
||||
)
|
||||
|
||||
func (this *Configure) init() (err error) {
|
||||
|
||||
this.RegisterConfigure(game_com, cfg.NewGame_com)
|
||||
// _data := this.configure[game_com]
|
||||
// if _da, ok := _data.(*cfg.Game_com).GetDataMap()["max_char"]; ok {
|
||||
// log.Debugf("%b==%v", ok, _da.Var)
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Configure) Start() (err error) {
|
||||
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
|
||||
go func() {
|
||||
@ -166,12 +150,12 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
|
||||
|
||||
fliepath = path.Join(this.options.ConfigurePath, name)
|
||||
if fileInfo, err = os.Stat(fliepath); err != nil {
|
||||
err = fmt.Errorf("no fond file:%s", fliepath)
|
||||
err = fmt.Errorf("no found file:%s", fliepath)
|
||||
return
|
||||
}
|
||||
|
||||
if file, err = os.Open(fliepath); err != nil {
|
||||
err = fmt.Errorf("no fond file:%s", fliepath)
|
||||
err = fmt.Errorf("no found file:%s", fliepath)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
@ -1,9 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func ParseP(p string) (string, string, bool) {
|
||||
@ -34,3 +37,24 @@ func DeleteString(list []string, ele string) []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//转换包含数字字符串数组
|
||||
//eg. "3,4,5" to []int32{3,4,5}
|
||||
func TrInt32(val string) (nums []int32) {
|
||||
strArr := strings.Split(val, ",")
|
||||
if len(strArr) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, n := range strArr {
|
||||
if IsNum(strings.TrimSpace(n)) {
|
||||
nums = append(nums, cast.ToInt32(strings.TrimSpace(n)))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func IsNum(s string) bool {
|
||||
_, err := strconv.ParseFloat(s, 64)
|
||||
return err == nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user