From 69d8663f904f296023979062079aed2946d70d12 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 28 Jun 2022 09:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=A8=A1=E5=9D=97=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 16 ++++++++-------- modules/items/module.go | 8 ++++---- modules/mail/api_getAttachment.go | 6 +++++- modules/modulebase.go | 15 +++++++++++---- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 9c03a12d8..731be8541 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -9,7 +9,7 @@ import ( */ type ( - IModuleCallSource struct { + ModuleCallSource struct { Module string //来源模块 FuncName string //来源方法 Describe string //调用描述 @@ -22,13 +22,13 @@ type ( //道具背包接口 IItems interface { //查询用户背包物品数量 - QueryItemAmount(uId string, itemid int32) (amount uint32) + QueryItemAmount(source *ModuleCallSource, uId string, itemid int32) (amount uint32) //查询用户背包多个物品数量 - QueryItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) + QueryItemsAmount(source *ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) ///添加单个物品到背包 (可以加物品和减物品) - AddItem(uId string, itemid, addnum int32) (code pb.ErrorCode) + AddItem(source *ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) ///添加多个物品到背包 (可以加物品和减物品) - AddItems(uId string, items map[int32]int32) (code pb.ErrorCode) + AddItems(source *ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) } //英雄 @@ -59,10 +59,10 @@ type ( //武器模块 IEquipment interface { //查询服务资源数量 db id - QueryEquipment(uid string, Id int32) (equipment pb.DB_Equipment, code pb.ErrorCode) + QueryEquipment(source *ModuleCallSource, uid string, Id int32) (equipment pb.DB_Equipment, code pb.ErrorCode) //查询服务资源数量 参数武器配置id - QueryEquipmentAmount(uid string, equipmentId int32) (amount uint32) + QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32) //新加武器 - AddNewEquipments(uid string, eid int, add int32) (code pb.ErrorCode) + AddNewEquipments(source *ModuleCallSource, uid string, eid int, add int32) (code pb.ErrorCode) } ) diff --git a/modules/items/module.go b/modules/items/module.go index 965ff2156..772acbc45 100644 --- a/modules/items/module.go +++ b/modules/items/module.go @@ -48,7 +48,7 @@ func (this *Items) OnInstallComp() { //IPack------------------------------------------------------------------------------------------------------------------------------- ///查询用户背包物品数量 -func (this *Items) QueryUserItemAmount(uId string, itemid int32) (amount uint32) { +func (this *Items) QueryItemAmount(source *comm.ModuleCallSource, uId string, itemid int32) (amount uint32) { defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount) amount = 0 if result := this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid); result != nil && len(result) > 0 { @@ -58,13 +58,13 @@ func (this *Items) QueryUserItemAmount(uId string, itemid int32) (amount uint32) } ///查询用户背包多个物品数量 -func (this *Items) QueryUserItemsAmount(uId string, itemid ...int32) (result map[int32]uint32) { +func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) { result = this.model_pack_comp.Pack_QueryUserPackItemsAmount(uId, itemid...) return } ///添加单个物品到背包 (可以加物品和减物品) -func (this *Items) AddItem(uId string, itemid, addnum int32) (code pb.ErrorCode) { +func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) { var err error 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 { @@ -81,7 +81,7 @@ func (this *Items) AddItem(uId string, itemid, addnum int32) (code pb.ErrorCode) } ///添加多个物品到背包 (可以加物品和减物品) -func (this *Items) AddItems(uId string, items map[int32]int32) (code pb.ErrorCode) { +func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) { var err error 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 { diff --git a/modules/mail/api_getAttachment.go b/modules/mail/api_getAttachment.go index e1a112738..ff4de88b3 100644 --- a/modules/mail/api_getAttachment.go +++ b/modules/mail/api_getAttachment.go @@ -35,7 +35,11 @@ func (this *Api_Comp) GetUserMailAttachment(session comm.IUserSession, agrs map[ for _, v := range _data { _items[int32(v.ItemId)] += int32(v.ItemCount) } - code = this.items.AddItems(mail.Uid, _items) + code = this.items.AddItems(&comm.ModuleCallSource{ + Module: string(this.module.GetType()), + FuncName: "GetUserMailAttachment", + Describe: "领取附件", + }, mail.Uid, _items) if code == pb.ErrorCode_Success { // 修改状态 this.module.db_comp.Mail_UpdateMailAttachmentState(req.ObjID) diff --git a/modules/modulebase.go b/modules/modulebase.go index c69a8c8b6..8c22c5f66 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -21,6 +21,7 @@ import ( */ type ModuleBase struct { cbase.ModuleBase + module core.IModule service base.IRPCXService } @@ -28,6 +29,7 @@ type ModuleBase struct { func (this *ModuleBase) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) + this.module = module return } @@ -102,6 +104,11 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p if module, err = this.service.GetModule(comm.SM_UserModule); err == nil { return } + source := &comm.ModuleCallSource{ + Module: string(this.module.GetType()), + FuncName: "CheckConsumeRes", + Describe: "消耗资源", + } equipment = module.(comm.IEquipment) //校验消费资源是否充足 for _, v := range res { @@ -115,7 +122,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p code = pb.ErrorCode_ConfigurationException return } - if amount = int32(items.QueryItemAmount(uid, int32(resID))); amount < v.N { + if amount = int32(items.QueryItemAmount(source, uid, int32(resID))); amount < v.N { code = pb.ErrorCode_ResNoEnough return } @@ -133,7 +140,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p code = pb.ErrorCode_ConfigurationException return } - if amount = int32(equipment.QueryEquipmentAmount(uid, int32(resID))); amount < v.N { + if amount = int32(equipment.QueryEquipmentAmount(source, uid, int32(resID))); amount < v.N { code = pb.ErrorCode_ResNoEnough return } @@ -145,13 +152,13 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p user.AddAttributeValue(uid, v.T, -1*v.N) } else if v.A == comm.ItemType { //道具资源 resID, _ = strconv.Atoi(v.T) - items.AddItem(uid, int32(resID), -1*v.N) + items.AddItem(source, uid, int32(resID), -1*v.N) } else if v.A == comm.CardType { //卡片资源 resID, _ = strconv.Atoi(v.T) hero.AddCard(uid, int32(resID), -1*v.N) } else if v.A == comm.EquipmentType { resID, _ = strconv.Atoi(v.T) - equipment.AddNewEquipments(uid, resID, -1*v.N) + equipment.AddNewEquipments(source, uid, resID, -1*v.N) } }