This commit is contained in:
meixiongfeng 2022-06-28 17:13:42 +08:00
commit 95f071b3bc
50 changed files with 1400 additions and 1715 deletions

File diff suppressed because it is too large Load Diff

View File

@ -495,7 +495,7 @@
"level": 15,
"need": [],
"bonus": 4500,
"activation": false,
"activation": true,
"probability": 250,
"num": 16
},
@ -559,7 +559,7 @@
}
],
"bonus": 900,
"activation": false,
"activation": true,
"probability": 850,
"num": 4
},
@ -607,7 +607,7 @@
}
],
"bonus": 1800,
"activation": false,
"activation": true,
"probability": 700,
"num": 7
},
@ -655,7 +655,7 @@
}
],
"bonus": 2700,
"activation": false,
"activation": true,
"probability": 550,
"num": 10
},
@ -703,7 +703,7 @@
}
],
"bonus": 3600,
"activation": false,
"activation": true,
"probability": 400,
"num": 13
},
@ -745,7 +745,7 @@
"level": 15,
"need": [],
"bonus": 4500,
"activation": false,
"activation": true,
"probability": 250,
"num": 16
},
@ -809,7 +809,7 @@
}
],
"bonus": 900,
"activation": false,
"activation": true,
"probability": 850,
"num": 4
},
@ -857,7 +857,7 @@
}
],
"bonus": 1800,
"activation": false,
"activation": true,
"probability": 700,
"num": 7
},
@ -905,7 +905,7 @@
}
],
"bonus": 2700,
"activation": false,
"activation": true,
"probability": 550,
"num": 10
},
@ -953,7 +953,7 @@
}
],
"bonus": 3600,
"activation": false,
"activation": true,
"probability": 400,
"num": 13
},
@ -995,7 +995,7 @@
"level": 15,
"need": [],
"bonus": 4500,
"activation": false,
"activation": true,
"probability": 250,
"num": 16
},
@ -1059,7 +1059,7 @@
}
],
"bonus": 900,
"activation": false,
"activation": true,
"probability": 850,
"num": 4
},
@ -1107,7 +1107,7 @@
}
],
"bonus": 1800,
"activation": false,
"activation": true,
"probability": 700,
"num": 7
},
@ -1155,7 +1155,7 @@
}
],
"bonus": 2700,
"activation": false,
"activation": true,
"probability": 550,
"num": 10
},
@ -1203,7 +1203,7 @@
}
],
"bonus": 3600,
"activation": false,
"activation": true,
"probability": 400,
"num": 13
},
@ -1245,7 +1245,7 @@
"level": 15,
"need": [],
"bonus": 4500,
"activation": false,
"activation": true,
"probability": 250,
"num": 16
},
@ -1309,7 +1309,7 @@
}
],
"bonus": 900,
"activation": false,
"activation": true,
"probability": 850,
"num": 4
},
@ -1357,7 +1357,7 @@
}
],
"bonus": 1800,
"activation": false,
"activation": true,
"probability": 700,
"num": 7
},
@ -1405,7 +1405,7 @@
}
],
"bonus": 2700,
"activation": false,
"activation": true,
"probability": 550,
"num": 10
},
@ -1453,7 +1453,7 @@
}
],
"bonus": 3600,
"activation": false,
"activation": true,
"probability": 400,
"num": 13
},
@ -1495,7 +1495,7 @@
"level": 15,
"need": [],
"bonus": 4500,
"activation": false,
"activation": true,
"probability": 250,
"num": 16
}

View File

@ -16,8 +16,7 @@ import (
type ISC_GateRouteComp interface {
core.IServiceComp
ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, check, handle reflect.Method)
}
//游戏类资源类型
@ -35,8 +34,6 @@ type Autogenerated struct {
D []interface{}
}
const (
HeroStarLvRatio int32 = 10 // 卡牌等级上限系数(星级*10
)
@ -57,6 +54,7 @@ type IUserSession interface {
Bind(uid string, wokerId string) (err error)
UnBind() (err error)
SendMsg(mainType, subType string, msg proto.Message) (err error)
Polls() []*pb.UserMessage
Close() (err error)
ToString() string
}

View File

@ -59,10 +59,10 @@ type (
//武器模块
IEquipment interface {
//查询服务资源数量 db id
QueryEquipment(source *ModuleCallSource, uid string, Id int32) (equipment pb.DB_Equipment, code pb.ErrorCode)
QueryEquipment(source *ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode)
//查询服务资源数量 参数武器配置id
QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32)
//武器
AddNewEquipments(source *ModuleCallSource, uid string, eid int, add int32) (code pb.ErrorCode)
//添加新武器
AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode)
}
)

View File

@ -22,6 +22,7 @@ func NewUserSession(service base.IRPCXService, ip, sessionId, gatewayServiceId s
SessionId: sessionId,
GatewayServiceId: gatewayServiceId,
UserId: uid,
msgqueue: make([]*pb.UserMessage, 0),
service: service,
}
}
@ -32,6 +33,7 @@ type UserSession struct {
GatewayServiceId string //用户所在网关服务
UserId string
service base.IRPCXService
msgqueue []*pb.UserMessage
}
//获取用户的会话id
@ -87,17 +89,24 @@ func (this *UserSession) UnBind() (err error) {
//向用户发送消息
func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) {
reply := &pb.RPCMessageReply{}
data, _ := anypb.New(msg)
log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
UserSessionId: this.SessionId,
MainType: mainType,
SubType: subType,
Data: data,
}, reply); err != nil {
log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
}
data, _ := anypb.New(msg)
this.msgqueue = append(this.msgqueue, &pb.UserMessage{
MainType: mainType,
SubType: subType,
Data: data,
})
// reply := &pb.RPCMessageReply{}
// data, _ := anypb.New(msg)
// log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
// if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
// UserSessionId: this.SessionId,
// MainType: mainType,
// SubType: subType,
// Data: data,
// }, reply); err != nil {
// log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
// }
return
}
@ -112,6 +121,13 @@ func (this *UserSession) Close() (err error) {
return
}
//清空消息队列
func (this *UserSession) Polls() []*pb.UserMessage {
msgs := this.msgqueue
this.msgqueue = this.msgqueue[:0]
return msgs
}
//打印日志需要
func (this *UserSession) ToString() string {
return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId)

View File

