diff --git a/go_dreamfactory.rar b/go_dreamfactory.rar deleted file mode 100644 index 7b1212ae4..000000000 Binary files a/go_dreamfactory.rar and /dev/null differ diff --git a/modules/game/api.go b/modules/game/api.go new file mode 100644 index 000000000..a929fda55 --- /dev/null +++ b/modules/game/api.go @@ -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 +} diff --git a/modules/game/configure_comp.go b/modules/game/configure_comp.go new file mode 100644 index 000000000..ef8da7ee6 --- /dev/null +++ b/modules/game/configure_comp.go @@ -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 +} diff --git a/modules/game/module.go b/modules/game/module.go new file mode 100644 index 000000000..0d62a9443 --- /dev/null +++ b/modules/game/module.go @@ -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) +} diff --git a/modules/game/module_test.go b/modules/game/module_test.go new file mode 100644 index 000000000..87d42fdf1 --- /dev/null +++ b/modules/game/module_test.go @@ -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) { + +} diff --git a/modules/pack/module.go b/modules/pack/module.go index 22b2bce0e..c9b8165ed 100644 --- a/modules/pack/module.go +++ b/modules/pack/module.go @@ -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 } diff --git a/pb/proto/forum/forum_db.proto b/pb/proto/forum/forum_db.proto new file mode 100644 index 000000000..f3d2253e6 --- /dev/null +++ b/pb/proto/forum/forum_db.proto @@ -0,0 +1,3 @@ +syntax = "proto3"; +option go_package = ".;pb"; + diff --git a/pb/proto/forum/forum_msg.proto b/pb/proto/forum/forum_msg.proto new file mode 100644 index 000000000..fbeb20245 --- /dev/null +++ b/pb/proto/forum/forum_msg.proto @@ -0,0 +1,2 @@ +syntax = "proto3"; +option go_package = ".;pb"; \ No newline at end of file