Files
bl/logic/service/fight/action/BattleAction.go
昔念 4b34445dfc ```
refactor(fight): 重构战斗逻辑中技能实体传递方式

将战斗逻辑中使用的 action.SelectSkillAction 替换为 info.SkillEntity,
以统一技能数据结构。同时更新相关函数签名和字段引用。

此外,移除了未使用的 Attack 字段,并调整了部分逻辑实现以提高代码清晰度。
还修复了 effect_power_doblue.go 中对输入参数的错误引用问题。

最后,修改了通道命名规范(ActionChan -> actionChan, GetActionChan -> GetOverChan),
并引入 overchan 用于战斗结束通知,提升并发安全性与语义明确性。
```
2025-11-10 02:29:00 +08:00

114 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package action
import (
"blazing/logic/service/fight/info"
"github.com/tnnmigga/enum"
)
// EnumPlayerOperation 玩家操作枚举类型
type EnumPlayerOperation int
// 定义读秒倒计时期间玩家可执行的操作枚举
var PlayerOperations = enum.New[struct {
//SystemGiveUp EnumPlayerOperation `enum:"-1"` // 系统选择放弃出手(比如没有PP)
//系统放弃出手就是SKILL ID=0
SelectSkill EnumPlayerOperation `enum:"0"` // 选择技能-6到6
ActiveSwitch EnumPlayerOperation `enum:"2"` // 主动切换(中切)
UsePotion EnumPlayerOperation `enum:"3"` // 使用药剂(捕捉、逃跑等)
Escape EnumPlayerOperation `enum:"4"` // 逃跑(等级最高,以及掉线)
PlayerOffline EnumPlayerOperation `enum:"5"` // 玩家掉线
// BeExpelledSwitch EnumPlayerOperation `enum:"6"` // 被驱逐切换
}]()
// BattleActionI 战斗动作接口
type BattleActionI interface {
GetPlayerID() uint32
Priority() int // 优先级
}
// SelectSkillAction 选择技能的战斗动作
type SelectSkillAction struct {
BaseAction
*info.SkillEntity // 使用的技能
//PetInfo *info.BattlePetEntity // 使用技能的宠物
//Attack info.AttackValue
}
// Priority 返回动作优先级
func (s *SelectSkillAction) Priority() int {
return int(PlayerOperations.SelectSkill)
}
type BaseAction struct {
PlayerID uint32 // 玩家ID
}
func NewBaseAction(t uint32) BaseAction {
return BaseAction{
PlayerID: t,
}
}
func (a *BaseAction) GetPlayerID() uint32 {
return a.PlayerID
// fmt.Printf("玩家[%d]主动切换宠物:从%s切换到%s原因%s\n",
// // a.PlayerID, a.CurrentPet.Name, a.TargetPet.Name, a.SwitchReason)
}
// ActiveSwitchAction 主动切换宠物的战斗动作
type ActiveSwitchAction struct {
BaseAction
Reason info.ChangePetInfo
// CurrentPet BattlePetEntity // 当前在场宠物
// TargetPet BattlePetEntity // 要切换上场的宠物
// SwitchReason string // 切换原因
}
// Priority 返回动作优先级
func (a *ActiveSwitchAction) Priority() int {
return int(PlayerOperations.ActiveSwitch)
}
// UsePotionAction 使用药剂的战斗动作
type UseItemAction struct {
BaseAction
ItemID uint32 // 药剂ID
CacthTime uint32
TargetPet info.BattlePetEntity // 药剂作用目标宠物
}
// Priority 返回动作优先级
func (u *UseItemAction) Priority() int {
return int(PlayerOperations.UsePotion)
}
// EscapeAction 逃跑的战斗动作
type EscapeAction struct {
BaseAction
Reason info.EnumBattleOverReason
}
// Priority 返回动作优先级
func (e *EscapeAction) Priority() int {
return int(PlayerOperations.Escape)
}
// EscapeAction 逃跑的战斗动作
type OverTimeAction struct {
BaseAction
Reason info.FightOverInfo
}
func (e *OverTimeAction) GetInfo() info.FightOverInfo {
return e.Reason
}
// Priority 返回动作优先级
func (e *OverTimeAction) Priority() int {
return int(PlayerOperations.PlayerOffline)
}