上传模块基础对象的通用依赖封装
This commit is contained in:
parent
2eb02b80fb
commit
b9aaff762b
@ -48,7 +48,7 @@ func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq)
|
||||
}
|
||||
}
|
||||
//获取英雄数据
|
||||
if hero, code = this.module.hero.GetHero(session.GetUserId(), req.HeroCardId); code != pb.ErrorCode_Success {
|
||||
if hero, code = this.module.ModuleHero.GetHero(session.GetUserId(), req.HeroCardId); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
//读取英雄原装备
|
||||
@ -110,7 +110,7 @@ func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq)
|
||||
}
|
||||
}
|
||||
//更新装备数据加成
|
||||
if code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success {
|
||||
if code = this.module.ModuleHero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success {
|
||||
if err = this.module.modelEquipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
|
||||
log.Errorf("Equip err%v", err)
|
||||
code = pb.ErrorCode_SystemError
|
||||
|
@ -124,7 +124,7 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgrade
|
||||
|
||||
//已装备 重新计算属性
|
||||
if equipment.HeroId != "" {
|
||||
if hero, code = this.module.hero.GetHero(session.GetUserId(), equipment.HeroId); code != pb.ErrorCode_Success {
|
||||
if hero, code = this.module.ModuleHero.GetHero(session.GetUserId(), equipment.HeroId); code != pb.ErrorCode_Success {
|
||||
log.Errorf("Upgrade code:%d", code)
|
||||
return
|
||||
}
|
||||
@ -142,7 +142,7 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgrade
|
||||
}
|
||||
}
|
||||
}
|
||||
code = this.module.hero.UpdateEquipment(hero, equipments)
|
||||
code = this.module.ModuleHero.UpdateEquipment(hero, equipments)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -5,16 +5,18 @@ import (
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.ItemsGetlistReq) (result map[string]interface{}, code comm.ErrorCode) {
|
||||
result = map[string]interface{}{"ce": 123}
|
||||
func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.ItemsGetlistReq) (code pb.ErrorCode) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
///获取用户道具
|
||||
func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsGetlistReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
err error
|
||||
items []*pb.DB_UserItemData
|
||||
|
@ -3,16 +3,18 @@ package items
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellItemReq) (result map[string]interface{}, code comm.ErrorCode) {
|
||||
func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//出售道具
|
||||
func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) SellItem(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode, data proto.Message) {
|
||||
defer func() {
|
||||
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{})
|
||||
}()
|
||||
|
@ -3,16 +3,18 @@ package items
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) UseitemCheck(session comm.IUserSession, req *pb.ItemsUseItemReq) (result map[string]interface{}, code comm.ErrorCode) {
|
||||
func (this *apiComp) UseitemCheck(session comm.IUserSession, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//使用道具
|
||||
func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq) (code pb.ErrorCode, data proto.Message) {
|
||||
defer func() {
|
||||
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{})
|
||||
}()
|
||||
|
@ -23,6 +23,11 @@ type ModuleBase struct {
|
||||
cbase.ModuleBase
|
||||
module core.IModule
|
||||
service base.IRPCXService
|
||||
//常用的一些通用模块 在底层注册好
|
||||
ModuleUser comm.IUser //用户模块
|
||||
ModuleItems comm.IItems //道具背包模块
|
||||
ModuleHero comm.IHero //英雄模块
|
||||
ModuleEquipment comm.IEquipment //装备模块
|
||||
}
|
||||
|
||||
//模块初始化接口
|
||||
@ -33,6 +38,29 @@ func (this *ModuleBase) Init(service core.IService, module core.IModule, options
|
||||
return
|
||||
}
|
||||
|
||||
//模块启动接口
|
||||
func (this *ModuleBase) Start() (err error) {
|
||||
err = this.ModuleBase.Start()
|
||||
var module core.IModule
|
||||
if module, err = this.service.GetModule(comm.ModuleUser); err != nil {
|
||||
return
|
||||
}
|
||||
this.ModuleUser = module.(comm.IUser)
|
||||
if module, err = this.service.GetModule(comm.ModuleItems); err != nil {
|
||||
return
|
||||
}
|
||||
this.ModuleItems = module.(comm.IItems)
|
||||
if module, err = this.service.GetModule(comm.ModuleHero); err != nil {
|
||||
return
|
||||
}
|
||||
this.ModuleHero = module.(comm.IHero)
|
||||
if module, err = this.service.GetModule(comm.ModuleEquipment); err == nil {
|
||||
return
|
||||
}
|
||||
this.ModuleEquipment = module.(comm.IEquipment)
|
||||
return
|
||||
}
|
||||
|
||||
//向指定用户发送消息
|
||||
func (this *ModuleBase) SendMsgToUser(mainType, subType string, msg proto.Message, user *pb.CacheUser) (err error) {
|
||||
reply := &pb.RPCMessageReply{}
|
||||
@ -80,34 +108,11 @@ 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 //装备模块
|
||||
)
|
||||
if module, err = this.service.GetModule(comm.ModuleUser); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
user = module.(comm.IUser)
|
||||
if module, err = this.service.GetModule(comm.ModuleItems); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
items = module.(comm.IItems)
|
||||
if module, err = this.service.GetModule(comm.ModuleHero); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
hero = module.(comm.IHero)
|
||||
// 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",
|
||||
@ -116,7 +121,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
//校验消费资源是否充足
|
||||
for _, v := range res {
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
if amount = user.QueryAttributeValue(uid, v.T); amount < v.N {
|
||||
if amount = this.ModuleUser.QueryAttributeValue(uid, v.T); amount < v.N {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
return
|
||||
}
|
||||
@ -125,7 +130,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
code = pb.ErrorCode_ConfigurationException
|
||||
return
|
||||
}
|
||||
if amount = int32(items.QueryItemAmount(source, uid, int32(resID))); amount < v.N {
|
||||
if amount = int32(this.ModuleItems.QueryItemAmount(source, uid, int32(resID))); amount < v.N {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
return
|
||||
}
|
||||
@ -134,7 +139,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
code = pb.ErrorCode_ConfigurationException
|
||||
return
|
||||
}
|
||||
if amount = int32(hero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
|
||||
if amount = int32(this.ModuleHero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
|
||||
code = pb.ErrorCode_ResNoEnough
|
||||
return
|
||||
}
|
||||
@ -154,13 +159,13 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
|
||||
for _, v := range res {
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
user.AddAttributeValue(uid, v.T, -1*v.N)
|
||||
this.ModuleUser.AddAttributeValue(uid, v.T, -1*v.N)
|
||||
} else if v.A == comm.ItemType { //道具资源
|
||||
resID, _ = strconv.Atoi(v.T)
|
||||
items.AddItem(source, uid, int32(resID), -1*v.N)
|
||||
this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N)
|
||||
} else if v.A == comm.CardType { //卡片资源
|
||||
resID, _ = strconv.Atoi(v.T)
|
||||
hero.ChangeCard(uid, int32(resID), -1*v.N)
|
||||
this.ModuleHero.ChangeCard(uid, int32(resID), -1*v.N)
|
||||
}
|
||||
// } else if v.A == comm.EquipmentType {
|
||||
// resID, _ = strconv.Atoi(v.T)
|
||||
@ -174,34 +179,8 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
//发放资源
|
||||
func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) {
|
||||
var (
|
||||
module core.IModule
|
||||
err error
|
||||
resID int
|
||||
user comm.IUser //用户模块
|
||||
items comm.IItems //道具背包模块
|
||||
hero comm.IHero //英雄模块
|
||||
equipment comm.IEquipment //装备模块
|
||||
resID int
|
||||
)
|
||||
if module, err = this.service.GetModule(comm.ModuleUser); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
user = module.(comm.IUser)
|
||||
if module, err = this.service.GetModule(comm.ModuleItems); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
items = module.(comm.IItems)
|
||||
if module, err = this.service.GetModule(comm.ModuleHero); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
hero = module.(comm.IHero)
|
||||
if module, err = this.service.GetModule(comm.ModuleEquipment); err != nil {
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
equipment = module.(comm.IEquipment)
|
||||
source := &comm.ModuleCallSource{
|
||||
Module: string(this.module.GetType()),
|
||||
FuncName: "DispenseRes",
|
||||
@ -209,16 +188,16 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.Er
|
||||
}
|
||||
for _, v := range res {
|
||||
if v.A == comm.AttrType { //用户属性资源
|
||||
user.AddAttributeValue(uid, v.T, v.N)
|
||||
this.ModuleUser.AddAttributeValue(uid, v.T, v.N)
|
||||
} else if v.A == comm.ItemType { //道具资源
|
||||
resID, _ = strconv.Atoi(v.T)
|
||||
items.AddItem(source, uid, int32(resID), v.N)
|
||||
this.ModuleItems.AddItem(source, uid, int32(resID), v.N)
|
||||
} else if v.A == comm.CardType { //卡片资源
|
||||
resID, _ = strconv.Atoi(v.T)
|
||||
hero.ChangeCard(uid, int32(resID), v.N)
|
||||
this.ModuleHero.ChangeCard(uid, int32(resID), v.N)
|
||||
} else if v.A == comm.EquipmentType {
|
||||
resID, _ = strconv.Atoi(v.T)
|
||||
equipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)})
|
||||
this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)})
|
||||
}
|
||||
}
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user