添加道具接口增加扣除道具检测
This commit is contained in:
parent
a9aeb01e99
commit
64bcbb896e
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
"mongo.games.com/game/worldsrv/internal"
|
"mongo.games.com/game/worldsrv/internal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -204,6 +205,23 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
|
||||||
}
|
}
|
||||||
|
|
||||||
var code = bag.OpResultCode_OPRC_Sucess
|
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 {
|
for _, v := range items {
|
||||||
if v == nil || v.ItemNum == 0 {
|
if v == nil || v.ItemNum == 0 {
|
||||||
continue
|
continue
|
||||||
|
|
@ -214,7 +232,6 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
|
||||||
code = bag.OpResultCode_OPRC_IdErr
|
code = bag.OpResultCode_OPRC_IdErr
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if itm, exist := newBagInfo.BagItem[v.ItemId]; exist {
|
if itm, exist := newBagInfo.BagItem[v.ItemId]; exist {
|
||||||
if itm.ItemNum+v.ItemNum < 0 {
|
if itm.ItemNum+v.ItemNum < 0 {
|
||||||
code = bag.OpResultCode_OPRC_IdErr
|
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.PlayerBag[p.SnId] = newBagInfo
|
||||||
this.SyncBagData(p.SnId, changeItems...)
|
this.SyncBagData(p.SnId, changeItems...)
|
||||||
}
|
}
|
||||||
|
if code != bag.OpResultCode_OPRC_Sucess {
|
||||||
|
return newBagInfo, code, false
|
||||||
|
}
|
||||||
return newBagInfo, code, true
|
return newBagInfo, code, true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BagMgr) AddItem(p *Player, itemId, itemNum int64, add int64, gainWay int32, operator, remark string,
|
func (this *BagMgr) AddItem(p *Player, itemId, itemNum int64, add int64, gainWay int32, operator, remark string,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"mongo.games.com/game/protocol/bag"
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -779,9 +780,9 @@ func (this *ShopMgr) Exchange(p *Player, goodsId int32, username, mobile, commen
|
||||||
ItemId: VCard,
|
ItemId: VCard,
|
||||||
ItemNum: int64(info.Price * num),
|
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)
|
"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)
|
p.SendToClient(int(shop.SPacketID_PACKET_SC_SHOP_EXCHANGE), pack)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue