All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(fight): 添加旧组队协议支持并优化战斗系统 - 实现了旧组队协议相关功能,包括GroupReadyFightFinish、GroupUseSkill、 GroupUseItem、GroupChangePet和GroupEscape方法 - 新增组队战斗相关的入站信息结构体定义 - 实现了组队BOSS战斗逻辑,添加groupBossSlotLimit常量 - 重构宠物技能设置逻辑,调整金币消耗时机 - 优化战斗循环逻辑,添加对无行动槽位的处理 - 改进AI行动逻辑,增加多位置目标选择机制 - 完善捕获系统上下文处理,修复空指针问题 - 添加战斗状态更新和数据同步机制 fix(pet-skill): 修复宠物技能设置中的金币扣除逻辑错误 - 将金币扣除逻辑移到验证之后 - 修正宠物技能数量限制检查的顺序 - 防止重复添加已有技能的情况 refactor(fight): 重构战斗系统代码结构 - 分离新旧组队协议的战斗创建逻辑 - 优化战斗输入验证和处理流程 - 改进战斗循环中的错误处理机制 ```
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package fight
|
|
|
|
import (
|
|
"blazing/logic/service/common"
|
|
"blazing/modules/player/model"
|
|
"testing"
|
|
)
|
|
|
|
func TestArrangePetsBySlotLimit(t *testing.T) {
|
|
pets := []model.PetInfo{
|
|
{ID: 1, Hp: 10},
|
|
{ID: 2, Hp: 10},
|
|
{ID: 3, Hp: 10},
|
|
{ID: 4, Hp: 10},
|
|
{ID: 5, Hp: 10},
|
|
{ID: 6, Hp: 10},
|
|
}
|
|
|
|
slots := ArrangePetsBySlotLimit(pets, 3)
|
|
if len(slots) != 3 {
|
|
t.Fatalf("expected 3 slots, got %d", len(slots))
|
|
}
|
|
if len(slots[0]) != 2 || slots[0][0].ID != 1 || slots[0][1].ID != 4 {
|
|
t.Fatalf("slot 0 mismatch: %+v", slots[0])
|
|
}
|
|
if len(slots[1]) != 2 || slots[1][0].ID != 2 || slots[1][1].ID != 5 {
|
|
t.Fatalf("slot 1 mismatch: %+v", slots[1])
|
|
}
|
|
if len(slots[2]) != 2 || slots[2][0].ID != 3 || slots[2][1].ID != 6 {
|
|
t.Fatalf("slot 2 mismatch: %+v", slots[2])
|
|
}
|
|
}
|
|
|
|
func TestExpandPlayersWithSlotLimit(t *testing.T) {
|
|
players := []common.PlayerI{&stubPlayer{}, &stubPlayer{}}
|
|
petsByPlayer := [][]model.PetInfo{
|
|
{
|
|
{ID: 1, Hp: 10},
|
|
{ID: 2, Hp: 10},
|
|
{ID: 3, Hp: 10},
|
|
},
|
|
{
|
|
{ID: 11, Hp: 10},
|
|
{ID: 12, Hp: 10},
|
|
},
|
|
}
|
|
flatPlayers, flatSlots, err := ExpandPlayersWithSlotLimit(players, petsByPlayer, 1)
|
|
if err != 0 {
|
|
t.Fatalf("unexpected err: %v", err)
|
|
}
|
|
if len(flatPlayers) != 2 || len(flatSlots) != 2 {
|
|
t.Fatalf("unexpected flatten result: players=%d slots=%d", len(flatPlayers), len(flatSlots))
|
|
}
|
|
if len(flatSlots[0]) != 3 || flatSlots[0][0].ID != 1 || flatSlots[0][1].ID != 2 || flatSlots[0][2].ID != 3 {
|
|
t.Fatalf("player0 slot mismatch: %+v", flatSlots[0])
|
|
}
|
|
if len(flatSlots[1]) != 2 || flatSlots[1][0].ID != 11 || flatSlots[1][1].ID != 12 {
|
|
t.Fatalf("player1 slot mismatch: %+v", flatSlots[1])
|
|
}
|
|
}
|