From 664a408ac8ecf00e9b300cd6816c7b05d7752bf8 Mon Sep 17 00:00:00 2001 From: UnKownOwO <80520429@qq.com> Date: Thu, 1 Dec 2022 21:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=90=E5=8A=9B=E6=A8=A1=E5=9D=97=E7=BC=93?= =?UTF-8?q?=E6=85=A2=E6=B8=B8=E6=B3=B3=E7=BC=93=E6=85=A2=E6=94=80=E7=88=AC?= =?UTF-8?q?=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/constant/stamina_cost.go | 4 +- gs/game/game_manager.go | 5 +- gs/game/route_manager.go | 1 + gs/game/user_stamina.go | 118 +++++++++++++-------------- gs/model/stamina.go | 5 +- protocol/cmd/cmd_id_proto_obj_map.go | 4 + 6 files changed, 69 insertions(+), 68 deletions(-) diff --git a/gs/constant/stamina_cost.go b/gs/constant/stamina_cost.go index 83bd19d0..e0a0ba51 100644 --- a/gs/constant/stamina_cost.go +++ b/gs/constant/stamina_cost.go @@ -28,7 +28,7 @@ type StaminaCost struct { func InitStaminaCostConst() { StaminaCostConst = new(StaminaCost) - StaminaCostConst.CLIMBING = -150 + StaminaCostConst.CLIMBING = -110 StaminaCostConst.CLIMB_START = -500 StaminaCostConst.CLIMB_JUMP = -2500 StaminaCostConst.DASH = -360 @@ -37,7 +37,7 @@ func InitStaminaCostConst() { StaminaCostConst.SPRINT = -1800 StaminaCostConst.SWIM_DASH_START = -2000 StaminaCostConst.SWIM_DASH = -204 - StaminaCostConst.SWIMMING = -80 + StaminaCostConst.SWIMMING = -400 StaminaCostConst.TALENT_DASH = -300 StaminaCostConst.TALENT_DASH_START = -1000 StaminaCostConst.POWERED_FLY = 500 diff --git a/gs/game/game_manager.go b/gs/game/game_manager.go index 0631dc2b..0dbef4a5 100644 --- a/gs/game/game_manager.go +++ b/gs/game/game_manager.go @@ -71,12 +71,13 @@ func (g *GameManager) Start() { } func (g *GameManager) Stop() { + // 保存玩家数据 + g.userManager.SaveUser() + // 踢出所有在线玩家 for userId := range g.userManager.GetAllOnlineUserList() { g.DisconnectPlayer(userId) } - // 保存玩家数据 - g.userManager.SaveUser() //g.worldManager.worldStatic.SaveTerrain() } diff --git a/gs/game/route_manager.go b/gs/game/route_manager.go index f144e522..58cf5f15 100644 --- a/gs/game/route_manager.go +++ b/gs/game/route_manager.go @@ -102,6 +102,7 @@ func (r *RouteManager) InitRoute() { r.registerRouter(cmd.ChangeWorldToSingleModeReq, r.gameManager.ChangeWorldToSingleModeReq) r.registerRouter(cmd.SceneKickPlayerReq, r.gameManager.SceneKickPlayerReq) r.registerRouter(cmd.ChangeMpTeamAvatarReq, r.gameManager.ChangeMpTeamAvatarReq) + r.registerRouter(cmd.SceneAvatarStaminaStepReq, r.gameManager.SceneAvatarStaminaStepReq) } func (r *RouteManager) RouteHandle(netMsg *cmd.NetMsg) { diff --git a/gs/game/user_stamina.go b/gs/game/user_stamina.go index 0b58b4ba..39b3ad3a 100644 --- a/gs/game/user_stamina.go +++ b/gs/game/user_stamina.go @@ -1,37 +1,55 @@ package game import ( + pb "google.golang.org/protobuf/proto" "hk4e/gs/constant" "hk4e/gs/model" - "hk4e/pkg/logger" "hk4e/protocol/cmd" "hk4e/protocol/proto" ) +// SceneAvatarStaminaStepReq 缓慢游泳或缓慢攀爬时消耗耐力 +func (g *GameManager) SceneAvatarStaminaStepReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.SceneAvatarStaminaStepReq) + + // 根据动作状态消耗耐力 + switch player.StaminaInfo.State { + case proto.MotionState_MOTION_STATE_CLIMB: + // 缓慢攀爬 + g.UpdateStamina(player, constant.StaminaCostConst.CLIMBING) + case proto.MotionState_MOTION_STATE_SWIM_MOVE: + // 缓慢游泳 + g.UpdateStamina(player, constant.StaminaCostConst.SWIMMING) + } + + // PacketSceneAvatarStaminaStepRsp + sceneAvatarStaminaStepRsp := new(proto.SceneAvatarStaminaStepRsp) + sceneAvatarStaminaStepRsp.Retcode = int32(proto.Retcode_RETCODE_RET_SUCC) + sceneAvatarStaminaStepRsp.UseClientRot = req.UseClientRot + sceneAvatarStaminaStepRsp.Rot = req.Rot + g.SendMsg(cmd.GetShopRsp, player.PlayerID, player.ClientSeq, sceneAvatarStaminaStepRsp) +} + // HandleStamina 处理即时耐力消耗 func (g *GameManager) HandleStamina(player *model.Player, motionState proto.MotionState) { staminaInfo := player.StaminaInfo - logger.LOG.Debug("stamina handle, uid: %v, motionState: %v", player.PlayerID, motionState) - - // 记录玩家的此时位置 - staminaInfo.CurPos = &model.Vector{ - X: player.Pos.X, - Y: player.Pos.Y, - Z: player.Pos.Z, - } - - // 未改变状态执行后面没有意义 - if motionState == staminaInfo.State { - return - } + //logger.LOG.Debug("stamina handle, uid: %v, motionState: %v", player.PlayerID, motionState) // 设置用于持续消耗或恢复耐力的值 g.SetStaminaCost(player, motionState) + // 未改变状态不执行后面 有些仅在动作开始消耗耐力 + if motionState == staminaInfo.State { + return + } + + // 记录玩家的动作状态 + staminaInfo.State = motionState + // 根据玩家的状态立刻消耗耐力 switch motionState { case proto.MotionState_MOTION_STATE_CLIMB: - // 攀爬 + // 攀爬开始 g.UpdateStamina(player, constant.StaminaCostConst.CLIMB_START) case proto.MotionState_MOTION_STATE_DASH_BEFORE_SHAKE: // 冲刺 @@ -40,11 +58,19 @@ func (g *GameManager) HandleStamina(player *model.Player, motionState proto.Moti // 攀爬跳跃 g.UpdateStamina(player, constant.StaminaCostConst.CLIMB_JUMP) case proto.MotionState_MOTION_STATE_SWIM_DASH: - // 游泳冲刺 + // 游泳冲刺开始 g.UpdateStamina(player, constant.StaminaCostConst.SWIM_DASH_START) } } +// SetStaminaLastSkill 记录最后释放的技能 +func (g *GameManager) SetStaminaLastSkill(player *model.Player, casterId uint32, skillId uint32) { + // TODO 有些角色的重击消耗不同 + switch skillId { + + } +} + // StaminaHandler 处理持续耐力消耗 func (g *GameManager) StaminaHandler(player *model.Player) { staminaInfo := player.StaminaInfo @@ -53,7 +79,7 @@ func (g *GameManager) StaminaHandler(player *model.Player) { if staminaInfo.Cost > 0 { // 耐力延迟1s(5 ticks)恢复 动作状态为加速将立刻恢复耐力 if staminaInfo.RestoreDelay < 5 && staminaInfo.State != proto.MotionState_MOTION_STATE_POWERED_FLY && staminaInfo.State != proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH { - logger.LOG.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay) + //logger.LOG.Debug("stamina delay add, restoreDelay: %v", staminaInfo.RestoreDelay) staminaInfo.RestoreDelay++ return // 不恢复耐力 } @@ -61,80 +87,50 @@ func (g *GameManager) StaminaHandler(player *model.Player) { // 更新玩家耐力 g.UpdateStamina(player, staminaInfo.Cost) - - // 记录坐标 用于判断是否移动 - staminaInfo.PrevPos = staminaInfo.CurPos } // SetStaminaCost 设置动作需要消耗的耐力 func (g *GameManager) SetStaminaCost(player *model.Player, state proto.MotionState) { staminaInfo := player.StaminaInfo - // 耐力消耗值 - var cost int32 - // 根据状态决定要修改的耐力 // TODO 角色天赋 食物 会影响耐力消耗 switch state { // 消耗耐力 - case proto.MotionState_MOTION_STATE_CLIMB: - // 攀爬 - // TODO 不应该通过这种方式判断玩家是否移动 应该有更好的方式 - if g.GetPlayerIsMoving(staminaInfo) { - cost = constant.StaminaCostConst.CLIMBING - } case proto.MotionState_MOTION_STATE_DASH: // 疾跑 - cost = constant.StaminaCostConst.DASH + staminaInfo.Cost = constant.StaminaCostConst.DASH case proto.MotionState_MOTION_STATE_FLY, proto.MotionState_MOTION_STATE_FLY_FAST, proto.MotionState_MOTION_STATE_FLY_SLOW: // 飞行 - cost = constant.StaminaCostConst.FLY - case proto.MotionState_MOTION_STATE_SWIM_MOVE: - // 游泳移动 - cost = constant.StaminaCostConst.SWIMMING + staminaInfo.Cost = constant.StaminaCostConst.FLY case proto.MotionState_MOTION_STATE_SWIM_DASH: // 游泳加速 - cost = constant.StaminaCostConst.SWIM_DASH + staminaInfo.Cost = constant.StaminaCostConst.SWIM_DASH case proto.MotionState_MOTION_STATE_SKIFF_DASH: // 小艇加速移动 // TODO 玩家使用载具时需要用载具的协议发送prop - cost = constant.StaminaCostConst.SKIFF_DASH + staminaInfo.Cost = constant.StaminaCostConst.SKIFF_DASH // 恢复耐力 case proto.MotionState_MOTION_STATE_DANGER_RUN, proto.MotionState_MOTION_STATE_RUN: // 跑步 - cost = constant.StaminaCostConst.RUN + staminaInfo.Cost = constant.StaminaCostConst.RUN case proto.MotionState_MOTION_STATE_DANGER_STANDBY_MOVE, proto.MotionState_MOTION_STATE_DANGER_STANDBY, proto.MotionState_MOTION_STATE_LADDER_TO_STANDBY, proto.MotionState_MOTION_STATE_STANDBY_MOVE, proto.MotionState_MOTION_STATE_STANDBY: // 站立 - cost = constant.StaminaCostConst.STANDBY + staminaInfo.Cost = constant.StaminaCostConst.STANDBY case proto.MotionState_MOTION_STATE_DANGER_WALK, proto.MotionState_MOTION_STATE_WALK: // 走路 - cost = constant.StaminaCostConst.WALK + staminaInfo.Cost = constant.StaminaCostConst.WALK case proto.MotionState_MOTION_STATE_POWERED_FLY: // 飞行加速 (风圈等) - cost = constant.StaminaCostConst.POWERED_FLY + staminaInfo.Cost = constant.StaminaCostConst.POWERED_FLY case proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH: // 小艇加速 (风圈等) - cost = constant.StaminaCostConst.POWERED_SKIFF + staminaInfo.Cost = constant.StaminaCostConst.POWERED_SKIFF + // 缓慢动作将在客户端发送消息后消耗 + case proto.MotionState_MOTION_STATE_CLIMB, proto.MotionState_MOTION_STATE_SWIM_MOVE: + // 缓慢攀爬 或 缓慢游泳 + staminaInfo.Cost = 0 } - - // 确保目前的动作状态会改变耐力 - // 如果会则修改记录 tick执行时会调用数据 - if cost != 0 { - staminaInfo.State = state - staminaInfo.Cost = cost - } -} - -// GetPlayerIsMoving 玩家是否正在移动 -func (g *GameManager) GetPlayerIsMoving(staminaInfo *model.StaminaInfo) bool { - if staminaInfo.PrevPos == nil || staminaInfo.CurPos == nil { - return false - } - diffX := staminaInfo.CurPos.X - staminaInfo.PrevPos.X - diffY := staminaInfo.CurPos.Y - staminaInfo.PrevPos.Y - diffZ := staminaInfo.CurPos.Z - staminaInfo.PrevPos.Z - logger.LOG.Debug("get player is moving, diffX: %v, diffY: %v, diffZ: %v", diffX, diffY, diffZ) - return diffX > 0.3 || diffY > 0.2 || diffZ > 0.3 } // UpdateStamina 更新耐力 当前耐力值 + 消耗的耐力值 @@ -145,7 +141,7 @@ func (g *GameManager) UpdateStamina(player *model.Player, staminaCost int32) { } // 消耗耐力重新计算恢复需要延迟的tick if staminaCost < 0 { - logger.LOG.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.RestoreDelay) + //logger.LOG.Debug("stamina delay reset, restoreDelay: %v", player.StaminaInfo.RestoreDelay) player.StaminaInfo.RestoreDelay = 0 } diff --git a/gs/model/stamina.go b/gs/model/stamina.go index 71b8a732..49398487 100644 --- a/gs/model/stamina.go +++ b/gs/model/stamina.go @@ -6,7 +6,6 @@ type StaminaInfo struct { State proto.MotionState // 动作状态 Cost int32 // 消耗或恢复的耐力 RestoreDelay uint8 // 恢复延迟 - - PrevPos *Vector - CurPos *Vector + LastCasterId uint32 // 最后技能释放者 + LastSkillId uint32 // 最后释放的技能 } diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 14e061fc..c8e13961 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -212,6 +212,10 @@ func (a *CmdProtoMap) registerAllMessage() { a.registerMessage(McoinExchangeHcoinReq, &proto.McoinExchangeHcoinReq{}) // 结晶换原石请求 a.registerMessage(McoinExchangeHcoinRsp, &proto.McoinExchangeHcoinRsp{}) // 结晶换原石响应 + // 耐力 + a.registerMessage(SceneAvatarStaminaStepReq, &proto.SceneAvatarStaminaStepReq{}) // 缓慢游泳或缓慢攀爬时消耗耐力请求 + a.registerMessage(SceneAvatarStaminaStepRsp, &proto.SceneAvatarStaminaStepRsp{}) // 缓慢游泳或缓慢攀爬时消耗耐力响应 + // 乱七八糟 a.registerMessage(MarkMapReq, &proto.MarkMapReq{}) // 标记地图请求 a.registerMessage(TowerAllDataReq, &proto.TowerAllDataReq{}) // 深渊数据请求