feat(fight_boss): 优化BOSS战斗奖励逻辑并修复宠物等级突破100级限制 重构了handleMapBossFightRewards函数,将奖励逻辑分离到独立的处理函数中, 增加了shouldGrantBossWinBonus条件判断,确保只有满足条件时才发放胜利奖励。 同时修复了宠物等级系统,允许宠物等级突破100级限制但面板属性仍保持100级上限, 改进了经验获取和面板更新逻辑。 fix(item
90 lines
2.4 KiB
Go
90 lines
2.4 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 TestAddPetExpAllowsLevelBeyond100WhilePanelStaysCapped(t *testing.T) {
|
|
petID := firstPetIDForTest(t)
|
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
|
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
|
if petInfo == nil {
|
|
t.Fatalf("failed to generate test pet")
|
|
}
|
|
if expectedPanel == nil {
|
|
t.Fatalf("failed to generate expected 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 continue beyond 100, got %d", petInfo.Level)
|
|
}
|
|
if petInfo.MaxHp != expectedPanel.MaxHp {
|
|
t.Fatalf("expected max hp to stay capped at 100-level panel, got %d want %d", petInfo.MaxHp, expectedPanel.MaxHp)
|
|
}
|
|
if petInfo.Prop != expectedPanel.Prop {
|
|
t.Fatalf("expected props to stay capped at 100-level panel, got %+v want %+v", petInfo.Prop, expectedPanel.Prop)
|
|
}
|
|
}
|
|
|
|
func TestAddPetExpRecalculatesPanelForLevelAbove100(t *testing.T) {
|
|
petID := firstPetIDForTest(t)
|
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
|
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
|
if petInfo == nil {
|
|
t.Fatalf("failed to generate test pet")
|
|
}
|
|
if expectedPanel == nil {
|
|
t.Fatalf("failed to generate expected test pet")
|
|
}
|
|
petInfo.Level = 101
|
|
petInfo.Exp = 7
|
|
petInfo.MaxHp = 1
|
|
petInfo.Hp = 999999
|
|
|
|
player := &Player{
|
|
baseplayer: baseplayer{
|
|
Info: &playermodel.PlayerInfo{
|
|
ExpPool: 50_000,
|
|
},
|
|
},
|
|
}
|
|
|
|
player.AddPetExp(petInfo, 12_345)
|
|
|
|
if petInfo.Level < 101 {
|
|
t.Fatalf("expected level above 100 to be preserved, got %d", petInfo.Level)
|
|
}
|
|
if petInfo.MaxHp != expectedPanel.MaxHp {
|
|
t.Fatalf("expected max hp to be recalculated using level 100 cap, got %d want %d", petInfo.MaxHp, expectedPanel.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)
|
|
}
|
|
if player.Info.ExpPool != 50_000-12_345 {
|
|
t.Fatalf("expected exp pool to be consumed normally, got %d", player.Info.ExpPool)
|
|
}
|
|
}
|