@ -4,6 +4,7 @@ import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"log"
"reflect"
"strings"
"unicode"
@ -28,7 +29,7 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
/*
模块 网关组件 接收处理用户传递消息
*/
type MComp_GateComp struct {
type MCompGate struct {
cbase.ModuleCompBase
service base.IRPCXService //rpc服务对象
module core.IModule //当前业务模块
@ -37,7 +38,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.service = service.(base.IRPCXService)
this.module = module
@ -46,7 +47,7 @@ func (this *MComp_GateComp) Init(service core.IService, module core.IModule, com
}
//组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中
func (this *MComp_GateComp) Start() (err error) {
func (this *MCompGate) Start() (err error) {
if err = this.ModuleCompBase.Start(); err != nil {
return
}
@ -56,21 +57,21 @@ func (this *MComp_GateComp) Start() (err error) {
return
}
this.scomp = comp.(comm.ISC_GateRouteComp)
this.suitableMethods(reflect.TypeOf(this.comp))
this.suitableMethods()
return
}
//反射注册相关接口道services/comp_gateroute.go 对象中
func (this *MComp_GateComp) suitableMethods(typ reflect.Type) {
func (this *MCompGate) suitableMethods() {
typ := reflect.TypeOf(this.comp)
for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m)
this.reflectionRouteHandle(method)
this.reflectionRouteCheck(method)
this.reflectionRouteHandle(typ, method)
}
}
//反射注册路由处理函数
func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
func (this *MCompGate) reflectionRouteHandle(typ reflect.Type, method reflect.Method) {
mtype := method.Type
mname := method.Name
if method.PkgPath != "" {
@ -87,13 +88,14 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
if !argType.Implements(typeOfMapStringIntface) {
return
}
replyType := mtype.In(3)
if replyType.Kind() != reflect.Ptr {
agrType := mtype.In(3)
if agrType.Kind() != reflect.Ptr {
return
}
if !this.isExportedOrBuiltinType(replyType) {
if !this.isExportedOrBuiltinType(agrType) {
return
}
if mtype.NumOut() != 1 {
return
}
@ -101,55 +103,61 @@ func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) {
if returnCodeType != typeOfErrorCode {
return
}
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
//寻找校验函数
check, ok := typ.MethodByName(mname + "Check")
if !ok {
log.Panicf("反射注册用户处理函数错误 [%s-%s]没有对应的校验函数", this.module.GetType(), mname)
return
}
if err := this.reflectionRouteCheck(check, agrType); err == nil {
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), agrType, check, method)
} else {
log.Panicf("反射注册用户处理函数错误 [%s-%s]校验函数格式异常:%v", this.module.GetType(), mname, err)
return
}
}
//反射注册路由校验函数
func (this *MComp_GateComp) reflectionRouteCheck(method reflect.Method) {
func (this *MCompGate) reflectionRouteCheck(method reflect.Method, msgtype reflect.Type) error {
mtype := method.Type
mname := strings.Split(method.Name, "_")
if len(mname) != 2 || mname[1] != "Check" {
return
}
if method.PkgPath != "" {
return
return fmt.Errorf("method.PkgPath:%v", method.PkgPath)
}
if mtype.NumIn() != 3 {
return
return fmt.Errorf("mtype.NumIn():%v", mtype.NumIn())
}
ctxType := mtype.In(1)
if !ctxType.Implements(typeOfSession) {
return
return fmt.Errorf("ctxType:%T", ctxType)
}
replyType := mtype.In(2)
if replyType.Kind() != reflect.Ptr {
return
}
if !this.isExportedOrBuiltinType(replyType) {
return
if replyType != msgtype {
return fmt.Errorf("replyType:%T", replyType)
}
if mtype.NumOut() != 2 {
return
return fmt.Errorf("mtype.NumOut():%d", mtype.NumOut())
}
returnMapType := mtype.Out(0)
if !returnMapType.Implements(typeOfMapStringIntface) {
return
return fmt.Errorf("returnMapType:%T", returnMapType)
}
returnCodeType := mtype.Out(1)
if returnCodeType != typeOfCode {
return
return fmt.Errorf("returnCodeType:%T", returnCodeType)
}
this.scomp.RegisterRouteCheck(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname[0])), reflect.ValueOf(this.comp), replyType, method)
return nil
}
func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool {
func (this *MCompGate) isExportedOrBuiltinType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
t = t.Elem()
}
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)
return unicode.IsUpper(rune)
}

View File

@ -23,7 +23,7 @@ import (
基础组件 缓存组件 读写缓存数据
DB组件也封装进来
*/
type Model_Comp struct {
type MCompModel struct {
cbase.ModuleCompBase
Redis redis.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.Redis = cache.Redis()
this.DB = db.Mgo()
return
}
func (this *Model_Comp) Start() (err error) {
func (this *MCompModel) Start() (err error) {
err = this.ModuleCompBase.Start()
return
}
func (this *Model_Comp) ukey(uid string) string {
func (this *MCompModel) ukey(uid string) string {
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)
}
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{
ID: primitive.NewObjectID().Hex(),
@ -70,7 +70,7 @@ func (this *Model_Comp) InsertModelLogs(table string, uID string, target interfa
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{
ID: primitive.NewObjectID().Hex(),
@ -88,7 +88,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac
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{
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 {
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)
if err = this.Redis.HMSet(key, data); err != nil {
return
@ -134,13 +134,13 @@ func (this *Model_Comp) AddList(uid string, id string, data interface{}, attrs .
this.Redis.Expire(this.ukey(uid), ret.(time.Duration))
}
if ret := cache.OperationAttrs(attrs).Find(cache.ATTR_MGOLOG).Unwrap_Or(nil); ret == nil {
err = this.InsertModelLogs(this.TableName, uid, data)
err = this.InsertModelLogs(this.TableName, uid, []interface{}{data})
}
return
}
//添加新的多个数据到列表 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)
if !vof.IsValid() {
return fmt.Errorf("Model_Comp: AddLists(nil)")
@ -180,7 +180,7 @@ func (this *Model_Comp) AddLists(uid string, data interface{}, attrs ...*cache.O
}
//修改数据多个字段 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 {
return
}
@ -194,7 +194,7 @@ func (this *Model_Comp) Change(uid string, data map[string]interface{}, attrs ..
}
//修改数据多个字段 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 {
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 {
return
}
@ -223,7 +223,7 @@ func (this *Model_Comp) Get(uid string, data interface{}) (err error) {
}
//获取列表数据 注意 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 c *mongo.Cursor
t := reflect.TypeOf(data)
@ -294,6 +294,9 @@ func (this *Model_Comp) GetList(uid string, data interface{}) (err error) {
}
temp[_id] = elem.Elem().Addr().Interface()
}
if len(temp) == 0 { //没有数据自己返回
return
}
for k, v := range temp {
key := this.ukeylist(uid, k)
if err = this.Redis.HMSet(key, v); err != nil {
@ -311,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...)
return
}
//读取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...)
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)
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))
if err != nil {
return err
@ -339,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)
for _, v := range ids {
key := this.ukeylist(uid, v)
@ -354,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)
if ret == nil { //启用mgolog
ir := cache.OperationAttrs(attrs).Find(cache.ATTR_INSERT).Unwrap_Or(nil)

View File

@ -8,14 +8,14 @@ import (
)
///配置管理基础组件
type MComp_Configure struct {
type MCompConfigure struct {
cbase.ModuleCompBase
S base.IRPCXService //rpc服务对象
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.S = service.(base.IRPCXService)
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)
}
//加载多个配置文件
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 {
err = configure.RegisterConfigure(k, v)
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)
}

View File

@ -14,20 +14,20 @@ import (
)
type DB_Comp struct {
modules.Model_Comp
modules.MCompModel
task chan string
isInit bool
}
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)
return
}
func (this *DB_Comp) Start() (err error) {
err = this.Model_Comp.Start()
err = this.MCompModel.Start()
model_count := this.Model_TotalCount()
if model_count > 0 { //1000
this.Redis.Set(comm.DBService_Status, true, -1)

View File

@ -9,21 +9,21 @@ import (
/*
装备模块 API
*/
type Api_Comp struct {
modules.MComp_GateComp
type apiComp struct {
modules.MCompGate
service core.IService
module *Equipment
}
//组件初始化接口
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)
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Equipment)
this.service = service
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
func (this *apiComp) Start() (err error) {
err = this.MCompGate.Start()
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 (
err error
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))
for i, v := range req.EquipmentId {
if v != "" {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
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)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
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 (
err error
confs []*cfg.Game_equipData
@ -55,11 +55,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
updatequipment []*pb.DB_Equipment
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)
equipments = agrs["equipment"].([]*pb.DB_Equipment)
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 {
if v != "" {
if equipments[i] != nil && v != equipments[i].Id {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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)
code = pb.ErrorCode_SystemError
return
@ -77,7 +73,7 @@ func (this *Api_Comp) Equip(session comm.IUserSession, agrs map[string]interface
equipments[i].HeroId = hero.Id
updatequipment = append(updatequipment, equipment, equipments[i])
} else if equipments[i] == nil {
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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)
code = pb.ErrorCode_SystemError
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 err = this.module.model_equipment_comp.Equipment_UpdateIsEquip(session.GetUserId(), updatequipment...); err != nil {
if err = this.module.modelEquipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
log.Errorf("Equip err%v", err)
code = pb.ErrorCode_SystemError
return

View File

@ -7,13 +7,13 @@ 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
}
///获取用户装备列表
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) (code pb.ErrorCode) {
var (
err error
items []*pb.DB_Equipment
@ -23,7 +23,7 @@ func (this *Api_Comp) Getlist(session comm.IUserSession, agrs map[string]interfa
session.SendMsg(string(this.module.GetType()), "", &pb.Equipment_GetList_Resp{Equipments: items})
}
}()
if items, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPack(session.GetUserId()); err != nil {
if items, err = this.module.modelequipment.QueryUserEquipments(session.GetUserId()); err != nil {
log.Errorf("QueryUserPackReq err:%v", err)
code = pb.ErrorCode_CacheReadError
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 (
err error
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
return
}
if equipment, err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(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)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
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)
code.Code = pb.ErrorCode_EquipmentOnFoundEquipment
return
}
//找到下一个等级的相关配置
if intensify, err = this.module.configure_comp.GetEquipmentIntensifyConfigureById(equipment.Lv + 1); err != nil {
if intensify, err = this.module.configure.GetEquipmentIntensifyConfigureById(equipment.Lv); err != nil {
log.Errorf("Equip_Check err:%v", err)
code.Code = pb.ErrorCode_EquipmentLvlimitReached
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 (
err error
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 {
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,
"heroId": "",
}); err != nil {
@ -97,17 +97,27 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
equipment.Id = primitive.NewObjectID().Hex()
equipment.IsInitialState = false
equipment.OverlayNum = 1
equipment.Lv++
if err = this.module.model_equipment_comp.AddList(session.GetUserId(), equipment.Id, equipment); err != nil {
if err = this.module.modelEquipment.upgradeEquipment(equipment, conf, intensify); err != nil {
code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err)
return
}
if err = this.module.modelEquipment.AddList(session.GetUserId(), equipment.Id, equipment); err != nil {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_SystemError
return
}
} else {
equipment.IsInitialState = false
equipment.Lv++
if err = this.module.model_equipment_comp.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{
if err = this.module.modelEquipment.upgradeEquipment(equipment, conf, intensify); err != nil {
code = pb.ErrorCode_SystemError
log.Errorf("Upgrade err:%v", err)
return
}
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equipment.Id, map[string]interface{}{
"lv": equipment.Lv,
"mainEntry": equipment.MainEntry,
"adverbEntry": equipment.AdverbEntry,
"isInitialState": false,
}); err != nil {
log.Errorf("Upgrade err:%v", err)
@ -126,7 +136,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa
for i, v := range hero.EquipID {
if v != "" {
if v != equipment.Id {
if equipments[i], err = this.module.model_equipment_comp.Equipment_QueryUserEquipmentsPackById(session.GetUserId(), v); err != nil {
if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_EquipmentOnFoundEquipment
return

View File

@ -6,22 +6,23 @@ import (
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
)
const (
game_equip = "game_equip.json" //装备信息表
equip_attrlibrary = "equip_attrlibrary.json" //装备属性配置表
equip_intensify = "equip_intensify.json" //装备等级消耗表
equip_suit = "equip_suit.json" //装备套装表
game_equip = "game_equip.json" //装备信息表
equip_attrlibrary = "game_equipattrlibrary.json" //装备属性配置表
equip_intensify = "game_equipintensify.json" //装备等级消耗表
equip_suit = "game_equipsuit.json" //装备套装表
)
///背包配置管理组件
type Configure_Comp struct {
modules.MComp_Configure
type configureComp struct {
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.LoadConfigure(game_equip, cfg.NewGame_equip)
this.LoadConfigure(equip_attrlibrary, cfg.NewGame_equipAttrlibrary)
@ -29,16 +30,18 @@ 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 (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_equip); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equip); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return
}
}
@ -46,16 +49,18 @@ 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 (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_equip); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equip).GetDataMap()[equipmentId]; !ok {
err = fmt.Errorf("EquipmentConfigure not found:%d ", equipmentId)
log.Errorf("err:%v", err)
return
}
}
@ -63,16 +68,18 @@ 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 (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equipAttrlibrary); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return
}
}
@ -80,11 +87,31 @@ func (this *Configure_Comp) GetEquipmentAttrlibraryConfigure() (configure *cfg.G
}
//获取属性词列表
func (this *Configure_Comp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) {
func (this *configureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.Game_equipAttrlibraryData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equipAttrlibrary).GetDataMap()[key]; !ok {
err = fmt.Errorf("EquipmentConfigure GetEquipmentAttrlibraryConfigureByKey not found:%d ", key)
log.Errorf("err:%v", err)
return
}
}
return
}
//获取属性词列表
func (this *configureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.Game_equipAttrlibraryData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
log.Errorf("err:%v", err)
return
} else {
configure = make([]*cfg.Game_equipAttrlibraryData, 0)
@ -98,16 +125,18 @@ 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 (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_intensify); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equipIntensify); !ok {
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
log.Errorf("err:%v", err)
return
}
}
@ -115,16 +144,18 @@ 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 (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_intensify); err != nil {
log.Errorf("err:%v", err)
return
} else {
if configure, ok = v.(*cfg.Game_equipIntensify).GetDataMap()[Id]; !ok {
err = fmt.Errorf("EquipmentConfigure not found:%d ", Id)
log.Errorf("err:%v", err)
return
}
}

View File

@ -0,0 +1,234 @@
package equipment
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///装备 数据组件
type modelEquipmentComp struct {
modules.MCompModel
module *Equipment
}
//组件初始化接口
func (this *modelEquipmentComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Equipment)
this.TableName = "equipment"
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户装备数据
func (this *modelEquipmentComp) QueryUserEquipmentsById(uId, id string) (equipment *pb.DB_Equipment, err error) {
equipment = &pb.DB_Equipment{}
err = this.GetListObj(uId, id, equipment)
return
}
///查询用户的武器背包
func (this *modelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) {
equipments = make([]*pb.DB_Equipment, 0)
err = this.GetList(uId, &equipments)
return
}
///查询目标卡片数量
func (this *modelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) {
var (
equipments []*pb.DB_Equipment
err error
)
amount = 0
if equipments, err = this.QueryUserEquipments(uid); err != nil {
return
}
for _, v := range equipments {
if v.CId == equipmentId {
amount += v.OverlayNum
}
}
return
}
//添加装备
func (this *modelEquipmentComp) AddEquipments(uId string, cIds map[int32]uint32) (err error) {
var (
configure *cfg.Game_equip
equipments []*pb.DB_Equipment
iskeep bool
add map[string]*pb.DB_Equipment
update map[string]*pb.DB_Equipment
)
if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return
}
if equipments, err = this.QueryUserEquipments(uId); err != nil {
return
}
add = make(map[string]*pb.DB_Equipment)
update = make(map[string]*pb.DB_Equipment)
for k, v := range cIds {
iskeep = false
for _, equipment := range equipments {
if equipment.CId == k && equipment.IsInitialState {
update[equipment.Id] = equipment
equipment.OverlayNum += v
iskeep = true
break
}
}
if !iskeep {
if c, ok := configure.GetDataMap()[k]; ok {
if equipment, err := this.newEquipment(uId, c, v); err != nil {
return err
} else {
add[equipment.Id] = equipment
}
}
}
}
if err = this.AddLists(uId, add); err != nil {
log.Errorf("err:%v", err)
return
}
for _, v := range update {
if err = this.ChangeList(uId, v.Id, map[string]interface{}{"overlayNum": v.OverlayNum}); err != nil {
log.Errorf("err:%v", err)
return
}
}
return
}
//更新武器挂载信息
func (this *modelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) {
for _, v := range equipments {
if err = this.ChangeList(uid, v.Id, map[string]interface{}{
"heroId": v.HeroId,
}); err != nil {
log.Errorf("err:%v", err)
return
}
}
return
}
//创建新的武器对象
func (this *modelEquipmentComp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) {
var (
mattr []*cfg.Game_equipAttrlibraryData
sattr []*cfg.Game_equipAttrlibraryData
total int
satterNum int32
)
equipment = &pb.DB_Equipment{
Id: primitive.NewObjectID().Hex(),
CId: conf.Id,
Lv: 1,
UId: uid,
OverlayNum: num,
IsInitialState: true,
AdverbEntry: make([]*pb.EquipmentAttributeEntry, 0),
}
if mattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 {
return
}
equipment.MainEntry = &pb.EquipmentAttributeEntry{
Id: mattr[0].Key,
Libraryid: mattr[0].Libraryid,
Lv: 1,
AttrName: mattr[0].Attrkey,
Value: mattr[0].Attrvar,
}
if sattr, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 {
return
}
for _, v := range conf.Addattrnump {
total += int(v)
}
n := rand.Intn(total)
for i, v := range conf.Addattrnump {
if int32(n) <= v {
satterNum = conf.Addattrnum[i]
break
}
}
if satterNum > 0 && satterNum <= 4 {
r := rand.New(rand.NewSource(time.Now().Unix()))
for _, v := range r.Perm(len(sattr))[:satterNum] {
equipment.AdverbEntry = append(equipment.AdverbEntry, &pb.EquipmentAttributeEntry{
Id: sattr[v].Key,
Libraryid: sattr[v].Libraryid,
Lv: 1,
AttrName: sattr[v].Attrkey,
Value: sattr[v].Attrvar,
})
}
}
return
}
//升级武器
func (this *modelEquipmentComp) upgradeEquipment(equipment *pb.DB_Equipment, equip *cfg.Game_equipData, intensify *cfg.Game_equipIntensifyData) (err error) {
equipment.Lv++
equipment.MainEntry.Lv++
equipment.MainEntry.Value += equipment.MainEntry.Value * (intensify.Bonus / 1000.0)
if !intensify.Activation { //不触发副词条变化
return
}
if len(equipment.AdverbEntry) < 4 { //去随机副词条
var temp []*cfg.Game_equipAttrlibraryData
var sattr []*cfg.Game_equipAttrlibraryData
if temp, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(equip.Addlibrary); err != nil || len(temp) == 0 {
log.Errorf("升级服务错误 读取副词条配置错误!")
return
}
//检索出未使用的词条
for _, v := range sattr {
iskeep := false
for _, v1 := range equipment.AdverbEntry {
if v.Key == v1.Id {
iskeep = true
}
}
if !iskeep {
sattr = append(sattr, v)
}
}
r := rand.New(rand.NewSource(time.Now().Unix()))
index := r.Perm(len(sattr))[0]
equipment.AdverbEntry = append(equipment.AdverbEntry, &pb.EquipmentAttributeEntry{
Id: sattr[index].Key,
Libraryid: sattr[index].Libraryid,
Lv: 1,
AttrName: sattr[index].Attrkey,
Value: sattr[index].Attrvar,
})
} else { //随机一个副词条 强化
var attrlibrary *cfg.Game_equipAttrlibraryData
r := rand.New(rand.NewSource(time.Now().Unix()))
index := r.Perm(len(equipment.AdverbEntry))[0]
if attrlibrary, err = this.module.configure.GetEquipmentAttrlibraryConfigureByKey(equipment.AdverbEntry[index].Id); err != nil {
return
}
equipment.AdverbEntry[index].Value += attrlibrary.Addition[equipment.AdverbEntry[index].Lv-1] / 1000.0 * attrlibrary.Attrvar
equipment.AdverbEntry[index].Lv++
}
return
}

View File

@ -1,165 +0,0 @@
package equipment
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
///装备 数据组件
type Model_Equipment_Comp struct {
modules.Model_Comp
module *Equipment
}
//组件初始化接口
func (this *Model_Equipment_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt)
this.module = module.(*Equipment)
this.TableName = "equipment"
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户装备数据
func (this *Model_Equipment_Comp) Equipment_QueryUserEquipmentsPackById(uId, id string) (equipment *pb.DB_Equipment, err error) {
equipment = &pb.DB_Equipment{}
err = this.GetListObj(uId, id, equipment)
return
}
///查询用户的武器背包
func (this *Model_Equipment_Comp) Equipment_QueryUserEquipmentsPack(uId string) (equipments []*pb.DB_Equipment, err error) {
equipments = make([]*pb.DB_Equipment, 0)
err = this.GetList(uId, &equipments)
return
}
//添加装备
func (this *Model_Equipment_Comp) Equipment_AddEquipmentsToPack(uId string, cIds map[int32]uint32) (err error) {
var (
configure *cfg.Game_equip
equipments []*pb.DB_Equipment
iskeep bool
add map[string]*pb.DB_Equipment
update map[string]*pb.DB_Equipment
)
if configure, err = this.module.configure_comp.GetEquipmentConfigure(); err != nil {
return
}
if equipments, err = this.Equipment_QueryUserEquipmentsPack(uId); err != nil {
return
}
add = make(map[string]*pb.DB_Equipment)
update = make(map[string]*pb.DB_Equipment)
for k, v := range cIds {
iskeep = false
for _, equipment := range equipments {
if equipment.CId == k && equipment.IsInitialState {
update[equipment.Id] = equipment
equipment.OverlayNum += v
iskeep = true
break
}
}
if !iskeep {
if c, ok := configure.GetDataMap()[k]; ok {
if equipment, err := this.newEquipment(uId, c, v); err != nil {
return err
} else {
add[equipment.Id] = equipment
}
}
}
}
if err = this.AddLists(uId, add); err != nil {
log.Errorf("[Equipment] Equipment_AddEquipmentsToPack err:%v", err)
return
}
for _, v := range update {
if err = this.ChangeList(uId, v.Id, map[string]interface{}{"overlayNum": v.OverlayNum}); err != nil {
log.Errorf("[Equipment] Equipment_AddEquipmentsToPack err:%v", err)
return
}
}
return
}
func (this *Model_Equipment_Comp) Equipment_UpdateIsEquip(uid string, equipments ...*pb.DB_Equipment) (err error) {
for _, v := range equipments {
if err = this.ChangeList(uid, v.Id, map[string]interface{}{
"heroId": v.HeroId,
}); err != nil {
log.Errorf("Equipment_UpdateIsEquip err:%v", err)
return
}
}
return
}
//创建新的武器对象
func (this *Model_Equipment_Comp) newEquipment(uid string, conf *cfg.Game_equipData, num uint32) (equipment *pb.DB_Equipment, err error) {
var (
mattr []*cfg.Game_equipAttrlibraryData
sattr []*cfg.Game_equipAttrlibraryData
total int
satterNum int32
)
equipment = &pb.DB_Equipment{
Id: primitive.NewObjectID().Hex(),
CId: conf.Id,
UId: uid,
OverlayNum: num,
IsInitialState: true,
AdverbEntry: make([]*pb.EquipmentAttributeEntry, 4),
}
if mattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Leadlibrary); err != nil || len(mattr) == 0 {
return
}
equipment.MainEntry = &pb.EquipmentAttributeEntry{
Id: mattr[0].Key,
Libraryid: mattr[0].Libraryid,
Lv: 0,
AttrName: mattr[0].Attr[0],
Value: 0,
}
if sattr, err = this.module.configure_comp.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(mattr) == 0 {
return
}
for _, v := range conf.Addattrnump {
total += int(v)
}
n := rand.Intn(total)
for i, v := range conf.Addattrnump {
if int32(n) <= v {
satterNum = conf.Addattrnum[i]
break
}
}
if satterNum > 0 {
r := rand.New(rand.NewSource(time.Now().Unix()))
for i, v := range r.Perm(len(sattr))[:satterNum] {
equipment.AdverbEntry[i] = &pb.EquipmentAttributeEntry{
Id: sattr[v].Key,
Libraryid: sattr[v].Libraryid,
Lv: 0,
AttrName: sattr[v].Attr[0],
Value: 0,
}
}
}
return
}

View File

@ -4,7 +4,9 @@ import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"github.com/go-redis/redis/v8"
"github.com/smallnest/rpcx/log"
)
@ -20,11 +22,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
service core.IService
api *apiComp
configure *configureComp
modelEquipment *modelEquipmentComp
hero comm.IHero
}
//模块名
@ -54,7 +56,37 @@ func (this *Equipment) Start() (err error) {
//装备组件
func (this *Equipment) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.model_equipment_comp = this.RegisterComp(new(Model_Equipment_Comp)).(*Model_Equipment_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelEquipment = this.RegisterComp(new(modelEquipmentComp)).(*modelEquipmentComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
//IEquipment-------------------------------------------------------------------------------------------------------------------------------
//查询武器信息
func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, Id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) {
var err error
if equipment, err = this.modelEquipment.QueryUserEquipmentsById(uid, Id); err != nil {
if err == redis.Nil {
code = pb.ErrorCode_EquipmentOnFoundEquipment
} else {
code = pb.ErrorCode_SystemError
}
}
return
}
//查询卡片数量
func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId int32) (amount uint32) {
amount = this.modelEquipment.QueryEquipmentAmount(uid, equipmentId)
return
}
//添加武器
func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) {
var err error
if err = this.modelEquipment.AddEquipments(uid, cIds); err != nil {
log.Errorf("err%v", err)
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,4 +1,4 @@
package equipment
package equipment_test
import (
"fmt"
@ -7,6 +7,8 @@ import (
"go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/equipment"
"go_dreamfactory/modules/hero"
"go_dreamfactory/services"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/configure"
@ -40,7 +42,7 @@ func (this *TestService) InitSys() {
} else {
log.Infof("init sys.db success!")
}
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil {
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
} else {
log.Infof("init sys.configure success!")
@ -49,7 +51,7 @@ func (this *TestService) InitSys() {
var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Equipment)
var module = new(equipment.Equipment)
//测试环境下初始化db和cache 系统
func TestMain(m *testing.M) {
@ -63,6 +65,7 @@ func TestMain(m *testing.M) {
go func() {
lego.Run(service, //运行模块
module,
hero.NewModule(),
)
}()
time.Sleep(time.Second * 3)
@ -70,5 +73,10 @@ func TestMain(m *testing.M) {
}
func Test_Module(t *testing.T) {
code := module.AddNewEquipments(&comm.ModuleCallSource{
Module: "Test",
FuncName: "Test_Module",
Describe: "摸底测试",
}, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1})
log.Debugf("Test_Module Code:%d", code)
}

View File

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

View File

@ -11,12 +11,12 @@ const (
)
///背包配置管理组件
type Configure_Comp struct {
modules.MComp_Configure
type configureComp struct {
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)
return

View File

@ -9,14 +9,14 @@ import (
)
///论坛 数据组件
type Model_Forum_Comp struct {
modules.Model_Comp
type modelForumComp struct {
modules.MCompModel
module *Forum
}
//组件初始化接口
func (this *Model_Forum_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt)
func (this *modelForumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Forum)
this.TableName = "forum"
//创建uid索引

View File

@ -18,9 +18,9 @@ func NewModule() core.IModule {
type Forum struct {
modules.ModuleBase
api_comp *Api_Comp
configure_comp *Configure_Comp
model_forum_comp *Model_Forum_Comp
api_comp *apiComp
configure_comp *configureComp
model_forum_comp *modelForumComp
}
//模块名
@ -37,7 +37,7 @@ func (this *Forum) Init(service core.IService, module core.IModule, options core
//装备组件
func (this *Forum) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.model_forum_comp = this.RegisterComp(new(Model_Forum_Comp)).(*Model_Forum_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_forum_comp = this.RegisterComp(new(modelForumComp)).(*modelForumComp)
this.configure_comp = this.RegisterComp(new(configureComp)).(*configureComp)
}

View File

@ -18,12 +18,12 @@ const (
)
type apiComp struct {
modules.MComp_GateComp
modules.MCompGate
module *Friend
}
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.(*Friend)
return
}

View File

@ -15,7 +15,7 @@ const (
)
type ModelFriend struct {
modules.Model_Comp
modules.MCompModel
}
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {

View File

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

View File

@ -208,7 +208,7 @@ func (this *Agent) Close() {
}
//分发用户消息
func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
servicePath := comm.Service_Worker
@ -219,25 +219,32 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) error {
servicePath = fmt.Sprintf("%s/%s", comm.Service_Worker, this.wId)
}
}
if err := this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
if err = this.gateway.Service().RpcCall(context.Background(), servicePath, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
Ip: this.IP(),
UserSessionId: this.sessionId,
UserId: this.uId,
GatewayServiceId: this.gateway.Service().GetId(),
Method: fmt.Sprintf("%s.%s", msg.MainType, msg.SubType),
MainType: msg.MainType,
SubType: msg.SubType,
Message: msg.Data,
}, reply); err != nil {
log.Errorf("agent:%s uId:%s MessageDistribution err:%v", this.sessionId, this.uId, err)
return err
return
}
if reply.Code != pb.ErrorCode_Success {
data, _ := anypb.New(&pb.ErrorNotify{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode(reply.Code.Number())})
err := this.WriteMsg(&pb.UserMessage{
err = this.WriteMsg(&pb.UserMessage{
MainType: comm.MainType_Notify,
SubType: comm.SubType_ErrorNotify,
Data: data,
})
return err
return
} else {
for _, v := range reply.Reply {
if err = this.WriteMsg(v); err != nil {
return
}
}
}
return nil
}

View File

@ -16,13 +16,13 @@ import (
/*
用户代理对象管理组件
*/
type AgentMgr_Comp struct {
type AgentMgrComp struct {
cbase.ModuleCompBase
service base.IRPCXService
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)
this.service = service.(base.IRPCXService)
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)
}
//移除断开的用户
func (this *AgentMgr_Comp) DisConnect(a IAgent) {
func (this *AgentMgrComp) DisConnect(a IAgent) {
this.agents.Delete(a.SessionId())
if a.UserId() != "" { //登录用户 通知业务服务处理玩家离线相关
reply := &pb.RPCMessageReply{}
@ -48,29 +48,29 @@ func (this *AgentMgr_Comp) DisConnect(a IAgent) {
}
//用户登录绑定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 {
a.(IAgent).Bind(args.UserId, args.WorkerId)
} else {
reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
}
return nil
}
//用户登录解绑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 {
a.(IAgent).UnBind()
} else {
reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
}
return nil
}
//向用户发送消息
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 {
a.(IAgent).WriteMsg(&pb.UserMessage{
MainType: args.MainType,
@ -79,13 +79,13 @@ func (this *AgentMgr_Comp) SendMsgToAgent(ctx context.Context, args *pb.AgentSen
})
} else {
reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
}
return nil
}
//向多个户发送消息
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{
MainType: args.MainType,
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{
MainType: args.MainType,
SubType: args.SubType,
@ -114,12 +114,12 @@ 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 {
a.(IAgent).Close()
} else {
reply.Code = pb.ErrorCode_UserSessionNobeing
reply.Message = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
reply.ErrorMessage = pb.GetErrorCodeMsg(pb.ErrorCode_UserSessionNobeing)
}
return nil
}

View File

@ -21,10 +21,10 @@ func NewModule() core.IModule {
type Gateway struct {
modules.ModuleBase
service base.IRPCXService
wsservice_comp *WSService_Comp //websocket 服务组件 提供websocket服务监听
agentmgr_comp *AgentMgr_Comp //用户代理对象管理组件 管理用户socekt对象
configure_comp *Configure_Comp
service base.IRPCXService
wsservice *WSServiceComp //websocket 服务组件 提供websocket服务监听
agentmgr *AgentMgrComp //用户代理对象管理组件 管理用户socekt对象
configure *ConfigureComp
}
//模块名
@ -52,17 +52,17 @@ func (this *Gateway) Init(service core.IService, module core.IModule, options co
//模块启动函数 注册rpc服务接口提供用户相关的rpc接口服务
func (this *Gateway) Start() (err error) {
//注册用户绑定uid接口 登录成功后触发
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr_comp.Bind)
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBind), this.agentmgr.Bind)
//注册用户解绑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连接接口
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()
return
}
@ -70,24 +70,24 @@ func (this *Gateway) Start() (err error) {
//装备组件
func (this *Gateway) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp)
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
this.agentmgr = this.RegisterComp(new(AgentMgrComp)).(*AgentMgrComp)
this.wsservice = this.RegisterComp(new(WSServiceComp)).(*WSServiceComp)
this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
}
//有新的连接对象进入
func (this *Gateway) Connect(a IAgent) {
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) {
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) {
return this.configure_comp.GetMsgDistribRule(mtype, stype)
return this.configure.GetMsgDistribRule(mtype, stype)
}

View File

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

View File

@ -7,7 +7,7 @@ import (
)
type apiComp struct {
modules.MComp_GateComp
modules.MCompGate
service core.IService
moduleHero *Hero
user comm.IUser
@ -21,14 +21,14 @@ const ( //消息回复的头名称
//组件初始化接口
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.moduleHero = module.(*Hero)
this.service = service
return
}
func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start()
err = this.MCompGate.Start()
var module core.IModule

View File

@ -19,13 +19,13 @@ const (
///配置管理组件
type configureComp struct {
modules.MComp_Configure
modules.MCompConfigure
}
//组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MComp_Configure.Init(service, module, comp, options)
err = this.MCompConfigure.Init(service, module, comp, options)
err = this.LoadMultiConfigure(map[string]interface{}{
new_hero: cfg.NewGame_newHero,
hero_stargrow: cfg.NewGame_heroStargrow,

View File

@ -15,12 +15,12 @@ import (
)
type ModelHero struct {
modules.Model_Comp
modules.MCompModel
moduleHero *Hero
}
func (this *ModelHero) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options)
err = this.MCompModel.Init(service, module, comp, options)
this.moduleHero = module.(*Hero)
this.TableName = "hero"
return

View File

@ -15,21 +15,21 @@ const ( //消息回复的头名称
/*
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
*/
type Api_Comp struct {
modules.MComp_GateComp
type apiComp struct {
modules.MCompGate
service core.IService
module *Items
}
//组件初始化接口
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)
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Items)
this.service = service
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
func (this *apiComp) Start() (err error) {
err = this.MCompGate.Start()
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}
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 (
err error
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})
if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据
this.module.model_pack_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...)
this.module.model_pack_comp.Pack_DeleteUserPack(session.GetUserId(), dels...)
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
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)
code = pb.ErrorCode_CacheReadError
return
} 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))
dels = make([]string, 0, len(tempgrids))
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
}
//出售道具
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() {
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
}
//使用道具
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() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.Items_UseItem_Resp{})
}()

View File

@ -15,19 +15,19 @@ const (
)
///背包配置管理组件
type Configure_Comp struct {
modules.MComp_Configure
type ConfigureComp struct {
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.LoadConfigure(game_item, cfg.NewGame_item)
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 (
v interface{}
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))
var (
v interface{}

View File

@ -12,14 +12,14 @@ import (
)
///背包缓存数据管理组件
type Model_Pack_Comp struct {
modules.Model_Comp
type ModelItemsComp struct {
modules.MCompModel
module *Items
}
//组件初始化接口
func (this *Model_Pack_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, opt)
func (this *ModelItemsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Items)
this.TableName = "items"
//创建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)
err = this.GetList(uId, &itmes)
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{}
err = this.GetListObj(uId, grid, itme)
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 {
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...)
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 {
this.ChangeList(uId, v.GridId, map[string]interface{}{
"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...)
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 (
itmes []*pb.DB_UserItemData
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 (
itmes []*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 (
itmes []*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 (
itme *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 (
num int64
isNew bool

View File

@ -21,10 +21,9 @@ func NewModule() core.IModule {
type Items struct {
modules.ModuleBase
api_comp *Api_Comp
model_pack_comp *Model_Pack_Comp
// db_comp *DB_Comp
configure_comp *Configure_Comp
api *apiComp
modelItems *ModelItemsComp
configure *ConfigureComp
}
//模块名称
@ -41,17 +40,17 @@ func (this *Items) Init(service core.IService, module core.IModule, options core
//装备组件
func (this *Items) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.model_pack_comp = this.RegisterComp(new(Model_Pack_Comp)).(*Model_Pack_Comp)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelItems = this.RegisterComp(new(ModelItemsComp)).(*ModelItemsComp)
this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp)
}
//IPack-------------------------------------------------------------------------------------------------------------------------------
//IItems-------------------------------------------------------------------------------------------------------------------------------
///查询用户背包物品数量
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)
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
@ -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) {
result = this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid...)
result = this.modelItems.Pack_QueryUserPackItemsAmount(uId, itemid...)
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) {
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 {
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)
if err == ItemNotEnoughError {
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) {
var err error
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)
if err == ItemNotEnoughError {
code = pb.ErrorCode_ItemsNoEnough

View File

@ -1,4 +1,4 @@
package items
package items_test
import (
"context"
@ -8,6 +8,7 @@ import (
"go_dreamfactory/lego/base/rpcx"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules/items"
"go_dreamfactory/pb"
"go_dreamfactory/services"
"go_dreamfactory/sys/cache"
@ -53,7 +54,7 @@ func (this *TestService) InitSys() {
var service core.IService
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
var module = new(Items)
var module = new(items.Items)
//测试环境下初始化db和cache 系统
func TestMain(m *testing.M) {
@ -75,7 +76,7 @@ func TestMain(m *testing.M) {
func Test_Modules(t *testing.T) {
data, _ := ptypes.MarshalAny(&pb.Items_Getlist_Req{})
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{Method: "pack.getlist", Message: data}, &pb.RPCMessageReply{})
s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{MainType: "pack", SubType: "getlist", Message: data}, &pb.RPCMessageReply{})
// items, err := module.db_comp.Pack_QueryUserPack("liwei1dao")
// log.Debugf("item:%v err:%v", items, err)
}

View File

@ -16,14 +16,14 @@ const (
)
type apiComp struct {
modules.MComp_GateComp
modules.MCompGate
service core.IService
module *Mail
items comm.IItems
}
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.service = service
this.module = module.(*Mail)
@ -31,7 +31,7 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core.
}
func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start()
err = this.MCompGate.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.SM_ItemsModule); err != nil {

View File

@ -57,7 +57,7 @@ func (this *Mail) CreateNewMail(uId string) {
}
// 通知玩家
var _cache = &pb.Cache_UserData{}
err = this.modelMail.Model_Comp.Get(uId, _cache)
err = this.modelMail.MCompModel.Get(uId, _cache)
if err == nil {
return
}

View File

@ -80,36 +80,36 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
//校验消耗资源
func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) {
var (
module core.IModule
err error
resID int
amount int32
user comm.IUser //用户模块
items comm.IItems //道具背包模块
hero comm.IHero //英雄模块
equipment comm.IEquipment //装备模块
module core.IModule
err error
resID int
amount int32
user comm.IUser //用户模块
items comm.IItems //道具背包模块
hero comm.IHero //英雄模块
// equipment comm.IEquipment //装备模块
)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil {
return
}
user = module.(comm.IUser)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil {
if module, err = this.service.GetModule(comm.SM_ItemsModule); err == nil {
return
}
items = module.(comm.IItems)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil {
if module, err = this.service.GetModule(comm.SM_HeroModule); err == nil {
return
}
hero = module.(comm.IHero)
if module, err = this.service.GetModule(comm.SM_UserModule); err == nil {
return
}
// if module, err = this.service.GetModule(comm.SM_EquipmentModule); err == nil {
// return
// }
// equipment = module.(comm.IEquipment)
source := &comm.ModuleCallSource{
Module: string(this.module.GetType()),
FuncName: "CheckConsumeRes",
Describe: "消耗资源",
}
equipment = module.(comm.IEquipment)
//校验消费资源是否充足
for _, v := range res {
if v.A == comm.AttrType { //用户属性资源
@ -135,16 +135,18 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
code = pb.ErrorCode_ResNoEnough
return
}
} else if v.A == comm.EquipmentType {
if resID, err = strconv.Atoi(v.T); err != nil {
code = pb.ErrorCode_ConfigurationException
return
}
if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N {
code = pb.ErrorCode_ResNoEnough
return
}
}
//不存在消耗武器的情况
// } else if v.A == comm.EquipmentType {
// if resID, err = strconv.Atoi(v.T); err != nil {
// code = pb.ErrorCode_ConfigurationException
// return
// }
// if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N {
// code = pb.ErrorCode_ResNoEnough
// return
// }
// }
}
for _, v := range res {
@ -156,10 +158,11 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
} else if v.A == comm.CardType { //卡片资源
resID, _ = strconv.Atoi(v.T)
hero.ChangeCard(uid, int32(resID), -1*v.N)
} else if v.A == comm.EquipmentType {
resID, _ = strconv.Atoi(v.T)
equipment.AddNewEquipments(source, uid, resID, -1*v.N)
}
// } else if v.A == comm.EquipmentType {
// resID, _ = strconv.Atoi(v.T)
// equipment.AddNewEquipments(source, uid, resID, -1*v.N)
// }
}
return

View File

@ -15,21 +15,21 @@ const (
)
type apiComp struct {
modules.MComp_GateComp
modules.MCompGate
service base.IRPCXService
module *User
hero comm.IHero
}
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.service = service.(base.IRPCXService)
this.module = module.(*User)
return
}
func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start()
err = this.MCompGate.Start()
var module core.IModule
//get module hero

View File

@ -6,11 +6,11 @@ import (
)
type ModelSession struct {
modules.Model_Comp
modules.MCompModel
}
func (this *ModelSession) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options)
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = "session"
return
}

View File

@ -17,11 +17,11 @@ const ( //Redis
)
type ModelUser struct {
modules.Model_Comp
modules.MCompModel
}
func (this *ModelUser) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.Model_Comp.Init(service, module, comp, options)
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = "user"
return
}

View File

@ -160,8 +160,9 @@ type AgentMessage struct {
UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId"`
UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId"`
GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"`
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method"`
Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message"`
MainType string `protobuf:"bytes,5,opt,name=MainType,proto3" json:"MainType"`
SubType string `protobuf:"bytes,6,opt,name=SubType,proto3" json:"SubType"`
Message *anypb.Any `protobuf:"bytes,7,opt,name=Message,proto3" json:"Message"`
}
func (x *AgentMessage) Reset() {
@ -224,9 +225,16 @@ func (x *AgentMessage) GetGatewayServiceId() string {
return ""
}
func (x *AgentMessage) GetMethod() string {
func (x *AgentMessage) GetMainType() string {
if x != nil {
return x.Method
return x.MainType
}
return ""
}
func (x *AgentMessage) GetSubType() string {
if x != nil {
return x.SubType
}
return ""
}
@ -244,9 +252,10 @@ type RPCMessageReply struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message"`
Data string `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data"`
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
ErrorMessage string `protobuf:"bytes,2,opt,name=ErrorMessage,proto3" json:"ErrorMessage"`
ErrorData string `protobuf:"bytes,3,opt,name=ErrorData,proto3" json:"ErrorData"`
Reply []*UserMessage `protobuf:"bytes,4,rep,name=Reply,proto3" json:"Reply"`
}
func (x *RPCMessageReply) Reset() {
@ -288,20 +297,27 @@ func (x *RPCMessageReply) GetCode() ErrorCode {
return ErrorCode_Success
}
func (x *RPCMessageReply) GetMessage() string {
func (x *RPCMessageReply) GetErrorMessage() string {
if x != nil {
return x.Message
return x.ErrorMessage
}
return ""
}
func (x *RPCMessageReply) GetData() string {
func (x *RPCMessageReply) GetErrorData() string {
if x != nil {
return x.Data
return x.ErrorData
}
return ""
}
func (x *RPCMessageReply) GetReply() []*UserMessage {
if x != nil {
return x.Reply
}
return nil
}
//用户代理绑定Uid请求
type AgentBuildReq struct {
state protoimpl.MessageState
@ -732,7 +748,7 @@ var file_comm_proto_rawDesc = []byte{
0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e,
0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x65, 0x63, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x65, 0x63, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x41, 0x67,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x65, 0x63, 0x22, 0xee, 0x01, 0x0a, 0x0c, 0x41, 0x67,
0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
@ -741,66 +757,72 @@ var file_comm_proto_rawDesc = []byte{
0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65,
0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x2e, 0x0a, 0x07,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e,
0x63, 0x65, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x4d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e,
0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x97, 0x01, 0x0a, 0x0f, 0x52,
0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e,
0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45,
0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x22,
0x0a, 0x0c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x61, 0x74, 0x61,
0x12, 0x22, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x0c, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x52,
0x65, 0x70, 0x6c, 0x79, 0x22, 0x69, 0x0a, 0x0d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69,
0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73,
0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55,
0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65,
0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22,
0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52,
0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53,
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x9b, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65,
0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71,
0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73,
0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79,
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79,
0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04,
0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79,
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73,
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03,
0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61,
0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61,
0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69,
0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69,
0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12,
0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x41, 0x6e, 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x5f, 0x0a, 0x0f,
0x52, 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12,
0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74,
0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x69, 0x0a,
0x0d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24,
0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69,
0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08,
0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x57, 0x6f, 0x72, 0x6b, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e,
0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55,
0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65,
0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55,
0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x22, 0x9b, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65,
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12,
0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53,
0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75,
0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22,
0x99, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69,
0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65,
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d,
0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d,
0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79,
0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70,
0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42,
0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52,
0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61,
0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65,
0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73,
0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65,
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x2c, 0x0a, 0x12, 0x4e, 0x6f,
0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71,
0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f,
0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06,
0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12,
0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65,
0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a,
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x64, 0x22, 0x2c, 0x0a, 0x12, 0x4e, 0x6f, 0x74, 0x69, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x43,
0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x2a,
0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65,
0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a,
0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12,
0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65, 0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72,
0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -836,14 +858,15 @@ var file_comm_proto_depIdxs = []int32{
11, // 0: UserMessage.data:type_name -> google.protobuf.Any
11, // 1: AgentMessage.Message:type_name -> google.protobuf.Any
12, // 2: RPCMessageReply.Code:type_name -> ErrorCode
11, // 3: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
11, // 4: BatchMessageReq.Data:type_name -> google.protobuf.Any
11, // 5: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
6, // [6:6] is the sub-list for method output_type
6, // [6:6] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name
1, // 3: RPCMessageReply.Reply:type_name -> UserMessage
11, // 4: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
11, // 5: BatchMessageReq.Data:type_name -> google.protobuf.Any
11, // 6: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
7, // [7:7] is the sub-list for method output_type
7, // [7:7] is the sub-list for method input_type
7, // [7:7] is the sub-list for extension type_name
7, // [7:7] is the sub-list for extension extendee
0, // [0:7] is the sub-list for field type_name
}
func init() { file_comm_proto_init() }

View File

@ -18,15 +18,17 @@ message AgentMessage {
string UserSessionId = 2;
string UserId = 3;
string GatewayServiceId = 4;
string Method = 5;
google.protobuf.Any Message = 6;
string MainType = 5;
string SubType = 6;
google.protobuf.Any Message = 7;
}
// RPC
message RPCMessageReply {
ErrorCode Code = 1;
string Message = 2;
string Data = 3;
string ErrorMessage = 2;
string ErrorData = 3;
repeated UserMessage Reply = 4;
}
//Uid请求

View File

@ -27,64 +27,49 @@ import (
*/
func NewGateRouteComp() comm.ISC_GateRouteComp {
comp := new(SComp_GateRouteComp)
comp := new(SCompGateRoute)
return comp
}
//用户协议处理函数注册的反射对象
type msghandle struct {
rcvr reflect.Value
msgType reflect.Type
fn reflect.Method
msgType reflect.Type //消息请求类型
check reflect.Method //校验函数
handle reflect.Method //处理函数
}
//服务网关组件
type SComp_GateRouteComp struct {
type SCompGateRoute struct {
cbase.ServiceCompBase
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
mrlock sync.RWMutex //msghandles 对象的锁
msgcheck map[string]*msghandle //处理函数的校验接口
msghandles map[string]*msghandle //处理函数的管理对象
}
//设置服务组件名称 方便业务模块中获取此组件对象
func (this *SComp_GateRouteComp) GetName() core.S_Comps {
func (this *SCompGateRoute) GetName() core.S_Comps {
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)
this.service = service.(base.IRPCXService)
this.msgcheck = make(map[string]*msghandle)
this.msghandles = make(map[string]*msghandle)
return err
} //
//组件启动时注册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_NoticeUserClose), this.NoticeUserClose) //注册用户离线通知
err = this.ServiceCompBase.Start()
event.RegisterGO(core.Event_ServiceStartEnd, func() {
for k, v := range this.msghandles {
if v1, ok := this.msgcheck[k]; !ok {
log.Panicf("注册用户消息处理函数:%s 没有实现参数校验接口", k)
return
} else if v.msgType != v1.msgType {
log.Panicf("注册用户消息处理函数:%s 实现参数校验接口不一致 请检查代码!", k)
return
}
}
})
event.RegisterGO(core.Event_FindNewService, func() {
log.Debugf("find new service")
})
return
}
//业务模块注册用户消息处理路由
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, check, handele reflect.Method) {
log.Debugf("注册用户路由【%s】", methodName)
this.mrlock.RLock()
_, ok := this.msghandles[methodName]
@ -97,46 +82,28 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V
this.msghandles[methodName] = &msghandle{
rcvr: comp,
msgType: msg,
fn: fn,
}
this.mrlock.Unlock()
}
//业务模块注册用户消息处理路由
func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) {
log.Debugf("注册用户路由校验[%s]", methodName)
this.mrlock.RLock()
_, ok := this.msgcheck[methodName]
this.mrlock.RUnlock()
if ok {
log.Errorf("重复 注册用户路由校验[%s]", methodName)
return
}
this.mrlock.Lock()
this.msgcheck[methodName] = &msghandle{
rcvr: comp,
msgType: msg,
fn: fn,
check: check,
handle: handele,
}
this.mrlock.Unlock()
}
//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() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil {
buf := make([]byte, 1024)
l := runtime.Stack(buf, false)
reply.Code = pb.ErrorCode_Exception
reply.Message = fmt.Sprintf("%v: %s", r, buf[:l])
log.Errorf("HandleUserMsg:%s err:%s", args.Method, reply.Message)
reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
log.Errorf("HandleUserMsg:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
}
}()
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:[%s-%s]", args.UserSessionId, args.UserId, args.MainType, args.SubType)
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
//获取用户消息处理函数
this.mrlock.RLock()
msghandle, ok := this.msghandles[args.Method]
msgcheck := this.msgcheck[args.Method]
msghandle, ok := this.msghandles[method]
this.mrlock.RUnlock()
if ok {
//封装用户会话
@ -144,24 +111,24 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
//序列化用户消息对象
msg := reflect.New(msghandle.msgType.Elem()).Interface()
if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil {
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err)
log.Errorf("UserMessage:%s Unmarshal err:%v", method, err)
return err
}
//调用校验接口
checkreturn := msgcheck.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
checkreturn := msghandle.check.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
//读取校验结果 有错误直接返回错误码给用户
code := checkreturn[1].Interface().(comm.ErrorCode)
if code.Code != pb.ErrorCode_Success {
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code)
reply.Code = code.Code
reply.Message = pb.GetErrorCodeMsg(code.Code)
reply.ErrorMessage = pb.GetErrorCodeMsg(code.Code)
if code.Data != nil { //处理错误附加数据 采用json 序列化为string
if d, err := jsoniter.Marshal(code.Data); err != nil {
log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", args.Method, msg, code, err)
log.Errorf("HandleUserMsg:%s msg:%v code:%d err:%v", method, msg, code, err)
return nil
} else {
reply.Data = codec.BytesToString(d)
reply.ErrorData = codec.BytesToString(d)
}
}
return nil
@ -169,13 +136,15 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
//校验结果成功 处理临时数据转移
result := checkreturn[0].Interface().(map[string]interface{})
//调用用户处理函数
handlereturn := msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)})
handlereturn := msghandle.handle.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(result), reflect.ValueOf(msg)})
errcode := pb.ErrorCode(handlereturn[0].Int())
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
log.Errorf("HandleUserMsg:%s msg:%v code:%d", args.Method, msg, code)
log.Errorf("HandleUserMsg:%s msg:%v code:%d", method, msg, code)
reply.Code = errcode
reply.Message = pb.GetErrorCodeMsg(errcode)
reply.ErrorMessage = pb.GetErrorCodeMsg(errcode)
return nil
} else {
reply.Reply = session.Polls()
}
} else { //未找到消息处理函数
reply.Code = pb.ErrorCode_ReqParameterError
@ -184,7 +153,8 @@ func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentM
}
//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)
return nil
}

View File

@ -1,4 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@ -11,49 +10,87 @@ package cfg
import "errors"
type Game_equipAttrlibraryData struct {
Key int32
Libraryid int32
Attr []string
Probability int32
Addition []int32
Key int32
Libraryid int32
Attrkey string
Attrvar int32
Probability int32
Addition []int32
}
func (Game_equipAttrlibraryData) GetTypeId() int {
return -437457248
return -437457248
}
func NewGame_equipAttrlibraryData(_buf map[string]interface{}) (_v *Game_equipAttrlibraryData, err error) {
_v = &Game_equipAttrlibraryData{}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["libraryid"].(float64); !_ok_ { err = errors.New("libraryid error"); return }; _v.Libraryid = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["attr"].([]interface{}); !_ok_ { err = errors.New("attr error"); return }
_v = &Game_equipAttrlibraryData{}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ {
err = errors.New("key error")
return
}
_v.Key = int32(_tempNum_)
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["libraryid"].(float64); !_ok_ {
err = errors.New("libraryid error")
return
}
_v.Libraryid = int32(_tempNum_)
}
{
var _ok_ bool
if _v.Attrkey, _ok_ = _buf["attrkey"].(string); !_ok_ {
err = errors.New("attrkey error")
return
}
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["attrvar"].(float64); !_ok_ {
err = errors.New("attrvar error")
return
}
_v.Attrvar = int32(_tempNum_)
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["probability"].(float64); !_ok_ {
err = errors.New("probability error")
return
}
_v.Probability = int32(_tempNum_)
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["Addition"].([]interface{}); !_ok_ {
err = errors.New("Addition error")
return
}
_v.Attr = make([]string, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ string
{ if _list_v_, _ok_ = _e_.(string); !_ok_ { err = errors.New("_list_v_ error"); return } }
_v.Attr = append(_v.Attr, _list_v_)
}
}
_v.Addition = make([]int32, 0, len(_arr_))
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["probability"].(float64); !_ok_ { err = errors.New("probability error"); return }; _v.Probability = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["Addition"].([]interface{}); !_ok_ { err = errors.New("Addition error"); return }
for _, _e_ := range _arr_ {
var _list_v_ int32
{
var _ok_ bool
var _x_ float64
if _x_, _ok_ = _e_.(float64); !_ok_ {
err = errors.New("_list_v_ error")
return
}
_list_v_ = int32(_x_)
}
_v.Addition = append(_v.Addition, _list_v_)
}
}
_v.Addition = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.Addition = append(_v.Addition, _list_v_)
}
}
return
return
}