背包容量限制

This commit is contained in:
UnKownOwO
2023-02-13 19:01:42 +08:00
parent ddecfdea12
commit c23a75b802
7 changed files with 81 additions and 52 deletions

View File

@@ -0,0 +1,9 @@
package constant
const (
STORE_PACK_LIMIT_WEIGHT = 30000 // 背包重量限制
STORE_PACK_LIMIT_WEAPON = 2000 // 武器容量限制
STORE_PACK_LIMIT_RELIQUARY = 1500 // 圣遗物容量限制
STORE_PACK_LIMIT_MATERIAL = 2000 // 材料容量限制
STORE_PACK_LIMIT_FURNITURE = 2000 // 家具容量限制
)

View File

@@ -0,0 +1,6 @@
package constant
const (
WEAPON_AWAKEN_MAX_REFINEMENT = 5 // 武器最大精炼等级
WEAPON_AWAKEN_MIN_EQUIPLEVEL = 3 // 武器精炼最小星级
)

View File

@@ -185,11 +185,11 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti
storeWeightLimitNotify := &proto.StoreWeightLimitNotify{ storeWeightLimitNotify := &proto.StoreWeightLimitNotify{
StoreType: proto.StoreType_STORE_PACK, StoreType: proto.StoreType_STORE_PACK,
// 背包容量限制 // 背包容量限制
WeightLimit: 30000, WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
WeaponCountLimit: 2000, WeaponCountLimit: constant.STORE_PACK_LIMIT_WEAPON,
ReliquaryCountLimit: 1500, ReliquaryCountLimit: constant.STORE_PACK_LIMIT_RELIQUARY,
MaterialCountLimit: 2000, MaterialCountLimit: constant.STORE_PACK_LIMIT_MATERIAL,
FurnitureCountLimit: 2000, FurnitureCountLimit: constant.STORE_PACK_LIMIT_FURNITURE,
} }
return storeWeightLimitNotify return storeWeightLimitNotify
} }
@@ -197,14 +197,10 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti
func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify { func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify {
playerStoreNotify := &proto.PlayerStoreNotify{ playerStoreNotify := &proto.PlayerStoreNotify{
StoreType: proto.StoreType_STORE_PACK, StoreType: proto.StoreType_STORE_PACK,
WeightLimit: 30000, WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT,
ItemList: make([]*proto.Item, 0, len(player.WeaponMap)+len(player.ReliquaryMap)+len(player.ItemMap)),
} }
for _, weapon := range player.WeaponMap { for _, weapon := range player.WeaponMap {
pbItem := &proto.Item{
ItemId: weapon.ItemId,
Guid: weapon.Guid,
Detail: nil,
}
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId)) itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
if itemDataConfig == nil { if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", weapon.ItemId) logger.Error("get item data config is nil, itemId: %v", weapon.ItemId)
@@ -217,27 +213,26 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
for _, affixId := range weapon.AffixIdList { for _, affixId := range weapon.AffixIdList {
affixMap[affixId] = uint32(weapon.Refinement) affixMap[affixId] = uint32(weapon.Refinement)
} }
pbItem.Detail = &proto.Item_Equip{ pbItem := &proto.Item{
Equip: &proto.Equip{ ItemId: weapon.ItemId,
Detail: &proto.Equip_Weapon{ Guid: weapon.Guid,
Weapon: &proto.Weapon{ Detail: &proto.Item_Equip{
Level: uint32(weapon.Level), Equip: &proto.Equip{
Exp: weapon.Exp, Detail: &proto.Equip_Weapon{
PromoteLevel: uint32(weapon.Promote), Weapon: &proto.Weapon{
AffixMap: affixMap, Level: uint32(weapon.Level),
Exp: weapon.Exp,
PromoteLevel: uint32(weapon.Promote),
AffixMap: affixMap,
},
}, },
IsLocked: weapon.Lock,
}, },
IsLocked: weapon.Lock,
}, },
} }
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem) playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
} }
for _, reliquary := range player.ReliquaryMap { for _, reliquary := range player.ReliquaryMap {
pbItem := &proto.Item{
ItemId: reliquary.ItemId,
Guid: reliquary.Guid,
Detail: nil,
}
itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId)) itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
if itemDataConfig == nil { if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId) logger.Error("get item data config is nil, itemId: %v", reliquary.ItemId)
@@ -246,33 +241,37 @@ func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.Playe
if uint16(itemDataConfig.Type) != constant.ITEM_TYPE_RELIQUARY { if uint16(itemDataConfig.Type) != constant.ITEM_TYPE_RELIQUARY {
continue continue
} }
pbItem.Detail = &proto.Item_Equip{ pbItem := &proto.Item{
Equip: &proto.Equip{ ItemId: reliquary.ItemId,
Detail: &proto.Equip_Reliquary{ Guid: reliquary.Guid,
Reliquary: &proto.Reliquary{ Detail: &proto.Item_Equip{
Level: uint32(reliquary.Level), Equip: &proto.Equip{
Exp: reliquary.Exp, Detail: &proto.Equip_Reliquary{
PromoteLevel: uint32(reliquary.Promote), Reliquary: &proto.Reliquary{
MainPropId: reliquary.MainPropId, Level: uint32(reliquary.Level),
AppendPropIdList: reliquary.AppendPropIdList, Exp: reliquary.Exp,
PromoteLevel: uint32(reliquary.Promote),
MainPropId: reliquary.MainPropId,
AppendPropIdList: reliquary.AppendPropIdList,
},
}, },
IsLocked: reliquary.Lock,
}, },
IsLocked: reliquary.Lock,
}, },
} }
playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem) playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem)
} }
for _, item := range player.ItemMap { for _, item := range player.ItemMap {
pbItem := &proto.Item{
ItemId: item.ItemId,
Guid: item.Guid,
Detail: nil,
}
itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId)) itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId))
if itemDataConfig == nil { if itemDataConfig == nil {
logger.Error("get item data config is nil, itemId: %v", item.ItemId) logger.Error("get item data config is nil, itemId: %v", item.ItemId)
continue continue
} }
pbItem := &proto.Item{
ItemId: item.ItemId,
Guid: item.Guid,
Detail: nil,
}
if itemDataConfig != nil && uint16(itemDataConfig.Type) == constant.ITEM_TYPE_FURNITURE { if itemDataConfig != nil && uint16(itemDataConfig.Type) == constant.ITEM_TYPE_FURNITURE {
pbItem.Detail = &proto.Item_Furniture{ pbItem.Detail = &proto.Item_Furniture{
Furniture: &proto.Furniture{ Furniture: &proto.Furniture{

View File

@@ -148,14 +148,14 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
return return
} }
// 一星二星的武器不能精炼 // 一星二星的武器不能精炼
if weaponConfig.EquipLevel < 3 { if weaponConfig.EquipLevel < constant.WEAPON_AWAKEN_MIN_EQUIPLEVEL {
logger.Error("weapon equip level le 3, itemId: %v", weapon.ItemId) logger.Error("weapon equip level le 3, itemId: %v", weapon.ItemId)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX) g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX)
return return
} }
// 武器精炼等级是否不超过限制 // 武器精炼等级是否不超过限制
// 暂时精炼等级是写死的 应该最大精炼等级就是5级 // 暂时精炼等级是写死的 应该最大精炼等级就是5级
if weapon.Refinement >= 4 { if weapon.Refinement+1 >= constant.WEAPON_AWAKEN_MAX_REFINEMENT {
logger.Error("weapon refinement ge 4, refinement: %v", weapon.Refinement) logger.Error("weapon refinement ge 4, refinement: %v", weapon.Refinement)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX) g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX)
return return

View File

@@ -62,6 +62,11 @@ func (p *Player) GetItemCount(itemId uint32) uint32 {
func (p *Player) AddItem(itemId uint32, count uint32) { func (p *Player) AddItem(itemId uint32, count uint32) {
itemInfo := p.ItemMap[itemId] itemInfo := p.ItemMap[itemId]
if itemInfo == nil { if itemInfo == nil {
// 该物品为新物品时校验背包物品容量
// 目前物品包括材料和家具
if len(p.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE {
return
}
itemInfo = &Item{ itemInfo = &Item{
ItemId: itemId, ItemId: itemId,
Count: 0, Count: 0,

View File

@@ -1,6 +1,7 @@
package model package model
import ( import (
"hk4e/common/constant"
"hk4e/gdconf" "hk4e/gdconf"
"hk4e/pkg/logger" "hk4e/pkg/logger"
) )
@@ -63,6 +64,15 @@ func (p *Player) GetReliquary(reliquaryId uint64) *Reliquary {
} }
func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint32) { func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint32) {
// 校验背包圣遗物容量
if len(p.ReliquaryMap) > constant.STORE_PACK_LIMIT_RELIQUARY {
return
}
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
logger.Error("reliquary config is nil, itemId: %v", itemId)
return
}
reliquary := &Reliquary{ reliquary := &Reliquary{
ReliquaryId: reliquaryId, ReliquaryId: reliquaryId,
ItemId: itemId, ItemId: itemId,
@@ -75,11 +85,6 @@ func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint
AvatarId: 0, AvatarId: 0,
Guid: 0, Guid: 0,
} }
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
logger.Error("reliquary config is nil, itemId: %v", itemId)
return
}
_ = itemDataConfig _ = itemDataConfig
p.InitReliquary(reliquary) p.InitReliquary(reliquary)
p.ReliquaryMap[reliquaryId] = reliquary p.ReliquaryMap[reliquaryId] = reliquary

View File

@@ -1,6 +1,7 @@
package model package model
import ( import (
"hk4e/common/constant"
"hk4e/gdconf" "hk4e/gdconf"
"hk4e/pkg/logger" "hk4e/pkg/logger"
) )
@@ -57,6 +58,15 @@ func (p *Player) GetWeapon(weaponId uint64) *Weapon {
} }
func (p *Player) AddWeapon(itemId uint32, weaponId uint64) { func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
// 校验背包武器容量
if len(p.WeaponMap) > constant.STORE_PACK_LIMIT_WEAPON {
return
}
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
logger.Error("weapon config is nil, itemId: %v", itemId)
return
}
weapon := &Weapon{ weapon := &Weapon{
WeaponId: weaponId, WeaponId: weaponId,
ItemId: itemId, ItemId: itemId,
@@ -68,11 +78,6 @@ func (p *Player) AddWeapon(itemId uint32, weaponId uint64) {
Refinement: 0, Refinement: 0,
Guid: 0, Guid: 0,
} }
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
logger.Error("weapon config is nil, itemId: %v", itemId)
return
}
for _, skillAffix := range itemDataConfig.SkillAffix { for _, skillAffix := range itemDataConfig.SkillAffix {
weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix)) weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix))
} }