fix: correct self-destruct mutual KO handling
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
xinian
2026-04-16 09:21:02 +08:00
parent 9f7fd83626
commit 85f9c02ced
2 changed files with 43 additions and 2 deletions

View File

@@ -220,6 +220,15 @@ func (f *FightC) buildNoteUseSkillOutboundInfo() info.NoteUseSkillOutboundInfo {
return result
}
// normalizeMutualKO intentionally does not revive either side.
// Effects that need "survive at 1 HP" on mutual KO must cap damage in their
// own implementation instead of relying on a generic round fallback.
func normalizeMutualKO(attackerPet, defenderPet *info.BattlePetEntity) {
if attackerPet == nil || defenderPet == nil {
return
}
}
func (f *FightC) roundOpponentInput(attacker *input.Input) *input.Input {
if attacker == nil {
return nil
@@ -423,8 +432,8 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
return true
})
if defenderPet != nil && attackerPet != nil && defenderPet.Info.Hp <= 0 && attackerPet.Info.Hp <= 0 { //先手方死亡,触发反同归于尽
attackerPet.Info.Hp = 1
if defenderPet != nil && attackerPet != nil && defenderPet.Info.Hp <= 0 && attackerPet.Info.Hp <= 0 {
normalizeMutualKO(attackerPet, defenderPet)
}
if defenderPet != nil && defenderPet.Info.Hp <= 0 {

View File

@@ -0,0 +1,32 @@
package fight
import (
"testing"
fightinfo "blazing/logic/service/fight/info"
"blazing/modules/player/model"
)
func TestNormalizeMutualKODoesNotReviveAttacker(t *testing.T) {
attacker := fightinfo.CreateBattlePetEntity(model.PetInfo{
ID: 1,
Hp: 0,
MaxHp: 100,
CatchTime: 101,
})
defender := fightinfo.CreateBattlePetEntity(model.PetInfo{
ID: 2,
Hp: 0,
MaxHp: 100,
CatchTime: 202,
})
normalizeMutualKO(attacker, defender)
if attacker.Info.Hp != 0 {
t.Fatalf("expected attacker to remain defeated on mutual KO, got hp=%d", attacker.Info.Hp)
}
if defender.Info.Hp != 0 {
t.Fatalf("expected defender to remain defeated on mutual KO, got hp=%d", defender.Info.Hp)
}
}