mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 16:02:26 +08:00
性能优化
This commit is contained in:
@@ -369,6 +369,9 @@ func (g *Game) SendMsg(cmdId uint16, userId uint32, clientSeq uint32, payloadMsg
|
||||
logger.Error("player not exist, uid: %v, stack: %v", userId, logger.Stack())
|
||||
return
|
||||
}
|
||||
if player.NetFreeze {
|
||||
return
|
||||
}
|
||||
gameMsg := new(mq.GameMsg)
|
||||
gameMsg.UserId = userId
|
||||
gameMsg.CmdId = cmdId
|
||||
|
||||
@@ -160,13 +160,13 @@ func (c *CommandManager) TeleportCommand(cmd *CommandMessage) {
|
||||
c.SendMessage(cmd.Executor, "已将玩家 UID:%v 请求加入目标玩家 UID:%v 的世界。", player.PlayerID, targetUid)
|
||||
} else {
|
||||
// 传送玩家至目标玩家的位置
|
||||
c.gmCmd.GMTeleportPlayer(player.PlayerID, target.SceneId, 0, target.Pos.X, target.Pos.Y, target.Pos.Z)
|
||||
c.gmCmd.GMTeleportPlayer(player.PlayerID, target.SceneId, target.Pos.X, target.Pos.Y, target.Pos.Z)
|
||||
// 发送消息给执行者
|
||||
c.SendMessage(cmd.Executor, "已将玩家 UID:%v 传送至 目标玩家 UID:%v。", player.PlayerID, targetUid)
|
||||
}
|
||||
} else {
|
||||
// 传送玩家至指定的位置
|
||||
c.gmCmd.GMTeleportPlayer(player.PlayerID, sceneId, 0, pos.X, pos.Y, pos.Z)
|
||||
c.gmCmd.GMTeleportPlayer(player.PlayerID, sceneId, pos.X, pos.Y, pos.Z)
|
||||
// 发送消息给执行者
|
||||
c.SendMessage(cmd.Executor, "已将玩家 UID:%v 传送至 场景:%v, X:%.2f, Y:%.2f, Z:%.2f。", player.PlayerID, sceneId, pos.X, pos.Y, pos.Z)
|
||||
}
|
||||
|
||||
@@ -19,40 +19,20 @@ type GMCmd struct {
|
||||
// 玩家通用GM指令
|
||||
|
||||
// GMTeleportPlayer 传送玩家
|
||||
func (g *GMCmd) GMTeleportPlayer(userId, sceneId, dungeonId uint32, posX, posY, posZ float64) {
|
||||
func (g *GMCmd) GMTeleportPlayer(userId, sceneId uint32, posX, posY, posZ float64) {
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
dungeonPointId := uint32(0)
|
||||
if dungeonId != 0 {
|
||||
end := false
|
||||
for _, pointData := range gdconf.GetScenePointMapBySceneId(int32(sceneId)) {
|
||||
if end {
|
||||
break
|
||||
}
|
||||
for _, v := range pointData.DungeonIds {
|
||||
if uint32(v) == dungeonId {
|
||||
dungeonPointId = uint32(pointData.Id)
|
||||
end = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if dungeonPointId == 0 {
|
||||
logger.Error("dungeon pointid not found, dungeonId: %v, uid: %v", dungeonId, userId)
|
||||
return
|
||||
}
|
||||
}
|
||||
GAME.TeleportPlayer(
|
||||
player,
|
||||
proto.EnterReason_ENTER_REASON_GM,
|
||||
sceneId,
|
||||
&model.Vector{X: posX, Y: posY, Z: posZ},
|
||||
new(model.Vector),
|
||||
dungeonId,
|
||||
dungeonPointId,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -106,6 +86,7 @@ func (g *GMCmd) GMAddUserFlycloak(userId, flycloakId uint32) {
|
||||
|
||||
// GMAddUserAllItem 给予玩家所有物品
|
||||
func (g *GMCmd) GMAddUserAllItem(userId, itemCount uint32) {
|
||||
g.GMHWOptLogoutPlayer(userId)
|
||||
itemList := make([]*ChangeItem, 0)
|
||||
for itemId := range GAME.GetAllItemDataConfig() {
|
||||
itemList = append(itemList, &ChangeItem{
|
||||
@@ -125,6 +106,7 @@ func (g *GMCmd) GMAddUserAllWeapon(userId, itemCount uint32) {
|
||||
|
||||
// GMAddUserAllReliquary 给予玩家所有圣遗物
|
||||
func (g *GMCmd) GMAddUserAllReliquary(userId, itemCount uint32) {
|
||||
g.GMHWOptLogoutPlayer(userId)
|
||||
for itemId := range GAME.GetAllReliquaryDataConfig() {
|
||||
g.GMAddUserReliquary(userId, uint32(itemId), itemCount)
|
||||
}
|
||||
@@ -153,6 +135,7 @@ func (g *GMCmd) GMAddUserAllFlycloak(userId uint32) {
|
||||
|
||||
// GMAddUserAllEvery 给予玩家所有内容
|
||||
func (g *GMCmd) GMAddUserAllEvery(userId, itemCount uint32) {
|
||||
g.GMHWOptLogoutPlayer(userId)
|
||||
// 给予玩家所有物品
|
||||
g.GMAddUserAllItem(userId, itemCount)
|
||||
// 给予玩家所有武器
|
||||
@@ -165,8 +148,18 @@ func (g *GMCmd) GMAddUserAllEvery(userId, itemCount uint32) {
|
||||
g.GMAddUserAllCostume(userId)
|
||||
// 给予玩家所有风之翼
|
||||
g.GMAddUserAllFlycloak(userId)
|
||||
}
|
||||
|
||||
// GMHWOptLogoutPlayer GM重量级操作主动下线玩家
|
||||
func (g *GMCmd) GMHWOptLogoutPlayer(userId uint32) {
|
||||
GAME.LogoutPlayer(userId)
|
||||
player := USER_MANAGER.GetOnlineUser(userId)
|
||||
if player == nil {
|
||||
logger.Error("player is nil, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
// 冻结掉服务器对该玩家的下行 避免大量发包对整个系统造成压力
|
||||
player.NetFreeze = true
|
||||
}
|
||||
|
||||
// GMAddQuest 添加任务
|
||||
|
||||
@@ -47,6 +47,9 @@ func (r *RouteManager) doRoute(cmdId uint16, userId uint32, clientSeq uint32, pa
|
||||
logger.Error("player not online, uid: %v", userId)
|
||||
return
|
||||
}
|
||||
if player.NetFreeze {
|
||||
return
|
||||
}
|
||||
player.ClientSeq = clientSeq
|
||||
SELF = player
|
||||
handlerFunc(player, payloadMsg)
|
||||
|
||||
@@ -399,8 +399,8 @@ type WorldAvatar struct {
|
||||
avatarId uint32
|
||||
avatarEntityId uint32
|
||||
weaponEntityId uint32
|
||||
abilityList []*proto.AbilityAppliedAbility
|
||||
modifierList []*proto.AbilityAppliedModifier
|
||||
abilityMap map[uint32]*proto.AbilityAppliedAbility
|
||||
modifierMap map[uint32]*proto.AbilityAppliedModifier
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) GetUid() uint32 {
|
||||
@@ -424,28 +424,31 @@ func (w *WorldAvatar) SetWeaponEntityId(weaponEntityId uint32) {
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) GetAbilityList() []*proto.AbilityAppliedAbility {
|
||||
return w.abilityList
|
||||
abilityList := make([]*proto.AbilityAppliedAbility, 0)
|
||||
for _, ability := range w.abilityMap {
|
||||
abilityList = append(abilityList, ability)
|
||||
}
|
||||
return abilityList
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) GetAbilityByInstanceId(instanceId uint32) *proto.AbilityAppliedAbility {
|
||||
for _, ability := range w.abilityList {
|
||||
if ability.InstancedAbilityId == instanceId {
|
||||
return ability
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return w.abilityMap[instanceId]
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) SetAbilityList(abilityList []*proto.AbilityAppliedAbility) {
|
||||
w.abilityList = abilityList
|
||||
func (w *WorldAvatar) AddAbility(ability *proto.AbilityAppliedAbility) {
|
||||
w.abilityMap[ability.InstancedAbilityId] = ability
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) GetModifierList() []*proto.AbilityAppliedModifier {
|
||||
return w.modifierList
|
||||
modifierList := make([]*proto.AbilityAppliedModifier, 0)
|
||||
for _, modifier := range w.modifierMap {
|
||||
modifierList = append(modifierList, modifier)
|
||||
}
|
||||
return modifierList
|
||||
}
|
||||
|
||||
func (w *WorldAvatar) SetModifierList(modifierList []*proto.AbilityAppliedModifier) {
|
||||
w.modifierList = modifierList
|
||||
func (w *WorldAvatar) AddModifier(modifier *proto.AbilityAppliedModifier) {
|
||||
w.modifierMap[modifier.InstancedModifierId] = modifier
|
||||
}
|
||||
|
||||
// GetWorldAvatarList 获取世界队伍的全部角色列表
|
||||
@@ -632,8 +635,8 @@ func (w *World) SetPlayerLocalTeam(player *model.Player, avatarIdList []uint32)
|
||||
avatarId: avatarId,
|
||||
avatarEntityId: 0,
|
||||
weaponEntityId: 0,
|
||||
abilityList: make([]*proto.AbilityAppliedAbility, 0),
|
||||
modifierList: make([]*proto.AbilityAppliedModifier, 0),
|
||||
abilityMap: make(map[uint32]*proto.AbilityAppliedAbility),
|
||||
modifierMap: make(map[uint32]*proto.AbilityAppliedModifier),
|
||||
}
|
||||
}
|
||||
w.multiplayerTeam.localTeamMap[player.PlayerID] = newLocalTeam
|
||||
@@ -650,8 +653,8 @@ func (w *World) copyLocalTeamToWorld(start int, end int, peerId uint32) {
|
||||
avatarId: 0,
|
||||
avatarEntityId: 0,
|
||||
weaponEntityId: 0,
|
||||
abilityList: nil,
|
||||
modifierList: nil,
|
||||
abilityMap: nil,
|
||||
modifierMap: nil,
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -487,9 +487,7 @@ func (g *Game) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Mes
|
||||
if abilityMetaAddAbility.Ability == nil {
|
||||
continue
|
||||
}
|
||||
abilityList := worldAvatar.GetAbilityList()
|
||||
abilityList = append(abilityList, abilityMetaAddAbility.Ability)
|
||||
worldAvatar.SetAbilityList(abilityList)
|
||||
worldAvatar.AddAbility(abilityMetaAddAbility.Ability)
|
||||
case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_CHANGE:
|
||||
abilityMetaModifierChange := new(proto.AbilityMetaModifierChange)
|
||||
err := pb.Unmarshal(abilityInvokeEntry.AbilityData, abilityMetaModifierChange)
|
||||
@@ -516,9 +514,7 @@ func (g *Game) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Mes
|
||||
if worldAvatar == nil {
|
||||
continue
|
||||
}
|
||||
modifierList := worldAvatar.GetModifierList()
|
||||
modifierList = append(modifierList, abilityAppliedModifier)
|
||||
worldAvatar.SetModifierList(modifierList)
|
||||
worldAvatar.AddModifier(abilityAppliedModifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,6 +734,7 @@ func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity,
|
||||
}
|
||||
g.ChangeGadgetState(player, entity.GetId(), constant.GADGET_STATE_GEAR_START)
|
||||
} else if strings.Contains(gadgetDataConfig.ServerLuaScript, "SubfieldDrop_WoodenObject_Broken") {
|
||||
// 木箱破碎
|
||||
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,21 +56,21 @@ type Player struct {
|
||||
DbQuest *DbQuest // 任务
|
||||
DbWorld *DbWorld // 大世界
|
||||
// 在线数据 请随意 记得加忽略字段的tag
|
||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次保存时间
|
||||
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次存档保存时间
|
||||
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
|
||||
WorldId uint32 `bson:"-" msgpack:"-"` // 所在的世界id
|
||||
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
|
||||
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
|
||||
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端的本地时钟
|
||||
ClientRTT 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:"-"` // 场景加载状态
|
||||
CoopApplyMap map[uint32]int64 `bson:"-" msgpack:"-"` // 敲门申请的玩家uid及时间
|
||||
StaminaInfo *StaminaInfo `bson:"-" msgpack:"-"` // 耐力临时数据
|
||||
VehicleInfo *VehicleInfo `bson:"-" msgpack:"-"` // 载具临时数据
|
||||
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转发器
|
||||
@@ -79,6 +79,7 @@ type Player struct {
|
||||
GCGCurGameGuid uint32 `bson:"-" msgpack:"-"` // GCG玩家所在的游戏guid
|
||||
GCGInfo *GCGInfo `bson:"-" msgpack:"-"` // 七圣召唤信息
|
||||
XLuaDebug bool `bson:"-" msgpack:"-"` // 是否开启客户端XLUA调试
|
||||
NetFreeze bool `bson:"-" msgpack:"-"` // 客户端网络上下行冻结状态
|
||||
// 特殊数据
|
||||
ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user