```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(fight): 添加旧组队协议支持并优化战斗系统

- 实现了旧组队协议相关功能,包括GroupReadyFightFinish、GroupUseSkill、
  GroupUseItem、GroupChangePet和GroupEscape方法
- 新增组队战斗相关的入站信息结构体定义
- 实现了组队BOSS战斗逻辑,添加groupBossSlotLimit常量
- 重构宠物技能设置逻辑,调整金币消耗时机
- 优化战斗循环逻辑,添加对无行动槽位的处理
- 改进AI行动逻辑,增加多位置目标选择
This commit is contained in:
昔念
2026-04-08 01:28:55 +08:00
parent 918cdeac0e
commit 0051ac0be8
21 changed files with 993 additions and 67 deletions

View File

@@ -47,6 +47,41 @@ func NewFightSingleControllerN(
)
}
// NewLegacyGroupFightSingleControllerN 创建旧组队协议的单人控制多站位战斗。
func NewLegacyGroupFightSingleControllerN(
ourController common.PlayerI,
oppController common.PlayerI,
ourPetsBySlot [][]model.PetInfo,
oppPetsBySlot [][]model.PetInfo,
fn func(model.FightOverInfo),
) (*FightC, errorcode.ErrorCode) {
if ourController == nil || oppController == nil {
return nil, errorcode.ErrorCodes.ErrSystemBusyTryLater
}
fightInfo := ourController.Getfightinfo()
ourInputs, err := buildSideInputsByController(ourController, ourPetsBySlot, fightInfo.Mode)
if err > 0 {
return nil, err
}
oppInputs, err := buildSideInputsByController(oppController, oppPetsBySlot, fightInfo.Mode)
if err > 0 {
return nil, err
}
return NewFightWithOptions(
WithFightInputs(ourInputs, oppInputs),
WithFightPlayersOnSide(
[]common.PlayerI{ourController},
[]common.PlayerI{oppController},
),
WithInputControllerBinding(InputControllerBindingSingle),
WithLegacyGroupProtocol(true),
WithFightCallback(fn),
WithFightInfo(fightInfo),
)
}
// NewFightPerSlotControllerN 创建 N 打战斗(多人各控制一个站位)。
// ourPlayers/oppPlayers 与 ourPetsBySlot/oppPetsBySlot 按站位一一对应。
func NewFightPerSlotControllerN(
@@ -116,6 +151,7 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
f := &FightC{}
f.ownerID = opts.owner.GetInfo().UserID
f.LegacyGroupProtocol = opts.legacyGroupProtocol
f.OurPlayers = opts.ourPlayers
f.OppPlayers = opts.oppPlayers
f.Switch = make(map[actionSlotKey]*action.ActiveSwitchAction)
@@ -160,9 +196,13 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
}
f.FightStartOutboundInfo = f.buildFightStartInfo()
f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2503, &f.ReadyInfo)
})
if f.LegacyGroupProtocol {
f.sendLegacyGroupReady()
} else {
f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2503, &f.ReadyInfo)
})
}
cool.Cron.AfterFunc(loadtime, func() {
our := f.primaryOur()
@@ -180,7 +220,11 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
f.WinnerId = opp.Player.GetInfo().UserID
}
f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2506, &f.FightOverInfo)
if f.LegacyGroupProtocol {
f.sendLegacyGroupOver(ff.Player, &f.FightOverInfo)
} else {
ff.Player.SendPackCmd(2506, &f.FightOverInfo)
}
ff.Player.QuitFight()
})
}