From 5755b8101a55c5f474dc28b1f6348aa967cf5a23 Mon Sep 17 00:00:00 2001 From: liwei Date: Fri, 22 Jul 2022 22:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=89=A9=E5=93=81=E5=8F=A0?= =?UTF-8?q?=E5=8A=A0-1=20=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/items/modelitems.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/items/modelitems.go b/modules/items/modelitems.go index 40e2750b0..604ed5c91 100644 --- a/modules/items/modelitems.go +++ b/modules/items/modelitems.go @@ -236,7 +236,7 @@ func (this *ModelItemsComp) AddItemToUserPackByGrid(uId string, gridid string, i if num < 0 { err = ItemNotEnoughError } else { - if num > int64(conf.UpperLimit) { + if conf.UpperLimit > 0 && num > int64(conf.UpperLimit) { err = GirdAmountUpper return } else { @@ -261,6 +261,10 @@ func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserIte if conf, err = this.module.configure.GetItemConfigure(itemId); err != nil { return } + if conf.UpperLimit == 0 { + err = fmt.Errorf("item UpperLimit is 0") + return + } isNew = true leftnum = int64(addnum) add = make([]*pb.DB_UserItemData, 0) @@ -281,17 +285,23 @@ func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserIte update = append(update, v) break } else if num > 0 && num > int64(v.Amount) { - if num <= int64(conf.UpperLimit) { + if conf.UpperLimit > 0 { + if num <= int64(conf.UpperLimit) { + leftnum = 0 + v.Amount = uint32(num) + update = append(update, v) + break + } else { + if v.Amount < uint32(conf.UpperLimit) { + leftnum = int64(num - int64(conf.UpperLimit)) + v.Amount = uint32(conf.UpperLimit) + update = append(update, v) + } + } + } else { leftnum = 0 v.Amount = uint32(num) update = append(update, v) - break - } else { - if v.Amount < uint32(conf.UpperLimit) { - leftnum = int64(num - int64(conf.UpperLimit)) - v.Amount = uint32(conf.UpperLimit) - update = append(update, v) - } } } else if num == 0 { leftnum = 0 @@ -306,7 +316,7 @@ func (this *ModelItemsComp) addItemToUserPack(uid string, items []*pb.DB_UserIte if leftnum > 0 { //还没有放完 寻找空的格子填充 index := int32(len(items)) for leftnum > 0 { //需要补充格子 - if leftnum <= int64(conf.UpperLimit) { + if conf.UpperLimit < 0 || (conf.UpperLimit > 0 && leftnum <= int64(conf.UpperLimit)) { grid := &pb.DB_UserItemData{ GridId: primitive.NewObjectID().Hex(), UId: uid,