添加道具接口增加扣除道具检测

This commit is contained in:
by 2024-05-20 10:09:48 +08:00
parent a9aeb01e99
commit 64bcbb896e
2 changed files with 25 additions and 4 deletions

View File

@ -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,

View File

@ -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
}