耐力模块技能耐力消耗初步

This commit is contained in:
UnKownOwO
2022-12-02 23:01:41 +08:00
parent 1019d1d6bd
commit b55f52932d
8 changed files with 162 additions and 53 deletions

View File

@@ -19,4 +19,5 @@ func InitConstant() {
InitSceneTypeConst() InitSceneTypeConst()
InitEntityTypeConst() InitEntityTypeConst()
InitStaminaCostConst() InitStaminaCostConst()
InitWeaponTypeConst()
} }

View File

@@ -4,25 +4,23 @@ var StaminaCostConst *StaminaCost
type StaminaCost struct { type StaminaCost struct {
// 消耗耐力 // 消耗耐力
CLIMBING_BASE int32 CLIMBING_BASE int32 // 缓慢攀爬基数
CLIMB_START int32 CLIMB_START int32 // 攀爬开始
CLIMB_JUMP int32 CLIMB_JUMP int32 // 攀爬跳跃
DASH int32 DASH int32 // 快速跑步
FLY int32 FLY int32 // 滑翔
SKIFF_DASH int32 SKIFF_DASH int32 // 浪船加速
SPRINT int32 SPRINT int32 // 冲刺
SWIM_DASH_START int32 SWIM_DASH_START int32 // 快速游泳开始
SWIM_DASH int32 SWIM_DASH int32 // 快速游泳
SWIMMING int32 SWIMMING int32 // 缓慢游泳
TALENT_DASH int32
TALENT_DASH_START int32
// 恢复耐力 // 恢复耐力
POWERED_FLY int32 POWERED_FLY int32 // 滑翔加速(风圈等)
POWERED_SKIFF int32 POWERED_SKIFF int32 // 浪船加速(风圈等)
RUN int32 RUN int32 // 正常跑步
SKIFF int32 SKIFF int32 // 游艇行驶
STANDBY int32 STANDBY int32 // 站立
WALK int32 WALK int32 // 走路
} }
func InitStaminaCostConst() { func InitStaminaCostConst() {
@@ -38,8 +36,6 @@ func InitStaminaCostConst() {
StaminaCostConst.SWIM_DASH_START = -2000 StaminaCostConst.SWIM_DASH_START = -2000
StaminaCostConst.SWIM_DASH = -204 StaminaCostConst.SWIM_DASH = -204
StaminaCostConst.SWIMMING = -400 StaminaCostConst.SWIMMING = -400
StaminaCostConst.TALENT_DASH = -300
StaminaCostConst.TALENT_DASH_START = -1000
StaminaCostConst.POWERED_FLY = 500 StaminaCostConst.POWERED_FLY = 500
StaminaCostConst.POWERED_SKIFF = 500 StaminaCostConst.POWERED_SKIFF = 500
StaminaCostConst.RUN = 500 StaminaCostConst.RUN = 500

View File

@@ -0,0 +1,39 @@
package constant
var WeaponTypeConst *WeaponType
type WeaponType struct {
WEAPON_NONE int32
WEAPON_SWORD_ONE_HAND int32 // 单手剑
WEAPON_CROSSBOW int32 // 弩
WEAPON_STAFF int32 // 权杖
WEAPON_DOUBLE_DAGGER int32 // 双刀
WEAPON_KATANA int32 // 武士刀
WEAPON_SHURIKEN int32 // 手里剑
WEAPON_STICK int32 // 棍
WEAPON_SPEAR int32 // 矛
WEAPON_SHIELD_SMALL int32 // 小盾牌
WEAPON_CATALYST int32 // 法器
WEAPON_CLAYMORE int32 // 双手剑
WEAPON_BOW int32 // 弓
WEAPON_POLE int32 // 长枪
}
func InitWeaponTypeConst() {
WeaponTypeConst = new(WeaponType)
WeaponTypeConst.WEAPON_NONE = 0
WeaponTypeConst.WEAPON_SWORD_ONE_HAND = 1
WeaponTypeConst.WEAPON_CROSSBOW = 2
WeaponTypeConst.WEAPON_STAFF = 3
WeaponTypeConst.WEAPON_DOUBLE_DAGGER = 4
WeaponTypeConst.WEAPON_KATANA = 5
WeaponTypeConst.WEAPON_SHURIKEN = 6
WeaponTypeConst.WEAPON_STICK = 7
WeaponTypeConst.WEAPON_SPEAR = 8
WeaponTypeConst.WEAPON_SHIELD_SMALL = 9
WeaponTypeConst.WEAPON_CATALYST = 10
WeaponTypeConst.WEAPON_CLAYMORE = 11
WeaponTypeConst.WEAPON_BOW = 12
WeaponTypeConst.WEAPON_POLE = 13
}

27
gs/game/user_ability.go Normal file
View File

@@ -0,0 +1,27 @@
package game
import (
"hk4e/gs/model"
"hk4e/protocol/proto"
)
// HandleAbilityInvoke 处理能力调用
func (g *GameManager) HandleAbilityInvoke(player *model.Player, entry *proto.AbilityInvokeEntry) {
//logger.LOG.Debug("ability invoke handle, entry: %v", entry.ArgumentType)
switch entry.ArgumentType {
case proto.AbilityInvokeArgument_ABILITY_INVOKE_ARGUMENT_MIXIN_COST_STAMINA:
// 消耗耐力
//costStamina := new(proto.AbilityMixinCostStamina)
//err := pb.Unmarshal(entry.AbilityData, costStamina)
//if err != nil {
// logger.LOG.Error("unmarshal ability data err: %v", err)
// return
//}
// 处理技能持续时的耐力消耗
g.HandleSkillSustainStamina(player)
}
}

View File

@@ -262,6 +262,10 @@ func (g *GameManager) AbilityInvocationsNotify(player *model.Player, payloadMsg
invokeHandler := NewInvokeHandler[proto.AbilityInvokeEntry]() invokeHandler := NewInvokeHandler[proto.AbilityInvokeEntry]()
for _, entry := range req.Invokes { for _, entry := range req.Invokes {
//logger.LOG.Debug("AT: %v, FT: %v, UID: %v", entry.ArgumentType, entry.ForwardType, player.PlayerID) //logger.LOG.Debug("AT: %v, FT: %v, UID: %v", entry.ArgumentType, entry.ForwardType, player.PlayerID)
// 处理能力调用
g.HandleAbilityInvoke(player, entry)
invokeHandler.addEntry(entry.ForwardType, entry) invokeHandler.addEntry(entry.ForwardType, entry)
} }
@@ -316,6 +320,10 @@ func (g *GameManager) ClientAbilityInitFinishNotify(player *model.Player, payloa
invokeHandler := NewInvokeHandler[proto.AbilityInvokeEntry]() invokeHandler := NewInvokeHandler[proto.AbilityInvokeEntry]()
for _, entry := range req.Invokes { for _, entry := range req.Invokes {
//logger.LOG.Debug("AT: %v, FT: %v, UID: %v", entry.ArgumentType, entry.ForwardType, player.PlayerID) //logger.LOG.Debug("AT: %v, FT: %v, UID: %v", entry.ArgumentType, entry.ForwardType, player.PlayerID)
// 处理能力调用
g.HandleAbilityInvoke(player, entry)
invokeHandler.addEntry(entry.ForwardType, entry) invokeHandler.addEntry(entry.ForwardType, entry)
} }
@@ -363,6 +371,9 @@ func (g *GameManager) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.M
logger.LOG.Debug("user event do skill success, uid: %v", player.PlayerID) logger.LOG.Debug("user event do skill success, uid: %v", player.PlayerID)
req := payloadMsg.(*proto.EvtDoSkillSuccNotify) req := payloadMsg.(*proto.EvtDoSkillSuccNotify)
logger.LOG.Debug("EvtDoSkillSuccNotify: %v", req) logger.LOG.Debug("EvtDoSkillSuccNotify: %v", req)
// 处理技能开始时的耐力消耗
g.HandleSkillStartStamina(player, req.SkillId)
} }
func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Message) { func (g *GameManager) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Message) {

View File

@@ -2,10 +2,13 @@ package game
import ( import (
pb "google.golang.org/protobuf/proto" pb "google.golang.org/protobuf/proto"
"hk4e/gdconf"
"hk4e/gs/constant" "hk4e/gs/constant"
"hk4e/gs/model" "hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/protocol/cmd" "hk4e/protocol/cmd"
"hk4e/protocol/proto" "hk4e/protocol/proto"
"time"
) )
// SceneAvatarStaminaStepReq 缓慢游泳或缓慢攀爬时消耗耐力 // SceneAvatarStaminaStepReq 缓慢游泳或缓慢攀爬时消耗耐力
@@ -85,17 +88,43 @@ func (g *GameManager) HandleStamina(player *model.Player, motionState proto.Moti
// 攀爬跳跃 // 攀爬跳跃
g.UpdateStamina(player, constant.StaminaCostConst.CLIMB_JUMP) g.UpdateStamina(player, constant.StaminaCostConst.CLIMB_JUMP)
case proto.MotionState_MOTION_STATE_SWIM_DASH: case proto.MotionState_MOTION_STATE_SWIM_DASH:
// 游泳冲刺开始 // 快速游泳开始
g.UpdateStamina(player, constant.StaminaCostConst.SWIM_DASH_START) g.UpdateStamina(player, constant.StaminaCostConst.SWIM_DASH_START)
} }
} }
// SetStaminaLastSkill 记录最后释放的技能 // HandleSkillSustainStamina 处理技能持续时的耐力消耗
func (g *GameManager) SetStaminaLastSkill(player *model.Player, casterId uint32, skillId uint32) { func (g *GameManager) HandleSkillSustainStamina(player *model.Player) {
// TODO 有些角色的重击消耗不同 skillId := player.StaminaInfo.LastSkillId
switch skillId { logger.LOG.Error("stamina skill sustain, skillId: %v", skillId)
avatarSkillConfig, ok := gdconf.CONF.AvatarSkillDataMap[int32(skillId)]
if !ok {
logger.LOG.Error("avatarSkillConfig error, skillId: %v", skillId)
return
} }
// 距离上次执行过去的时间
pastTime := time.Now().UnixMilli() - player.StaminaInfo.LastSkillTime
// 根据配置以及距离上次的时间计算消耗的耐力
g.UpdateStamina(player, -(int32(pastTime/1000)*avatarSkillConfig.CostStamina)*100)
// 记录最后释放技能时间
player.StaminaInfo.LastSkillTime = time.Now().UnixMilli()
}
// HandleSkillStartStamina 处理技能开始时即时耐力消耗
func (g *GameManager) HandleSkillStartStamina(player *model.Player, skillId uint32) {
logger.LOG.Error("stamina skill start, skillId: %v", skillId)
avatarSkillConfig, ok := gdconf.CONF.AvatarSkillDataMap[int32(skillId)]
if !ok {
logger.LOG.Error("avatarSkillConfig error, skillId: %v", skillId)
return
}
// 根据配置消耗耐力
g.UpdateStamina(player, -avatarSkillConfig.CostStamina*100)
// 记录最后释放的技能
player.StaminaInfo.LastSkillId = skillId
player.StaminaInfo.LastSkillTime = time.Now().UnixMilli()
} }
// StaminaHandler 处理持续耐力消耗 // StaminaHandler 处理持续耐力消耗
@@ -103,9 +132,9 @@ func (g *GameManager) StaminaHandler(player *model.Player) {
staminaInfo := player.StaminaInfo staminaInfo := player.StaminaInfo
// 添加的耐力大于0为恢复 // 添加的耐力大于0为恢复
if staminaInfo.Cost > 0 { if staminaInfo.CostStamina > 0 {
// 耐力延迟1s(5 ticks)恢复 动作状态为加速将立刻恢复耐力 // 耐力延迟1s(5 ticks)恢复 动作状态为加速将立刻恢复耐力
if staminaInfo.RestoreDelay < 5 && staminaInfo.State != proto.MotionState_MOTION_STATE_POWERED_FLY && staminaInfo.State != proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH { 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++ staminaInfo.RestoreDelay++
return // 不恢复耐力 return // 不恢复耐力
@@ -113,7 +142,7 @@ func (g *GameManager) StaminaHandler(player *model.Player) {
} }
// 更新玩家耐力 // 更新玩家耐力
g.UpdateStamina(player, staminaInfo.Cost) g.UpdateStamina(player, staminaInfo.CostStamina)
} }
// SetStaminaCost 设置动作需要消耗的耐力 // SetStaminaCost 设置动作需要消耗的耐力
@@ -125,38 +154,38 @@ func (g *GameManager) SetStaminaCost(player *model.Player, state proto.MotionSta
switch state { switch state {
// 消耗耐力 // 消耗耐力
case proto.MotionState_MOTION_STATE_DASH: case proto.MotionState_MOTION_STATE_DASH:
// 疾跑 // 快速跑步
staminaInfo.Cost = constant.StaminaCostConst.DASH staminaInfo.CostStamina = constant.StaminaCostConst.DASH
case proto.MotionState_MOTION_STATE_FLY, proto.MotionState_MOTION_STATE_FLY_FAST, proto.MotionState_MOTION_STATE_FLY_SLOW: case proto.MotionState_MOTION_STATE_FLY, proto.MotionState_MOTION_STATE_FLY_FAST, proto.MotionState_MOTION_STATE_FLY_SLOW:
// 飞行 // 滑翔
staminaInfo.Cost = constant.StaminaCostConst.FLY staminaInfo.CostStamina = constant.StaminaCostConst.FLY
case proto.MotionState_MOTION_STATE_SWIM_DASH: case proto.MotionState_MOTION_STATE_SWIM_DASH:
// 游泳加速 // 快速游泳
staminaInfo.Cost = constant.StaminaCostConst.SWIM_DASH staminaInfo.CostStamina = constant.StaminaCostConst.SWIM_DASH
case proto.MotionState_MOTION_STATE_SKIFF_DASH: case proto.MotionState_MOTION_STATE_SKIFF_DASH:
// 小艇加速移动 // 浪船加速
// TODO 玩家使用载具时需要用载具的协议发送prop // TODO 玩家使用载具时需要用载具的协议发送prop
staminaInfo.Cost = constant.StaminaCostConst.SKIFF_DASH staminaInfo.CostStamina = constant.StaminaCostConst.SKIFF_DASH
// 恢复耐力 // 恢复耐力
case proto.MotionState_MOTION_STATE_DANGER_RUN, proto.MotionState_MOTION_STATE_RUN: case proto.MotionState_MOTION_STATE_DANGER_RUN, proto.MotionState_MOTION_STATE_RUN:
// 跑步 // 正常跑步
staminaInfo.Cost = constant.StaminaCostConst.RUN staminaInfo.CostStamina = 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: 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:
// 站立 // 站立
staminaInfo.Cost = constant.StaminaCostConst.STANDBY staminaInfo.CostStamina = constant.StaminaCostConst.STANDBY
case proto.MotionState_MOTION_STATE_DANGER_WALK, proto.MotionState_MOTION_STATE_WALK: case proto.MotionState_MOTION_STATE_DANGER_WALK, proto.MotionState_MOTION_STATE_WALK:
// 走路 // 走路
staminaInfo.Cost = constant.StaminaCostConst.WALK staminaInfo.CostStamina = constant.StaminaCostConst.WALK
case proto.MotionState_MOTION_STATE_POWERED_FLY: case proto.MotionState_MOTION_STATE_POWERED_FLY:
// 飞行加速 (风圈等) // 滑翔加速 (风圈等)
staminaInfo.Cost = constant.StaminaCostConst.POWERED_FLY staminaInfo.CostStamina = constant.StaminaCostConst.POWERED_FLY
case proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH: case proto.MotionState_MOTION_STATE_SKIFF_POWERED_DASH:
// 小艇加速 (风圈等) // 浪船加速 (风圈等)
staminaInfo.Cost = constant.StaminaCostConst.POWERED_SKIFF staminaInfo.CostStamina = constant.StaminaCostConst.POWERED_SKIFF
// 缓慢动作将在客户端发送消息后消耗 // 缓慢动作将在客户端发送消息后消耗
case proto.MotionState_MOTION_STATE_CLIMB, proto.MotionState_MOTION_STATE_SWIM_MOVE: case proto.MotionState_MOTION_STATE_CLIMB, proto.MotionState_MOTION_STATE_SWIM_MOVE:
// 缓慢攀爬 或 缓慢游泳 // 缓慢攀爬 或 缓慢游泳
staminaInfo.Cost = 0 staminaInfo.CostStamina = 0
} }
} }

