Files
bl/logic/service/fight/input/team_test.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

61 lines
1.7 KiB
Go

package input
import (
"testing"
fightinfo "blazing/logic/service/fight/info"
"blazing/modules/player/model"
)
func TestLivingTeammatesFiltersSelfAndDeadSlots(t *testing.T) {
owner := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 10}}}}
aliveMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 5}}}}
deadMate := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}}
team := []*Input{owner, aliveMate, deadMate}
owner.Team = team
aliveMate.Team = team
deadMate.Team = team
teammates := owner.LivingTeammates()
if len(teammates) != 1 {
t.Fatalf("expected 1 living teammate, got %d", len(teammates))
}
if teammates[0] != aliveMate {
t.Fatalf("expected alive teammate to be returned")
}
if owner.HasLivingTeammate() != true {
t.Fatalf("expected owner to detect living teammate")
}
}
func TestTeamSlotIndexKeepsOriginalSlot(t *testing.T) {
first := &Input{}
second := &Input{}
third := &Input{}
team := []*Input{first, second, third}
first.Team = team
second.Team = team
third.Team = team
if got := third.TeamSlotIndex(); got != 2 {
t.Fatalf("expected slot index 2, got %d", got)
}
}
func TestRandomOpponentSlotIndexPrefersLivingTarget(t *testing.T) {
owner := &Input{}
deadOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 0}}}}
liveOpp := &Input{CurPet: []*fightinfo.BattlePetEntity{{Info: model.PetInfo{Hp: 12}}}}
owner.OppTeam = []*Input{deadOpp, liveOpp}
if got := owner.RandomOpponentSlotIndex(); got != 1 {
t.Fatalf("expected living opponent slot 1, got %d", got)
}
if got := owner.OpponentSlotAt(1); got != liveOpp {
t.Fatalf("expected opponent slot 1 to return live opponent")
}
}