上传背包接口优化
This commit is contained in:
parent
e8a503c99b
commit
d183100176
Binary file not shown.
29
modules/game/api.go
Normal file
29
modules/game/api.go
Normal file
@ -0,0 +1,29 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
|
||||
/*
|
||||
API
|
||||
*/
|
||||
type Api_Comp struct {
|
||||
modules.MComp_GateComp
|
||||
service core.IService
|
||||
module *Game
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.module = module.(*Game)
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Api_Comp) Start() (err error) {
|
||||
err = this.MComp_GateComp.Start()
|
||||
return
|
||||
}
|
42
modules/game/configure_comp.go
Normal file
42
modules/game/configure_comp.go
Normal file
@ -0,0 +1,42 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/modules"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
|
||||
const (
|
||||
game_equipment = "game_equipment.json"
|
||||
)
|
||||
|
||||
///配置管理组件
|
||||
type Configure_Comp struct {
|
||||
modules.MComp_Configure
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.ModuleCompBase.Init(service, module, comp, options)
|
||||
this.LoadConfigure(game_equipment, cfg.NewGame_equipment)
|
||||
return
|
||||
}
|
||||
|
||||
//获取装备配置数据
|
||||
func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equipment, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, err = this.GetConfigure(game_equipment); err != nil {
|
||||
return
|
||||
} else {
|
||||
if configure, ok = v.(*cfg.Game_equipment); !ok {
|
||||
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
41
modules/game/module.go
Normal file
41
modules/game/module.go
Normal file
@ -0,0 +1,41 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
)
|
||||
|
||||
/*
|
||||
模块名:游戏模块
|
||||
描述:游戏战斗逻辑模块
|
||||
开发:李伟
|
||||
*/
|
||||
func NewModule() core.IModule {
|
||||
m := new(Game)
|
||||
return m
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
modules.ModuleBase
|
||||
api_comp *Api_Comp
|
||||
configure_comp *Configure_Comp
|
||||
}
|
||||
|
||||
//模块名
|
||||
func (this *Game) GetType() core.M_Modules {
|
||||
return comm.SM_EquipmentModule
|
||||
}
|
||||
|
||||
//模块初始化接口 注册用户创建角色事件
|
||||
func (this *Game) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
return
|
||||
}
|
||||
|
||||
//装备组件
|
||||
func (this *Game) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||
}
|
74
modules/game/module_test.go
Normal file
74
modules/game/module_test.go
Normal file
@ -0,0 +1,74 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/sys/db"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newService(ops ...rpcx.Option) core.IService {
|
||||
s := new(TestService)
|
||||
s.Configure(ops...)
|
||||
return s
|
||||
}
|
||||
|
||||
//梦工厂基础服务对象
|
||||
type TestService struct {
|
||||
rpcx.RPCXService
|
||||
}
|
||||
|
||||
//初始化相关系统
|
||||
func (this *TestService) InitSys() {
|
||||
this.RPCXService.InitSys()
|
||||
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.cache success!")
|
||||
}
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.configure success!")
|
||||
}
|
||||
}
|
||||
|
||||
var service core.IService
|
||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||
var module = new(Game)
|
||||
|
||||
//测试环境下初始化db和cache 系统
|
||||
func TestMain(m *testing.M) {
|
||||
service = newService(
|
||||
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
)
|
||||
service.OnInstallComp( //装备组件
|
||||
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
||||
)
|
||||
go func() {
|
||||
lego.Run(service, //运行模块
|
||||
module,
|
||||
)
|
||||
}()
|
||||
time.Sleep(time.Second * 3)
|
||||
defer os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func Test_Module(t *testing.T) {
|
||||
|
||||
}
|
@ -64,10 +64,18 @@ func (this *Pack) QueryUserPackItemsAmount(uId string, itemid ...int32) (result
|
||||
}
|
||||
|
||||
///添加单个物品到背包 (可以加物品和减物品)
|
||||
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) {
|
||||
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (code pb.ErrorCode) {
|
||||
var err error
|
||||
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil)
|
||||
if err = this.model_pack_comp.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
|
||||
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
|
||||
if err == ItemNotEnoughError {
|
||||
code = pb.ErrorCode_PackNoEnough
|
||||
} else if err == PackGridNumUpper {
|
||||
code = pb.ErrorCode_PackGridNumUpper
|
||||
} else {
|
||||
code = pb.ErrorCode_Unknown
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
3
pb/proto/forum/forum_db.proto
Normal file
3
pb/proto/forum/forum_db.proto
Normal file
@ -0,0 +1,3 @@
|
||||
syntax = "proto3";
|
||||
option go_package = ".;pb";
|
||||
|
2
pb/proto/forum/forum_msg.proto
Normal file
2
pb/proto/forum/forum_msg.proto
Normal file
@ -0,0 +1,2 @@
|
||||
syntax = "proto3";
|
||||
option go_package = ".;pb";
|
Loading…
Reference in New Issue
Block a user