道具索引id修改为字符串
This commit is contained in:
parent
68f51d0c5d
commit
a0884972d3
|
|
@ -612,6 +612,7 @@ const (
|
|||
ItemTypeChange = 17 // 兑换话费
|
||||
ItemTypeSkinChip = 22 // 皮肤碎片
|
||||
ItemTypeDoll = 26 //娃娃兑换
|
||||
ItemTypeSeasonPicket = 28 //赛季凭证
|
||||
)
|
||||
|
||||
func GetKeyNoviceGameId(gameId int) string {
|
||||
|
|
@ -902,3 +903,7 @@ var GuideIdToGainWay = map[int]int{
|
|||
func GetKeyGameDif(gamedif string) string {
|
||||
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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package svc
|
|||
import (
|
||||
"errors"
|
||||
"net/rpc"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/globalsign/mgo"
|
||||
|
|
@ -117,7 +118,12 @@ func (svc *BagSvc) AddBagItem(args *model.BagInfo, ret *bool) error {
|
|||
item.ItemNum += v.ItemNum
|
||||
}
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ type Item struct {
|
|||
}
|
||||
|
||||
type BagInfo struct {
|
||||
BagId bson.ObjectId `bson:"_id"`
|
||||
SnId int32 //玩家账号直接在这里生成
|
||||
Platform string //平台
|
||||
BagItem map[int32]*Item //背包数据 key为itemId
|
||||
Ts int64 // 最后数据更新纳秒时间戳
|
||||
BagId bson.ObjectId `bson:"_id"`
|
||||
SnId int32 //玩家账号直接在这里生成
|
||||
Platform string //平台
|
||||
BagItem map[string]*Item //背包数据 key为itemId
|
||||
Ts int64 // 最后数据更新纳秒时间戳
|
||||
|
||||
// 临时参数,不保存数据库
|
||||
GainWay int32 `bson:"-"`
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/globalsign/mgo/bson"
|
||||
|
|
@ -166,10 +167,10 @@ type Item struct {
|
|||
}
|
||||
|
||||
type BagInfo struct {
|
||||
SnId int32 //玩家id
|
||||
Platform string //平台id
|
||||
BagItem map[int32]*Item //背包数据 key为itemId
|
||||
Ts int64 //更新时间戳
|
||||
SnId int32 //玩家id
|
||||
Platform string //平台id
|
||||
BagItem map[string]*Item //背包数据 key为itemId
|
||||
Ts int64 //更新时间戳
|
||||
|
||||
// 临时携带参数
|
||||
dirty bool `bson:"-"` //是否需要更新数据库
|
||||
|
|
@ -180,7 +181,7 @@ func NewBagInfo(platform string, snid int32) *BagInfo {
|
|||
return &BagInfo{
|
||||
SnId: snid,
|
||||
Platform: platform,
|
||||
BagItem: make(map[int32]*Item),
|
||||
BagItem: make(map[string]*Item),
|
||||
Ts: time.Now().Unix(),
|
||||
dirty: true,
|
||||
LogId: "",
|
||||
|
|
@ -346,15 +347,16 @@ func (this *BagMgr) CallbackAfter(ret *internal.PlayerLoadReplay) {
|
|||
}
|
||||
if v.Offline == 0 {
|
||||
// 在线数据恢复
|
||||
tempItemId := strconv.Itoa(int(v.ItemId))
|
||||
logger.Logger.Tracef("道具恢复 SnId:%v Item:%+v", p.SnId, *v)
|
||||
if _, ok := bagInfo.BagItem[v.ItemId]; !ok {
|
||||
bagInfo.BagItem[v.ItemId] = &Item{
|
||||
if _, ok := bagInfo.BagItem[tempItemId]; !ok {
|
||||
bagInfo.BagItem[tempItemId] = &Item{
|
||||
ItemId: v.ItemId,
|
||||
ItemNum: 0,
|
||||
ObtainTime: v.CreateTs,
|
||||
}
|
||||
}
|
||||
bagInfo.BagItem[v.ItemId].ItemNum += num
|
||||
bagInfo.BagItem[tempItemId].ItemNum += num
|
||||
changeItems[v.ItemId] = struct{}{}
|
||||
} else {
|
||||
// 离线时的变更
|
||||
|
|
@ -393,10 +395,11 @@ func (this *BagMgr) Save(platform string, snid int32, isSync, force bool) {
|
|||
SnId: bagInfo.SnId,
|
||||
Platform: bagInfo.Platform,
|
||||
Ts: bagInfo.Ts,
|
||||
BagItem: make(map[int32]*model.Item),
|
||||
BagItem: make(map[string]*model.Item),
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
|
@ -472,7 +475,8 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item {
|
|||
default:
|
||||
if bagItem, ok := this.PlayerBag[snid]; ok {
|
||||
if bagItem != nil {
|
||||
item = bagItem.BagItem[itemId]
|
||||
strItemId := strconv.Itoa(int(itemId))
|
||||
item = bagItem.BagItem[strItemId]
|
||||
if item != nil {
|
||||
f()
|
||||
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) {
|
||||
if v, exist := this.PlayerBag[snid]; exist {
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
|
|
@ -512,7 +520,11 @@ func (this *BagMgr) GetBagInfo(snid int32) *BagInfo {
|
|||
ret.dirty = v.dirty
|
||||
ret.LogId = v.LogId
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
return items, bag.OpResultCode_OPRC_UseUp, false
|
||||
}
|
||||
|
|
@ -674,14 +688,34 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
|
|||
if itemData == nil {
|
||||
continue
|
||||
}
|
||||
if itm, exist := newBagInfo.BagItem[v.ItemId]; exist {
|
||||
itm.ItemNum += v.ItemNum
|
||||
} else {
|
||||
newBagInfo.BagItem[v.ItemId] = &Item{
|
||||
ItemId: v.ItemId, // 物品id
|
||||
ItemNum: v.ItemNum, // 数量
|
||||
ObtainTime: time.Now().Unix(),
|
||||
|
||||
strItemId := strconv.Itoa(int(v.ItemId))
|
||||
if itemData.Type != common.ItemTypeSeasonPicket {
|
||||
if itm, exist := newBagInfo.BagItem[strItemId]; exist {
|
||||
itm.ItemNum += v.ItemNum
|
||||
} else {
|
||||
strItemId := strconv.Itoa(int(v.ItemId))
|
||||
newBagInfo.BagItem[strItemId] = &Item{
|
||||
ItemId: v.ItemId, // 物品id
|
||||
ItemNum: v.ItemNum, // 数量
|
||||
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
|
||||
|
|
@ -794,7 +828,7 @@ func (this *BagMgr) AddItemsOffline(param *model.AddItemParam, callback func(err
|
|||
newBagInfo := &model.BagInfo{
|
||||
SnId: findPlayer.SnId,
|
||||
Platform: findPlayer.Platform,
|
||||
BagItem: make(map[int32]*model.Item),
|
||||
BagItem: make(map[string]*model.Item),
|
||||
GainWay: param.GainWay,
|
||||
}
|
||||
for _, v := range param.Change {
|
||||
|
|
@ -805,7 +839,9 @@ func (this *BagMgr) AddItemsOffline(param *model.AddItemParam, callback func(err
|
|||
if itemData == nil {
|
||||
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 {
|
||||
logger.Logger.Errorf("离线保存道具变更错误 %v", err)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"mongo.games.com/game/protocol/gamehall"
|
||||
"mongo.games.com/game/protocol/pets"
|
||||
"mongo.games.com/game/srvdata"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -282,7 +283,8 @@ func (this *ModelMgr) GetSkinInfo(p *Player, id int32) *pets.SkinInfo {
|
|||
}
|
||||
for _, v := range cost {
|
||||
if bag != nil {
|
||||
info := bag.BagItem[v.GetId()]
|
||||
strItemId := strconv.Itoa(int(v.GetId()))
|
||||
info := bag.BagItem[strItemId]
|
||||
if info != nil {
|
||||
have = append(have, &pets.Item{
|
||||
Id: v.GetId(),
|
||||
|
|
|
|||
|
|
@ -1729,14 +1729,16 @@ func (this *Player) ResetPermit() {
|
|||
// 清理数据
|
||||
bag := BagMgrSingleton.GetBagInfo(this.SnId)
|
||||
if bag != nil {
|
||||
if bag.BagItem[common.ItemIDPermit] != nil {
|
||||
strItemId := strconv.Itoa(common.ItemIDPermit)
|
||||
|
||||
if bag.BagItem[strItemId] != nil {
|
||||
BagMgrSingleton.AddItems(&model.AddItemParam{
|
||||
Platform: this.Platform,
|
||||
SnId: this.SnId,
|
||||
Change: []*model.Item{
|
||||
{
|
||||
ItemId: common.ItemIDPermit,
|
||||
ItemNum: -bag.BagItem[common.ItemIDPermit].ItemNum,
|
||||
ItemNum: -bag.BagItem[strItemId].ItemNum,
|
||||
},
|
||||
},
|
||||
GainWay: common.GainWayPermitReset,
|
||||
|
|
@ -1748,7 +1750,7 @@ func (this *Player) ResetPermit() {
|
|||
if model.GameParamData.PermitInitScore > 0 {
|
||||
bagInfo := BagMgrSingleton.GetBagInfo(this.SnId)
|
||||
if bagInfo != nil {
|
||||
bagInfo.BagItem[common.ItemIDPermit] = &Item{
|
||||
bagInfo.BagItem[strItemId] = &Item{
|
||||
ItemId: common.ItemIDPermit,
|
||||
ItemNum: model.GameParamData.PermitInitScore,
|
||||
ObtainTime: time.Now().Unix(),
|
||||
|
|
|
|||
|
|
@ -1069,8 +1069,9 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
|
|||
// 扣道具
|
||||
f := func() {
|
||||
//扣除V卡
|
||||
strItemId := strconv.Itoa(common.ItemIDVCard)
|
||||
if info.Price > 0 {
|
||||
item := bagInfo.BagItem[common.ItemIDVCard]
|
||||
item := bagInfo.BagItem[strItemId]
|
||||
n := int64(info.Price * param.Num)
|
||||
if item != nil && item.ItemNum >= n {
|
||||
itemInfo = append(itemInfo, &model.Item{
|
||||
|
|
@ -1084,7 +1085,7 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
|
|||
}
|
||||
//扣除金券
|
||||
if info.JPrice > 0 {
|
||||
item := bagInfo.BagItem[common.ItemIDJCard]
|
||||
item := bagInfo.BagItem[strItemId]
|
||||
n := int64(info.JPrice * param.Num)
|
||||
if item != nil && item.ItemNum >= n {
|
||||
itemInfo = append(itemInfo, &model.Item{
|
||||
|
|
@ -1099,7 +1100,7 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
|
|||
|
||||
if info.DPrice > 0 {
|
||||
n := int64(info.DPrice * param.Num)
|
||||
item := bagInfo.BagItem[common.ItemDollCard]
|
||||
item := bagInfo.BagItem[strItemId]
|
||||
if item != nil && item.ItemNum >= n {
|
||||
itemInfo = append(itemInfo, &model.Item{
|
||||
ItemId: common.ItemDollCard,
|
||||
|
|
@ -1154,10 +1155,11 @@ func (this *ShopMgr) Exchange(param *ExchangeParam) {
|
|||
bagInfo = &model.BagInfo{
|
||||
SnId: bagOnline.SnId,
|
||||
Platform: bagOnline.Platform,
|
||||
BagItem: make(map[int32]*model.Item),
|
||||
BagItem: make(map[string]*model.Item),
|
||||
}
|
||||
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,
|
||||
ItemNum: v.ItemNum,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue