From c48ceefa17b597a2feacda26204c5595e569d686 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 24 Jun 2022 09:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=AD=A6=E5=99=A8=E8=83=8C?= =?UTF-8?q?=E5=8C=85api=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/equipment/api_equip.go | 28 +++++++++++++++++++++++++++- modules/equipment/module.go | 17 +++++++++++++++++ pb/proto/errorcode.proto | 3 +++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/modules/equipment/api_equip.go b/modules/equipment/api_equip.go index 4820955a0..650b7b007 100644 --- a/modules/equipment/api_equip.go +++ b/modules/equipment/api_equip.go @@ -2,22 +2,48 @@ package equipment import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" ) //参数校验 func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_Equip_Req) (result map[string]interface{}, code comm.ErrorCode) { + var ( + err error + errorCode pb.ErrorCode + equipment *pb.DB_Equipment + hero *pb.DB_HeroData + ) + if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(session.GetUserId(), req.EquipmentId); err != nil { + log.Errorf("Equip_Check err:%v", err) + code.Code = pb.ErrorCode_EquipmentOnFoundEquipment + return + } + + if hero, errorCode = this.module.hero.GetHero(req.HeroCardId); errorCode != pb.ErrorCode_Success { + code.Code = errorCode + return + } + result = map[string]interface{}{ + "equipment": equipment, + "hero": hero, + } return } ///英雄挂在装备 func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Equip_Req) (code pb.ErrorCode) { - + var ( + equipment *pb.DB_Equipment + hero *pb.DB_HeroData + ) defer func() { if code == pb.ErrorCode_Success { session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_Equip_Resp{}) } }() + equipment = agrs["equipment"].(*pb.DB_Equipment) + hero = agrs["hero"].(*pb.DB_HeroData) return } diff --git a/modules/equipment/module.go b/modules/equipment/module.go index 1985a7774..78eb4b435 100644 --- a/modules/equipment/module.go +++ b/modules/equipment/module.go @@ -4,6 +4,8 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" + + "github.com/smallnest/rpcx/log" ) /* @@ -18,9 +20,11 @@ func NewModule() core.IModule { type Equipment struct { modules.ModuleBase + service core.IService api_comp *Api_Comp configure_comp *Configure_Comp model_equipment_comp *Model_Equipment_Comp + hero comm.IHero } //模块名 @@ -31,6 +35,19 @@ func (this *Equipment) GetType() core.M_Modules { //模块初始化接口 注册用户创建角色事件 func (this *Equipment) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) + this.service = service + return +} + +//模块启动接口 +func (this *Equipment) Start() (err error) { + err = this.ModuleBase.Start() + var module interface{} + if module, err = this.service.GetModule(comm.SM_HeroModule); err != nil { + log.Errorf("Equipment Start err:%v", err) + return + } + this.hero = module.(comm.IHero) return } diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index b941e3935..f41e041f8 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -43,4 +43,7 @@ enum ErrorCode { PackNoFoundGird = 1201; //背包未找到物品格子 PackGridNumUpper = 1202; //背包格子数量已达上限 PackGirdAmountUpper = 1203; //背包格子容量已达上限 + + //equipment + EquipmentOnFoundEquipment = 1300; // 未找到武器 } \ No newline at end of file