diff --git a/common/constant/store_pack_limit.go b/common/constant/store_pack_limit.go new file mode 100644 index 00000000..29a0aa64 --- /dev/null +++ b/common/constant/store_pack_limit.go @@ -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 // 家具容量限制 +) diff --git a/common/constant/weapon_awaken.go b/common/constant/weapon_awaken.go new file mode 100644 index 00000000..e56a535f --- /dev/null +++ b/common/constant/weapon_awaken.go @@ -0,0 +1,6 @@ +package constant + +const ( + WEAPON_AWAKEN_MAX_REFINEMENT = 5 // 武器最大精炼等级 + WEAPON_AWAKEN_MIN_EQUIPLEVEL = 3 // 武器精炼最小星级 +) diff --git a/gs/game/player_login.go b/gs/game/player_login.go index b0cb81e0..b23758aa 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -185,11 +185,11 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti storeWeightLimitNotify := &proto.StoreWeightLimitNotify{ StoreType: proto.StoreType_STORE_PACK, // 背包容量限制 - WeightLimit: 30000, - WeaponCountLimit: 2000, - ReliquaryCountLimit: 1500, - MaterialCountLimit: 2000, - FurnitureCountLimit: 2000, + WeightLimit: constant.STORE_PACK_LIMIT_WEIGHT, + WeaponCountLimit: constant.STORE_PACK_LIMIT_WEAPON, + ReliquaryCountLimit: constant.STORE_PACK_LIMIT_RELIQUARY, + MaterialCountLimit: constant.STORE_PACK_LIMIT_MATERIAL, + FurnitureCountLimit: constant.STORE_PACK_LIMIT_FURNITURE, } return storeWeightLimitNotify } @@ -197,14 +197,10 @@ func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNoti func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify { playerStoreNotify := &proto.PlayerStoreNotify{ 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 { - pbItem := &proto.Item{ - ItemId: weapon.ItemId, - Guid: weapon.Guid, - Detail: nil, - } itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId)) if itemDataConfig == nil { 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 { affixMap[affixId] = uint32(weapon.Refinement) } - pbItem.Detail = &proto.Item_Equip{ - Equip: &proto.Equip{ - Detail: &proto.Equip_Weapon{ - Weapon: &proto.Weapon{ - Level: uint32(weapon.Level), - Exp: weapon.Exp, - PromoteLevel: uint32(weapon.Promote), - AffixMap: affixMap, + pbItem := &proto.Item{ + ItemId: weapon.ItemId, + Guid: weapon.Guid, + Detail: &proto.Item_Equip{ + Equip: &proto.Equip{ + Detail: &proto.Equip_Weapon{ + Weapon: &proto.Weapon{ + 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) } for _, reliquary := range player.ReliquaryMap { - pbItem := &proto.Item{ - ItemId: reliquary.ItemId, - Guid: reliquary.Guid, - Detail: nil, - } itemDataConfig := gdconf.GetItemDataById(int32(reliquary.ItemId)) if itemDataConfig == nil { 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 { continue } - pbItem.Detail = &proto.Item_Equip{ - Equip: &proto.Equip{ - Detail: &proto.Equip_Reliquary{ - Reliquary: &proto.Reliquary{ - Level: uint32(reliquary.Level), - Exp: reliquary.Exp, - PromoteLevel: uint32(reliquary.Promote), - MainPropId: reliquary.MainPropId, - AppendPropIdList: reliquary.AppendPropIdList, + pbItem := &proto.Item{ + ItemId: reliquary.ItemId, + Guid: reliquary.Guid, + Detail: &proto.Item_Equip{ + Equip: &proto.Equip{ + Detail: &proto.Equip_Reliquary{ + Reliquary: &proto.Reliquary{ + Level: uint32(reliquary.Level), + 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) } for _, item := range player.ItemMap { - pbItem := &proto.Item{ - ItemId: item.ItemId, - Guid: item.Guid, - Detail: nil, - } itemDataConfig := gdconf.GetItemDataById(int32(item.ItemId)) if itemDataConfig == nil { logger.Error("get item data config is nil, itemId: %v", item.ItemId) continue } + pbItem := &proto.Item{ + ItemId: item.ItemId, + Guid: item.Guid, + Detail: nil, + } if itemDataConfig != nil && uint16(itemDataConfig.Type) == constant.ITEM_TYPE_FURNITURE { pbItem.Detail = &proto.Item_Furniture{ Furniture: &proto.Furniture{ diff --git a/gs/game/player_weapon.go b/gs/game/player_weapon.go index 64b03359..ce4f08c5 100644 --- a/gs/game/player_weapon.go +++ b/gs/game/player_weapon.go @@ -148,14 +148,14 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag return } // 一星二星的武器不能精炼 - if weaponConfig.EquipLevel < 3 { + if weaponConfig.EquipLevel < constant.WEAPON_AWAKEN_MIN_EQUIPLEVEL { logger.Error("weapon equip level le 3, itemId: %v", weapon.ItemId) g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX) return } // 武器精炼等级是否不超过限制 // 暂时精炼等级是写死的 应该最大精炼等级就是5级 - if weapon.Refinement >= 4 { + if weapon.Refinement+1 >= constant.WEAPON_AWAKEN_MAX_REFINEMENT { logger.Error("weapon refinement ge 4, refinement: %v", weapon.Refinement) g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_AWAKEN_LEVEL_MAX) return diff --git a/gs/model/item.go b/gs/model/item.go index f5a2693d..4298e922 100644 --- a/gs/model/item.go +++ b/gs/model/item.go @@ -62,6 +62,11 @@ func (p *Player) GetItemCount(itemId uint32) uint32 { func (p *Player) AddItem(itemId uint32, count uint32) { itemInfo := p.ItemMap[itemId] if itemInfo == nil { + // 该物品为新物品时校验背包物品容量 + // 目前物品包括材料和家具 + if len(p.ItemMap) > constant.STORE_PACK_LIMIT_MATERIAL+constant.STORE_PACK_LIMIT_FURNITURE { + return + } itemInfo = &Item{ ItemId: itemId, Count: 0, diff --git a/gs/model/reliquary.go b/gs/model/reliquary.go index 373e34e3..521b24c5 100644 --- a/gs/model/reliquary.go +++ b/gs/model/reliquary.go @@ -1,6 +1,7 @@ package model import ( + "hk4e/common/constant" "hk4e/gdconf" "hk4e/pkg/logger" ) @@ -63,6 +64,15 @@ func (p *Player) GetReliquary(reliquaryId uint64) *Reliquary { } 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{ ReliquaryId: reliquaryId, ItemId: itemId, @@ -75,11 +85,6 @@ func (p *Player) AddReliquary(itemId uint32, reliquaryId uint64, mainPropId uint AvatarId: 0, Guid: 0, } - itemDataConfig := gdconf.GetItemDataById(int32(itemId)) - if itemDataConfig == nil { - logger.Error("reliquary config is nil, itemId: %v", itemId) - return - } _ = itemDataConfig p.InitReliquary(reliquary) p.ReliquaryMap[reliquaryId] = reliquary diff --git a/gs/model/weapon.go b/gs/model/weapon.go index a3ef88a1..dbd0956e 100644 --- a/gs/model/weapon.go +++ b/gs/model/weapon.go @@ -1,6 +1,7 @@ package model import ( + "hk4e/common/constant" "hk4e/gdconf" "hk4e/pkg/logger" ) @@ -57,6 +58,15 @@ func (p *Player) GetWeapon(weaponId uint64) *Weapon { } 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{ WeaponId: weaponId, ItemId: itemId, @@ -68,11 +78,6 @@ func (p *Player) AddWeapon(itemId uint32, weaponId uint64) { Refinement: 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 { weapon.AffixIdList = append(weapon.AffixIdList, uint32(skillAffix)) }