From 64bcbb896e647d565eb2b72bf25ace8b1a93898c Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Mon, 20 May 2024 10:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=81=93=E5=85=B7=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0=E6=89=A3=E9=99=A4=E9=81=93=E5=85=B7?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/bagmgr.go | 24 ++++++++++++++++++++++-- worldsrv/shopmgr.go | 5 +++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/worldsrv/bagmgr.go b/worldsrv/bagmgr.go index 8ad2cb0..ed64942 100644 --- a/worldsrv/bagmgr.go +++ b/worldsrv/bagmgr.go @@ -2,6 +2,7 @@ package main import ( "errors" + "math" "mongo.games.com/game/worldsrv/internal" "strconv" "time" @@ -204,6 +205,23 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int } var code = bag.OpResultCode_OPRC_Sucess + //检查道具数量 + for _, v := range items { + if v == nil || v.ItemNum == 0 { + continue + } + + item := srvdata.PBDB_GameItemMgr.GetData(v.ItemId) + if item == nil { + code = bag.OpResultCode_OPRC_IdErr + return newBagInfo, code, false + } + if v.ItemNum < 0 && item.Num < int64(math.Abs(float64(v.ItemNum))) { + code = bag.OpResultCode_OPRC_UseUp + return newBagInfo, code, false + } + } + for _, v := range items { if v == nil || v.ItemNum == 0 { continue @@ -214,7 +232,6 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int code = bag.OpResultCode_OPRC_IdErr continue } - if itm, exist := newBagInfo.BagItem[v.ItemId]; exist { if itm.ItemNum+v.ItemNum < 0 { code = bag.OpResultCode_OPRC_IdErr @@ -271,8 +288,11 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int this.PlayerBag[p.SnId] = newBagInfo this.SyncBagData(p.SnId, changeItems...) } - + if code != bag.OpResultCode_OPRC_Sucess { + return newBagInfo, code, false + } return newBagInfo, code, true + } func (this *BagMgr) AddItem(p *Player, itemId, itemNum int64, add int64, gainWay int32, operator, remark string, diff --git a/worldsrv/shopmgr.go b/worldsrv/shopmgr.go index 953c281..9ec8e34 100644 --- a/worldsrv/shopmgr.go +++ b/worldsrv/shopmgr.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "math/rand" + "mongo.games.com/game/protocol/bag" "slices" "time" @@ -779,9 +780,9 @@ func (this *ShopMgr) Exchange(p *Player, goodsId int32, username, mobile, commen ItemId: VCard, ItemNum: int64(info.Price * num), } - _, _, isF := BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWay_Exchange, + _, code, _ := BagMgrSingleton.AddItem(p, int64(item.ItemId), -item.ItemNum, 0, common.GainWay_Exchange, "sys", fmt.Sprintf("兑换扣除%v", item.ItemId), 0, 0, false) - if !isF { // 扣掉V卡 + if code != bag.OpResultCode_OPRC_Sucess { // 扣掉V卡 p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack) return false }