Files
bl/logic/service/fight/input/node.go
昔念 83fb06a229 feat(utils): 重构 OrderedMap 为 OrderMap,支持排序和非阻塞遍历
- 将原有的 `OrderedMap` 替换为 `OrderMap`,基于 `map` 和 `slice` 实现,提升性能并简化逻辑
- 支持自定义 key 排序规则,若未提供则按插入顺序维护
- 提供 `Set`、`Get`、`Delete`、`Keys`、`Values` 等基本操作,均并发安全
- 引入非阻塞遍历机制(`Iter`、`Iter
2025-10-22 21:30:05 +08:00

178 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.Get(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.Get(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.Get(e.ID)
if !ok {
c.Effects.Set(e.ID, e.Effect)
return
}
if !eff.Alive() { //如果不存活
c.Effects.Set(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
})
}