All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(fight): 新增疲惫状态并优化睡眠状态机制 - 实现疲惫状态(StatusTired),仅限制攻击技能,允许属性技能正常使用 - 重构睡眠状态,改为在被攻击且未miss时立即解除,而非技能使用后 - 修复寄生种子效果触发时机,改为回合开始时触发 - 调整寄生效果的目标为技能施放者而非
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package player
|
|
|
|
import (
|
|
"blazing/common/data/xmlres"
|
|
playermodel "blazing/modules/player/model"
|
|
"testing"
|
|
)
|
|
|
|
func firstPetIDForTest(t *testing.T) int {
|
|
t.Helper()
|
|
|
|
for id := range xmlres.PetMAP {
|
|
return id
|
|
}
|
|
|
|
t.Fatal("xmlres.PetMAP is empty")
|
|
return 0
|
|
}
|
|
|
|
func TestAddPetExpStopsAtLevel100(t *testing.T) {
|
|
petID := firstPetIDForTest(t)
|
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 99, nil, 0)
|
|
if petInfo == nil {
|
|
t.Fatalf("failed to generate test pet")
|
|
}
|
|
|
|
player := &Player{
|
|
baseplayer: baseplayer{
|
|
Info: &playermodel.PlayerInfo{
|
|
ExpPool: 1_000_000,
|
|
},
|
|
},
|
|
}
|
|
|
|
player.AddPetExp(petInfo, petInfo.NextLvExp+10_000)
|
|
|
|
if petInfo.Level != 100 {
|
|
t.Fatalf("expected pet level to stop at 100, got %d", petInfo.Level)
|
|
}
|
|
if petInfo.Exp != 0 {
|
|
t.Fatalf("expected pet exp to reset at level cap, got %d", petInfo.Exp)
|
|
}
|
|
}
|
|
|
|
func TestAddPetExpDoesNotConsumePoolAboveLevel100(t *testing.T) {
|
|
petID := firstPetIDForTest(t)
|
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
|
if petInfo == nil {
|
|
t.Fatalf("failed to generate test pet")
|
|
}
|
|
petInfo.Level = 101
|
|
petInfo.MaxHp = 1
|
|
petInfo.Hp = 999999
|
|
|
|
player := &Player{
|
|
baseplayer: baseplayer{
|
|
Info: &playermodel.PlayerInfo{
|
|
ExpPool: 50_000,
|
|
},
|
|
},
|
|
}
|
|
|
|
player.AddPetExp(petInfo, 12_345)
|
|
|
|
if petInfo.Level != 100 {
|
|
t.Fatalf("expected level to be normalized to 100, got %d", petInfo.Level)
|
|
}
|
|
if player.Info.ExpPool != 50_000 {
|
|
t.Fatalf("expected exp pool to remain unchanged, got %d", player.Info.ExpPool)
|
|
}
|
|
if petInfo.Exp != 0 {
|
|
t.Fatalf("expected exp to reset after normalization, got %d", petInfo.Exp)
|
|
}
|
|
if petInfo.MaxHp <= 1 {
|
|
t.Fatalf("expected pet panel to be recalculated, got max hp %d", petInfo.MaxHp)
|
|
}
|
|
if petInfo.Hp != petInfo.MaxHp {
|
|
t.Fatalf("expected hp to be clamped to recalculated max hp, got hp=%d maxHp=%d", petInfo.Hp, petInfo.MaxHp)
|
|
}
|
|
}
|