feat(fight): 调整战斗逻辑与初始化流程

- 移除 initplayer 中重复的 InitAttackValue 调用
- 启用 battleLoop 的超时时间为 60 秒
- 优化切换宠物时的出手顺序逻辑
- 修复 processSkillAttack 中缺少的 else 分支
- 在 enterturn 中重新初始化双方攻击值
- 清理无用的日志打印和冗余代码
- 修复 SendPack 中连接判断逻辑,确保类型安全
This commit is contained in:
2025-10-21 22:14:30 +08:00
parent ee119a0f0f
commit a69e9882d9
3 changed files with 33 additions and 21 deletions

View File

@@ -96,7 +96,7 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) {
temp := input.NewInput(f, c)
temp.AllPet = make([]*info.BattlePetEntity, 0)
temp.InitAttackValue()
for i := 0; i < len(c.GetInfo().PetList); i++ {
if f.Info.MAXPET == 0 || i < int(f.Info.MAXPET) {
@@ -185,7 +185,7 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla
ff.Player.SendNoteReadyToFightInfo(f.Info)
})
}()
//go f.battleLoop() // 起战斗循环
return f
}
@@ -239,7 +239,7 @@ func (f *FightC) battleLoop() {
f.Round++ //回合数自增
actions := make(map[uint32]action.BattleActionI) // 每个玩家一条记录
timeout := time.After(30 * time.Second)
timeout := time.After(60 * time.Second)
for len(actions) < 2 {
select {
@@ -322,22 +322,32 @@ func (f *FightC) battleLoop() {
f.closefight = true
case *action.ActiveSwitchAction: // 切换上场的, 切换方放弃出手
leftAction := BattleActionI[0]
rightAction := BattleActionI[1]
// 如果后手不是技能,替换成空技能(放弃出手)
if _, ok := rightAction.(*action.SelectSkillAction); !ok {
rightAction = &action.SelectSkillAction{
if _, ok := BattleActionI[1].(*action.SelectSkillAction); !ok {
BattleActionI[1] = &action.SelectSkillAction{
ID: 0,
BaseAction: action.NewBaseAction(rightAction.GetPlayerID()),
BaseAction: action.NewBaseAction(BattleActionI[1].GetPlayerID()),
}
}
f.enterturn(rightAction.(*action.SelectSkillAction),
&action.SelectSkillAction{
f.enterturn(&action.SelectSkillAction{ //双方均放弃出手
ID: 0,
BaseAction: action.NewBaseAction(leftAction.GetPlayerID()),
})
BaseAction: action.NewBaseAction(BattleActionI[1].GetPlayerID()),
},
&action.SelectSkillAction{
ID: 0,
BaseAction: action.NewBaseAction(BattleActionI[0].GetPlayerID()),
})
} else {
f.enterturn(BattleActionI[1].(*action.SelectSkillAction), //后手方先手,先手方放弃出手
&action.SelectSkillAction{
ID: 0,
BaseAction: action.NewBaseAction(BattleActionI[0].GetPlayerID()),
})
}
case *action.UseItemAction: // 使用道具
switch {
@@ -474,6 +484,8 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *action.S
}
} else {
}
for _, e := range attacker.EffectCache {
//这里实现应该参考本地技能是否命中,然后
@@ -536,8 +548,9 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方
}
fmt.Println("房主", f.First.CurrentPet.Info.CatchTime, "挑战者", f.Second.CurrentPet.Info.CatchTime)
f.First.InitAttackValue()
f.Second.InitAttackValue()
fmt.Println("房主", fattack.ID, "挑战者", sattack.ID)
switch {
case sattack.ID != 0:
@@ -719,13 +732,15 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
f.Broadcast(func(ff *input.Input) {
for _, v := range f.Switch {
if ff.Player.GetInfo().UserID != v.PlayerID {
ff.Player.SendChangePet(v.Reason)
}
}
f.Switch = []*action.ActiveSwitchAction{}
fmt.Println("得到用户", ff.Player.GetInfo().UserID)
ff.Player.SendAttackValue(ret)
})
f.Switch = []*action.ActiveSwitchAction{}
}

View File

@@ -7,7 +7,6 @@ import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/player"
"fmt"
"math"
"github.com/gogf/gf/v2/util/gconv"
@@ -138,8 +137,6 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
rrsult()
case info.BattleStatus.FIGHT_WITH_NPC: // 野怪战斗
//判断捕捉率大于0
fmt.Println("CatchRate", xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate)
if gconv.Int(xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate) > 0 {
rett.Info2.Catchable = 1
t, _ := f.Opp.Player.(*player.AI_player)

View File

@@ -231,7 +231,7 @@ func (p *Player) ItemAdd(t []model.SingleItemInfo) {
}
func (p *Player) SendPack(b []byte) error {
if p.MainConn == nil {
if _, ok := p.MainConn.Context().(*ClientData); !ok {
return fmt.Errorf("链接错误,取消发包")
}