上传 变量接口命名规范

This commit is contained in:
liwei1dao 2022-06-28 14:51:58 +08:00
parent 6c58432270
commit b6a3ce955a
26 changed files with 208 additions and 209 deletions

View File

@ -8,14 +8,14 @@ import (
) )
///配置管理基础组件 ///配置管理基础组件
type MComp_Configure struct { type MCompConfigure struct {
cbase.ModuleCompBase cbase.ModuleCompBase
S base.IRPCXService //rpc服务对象 S base.IRPCXService //rpc服务对象
M IModule //当前业务模块 M IModule //当前业务模块
} }
//组件初始化接口 //组件初始化接口
func (this *MComp_Configure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.S = service.(base.IRPCXService) this.S = service.(base.IRPCXService)
this.M = module.(IModule) this.M = module.(IModule)
@ -23,12 +23,12 @@ func (this *MComp_Configure) Init(service core.IService, module core.IModule, co
} }
//加载一个配置文件 //加载一个配置文件
func (this *MComp_Configure) LoadConfigure(name string, fn interface{}) (err error) { func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
return configure.RegisterConfigure(name, fn) return configure.RegisterConfigure(name, fn)
} }
//加载多个配置文件 //加载多个配置文件
func (this *MComp_Configure) LoadMultiConfigure(confs map[string]interface{}) (err error) { func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
for k, v := range confs { for k, v := range confs {
err = configure.RegisterConfigure(k, v) err = configure.RegisterConfigure(k, v)
if err != nil { if err != nil {
@ -39,6 +39,6 @@ func (this *MComp_Configure) LoadMultiConfigure(confs map[string]interface{}) (e
} }
//读取配置数据 //读取配置数据
func (this *MComp_Configure) GetConfigure(name string) (v interface{}, err error) { func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name) return configure.GetConfigure(name)
} }

View File

@ -28,7 +28,7 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
/* /*
模块 网关组件 接收处理用户传递消息 模块 网关组件 接收处理用户传递消息
*/ */
type MComp_GateComp struct { type MCompGate struct {
cbase.ModuleCompBase cbase.ModuleCompBase
service base.IRPCXService //rpc服务对象 service base.IRPCXService //rpc服务对象
module core.IModule //当前业务模块 module core.IModule //当前业务模块
@ -37,7 +37,7 @@ type MComp_GateComp struct {
} }
//组件初始化接口 //组件初始化接口
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *MCompGate) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.module = module this.module = module
@ -46,7 +46,7 @@ func (this *MComp_GateComp) Init(service core.IService, module core.IModule, com
} }
//组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中 //组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中
func (this *MComp_GateComp) Start() (err error) { func (this *MCompGate) Start() (err error) {
if err = this.ModuleCompBase.Start(); err != nil { if err = this.ModuleCompBase.Start(); err != nil {
return return
} }
@ -61,7 +61,7 @@ func (this *MComp_GateComp) Start() (err error) {
} }
//反射注册相关接口道services/comp_gateroute.go 对象中 //反射注册相关接口道services/comp_gateroute.go 对象中
func (this *MComp_GateComp) suitableMethods(typ reflect.Type) { func (this *MCompGate) suitableMethods(typ reflect.Type) {
for m := 0; m < typ.NumMethod(); m++ { for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m) method := typ.Method(m)
this.reflectionRouteHandle(method) this.reflectionRouteHandle(method)
@ -70,7 +70,7 @@ func (this *MComp_GateComp) suitableMethods(typ reflect.Type) {
} }
//反射注册路由处理函数 //反射注册路由处理函数
func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) { func (this *MCompGate) reflectionRouteHandle(method reflect.Method) {
mtype := method.Type mtype := method.Type
mname := method.Name mname := method.Name
if method.PkgPath != "" { if method.PkgPath != "" {
@ -105,7 +105,7 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
} }
//反射注册路由校验函数 //反射注册路由校验函数
func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) { func (this *MCompGate) reflectionRouteCheck(method reflect.Method) {
mtype := method.Type mtype := method.Type
mname := strings.Split(method.Name, "_") mname := strings.Split(method.Name, "_")
if len(mname) != 2 || mname[1] != "Check" { if len(mname) != 2 || mname[1] != "Check" {
@ -142,14 +142,14 @@ func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) {
this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method) this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method)
} }
func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool { func (this *MCompGate) isExportedOrBuiltinType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr { for t.Kind() == reflect.Ptr {
t = t.Elem() t = t.Elem()
} }
return this.isExported(t.Name()) || t.PkgPath() == "" return this.isExported(t.Name()) || t.PkgPath() == ""
} }
func (this *MComp_GateComp) isExported(name string) bool { func (this *MCompGate) isExported(name string) bool {
rune, _ := utf8.DecodeRuneInString(name) rune, _ := utf8.DecodeRuneInString(name)
return unicode.IsUpper(rune) return unicode.IsUpper(rune)
} }

View File

@ -23,7 +23,7 @@ import (
基础组件 缓存组件 读写缓存数据 基础组件 缓存组件 读写缓存数据
DB组件也封装进来 DB组件也封装进来
*/ */
type Model_Comp struct { type MCompModel struct {
cbase.ModuleCompBase cbase.ModuleCompBase
Redis redis.ISys Redis redis.ISys
DB mgo.ISys DB mgo.ISys
@ -35,25 +35,25 @@ const (
) )
//组件初始化接口 //组件初始化接口
func (this *Model_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *MCompModel) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.Redis = cache.Redis() this.Redis = cache.Redis()
this.DB = db.Mgo() this.DB = db.Mgo()
return return
} }
func (this *Model_Comp) Start() (err error) { func (this *MCompModel) Start() (err error) {
err = this.ModuleCompBase.Start() err = this.ModuleCompBase.Start()
return return
} }
func (this *Model_Comp) ukey(uid string) string { func (this *MCompModel) ukey(uid string) string {
return fmt.Sprintf("%s:%s", this.TableName, uid) return fmt.Sprintf("%s:%s", this.TableName, uid)
} }
func (this *Model_Comp) ukeylist(uid string, id string) string { func (this *MCompModel) ukeylist(uid string, id string) string {
return fmt.Sprintf("%s:%s-%s", this.TableName, uid, id) return fmt.Sprintf("%s:%s-%s", this.TableName, uid, id)
} }
func (this *Model_Comp) InsertModelLogs(table string, uID string, target interface{}) (err error) { func (this *MCompModel) InsertModelLogs(table string, uID string, target interface{}) (err error) {
data := &comm.Autogenerated{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), ID: primitive.NewObjectID().Hex(),
@ -70,7 +70,7 @@ func (this *Model_Comp) InsertModelLogs(table string, uID string, target interfa
return err return err
} }
func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interface{}) (err error) { func (this *MCompModel) DeleteModelLogs(table string, uID string, where interface{}) (err error) {
data := &comm.Autogenerated{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), ID: primitive.NewObjectID().Hex(),
@ -88,7 +88,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac
return err return err
} }
func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) { func (this *MCompModel) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) {
data := &comm.Autogenerated{ data := &comm.Autogenerated{
ID: primitive.NewObjectID().Hex(), ID: primitive.NewObjectID().Hex(),
@ -108,7 +108,7 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M,
} }
//添加新的数据 //添加新的数据
func (this *Model_Comp) Add(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { func (this *MCompModel) Add(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) {
if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil {
return return
} }
@ -122,7 +122,7 @@ func (this *Model_Comp) Add(uid string, data interface{}, attrs ...*cache.Operat
} }
//添加新的数据到列表 //添加新的数据到列表
func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs ...*cache.OperationAttr) (err error) { func (this *MCompModel) AddList(uid string, id string, data interface{}, attrs ...*cache.OperationAttr) (err error) {
key := this.ukeylist(uid, id) key := this.ukeylist(uid, id)
if err = this.Redis.HMSet(key, data); err != nil { if err = this.Redis.HMSet(key, data); err != nil {
return return
@ -140,7 +140,7 @@ func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs .
} }
//添加新的多个数据到列表 data map[string]type //添加新的多个数据到列表 data map[string]type
func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) { func (this *MCompModel) AddLists(uid string, data interface{}, attrs ...*cache.OperationAttr) (err error) {
vof := reflect.ValueOf(data) vof := reflect.ValueOf(data)
if !vof.IsValid() { if !vof.IsValid() {
return fmt.Errorf("Model_Comp: AddLists(nil)") return fmt.Errorf("Model_Comp: AddLists(nil)")
@ -180,7 +180,7 @@ func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.O
} }
//修改数据多个字段 uid 作为主键 //修改数据多个字段 uid 作为主键
func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { func (this *MCompModel) Change(uid string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) {
if err = this.Redis.HMSet(this.ukey(uid), data); err != nil { if err = this.Redis.HMSet(this.ukey(uid), data); err != nil {
return return
} }
@ -194,7 +194,7 @@ func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs ..
} }
//修改数据多个字段 uid 作为主键 //修改数据多个字段 uid 作为主键
func (this *Model_Comp) ChangeList(uid string, _id string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) { func (this *MCompModel) ChangeList(uid string, _id string, data map[string]interface{}, attrs ...*cache.OperationAttr) (err error) {
if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil { if err = this.Redis.HMSet(this.ukeylist(uid, _id), data); err != nil {
return return
} }
@ -208,7 +208,7 @@ func (this *Model_Comp) ChangeList(uid string, _id string, data map[string]inter
} }
//读取全部数据 //读取全部数据
func (this *Model_Comp) Get(uid string, data interface{}) (err error) { func (this *MCompModel) Get(uid string, data interface{}) (err error) {
if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil { if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil {
return return
} }
@ -223,7 +223,7 @@ func (this *Model_Comp) Get(uid string, data interface{}) (err error) {
} }
//获取列表数据 注意 data 必须啊转 切片的指针 *[]type //获取列表数据 注意 data 必须啊转 切片的指针 *[]type
func (this *Model_Comp) GetList(uid string, data interface{}) (err error) { func (this *MCompModel) GetList(uid string, data interface{}) (err error) {
var keys map[string]string = make(map[string]string) var keys map[string]string = make(map[string]string)
var c *mongo.Cursor var c *mongo.Cursor
t := reflect.TypeOf(data) t := reflect.TypeOf(data)
@ -314,25 +314,25 @@ func (this *Model_Comp) GetList(uid string, data interface{}) (err error) {
} }
//读取单个数据中 多个字段数据 //读取单个数据中 多个字段数据
func (this *Model_Comp) GetFields(uid string, data interface{}, fields ...string) (err error) { func (this *MCompModel) GetFields(uid string, data interface{}, fields ...string) (err error) {
this.Redis.HMGet(this.ukey(uid), data, fields...) this.Redis.HMGet(this.ukey(uid), data, fields...)
return return
} }
//读取List列表中单个数据中 多个字段数据 //读取List列表中单个数据中 多个字段数据
func (this *Model_Comp) GetListFields(uid string, id string, data interface{}, fields ...string) (err error) { func (this *MCompModel) GetListFields(uid string, id string, data interface{}, fields ...string) (err error) {
this.Redis.HMGet(this.ukeylist(uid, id), data, fields...) this.Redis.HMGet(this.ukeylist(uid, id), data, fields...)
return return
} }
//读取列表数据中单个数据 //读取列表数据中单个数据
func (this *Model_Comp) GetListObj(uid string, id string, data interface{}) (err error) { func (this *MCompModel) GetListObj(uid string, id string, data interface{}) (err error) {
err = this.Redis.HGetAll(this.ukeylist(uid, id), data) err = this.Redis.HGetAll(this.ukeylist(uid, id), data)
return return
} }
//删除用户数据 //删除用户数据
func (this *Model_Comp) Del(uid string) (err error) { func (this *MCompModel) Del(uid string) (err error) {
err = this.Redis.Delete(this.ukey(uid)) err = this.Redis.Delete(this.ukey(uid))
if err != nil { if err != nil {
return err return err
@ -342,7 +342,7 @@ func (this *Model_Comp) Del(uid string) (err error) {
} }
//删除多条数据 //删除多条数据
func (this *Model_Comp) DelListlds(uid string, ids ...string) (err error) { func (this *MCompModel) DelListlds(uid string, ids ...string) (err error) {
listkey := this.ukey(uid) listkey := this.ukey(uid)
for _, v := range ids { for _, v := range ids {
key := this.ukeylist(uid, v) key := this.ukeylist(uid, v)
@ -357,7 +357,7 @@ func (this *Model_Comp) DelListlds(uid string, ids ...string) (err error) {
} }
//日志操作可选项 //日志操作可选项
func (this *Model_Comp) logOpt(uid string, data interface{}, attrs ...*cache.OperationAttr) error { func (this *MCompModel) logOpt(uid string, data interface{}, attrs ...*cache.OperationAttr) error {
ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil) ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil)
if ret == nil { //启用mgolog if ret == nil { //启用mgolog
ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil) ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil)

View File

@ -14,20 +14,20 @@ import (
) )
type DB_Comp struct { type DB_Comp struct {
modules.Model_Comp modules.MCompModel
task chan string task chan string
isInit bool isInit bool
} }
func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, options) this.MCompModel.Init(service, module, comp, options)
this.task = make(chan string, TaskMaxNum) this.task = make(chan string, TaskMaxNum)
return return
} }
func (this *DB_Comp) Start() (err error) { func (this *DB_Comp) Start() (err error) {
err = this.Model_Comp.Start() err = this.MCompModel.Start()
model_count := this.Model_TotalCount() model_count := this.Model_TotalCount()
if model_count > 0 { //1000 if model_count > 0 { //1000
this.Redis.Set(comm.DBService_Status, true, -1) this.Redis.Set(comm.DBService_Status, true, -1)

View File

@ -9,21 +9,21 @@ import (
/* /*
装备模块 API 装备模块 API
*/ */
type Api_Comp struct { type ApiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Equipment module *Equipment
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ApiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Equipment) this.module = module.(*Equipment)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *ApiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
return return
} }

View File

@ -8,7 +8,7 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_Equip_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *ApiComp) Equip_Check(session comm.IUserSession, req *pb.Equipment_Equip_Req) (result map[string]interface{}, code comm.ErrorCode) {
var ( var (
err error err error
errorCode pb.ErrorCode errorCode pb.ErrorCode
@ -20,12 +20,12 @@ func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_E
equipments = make([]*pb.DB_Equipment, len(req.EquipmentId)) equipments = make([]*pb.DB_Equipment, len(req.EquipmentId))
for i, v := range req.EquipmentId { for i, v := range req.EquipmentId {
if v != "" { if v != "" {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { if equipments[i], err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return return
} }
if confs[i], err = this.module.configure_comp.GetEquipmentConfigureById(equipments[i].CId); err != nil { if confs[i], err = this.module.configure.GetEquipmentConfigureById(equipments[i].CId); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return return
@ -46,7 +46,7 @@ func (this *Api_Comp) Equip_Check(session comm.IUserSession, req *pb.Equipment_E
} }
///英雄挂在装备 ///英雄挂在装备
func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Equip_Req) (code pb.ErrorCode) { func (this *ApiComp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Equip_Req) (code pb.ErrorCode) {
var ( var (
err error err error
confs []*cfg.Game_equipData confs []*cfg.Game_equipData
@ -55,11 +55,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
updatequipment []*pb.DB_Equipment updatequipment []*pb.DB_Equipment
hero *pb.DB_HeroData hero *pb.DB_HeroData
) )
defer func() {
if code == pb.ErrorCode_Success {
session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_Equip_Resp{})
}
}()
confs = agrs["conf"].([]*cfg.Game_equipData) confs = agrs["conf"].([]*cfg.Game_equipData)
equipments = agrs["equipment"].([]*pb.DB_Equipment) equipments = agrs["equipment"].([]*pb.DB_Equipment)
updatequipment = make([]*pb.DB_Equipment, 0) updatequipment = make([]*pb.DB_Equipment, 0)
@ -68,7 +64,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
for i, v := range hero.EquipID { for i, v := range hero.EquipID {
if v != "" { if v != "" {
if equipments[i] != nil && v != equipments[i].Id { if equipments[i] != nil && v != equipments[i].Id {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err) log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
@ -77,7 +73,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
equipments[i].HeroId = hero.Id equipments[i].HeroId = hero.Id
updatequipment = append(updatequipment, equipment, equipments[i]) updatequipment = append(updatequipment, equipment, equipments[i])
} else if equipments[i] == nil { } else if equipments[i] == nil {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err) log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
@ -100,7 +96,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
} }
} }
if code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success { if code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success {
if err = this.module.model_equipment_comp.Equipment_UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil { if err = this.module.modelequipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
log.Errorf("Equip err%v", err) log.Errorf("Equip err%v", err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return

View File

@ -7,26 +7,27 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.Equipment_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *ApiComp) Getlist_Check(session comm.IUserSession, req *pb.Equipment_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
///获取用户装备列表 ///获取用户装备列表
func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_GetList_Req) (code pb.ErrorCode) { func (this *ApiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_GetList_Req, resp *pb.Equipment_GetList_Resp) (code pb.ErrorCode) {
var ( var (
err error err error
items []*pb.DB_Equipment items []*pb.DB_Equipment
) )
defer func() { // defer func() {
if code == pb.ErrorCode_Success { // if code == pb.ErrorCode_Success {
session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items}) // session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items})
} // }
}() // }()
if items, err = this.module.model_equipment_comp.Equipment_QueryUserEquipments(session.GetUserId()); err != nil { if items, err = this.module.modelequipment.QueryUserEquipments(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err) log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return
} }
resp.Equipments = items
return return
} }

View File

@ -12,7 +12,7 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment_Upgrade_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *ApiComp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment_Upgrade_Req) (result map[string]interface{}, code comm.ErrorCode) {
var ( var (
err error err error
conf *cfg.Game_equipData conf *cfg.Game_equipData
@ -24,18 +24,18 @@ func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment
code.Code = pb.ErrorCode_ReqParameterError code.Code = pb.ErrorCode_ReqParameterError
return return
} }
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), req.EquipmentId); err != nil { if equipment, err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), req.EquipmentId); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return return
} }
if conf, err = this.module.configure_comp.GetEquipmentConfigureById(equipment.CId); err != nil { if conf, err = this.module.configure.GetEquipmentConfigureById(equipment.CId); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return return
} }
//找到下一个等级的相关配置 //找到下一个等级的相关配置
if intensify, err = this.module.configure_comp.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil { if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil {
log.Errorf("Equip_Check err:%v", err) log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentLvlimitReached code.Code = pb.ErrorCode_EquipmentLvlimitReached
return return
@ -49,7 +49,7 @@ func (this *Api_Comp) Upgrade_Check(session comm.IUserSession, req *pb.Equipment
} }
///英雄挂在装备 ///英雄挂在装备
func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Upgrade_Req) (code pb.ErrorCode) { func (this *ApiComp) Upgrade(session comm.IUserSession, agrs map[string]interface{}, req *pb.Equipment_Upgrade_Req) (code pb.ErrorCode) {
var ( var (
err error err error
conf *cfg.Game_equipData conf *cfg.Game_equipData
@ -85,7 +85,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
//叠加装备 拆分处理 //叠加装备 拆分处理
if equipment.IsInitialState && equipment.OverlayNum > 1 { if equipment.IsInitialState && equipment.OverlayNum > 1 {
equipment.OverlayNum-- equipment.OverlayNum--
if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ if err = this.module.modelequipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{
"overlayNum": equipment.OverlayNum, "overlayNum": equipment.OverlayNum,
"heroId": "", "heroId": "",
}); err != nil { }); err != nil {
@ -97,24 +97,24 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
equipment.Id = primitive.NewObjectID().Hex() equipment.Id = primitive.NewObjectID().Hex()
equipment.IsInitialState = false equipment.IsInitialState = false
equipment.OverlayNum = 1 equipment.OverlayNum = 1
if err = this.module.model_equipment_comp.upgradeEquipment(equipment, conf, intensify); err != nil { if err = this.module.modelequipment.upgradeEquipment(equipment, conf, intensify); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
return return
} }
if err = this.module.model_equipment_comp.AddList(session.GetUserId(), equipment.Id, equipment); err != nil { if err = this.module.modelequipment.AddList(session.GetUserId(), equipment.Id, equipment); err != nil {
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
} else { } else {
equipment.IsInitialState = false equipment.IsInitialState = false
if err = this.module.model_equipment_comp.upgradeEquipment(equipment, conf, intensify); err != nil { if err = this.module.modelequipment.upgradeEquipment(equipment, conf, intensify); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
return return
} }
if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{ if err = this.module.modelequipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{
"lv": equipment.Lv, "lv": equipment.Lv,
"mainEntry": equipment.MainEntry, "mainEntry": equipment.MainEntry,
"adverbEntry": equipment.AdverbEntry, "adverbEntry": equipment.AdverbEntry,
@ -136,7 +136,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
for i, v := range hero.EquipID { for i, v := range hero.EquipID {
if v != "" { if v != "" {
if v != equipment.Id { if v != equipment.Id {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsById(session.GetUserId(), v); err != nil { if equipments[i], err = this.module.modelequipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Upgrade err:%v", err) log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_EquipmentOnFoundEquipment code = pb.ErrorCode_EquipmentOnFoundEquipment
return return

View File

@ -17,12 +17,12 @@ const (
) )
///背包配置管理组件 ///背包配置管理组件
type Configure_Comp struct { type ConfigureComp struct {
modules.MComp_Configure modules.MCompConfigure
} }
//组件初始化接口 //组件初始化接口
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ConfigureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.LoadConfigure(game_equip, cfg.NewGame_equip) this.LoadConfigure(game_equip, cfg.NewGame_equip)
this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary) this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary)
@ -30,7 +30,7 @@ func (this *Configure_Comp) Init(service core.IService, module core.IModule, com
} }
//获取装备配置数据 //获取装备配置数据
func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equip, err error) { func (this *ConfigureComp) GetEquipmentConfigure() (configure *cfg.Game_equip, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -49,7 +49,7 @@ func (this *Configure_Comp) GetEquipmentConfigure() (configure *cfg.Game_equip,
} }
//获取装备配置数据 //获取装备配置数据
func (this *Configure_Comp) GetEquipmentConfigureById(equipmentId int32) (configure *cfg.Game_equipData, err error) { func (this *ConfigureComp) GetEquipmentConfigureById(equipmentId int32) (configure *cfg.Game_equipData, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -68,7 +68,7 @@ func (this *Configure_Comp) GetEquipmentConfigureById(equipmentId int32) (config
} }
//获取装备属性表 //获取装备属性表
func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.Game_equipAttrlibrary, err error) { func (this *ConfigureComp) GetEquipmentAttrlibraryConfigure() (configure *cfg.Game_equipAttrlibrary, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -87,7 +87,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.G
} }
//获取属性词列表 //获取属性词列表
func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) { func (this *ConfigureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -106,7 +106,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureByKey(key int32) (co
} }
//获取属性词列表 //获取属性词列表
func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) { func (this *ConfigureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) {
var ( var (
v interface{} v interface{}
) )
@ -125,7 +125,7 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (conf
} }
//获取武器等级消耗表 //获取武器等级消耗表
func (this *Configure_Comp) GetEquipmentIntensifyConfigure() (configure *cfg.Game_equipIntensify, err error) { func (this *ConfigureComp) GetEquipmentIntensifyConfigure() (configure *cfg.Game_equipIntensify, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -144,7 +144,7 @@ func (this *Configure_Comp) GetEquipmentIntensifyConfigure() (configure *cfg.Gam
} }
//获取武器等级消耗表 //获取武器等级消耗表
func (this *Configure_Comp) GetEquipmentIntensifyConfigureById(Id int32) (configure *cfg.Game_equipIntensifyData, err error) { func (this *ConfigureComp) GetEquipmentIntensifyConfigureById(Id int32) (configure *cfg.Game_equipIntensifyData, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool

View File

@ -15,14 +15,14 @@ import (
) )
///装备 数据组件 ///装备 数据组件
type Model_Equipment_Comp struct { type ModelEquipmentComp struct {
modules.Model_Comp modules.MCompModel
module *Equipment module *Equipment
} }
//组件初始化接口 //组件初始化接口
func (this *Model_Equipment_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { func (this *ModelEquipmentComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Equipment) this.module = module.(*Equipment)
this.TableName = "equipment" this.TableName = "equipment"
//创建uid索引 //创建uid索引
@ -33,27 +33,27 @@ func (this *Model_Equipment_Comp) Init(service core.IService, module core.IModul
} }
//查询用户装备数据 //查询用户装备数据
func (this *Model_Equipment_Comp) Equipment_QueryUserEquipmentsById(uId, id string) (equipment *pb.DB_Equipment, err error) { func (this *ModelEquipmentComp) QueryUserEquipmentsById(uId, id string) (equipment *pb.DB_Equipment, err error) {
equipment = &pb.DB_Equipment{} equipment = &pb.DB_Equipment{}
err = this.GetListObj(uId, id, equipment) err = this.GetListObj(uId, id, equipment)
return return
} }
///查询用户的武器背包 ///查询用户的武器背包
func (this *Model_Equipment_Comp) Equipment_QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) { func (this *ModelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) {
equipments = make([]*pb.DB_Equipment, 0) equipments = make([]*pb.DB_Equipment, 0)
err = this.GetList(uId, &equipments) err = this.GetList(uId, &equipments)
return return
} }
///查询目标卡片数量 ///查询目标卡片数量
func (this *Model_Equipment_Comp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) { func (this *ModelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) {
var ( var (
equipments []*pb.DB_Equipment equipments []*pb.DB_Equipment
err error err error
) )
amount = 0 amount = 0
if equipments, err = this.Equipment_QueryUserEquipments(uid); err != nil { if equipments, err = this.QueryUserEquipments(uid); err != nil {
return return
} }
for _, v := range equipments { for _, v := range equipments {
@ -65,7 +65,7 @@ func (this *Model_Equipment_Comp) QueryEquipmentAmount(uid string, equipmentId i
} }
//添加装备 //添加装备
func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[int32]uint32) (err error) { func (this *ModelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (err error) {
var ( var (
configure *cfg.Game_equip configure *cfg.Game_equip
equipments []*pb.DB_Equipment equipments []*pb.DB_Equipment
@ -73,10 +73,10 @@ func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[i
add map[string]*pb.DB_Equipment add map[string]*pb.DB_Equipment
update map[string]*pb.DB_Equipment update map[string]*pb.DB_Equipment
) )
if configure, err = this.module.configure_comp.GetEquipmentConfigure(); err != nil { if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return return
} }
if equipments, err = this.Equipment_QueryUserEquipments(uId); err != nil { if equipments, err = this.QueryUserEquipments(uId); err != nil {
return return
} }
add = make(map[string]*pb.DB_Equipment) add = make(map[string]*pb.DB_Equipment)
@ -115,7 +115,7 @@ func (this *Model_Equipment_Comp) Equipment_AddEquipments(uId string, cIds map[i
} }
//更新武器挂载信息 //更新武器挂载信息
func (this *Model_Equipment_Comp) Equipment_UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) { func (this *ModelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) {
for _, v := range equipments { for _, v := range equipments {
if err = this.ChangeList(uid, v.Id, map[string]interface{}{ if err = this.ChangeList(uid, v.Id, map[string]interface{}{
"heroId": v.HeroId, "heroId": v.HeroId,
@ -128,7 +128,7 @@ func (this *Model_Equipment_Comp) Equipment_UpdateByHeroId(uid string, equipment
} }
//创建新的武器对象 //创建新的武器对象
func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) { func (this *ModelEquipmentComp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) {
var ( var (
mattr []*cfg.Game_equipAttrlibraryData mattr []*cfg.Game_equipAttrlibraryData
sattr []*cfg.Game_equipAttrlibraryData sattr []*cfg.Game_equipAttrlibraryData
@ -144,7 +144,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD
IsInitialState: true, IsInitialState: true,
AdverbEntry: make([]*pb.EquipmentAttributeEntry, 0), AdverbEntry: make([]*pb.EquipmentAttributeEntry, 0),
} }
if mattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 { if mattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 {
return return
} }
equipment.MainEntry = &pb.EquipmentAttributeEntry{ equipment.MainEntry = &pb.EquipmentAttributeEntry{
@ -154,7 +154,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD
AttrName: mattr[0].Attrkey, AttrName: mattr[0].Attrkey,
Value: mattr[0].Attrvar, Value: mattr[0].Attrvar,
} }
if sattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 { if sattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 {
return return
} }
@ -184,7 +184,7 @@ func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipD
} }
//升级武器 //升级武器
func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, equip *cfg.Game_equipData, intensify *cfg.Game_equipIntensifyData) (err error) { func (this *ModelEquipmentComp) upgradeEquipment(equipment *pb.DB_Equipment, equip *cfg.Game_equipData, intensify *cfg.Game_equipIntensifyData) (err error) {
equipment.Lv++ equipment.Lv++
equipment.MainEntry.Lv++ equipment.MainEntry.Lv++
equipment.MainEntry.Value += equipment.MainEntry.Value * (intensify.Bonus / 1000.0) equipment.MainEntry.Value += equipment.MainEntry.Value * (intensify.Bonus / 1000.0)
@ -194,7 +194,7 @@ func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, e
if len(equipment.AdverbEntry) < 4 { //去随机副词条 if len(equipment.AdverbEntry) < 4 { //去随机副词条
var temp []*cfg.Game_equipAttrlibraryData var temp []*cfg.Game_equipAttrlibraryData
var sattr []*cfg.Game_equipAttrlibraryData var sattr []*cfg.Game_equipAttrlibraryData
if temp, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 { if temp, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 {
log.Errorf("升级服务错误 读取副词条配置错误!") log.Errorf("升级服务错误 读取副词条配置错误!")
return return
} }
@ -224,7 +224,7 @@ func (this *Model_Equipment_Comp) upgradeEquipment(equipment *pb.DB_Equipment, e
r := rand.New(rand.NewSource(time.Now().Unix())) r := rand.New(rand.NewSource(time.Now().Unix()))
index := r.Perm(len(equipment.AdverbEntry))[0] index := r.Perm(len(equipment.AdverbEntry))[0]
if attrlibrary, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureByKey(equipment.AdverbEntry[index].Id); err != nil { if attrlibrary, err = this.module.configure.GetEquipmentAttrlibraryConfigureByKey(equipment.AdverbEntry[index].Id); err != nil {
return return
} }
equipment.AdverbEntry[index].Value += attrlibrary.Addition[equipment.AdverbEntry[index].Lv-1] / 1000.0 * attrlibrary.Attrvar equipment.AdverbEntry[index].Value += attrlibrary.Addition[equipment.AdverbEntry[index].Lv-1] / 1000.0 * attrlibrary.Attrvar

View File

@ -22,11 +22,11 @@ func NewModule() core.IModule {
type Equipment struct { type Equipment struct {
modules.ModuleBase modules.ModuleBase
service core.IService service core.IService
api_comp *Api_Comp api *ApiComp
configure_comp *Configure_Comp configure *ConfigureComp
model_equipment_comp *Model_Equipment_Comp modelequipment *ModelEquipmentComp
hero comm.IHero hero comm.IHero
} }
//模块名 //模块名
@ -56,16 +56,16 @@ func (this *Equipment) Start() (err error) {
//装备组件 //装备组件
func (this *Equipment) OnInstallComp() { func (this *Equipment) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(ApiComp)).(*ApiComp)
this.model_equipment_comp = this.RegisterComp(new(Model_Equipment_Comp)).(*Model_Equipment_Comp) this.modelequipment = this.RegisterComp(new(ModelEquipmentComp)).(*ModelEquipmentComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }
//IEquipment------------------------------------------------------------------------------------------------------------------------------- //IEquipment-------------------------------------------------------------------------------------------------------------------------------
//查询武器信息 //查询武器信息
func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) { func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) {
var err error var err error
if equipment, err = this.model_equipment_comp.Equipment_QueryUserEquipmentsById(uid, Id); err != nil { if equipment, err = this.modelequipment.QueryUserEquipmentsById(uid, Id); err != nil {
if err == redis.Nil { if err == redis.Nil {
code = pb.ErrorCode_EquipmentOnFoundEquipment code = pb.ErrorCode_EquipmentOnFoundEquipment
} else { } else {
@ -77,14 +77,14 @@ func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string,
//查询卡片数量 //查询卡片数量
func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId int32) (amount uint32) { func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId int32) (amount uint32) {
amount = this.model_equipment_comp.QueryEquipmentAmount(uid, equipmentId) amount = this.modelequipment.QueryEquipmentAmount(uid, equipmentId)
return return
} }
//添加武器 //添加武器
func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) { func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) {
var err error var err error
if err = this.model_equipment_comp.Equipment_AddEquipments(uid, cIds); err != nil { if err = this.modelequipment.AddEquipments(uid, cIds); err != nil {
log.Errorf("err%v", err) log.Errorf("err%v", err)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
} }

View File

@ -1,4 +1,4 @@
package equipment package equipment_test
import ( import (
"fmt" "fmt"
@ -7,6 +7,7 @@ import (
"go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/equipment"
"go_dreamfactory/modules/hero" "go_dreamfactory/modules/hero"
"go_dreamfactory/services" "go_dreamfactory/services"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
@ -50,7 +51,7 @@ func (this *TestService) InitSys() {
var service core.IService var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Equipment) var module = new(equipment.Equipment)
//测试环境下初始化db和cache 系统 //测试环境下初始化db和cache 系统
func TestMain(m *testing.M) { func TestMain(m *testing.M) {

View File

@ -18,8 +18,8 @@ func NewModule() core.IModule {
type Game struct { type Game struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *ApiComp
configure_comp *Configure_Comp configure *ConfigureComp
} }
//模块名 //模块名
@ -36,6 +36,6 @@ func (this *Game) Init(service core.IService, module core.IModule, options core.
//装备组件 //装备组件
func (this *Game) OnInstallComp() { func (this *Game) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(ApiComp)).(*ApiComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }

View File

@ -16,13 +16,13 @@ import (
/* /*
用户代理对象管理组件 用户代理对象管理组件
*/ */
type AgentMgr_Comp struct { type AgentMgrComp struct {
cbase.ModuleCompBase cbase.ModuleCompBase
service base.IRPCXService service base.IRPCXService
agents *sync.Map agents *sync.Map
} }
func (this *AgentMgr_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *AgentMgrComp) 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.ModuleCompBase.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.agents = new(sync.Map) this.agents = new(sync.Map)
@ -30,12 +30,12 @@ func (this *AgentMgr_Comp) Init(service core.IService, module core.IModule, comp
} }
//加入新的用户 //加入新的用户
func (this *AgentMgr_Comp) Connect(a IAgent) { func (this *AgentMgrComp) Connect(a IAgent) {
this.agents.Store(a.SessionId(), a) this.agents.Store(a.SessionId(), a)
} }
//移除断开的用户 //移除断开的用户
func (this *AgentMgr_Comp) DisConnect(a IAgent) { func (this *AgentMgrComp) DisConnect(a IAgent) {
this.agents.Delete(a.SessionId()) this.agents.Delete(a.SessionId())
if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关 if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关
reply := &pb.RPCMessageReply{} reply := &pb.RPCMessageReply{}
@ -48,7 +48,7 @@ func (this *AgentMgr_Comp) DisConnect(a IAgent) {
} }
//用户登录绑定Id //用户登录绑定Id
func (this *AgentMgr_Comp) Bind(ctx context.Context, args *pb.AgentBuildReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) Bind(ctx context.Context, args *pb.AgentBuildReq, reply *pb.RPCMessageReply) error {
if a, ok := this.agents.Load(args.UserSessionId); ok { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).Bind(args.UserId, args.WorkerId) a.(IAgent).Bind(args.UserId, args.WorkerId)
} else { } else {
@ -59,7 +59,7 @@ func (this *AgentMgr_Comp) Bind(ctx context.Context, args *pb.AgentBuildReq, rep
} }
//用户登录解绑Id //用户登录解绑Id
func (this *AgentMgr_Comp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq, reply *pb.RPCMessageReply) error {
if a, ok := this.agents.Load(args.UserSessionId); ok { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).UnBind() a.(IAgent).UnBind()
} else { } else {
@ -70,7 +70,7 @@ func (this *AgentMgr_Comp) UnBind(ctx context.Context, args *pb.AgentUnBuildReq,
} }
//向用户发送消息 //向用户发送消息
func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSendMessageReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) SendMsgToAgent(ctx context.Context, args *pb.AgentSendMessageReq, reply *pb.RPCMessageReply) error {
if a, ok := this.agents.Load(args.UserSessionId); ok { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).WriteMsg(&pb.UserMessage{ a.(IAgent).WriteMsg(&pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
@ -85,7 +85,7 @@ func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSen
} }
//向多个户发送消息 //向多个户发送消息
func (this *AgentMgr_Comp) SendMsgToAgents(ctx context.Context, args *pb.BatchMessageReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) SendMsgToAgents(ctx context.Context, args *pb.BatchMessageReq, reply *pb.RPCMessageReply) error {
msg := &pb.UserMessage{ msg := &pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
SubType: args.SubType, SubType: args.SubType,
@ -100,7 +100,7 @@ func (this *AgentMgr_Comp) SendMsgToAgents(ctx context.Context, args *pb.BatchMe
} }
//向所有户发送消息 //向所有户发送消息
func (this *AgentMgr_Comp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadCastMessageReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadCastMessageReq, reply *pb.RPCMessageReply) error {
msg := &pb.UserMessage{ msg := &pb.UserMessage{
MainType: args.MainType, MainType: args.MainType,
SubType: args.SubType, SubType: args.SubType,
@ -114,7 +114,7 @@ func (this *AgentMgr_Comp) SendMsgToAllAgent(ctx context.Context, args *pb.Broad
} }
//关闭代理 //关闭代理
func (this *AgentMgr_Comp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error { func (this *AgentMgrComp) CloseAgent(ctx context.Context, args *pb.AgentCloseeReq, reply *pb.RPCMessageReply) error {
if a, ok := this.agents.Load(args.UserSessionId); ok { if a, ok := this.agents.Load(args.UserSessionId); ok {
a.(IAgent).Close() a.(IAgent).Close()
} else { } else {

View File

@ -21,10 +21,10 @@ func NewModule() core.IModule {
type Gateway struct { type Gateway struct {
modules.ModuleBase modules.ModuleBase
service base.IRPCXService service base.IRPCXService
wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听 wsservice *WSServiceComp //websocket 服务组件 提供websocket服务监听
agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象 agentmgr *AgentMgrComp //用户代理对象管理组件 管理用户socekt对象
configure_comp *Configure_Comp configure *ConfigureComp
} }
//模块名 //模块名
@ -52,17 +52,17 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
//模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务 //模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) { func (this *Gateway) Start() (err error) {
//注册用户绑定uid接口 登录成功后触发 //注册用户绑定uid接口 登录成功后触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr_comp.Bind) this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr.Bind)
//注册用户解绑uid接口 登出或则切换账号是触发 //注册用户解绑uid接口 登出或则切换账号是触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentmgr_comp.UnBind) this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBind), this.agentmgr.UnBind)
//向用户发送消息接口 //向用户发送消息接口
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr_comp.SendMsgToAgent) this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr.SendMsgToAgent)
//向多个用户对象发送消息接口 //向多个用户对象发送消息接口
this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendBatchMsg), this.agentmgr_comp.SendMsgToAgents) this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendBatchMsg), this.agentmgr.SendMsgToAgents)
//向所有用户发送消息接口 //向所有用户发送消息接口
this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendRadioMsg), this.agentmgr_comp.SendMsgToAllAgent) this.service.RegisterFunctionName(string(comm.Rpc_GatewaySendRadioMsg), this.agentmgr.SendMsgToAllAgent)
//关闭用户socket连接接口 //关闭用户socket连接接口
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr_comp.CloseAgent) this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr.CloseAgent)
err = this.ModuleBase.Start() err = this.ModuleBase.Start()
return return
} }
@ -70,24 +70,24 @@ func (this *Gateway) Start() (err error) {
//装备组件 //装备组件
func (this *Gateway) OnInstallComp() { func (this *Gateway) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp) this.agentmgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp) this.wsservice = this.RegisterComp(new(WSServiceComp)).(*WSServiceComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }
//有新的连接对象进入 //有新的连接对象进入
func (this *Gateway) Connect(a IAgent) { func (this *Gateway) Connect(a IAgent) {
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId()) log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId())
this.agentmgr_comp.Connect(a) this.agentmgr.Connect(a)
} }
//有用户断开连接 //有用户断开连接
func (this *Gateway) DisConnect(a IAgent) { func (this *Gateway) DisConnect(a IAgent) {
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId()) log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%s]", a.IP(), a.SessionId(), a.UserId())
this.agentmgr_comp.DisConnect(a) this.agentmgr.DisConnect(a)
} }
//读取消息分发规则 //读取消息分发规则
func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) { func (this *Gateway) GetMsgDistribRule(mtype, stype string) (rule string, ok bool) {
return this.configure_comp.GetMsgDistribRule(mtype, stype) return this.configure.GetMsgDistribRule(mtype, stype)
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
type WSService_Comp struct { type WSServiceComp struct {
cbase.ModuleCompBase cbase.ModuleCompBase
options *Options options *Options
@ -20,7 +20,7 @@ type WSService_Comp struct {
gin gin.ISys gin gin.ISys
} }
func (this *WSService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *WSServiceComp) 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.ModuleCompBase.Init(service, module, comp, options)
this.options = options.(*Options) this.options = options.(*Options)
this.module = module.(IGateway) this.module = module.(IGateway)
@ -29,7 +29,7 @@ func (this *WSService_Comp) Init(service core.IService, module core.IModule, com
return return
} }
func (this *WSService_Comp) ws(c *engine.Context) { func (this *WSServiceComp) ws(c *engine.Context) {
upGrader := websocket.Upgrader{ upGrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(r *http.Request) bool {
return true return true

View File

@ -15,21 +15,21 @@ const ( //消息回复的头名称
/* /*
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp 背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
*/ */
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MCompGate
service core.IService service core.IService
module *Items module *Items
} }
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Items) this.module = module.(*Items)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MCompGate.Start()
return return
} }

View File

@ -8,13 +8,13 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Getlist_Check(session comm.IUserSession, req *pb.Items_Getlist_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Getlist_Check(session comm.IUserSession, req *pb.Items_Getlist_Req) (result map[string]interface{}, code comm.ErrorCode) {
result = map[string]interface{}{"ce": 123} result = map[string]interface{}{"ce": 123}
return return
} }
///获取用户道具 ///获取用户道具
func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_Getlist_Req) (code pb.ErrorCode) { func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_Getlist_Req) (code pb.ErrorCode) {
var ( var (
err error err error
items []*pb.DB_UserItemData items []*pb.DB_UserItemData
@ -28,18 +28,18 @@ func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interfa
session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.Items_Getlist_Resp{Grids: grids}) session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.Items_Getlist_Resp{Grids: grids})
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据 go func() { //异步处理修改数据
this.module.model_pack_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...) this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
this.module.model_pack_comp.Pack_DeleteUserPack(session.GetUserId(), dels...) this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...)
}() }()
} }
}() }()
if items, err = this.module.model_pack_comp.Pack_QueryUserPack(session.GetUserId()); err != nil { if items, err = this.module.modelItems.Pack_QueryUserPack(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err) log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return
} else { } else {
tempgrids = this.module.configure_comp.GetPackItemByType(items, req.IType) tempgrids = this.module.configure.GetPackItemByType(items, req.IType)
modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids)) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids))
dels = make([]string, 0, len(tempgrids)) dels = make([]string, 0, len(tempgrids))
grids = make([]*pb.DB_UserItemData, 0, len(grids)) grids = make([]*pb.DB_UserItemData, 0, len(grids))

View File

@ -6,13 +6,13 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) SellItem_Check(session comm.IUserSession, req *pb.Items_SellItem_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) SellItem_Check(session comm.IUserSession, req *pb.Items_SellItem_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
//出售道具 //出售道具
func (this *Api_Comp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_SellItem_Req) (code pb.ErrorCode) { func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_SellItem_Req) (code pb.ErrorCode) {
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.Items_SellItem_Resp{}) session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.Items_SellItem_Resp{})
}() }()

View File

@ -6,13 +6,13 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Useitem_Check(session comm.IUserSession, req *pb.Items_UseItem_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Useitem_Check(session comm.IUserSession, req *pb.Items_UseItem_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
//使用道具 //使用道具
func (this *Api_Comp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_UseItem_Req) (code pb.ErrorCode) { func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_UseItem_Req) (code pb.ErrorCode) {
defer func() { defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{}) session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{})
}() }()

View File

@ -15,19 +15,19 @@ const (
) )
///背包配置管理组件 ///背包配置管理组件
type Configure_Comp struct { type ConfigureComp struct {
modules.MComp_Configure modules.MCompConfigure
} }
//组件初始化接口 //组件初始化接口
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ConfigureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.ModuleCompBase.Init(service, module, comp, options) this.ModuleCompBase.Init(service, module, comp, options)
this.LoadConfigure(game_item, cfg.NewGame_item) this.LoadConfigure(game_item, cfg.NewGame_item)
return return
} }
//读取物品配置 //读取物品配置
func (this *Configure_Comp) GetItemConfigure(id int32) (item *cfg.Game_itemData, err error) { func (this *ConfigureComp) GetItemConfigure(id int32) (item *cfg.Game_itemData, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -44,7 +44,7 @@ func (this *Configure_Comp) GetItemConfigure(id int32) (item *cfg.Game_itemData,
} }
//获取指定类型的物品列表 //获取指定类型的物品列表
func (this *Configure_Comp) GetPackItemByType(itmes []*pb.DB_UserItemData, usetype int32) (result []*pb.DB_UserItemData) { func (this *ConfigureComp) GetPackItemByType(itmes []*pb.DB_UserItemData, usetype int32) (result []*pb.DB_UserItemData) {
result = make([]*pb.DB_UserItemData, 0, len(itmes)) result = make([]*pb.DB_UserItemData, 0, len(itmes))
var ( var (
v interface{} v interface{}

View File

@ -12,14 +12,14 @@ import (
) )
///背包缓存数据管理组件 ///背包缓存数据管理组件
type Model_Pack_Comp struct { type ModelItemsComp struct {
modules.Model_Comp modules.MCompModel
module *Items module *Items
} }
//组件初始化接口 //组件初始化接口
func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { func (this *ModelItemsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Items) this.module = module.(*Items)
this.TableName = "items" this.TableName = "items"
//创建uid索引 //创建uid索引
@ -30,21 +30,21 @@ func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, co
} }
///查询用户背包数据 ///查询用户背包数据
func (this *Model_Pack_Comp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { func (this *ModelItemsComp) Pack_QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) {
itmes = make([]*pb.DB_UserItemData, 0) itmes = make([]*pb.DB_UserItemData, 0)
err = this.GetList(uId, &itmes) err = this.GetList(uId, &itmes)
return return
} }
///查询用户指定格子的物品数据 ///查询用户指定格子的物品数据
func (this *Model_Pack_Comp) Pack_QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) { func (this *ModelItemsComp) Pack_QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) {
itme = &pb.DB_UserItemData{} itme = &pb.DB_UserItemData{}
err = this.GetListObj(uId, grid, itme) err = this.GetListObj(uId, grid, itme)
return return
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *Model_Pack_Comp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { func (this *ModelItemsComp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) {
for _, v := range itmes { for _, v := range itmes {
this.AddList(uId, v.GridId, v) this.AddList(uId, v.GridId, v)
} }
@ -52,13 +52,13 @@ func (this *Model_Pack_Comp) Pack_AddUserPack(uId string, itmes ...*pb.DB_UserIt
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *Model_Pack_Comp) Pack_DelUserPack(uId string, ids ...string) (err error) { func (this *ModelItemsComp) Pack_DelUserPack(uId string, ids ...string) (err error) {
err = this.DelListlds(uId, ids...) err = this.DelListlds(uId, ids...)
return return
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *Model_Pack_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { func (this *ModelItemsComp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) {
for _, v := range itmes { for _, v := range itmes {
this.ChangeList(uId, v.GridId, map[string]interface{}{ this.ChangeList(uId, v.GridId, map[string]interface{}{
"amount": v.Amount, "amount": v.Amount,
@ -68,13 +68,13 @@ func (this *Model_Pack_Comp) Pack_UpdateUserPack(uId string, itmes ...*pb.DB_Use
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *Model_Pack_Comp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) { func (this *ModelItemsComp) Pack_DeleteUserPack(uId string, gridIds ...string) (err error) {
err = this.DelListlds(uId, gridIds...) err = this.DelListlds(uId, gridIds...)
return return
} }
//查询用户背包物品数量 //查询用户背包物品数量
func (this *Model_Pack_Comp) Pack_QueryUserPackItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) { func (this *ModelItemsComp) Pack_QueryUserPackItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) {
var ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
err error err error
@ -94,7 +94,7 @@ func (this *Model_Pack_Comp) Pack_QueryUserPackItemsAmount(uId string, itemid ..
} }
///添加或则减少物品到用户背包 ///添加或则减少物品到用户背包
func (this *Model_Pack_Comp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) { func (this *ModelItemsComp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) {
var ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
add []*pb.DB_UserItemData add []*pb.DB_UserItemData
@ -136,7 +136,7 @@ func (this *Model_Pack_Comp) Pack_AddItemToUserPack(uId string, itemId int32, ad
} }
///添加或则减少多个物品到用户背包 ///添加或则减少多个物品到用户背包
func (this *Model_Pack_Comp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) { func (this *ModelItemsComp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
var ( var (
itmes []*pb.DB_UserItemData itmes []*pb.DB_UserItemData
add []*pb.DB_UserItemData add []*pb.DB_UserItemData
@ -176,7 +176,7 @@ func (this *Model_Pack_Comp) Pack_AddItemsToUserPack(uId string, items map[int32
} }
///修改指定格子的物品数量 ///修改指定格子的物品数量
func (this *Model_Pack_Comp) Pack_AddItemToUserPackByGrid(uId string, gridid string, itemId int32, addnum int32) (err error) { func (this *ModelItemsComp) Pack_AddItemToUserPackByGrid(uId string, gridid string, itemId int32, addnum int32) (err error) {
var ( var (
itme *pb.DB_UserItemData itme *pb.DB_UserItemData
grid *pb.DB_UserItemData grid *pb.DB_UserItemData
@ -211,7 +211,7 @@ func (this *Model_Pack_Comp) Pack_AddItemToUserPackByGrid(uId string, gridid str
} }
///添加移除物品到用户背包 ///添加移除物品到用户背包
func (this *Model_Pack_Comp) pack_addItemToUserPack(items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update []*pb.DB_UserItemData, del []string, leftnum int64) { func (this *ModelItemsComp) pack_addItemToUserPack(items []*pb.DB_UserItemData, itemId int32, addnum int32) (add, update []*pb.DB_UserItemData, del []string, leftnum int64) {
var ( var (
num int64 num int64
isNew bool isNew bool

View File

@ -21,10 +21,9 @@ func NewModule() core.IModule {
type Items struct { type Items struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *apiComp
model_pack_comp *Model_Pack_Comp modelItems *ModelItemsComp
// db_comp *DB_Comp configure *ConfigureComp
configure_comp *Configure_Comp
} }
//模块名称 //模块名称
@ -41,9 +40,9 @@ func (this *Items) Init(service core.IService, module core.IModule, options core
//装备组件 //装备组件
func (this *Items) OnInstallComp() { func (this *Items) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_pack_comp = this.RegisterComp(new(Model_Pack_Comp)).(*Model_Pack_Comp) this.modelItems = this.RegisterComp(new(ModelItemsComp)).(*ModelItemsComp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
} }
//IItems------------------------------------------------------------------------------------------------------------------------------- //IItems-------------------------------------------------------------------------------------------------------------------------------
@ -51,7 +50,7 @@ func (this *Items) OnInstallComp() {
func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, itemid int32) (amount uint32) { func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, itemid int32) (amount uint32) {
defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount) defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount)
amount = 0 amount = 0
if result := this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid); result != nil && len(result) > 0 { if result := this.modelItems.Pack_QueryUserPackItemsAmount(uId, itemid); result != nil && len(result) > 0 {
return result[itemid] return result[itemid]
} }
return return
@ -59,7 +58,7 @@ func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, it
///查询用户背包多个物品数量 ///查询用户背包多个物品数量
func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) { func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) {
result = this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid...) result = this.modelItems.Pack_QueryUserPackItemsAmount(uId, itemid...)
return return
} }
@ -67,7 +66,7 @@ func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, i
func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) { func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) {
var err error var err error
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil) 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 { if err = this.modelItems.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err) log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
if err == ItemNotEnoughError { if err == ItemNotEnoughError {
code = pb.ErrorCode_ItemsNoEnough code = pb.ErrorCode_ItemsNoEnough
@ -84,7 +83,7 @@ func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, ad
func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) { func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) {
var err error var err error
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil) defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil)
if err = this.model_pack_comp.Pack_AddItemsToUserPack(uId, items); err != nil { if err = this.modelItems.Pack_AddItemsToUserPack(uId, items); err != nil {
log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err) log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
if err == ItemNotEnoughError { if err == ItemNotEnoughError {
code = pb.ErrorCode_ItemsNoEnough code = pb.ErrorCode_ItemsNoEnough

View File

@ -1,4 +1,4 @@
package items package items_test
import ( import (
"context" "context"
@ -8,6 +8,7 @@ import (
"go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/items"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/services" "go_dreamfactory/services"
"go_dreamfactory/sys/cache" "go_dreamfactory/sys/cache"
@ -53,7 +54,7 @@ func (this *TestService) InitSys() {
var service core.IService var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Items) var module = new(items.Items)
//测试环境下初始化db和cache 系统 //测试环境下初始化db和cache 系统
func TestMain(m *testing.M) { func TestMain(m *testing.M) {

View File

@ -25,8 +25,9 @@ message AgentMessage {
// RPC // RPC
message RPCMessageReply { message RPCMessageReply {
ErrorCode Code = 1; ErrorCode Code = 1;
string Message = 2; string ErrorMessage = 2;
string Data = 3; string ErrorData = 3;
UserMessage Reply = 4;
} }
//Uid请求 //Uid请求

View File

@ -27,7 +27,7 @@ import (
*/ */
func NewGateRouteComp() comm.ISC_GateRouteComp { func NewGateRouteComp() comm.ISC_GateRouteComp {
comp := new(SComp_GateRouteComp) comp := new(SCompGateRoute)
return comp return comp
} }
@ -39,7 +39,7 @@ type msghandle struct {
} }
//服务网关组件 //服务网关组件
type SComp_GateRouteComp struct { type SCompGateRoute struct {
cbase.ServiceCompBase cbase.ServiceCompBase
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
mrlock sync.RWMutex //msghandles 对象的锁 mrlock sync.RWMutex //msghandles 对象的锁
@ -48,12 +48,12 @@ type SComp_GateRouteComp struct {
} }
//设置服务组件名称 方便业务模块中获取此组件对象 //设置服务组件名称 方便业务模块中获取此组件对象
func (this *SComp_GateRouteComp) GetName() core.S_Comps { func (this *SCompGateRoute) GetName() core.S_Comps {
return comm.SC_ServiceGateRouteComp return comm.SC_ServiceGateRouteComp
} }
//组件初始化函数 //组件初始化函数
func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) { func (this *SCompGateRoute) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) {
err = this.ServiceCompBase.Init(service, comp, options) err = this.ServiceCompBase.Init(service, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.msgcheck = make(map[string]*msghandle) this.msgcheck = make(map[string]*msghandle)
@ -62,7 +62,7 @@ func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceC
} // } //
//组件启动时注册rpc服务监听 //组件启动时注册rpc服务监听
func (this *SComp_GateRouteComp) Start() (err error) { func (this *SCompGateRoute) Start() (err error) {
this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口 this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知 this.service.RegisterFunctionName(string(comm.Rpc_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知
err = this.ServiceCompBase.Start() err = this.ServiceCompBase.Start()
@ -84,7 +84,7 @@ func (this *SComp_GateRouteComp) Start() (err error) {
} }
//业务模块注册用户消息处理路由 //业务模块注册用户消息处理路由
func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) {
log.Debugf("注册用户路由【%s】", methodName) log.Debugf("注册用户路由【%s】", methodName)
this.mrlock.RLock() this.mrlock.RLock()
_, ok := this.msghandles[methodName] _, ok := this.msghandles[methodName]
@ -103,7 +103,7 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V
} }
//业务模块注册用户消息处理路由 //业务模块注册用户消息处理路由
func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) { func (this *SCompGateRoute) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) {
log.Debugf("注册用户路由校验[%s]", methodName) log.Debugf("注册用户路由校验[%s]", methodName)
this.mrlock.RLock() this.mrlock.RLock()
_, ok := this.msgcheck[methodName] _, ok := this.msgcheck[methodName]
@ -122,7 +122,7 @@ func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp refl
} }
//Rpc_GatewayRoute服务接口的接收函数 //Rpc_GatewayRoute服务接口的接收函数
func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error { func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error {
defer func() { //程序异常 收集异常信息传递给前端显示 defer func() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil { if r := recover(); r != nil {
buf := make([]byte, 1024) buf := make([]byte, 1024)
@ -132,7 +132,7 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
log.Errorf("HandleUserMsg:%s err:%s", args.Method, reply.Message) log.Errorf("HandleUserMsg:%s err:%s", args.Method, reply.Message)
} }
}() }()
log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method) log.Debugf("SCompGateRoute ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method)
//获取用户消息处理函数 //获取用户消息处理函数
this.mrlock.RLock() this.mrlock.RLock()
msghandle, ok := this.msghandles[args.Method] msghandle, ok := this.msghandles[args.Method]
@ -184,7 +184,7 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
} }
//RPC_NoticeUserClose 接收用户离线通知 //RPC_NoticeUserClose 接收用户离线通知
func (this *SComp_GateRouteComp) NoticeUserClose(ctx context.Context, args *pb.NoticeUserCloseReq, reply *pb.RPCMessageReply) error { func (this *SCompGateRoute) NoticeUserClose(ctx context.Context, args *pb.NoticeUserCloseReq, reply *pb.RPCMessageReply) error {
event.TriggerEvent(comm.Event_UserOffline, args.UserId) event.TriggerEvent(comm.Event_UserOffline, args.UserId)
return nil return nil
} }