***
This commit is contained in:
1 parent
d8a3af9fc8
commit
656b7c27ca
15 files changed
+809
-315
No files matched your search
@@ -3,22 +3,37 @@ package constant
|
||||
import "hk4e/pkg/endec"
|
||||
|
||||
var (
|
||||
DEFAULT_ABILITY_HASH_CODE []int32
|
||||
DEFAULT_ABILITY_HASH_CODE []int32
|
||||
DEFAULT_TEAM_ABILITY_HASH_CODE []int32
|
||||
)
|
||||
|
||||
func init() {
|
||||
defaultAbilityStringList := []string{
|
||||
abilityList := []string{
|
||||
"Avatar_DefaultAbility_VisionReplaceDieInvincible",
|
||||
"Avatar_DefaultAbility_AvartarInShaderChange",
|
||||
"Avatar_SprintBS_Invincible",
|
||||
"Avatar_Freeze_Duration_Reducer",
|
||||
"Avatar_Attack_ReviveEnergy",
|
||||
"Avatar_Component_Initializer",
|
||||
"Avatar_HDMesh_Controller",
|
||||
"Avatar_Trampoline_Jump_Controller",
|
||||
"Avatar_FallAnthem_Achievement_Listener",
|
||||
"GrapplingHookSkill_Ability",
|
||||
"Avatar_PlayerBoy_DiveStamina_Reduction",
|
||||
"Ability_Avatar_Dive_SealEcho",
|
||||
"Absorb_SealEcho_Bullet_01",
|
||||
"Absorb_SealEcho_Bullet_02",
|
||||
"Ability_Avatar_Dive_CrabShield",
|
||||
"ActivityAbility_Absorb_Shoot",
|
||||
"SceneAbility_DiveVolume",
|
||||
}
|
||||
DEFAULT_ABILITY_HASH_CODE = make([]int32, 0)
|
||||
for _, defaultAbilityString := range defaultAbilityStringList {
|
||||
DEFAULT_ABILITY_HASH_CODE = append(DEFAULT_ABILITY_HASH_CODE, endec.Hk4eAbilityHashCode(defaultAbilityString))
|
||||
for _, ability := range abilityList {
|
||||
DEFAULT_ABILITY_HASH_CODE = append(DEFAULT_ABILITY_HASH_CODE, endec.Hk4eAbilityHashCode(ability))
|
||||
}
|
||||
abilityList = []string{
|
||||
"Ability_Avatar_Dive_Team",
|
||||
}
|
||||
DEFAULT_TEAM_ABILITY_HASH_CODE = make([]int32, 0)
|
||||
for _, ability := range abilityList {
|
||||
DEFAULT_TEAM_ABILITY_HASH_CODE = append(DEFAULT_TEAM_ABILITY_HASH_CODE, endec.Hk4eAbilityHashCode(ability))
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,7 @@ func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player {
|
||||
EntityId: world.GetPlayerWorldAvatarEntityId(robot, 10000007),
|
||||
})
|
||||
robot.SetPos(&model.Vector{X: 500.0, Y: 900.0, Z: -500.0})
|
||||
robot.WuDi = true
|
||||
return robot
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ func (c *CommandManager) InitController() {
|
||||
c.NewWeatherCommandController(),
|
||||
c.NewClearCommandController(),
|
||||
c.NewDebugCommandController(),
|
||||
c.NewWudiCommandController(),
|
||||
c.NewEnergyCommandController(),
|
||||
c.NewStaminaCommandController(),
|
||||
}
|
||||
c.RegAllController(controllerList...)
|
||||
}
|
||||
@@ -955,3 +958,151 @@ func (c *CommandManager) DebugCommand(content *CommandContent) bool {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (c *CommandManager) NewWudiCommandController() *CommandController {
|
||||
return &CommandController{
|
||||
Name: "开关无敌",
|
||||
AliasList: []string{"wudi"},
|
||||
Description: "<color=#FFFFCC>{alias}</color> <color=#FFCC99>开关无敌</color>",
|
||||
UsageList: []string{
|
||||
"{alias} global avatar <on/off> 开关玩家无敌",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Func: c.WudiCommand,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CommandManager) WudiCommand(content *CommandContent) bool {
|
||||
var mode1 string // 模式
|
||||
var mode2 string // 模式
|
||||
var param1 string // 参数
|
||||
|
||||
return content.Dynamic("string", func(param any) bool {
|
||||
// 模式
|
||||
mode1 = param.(string)
|
||||
return true
|
||||
}).Dynamic("string", func(param any) bool {
|
||||
// 模式
|
||||
mode2 = param.(string)
|
||||
return true
|
||||
}).Option("string", func(param any) bool {
|
||||
// 参数1
|
||||
param1 = param.(string)
|
||||
return true
|
||||
}).Execute(func() bool {
|
||||
switch mode1 {
|
||||
case "global":
|
||||
switch mode2 {
|
||||
case "avatar":
|
||||
switch param1 {
|
||||
case "on":
|
||||
c.gmCmd.GMSetPlayerWuDi(content.AssignPlayer.PlayerId, true)
|
||||
content.SendSuccMessage(content.Executor, "已开启玩家无敌,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
case "off":
|
||||
c.gmCmd.GMSetPlayerWuDi(content.AssignPlayer.PlayerId, false)
|
||||
content.SendSuccMessage(content.Executor, "已关闭玩家无敌,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (c *CommandManager) NewEnergyCommandController() *CommandController {
|
||||
return &CommandController{
|
||||
Name: "元素能量",
|
||||
AliasList: []string{"energy"},
|
||||
Description: "<color=#FFFFCC>{alias}</color> <color=#FFCC99>元素能量</color>",
|
||||
UsageList: []string{
|
||||
"{alias} infinite <on/off> 开关无限元素爆发",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Func: c.EnergyCommand,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CommandManager) EnergyCommand(content *CommandContent) bool {
|
||||
var mode1 string // 模式
|
||||
var param1 string // 参数
|
||||
|
||||
return content.Dynamic("string", func(param any) bool {
|
||||
// 模式
|
||||
mode1 = param.(string)
|
||||
return true
|
||||
}).Option("string", func(param any) bool {
|
||||
// 参数1
|
||||
param1 = param.(string)
|
||||
return true
|
||||
}).Execute(func() bool {
|
||||
switch mode1 {
|
||||
case "infinite":
|
||||
switch param1 {
|
||||
case "on":
|
||||
c.gmCmd.GMSetPlayerEnergyInf(content.AssignPlayer.PlayerId, true)
|
||||
content.SendSuccMessage(content.Executor, "已开启无限元素爆发,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
case "off":
|
||||
c.gmCmd.GMSetPlayerEnergyInf(content.AssignPlayer.PlayerId, false)
|
||||
content.SendSuccMessage(content.Executor, "已关闭无限元素爆发,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (c *CommandManager) NewStaminaCommandController() *CommandController {
|
||||
return &CommandController{
|
||||
Name: "无限耐力",
|
||||
AliasList: []string{"stamina"},
|
||||
Description: "<color=#FFFFCC>{alias}</color> <color=#FFCC99>无限耐力</color>",
|
||||
UsageList: []string{
|
||||
"{alias} infinite <on/off> 开关无限耐力",
|
||||
},
|
||||
Perm: CommandPermNormal,
|
||||
Func: c.StaminaCommand,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CommandManager) StaminaCommand(content *CommandContent) bool {
|
||||
var mode1 string // 模式
|
||||
var param1 string // 参数
|
||||
|
||||
return content.Dynamic("string", func(param any) bool {
|
||||
// 模式
|
||||
mode1 = param.(string)
|
||||
return true
|
||||
}).Option("string", func(param any) bool {
|
||||
// 参数1
|
||||
param1 = param.(string)
|
||||
return true
|
||||
}).Execute(func() bool {
|
||||
switch mode1 {
|
||||
case "infinite":
|
||||
switch param1 {
|
||||
case "on":
|
||||
c.gmCmd.GMSetPlayerStaminaInf(content.AssignPlayer.PlayerId, true)
|
||||
content.SendSuccMessage(content.Executor, "已开启无限耐力,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
case "off":
|
||||
c.gmCmd.GMSetPlayerStaminaInf(content.AssignPlayer.PlayerId, false)
|
||||
content.SendSuccMessage(content.Executor, "已关闭无限耐力,指定UID:%v。", content.AssignPlayer.PlayerId)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -202,9 +202,13 @@ func (g *GMCmd) GMKillSelf(userId uint32) {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
// 激活的角色id
|
||||
activeAvatarId := player.GetDbTeam().GetActiveAvatarId()
|
||||
// 杀死角色
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
// 杀死当前活跃角色
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
GAME.KillPlayerAvatar(player, activeAvatarId, proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
}
|
||||
|
||||
@@ -506,6 +510,59 @@ func (g *GMCmd) GMFreeMode(userId uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
// GMChangeSkillDepot 切换当前角色技能库
|
||||
func (g *GMCmd) GMChangeSkillDepot(userId uint32, skillDepotId uint32) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
GAME.ChangePlayerAvatarSkillDepot(player.PlayerId, world.GetPlayerActiveAvatarId(player), skillDepotId, 0)
|
||||
}
|
||||
|
||||
// GMSetPlayerWuDi 开启关闭玩家角色无敌
|
||||
func (g *GMCmd) GMSetPlayerWuDi(userId uint32, open bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.WuDi = open
|
||||
}
|
||||
|
||||
// GMSetPlayerEnergyInf 开启关闭玩家角色无限能量
|
||||
func (g *GMCmd) GMSetPlayerEnergyInf(userId uint32, open bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.EnergyInf = open
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
GAME.AddPlayerAvatarEnergy(player.PlayerId, worldAvatar.GetAvatarId(), 0.0, true)
|
||||
}
|
||||
}
|
||||
|
||||
// GMSetPlayerStaminaInf 开启关闭玩家无限耐力
|
||||
func (g *GMCmd) GMSetPlayerStaminaInf(userId uint32, open bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
player.StaminaInf = open
|
||||
}
|
||||
|
||||
// 系统级GM指令
|
||||
|
||||
// TODO 不知道为什么0个参数的函数会反射调用失败
|
||||
|
||||
@@ -376,6 +376,7 @@ func (p *PluginPubg) StartPubg() {
|
||||
FightPropMap: avatar.FightPropMap,
|
||||
})
|
||||
p.playerHitTimeMap[player.PlayerId] = 0
|
||||
player.StaminaInf = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+107
-69
@@ -367,28 +367,13 @@ func (w *World) AddPlayer(player *model.Player) {
|
||||
// 将玩家自身当前的队伍角色信息复制到世界的玩家本地队伍
|
||||
dbTeam := player.GetDbTeam()
|
||||
team := dbTeam.GetActiveTeam()
|
||||
if player.PlayerId == w.owner.PlayerId {
|
||||
w.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
||||
} else {
|
||||
activeAvatarId := dbTeam.GetActiveAvatarId()
|
||||
w.SetPlayerLocalTeam(player, []uint32{activeAvatarId})
|
||||
}
|
||||
w.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
||||
w.SetPlayerActiveAvatarId(player, dbTeam.GetActiveAvatarId())
|
||||
if WORLD_MANAGER.IsAiWorld(w) {
|
||||
w.AddMultiplayerTeam(player)
|
||||
} else {
|
||||
w.UpdateMultiplayerTeam()
|
||||
}
|
||||
for _, worldPlayer := range w.playerMap {
|
||||
list := w.GetPlayerWorldAvatarList(worldPlayer)
|
||||
maxIndex := len(list) - 1
|
||||
worldPlayerDbTeam := worldPlayer.GetDbTeam()
|
||||
index := int(worldPlayerDbTeam.CurrAvatarIndex)
|
||||
if index > maxIndex {
|
||||
w.SetPlayerAvatarIndex(worldPlayer, 0)
|
||||
} else {
|
||||
w.SetPlayerAvatarIndex(worldPlayer, index)
|
||||
}
|
||||
}
|
||||
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
scene.AddPlayer(player)
|
||||
@@ -404,8 +389,8 @@ func (w *World) RemovePlayer(player *model.Player) {
|
||||
delete(w.playerMap, player.PlayerId)
|
||||
delete(w.playerFirstEnterMap, player.PlayerId)
|
||||
delete(w.multiplayerTeam.localTeamMap, player.PlayerId)
|
||||
delete(w.multiplayerTeam.localAvatarIndexMap, player.PlayerId)
|
||||
delete(w.multiplayerTeam.localTeamEntityMap, player.PlayerId)
|
||||
delete(w.multiplayerTeam.localActiveAvatarMap, player.PlayerId)
|
||||
if WORLD_MANAGER.IsAiWorld(w) {
|
||||
w.RemoveMultiplayerTeam(player)
|
||||
} else {
|
||||
@@ -556,25 +541,25 @@ func (w *World) GetPlayerWorldAvatarWeaponEntityId(player *model.Player, avatarI
|
||||
return worldAvatar.weaponEntityId
|
||||
}
|
||||
|
||||
// GetPlayerAvatarIndex 获取某玩家当前角色索引
|
||||
func (w *World) GetPlayerAvatarIndex(player *model.Player) int {
|
||||
return w.multiplayerTeam.localAvatarIndexMap[player.PlayerId]
|
||||
}
|
||||
|
||||
// SetPlayerAvatarIndex 设置某玩家当前角色索引
|
||||
func (w *World) SetPlayerAvatarIndex(player *model.Player, index int) {
|
||||
if index > len(w.GetPlayerLocalTeam(player))-1 {
|
||||
return
|
||||
}
|
||||
w.multiplayerTeam.localAvatarIndexMap[player.PlayerId] = index
|
||||
}
|
||||
|
||||
// GetPlayerActiveAvatarId 获取玩家当前活跃角色id
|
||||
func (w *World) GetPlayerActiveAvatarId(player *model.Player) uint32 {
|
||||
avatarIndex := w.GetPlayerAvatarIndex(player)
|
||||
return w.multiplayerTeam.localActiveAvatarMap[player.PlayerId]
|
||||
}
|
||||
|
||||
// SetPlayerActiveAvatarId 设置玩家当前活跃角色id
|
||||
func (w *World) SetPlayerActiveAvatarId(player *model.Player, avatarId uint32) {
|
||||
localTeam := w.GetPlayerLocalTeam(player)
|
||||
worldTeamAvatar := localTeam[avatarIndex]
|
||||
return worldTeamAvatar.avatarId
|
||||
exist := false
|
||||
for _, worldAvatar := range localTeam {
|
||||
if worldAvatar.avatarId == avatarId {
|
||||
exist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
w.multiplayerTeam.localActiveAvatarMap[player.PlayerId] = avatarId
|
||||
}
|
||||
|
||||
// GetPlayerAvatarIndexByAvatarId 获取玩家某角色的索引
|
||||
@@ -594,6 +579,9 @@ func (w *World) GetPlayerActiveAvatarEntity(player *model.Player) *Entity {
|
||||
avatarEntityId := w.GetPlayerWorldAvatarEntityId(player, activeAvatarId)
|
||||
scene := w.GetSceneById(player.SceneId)
|
||||
entity := scene.GetEntity(avatarEntityId)
|
||||
if entity == nil {
|
||||
panic("fuck")
|
||||
}
|
||||
return entity
|
||||
}
|
||||
|
||||
@@ -609,9 +597,10 @@ func (w *World) IsPlayerActiveAvatarEntity(player *model.Player, entityId uint32
|
||||
type MultiplayerTeam struct {
|
||||
// key:uid value:玩家的本地队伍
|
||||
localTeamMap map[uint32][]*WorldAvatar
|
||||
// key:uid value:玩家当前角色索引
|
||||
localAvatarIndexMap map[uint32]int
|
||||
localTeamEntityMap map[uint32]uint32
|
||||
// key:uid value:玩家的本地队伍实体id
|
||||
localTeamEntityMap map[uint32]uint32
|
||||
// key:uid value:玩家当前活跃角色id
|
||||
localActiveAvatarMap map[uint32]uint32
|
||||
// 最终的世界队伍
|
||||
worldTeam []*WorldAvatar
|
||||
}
|
||||
@@ -619,8 +608,8 @@ type MultiplayerTeam struct {
|
||||
func CreateMultiplayerTeam() (r *MultiplayerTeam) {
|
||||
r = new(MultiplayerTeam)
|
||||
r.localTeamMap = make(map[uint32][]*WorldAvatar)
|
||||
r.localAvatarIndexMap = make(map[uint32]int)
|
||||
r.localTeamEntityMap = make(map[uint32]uint32)
|
||||
r.localActiveAvatarMap = make(map[uint32]uint32)
|
||||
r.worldTeam = make([]*WorldAvatar, 0)
|
||||
return r
|
||||
}
|
||||
@@ -692,27 +681,6 @@ func (w *World) SetPlayerLocalTeam(player *model.Player, avatarIdList []uint32)
|
||||
w.multiplayerTeam.localTeamMap[player.PlayerId] = newLocalTeam
|
||||
}
|
||||
|
||||
func (w *World) copyLocalTeamToWorld(start int, end int, peerId uint32) {
|
||||
player := w.GetPlayerByPeerId(peerId)
|
||||
localTeam := w.GetPlayerLocalTeam(player)
|
||||
localTeamIndex := 0
|
||||
for index := start; index <= end; index++ {
|
||||
if localTeamIndex >= len(localTeam) {
|
||||
w.multiplayerTeam.worldTeam[index] = &WorldAvatar{
|
||||
uid: 0,
|
||||
avatarId: 0,
|
||||
avatarEntityId: 0,
|
||||
weaponEntityId: 0,
|
||||
abilityMap: nil,
|
||||
modifierMap: nil,
|
||||
}
|
||||
continue
|
||||
}
|
||||
w.multiplayerTeam.worldTeam[index] = localTeam[localTeamIndex]
|
||||
localTeamIndex++
|
||||
}
|
||||
}
|
||||
|
||||
// 为了实现大世界无限人数写的
|
||||
// 现在看来把世界里所有人放进队伍里发给客户端超过8个客户端会崩溃
|
||||
// 看来还是不能简单的走通用逻辑 需要对大世界场景队伍做特殊处理 欺骗客户端其他玩家仅仅以场景角色实体的形式出现
|
||||
@@ -743,25 +711,95 @@ func (w *World) UpdateMultiplayerTeam() {
|
||||
switch playerNum {
|
||||
case 1:
|
||||
// 1P*4
|
||||
w.copyLocalTeamToWorld(0, 3, 1)
|
||||
p1 := w.GetPlayerByPeerId(1)
|
||||
p1LocalTeam := w.GetPlayerLocalTeam(p1)
|
||||
for index := 0; index <= 3; index++ {
|
||||
worldAvatar := &WorldAvatar{
|
||||
uid: 0,
|
||||
avatarId: 0,
|
||||
avatarEntityId: 0,
|
||||
weaponEntityId: 0,
|
||||
abilityMap: nil,
|
||||
modifierMap: nil,
|
||||
}
|
||||
if index < len(p1LocalTeam) {
|
||||
worldAvatar = p1LocalTeam[index]
|
||||
}
|
||||
w.multiplayerTeam.worldTeam[index] = worldAvatar
|
||||
}
|
||||
case 2:
|
||||
// 1P*2 + 2P*2
|
||||
w.copyLocalTeamToWorld(0, 1, 1)
|
||||
w.copyLocalTeamToWorld(2, 3, 2)
|
||||
for index := 0; index <= 3; index++ {
|
||||
switch index {
|
||||
case 0:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(1, true)
|
||||
case 1:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(1, false)
|
||||
case 2:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(2, true)
|
||||
case 3:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(2, false)
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
// 1P*2 + 2P*1 + 3P*1
|
||||
w.copyLocalTeamToWorld(0, 1, 1)
|
||||
w.copyLocalTeamToWorld(2, 2, 2)
|
||||
w.copyLocalTeamToWorld(3, 3, 3)
|
||||
for index := 0; index <= 3; index++ {
|
||||
switch index {
|
||||
case 0:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(1, true)
|
||||
case 1:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(1, false)
|
||||
case 2:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(2, true)
|
||||
case 3:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(3, true)
|
||||
}
|
||||
}
|
||||
case 4:
|
||||
// 1P*1 + 2P*1 + 3P*1 + 4P*1
|
||||
w.copyLocalTeamToWorld(0, 0, 1)
|
||||
w.copyLocalTeamToWorld(1, 1, 2)
|
||||
w.copyLocalTeamToWorld(2, 2, 3)
|
||||
w.copyLocalTeamToWorld(3, 3, 4)
|
||||
for index := 0; index <= 3; index++ {
|
||||
switch index {
|
||||
case 0:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(1, true)
|
||||
case 1:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(2, true)
|
||||
case 2:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(3, true)
|
||||
case 3:
|
||||
w.multiplayerTeam.worldTeam[index] = w.SelectPlayerWorldAvatar(4, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (w *World) SelectPlayerWorldAvatar(peerId uint32, active bool) *WorldAvatar {
|
||||
worldAvatar := &WorldAvatar{
|
||||
uid: 0,
|
||||
avatarId: 0,
|
||||
avatarEntityId: 0,
|
||||
weaponEntityId: 0,
|
||||
abilityMap: nil,
|
||||
modifierMap: nil,
|
||||
}
|
||||
player := w.GetPlayerByPeerId(peerId)
|
||||
localTeam := w.GetPlayerLocalTeam(player)
|
||||
activeAvatarId := w.GetPlayerActiveAvatarId(player)
|
||||
for _, wa := range localTeam {
|
||||
if active {
|
||||
if wa.avatarId == activeAvatarId {
|
||||
worldAvatar = wa
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if wa.avatarId != activeAvatarId {
|
||||
worldAvatar = wa
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return worldAvatar
|
||||
}
|
||||
|
||||
// 世界聊天
|
||||
|
||||
func (w *World) AddChat(chatInfo *proto.ChatInfo) {
|
||||
|
||||
+168
-31
@@ -498,6 +498,8 @@ func (g *Game) UpgradePlayerAvatar(player *model.Player, avatar *model.Avatar, e
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
// 角色属性表更新通知
|
||||
g.SendMsg(cmd.AvatarPropNotify, player.PlayerId, player.ClientSeq, g.PacketAvatarPropNotify(avatar))
|
||||
|
||||
g.AddPlayerAvatarHp(player.PlayerId, avatar.AvatarId, 0.0, true, proto.ChangHpReason_CHANGE_HP_ADD_UPGRADE)
|
||||
}
|
||||
|
||||
// UpdatePlayerAvatarFightProp 更新玩家角色战斗属性
|
||||
@@ -507,20 +509,19 @@ func (g *Game) UpdatePlayerAvatarFightProp(userId uint32, avatarId uint32) {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil || WORLD_MANAGER.IsAiWorld(world) {
|
||||
return
|
||||
}
|
||||
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatar.AvatarId)
|
||||
return
|
||||
}
|
||||
// 角色初始化面板
|
||||
dbAvatar.InitAvatarFightProp(avatar)
|
||||
|
||||
// 更新角色面板
|
||||
dbAvatar.UpdateAvatarFightProp(avatar)
|
||||
|
||||
avatarFightPropNotify := &proto.AvatarFightPropNotify{
|
||||
AvatarGuid: avatar.Guid,
|
||||
@@ -529,53 +530,189 @@ func (g *Game) UpdatePlayerAvatarFightProp(userId uint32, avatarId uint32) {
|
||||
g.SendMsg(cmd.AvatarFightPropNotify, userId, player.ClientSeq, avatarFightPropNotify)
|
||||
}
|
||||
|
||||
func (g *Game) ChangePlayerAvatarElementType(player *model.Player, elementType int) {
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar := dbAvatar.AvatarMap[dbAvatar.MainCharAvatarId]
|
||||
switchSkillDepotId := uint32(0)
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
|
||||
if avatarDataConfig == nil {
|
||||
func (g *Game) ChangePlayerAvatarSkillDepot(userId uint32, avatarId uint32, changeSkillDepotId uint32, elementType int) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
for _, skillDepotId := range avatarDataConfig.SkillDepotIdList {
|
||||
skillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(skillDepotId)
|
||||
if skillDepotDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
avatarSkillDataConfig := gdconf.GetAvatarSkillDataById(skillDepotDataConfig.EnergySkill)
|
||||
if avatarSkillDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
if avatarSkillDataConfig.CostElemType != int32(elementType) {
|
||||
continue
|
||||
}
|
||||
switchSkillDepotId = uint32(skillDepotId)
|
||||
break
|
||||
}
|
||||
dbAvatar.SwitchSkillDepot(avatar.AvatarId, switchSkillDepotId)
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatar.AvatarId)
|
||||
if changeSkillDepotId == 0 {
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatarId))
|
||||
if avatarDataConfig == nil {
|
||||
return
|
||||
}
|
||||
for _, skillDepotId := range avatarDataConfig.SkillDepotIdList {
|
||||
skillDepotDataConfig := gdconf.GetAvatarSkillDepotDataById(skillDepotId)
|
||||
if skillDepotDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
avatarSkillDataConfig := gdconf.GetAvatarSkillDataById(skillDepotDataConfig.EnergySkill)
|
||||
if avatarSkillDataConfig == nil {
|
||||
continue
|
||||
}
|
||||
if avatarSkillDataConfig.CostElemType != int32(elementType) {
|
||||
continue
|
||||
}
|
||||
changeSkillDepotId = uint32(skillDepotId)
|
||||
break
|
||||
}
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
return
|
||||
}
|
||||
|
||||
dbAvatar.ChangeSkillDepot(avatarId, changeSkillDepotId)
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatarId)
|
||||
|
||||
g.SendMsg(cmd.AvatarSkillDepotChangeNotify, player.PlayerId, player.ClientSeq, &proto.AvatarSkillDepotChangeNotify{
|
||||
EntityId: entityId,
|
||||
AvatarGuid: avatar.Guid,
|
||||
SkillDepotId: switchSkillDepotId,
|
||||
SkillDepotId: changeSkillDepotId,
|
||||
SkillLevelMap: avatar.SkillLevelMap,
|
||||
})
|
||||
|
||||
g.SendMsg(cmd.AbilityChangeNotify, player.PlayerId, player.ClientSeq, &proto.AbilityChangeNotify{
|
||||
EntityId: entityId,
|
||||
AbilityControlBlock: g.PacketAbilityControlBlock(avatar.AvatarId, switchSkillDepotId),
|
||||
AbilityControlBlock: g.PacketAvatarAbilityControlBlock(avatar.AvatarId, changeSkillDepotId),
|
||||
})
|
||||
|
||||
dbAvatar.SetCurrEnergy(avatar.AvatarId, 0, true)
|
||||
dbAvatar.AddCurrEnergy(avatar.AvatarId, 0, true)
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatar.AvatarId)
|
||||
}
|
||||
|
||||
func (g *Game) AddPlayerAvatarHp(userId uint32, avatarId uint32, value float32, max bool, reason proto.ChangHpReason) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatarId)
|
||||
entity := scene.GetEntity(entityId)
|
||||
fightProp := entity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
deltaHp := float32(0.0)
|
||||
if max {
|
||||
deltaHp = maxHp - currHp
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = maxHp
|
||||
} else {
|
||||
currHp += value
|
||||
deltaHp = value
|
||||
if currHp > maxHp {
|
||||
deltaHp = value - (currHp - maxHp)
|
||||
currHp = maxHp
|
||||
}
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = currHp
|
||||
}
|
||||
g.EntityFightPropUpdateNotifyBroadcast(scene, entity)
|
||||
g.SendMsg(cmd.EntityFightPropChangeReasonNotify, player.PlayerId, player.ClientSeq, &proto.EntityFightPropChangeReasonNotify{
|
||||
PropDelta: deltaHp,
|
||||
ChangeHpReason: reason,
|
||||
EntityId: entity.GetId(),
|
||||
PropType: constant.FIGHT_PROP_CUR_HP,
|
||||
})
|
||||
}
|
||||
|
||||
func (g *Game) SubPlayerAvatarHp(userId uint32, avatarId uint32, value float32, max bool, reason proto.ChangHpReason) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
if player.WuDi {
|
||||
return
|
||||
}
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
entityId := world.GetPlayerWorldAvatarEntityId(player, avatarId)
|
||||
entity := scene.GetEntity(entityId)
|
||||
fightProp := entity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
deltaHp := float32(0.0)
|
||||
if max {
|
||||
deltaHp = currHp
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = 0.0
|
||||
} else {
|
||||
currHp -= value
|
||||
deltaHp = -value
|
||||
if currHp < 0.0 {
|
||||
deltaHp = value - currHp
|
||||
currHp = 0.0
|
||||
}
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = currHp
|
||||
}
|
||||
g.EntityFightPropUpdateNotifyBroadcast(scene, entity)
|
||||
g.SendMsg(cmd.EntityFightPropChangeReasonNotify, player.PlayerId, player.ClientSeq, &proto.EntityFightPropChangeReasonNotify{
|
||||
PropDelta: deltaHp,
|
||||
ChangeHpReason: reason,
|
||||
EntityId: entity.GetId(),
|
||||
PropType: constant.FIGHT_PROP_CUR_HP,
|
||||
})
|
||||
if currHp == 0.0 {
|
||||
var dieType proto.PlayerDieType
|
||||
switch reason {
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_MONSTER:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_KILL_BY_MONSTER
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_GEAR:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_KILL_BY_GEAR
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_FALL:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_FALL
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_DRAWN:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_DRAWN
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_ABYSS:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_ABYSS
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_GM:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_GM
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_CLIMATE_COLD:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_CLIMATE_COLD
|
||||
case proto.ChangHpReason_CHANGE_HP_SUB_STORM_LIGHTNING:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_STORM_LIGHTING
|
||||
default:
|
||||
dieType = proto.PlayerDieType_PLAYER_DIE_GM
|
||||
}
|
||||
g.KillPlayerAvatar(player, entity.GetAvatarEntity().GetAvatarId(), dieType)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) AddPlayerAvatarEnergy(userId uint32, avatarId uint32, value float32, max bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
dbAvatar.AddCurrEnergy(avatarId, float64(value), max)
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
}
|
||||
|
||||
func (g *Game) CostPlayerAvatarEnergy(userId uint32, avatarId uint32, value float32, max bool) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
if player.EnergyInf {
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
dbAvatar.CostCurrEnergy(avatarId, float64(value), max)
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
}
|
||||
|
||||
/************************************************** 打包封装 **************************************************/
|
||||
|
||||
// PacketAvatarInfo 转换角色信息
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hk4e/common/constant"
|
||||
"hk4e/gdconf"
|
||||
"hk4e/gs/model"
|
||||
"hk4e/pkg/alg"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/pkg/reflection"
|
||||
"hk4e/protocol/cmd"
|
||||
@@ -189,64 +189,46 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr
|
||||
logger.Error("not found def entity, DefenseId: %v", attackResult.DefenseId)
|
||||
return
|
||||
}
|
||||
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
if defEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR &&
|
||||
defEntity.GetAvatarEntity().GetUid() == world.GetOwner().PlayerId {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fightProp := defEntity.GetFightProp()
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
if currHp == 0.0 {
|
||||
return
|
||||
}
|
||||
currHp -= attackResult.Damage
|
||||
deltaHp := -attackResult.Damage
|
||||
if currHp < 0.0 {
|
||||
deltaHp -= currHp
|
||||
currHp = 0.0
|
||||
}
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = currHp
|
||||
g.EntityFightPropUpdateNotifyBroadcast(scene, defEntity)
|
||||
switch defEntity.GetEntityType() {
|
||||
case constant.ENTITY_TYPE_AVATAR:
|
||||
g.SendMsg(cmd.EntityFightPropChangeReasonNotify, player.PlayerId, player.ClientSeq, &proto.EntityFightPropChangeReasonNotify{
|
||||
PropDelta: deltaHp,
|
||||
ChangeHpReason: proto.ChangHpReason_CHANGE_HP_SUB_GM,
|
||||
EntityId: defEntity.GetId(),
|
||||
PropType: constant.FIGHT_PROP_CUR_HP,
|
||||
})
|
||||
if currHp == 0.0 {
|
||||
defAvatarEntity := defEntity.GetAvatarEntity()
|
||||
g.KillPlayerAvatar(player, defAvatarEntity.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetUid())
|
||||
if defPlayer == nil {
|
||||
g.SubPlayerAvatarHp(player.PlayerId, defEntity.GetAvatarEntity().GetAvatarId(), attackResult.Damage, false, proto.ChangHpReason_CHANGE_HP_SUB_MONSTER)
|
||||
if WORLD_MANAGER.IsAiWorld(world) {
|
||||
fightProp := defEntity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
if currHp > 0.0 {
|
||||
return
|
||||
}
|
||||
defPlayer := USER_MANAGER.GetOnlineUser(defEntity.GetAvatarEntity().GetUid())
|
||||
if defPlayer == nil {
|
||||
return
|
||||
}
|
||||
atkEntity := scene.GetEntity(attackResult.AttackerId)
|
||||
if atkEntity != nil && atkEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
atkPlayer := USER_MANAGER.GetOnlineUser(atkEntity.GetAvatarEntity().GetUid())
|
||||
if atkPlayer == nil {
|
||||
return
|
||||
}
|
||||
atkEntity := scene.GetEntity(attackResult.AttackerId)
|
||||
if atkEntity != nil && atkEntity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
|
||||
atkAvatarEntity := atkEntity.GetAvatarEntity()
|
||||
atkPlayer := USER_MANAGER.GetOnlineUser(atkAvatarEntity.GetUid())
|
||||
if atkPlayer == nil {
|
||||
return
|
||||
}
|
||||
info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName)
|
||||
g.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
info := fmt.Sprintf("『%v』击败了『%v』。", atkPlayer.NickName, defPlayer.NickName)
|
||||
g.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
|
||||
}
|
||||
}
|
||||
case constant.ENTITY_TYPE_MONSTER:
|
||||
fightProp := defEntity.GetFightProp()
|
||||
currHp := fightProp[constant.FIGHT_PROP_CUR_HP]
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
lastHp := currHp
|
||||
currHp -= attackResult.Damage
|
||||
if currHp < 0.0 {
|
||||
currHp = 0.0
|
||||
}
|
||||
fightProp[constant.FIGHT_PROP_CUR_HP] = currHp
|
||||
g.EntityFightPropUpdateNotifyBroadcast(scene, defEntity)
|
||||
monsterDataConfig := gdconf.GetMonsterDataById(int32(defEntity.GetMonsterEntity().GetMonsterId()))
|
||||
if monsterDataConfig == nil {
|
||||
logger.Error("get monster data config is nil, monsterId: %v", defEntity.GetMonsterEntity().GetMonsterId())
|
||||
break
|
||||
return
|
||||
}
|
||||
lastHpPercent := (currHp - deltaHp) / maxHp * 100.0
|
||||
lastHpPercent := lastHp / maxHp * 100.0
|
||||
currHpPercent := currHp / maxHp * 100.0
|
||||
for _, hpDrop := range monsterDataConfig.HpDropList {
|
||||
if hpDrop.HpPercent >= int32(currHpPercent) && hpDrop.HpPercent <= int32(lastHpPercent) {
|
||||
@@ -261,7 +243,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr
|
||||
gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetEntity.GetGadgetId()))
|
||||
if gadgetDataConfig == nil {
|
||||
logger.Error("get gadget data config is nil, gadgetId: %v", gadgetEntity.GetGadgetId())
|
||||
break
|
||||
return
|
||||
}
|
||||
logger.Debug("[EvtBeingHit] GadgetData: %+v, EntityId: %v, uid: %v", gadgetDataConfig, defEntity.GetId(), player.PlayerId)
|
||||
g.handleGadgetEntityBeHitLow(player, defEntity, attackResult.ElementType)
|
||||
@@ -289,14 +271,22 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
g.SceneWeatherAreaCheck(player, oldPos, pos)
|
||||
// 更新玩家角色实体的位置信息
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
waAvatarEntityId := worldAvatar.GetAvatarEntityId()
|
||||
waAvatarEntity := scene.GetEntity(waAvatarEntityId)
|
||||
waAvatarEntity.SetPos(pos)
|
||||
waAvatarEntity.SetRot(rot)
|
||||
waWeaponEntityId := worldAvatar.GetWeaponEntityId()
|
||||
waWeaponEntity := scene.GetEntity(waWeaponEntityId)
|
||||
waWeaponEntity.SetPos(pos)
|
||||
waWeaponEntity.SetRot(rot)
|
||||
worldAvatarEntityId := worldAvatar.GetAvatarEntityId()
|
||||
worldAvatarEntity := scene.GetEntity(worldAvatarEntityId)
|
||||
if worldAvatarEntity == nil {
|
||||
logger.Error("world avatar entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
|
||||
continue
|
||||
}
|
||||
worldAvatarEntity.SetPos(pos)
|
||||
worldAvatarEntity.SetRot(rot)
|
||||
worldWeaponEntityId := worldAvatar.GetWeaponEntityId()
|
||||
worldWeaponEntity := scene.GetEntity(worldWeaponEntityId)
|
||||
if worldWeaponEntity == nil {
|
||||
logger.Error("world weapon entity is nil, worldAvatar: %+v, uid: %v", worldAvatar, player.PlayerId)
|
||||
continue
|
||||
}
|
||||
worldWeaponEntity.SetPos(pos)
|
||||
worldWeaponEntity.SetRot(rot)
|
||||
}
|
||||
}
|
||||
// 更新场景实体的位置信息
|
||||
@@ -306,26 +296,38 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
|
||||
motionInfo := moveInfo.MotionInfo
|
||||
switch entity.GetEntityType() {
|
||||
case constant.ENTITY_TYPE_AVATAR:
|
||||
// 玩家安全位置更新
|
||||
switch motionInfo.State {
|
||||
case proto.MotionState_MOTION_DANGER_RUN,
|
||||
proto.MotionState_MOTION_RUN,
|
||||
proto.MotionState_MOTION_DANGER_STANDBY_MOVE,
|
||||
proto.MotionState_MOTION_DANGER_STANDBY,
|
||||
proto.MotionState_MOTION_LADDER_TO_STANDBY,
|
||||
proto.MotionState_MOTION_STANDBY_MOVE,
|
||||
proto.MotionState_MOTION_STANDBY,
|
||||
proto.MotionState_MOTION_DANGER_WALK,
|
||||
proto.MotionState_MOTION_WALK,
|
||||
proto.MotionState_MOTION_DASH:
|
||||
// 仅在陆地时更新玩家安全位置
|
||||
case proto.MotionState_MOTION_STANDBY, proto.MotionState_MOTION_WALK, proto.MotionState_MOTION_RUN, proto.MotionState_MOTION_DASH,
|
||||
58, 59, 60, 64, 65, 66:
|
||||
// 更新玩家安全位置
|
||||
player.SetPos(pos)
|
||||
player.SetRot(rot)
|
||||
}
|
||||
// 处理耐力消耗
|
||||
g.ImmediateStamina(player, motionInfo.State)
|
||||
// 坠落撞击死亡
|
||||
if player.Speed == nil {
|
||||
player.Speed = &model.Vector{X: float64(motionInfo.Speed.X), Y: float64(motionInfo.Speed.Y), Z: float64(motionInfo.Speed.Z)}
|
||||
}
|
||||
if motionInfo.State == proto.MotionState_MOTION_FALL_ON_GROUND || motionInfo.State == proto.MotionState_MOTION_FIGHT {
|
||||
oldSpeed := &alg.Vector3{X: float32(player.Speed.X), Y: float32(player.Speed.Y), Z: float32(player.Speed.Z)}
|
||||
newSpeed := &alg.Vector3{X: motionInfo.Speed.X, Y: motionInfo.Speed.Y, Z: motionInfo.Speed.Z}
|
||||
deltaSpeed := alg.Vector3Sub(oldSpeed, newSpeed)
|
||||
deltaSpeedMag := alg.Vector3Magnitude(deltaSpeed)
|
||||
if deltaSpeedMag > 20.0 {
|
||||
logger.Debug("player fall on ground, deltaSpeed: %+v, deltaSpeedMag: %v, uid: %v", deltaSpeed, deltaSpeedMag, player.PlayerId)
|
||||
rate := deltaSpeedMag - 20.0
|
||||
if rate > 10.0 {
|
||||
rate = 10.0
|
||||
}
|
||||
rate /= 10.0
|
||||
fightProp := entity.GetFightProp()
|
||||
maxHp := fightProp[constant.FIGHT_PROP_MAX_HP]
|
||||
g.SubPlayerAvatarHp(player.PlayerId, entity.GetAvatarEntity().GetAvatarId(), maxHp*rate, false, proto.ChangHpReason_CHANGE_HP_SUB_FALL)
|
||||
}
|
||||
}
|
||||
player.Speed = &model.Vector{X: float64(motionInfo.Speed.X), Y: float64(motionInfo.Speed.Y), Z: float64(motionInfo.Speed.Z)}
|
||||
case constant.ENTITY_TYPE_GADGET:
|
||||
// 载具耐力消耗
|
||||
gadgetEntity := entity.GetGadgetEntity()
|
||||
if gadgetEntity.GetGadgetVehicleEntity() != nil {
|
||||
// 处理耐力消耗
|
||||
@@ -344,12 +346,6 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene
|
||||
if !world.IsValidSceneBlockPos(scene.GetId(), float32(newPos.X), 0.0, float32(newPos.Z)) {
|
||||
return
|
||||
}
|
||||
// 服务器处理玩家移动场景区块aoi事件频率限制
|
||||
now := uint64(time.Now().UnixMilli())
|
||||
if now-player.LastSceneBlockAoiMoveTime < 200 {
|
||||
return
|
||||
}
|
||||
player.LastSceneBlockAoiMoveTime = now
|
||||
sceneBlockAoiMap := WORLD_MANAGER.GetSceneBlockAoiMap()
|
||||
aoiManager, exist := sceneBlockAoiMap[player.SceneId]
|
||||
if !exist {
|
||||
@@ -761,8 +757,7 @@ func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message)
|
||||
return
|
||||
}
|
||||
if int32(ntf.SkillId) == avatarSkillDataConfig.AvatarSkillId {
|
||||
dbAvatar.SetCurrEnergy(activeAvatarId, 0, false)
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, activeAvatarId)
|
||||
g.CostPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 0, true)
|
||||
}
|
||||
|
||||
if !WORLD_MANAGER.IsAiWorld(world) {
|
||||
|
||||
@@ -274,7 +274,8 @@ func (g *Game) QuestExec(player *model.Player, questId uint32, questExecType int
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
g.ChangePlayerAvatarElementType(player, elementType)
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
g.ChangePlayerAvatarSkillDepot(player.PlayerId, dbAvatar.MainCharAvatarId, 0, elementType)
|
||||
case constant.QUEST_EXEC_TYPE_SET_IS_FLYABLE:
|
||||
if len(questExec.Param) != 1 {
|
||||
continue
|
||||
|
||||
+20
-20
@@ -240,7 +240,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
TeamEnterInfo: &proto.TeamEnterSceneInfo{
|
||||
TeamEntityId: world.GetPlayerTeamEntityId(player),
|
||||
TeamAbilityInfo: new(proto.AbilitySyncStateInfo),
|
||||
AbilityControlBlock: new(proto.AbilityControlBlock),
|
||||
AbilityControlBlock: g.PacketTeamAbilityControlBlock(),
|
||||
},
|
||||
MpLevelEntityInfo: &proto.MPLevelEntityInfo{
|
||||
EntityId: world.GetMpLevelEntityId(),
|
||||
@@ -635,7 +635,9 @@ func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType p
|
||||
}
|
||||
|
||||
avatar.LifeState = constant.LIFE_STATE_DEAD
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = 0
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = 0.0
|
||||
|
||||
g.EntityFightPropUpdateNotifyBroadcast(scene, entity)
|
||||
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
if avatarId == activeAvatarId {
|
||||
@@ -653,30 +655,23 @@ func (g *Game) KillPlayerAvatar(player *model.Player, avatarId uint32, dieType p
|
||||
|
||||
// RevivePlayerAvatar 复活玩家活跃角色实体
|
||||
func (g *Game) RevivePlayerAvatar(player *model.Player, avatarId uint32) {
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
avatar, exist := dbAvatar.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("get db avatar is nil, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
|
||||
avatar.LifeState = constant.LIFE_STATE_ALIVE
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = 100
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = 100.0
|
||||
|
||||
g.SendMsg(cmd.AvatarFightPropUpdateNotify, player.PlayerId, player.ClientSeq, &proto.AvatarFightPropUpdateNotify{
|
||||
AvatarGuid: avatar.Guid,
|
||||
FightPropMap: avatar.FightPropMap,
|
||||
})
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
return
|
||||
}
|
||||
worldAvatar := world.GetPlayerWorldAvatar(player, avatarId)
|
||||
if worldAvatar == nil {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
entity := scene.GetEntity(worldAvatar.GetAvatarEntityId())
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, avatarId)
|
||||
|
||||
ntf := &proto.AvatarLifeStateChangeNotify{
|
||||
AvatarGuid: avatar.Guid,
|
||||
@@ -686,8 +681,13 @@ func (g *Game) RevivePlayerAvatar(player *model.Player, avatarId uint32) {
|
||||
}
|
||||
g.SendToWorldA(world, cmd.AvatarLifeStateChangeNotify, 0, ntf, 0)
|
||||
|
||||
worldAvatar := world.GetPlayerWorldAvatar(player, avatarId)
|
||||
if worldAvatar == nil {
|
||||
return
|
||||
}
|
||||
entity := scene.GetEntity(worldAvatar.GetAvatarEntityId())
|
||||
entity.SetLifeState(constant.LIFE_STATE_ALIVE)
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 100
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 100.0
|
||||
}
|
||||
|
||||
// KillEntity 杀死实体
|
||||
@@ -699,7 +699,7 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
|
||||
// 设置血量
|
||||
entity.SetLastDieType(int32(dieType))
|
||||
entity.SetLifeState(constant.LIFE_STATE_DEAD)
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 0
|
||||
entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] = 0.0
|
||||
ntf := &proto.LifeStateChangeNotify{
|
||||
EntityId: entity.GetId(),
|
||||
LifeState: uint32(entity.GetLifeState()),
|
||||
|
||||
@@ -322,14 +322,7 @@ func (g *Game) UpdateVehicleStamina(player *model.Player, vehicleEntity *Entity,
|
||||
|
||||
// UpdatePlayerStamina 更新玩家耐力
|
||||
func (g *Game) UpdatePlayerStamina(player *model.Player, staminaCost int32) {
|
||||
// 大世界无限耐力
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
// 大世界不扣除耐力 但可以回复
|
||||
if WORLD_MANAGER.IsAiWorld(world) && staminaCost < 0 {
|
||||
if player.StaminaInf && staminaCost < 0 {
|
||||
return
|
||||
}
|
||||
// 耐力消耗为0代表不更改 仍然执行后面的话会导致回复出问题
|
||||
|
||||
+127
-41
@@ -34,20 +34,8 @@ func (g *Game) ChangeAvatarReq(player *model.Player, payloadMsg pb.Message) {
|
||||
func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.SetUpAvatarTeamReq)
|
||||
teamId := req.TeamId
|
||||
avatarGuidList := req.AvatarTeamGuidList
|
||||
currAvatarGuid := req.CurAvatarGuid
|
||||
|
||||
if teamId <= 0 || teamId >= 5 {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
dbTeam := player.GetDbTeam()
|
||||
if (teamId == uint32(dbTeam.GetActiveTeamId()) && len(avatarGuidList) == 0) || len(avatarGuidList) > 4 {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
avatarIdList := make([]uint32, 0)
|
||||
for _, avatarGuid := range avatarGuidList {
|
||||
for _, avatarGuid := range req.AvatarTeamGuidList {
|
||||
avatar, ok := player.GameObjectGuidMap[avatarGuid].(*model.Avatar)
|
||||
if !ok {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
@@ -55,14 +43,34 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
avatarIdList = append(avatarIdList, avatar.AvatarId)
|
||||
}
|
||||
currAvatar, ok := player.GameObjectGuidMap[currAvatarGuid].(*model.Avatar)
|
||||
currAvatar, ok := player.GameObjectGuidMap[req.CurAvatarGuid].(*model.Avatar)
|
||||
if !ok {
|
||||
logger.Error("get curr avatar error, avatarGuid: %v", currAvatarGuid)
|
||||
logger.Error("get curr avatar error, avatarGuid: %v", req.CurAvatarGuid)
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
|
||||
if teamId <= 0 || teamId >= 5 {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
dbTeam := player.GetDbTeam()
|
||||
if (teamId == uint32(dbTeam.GetActiveTeamId()) && len(avatarIdList) == 0) || len(avatarIdList) > 4 {
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
g.SendError(cmd.SetUpAvatarTeamRsp, player, &proto.SetUpAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
|
||||
oldAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
g.ChangeTeam(player, teamId, avatarIdList, currAvatar.AvatarId)
|
||||
newAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
|
||||
rsp := &proto.SetUpAvatarTeamRsp{
|
||||
TeamId: req.TeamId,
|
||||
@@ -70,6 +78,22 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
AvatarTeamGuidList: req.AvatarTeamGuidList,
|
||||
}
|
||||
g.SendMsg(cmd.SetUpAvatarTeamRsp, player.PlayerId, player.ClientSeq, rsp)
|
||||
|
||||
if player.ClientVersion >= 400 && oldAvatarEntity.GetId() != newAvatarEntity.GetId() {
|
||||
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
|
||||
DisappearType: proto.VisionType_VISION_REPLACE,
|
||||
EntityList: []uint32{oldAvatarEntity.GetId()},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0)
|
||||
|
||||
sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId())
|
||||
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
|
||||
AppearType: proto.VisionType_VISION_REPLACE,
|
||||
Param: oldAvatarEntity.GetId(),
|
||||
EntityList: []*proto.SceneEntityInfo{sceneEntityInfo},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, player.ClientSeq, sceneEntityAppearNotify, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
|
||||
@@ -78,47 +102,62 @@ func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Messag
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
if world.IsMultiplayerWorld() {
|
||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
|
||||
oldAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
|
||||
dbTeam := player.GetDbTeam()
|
||||
team := dbTeam.GetTeamByIndex(uint8(teamId) - 1)
|
||||
if team == nil || len(team.GetAvatarIdList()) == 0 {
|
||||
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
|
||||
return
|
||||
}
|
||||
dbTeam.CurrTeamIndex = uint8(teamId) - 1
|
||||
dbTeam.CurrAvatarIndex = 0
|
||||
world.SetPlayerAvatarIndex(player, 0)
|
||||
|
||||
world.SetPlayerLocalTeam(player, team.GetAvatarIdList())
|
||||
world.SetPlayerActiveAvatarId(player, dbTeam.GetActiveAvatarId())
|
||||
world.UpdateMultiplayerTeam()
|
||||
world.UpdatePlayerWorldAvatar(player)
|
||||
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerId, player.ClientSeq, sceneTeamUpdateNotify)
|
||||
|
||||
newAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
|
||||
chooseCurAvatarTeamRsp := &proto.ChooseCurAvatarTeamRsp{
|
||||
CurTeamId: teamId,
|
||||
}
|
||||
g.SendMsg(cmd.ChooseCurAvatarTeamRsp, player.PlayerId, player.ClientSeq, chooseCurAvatarTeamRsp)
|
||||
|
||||
if player.ClientVersion >= 400 && oldAvatarEntity.GetId() != newAvatarEntity.GetId() {
|
||||
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
|
||||
DisappearType: proto.VisionType_VISION_REPLACE,
|
||||
EntityList: []uint32{oldAvatarEntity.GetId()},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0)
|
||||
|
||||
sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId())
|
||||
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
|
||||
AppearType: proto.VisionType_VISION_REPLACE,
|
||||
Param: oldAvatarEntity.GetId(),
|
||||
EntityList: []*proto.SceneEntityInfo{sceneEntityInfo},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, player.ClientSeq, sceneEntityAppearNotify, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
|
||||
avatarGuidList := req.AvatarGuidList
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
if WORLD_MANAGER.IsAiWorld(world) || !world.IsMultiplayerWorld() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
|
||||
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
|
||||
return
|
||||
}
|
||||
avatarIdList := make([]uint32, 0)
|
||||
for _, avatarGuid := range avatarGuidList {
|
||||
for _, avatarGuid := range req.AvatarGuidList {
|
||||
avatar, ok := player.GameObjectGuidMap[avatarGuid].(*model.Avatar)
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarGuid: %v", avatarGuid)
|
||||
@@ -127,28 +166,57 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
|
||||
avatarId := avatar.AvatarId
|
||||
avatarIdList = append(avatarIdList, avatarId)
|
||||
}
|
||||
world.SetPlayerLocalTeam(player, avatarIdList)
|
||||
world.UpdateMultiplayerTeam()
|
||||
world.UpdatePlayerWorldAvatar(player)
|
||||
|
||||
currAvatarGuid := req.CurAvatarGuid
|
||||
currAvatar, ok := player.GameObjectGuidMap[currAvatarGuid].(*model.Avatar)
|
||||
currAvatar, ok := player.GameObjectGuidMap[req.CurAvatarGuid].(*model.Avatar)
|
||||
if !ok {
|
||||
logger.Error("avatar error, avatarGuid: %v", currAvatarGuid)
|
||||
logger.Error("avatar error, avatarGuid: %v", req.CurAvatarGuid)
|
||||
return
|
||||
}
|
||||
currAvatarId := currAvatar.AvatarId
|
||||
newAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
|
||||
world.SetPlayerAvatarIndex(player, newAvatarIndex)
|
||||
|
||||
world := WORLD_MANAGER.GetWorldById(player.WorldId)
|
||||
if world == nil {
|
||||
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
if WORLD_MANAGER.IsAiWorld(world) || !world.IsMultiplayerWorld() || len(avatarIdList) == 0 || len(avatarIdList) > 4 {
|
||||
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
|
||||
return
|
||||
}
|
||||
|
||||
oldAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
|
||||
world.SetPlayerLocalTeam(player, avatarIdList)
|
||||
world.SetPlayerActiveAvatarId(player, currAvatarId)
|
||||
world.UpdateMultiplayerTeam()
|
||||
world.UpdatePlayerWorldAvatar(player)
|
||||
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
g.SendToWorldA(world, cmd.SceneTeamUpdateNotify, player.ClientSeq, sceneTeamUpdateNotify, 0)
|
||||
|
||||
newAvatarEntity := world.GetPlayerActiveAvatarEntity(player)
|
||||
|
||||
changeMpTeamAvatarRsp := &proto.ChangeMpTeamAvatarRsp{
|
||||
CurAvatarGuid: req.CurAvatarGuid,
|
||||
AvatarGuidList: req.AvatarGuidList,
|
||||
}
|
||||
g.SendMsg(cmd.ChangeMpTeamAvatarRsp, player.PlayerId, player.ClientSeq, changeMpTeamAvatarRsp)
|
||||
|
||||
if player.ClientVersion >= 400 && oldAvatarEntity.GetId() != newAvatarEntity.GetId() {
|
||||
sceneEntityDisappearNotify := &proto.SceneEntityDisappearNotify{
|
||||
DisappearType: proto.VisionType_VISION_REPLACE,
|
||||
EntityList: []uint32{oldAvatarEntity.GetId()},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityDisappearNotify, player.ClientSeq, sceneEntityDisappearNotify, 0)
|
||||
|
||||
sceneEntityInfo := g.PacketSceneEntityInfoAvatar(scene, player, newAvatarEntity.GetAvatarEntity().GetAvatarId())
|
||||
sceneEntityAppearNotify := &proto.SceneEntityAppearNotify{
|
||||
AppearType: proto.VisionType_VISION_REPLACE,
|
||||
Param: oldAvatarEntity.GetId(),
|
||||
EntityList: []*proto.SceneEntityInfo{sceneEntityInfo},
|
||||
}
|
||||
g.SendToSceneA(scene, cmd.SceneEntityAppearNotify, player.ClientSeq, sceneEntityAppearNotify, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) AvatarDieAnimationEndReq(player *model.Player, payloadMsg pb.Message) {
|
||||
@@ -255,7 +323,7 @@ func (g *Game) ChangeAvatar(player *model.Player, targetAvatarId uint32) {
|
||||
dbTeam := player.GetDbTeam()
|
||||
dbTeam.CurrAvatarIndex = uint8(newAvatarIndex)
|
||||
}
|
||||
world.SetPlayerAvatarIndex(player, newAvatarIndex)
|
||||
world.SetPlayerActiveAvatarId(player, targetAvatarId)
|
||||
oldAvatarEntityId := world.GetPlayerWorldAvatarEntityId(player, oldAvatarId)
|
||||
oldAvatarEntity := scene.GetEntity(oldAvatarEntityId)
|
||||
if oldAvatarEntity == nil {
|
||||
@@ -310,12 +378,12 @@ func (g *Game) ChangeTeam(player *model.Player, teamId uint32, avatarIdList []ui
|
||||
|
||||
if teamId == uint32(dbTeam.GetActiveTeamId()) {
|
||||
world.SetPlayerLocalTeam(player, avatarIdList)
|
||||
world.SetPlayerActiveAvatarId(player, currAvatarId)
|
||||
world.UpdateMultiplayerTeam()
|
||||
world.UpdatePlayerWorldAvatar(player)
|
||||
|
||||
currAvatarIndex := world.GetPlayerAvatarIndexByAvatarId(player, currAvatarId)
|
||||
dbTeam.CurrAvatarIndex = uint8(currAvatarIndex)
|
||||
world.SetPlayerAvatarIndex(player, currAvatarIndex)
|
||||
|
||||
sceneTeamUpdateNotify := g.PacketSceneTeamUpdateNotify(world, player)
|
||||
g.SendMsg(cmd.SceneTeamUpdateNotify, player.PlayerId, player.ClientSeq, sceneTeamUpdateNotify)
|
||||
@@ -367,7 +435,7 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *
|
||||
SgvDynamicValueMap: nil,
|
||||
},
|
||||
WeaponAbilityInfo: empty,
|
||||
AbilityControlBlock: g.PacketAbilityControlBlock(worldAvatar.GetAvatarId(), worldPlayerAvatar.SkillDepotId),
|
||||
AbilityControlBlock: g.PacketAvatarAbilityControlBlock(worldAvatar.GetAvatarId(), worldPlayerAvatar.SkillDepotId),
|
||||
}
|
||||
if world.IsMultiplayerWorld() {
|
||||
sceneTeamAvatar.AvatarInfo = g.PacketAvatarInfo(worldPlayerAvatar)
|
||||
@@ -378,8 +446,8 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *
|
||||
return sceneTeamUpdateNotify
|
||||
}
|
||||
|
||||
// PacketAbilityControlBlock 角色的ability控制块
|
||||
func (g *Game) PacketAbilityControlBlock(avatarId uint32, skillDepotId uint32) *proto.AbilityControlBlock {
|
||||
// PacketAvatarAbilityControlBlock 角色的ability控制块
|
||||
func (g *Game) PacketAvatarAbilityControlBlock(avatarId uint32, skillDepotId uint32) *proto.AbilityControlBlock {
|
||||
acb := &proto.AbilityControlBlock{
|
||||
AbilityEmbryoList: make([]*proto.AbilityEmbryo, 0),
|
||||
}
|
||||
@@ -424,3 +492,21 @@ func (g *Game) PacketAbilityControlBlock(avatarId uint32, skillDepotId uint32) *
|
||||
// TODO 装备ability
|
||||
return acb
|
||||
}
|
||||
|
||||
func (g *Game) PacketTeamAbilityControlBlock() *proto.AbilityControlBlock {
|
||||
acb := &proto.AbilityControlBlock{
|
||||
AbilityEmbryoList: make([]*proto.AbilityEmbryo, 0),
|
||||
}
|
||||
abilityId := 0
|
||||
// 默认ability
|
||||
for _, abilityHashCode := range constant.DEFAULT_TEAM_ABILITY_HASH_CODE {
|
||||
abilityId++
|
||||
ae := &proto.AbilityEmbryo{
|
||||
AbilityId: uint32(abilityId),
|
||||
AbilityNameHash: uint32(abilityHashCode),
|
||||
AbilityOverrideNameHash: uint32(endec.Hk4eAbilityHashCode("Default")),
|
||||
}
|
||||
acb.AbilityEmbryoList = append(acb.AbilityEmbryoList, ae)
|
||||
}
|
||||
return acb
|
||||
}
|
||||
+5
-13
@@ -443,9 +443,7 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
|
||||
// TODO 元素能量球吸收
|
||||
interactType = proto.InteractType_INTERACT_PICK_ITEM
|
||||
activeAvatarId := world.GetPlayerActiveAvatarId(player)
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
dbAvatar.SetCurrEnergy(activeAvatarId, 0, true)
|
||||
g.UpdatePlayerAvatarFightProp(player.PlayerId, activeAvatarId)
|
||||
g.AddPlayerAvatarEnergy(player.PlayerId, activeAvatarId, 10.0, false)
|
||||
case constant.GADGET_TYPE_GATHER_OBJECT:
|
||||
// 采集物摘取
|
||||
interactType = proto.InteractType_INTERACT_GATHER
|
||||
@@ -490,18 +488,12 @@ func (g *Game) EnterTransPointRegionNotify(player *model.Player, payloadMsg pb.M
|
||||
return
|
||||
}
|
||||
dbAvatar := player.GetDbAvatar()
|
||||
dbTeam := player.GetDbTeam()
|
||||
activeTeam := dbTeam.GetActiveTeam()
|
||||
for _, avatarId := range activeTeam.GetAvatarIdList() {
|
||||
avatar := dbAvatar.AvatarMap[avatarId]
|
||||
for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) {
|
||||
avatar := dbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
|
||||
if avatar.LifeState == constant.LIFE_STATE_DEAD {
|
||||
g.RevivePlayerAvatar(player, avatarId)
|
||||
g.RevivePlayerAvatar(player, worldAvatar.GetAvatarId())
|
||||
}
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CUR_HP] = avatar.FightPropMap[constant.FIGHT_PROP_MAX_HP]
|
||||
g.SendMsg(cmd.AvatarFightPropUpdateNotify, player.PlayerId, player.ClientSeq, &proto.AvatarFightPropUpdateNotify{
|
||||
AvatarGuid: avatar.Guid,
|
||||
FightPropMap: avatar.FightPropMap,
|
||||
})
|
||||
g.AddPlayerAvatarHp(player.PlayerId, worldAvatar.GetAvatarId(), 0.0, true, proto.ChangHpReason_CHANGE_HP_ADD_GM)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-13
@@ -68,7 +68,8 @@ func (a *DbAvatar) InitDbAvatar(player *Player) {
|
||||
|
||||
func (a *DbAvatar) InitAvatar(player *Player, avatar *Avatar) {
|
||||
// 角色战斗属性
|
||||
a.InitAvatarFightProp(avatar)
|
||||
avatar.FightPropMap = make(map[uint32]float32)
|
||||
a.UpdateAvatarFightProp(avatar)
|
||||
// guid
|
||||
avatar.Guid = player.GetNextGameObjectGuid()
|
||||
player.GameObjectGuidMap[avatar.Guid] = GameObject(avatar)
|
||||
@@ -78,14 +79,13 @@ func (a *DbAvatar) InitAvatar(player *Player, avatar *Avatar) {
|
||||
return
|
||||
}
|
||||
|
||||
// InitAvatarFightProp 初始化角色面板
|
||||
func (a *DbAvatar) InitAvatarFightProp(avatar *Avatar) {
|
||||
// UpdateAvatarFightProp 更新角色面板
|
||||
func (a *DbAvatar) UpdateAvatarFightProp(avatar *Avatar) {
|
||||
avatarDataConfig := gdconf.GetAvatarDataById(int32(avatar.AvatarId))
|
||||
if avatarDataConfig == nil {
|
||||
logger.Error("avatarDataConfig error, avatarId: %v", avatar.AvatarId)
|
||||
return
|
||||
}
|
||||
avatar.FightPropMap = make(map[uint32]float32)
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_NONE] = 0.0
|
||||
// 白字攻防血
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_BASE_ATTACK] = avatarDataConfig.GetBaseAttackByLevel(avatar.Level)
|
||||
@@ -104,7 +104,6 @@ func (a *DbAvatar) InitAvatarFightProp(avatar *Avatar) {
|
||||
avatar.FightPropMap[constant.FIGHT_PROP_CHARGE_EFFICIENCY] = 1.0
|
||||
avatarSkillDataConfig := gdconf.GetAvatarEnergySkillConfig(avatar.SkillDepotId)
|
||||
if avatarSkillDataConfig == nil {
|
||||
logger.Error("get avatar energy skill is nil, skillDepotId: %v", avatar.SkillDepotId)
|
||||
return
|
||||
}
|
||||
fightPropEnergy := constant.ELEMENT_TYPE_FIGHT_PROP_ENERGY_MAP[int(avatarSkillDataConfig.CostElemType)]
|
||||
@@ -151,11 +150,11 @@ func (a *DbAvatar) AddAvatar(player *Player, avatarId uint32) {
|
||||
}
|
||||
|
||||
a.AvatarMap[avatarId] = avatar
|
||||
a.SwitchSkillDepot(avatarId, uint32(avatarDataConfig.SkillDepotId))
|
||||
a.ChangeSkillDepot(avatarId, uint32(avatarDataConfig.SkillDepotId))
|
||||
a.InitAvatar(player, avatar)
|
||||
}
|
||||
|
||||
func (a *DbAvatar) SwitchSkillDepot(avatarId uint32, skillDepotId uint32) {
|
||||
func (a *DbAvatar) ChangeSkillDepot(avatarId uint32, skillDepotId uint32) {
|
||||
avatar, exist := a.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
@@ -167,15 +166,21 @@ func (a *DbAvatar) SwitchSkillDepot(avatarId uint32, skillDepotId uint32) {
|
||||
return
|
||||
}
|
||||
avatar.SkillDepotId = skillDepotId
|
||||
// 元素爆发1级
|
||||
avatar.SkillLevelMap[uint32(avatarSkillDepotDataConfig.EnergySkill)] = 1
|
||||
// 元素爆发
|
||||
_, exist = avatar.SkillLevelMap[uint32(avatarSkillDepotDataConfig.EnergySkill)]
|
||||
if !exist {
|
||||
avatar.SkillLevelMap[uint32(avatarSkillDepotDataConfig.EnergySkill)] = 1
|
||||
}
|
||||
for _, skillId := range avatarSkillDepotDataConfig.Skills {
|
||||
// 小技能1级
|
||||
avatar.SkillLevelMap[uint32(skillId)] = 1
|
||||
// 小技能
|
||||
_, exist = avatar.SkillLevelMap[uint32(skillId)]
|
||||
if !exist {
|
||||
avatar.SkillLevelMap[uint32(skillId)] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *DbAvatar) SetCurrEnergy(avatarId uint32, value float64, max bool) {
|
||||
func (a *DbAvatar) AddCurrEnergy(avatarId uint32, value float64, max bool) {
|
||||
avatar, exist := a.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
@@ -189,7 +194,26 @@ func (a *DbAvatar) SetCurrEnergy(avatarId uint32, value float64, max bool) {
|
||||
if max {
|
||||
avatar.CurrEnergy = float64(avatarSkillDataConfig.CostElemVal)
|
||||
} else {
|
||||
avatar.CurrEnergy = value
|
||||
avatar.CurrEnergy += value
|
||||
if avatar.CurrEnergy > float64(avatarSkillDataConfig.CostElemVal) {
|
||||
avatar.CurrEnergy = float64(avatarSkillDataConfig.CostElemVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *DbAvatar) CostCurrEnergy(avatarId uint32, value float64, max bool) {
|
||||
avatar, exist := a.AvatarMap[avatarId]
|
||||
if !exist {
|
||||
logger.Error("avatar not exist, avatarId: %v", avatarId)
|
||||
return
|
||||
}
|
||||
if max {
|
||||
avatar.CurrEnergy = 0.0
|
||||
} else {
|
||||
avatar.CurrEnergy -= value
|
||||
if avatar.CurrEnergy < 0.0 {
|
||||
avatar.CurrEnergy = 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+35
-32
@@ -50,38 +50,41 @@ type Player struct {
|
||||
DbQuest *DbQuest // 任务
|
||||
DbWorld *DbWorld // 大世界
|
||||
// 在线数据 请随意 记得加忽略字段的tag
|
||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次存档保存时间
|
||||
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
||||
WorldId uint64 `bson:"-" msgpack:"-"` // 所在的世界id
|
||||
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
||||
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端本地时钟
|
||||
ClientRTT uint32 `bson:"-" msgpack:"-"` // 客户端网络往返时延
|
||||
GameObjectGuidMap map[uint64]GameObject `bson:"-" msgpack:"-"` // 游戏对象guid映射表
|
||||
Online bool `bson:"-" msgpack:"-"` // 在线状态
|
||||
Pause bool `bson:"-" msgpack:"-"` // 暂停状态
|
||||
SceneJump bool `bson:"-" msgpack:"-"` // 是否场景切换
|
||||
SceneLoadState int `bson:"-" msgpack:"-"` // 场景加载状态
|
||||
SceneEnterReason uint32 `bson:"-" msgpack:"-"` // 场景进入原因
|
||||
CoopApplyMap map[uint32]int64 `bson:"-" msgpack:"-"` // 敲门申请的玩家uid及时间
|
||||
StaminaInfo *StaminaInfo `bson:"-" msgpack:"-"` // 耐力在线数据
|
||||
VehicleInfo *VehicleInfo `bson:"-" msgpack:"-"` // 载具在线数据
|
||||
ClientSeq uint32 `bson:"-" msgpack:"-"` // 客户端发包请求的序号
|
||||
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] `bson:"-" msgpack:"-"` // combat转发器
|
||||
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] `bson:"-" msgpack:"-"` // ability转发器
|
||||
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
||||
MultiServerAppId string `bson:"-" msgpack:"-"` // 多功能服务器的appid
|
||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||
XLuaDebug bool `bson:"-" msgpack:"-"` // 是否开启客户端XLUA调试
|
||||
NetFreeze bool `bson:"-" msgpack:"-"` // 客户端网络上下行冻结状态
|
||||
LastSceneBlockAoiMoveTime uint64 `bson:"-" msgpack:"-"` // 上一次移动处理场景区块aoi的时间
|
||||
CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid
|
||||
WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息
|
||||
ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本
|
||||
OfflineClear bool `bson:"-" msgpack:"-"` // 是否离线时清除账号数据
|
||||
NotSave bool `bson:"-" msgpack:"-"` // 是否离线回档
|
||||
RemoteWorldPlayerNum uint32 `bson:"-" msgpack:"-"` // 远程展示世界内人数
|
||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次存档保存时间
|
||||
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
||||
WorldId uint64 `bson:"-" msgpack:"-"` // 所在的世界id
|
||||
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
||||
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端本地时钟
|
||||
ClientRTT uint32 `bson:"-" msgpack:"-"` // 客户端网络往返时延
|
||||
GameObjectGuidMap map[uint64]GameObject `bson:"-" msgpack:"-"` // 游戏对象guid映射表
|
||||
Online bool `bson:"-" msgpack:"-"` // 在线状态
|
||||
Pause bool `bson:"-" msgpack:"-"` // 暂停状态
|
||||
SceneJump bool `bson:"-" msgpack:"-"` // 是否场景切换
|
||||
SceneLoadState int `bson:"-" msgpack:"-"` // 场景加载状态
|
||||
SceneEnterReason uint32 `bson:"-" msgpack:"-"` // 场景进入原因
|
||||
CoopApplyMap map[uint32]int64 `bson:"-" msgpack:"-"` // 敲门申请的玩家uid及时间
|
||||
StaminaInfo *StaminaInfo `bson:"-" msgpack:"-"` // 耐力在线数据
|
||||
VehicleInfo *VehicleInfo `bson:"-" msgpack:"-"` // 载具在线数据
|
||||
ClientSeq uint32 `bson:"-" msgpack:"-"` // 客户端发包请求的序号
|
||||
CombatInvokeHandler *InvokeHandler[proto.CombatInvokeEntry] `bson:"-" msgpack:"-"` // combat转发器
|
||||
AbilityInvokeHandler *InvokeHandler[proto.AbilityInvokeEntry] `bson:"-" msgpack:"-"` // ability转发器
|
||||
GateAppId string `bson:"-" msgpack:"-"` // 网关服务器的appid
|
||||
MultiServerAppId string `bson:"-" msgpack:"-"` // 多功能服务器的appid
|
||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||
XLuaDebug bool `bson:"-" msgpack:"-"` // 是否开启客户端XLUA调试
|
||||
NetFreeze bool `bson:"-" msgpack:"-"` // 客户端网络上下行冻结状态
|
||||
CommandAssignUid uint32 `bson:"-" msgpack:"-"` // 命令指定uid
|
||||
WeatherInfo *WeatherInfo `bson:"-" msgpack:"-"` // 天气信息
|
||||
ClientVersion int `bson:"-" msgpack:"-"` // 玩家在线的客户端版本
|
||||
OfflineClear bool `bson:"-" msgpack:"-"` // 是否离线时清除账号数据
|
||||
NotSave bool `bson:"-" msgpack:"-"` // 是否离线回档
|
||||
RemoteWorldPlayerNum uint32 `bson:"-" msgpack:"-"` // 远程展示世界内人数
|
||||
Speed *Vector `bson:"-" msgpack:"-"` // 速度
|
||||
WuDi bool `bson:"-" msgpack:"-"` // 是否开启玩家角色无敌
|
||||
EnergyInf bool `bson:"-" msgpack:"-"` // 是否开启玩家角色无限能量
|
||||
StaminaInf bool `bson:"-" msgpack:"-"` // 是否开启玩家无限耐力
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user