Files
bl/logic/service/fight/input/team.go
昔念 0051ac0be8
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(fight): 添加旧组队协议支持并优化战斗系统

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

123 lines
2.6 KiB
Go

package input
import "github.com/gogf/gf/v2/util/grand"
// TeamSlots 返回当前输入所在阵营的全部有效战斗位视图。
func (our *Input) TeamSlots() []*Input {
if our == nil {
return nil
}
if len(our.Team) == 0 {
return []*Input{our}
}
slots := make([]*Input, 0, len(our.Team))
for _, teammate := range our.Team {
if teammate == nil {
continue
}
slots = append(slots, teammate)
}
return slots
}
// TeamSlotIndex 返回当前输入在本阵营中的原始站位下标。
func (our *Input) TeamSlotIndex() int {
if our == nil || len(our.Team) == 0 {
return 0
}
for idx, teammate := range our.Team {
if teammate == our {
return idx
}
}
return 0
}
// Teammates 返回队友列表,不包含自己。
func (our *Input) Teammates() []*Input {
if our == nil {
return nil
}
teammates := make([]*Input, 0, len(our.Team))
for _, teammate := range our.TeamSlots() {
if teammate == nil || teammate == our {
continue
}
teammates = append(teammates, teammate)
}
return teammates
}
// LivingTeammates 返回当前仍有存活出战精灵的队友列表。
func (our *Input) LivingTeammates() []*Input {
if our == nil {
return nil
}
teammates := make([]*Input, 0, len(our.Team))
for _, teammate := range our.Teammates() {
currentPet := teammate.CurrentPet()
if currentPet == nil || currentPet.Info.Hp == 0 {
continue
}
teammates = append(teammates, teammate)
}
return teammates
}
// HasLivingTeammate 用于快速判断当前战斗位是否还有存活队友。
func (our *Input) HasLivingTeammate() bool {
return len(our.LivingTeammates()) > 0
}
// OpponentSlotAt 返回指定敌方站位。
func (our *Input) OpponentSlotAt(index int) *Input {
if our == nil {
return nil
}
if index >= 0 && index < len(our.OppTeam) {
return our.OppTeam[index]
}
if index == 0 {
return our.Opp
}
return nil
}
// RandomOpponentSlotIndex 返回一个可用的敌方站位下标,优先从存活站位中随机。
func (our *Input) RandomOpponentSlotIndex() int {
if our == nil {
return 0
}
if len(our.OppTeam) == 0 {
if our.Opp != nil {
return 0
}
return 0
}
living := make([]int, 0, len(our.OppTeam))
available := make([]int, 0, len(our.OppTeam))
for idx, opponent := range our.OppTeam {
if opponent == nil {
continue
}
available = append(available, idx)
current := opponent.CurrentPet()
if current != nil && current.Info.Hp > 0 {
living = append(living, idx)
}
}
candidates := living
if len(candidates) == 0 {
candidates = available
}
if len(candidates) == 0 {
return 0
}
if len(candidates) == 1 {
return candidates[0]
}
return candidates[grand.Intn(len(candidates))]
}