道具索引id修改为字符串

This commit is contained in:
DESKTOP-45ANQ2C\unis 2024-12-23 18:10:37 +08:00
parent 68f51d0c5d
commit a0884972d3
7 changed files with 91 additions and 38 deletions

View File

@ -612,6 +612,7 @@ const (
ItemTypeChange = 17 // 兑换话费 ItemTypeChange = 17 // 兑换话费
ItemTypeSkinChip = 22 // 皮肤碎片 ItemTypeSkinChip = 22 // 皮肤碎片
ItemTypeDoll = 26 //娃娃兑换 ItemTypeDoll = 26 //娃娃兑换
ItemTypeSeasonPicket = 28 //赛季凭证
) )
func GetKeyNoviceGameId(gameId int) string { func GetKeyNoviceGameId(gameId int) string {
@ -902,3 +903,7 @@ var GuideIdToGainWay = map[int]int{
func GetKeyGameDif(gamedif string) string { func GetKeyGameDif(gamedif string) string {
return fmt.Sprintf("gamedif-%v", gamedif) return fmt.Sprintf("gamedif-%v", gamedif)
} }
func GetItemUniqueId(itemId int32, snid int32) string {
return fmt.Sprintf("%v.%v.%v.%v", itemId, snid, time.Now().Unix(), RandInt(1, 10000))
}

View File

@ -3,6 +3,7 @@ package svc
import ( import (
"errors" "errors"
"net/rpc" "net/rpc"
"strconv"
"time" "time"
"github.com/globalsign/mgo" "github.com/globalsign/mgo"
@ -117,7 +118,12 @@ func (svc *BagSvc) AddBagItem(args *model.BagInfo, ret *bool) error {
item.ItemNum += v.ItemNum item.ItemNum += v.ItemNum
} }
// v卡返还 // v卡返还
if id == common.ItemIDVCard && args.GainWay == common.GainWay_Exchange && v.ItemNum > 0 { tempId, err := strconv.Atoi(id)
if err != nil {
continue
}
if tempId == common.ItemIDVCard && args.GainWay == common.GainWay_Exchange && v.ItemNum > 0 {
vCard = v.ItemNum vCard = v.ItemNum
} }
} }

View File

@ -18,7 +18,7 @@ type BagInfo struct {
BagId bson.ObjectId `bson:"_id"` BagId bson.ObjectId `bson:"_id"`
SnId int32 //玩家账号直接在这里生成 SnId int32 //玩家账号直接在这里生成
Platform string //平台 Platform string //平台
BagItem map[int32]*Item //背包数据 key为itemId BagItem map[string]*Item //背包数据 key为itemId
Ts int64 // 最后数据更新纳秒时间戳 Ts int64 // 最后数据更新纳秒时间戳
// 临时参数,不保存数据库 // 临时参数,不保存数据库

View File

@ -3,6 +3,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"strconv"
"time" "time"
"github.com/globalsign/mgo/bson" "github.com/globalsign/mgo/bson"
@ -168,7 +169,7 @@ type Item struct {
type BagInfo struct { type BagInfo struct {
SnId int32 //玩家id SnId int32 //玩家id
Platform string //平台id Platform string //平台id
BagItem map[int32]*Item //背包数据 key为itemId BagItem map[string]*Item //背包数据 key为itemId
Ts int64 //更新时间戳 Ts int64 //更新时间戳
// 临时携带参数 // 临时携带参数
@ -180,7 +181,7 @@ func NewBagInfo(platform string, snid int32) *BagInfo {
return &BagInfo{ return &BagInfo{
SnId: snid, SnId: snid,
Platform: platform, Platform: platform,
BagItem: make(map[int32]*Item), BagItem: make(map[string]*Item),
Ts: time.Now().Unix(), Ts: time.Now().Unix(),
dirty: true, dirty: true,
LogId: "", LogId: "",
@ -346,15 +347,16 @@ func (this *BagMgr) CallbackAfter(ret *internal.PlayerLoadReplay) {
} }
if v.Offline == 0 { if v.Offline == 0 {
// 在线数据恢复 // 在线数据恢复
tempItemId := strconv.Itoa(int(v.ItemId))
logger.Logger.Tracef("道具恢复 SnId:%v Item:%+v", p.SnId, *v) logger.Logger.Tracef("道具恢复 SnId:%v Item:%+v", p.SnId, *v)
if _, ok := bagInfo.BagItem[v.ItemId]; !ok { if _, ok := bagInfo.BagItem[tempItemId]; !ok {
bagInfo.BagItem[v.ItemId] = &Item{ bagInfo.BagItem[tempItemId] = &Item{
ItemId: v.ItemId, ItemId: v.ItemId,
ItemNum: 0, ItemNum: 0,
ObtainTime: v.CreateTs, ObtainTime: v.CreateTs,
} }
} }
bagInfo.BagItem[v.ItemId].ItemNum += num bagInfo.BagItem[tempItemId].ItemNum += num
changeItems[v.ItemId] = struct{}{} changeItems[v.ItemId] = struct{}{}
} else { } else {
// 离线时的变更 // 离线时的变更
@ -393,10 +395,11 @@ func (this *BagMgr) Save(platform string, snid int32, isSync, force bool) {
SnId: bagInfo.SnId, SnId: bagInfo.SnId,
Platform: bagInfo.Platform, Platform: bagInfo.Platform,
Ts: bagInfo.Ts, Ts: bagInfo.Ts,
BagItem: make(map[int32]*model.Item), BagItem: make(map[string]*model.Item),
} }
for _, v := range bagInfo.BagItem { for _, v := range bagInfo.BagItem {
newBagInfo.BagItem[v.ItemId] = &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum, ObtainTime: v.ObtainTime} strItemId := strconv.Itoa(int(v.ItemId))
newBagInfo.BagItem[strItemId] = &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum, ObtainTime: v.ObtainTime}
} }
err = model.UpBagItem(newBagInfo) err = model.UpBagItem(newBagInfo)
} }
@ -472,7 +475,8 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item {
default: default:
if bagItem, ok := this.PlayerBag[snid]; ok { if bagItem, ok := this.PlayerBag[snid]; ok {
if bagItem != nil { if bagItem != nil {
item = bagItem.BagItem[itemId] strItemId := strconv.Itoa(int(itemId))
item = bagItem.BagItem[strItemId]
if item != nil { if item != nil {
f() f()
return item return item
@ -488,7 +492,11 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item {
func (this *BagMgr) Range(snid int32, fn func(item *Item) bool) { func (this *BagMgr) Range(snid int32, fn func(item *Item) bool) {
if v, exist := this.PlayerBag[snid]; exist { if v, exist := this.PlayerBag[snid]; exist {
for k := range v.BagItem { for k := range v.BagItem {
e := this.GetItem(snid, k) itemId, err := strconv.Atoi(k)
if err != nil {
continue
}
e := this.GetItem(snid, int32(itemId))
if e == nil { if e == nil {
continue continue
} }
@ -512,7 +520,11 @@ func (this *BagMgr) GetBagInfo(snid int32) *BagInfo {
ret.dirty = v.dirty ret.dirty = v.dirty
ret.LogId = v.LogId ret.LogId = v.LogId
for k := range v.BagItem { for k := range v.BagItem {
ret.BagItem[k] = this.GetItem(snid, k) itemId, err := strconv.Atoi(k)
if err != nil {
continue
}
ret.BagItem[k] = this.GetItem(snid, int32(itemId))
} }
} else { } else {
this.PlayerBag[snid] = NewBagInfo(p.Platform, p.SnId) this.PlayerBag[snid] = NewBagInfo(p.Platform, p.SnId)
@ -575,7 +587,9 @@ func (this *BagMgr) AddItemCheck(param *model.AddItemParam) ([]*model.Item, bag.
if item == nil { if item == nil {
return items, bag.OpResultCode_OPRC_IdErr, false return items, bag.OpResultCode_OPRC_IdErr, false
} }
if itm, exist := newBagInfo.BagItem[v.ItemId]; exist {
strItemId := strconv.Itoa(int(v.ItemId))
if itm, exist := newBagInfo.BagItem[strItemId]; exist {
if v.ItemNum < 0 && itm.ItemNum < -v.ItemNum { if v.ItemNum < 0 && itm.ItemNum < -v.ItemNum {
return items, bag.OpResultCode_OPRC_UseUp, false return items, bag.OpResultCode_OPRC_UseUp, false
} }
@ -674,15 +688,35 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
if itemData == nil { if itemData == nil {
continue continue
} }
if itm, exist := newBagInfo.BagItem[v.ItemId]; exist {
strItemId := strconv.Itoa(int(v.ItemId))
if itemData.Type != common.ItemTypeSeasonPicket {
if itm, exist := newBagInfo.BagItem[strItemId]; exist {
itm.ItemNum += v.ItemNum itm.ItemNum += v.ItemNum
} else { } else {
newBagInfo.BagItem[v.ItemId] = &Item{ strItemId := strconv.Itoa(int(v.ItemId))
newBagInfo.BagItem[strItemId] = &Item{
ItemId: v.ItemId, // 物品id ItemId: v.ItemId, // 物品id
ItemNum: v.ItemNum, // 数量 ItemNum: v.ItemNum, // 数量
ObtainTime: time.Now().Unix(), ObtainTime: time.Now().Unix(),
} }
} }
} else {
if v.ItemNum > 0 {
itemUniqueId := common.GetItemUniqueId(v.ItemId, param.SnId)
if _, exist := newBagInfo.BagItem[itemUniqueId]; !exist {
newBagInfo.BagItem[itemUniqueId] = &Item{
ItemId: v.ItemId, // 物品id
ItemNum: v.ItemNum, // 数量
ObtainTime: time.Now().Unix(),
}
}
} else if v.ItemNum < 0 {
// 找到这类道具减一个
}
}
num := v.ItemNum num := v.ItemNum
logType := ItemObtain logType := ItemObtain
@ -794,7 +828,7 @@ func (this *BagMgr) AddItemsOffline(param *model.AddItemParam, callback func(err
newBagInfo := &model.BagInfo{ newBagInfo := &model.BagInfo{
SnId: findPlayer.SnId, SnId: findPlayer.SnId,
Platform: findPlayer.Platform, Platform: findPlayer.Platform,
BagItem: make(map[int32]*model.Item), BagItem: make(map[string]*model.Item),
GainWay: param.GainWay, GainWay: param.GainWay,
} }
for _, v := range param.Change { for _, v := range param.Change {
@ -805,7 +839,9 @@ func (this *BagMgr) AddItemsOffline(param *model.AddItemParam, callback func(err
if itemData == nil { if itemData == nil {
continue continue
} }
newBagInfo.BagItem[v.ItemId] = &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum}
strItemId := strconv.Itoa(int(v.ItemId))
newBagInfo.BagItem[strItemId] = &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum}
} }
if err := model.SaveDBBagItem(newBagInfo); err != nil { if err := model.SaveDBBagItem(newBagInfo); err != nil {
logger.Logger.Errorf("离线保存道具变更错误 %v", err) logger.Logger.Errorf("离线保存道具变更错误 %v", err)

View File

@ -6,6 +6,7 @@ import (
"mongo.games.com/game/protocol/gamehall" "mongo.games.com/game/protocol/gamehall"
"mongo.games.com/game/protocol/pets" "mongo.games.com/game/protocol/pets"
"mongo.games.com/game/srvdata" "mongo.games.com/game/srvdata"
"strconv"
) )
const ( const (
@ -282,7 +283,8 @@ func (this *ModelMgr) GetSkinInfo(p *Player, id int32) *pets.SkinInfo {
} }
for _, v := range cost { for _, v := range cost {
if bag != nil { if bag != nil {
info := bag.BagItem[v.GetId()] strItemId := strconv.Itoa(int(v.GetId()))
info := bag.BagItem[strItemId]
if info != nil { if info != nil {
have = append(have, &pets.Item{ have = append(have, &pets.Item{
Id: v.GetId(), Id: v.GetId(),

View File

@ -1729,14 +1729,16 @@ func (this *Player) ResetPermit() {
// 清理数据 // 清理数据
bag := BagMgrSingleton.GetBagInfo(this.SnId) bag := BagMgrSingleton.GetBagInfo(this.SnId)
if bag != nil { if bag != nil {
if bag.BagItem[common.ItemIDPermit] != nil { strItemId := strconv.Itoa(common.ItemIDPermit)
if bag.BagItem[strItemId] != nil {
BagMgrSingleton.AddItems(&model.AddItemParam{ BagMgrSingleton.AddItems(&model.AddItemParam{
Platform: this.Platform, Platform: this.Platform,
SnId: this.SnId, SnId: this.SnId,
Change: []*model.Item{ Change: []*model.Item{
{ {
ItemId: common.ItemIDPermit, ItemId: common.ItemIDPermit,
ItemNum: -bag.BagItem[common.ItemIDPermit].ItemNum, ItemNum: -bag.BagItem[strItemId].ItemNum,
}, },
}, },
GainWay: common.GainWayPermitReset, GainWay: common.GainWayPermitReset,
@ -1748,7 +1750,7 @@ func (this *Player) ResetPermit() {
if model.GameParamData.PermitInitScore > 0 { if model.GameParamData.PermitInitScore > 0 {
bagInfo := BagMgrSingleton.GetBagInfo(this.SnId) bagInfo := BagMgrSingleton.GetBagInfo(this.SnId)
if bagInfo != nil { if bagInfo != nil {
bagInfo.BagItem[common.ItemIDPermit] = &Item{ bagInfo.BagItem[strItemId] = &Item{
ItemId: common.ItemIDPermit, ItemId: common.ItemIDPermit,
ItemNum: model.GameParamData.PermitInitScore, ItemNum: model.GameParamData.PermitInitScore,
ObtainTime: time.Now().Unix(), ObtainTime: time.Now().Unix(),

View File

@ -1069,8 +1069,9 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
// 扣道具 // 扣道具
f := func() { f := func() {
//扣除V卡 //扣除V卡
strItemId := strconv.Itoa(common.ItemIDVCard)
if info.Price > 0 { if info.Price > 0 {
item := bagInfo.BagItem[common.ItemIDVCard] item := bagInfo.BagItem[strItemId]
n := int64(info.Price * param.Num) n := int64(info.Price * param.Num)
if item != nil && item.ItemNum >= n { if item != nil && item.ItemNum >= n {
itemInfo = append(itemInfo, &model.Item{ itemInfo = append(itemInfo, &model.Item{
@ -1084,7 +1085,7 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
} }
//扣除金券 //扣除金券
if info.JPrice > 0 { if info.JPrice > 0 {
item := bagInfo.BagItem[common.ItemIDJCard] item := bagInfo.BagItem[strItemId]
n := int64(info.JPrice * param.Num) n := int64(info.JPrice * param.Num)
if item != nil && item.ItemNum >= n { if item != nil && item.ItemNum >= n {
itemInfo = append(itemInfo, &model.Item{ itemInfo = append(itemInfo, &model.Item{
@ -1099,7 +1100,7 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
if info.DPrice > 0 { if info.DPrice > 0 {
n := int64(info.DPrice * param.Num) n := int64(info.DPrice * param.Num)
item := bagInfo.BagItem[common.ItemDollCard] item := bagInfo.BagItem[strItemId]
if item != nil && item.ItemNum >= n { if item != nil && item.ItemNum >= n {
itemInfo = append(itemInfo, &model.Item{ itemInfo = append(itemInfo, &model.Item{
ItemId: common.ItemDollCard, ItemId: common.ItemDollCard,
@ -1154,10 +1155,11 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
bagInfo = &model.BagInfo{ bagInfo = &model.BagInfo{
SnId: bagOnline.SnId, SnId: bagOnline.SnId,
Platform: bagOnline.Platform, Platform: bagOnline.Platform,
BagItem: make(map[int32]*model.Item), BagItem: make(map[string]*model.Item),
} }
for _, v := range bagOnline.BagItem { for _, v := range bagOnline.BagItem {
bagInfo.BagItem[v.ItemId] = &model.Item{ strItemId := strconv.Itoa(int(v.ItemId))
bagInfo.BagItem[strItemId] = &model.Item{
ItemId: v.ItemId, ItemId: v.ItemId,
ItemNum: v.ItemNum, ItemNum: v.ItemNum,
} }