refactor: 重构战斗结构体以支持双打模式

This commit is contained in:
xinian
2026-04-04 22:13:42 +08:00
committed by cnb
parent 7916f90992
commit 39e1d4c42f
16 changed files with 543 additions and 246 deletions

View File

@@ -2,6 +2,7 @@ package node
import (
element "blazing/common/data/Element"
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"sync"
@@ -75,12 +76,90 @@ func (e *EffectNode) OpponentInput() *input.Input {
return e.Ctx().Opp
}
func (e *EffectNode) SourcePet() *info.BattlePetEntity {
in := e.SourceInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
func (e *EffectNode) CarrierPet() *info.BattlePetEntity {
in := e.CarrierInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
func (e *EffectNode) TargetPet() *info.BattlePetEntity {
in := e.TargetInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
func (e *EffectNode) OpponentPet() *info.BattlePetEntity {
in := e.OpponentInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
func (e *EffectNode) ForEachOpponentSlot(fn func(*input.Input) bool) {
if fn == nil {
return
}
carrier := e.CarrierInput()
if carrier == nil {
if opp := e.OpponentInput(); opp != nil {
fn(opp)
}
return
}
opponents := carrier.OpponentSlots()
if len(opponents) == 0 {
if opp := e.OpponentInput(); opp != nil {
fn(opp)
}
return
}
for _, opp := range opponents {
if opp == nil {
continue
}
if !fn(opp) {
return
}
}
}
func (e *EffectNode) ForEachCarrierBenchPet(fn func(*info.BattlePetEntity) bool) {
if fn == nil {
return
}
carrier := e.CarrierInput()
if carrier == nil {
return
}
for _, pet := range carrier.BenchPets() {
if pet == nil {
continue
}
if !fn(pet) {
return
}
}
}
// IsOwner reports whether the current phase's Our side owns this effect.
func (e *EffectNode) IsOwner() bool {
if e.Ctx().Our == nil || len(e.Ctx().Our.CurPet) == 0 || e.Ctx().Our.CurPet[0] == nil {
if e.Ctx().Our == nil {
return false
}
return e.ID().GetCatchTime() == e.Ctx().Our.CurPet[0].Info.CatchTime
return e.Ctx().Our.IsCurrentPetCatchTime(e.ID().GetCatchTime())
}
func (e *EffectNode) Ctx() *input.Ctx {
@@ -176,10 +255,15 @@ func (e *EffectNode) PropBefer(in *input.Input, prop int8, level int8) bool {
func (e *EffectNode) ISNaturalEnemy() bool {
source := e.SourceInput()
opp := e.OpponentInput()
if source == nil || opp == nil || source.CurPet[0] == nil || opp.CurPet[0] == nil {
if source == nil || opp == nil {
return false
}
t, _ := element.Calculator.GetOffensiveMultiplier(opp.CurPet[0].Type, source.CurPet[0].Type)
sourcePet := source.CurrentPet()
oppPet := opp.CurrentPet()
if sourcePet == nil || oppPet == nil {
return false
}
t, _ := element.Calculator.GetOffensiveMultiplier(oppPet.Type, sourcePet.Type)
if t <= 1 {
return false