fix(fight): 修正空变更导致的潜在逻辑问题

This commit is contained in:
1
2025-11-30 04:57:48 +00:00
parent c55a1fd5fb
commit 1938346e89
5 changed files with 124 additions and 65 deletions

View File

@@ -3,7 +3,6 @@ package input
import (
"blazing/common/data/xmlres"
"fmt"
"sort"
"blazing/logic/service/common"
"blazing/logic/service/fight/action"
@@ -58,33 +57,21 @@ func NewInput(c common.FightI, p common.PlayerI) *Input {
}
// 非原地交换收集非0血量精灵 + 0血量精灵拼接后返回
func (our *Input) SortPet() {
sort.Slice(our.AllPet, func(i, j int) bool {
x, y := our.AllPet[i], our.AllPet[j]
// 若x血量>0且y血量=0则x排在前
if x.Info.Hp > 0 && y.Info.Hp <= 0 {
return true
}
// 若x血量=0且y血量>0则x排在后
if x.Info.Hp <= 0 && y.Info.Hp > 0 {
return false
}
// 同类型(都>0或都=0保持原有顺序
return i < j
})
for _, v := range our.AllPet {
if v.Info.Hp == 0 {
var nonZeroHP []*info.BattlePetEntity // 收集血量>0的精灵保持原顺序
var zeroHP []*info.BattlePetEntity // 收集血量=0的精灵保持原顺序
v.NotAlive = true
} else {
for _, e1 := range v.Info.EffectInfo {
// 线性遍历一次,分类收集
for _, s := range our.AllPet {
if s.HP > 0 {
for _, e1 := range s.Info.EffectInfo {
t := Geteffect(EffectType.NewSel, e1.EID)
if t != nil {
ef := t.ID()
fmt.Println("初始化特性", ef.Suffix())
ef.SetCatchTime(v.Info.CatchTime)
ef.SetCatchTime(s.Info.CatchTime)
t.ID(ef)
@@ -94,10 +81,17 @@ func (our *Input) SortPet() {
}
}
nonZeroHP = append(nonZeroHP, s)
} else {
s.NotAlive = true
zeroHP = append(zeroHP, s)
}
}
// 拼接非0血量精灵在前0血量精灵在后
our.AllPet = append(nonZeroHP, zeroHP...)
}
func (our *Input) GetPetInfo() *info.BattlePetEntity {
return our.CurrentPet