From 6955acb9183290db2324db41e55916abc7bd8990 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 11 Apr 2023 19:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/items/core.go | 9 +++++---- modules/items/modelitems.go | 12 ++++++++---- modules/items/module.go | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/items/core.go b/modules/items/core.go index ea4fd157a..d38ec6039 100644 --- a/modules/items/core.go +++ b/modules/items/core.go @@ -20,10 +20,11 @@ const ( ) var ( - ItemNotEnoughError = errors.New("item not enough!") //物品不足 - NoFoundGirdError = errors.New("no found gvrid!") //未找到格子 - PackGridNumUpper = errors.New("grid amount upper!") //背包格子达到上限 - GirdAmountUpper = errors.New("grid amount upper!") //格子容量达到上限 + NoFoundItemConfig = errors.New("no found itemconfig!") //道具配置未找到 + ItemNotEnoughError = errors.New("item not enough!") //物品不足 + NoFoundGirdError = errors.New("no found gvrid!") //未找到格子 + PackGridNumUpper = errors.New("grid amount upper!") //背包格子达到上限 + GirdAmountUpper = errors.New("grid amount upper!") //格子容量达到上限 ) //随机权重宝箱 diff --git a/modules/items/modelitems.go b/modules/items/modelitems.go index d7ae75bcc..1b517bda3 100644 --- a/modules/items/modelitems.go +++ b/modules/items/modelitems.go @@ -228,7 +228,9 @@ func (this *ModelItemsComp) AddItemToUserPack(uId string, itemId string, addnum return } change = make([]*pb.DB_UserItemData, 0) - add, update, del, leftnum = this.addItemToUserPack(uId, itmes, itemId, addnum) + if add, update, del, leftnum, err = this.addItemToUserPack(uId, itmes, itemId, addnum); err != nil { + return + } if leftnum < 0 { err = ItemNotEnoughError return @@ -275,7 +277,9 @@ func (this *ModelItemsComp) AddItemsToUserPack(uId string, items map[string]int3 } change = make([]*pb.DB_UserItemData, 0) for k, v := range items { - add, update, del, leftnum = this.addItemToUserPack(uId, itmes, k, v) + if add, update, del, leftnum, err = this.addItemToUserPack(uId, itmes, k, v); err != nil { + return + } if leftnum < 0 { err = ItemNotEnoughError return @@ -352,9 +356,8 @@ func (this *ModelItemsComp) AddItemToUserPackByGrid(uId string, gridid string, a } ///添加移除物品到用户背包 -func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserItemData, itemId string, addnum int32) (add, update, del []*pb.DB_UserItemData, leftnum int64) { +func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserItemData, itemId string, addnum int32) (add, update, del []*pb.DB_UserItemData, leftnum int64, err error) { var ( - err error conf *cfg.GameItemData num int64 isNew bool @@ -364,6 +367,7 @@ func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserIte } if conf, err = this.module.configure.GetItemConfigure(itemId); err != nil { this.module.Errorln(err) + err = NoFoundItemConfig return } if conf.UpperLimit == 0 { diff --git a/modules/items/module.go b/modules/items/module.go index 29bb9ebdd..24f77f1f0 100644 --- a/modules/items/module.go +++ b/modules/items/module.go @@ -148,6 +148,8 @@ func (this *Items) AddItems(session comm.IUserSession, items map[string]int32, b code = pb.ErrorCode_ItemsNoEnough } else if err == PackGridNumUpper { code = pb.ErrorCode_ItemsGridNumUpper + } else if err == NoFoundItemConfig { + code = pb.ErrorCode_ConfigNoFound } else { code = pb.ErrorCode_Unknown } @@ -192,7 +194,6 @@ func (this *Items) RecoverTicket(session comm.IUserSession) (code pb.ErrorCode) //Evens-------------------------------------------------------------------------------------------------------------------------------- //推送道具变化消息 func (this *Items) itemsChangePush(session comm.IUserSession, items []*pb.DB_UserItemData) (err error) { - session.SendMsg(string(this.GetType()), "change", &pb.ItemsChangePush{Grids: items}) return }