武器上锁功能

This commit is contained in:
UnKownOwO
2023-02-09 21:17:48 +08:00
parent ae4c505e48
commit 8f8525e434
7 changed files with 224 additions and 133 deletions
+1 -121
View File
@@ -57,7 +57,7 @@ func (g *GameManager) AddUserAvatar(userId uint32, avatarId uint32) {
weaponId := g.AddUserWeapon(player.PlayerID, uint32(avatarDataConfig.InitialWeapon))
// 角色装上初始武器
g.WearUserAvatarEquip(player.PlayerID, avatarId, weaponId)
g.WearUserAvatarWeapon(player.PlayerID, avatarId, weaponId)
g.UpdateUserAvatarFightProp(player.PlayerID, avatarId)
@@ -359,87 +359,6 @@ func (g *GameManager) PacketAvatarPropNotify(avatar *model.Avatar) *proto.Avatar
return avatarPropNotify
}
func (g *GameManager) WearEquipReq(player *model.Player, payloadMsg pb.Message) {
logger.Debug("user wear equip, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.WearEquipReq)
avatarGuid := req.AvatarGuid
equipGuid := req.EquipGuid
avatar, ok := player.GameObjectGuidMap[avatarGuid].(*model.Avatar)
if !ok {
logger.Error("avatar error, avatarGuid: %v", avatarGuid)
g.SendError(cmd.WearEquipRsp, player, &proto.WearEquipRsp{}, proto.Retcode_RET_CAN_NOT_FIND_AVATAR)
return
}
weapon, ok := player.GameObjectGuidMap[equipGuid].(*model.Weapon)
if !ok {
logger.Error("equip error, equipGuid: %v", equipGuid)
g.SendError(cmd.WearEquipRsp, player, &proto.WearEquipRsp{})
return
}
g.WearUserAvatarEquip(player.PlayerID, avatar.AvatarId, weapon.WeaponId)
wearEquipRsp := &proto.WearEquipRsp{
AvatarGuid: avatarGuid,
EquipGuid: equipGuid,
}
g.SendMsg(cmd.WearEquipRsp, player.PlayerID, player.ClientSeq, wearEquipRsp)
}
func (g *GameManager) WearUserAvatarEquip(userId uint32, avatarId uint32, weaponId uint64) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
return
}
avatar := player.AvatarMap[avatarId]
weapon := player.WeaponMap[weaponId]
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if weapon.AvatarId != 0 {
// 武器在别的角色身上
weakAvatarId := weapon.AvatarId
weakWeaponId := weaponId
strongAvatarId := avatarId
strongWeaponId := avatar.EquipWeapon.WeaponId
player.TakeOffWeapon(weakAvatarId, weakWeaponId)
player.TakeOffWeapon(strongAvatarId, strongWeaponId)
player.WearWeapon(weakAvatarId, strongWeaponId)
player.WearWeapon(strongAvatarId, weakWeaponId)
weakAvatar := player.AvatarMap[weakAvatarId]
weakWeapon := player.WeaponMap[weakAvatar.EquipWeapon.WeaponId]
weakWorldAvatar := world.GetPlayerWorldAvatar(player, weakAvatarId)
if weakWorldAvatar != nil {
weakWorldAvatar.SetWeaponEntityId(scene.CreateEntityWeapon())
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotify(weakAvatar, weakWeapon, weakWorldAvatar.GetWeaponEntityId())
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
} else {
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotify(weakAvatar, weakWeapon, 0)
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
}
} else if avatar.EquipWeapon != nil {
// 角色当前有武器
player.TakeOffWeapon(avatarId, avatar.EquipWeapon.WeaponId)
player.WearWeapon(avatarId, weaponId)
} else {
// 是新角色还没有武器
player.WearWeapon(avatarId, weaponId)
}
worldAvatar := world.GetPlayerWorldAvatar(player, avatarId)
if worldAvatar != nil {
worldAvatar.SetWeaponEntityId(scene.CreateEntityWeapon())
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotify(avatar, weapon, worldAvatar.GetWeaponEntityId())
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
} else {
avatarEquipChangeNotify := g.PacketAvatarEquipChangeNotify(avatar, weapon, 0)
g.SendMsg(cmd.AvatarEquipChangeNotify, userId, player.ClientSeq, avatarEquipChangeNotify)
}
}
func (g *GameManager) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb.Message) {
logger.Debug("user change avatar costume, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.AvatarChangeCostumeReq)
@@ -515,45 +434,6 @@ func (g *GameManager) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.
g.SendMsg(cmd.AvatarWearFlycloakRsp, player.PlayerID, player.ClientSeq, avatarWearFlycloakRsp)
}
func (g *GameManager) PacketAvatarEquipChangeNotify(avatar *model.Avatar, weapon *model.Weapon, entityId uint32) *proto.AvatarEquipChangeNotify {
itemDataConfig := gdconf.GetItemDataById(int32(weapon.ItemId))
if itemDataConfig == nil {
logger.Error("item data config error, itemId: %v", weapon.ItemId)
return new(proto.AvatarEquipChangeNotify)
}
avatarEquipChangeNotify := &proto.AvatarEquipChangeNotify{
AvatarGuid: avatar.Guid,
ItemId: weapon.ItemId,
EquipGuid: weapon.Guid,
}
switch itemDataConfig.Type {
case int32(constant.ITEM_TYPE_WEAPON):
avatarEquipChangeNotify.EquipType = uint32(constant.EQUIP_TYPE_WEAPON)
case int32(constant.ITEM_TYPE_RELIQUARY):
avatarEquipChangeNotify.EquipType = uint32(itemDataConfig.ReliquaryType)
}
avatarEquipChangeNotify.Weapon = &proto.SceneWeaponInfo{
EntityId: entityId,
GadgetId: uint32(itemDataConfig.GadgetId),
ItemId: weapon.ItemId,
Guid: weapon.Guid,
Level: uint32(weapon.Level),
AbilityInfo: new(proto.AbilitySyncStateInfo),
}
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
}
func (g *GameManager) UpdateUserAvatarFightProp(userId uint32, avatarId uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {