修复圣遗物替换的小问题并优化

This commit is contained in:
UnKownOwO
2023-02-15 21:02:46 +08:00
parent 76b417f3f4
commit 555463f669
8 changed files with 97 additions and 90 deletions

View File

@@ -73,7 +73,7 @@ func (g *GameManager) AvatarPromoteGetRewardReq(player *model.Player, payloadMsg
logger.Debug("user promote get reward, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarPromoteGetRewardReq)
// 是否拥有角色
avatar, ok := player.AvatarMap[player.GetAvatarIdByGuid(req.AvatarGuid)]
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", req.AvatarGuid)
g.SendError(cmd.AvatarPromoteGetRewardRsp, player, &proto.AvatarPromoteGetRewardRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)
@@ -124,7 +124,7 @@ func (g *GameManager) AvatarPromoteReq(player *model.Player, payloadMsg pb.Messa
logger.Debug("user promote, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarPromoteReq)
// 是否拥有角色
avatar, ok := player.AvatarMap[player.GetAvatarIdByGuid(req.Guid)]
avatar, ok := player.GameObjectGuidMap[req.Guid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", req.Guid)
g.SendError(cmd.AvatarPromoteRsp, player, &proto.AvatarPromoteRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)
@@ -210,7 +210,7 @@ func (g *GameManager) AvatarUpgradeReq(player *model.Player, payloadMsg pb.Messa
logger.Debug("user upgrade, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarUpgradeReq)
// 是否拥有角色
avatar, ok := player.AvatarMap[player.GetAvatarIdByGuid(req.AvatarGuid)]
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", req.AvatarGuid)
g.SendError(cmd.AvatarUpgradeRsp, player, &proto.AvatarUpgradeRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)

View File

@@ -53,7 +53,7 @@ func (g *GameManager) TakeoffEquipReq(player *model.Player, payloadMsg pb.Messag
req := payloadMsg.(*proto.TakeoffEquipReq)
// 获取目标角色
avatar, ok := player.AvatarMap[player.GetAvatarIdByGuid(req.AvatarGuid)]
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", req.AvatarGuid)
g.SendError(cmd.TakeoffEquipRsp, player, &proto.TakeoffEquipRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)
@@ -71,10 +71,7 @@ func (g *GameManager) TakeoffEquipReq(player *model.Player, payloadMsg pb.Messag
// 角色更新面板
g.UpdateUserAvatarFightProp(player.PlayerID, avatar.AvatarId)
// 更新玩家装备
avatarEquipChangeNotify := &proto.AvatarEquipChangeNotify{
AvatarGuid: avatar.Guid,
EquipType: req.Slot,
}
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, uint8(req.Slot))
g.SendMsg(cmd.AvatarEquipChangeNotify, player.PlayerID, player.ClientSeq, avatarEquipChangeNotify)
takeoffEquipRsp := &proto.TakeoffEquipRsp{
@@ -90,12 +87,18 @@ func (g *GameManager) WearEquipReq(player *model.Player, payloadMsg pb.Message)
req := payloadMsg.(*proto.WearEquipReq)
// 获取目标角色
avatar, ok := player.AvatarMap[player.GetAvatarIdByGuid(req.AvatarGuid)]
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", req.AvatarGuid)
g.SendError(cmd.WearEquipRsp, player, &proto.WearEquipRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)
return
}
// 获取角色配置表
avatarConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
if avatarConfig == nil {
logger.Error("avatar config error, avatarId: %v", avatar.AvatarId)
return
}
// 获取目标装备
equipGameObj, ok := player.GameObjectGuidMap[req.EquipGuid]
if !ok {
@@ -106,10 +109,23 @@ func (g *GameManager) WearEquipReq(player *model.Player, payloadMsg pb.Message)
switch equipGameObj.(type) {
case *model.Weapon:
weapon := equipGameObj.(*model.Weapon)
// 获取武器配置表
weaponConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
if weaponConfig == nil {
logger.Error("weapon config error, itemId: %v", weapon.ItemId)
return
}
// 校验装备的武器类型是否匹配
if weaponConfig.EquipType != avatarConfig.WeaponType {
logger.Error("weapon type error, weaponType: %v", weaponConfig.EquipType)
g.SendError(cmd.WearEquipRsp, player, &proto.WearEquipRsp{})
return
}
g.WearUserAvatarWeapon(player.PlayerID, avatar.AvatarId, weapon.WeaponId)
case *model.Reliquary:
reliquary := equipGameObj.(*model.Reliquary)
g.WearUserAvatarReliquary(player.PlayerID, avatar.AvatarId, reliquary.ReliquaryId)
logger.Error("itemId: %v", reliquary.ItemId)
// g.WearUserAvatarReliquary(player.PlayerID, avatar.AvatarId, reliquary.ReliquaryId)
default:
logger.Error("equip type error, equipGuid: %v", req.EquipGuid)
g.SendError(cmd.WearEquipRsp, player, &proto.WearEquipRsp{})
@@ -168,9 +184,9 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
player.TakeOffReliquary(targetReliquaryAvatar.AvatarId, reliquary.ReliquaryId)
// 更新目标圣遗物角色的装备
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(targetReliquaryAvatar, targetReliquaryAvatar.EquipReliquaryMap[uint8(reliquaryConfig.ReliquaryType)])
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(targetReliquaryAvatar, uint8(reliquaryConfig.ReliquaryType))
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
} else {
} else if avatarCurReliquary != nil {
// 角色当前有圣遗物则卸下
player.TakeOffReliquary(avatarId, avatarCurReliquary.ReliquaryId)
}
@@ -178,7 +194,7 @@ func (g *GameManager) WearUserAvatarReliquary(userId uint32, avatarId uint32, re
player.WearReliquary(avatarId, reliquaryId)
// 更新角色装备
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, reliquary)
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotifyByReliquary(avatar, uint8(reliquaryConfig.ReliquaryType))
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
}
@@ -217,10 +233,11 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
}
// 卸下角色已装备的武器
player.TakeOffWeapon(avatarId, avatarCurWeapon.WeaponId)
// 将目标武器的角色装备当前角色曾装备的武器
player.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon.WeaponId)
// 将目标武器的角色卸下武器
player.TakeOffWeapon(targetWeaponAvatar.AvatarId, weapon.WeaponId)
// 将目标武器的角色装备当前角色曾装备的武器
player.WearWeapon(targetWeaponAvatar.AvatarId, avatarCurWeapon.WeaponId)
// 更新目标武器角色的装备
weaponEntityId := uint32(0)
@@ -248,7 +265,17 @@ func (g *GameManager) WearUserAvatarWeapon(userId uint32, avatarId uint32, weapo
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
}
func (g *GameManager) PacketAvatarEquipChangeNotifyByReliquary(avatar *model.Avatar, reliquary *model.Reliquary) *proto.AvatarEquipChangeNotify {
func (g *GameManager) PacketAvatarEquipChangeNotifyByReliquary(avatar *model.Avatar, slot uint8) *proto.AvatarEquipChangeNotify {
// 获取角色对应位置的圣遗物
reliquary, ok := avatar.EquipReliquaryMap[slot]
if !ok {
// 没有则代表卸下
avatarEquipChangeNotify := &proto.AvatarEquipChangeNotify{
AvatarGuid: avatar.Guid,
EquipType: uint32(slot),
}
return avatarEquipChangeNotify
}
reliquaryConfig := gdconf.GetItemDataById(int32(reliquary.ItemId))
if reliquaryConfig == nil {
logger.Error("reliquary config error, itemId: %v", reliquary.ItemId)
@@ -297,14 +324,3 @@ func (g *GameManager) PacketAvatarEquipChangeNotifyByWeapon(avatar *model.Avatar
}
return avatarEquipChangeNotify
}
func (g *GameManager) PacketAvatarEquipTakeOffNotify(avatar *model.Avatar, weapon *model.Weapon) *proto.AvatarEquipChangeNotify {
avatarEquipChangeNotify := &proto.AvatarEquipChangeNotify{
AvatarGuid: avatar.Guid,
}
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
if itemDataConfig != nil {
avatarEquipChangeNotify.EquipType = uint32(itemDataConfig.Type)
}
return avatarEquipChangeNotify
}

View File

@@ -22,7 +22,12 @@ func (g *GameManager) ChangeAvatarReq(player *model.Player, payloadMsg pb.Messag
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
targetAvatarId := player.GetAvatarIdByGuid(targetAvatarGuid)
targetAvatar, ok := player.GameObjectGuidMap[targetAvatarGuid].(*model.Avatar)
if !ok {
logger.Error("target avatar error, avatarGuid: %v", targetAvatarGuid)
return
}
targetAvatarId := targetAvatar.AvatarId
oldAvatarId := world.GetPlayerActiveAvatarId(player)
if targetAvatarId == oldAvatarId {
logger.Error("can not change to the same avatar, uid: %v, oldAvatarId: %v, targetAvatarId: %v", player.PlayerID, oldAvatarId, targetAvatarId)
@@ -121,7 +126,12 @@ func (g *GameManager) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Mes
world.InitPlayerWorldAvatar(player)
currAvatarGuid := req.CurAvatarGuid
currAvatarId := player.GetAvatarIdByGuid(currAvatarGuid)
currAvatar, ok := player.GameObjectGuidMap[currAvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", currAvatarGuid)
return
}
currAvatarId := currAvatar.AvatarId
currAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
player.TeamConfig.CurrAvatarIndex = uint8(currAvatarIndex)
world.SetPlayerAvatarIndex(player, currAvatarIndex)
@@ -179,7 +189,12 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
}
avatarIdList := make([]uint32, 0)
for _, avatarGuid := range avatarGuidList {
avatarId := player.GetAvatarIdByGuid(avatarGuid)
avatar, ok := player.GameObjectGuidMap[avatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", avatarGuid)
return
}
avatarId := avatar.AvatarId
avatarIdList = append(avatarIdList, avatarId)
}
world.SetPlayerLocalTeam(player, avatarIdList)
@@ -187,7 +202,12 @@ func (g *GameManager) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.
world.InitPlayerWorldAvatar(player)
currAvatarGuid := req.CurAvatarGuid
currAvatarId := player.GetAvatarIdByGuid(currAvatarGuid)
currAvatar, ok := player.GameObjectGuidMap[currAvatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", currAvatarGuid)
return
}
currAvatarId := currAvatar.AvatarId
newAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
world.SetPlayerAvatarIndex(player, newAvatarIndex)

View File

@@ -123,7 +123,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
return
}
// 是否拥有武器
weapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(req.TargetWeaponGuid)]
weapon, ok := player.GameObjectGuidMap[req.TargetWeaponGuid].(*model.Weapon)
if !ok {
logger.Error("weapon error, weaponGuid: %v", req.TargetWeaponGuid)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -162,7 +162,22 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
}
// 获取精炼材料物品配置表
// 精炼的材料可能是武器也可能是物品
itemDataConfig := gdconf.GetItemDataById(int32(player.GetItemIdByItemAndWeaponGuid(req.ItemGuid)))
gameObj, ok := player.GameObjectGuidMap[req.ItemGuid]
if !ok {
logger.Error("item guid error, itemGuid: %v", req.ItemGuid)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{})
return
}
itemId := uint32(0)
switch gameObj.(type) {
case *model.Item:
item := gameObj.(*model.Item)
itemId = item.ItemId
case *model.Weapon:
weapon := gameObj.(*model.Weapon)
itemId = weapon.ItemId
}
itemDataConfig := gdconf.GetItemDataById(int32(itemId))
if itemDataConfig == nil {
logger.Error("item data config error, itemGuid: %v", req.ItemGuid)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -173,9 +188,9 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
case int32(constant.ITEM_TYPE_WEAPON):
// 精炼材料为武器
// 是否拥有将被用于精炼的武器
foodWeapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(req.ItemGuid)]
foodWeapon, ok := player.GameObjectGuidMap[req.ItemGuid].(*model.Weapon)
if !ok {
logger.Error("weapon error, weaponGuid: %v", req.TargetWeaponGuid)
logger.Error("weapon error, weaponGuid: %v", req.ItemGuid)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
return
}
@@ -196,7 +211,7 @@ func (g *GameManager) WeaponAwakenReq(player *model.Player, payloadMsg pb.Messag
case int32(constant.ITEM_TYPE_MATERIAL):
// 精炼材料为道具
// 是否拥有将被用于精炼的道具
item, ok := player.ItemMap[player.GetItemIdByGuid(req.ItemGuid)]
item, ok := player.GameObjectGuidMap[req.ItemGuid].(*model.Item)
if !ok {
logger.Error("item error, itemGuid: %v", req.ItemGuid)
g.SendError(cmd.WeaponAwakenRsp, player, &proto.WeaponAwakenRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -266,7 +281,7 @@ func (g *GameManager) WeaponPromoteReq(player *model.Player, payloadMsg pb.Messa
logger.Debug("user weapon promote, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.WeaponPromoteReq)
// 是否拥有武器
weapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(req.TargetWeaponGuid)]
weapon, ok := player.GameObjectGuidMap[req.TargetWeaponGuid].(*model.Weapon)
if !ok {
logger.Error("weapon error, weaponGuid: %v", req.TargetWeaponGuid)
g.SendError(cmd.WeaponPromoteRsp, player, &proto.WeaponPromoteRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -410,7 +425,7 @@ func (g *GameManager) GetWeaponUpgradeReturnMaterial(overflowExp uint32) (return
func (g *GameManager) CalcWeaponUpgradeExpAndCoin(player *model.Player, itemParamList []*proto.ItemParam, foodWeaponGuidList []uint64) (expCount uint32, coinCost uint32, success bool) {
// 武器经验计算
for _, weaponGuid := range foodWeaponGuidList {
foodWeapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(weaponGuid)]
foodWeapon, ok := player.GameObjectGuidMap[weaponGuid].(*model.Weapon)
if !ok {
logger.Error("food weapon error, weaponGuid: %v", weaponGuid)
return
@@ -534,7 +549,7 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
logger.Debug("user weapon upgrade, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.WeaponUpgradeReq)
// 是否拥有武器
weapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(req.TargetWeaponGuid)]
weapon, ok := player.GameObjectGuidMap[req.TargetWeaponGuid].(*model.Weapon)
if !ok {
logger.Error("weapon error, weaponGuid: %v", req.TargetWeaponGuid)
g.SendError(cmd.WeaponUpgradeRsp, player, &proto.WeaponUpgradeRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -596,7 +611,7 @@ func (g *GameManager) WeaponUpgradeReq(player *model.Player, payloadMsg pb.Messa
// 校验作为升级材料的武器是否存在
costWeaponIdList := make([]uint64, 0, len(req.FoodWeaponGuidList))
for _, weaponGuid := range req.FoodWeaponGuidList {
foodWeapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(weaponGuid)]
foodWeapon, ok := player.GameObjectGuidMap[weaponGuid].(*model.Weapon)
if !ok {
logger.Error("food weapon error, weaponGuid: %v", weaponGuid)
g.SendError(cmd.WeaponUpgradeRsp, player, &proto.WeaponUpgradeRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)
@@ -669,7 +684,7 @@ func (g *GameManager) CalcWeaponUpgradeReturnItemsReq(player *model.Player, payl
logger.Debug("user calc weapon upgrade, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.CalcWeaponUpgradeReturnItemsReq)
// 是否拥有武器
weapon, ok := player.WeaponMap[player.GetWeaponIdByGuid(req.TargetWeaponGuid)]
weapon, ok := player.GameObjectGuidMap[req.TargetWeaponGuid].(*model.Weapon)
if !ok {
logger.Error("weapon error, weaponGuid: %v", req.TargetWeaponGuid)
g.SendError(cmd.CalcWeaponUpgradeReturnItemsRsp, player, &proto.CalcWeaponUpgradeReturnItemsRsp{}, proto.Retcode_RET_ITEM_NOT_EXIST)

View File

@@ -80,15 +80,6 @@ func (p *Player) InitAvatarFightProp(avatar *Avatar) {
p.SetCurrEnergy(avatar, avatar.CurrEnergy, true)
}
func (p *Player) GetAvatarIdByGuid(guid uint64) uint32 {
for avatarId, avatar := range p.AvatarMap {
if guid == avatar.Guid {
return avatarId
}
}
return 0
}
func (p *Player) AddAvatar(avatarId uint32) {
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
if avatarDataConfig == nil {

View File

@@ -11,6 +11,7 @@ type Item struct {
func (p *Player) InitAllItem() {
for itemId, item := range p.ItemMap {
item.Guid = p.GetNextGameObjectGuid()
p.GameObjectGuidMap[item.Guid] = GameObject(item)
p.ItemMap[itemId] = item
}
}
@@ -23,28 +24,6 @@ func (p *Player) GetItemGuid(itemId uint32) uint64 {
return itemInfo.Guid
}
func (p *Player) GetItemIdByGuid(itemGuid uint64) uint32 {
for _, item := range p.ItemMap {
if item.Guid == itemGuid {
return item.ItemId
}
}
return 0
}
func (p *Player) GetItemIdByItemAndWeaponGuid(guid uint64) uint32 {
for _, item := range p.ItemMap {
if item.Guid == guid {
return item.ItemId
}
}
for _, weapon := range p.WeaponMap {
if weapon.Guid == guid {
return weapon.ItemId
}
}
return 0
}
func (p *Player) GetItemCount(itemId uint32) uint32 {
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
if ok {
@@ -72,6 +51,7 @@ func (p *Player) AddItem(itemId uint32, count uint32) {
Count: 0,
Guid: p.GetNextGameObjectGuid(),
}
p.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
}
itemInfo.Count += count
p.ItemMap[itemId] = itemInfo
@@ -89,6 +69,7 @@ func (p *Player) CostItem(itemId uint32, count uint32) {
}
if itemInfo.Count == 0 {
delete(p.ItemMap, itemId)
delete(p.GameObjectGuidMap, itemInfo.Guid)
} else {
p.ItemMap[itemId] = itemInfo
}

View File

@@ -50,15 +50,6 @@ func (p *Player) GetReliquaryGuid(reliquaryId uint64) uint64 {
return reliquaryInfo.Guid
}
func (p *Player) GetReliquaryIdByGuid(guid uint64) uint64 {
for reliquaryId, reliquary := range p.ReliquaryMap {
if guid == reliquary.Guid {
return reliquaryId
}
}
return 0
}
func (p *Player) GetReliquary(reliquaryId uint64) *Reliquary {
return p.ReliquaryMap[reliquaryId]
}
@@ -96,5 +87,6 @@ func (p *Player) CostReliquary(reliquaryId uint64) uint64 {
return 0
}
delete(p.ReliquaryMap, reliquaryId)
delete(p.GameObjectGuidMap, reliquary.Guid)
return reliquary.Guid
}

View File

@@ -44,15 +44,6 @@ func (p *Player) GetWeaponGuid(weaponId uint64) uint64 {
return weaponInfo.Guid
}
func (p *Player) GetWeaponIdByGuid(guid uint64) uint64 {
for weaponId, weapon := range p.WeaponMap {
if guid == weapon.Guid {
return weaponId
}
}
return 0
}
func (p *Player) GetWeapon(weaponId uint64) *Weapon {
return p.WeaponMap[weaponId]
}
@@ -91,5 +82,6 @@ func (p *Player) CostWeapon(weaponId uint64) uint64 {
return 0
}
delete(p.WeaponMap, weaponId)
delete(p.GameObjectGuidMap, weapon.Guid)
return weapon.Guid
}