189 lines
4.7 KiB
Go
189 lines
4.7 KiB
Go
package fight
|
||
|
||
import (
|
||
"blazing/logic/service/common"
|
||
"blazing/logic/service/fight/info"
|
||
"time"
|
||
|
||
"github.com/tnnmigga/enum"
|
||
)
|
||
|
||
// EnumPlayerOperation 玩家操作枚举类型
|
||
type EnumPlayerOperation int
|
||
|
||
// 定义读秒倒计时期间玩家可执行的操作枚举
|
||
var PlayerOperations = enum.New[struct {
|
||
SystemGiveUp EnumPlayerOperation `enum:"-1"` // 系统选择放弃出手(比如没有PP)
|
||
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"` // 被驱逐切换
|
||
}]()
|
||
|
||
// Compare 比较两个1v1战斗动作的执行优先级(核心逻辑)
|
||
func (f *FightC) Compare(a, b BattleActionI) (BattleActionI, BattleActionI) {
|
||
// 动作本身的优先级比较
|
||
p1 := b.Priority() - a.Priority()
|
||
if p1 > 0 { // 对手优先级更高
|
||
return b, a
|
||
} else if p1 < 0 {
|
||
return a, b
|
||
}
|
||
_, ok := b.(*SystemGiveUpAction)
|
||
|
||
if ok {
|
||
if _, ok := a.(*SystemGiveUpAction); ok {
|
||
return b, a
|
||
}
|
||
return a, b
|
||
}
|
||
|
||
bskill := b.(*SelectSkillAction)
|
||
askill := a.(*SelectSkillAction)
|
||
// 如果是选择技能操作,进一步比较技能优先级和宠物属性
|
||
|
||
p2 := bskill.Skill.Priority - askill.Skill.Priority
|
||
if p2 > 0 {
|
||
return b, a
|
||
} else if p2 < 0 {
|
||
return a, b
|
||
}
|
||
|
||
p2 = int(f.Opp.GetProp(4, false)) - int(f.Our.GetProp(4, false))
|
||
if p2 > 0 {
|
||
return b, a
|
||
} else if p2 < 0 {
|
||
return a, b
|
||
}
|
||
|
||
return a, b // 速度相同时,发起方优先
|
||
}
|
||
|
||
// BattleActionI 战斗动作接口
|
||
type BattleActionI interface {
|
||
GetPlayerID() uint32
|
||
Priority() int // 优先级
|
||
|
||
}
|
||
|
||
// SelectSkillAction 选择技能的战斗动作
|
||
type SelectSkillAction struct {
|
||
PlayerID uint32 // 玩家ID
|
||
Skill *info.SkillEntity // 使用的技能
|
||
PetInfo *info.BattlePetEntity // 使用技能的宠物
|
||
Attack info.AttackValue
|
||
}
|
||
|
||
func (s *SelectSkillAction) GetPlayerID() uint32 {
|
||
return s.PlayerID
|
||
}
|
||
|
||
// 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)
|
||
}
|
||
|
||
// SystemGiveUpAction 系统强制放弃出手的动作
|
||
type SystemGiveUpAction struct {
|
||
BaseAction
|
||
Reason string // 放弃原因(如没有PP值、宠物全部倒下等)
|
||
LastPet info.BattlePetEntity // 最后在场的宠物
|
||
}
|
||
|
||
// Priority 返回动作优先级
|
||
func (s *SystemGiveUpAction) Priority() int {
|
||
return int(PlayerOperations.SystemGiveUp)
|
||
}
|
||
|
||
// PlayerOfflineAction 玩家掉线的战斗动作
|
||
type PlayerOfflineAction struct {
|
||
BaseAction
|
||
OfflineTime time.Time // 掉线时间
|
||
Reason info.FightOverInfo
|
||
}
|
||
|
||
// Priority 返回动作优先级
|
||
func (p *PlayerOfflineAction) Priority() int {
|
||
return int(PlayerOperations.PlayerOffline)
|
||
}
|