```
feat(fight): 增加战斗模式枚举并重构战斗逻辑判断 - 引入完整的 BattleMode 枚举定义,替代原有的 BattleStatus,明确区分各类战斗场景 - 在多个控制器中替换对旧 Status 字段的依赖,统一使用 Mode 判断战斗状态 - 修复部分函数调用前未检查 FightC 是否为空的问题,增加 ErrBattleEnded 错误返回 - 调整
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/player"
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
)
|
||||
@@ -148,15 +147,20 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
|
||||
|
||||
// 3. 根据战斗类型判断是否满足战斗启动条件,满足则启动
|
||||
switch f.Info.Status {
|
||||
case info.BattleStatus.FIGHT_WITH_PLAYER: // PVP战斗:需双方都准备完成
|
||||
|
||||
case info.BattleMode.FIGHT_WITH_NPC: // NPC/野怪战斗:处理捕捉相关逻辑后启动
|
||||
//f.handleNPCFightSpecial(&fightStartInfo)
|
||||
|
||||
if f.Opp.Player.(*player.AI_player).CanCapture > 0 {
|
||||
f.Opp.CanCapture = f.Opp.Player.(*player.AI_player).CanCapture
|
||||
fightStartInfo.Info2.Catchable = 1 //可以捕捉就置1
|
||||
}
|
||||
f.startBattle(fightStartInfo)
|
||||
default: // PVP战斗:需双方都准备完成
|
||||
if f.checkBothPlayersReady(c) {
|
||||
f.startBattle(fightStartInfo)
|
||||
}
|
||||
case info.BattleStatus.FIGHT_WITH_BOSS: // BOSS战:单方准备完成即可启动
|
||||
f.startBattle(fightStartInfo)
|
||||
case info.BattleStatus.FIGHT_WITH_NPC: // NPC/野怪战斗:处理捕捉相关逻辑后启动
|
||||
f.handleNPCFightSpecial(&fightStartInfo)
|
||||
f.startBattle(fightStartInfo)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,28 +189,6 @@ func (f *FightC) checkBothPlayersReady(currentPlayer common.PlayerI) bool {
|
||||
return opponentInput.Finished
|
||||
}
|
||||
|
||||
// handleNPCFightSpecial 处理NPC战斗的特殊逻辑(如可捕捉标记)
|
||||
func (f *FightC) handleNPCFightSpecial(startInfo *info.FightStartOutboundInfo) {
|
||||
// 检查野怪是否可捕捉(根据宠物ID获取捕捉率)
|
||||
if len(f.ReadyInfo.OpponentPetList) == 0 {
|
||||
return
|
||||
}
|
||||
npcPetID := int(f.ReadyInfo.OpponentPetList[0].ID)
|
||||
petCfg, ok := xmlres.PetMAP[npcPetID]
|
||||
if !ok {
|
||||
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
||||
return
|
||||
}
|
||||
|
||||
catchRate := gconv.Int(petCfg.CatchRate)
|
||||
if catchRate > 0 {
|
||||
startInfo.Info2.Catchable = 1 // 标记为可捕捉
|
||||
// 标记AI对手允许被捕捉(类型断言确保安全)
|
||||
f.Opp.CanCapture = true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// startBattle 启动战斗核心逻辑:提交战斗循环任务并通知双方
|
||||
func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user