Files
bl/logic/service/fight/input/node.go
昔念 20f9af7dca fix(logic/service/fight): 修复战斗效果添加逻辑并优化调试信息输出
- 在 effect_10-16_94_99_114.go 中正确设置 Effect 字段的自我引用
- 修复 OnHit 方法中效果添加的逻辑问题
- 在 node.go 的 AddEffect 方法中增加调试信息,输出效果 ID 和持续回合数
- 优化调试日志格式,便于追踪效果的持续时间变化
2025-10-22 00:41:58 +08:00

177 lines
3.8 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 input
import (
"blazing/logic/service/fight/info"
"fmt"
"blazing/modules/blazing/model"
"github.com/brunoga/deep"
"github.com/tnnmigga/enum"
)
// 战斗结束原因枚举
type EnumEffectType int
var EffectType = enum.New[struct {
Skill EnumEffectType `enum:"1000000"` //技能
NewSel EnumEffectType `enum:"2000000"` //特性
Status EnumEffectType `enum:"3000000"` //状态
}]()
var NodeM = make(map[int]Effect, 0)
func InitEffect(etype EnumEffectType, id int, t Effect) {
NodeM[id+int(etype)] = t
}
func Geteffect(etype EnumEffectType, id int) *EffectID {
//todo 获取前GetEffect
ret, ok := NodeM[id+int(etype)]
if ok {
//todo 获取前GetEffect
eff := deep.MustCopy(ret)
return &EffectID{
ID: id + int(etype),
Effect: eff.(Effect),
}
//todo 获取后GetEffect
}
return &EffectID{}
}
// * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5)
// 是否需要真实提升
func (c *Input) GetProp(id int, istue bool) int {
// 获取基础属性值
baseValue := int(c.AttackValue.Prop[id])
// 命中情况直接返回基础值(优先判断)
if id >= 5 {
return baseValue
}
// 处理id < 5的情况
if istue {
return baseValue
}
// 计算实际值(这里可以插入后续优化的函数调用)
realValue := info.CalculateRealValue(int(c.CurrentPet.Info.Prop[id]), baseValue)
// todo: 插入获取后处理函数,例如:
// realValue = postProcessValue(realValue, id, c)
return realValue
}
func (c *Input) GetEffect(etype EnumEffectType, id int) *EffectID {
rer, ok := c.Effects.Load(id + int(etype))
if ok {
return &EffectID{
ID: id + int(etype),
Effect: rer,
}
//todo 获取后GetEffect
}
return &EffectID{}
}
func (c *Input) StatEffect_Exist(id int) bool {
rer, ok := c.Effects.Load(id + int(EffectType.Status))
if ok && rer.Alive() {
return true
}
return false
}
type EffectID struct {
ID int
Effect Effect
}
func (c *Input) GetCurrAttr(id int) *model.PetInfo {
//todo 获取前GetEffect
return c.CurrentPet.Info
//todo 获取后GetEffect
}
func (c *Input) AddEffect(e *EffectID) {
if e.ID == 0 {
return
}
//todo 免疫
//TODO 先激活
fmt.Println("产生回合数", e.ID, e.Effect.Duration())
// 如果已有同 ID 的效果,尝试叠加
eff, ok := c.Effects.LoadOrStore(e.ID, e.Effect)
if ok {
return
}
if !eff.Alive() { //如果不存活
c.Effects.Store(e.ID, e.Effect)
return
}
c.Effects.Range(func(key int, value Effect) bool {
if e.ID == key {
//设置输入源
if value.Stack() < value.MaxStack() { //如果小于最大叠层
value.Stack(value.Stack()) //获取到当前叠层数然后叠加
} else {
//这里,说明是延续回合效果
fmt.Println(e.ID, "回合数", value.Duration())
value.Duration(value.Duration())
}
return false
}
return true
})
}
// ForEachEffectBool 遍历所有 Effect执行“无参数、返回 bool”的方法
// 参数 fn接收单个 Effect返回 bool如 func(e Effect) bool { return e.OnBattleStart() }
// 返回值:所有 Effect 的方法返回值列表
func (c *Input) Exec(fn func(Effect) bool) bool {
result := true
c.Effects.Range(func(key int, value Effect) bool {
if value.Alive() {
result1 := fn(value)
if !result1 {
result = false //如果是false,说明存在阻止向下执行的effect比如免疫能力提升效果
}
}
return true
})
return result
}
// 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方
func (c *Input) CancelTurn(efftype bool) {
c.Effects.Range(func(key int, value Effect) bool {
if value.Duration() > 0 { //false是自身,true是对方,反转后为真就是自己的
//slice = append(slice[:i], slice[i+1:]...)
value.NotALive()
}
return true
})
}