```
feat(fight_boss): 优化BOSS战斗奖励逻辑并修复宠物等级突破100级限制 重构了handleMapBossFightRewards函数,将奖励逻辑分离到独立的处理函数中, 增加了shouldGrantBossWinBonus条件判断,确保只有满足条件时才发放胜利奖励。 同时修复了宠物等级系统,允许宠物等级突破100级限制但面板属性仍保持100级上限, 改进了经验获取和面板更新逻辑。 fix(item
This commit is contained in:
@@ -175,7 +175,7 @@ func (f *FightC) Over(c common.PlayerI, res model.EnumBattleOverReason) {
|
||||
// }
|
||||
|
||||
f.overl.Do(func() {
|
||||
f.Reason = res
|
||||
f.Reason = normalizeFightOverReason(res)
|
||||
if f.GetInputByPlayer(c, true) != nil {
|
||||
f.WinnerId = f.GetInputByPlayer(c, true).UserID
|
||||
}
|
||||
|
||||
@@ -7,12 +7,21 @@ import "blazing/modules/player/model"
|
||||
// 0=normal end 1=player lost/offline 2=overtime 3=draw 4=system error 5=npc escape.
|
||||
func buildFightOverPayload(over model.FightOverInfo) *model.FightOverInfo {
|
||||
payload := over
|
||||
payload.Reason = mapFightOverReasonFor2506(over.Reason)
|
||||
payload.Reason = model.EnumBattleOverReason(mapUnifiedFightOverReason(over.Reason))
|
||||
return &payload
|
||||
}
|
||||
|
||||
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
switch reason {
|
||||
func normalizeFightOverReason(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
if reason == model.BattleOverReason.DefaultEnd {
|
||||
return 0
|
||||
}
|
||||
return reason
|
||||
}
|
||||
|
||||
func mapUnifiedFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||
switch normalizeFightOverReason(reason) {
|
||||
case 0, model.BattleOverReason.Cacthok:
|
||||
return 0
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 1
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
@@ -20,12 +29,12 @@ func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBatt
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 3
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
// Player-initiated escape is handled by 2410 on the flash side; 2506 should
|
||||
// still land in a non-error bucket instead of "system error".
|
||||
return 1
|
||||
case model.BattleOverReason.Cacthok, model.BattleOverReason.DefaultEnd:
|
||||
return 0
|
||||
return 5
|
||||
default:
|
||||
return 4
|
||||
}
|
||||
}
|
||||
|
||||
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
return model.EnumBattleOverReason(mapUnifiedFightOverReason(reason))
|
||||
}
|
||||
|
||||
@@ -522,9 +522,9 @@ func (f *FightC) TURNOVER(cur *input.Input) {
|
||||
if f.IsWin(f.GetInputByPlayer(cur.Player, true)) { //然后检查是否战斗结束
|
||||
|
||||
f.FightOverInfo.WinnerId = f.GetInputByPlayer(cur.Player, true).UserID
|
||||
f.FightOverInfo.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.FightOverInfo.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.WinnerId = f.FightOverInfo.WinnerId
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = f.FightOverInfo.Reason
|
||||
|
||||
f.closefight = true
|
||||
// break
|
||||
|
||||
@@ -426,38 +426,15 @@ func (f *FightC) buildLegacyGroupOverInfo(over *model.FightOverInfo) *legacyGrou
|
||||
}
|
||||
|
||||
func mapLegacyGroupFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||
switch reason {
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 2
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
return 3
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 4
|
||||
case model.BattleOverReason.DefaultEnd:
|
||||
return 1
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
return 6
|
||||
default:
|
||||
return 5
|
||||
}
|
||||
return mapUnifiedFightOverReason(reason)
|
||||
}
|
||||
|
||||
func resolveLegacyGroupFightOverReason(over *model.FightOverInfo) uint32 {
|
||||
if over == nil {
|
||||
return 5
|
||||
}
|
||||
switch over.Reason {
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 2
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
return 3
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
return 6
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 4
|
||||
return mapUnifiedFightOverReason(0)
|
||||
}
|
||||
if over.WinnerId != 0 {
|
||||
return 1
|
||||
return mapUnifiedFightOverReason(0)
|
||||
}
|
||||
return mapLegacyGroupFightOverReason(over.Reason)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (f *FightC) battleLoop() {
|
||||
if player := f.primaryOppPlayer(); player != nil {
|
||||
f.WinnerId = player.GetInfo().UserID
|
||||
}
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.FightOverInfo.WinnerId = f.WinnerId
|
||||
f.FightOverInfo.Reason = f.Reason
|
||||
f.closefight = true
|
||||
@@ -86,7 +86,7 @@ func (f *FightC) battleLoop() {
|
||||
if player := f.primaryOurPlayer(); player != nil {
|
||||
f.WinnerId = player.GetInfo().UserID
|
||||
}
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.FightOverInfo.WinnerId = f.WinnerId
|
||||
f.FightOverInfo.Reason = f.Reason
|
||||
f.closefight = true
|
||||
|
||||
@@ -27,33 +27,24 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||
if petInfo == nil || addExp <= 0 {
|
||||
return
|
||||
}
|
||||
if petInfo.Level >= 100 {
|
||||
petInfo.Level = 100
|
||||
petInfo.Exp = 0
|
||||
if petInfo.Level > 100 {
|
||||
currentHP := petInfo.Hp
|
||||
petInfo.Update(false)
|
||||
petInfo.CalculatePetPane(100)
|
||||
if petInfo.Hp > petInfo.MaxHp {
|
||||
petInfo.Hp = petInfo.MaxHp
|
||||
}
|
||||
return
|
||||
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
||||
}
|
||||
addExp = utils.Min(addExp, p.Info.ExpPool)
|
||||
originalLevel := petInfo.Level
|
||||
exp := int64(petInfo.Exp) + addExp
|
||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||
gainedExp := exp //已获得的经验
|
||||
for petInfo.Level < 100 && exp >= int64(petInfo.NextLvExp) {
|
||||
for exp >= int64(petInfo.NextLvExp) {
|
||||
|
||||
petInfo.Level++
|
||||
|
||||
exp -= int64(petInfo.LvExp)
|
||||
petInfo.Update(true)
|
||||
}
|
||||
if petInfo.Level >= 100 {
|
||||
p.Info.ExpPool += exp // 超出100级上限的经验退回经验池
|
||||
gainedExp -= exp
|
||||
exp = 0
|
||||
}
|
||||
petInfo.Exp = (exp)
|
||||
// 重新计算面板
|
||||
if originalLevel != petInfo.Level {
|
||||
|
||||
@@ -17,12 +17,16 @@ func firstPetIDForTest(t *testing.T) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestAddPetExpStopsAtLevel100(t *testing.T) {
|
||||
func TestAddPetExpAllowsLevelBeyond100WhilePanelStaysCapped(t *testing.T) {
|
||||
petID := firstPetIDForTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 99, nil, 0)
|
||||
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{
|
||||
@@ -34,21 +38,29 @@ func TestAddPetExpStopsAtLevel100(t *testing.T) {
|
||||
|
||||
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.Level <= 100 {
|
||||
t.Fatalf("expected pet level to continue beyond 100, got %d", petInfo.Level)
|
||||
}
|
||||
if petInfo.Exp != 0 {
|
||||
t.Fatalf("expected pet exp to reset at level cap, got %d", petInfo.Exp)
|
||||
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 TestAddPetExpDoesNotConsumePoolAboveLevel100(t *testing.T) {
|
||||
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
|
||||
|
||||
@@ -62,19 +74,16 @@ func TestAddPetExpDoesNotConsumePoolAboveLevel100(t *testing.T) {
|
||||
|
||||
player.AddPetExp(petInfo, 12_345)
|
||||
|
||||
if petInfo.Level != 100 {
|
||||
t.Fatalf("expected level to be normalized to 100, got %d", petInfo.Level)
|
||||
if petInfo.Level < 101 {
|
||||
t.Fatalf("expected level above 100 to be preserved, 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.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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user