View File

@@ -76,7 +76,11 @@ func (p *Player) InitAvatar(avatar *Avatar) {
} }
func (p *Player) AddAvatar(avatarId uint32) { func (p *Player) AddAvatar(avatarId uint32) {
avatarDataConfig := gdc.CONF.AvatarDataMap[int32(avatarId)] avatarDataConfig, ok := gdc.CONF.AvatarDataMap[int32(avatarId)]
if !ok {
logger.LOG.Error("avatarDataConfig error, avatarId: %v", avatarId)
return
}
skillDepotId := int32(0) skillDepotId := int32(0)
// 主角要单独设置 // 主角要单独设置
if avatarId == 10000005 { if avatarId == 10000005 {

View File

@@ -1,11 +1,13 @@
package model package model
import "hk4e/protocol/proto" import (
"hk4e/protocol/proto"
)
type StaminaInfo struct { type StaminaInfo struct {
State proto.MotionState // 动作状态 State proto.MotionState // 动作状态
Cost int32 // 消耗或恢复的耐力 CostStamina int32 // 消耗或恢复的耐力
RestoreDelay uint8 // 恢复延迟 RestoreDelay uint8 // 恢复延迟
LastCasterId uint32 // 最后技能释放者 LastSkillId uint32 // 最后释放的技能Id
LastSkillId uint32 // 最后释放技能 LastSkillTime int64 // 最后释放技能的时间
} }