refactor(nono): 优化非诺相关结构体字段命名与初始化方式 将 nono 包中多个结构体的字段初始化方式改为键值对形式,提升可读性。 同时统一字段命名风格,增强代码一致性。 feat(fight): 移除冗余战斗循环逻辑并调整部分依赖引用 删除 fightc.go 中的 battleLoop 方法及相关逻辑,简化战斗流程控制。 移除未使用的包引用,并调整结构体成员顺序以提高清晰度。 refactor(player): 修改数据库字段类型为 jsonb 提升灵活性 将 Player 结构体中的 Data 字段由 text 类型修改为 jsonb 类型, 便于后续进行更灵活的数据存储与查询操作。 ```
122 lines
3.1 KiB
Go
122 lines
3.1 KiB
Go
package action
|
||
|
||
import (
|
||
"blazing/logic/service/common"
|
||
"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
|
||
TargetPet info.BattlePetEntity // 药剂作用目标宠物
|
||
}
|
||
|
||
// Priority 返回动作优先级
|
||
func (u *UseItemAction) Priority() int {
|
||
return int(PlayerOperations.UsePotion)
|
||
}
|
||
|
||
// EscapeAction 逃跑的战斗动作
|
||
type EscapeAction struct {
|
||
BaseAction
|
||
Reason info.FightOverInfo
|
||
Our common.PlayerI
|
||
Opp common.PlayerI
|
||
}
|
||
|
||
func (e *EscapeAction) GetInfo() info.FightOverInfo {
|
||
return e.Reason
|
||
}
|
||
|
||
// Priority 返回动作优先级
|
||
func (e *EscapeAction) Priority() int {
|
||
return int(PlayerOperations.Escape)
|
||
}
|
||
|
||
// EscapeAction 逃跑的战斗动作
|
||
type OverTimeAction struct {
|
||
BaseAction
|
||
Reason info.FightOverInfo
|
||
Our common.PlayerI
|
||
Opp common.PlayerI
|
||
}
|
||
|
||
func (e *OverTimeAction) GetInfo() info.FightOverInfo {
|
||
return e.Reason
|
||
}
|
||
|
||
// Priority 返回动作优先级
|
||
func (e *OverTimeAction) Priority() int {
|
||
return int(PlayerOperations.PlayerOffline)
|
||
}
|