Files
bl/logic/service/fight/input/node.go
昔念 30ed47a30c ```
refactor(socket): 优化消息处理逻辑,避免顺序执行问题

将消息处理的循环从协程外部移入协程内部,确保每个消息在独立的 goroutine 中处理,
避免因并发导致的消息顺序错乱问题。同时移除了多余的空行,使代码更简洁。

fix(controller): 为低 ID 用户设置 VIP 标志

在 COMMEND_ONLINE 接口逻辑中,新增对 UserID 小于 10000 的用户设置 IsVip = 1,
用于标识测试或特殊用户身份。

ref
2025-11-03 03:59:59 +08:00

162 lines
3.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 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) {
t.ID(id) //设置ID
NodeM[id+int(etype)] = t
}
func Geteffect(etype EnumEffectType, id int) Effect {
//todo 获取前GetEffect
ret, ok := NodeM[id+int(etype)]
if ok {
//todo 获取前GetEffect
eff := deep.MustCopy(ret)
return eff
//todo 获取后GetEffect
}
return nil
}
// * 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) Effect {
var ret []Effect
for _, v := range c.Effects {
if v.ID() == id {
ret = append(ret, v)
}
}
if len(ret) > 0 {
return ret[len(ret)-1]
}
return nil
}
func (c *Input) StatEffect_Exist(id int) bool {
for _, v := range c.Effects {
if v.ID() == id && v.Alive() {
return true
}
}
return false
}
func (c *Input) GetCurrAttr(id int) *model.PetInfo {
//todo 获取前GetEffect
return c.CurrentPet.Info
//todo 获取后GetEffect
}
func (c *Input) AddEffect(e Effect) {
//todo 免疫
//TODO 先激活
fmt.Println("产生回合数", e.ID(), e.Duration())
// 如果已有同 ID 的效果,尝试叠加
for _, v := range c.Effects {
if v.ID() == e.ID() && v.Alive() {
v.NotALive() //取消之前效果
if v.MaxStack() > 0 {
if v.Stack() < v.MaxStack() { //如果小于最大叠层,状态可以叠层
e.SetArgs(v.GetInput(), v.GetArgs()...) //参数输入
e.Stack(v.Stack() + e.Stack()) //获取到当前叠层数然后叠加
//v.Duration(e.Duration()) //回合数覆盖
}
}
c.Effects = append(c.Effects, e)
return
}
}
//无限叠加比如能力提升类buff
// 如果没有同 ID 的效果,直接添加
c.Effects = append(c.Effects, e)
}
// 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
for _, value := range c.Effects {
if value.Alive() {
if !fn(value) { //存在false,但是仍然要向下执行
result = false //如果是false,说明存在阻止向下执行的effect比如免疫能力提升效果
}
}
}
return result
}
// 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方
func (c *Input) CancelTurn(efftype bool) {
for _, value := range c.Effects {
if value.Duration() > 0 { //false是自身,true是对方,反转后为真就是自己的
//slice = append(slice[:i], slice[i+1:]...)
value.NotALive()
}
return
}
}