Files
bl/logic/service/fight/node/node.go
2026-04-11 09:39:00 +08:00

314 lines
6.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package node
import (
element "blazing/common/data/Element"
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"sync"
"github.com/alpacahq/alpacadecimal"
)
type EffectContextHolder struct {
input.Ctx
}
// 检查,激活,延后
// /基础节点
type EffectNode struct {
duration int // 默认为-1 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久) \
Input *input.Input
stacks int // 当前层数
id input.EffectIDCombiner
canStack bool // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 ,异常和能力的叠层
isFirst bool
SideEffectArgs []int // 附加效果参数
cachedArgs []alpacadecimal.Decimal
// owner bool //是否作用自身
Success bool // 是否执行成功 成功XXX失败XXX
arget bool // 传出作用对象,默认0是自身,1是作用于对面
Flag int //过滤掉的战斗类型 pvp pve boss战斗,野怪全部生效
alive bool // 是否失效 effect返回值是否被取消是否被删除
hit bool
trunl sync.Once
EffectContextHolder
//增加owner target如果owner target都为自身就回合效果结束后再使用回合效果
}
func (e *EffectNode) Alive(t ...bool) bool {
if len(t) > 0 {
// println("效果失效", e.id.GetEffectType(), e.ID().Suffix(), t[0])
e.alive = t[0]
}
return e.alive
}
func (e *EffectNode) GetInput() *input.Input {
return e.Input
}
// SourceInput 返回 effect 的来源输入(优先 Ctx.Source回退到绑定输入
func (e *EffectNode) SourceInput() *input.Input {
if e.Ctx().Source != nil {
return e.Ctx().Source
}
return e.Input
}
// CarrierInput 返回当前持有该 effect 的输入(优先 Ctx.Carrier
func (e *EffectNode) CarrierInput() *input.Input {
if e.Ctx().Carrier != nil {
return e.Ctx().Carrier
}
return e.Ctx().Our
}
// TargetInput 返回当前 effect 作用目标输入(优先 Ctx.Target
func (e *EffectNode) TargetInput() *input.Input {
if e.Ctx().Target != nil {
return e.Ctx().Target
}
return e.Ctx().Opp
}
// OpponentInput 返回当前上下文中的对位输入(兼容旧链路)。
func (e *EffectNode) OpponentInput() *input.Input {
return e.Ctx().Opp
}
// SourcePet 返回来源输入当前出战精灵。
func (e *EffectNode) SourcePet() *info.BattlePetEntity {
in := e.SourceInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
// CarrierPet 返回持有效果输入当前出战精灵。
func (e *EffectNode) CarrierPet() *info.BattlePetEntity {
in := e.CarrierInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
// TargetPet 返回目标输入当前出战精灵。
func (e *EffectNode) TargetPet() *info.BattlePetEntity {
in := e.TargetInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
// OpponentPet 返回对位输入当前出战精灵。
func (e *EffectNode) OpponentPet() *info.BattlePetEntity {
in := e.OpponentInput()
if in == nil {
return nil
}
return in.CurrentPet()
}
// ForEachOpponentSlot 遍历对面全部站位;回调返回 false 时提前停止。
// 无组队视图时回退到单目标 OpponentInput。
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
}
}
}
// ForEachCarrierBenchPet 遍历持有效果方当前站位的后备精灵(不含当前出战)。
// 回调返回 false 时提前停止。
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 {
return false
}
return e.Ctx().Our.IsCurrentPetCatchTime(e.ID().GetCatchTime())
}
func (e *EffectNode) Ctx() *input.Ctx {
return &e.EffectContextHolder.Ctx
}
func (e *EffectNode) Stack(t ...int) int {
if len(t) > 0 {
e.stacks = t[0]
}
return e.stacks
}
func (e *EffectNode) ID(t ...input.EffectIDCombiner) input.EffectIDCombiner {
if len(t) > 0 {
e.id = t[0]
}
return e.id
}
// func (e *EffectNode) Hit(t ...bool) bool {
// if len(t) > 0 {
// // println("效果命中", e.id.GetEffectType(), e.id.Suffix(), t[0])
// e.hit = t[0]
// }
// return e.hit
// }
func (e *EffectNode) CanStack(t ...bool) bool {
if len(t) > 0 {
e.canStack = t[0]
}
return e.canStack
}
func (e *EffectNode) IsFirst(t ...bool) bool {
if len(t) > 0 {
e.isFirst = t[0]
}
return e.isFirst
}
// 回合类改成int.max,然后魂印类重写切换精灵替换
func (e *EffectNode) Duration(t ...int) int {
if len(t) > 0 {
e.duration = t[0]
}
return e.duration
}
// 设置参数,加上设置输入源
func (e *EffectNode) SetArgs(t *input.Input, a ...int) {
e.Input = t
if len(a) > 0 {
e.SideEffectArgs = a
e.cachedArgs = e.cachedArgs[:0]
for _, v := range a {
e.cachedArgs = append(e.cachedArgs, alpacadecimal.NewFromInt(int64(v)))
}
}
}
func (e *EffectNode) Args() []alpacadecimal.Decimal {
if len(e.cachedArgs) == len(e.SideEffectArgs) {
return e.cachedArgs
}
e.cachedArgs = e.cachedArgs[:0]
for _, v := range e.SideEffectArgs {
e.cachedArgs = append(e.cachedArgs, alpacadecimal.NewFromInt(int64(v)))
}
return e.cachedArgs
}
func (e *EffectNode) AttackTime(*input.Input, *input.Input) bool {
return true
}
func (e *EffectNode) PropBefer(in *input.Input, prop int8, level int8) bool {
return true
}
func (e *EffectNode) ISNaturalEnemy() bool {
source := e.SourceInput()
opp := e.OpponentInput()
if source == nil || opp == nil {
return false
}
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
}
return true
}
// func (e *EffectNode) BoolisFalse(t ...bool) bool {
// if len(t) > 0 {
// if t[0] == false {
// return true
// }
// return false
// }
// return false
// }
// func (e *EffectNode) BoolisTrue(t ...bool) bool {
// if len(t) > 0 {
// if t[0] == true {
// return true
// }
// return false
// }
// return false
// }