时限类道具功能修改
This commit is contained in:
parent
a0884972d3
commit
73b3337888
|
@ -102,7 +102,21 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
|
|||
logger.Logger.Tracef("SCUpBagInfo: %v", pack)
|
||||
}
|
||||
|
||||
itemConfig := srvdata.GameItemMgr.Get(p.Platform, msg.ItemId)
|
||||
if itemConfig == nil {
|
||||
send()
|
||||
return nil
|
||||
}
|
||||
|
||||
item := BagMgrSingleton.GetItem(p.SnId, msg.ItemId)
|
||||
if itemConfig.Type != common.ItemTypeSeasonPicket {
|
||||
// 先找一个
|
||||
strItemUnique, bFind := BagMgrSingleton.FindItemUniqueByType(p.SnId, common.ItemTypeSeasonPicket)
|
||||
if bFind {
|
||||
item = BagMgrSingleton.GetItemByUniqueId(p.SnId, strItemUnique)
|
||||
}
|
||||
}
|
||||
|
||||
if item == nil || msg.ItemNum <= 0 || item.ItemNum < int64(msg.ItemNum) || len(item.Effect) != ItemMax || p.SnId == msg.AcceptSnId {
|
||||
send()
|
||||
return nil
|
||||
|
|
|
@ -454,6 +454,7 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item {
|
|||
item := &Item{
|
||||
ItemId: itemId,
|
||||
}
|
||||
|
||||
f := func() {
|
||||
itemX := srvdata.GameItemMgr.Get(p.Platform, itemId)
|
||||
if itemX != nil {
|
||||
|
@ -488,15 +489,74 @@ func (this *BagMgr) GetItem(snid, itemId int32) *Item {
|
|||
return item
|
||||
}
|
||||
|
||||
// Range 遍历背包
|
||||
func (this *BagMgr) Range(snid int32, fn func(item *Item) bool) {
|
||||
if v, exist := this.PlayerBag[snid]; exist {
|
||||
for k := range v.BagItem {
|
||||
itemId, err := strconv.Atoi(k)
|
||||
if err != nil {
|
||||
// GetItemByUniqueId 按照唯一道具ID获取个人的指定道具信息
|
||||
func (this *BagMgr) GetItemByUniqueId(snid int32, itemUniqueIdId string) *Item {
|
||||
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
item := &Item{}
|
||||
if bagItem, ok := this.PlayerBag[snid]; ok {
|
||||
if bagItem != nil {
|
||||
findItem := bagItem.BagItem[itemUniqueIdId]
|
||||
if findItem == nil {
|
||||
return item
|
||||
}
|
||||
itemX := srvdata.GameItemMgr.Get(p.Platform, findItem.ItemId)
|
||||
if itemX != nil {
|
||||
item.ItemId = findItem.ItemId
|
||||
item.Name = findItem.Name
|
||||
item.Effect0 = findItem.Effect
|
||||
item.Effect = findItem.Effect
|
||||
item.SaleType = findItem.SaleType
|
||||
item.SaleGold = findItem.SaleGold
|
||||
}
|
||||
if findItem != nil {
|
||||
return item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
// FindItemUniqueByType 按照道具类型获取背包内道具唯一ID
|
||||
func (this *BagMgr) FindItemUniqueByType(snid int32, itemType int32) (string, bool) {
|
||||
if p, exist := this.PlayerBag[snid]; exist {
|
||||
for k, itemInfo := range p.BagItem {
|
||||
|
||||
itemX := srvdata.GameItemMgr.Get(p.Platform, itemInfo.ItemId)
|
||||
if itemX == nil {
|
||||
continue
|
||||
}
|
||||
e := this.GetItem(snid, int32(itemId))
|
||||
|
||||
if itemX.Type == itemType {
|
||||
return k, true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Range 遍历背包
|
||||
func (this *BagMgr) Range(snid int32, fn func(item *Item) bool) {
|
||||
if p, exist := this.PlayerBag[snid]; exist {
|
||||
for k, itemInfo := range p.BagItem {
|
||||
|
||||
itemX := srvdata.GameItemMgr.Get(p.Platform, itemInfo.ItemId)
|
||||
if itemX == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var e *Item
|
||||
if itemX.Type != common.ItemTypeSeasonPicket {
|
||||
e = this.GetItem(snid, itemInfo.ItemId)
|
||||
} else {
|
||||
e = this.GetItemByUniqueId(snid, k)
|
||||
}
|
||||
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -519,12 +579,8 @@ func (this *BagMgr) GetBagInfo(snid int32) *BagInfo {
|
|||
ret.Ts = v.Ts
|
||||
ret.dirty = v.dirty
|
||||
ret.LogId = v.LogId
|
||||
for k := range v.BagItem {
|
||||
itemId, err := strconv.Atoi(k)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ret.BagItem[k] = this.GetItem(snid, int32(itemId))
|
||||
for k, v := range v.BagItem {
|
||||
ret.BagItem[k] = this.GetItem(snid, v.ItemId)
|
||||
}
|
||||
} else {
|
||||
this.PlayerBag[snid] = NewBagInfo(p.Platform, p.SnId)
|
||||
|
@ -562,11 +618,12 @@ func (this *BagMgr) SyncBagData(snid int32, changeItemIds ...int32) {
|
|||
|
||||
// AddItemCheck 校验道具是否充足
|
||||
// 返回道具变化,操作结果,是否成功
|
||||
func (this *BagMgr) AddItemCheck(param *model.AddItemParam) ([]*model.Item, bag.OpResultCode, bool) {
|
||||
func (this *BagMgr) AddItemCheck(param *model.AddItemParam) ([]*model.Item, bag.OpResultCode, bool, string) {
|
||||
var items []*model.Item // 道具变化
|
||||
var findItemUniqueId string
|
||||
p := PlayerMgrSington.GetPlayerBySnId(param.SnId)
|
||||
if p == nil {
|
||||
return items, bag.OpResultCode_OPRC_NotPlayer, false
|
||||
return items, bag.OpResultCode_OPRC_NotPlayer, false, findItemUniqueId
|
||||
}
|
||||
|
||||
// 获取背包
|
||||
|
@ -585,17 +642,26 @@ func (this *BagMgr) AddItemCheck(param *model.AddItemParam) ([]*model.Item, bag.
|
|||
}
|
||||
item := srvdata.GameItemMgr.Get(p.Platform, v.ItemId)
|
||||
if item == nil {
|
||||
return items, bag.OpResultCode_OPRC_IdErr, false
|
||||
return items, bag.OpResultCode_OPRC_IdErr, false, findItemUniqueId
|
||||
}
|
||||
|
||||
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
|
||||
if item.Type == common.ItemTypeSeasonPicket {
|
||||
// 找一个还在时效内的道具
|
||||
for itemUniqueId, findItem := range newBagInfo.BagItem {
|
||||
if findItem.ItemId == v.ItemId && ((v.ObtainTime + int64(item.Time*3600)) <= time.Now().Unix()) {
|
||||
return items, bag.OpResultCode_OPRC_UseUp, false, itemUniqueId
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return items, bag.OpResultCode_OPRC_UseUp, false, findItemUniqueId
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if v.ItemNum < 0 {
|
||||
return items, bag.OpResultCode_OPRC_UseUp, false
|
||||
return items, bag.OpResultCode_OPRC_UseUp, false, findItemUniqueId
|
||||
}
|
||||
}
|
||||
items = append(items, &model.Item{
|
||||
|
@ -604,7 +670,7 @@ func (this *BagMgr) AddItemCheck(param *model.AddItemParam) ([]*model.Item, bag.
|
|||
ObtainTime: v.ObtainTime,
|
||||
})
|
||||
}
|
||||
return items, bag.OpResultCode_OPRC_Sucess, true
|
||||
return items, bag.OpResultCode_OPRC_Sucess, true, findItemUniqueId
|
||||
}
|
||||
|
||||
// AddItems 修改道具,玩家需在线
|
||||
|
@ -665,7 +731,7 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
|
|||
}
|
||||
// 非道具
|
||||
|
||||
items, code, ok := this.AddItemCheck(param)
|
||||
items, code, ok, findItemUniqueId := this.AddItemCheck(param)
|
||||
if !ok {
|
||||
return nil, code, ok
|
||||
}
|
||||
|
@ -710,12 +776,15 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
|
|||
ItemNum: v.ItemNum, // 数量
|
||||
ObtainTime: time.Now().Unix(),
|
||||
}
|
||||
|
||||
findItemUniqueId = itemUniqueId
|
||||
}
|
||||
} else if v.ItemNum < 0 {
|
||||
// 找到这类道具减一个
|
||||
|
||||
// 找到这类道具增减
|
||||
if itm, exist := newBagInfo.BagItem[findItemUniqueId]; exist {
|
||||
itm.ItemNum += v.ItemNum
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
num := v.ItemNum
|
||||
|
@ -767,9 +836,16 @@ func (this *BagMgr) AddItems(param *model.AddItemParam) (*BagInfo, bag.OpResultC
|
|||
Cost: param.Cost,
|
||||
})
|
||||
|
||||
itemInfo := this.GetItem(p.SnId, v.ItemId)
|
||||
if itemInfo != nil {
|
||||
itemInfos = append(itemInfos, v.ItemId)
|
||||
if itemData.Type != common.ItemTypeSeasonPicket {
|
||||
itemInfo := this.GetItem(p.SnId, v.ItemId)
|
||||
if itemInfo != nil {
|
||||
itemInfos = append(itemInfos, v.ItemId)
|
||||
}
|
||||
} else {
|
||||
itemInfo := this.GetItemByUniqueId(p.SnId, findItemUniqueId)
|
||||
if itemInfo != nil {
|
||||
itemInfos = append(itemInfos, v.ItemId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -396,7 +396,14 @@ func (this *Scene) PlayerEnter(p *Player, pos int, ischangeroom bool) bool {
|
|||
dbItemArr := srvdata.GameItemMgr.GetArr(p.Platform)
|
||||
for _, dbItem := range dbItemArr {
|
||||
msg.Items[dbItem.Id] = 0
|
||||
itemInfo := BagMgrSingleton.GetItem(p.SnId, dbItem.Id)
|
||||
|
||||
var itemInfo *Item
|
||||
if dbItem.Type != common.ItemTypeSeasonPicket {
|
||||
itemInfo = BagMgrSingleton.GetItem(p.SnId, dbItem.Id)
|
||||
} else {
|
||||
//itemInfo = Bag
|
||||
}
|
||||
|
||||
if itemInfo != nil {
|
||||
msg.Items[dbItem.Id] = itemInfo.ItemNum
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue