package input import ( "blazing/common/utils" "blazing/logic/service/fight/info" "fmt" "blazing/modules/blazing/model" "github.com/alpacahq/alpacadecimal" "github.com/brunoga/deep" "github.com/gogf/gf/v2/util/gconv" "github.com/tnnmigga/enum" ) // 战斗结束原因枚举 type EnumEffectType uint16 var EffectType = enum.New[struct { Skill EnumEffectType `enum:"1"` //技能 NewSel EnumEffectType `enum:"2"` //特性 Status EnumEffectType `enum:"3"` //状态 Sub EnumEffectType `enum:"4"` //子效果 }]() var NodeM = make(map[int64]Effect, 0) func InitEffect(etype EnumEffectType, id int, t Effect) { pr := EffectIDCombiner{} pr.Combine(etype, 0, gconv.Uint16(id)) t.ID(pr) //设置ID NodeM[pr.EffectID()] = t } // 这里的catchtime为0,取出来之后如果是魂印,要重新赋值 func Geteffect[T int | byte | uint16](etype EnumEffectType, id T) Effect { pr := EffectIDCombiner{} pr.Combine(etype, 0, gconv.Uint16(id)) //todo 获取前GetEffect ret, ok := NodeM[pr.EffectID()] if ok { //todo 获取前GetEffect eff := deep.MustCopy(ret) if etype == EffectType.Status { eff.CanStack(true) //状态类不能被覆盖,只能无限叠加 } return eff //todo 获取后GetEffect } return nil } // * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5) // 是否需要真实提升 func (our *Input) GetProp(id int, istue bool) int { // 获取基础属性值 baseValue := int(our.AttackValue.Prop[id]) // 命中情况直接返回基础值(优先判断) if id >= 5 { return baseValue } // 处理id < 5的情况 if istue { return baseValue } // 计算实际值(这里可以插入后续优化的函数调用) realValue := info.CalculateRealValue(int(our.CurrentPet.Info.Prop[id]), baseValue) // todo: 插入获取后处理函数,例如: // realValue = postProcessValue(realValue, id, c) return realValue } func (our *Input) GetEffect(etype EnumEffectType, id int) Effect { var ret []Effect pr := EffectIDCombiner{} pr.Combine(etype, 0, gconv.Uint16(id)) for _, v := range our.Effects { if v.ID().Base == pr.Base && v.Alive() { ret = append(ret, v) } } if len(ret) > 0 { return ret[len(ret)-1] } return nil } func (our *Input) StatEffect_Exist(id info.EnumPetStatus) bool { t := our.GetEffect(EffectType.Status, int(id)) if t == nil { return false } return t.Alive() } func (our *Input) StatEffect_Exist_all() bool { for _, v := range our.Effects { t := v.ID() if t.GetEffectType() == EffectType.Status && v.Alive() { return true } } return false } // 判断是否是状态技能 func (our *Input) IS_Stat(v Effect) bool { t := v.ID() if t.GetEffectType() == EffectType.Status { return true } return false } // func (our *Input) GetCurrAttr(id int) model.PetInfo { //todo 获取前GetEffect return our.CurrentPet.Info //todo 获取后GetEffect } // 比较两个[]int是否内容相等 func equalInts(a, b []alpacadecimal.Decimal) bool { // 先判断长度是否相等 if len(a) != len(b) { return false } // 逐个比较元素 for i := range a { if a[i].IntPart() != b[i].IntPart() { return false } } return true } // 返回被替换eddect func (our *Input) AddEffect(in *Input, e Effect) Effect { if in != our { canuseskill := our.Exec(func(t Effect) bool { //这个是能否使用技能 //结算状态 return t.EFFect_Befer(in, e) //返回本身结算,如果false,说明不能使用技能了 }) if !canuseskill { return nil } } e.Alive(true) //添加后默认激活 //todo 免疫 //TODO 先激活 fmt.Println("产生回合数", e.ID(), e.Duration()) // 如果已有同 ID 的效果,尝试叠加 for _, v := range our.Effects { if v == e { return nil //完全相同,跳过执行 } //如果效果相同,id相同,参数相同,就是同一个,确认是否可以叠加,正常来说本身就可以共存 //衰弱本身参数也是相同的,区别只是传入的回合数不一样和层数不一样 if v.ID().Base == e.ID().Base && //找到相同的效果id v.Alive() && //如果之前的效果还存活 equalInts(v.Args(), e.Args()) { //如果层数可以叠加或者是无限层数 fmt.Println("重复效果", e.ID().Suffix(), v.ID().Suffix()) if !v.CanStack() { //说明进行了替换 v.Alive(false) //不允许叠层,取消效果 e.Duration(utils.Max(e.Duration(), v.Duration())) our.Effects = append(our.Effects, e) return v //这里把V替换掉了 } else { //默认给叠一层 v.Stack(v.Stack() + 1) //获取到当前叠层数然后叠加 //这里直接返回,不再继续执行后续效果,因为这里是可以叠加的效果 //v.Duration(e.Duration()) //回合数覆盖 v.Duration(utils.Max(e.Duration(), v.Duration())) return nil // c.Effects = append(c.Effects, e) //return } } } //无限叠加,比如能力提升类buff // 如果没有同 ID 的效果,直接添加 our.Effects = append(our.Effects, e) return nil } // ForEachEffectBool 遍历所有 Effect,执行“无参数、返回 bool”的方法 // 参数 fn:接收单个 Effect,返回 bool(如 func(e Effect) bool { return e.OnBattleStart() }) // 返回值:所有 Effect 的方法返回值列表 func (our *Input) Exec(fn func(Effect) bool) bool { result := true for _, value := range our.Effects { if value.Alive() { value.Ctx().Our = our value.Ctx().Opp = our.Opp //value.Ctx().DamageZone = &info.DamageZone{} if !fn(value) { //存在false,但是仍然要向下执行 result = false //如果是false,说明存在阻止向下执行的effect,比如免疫能力提升效果 } } } return result } // 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方 func (our *Input) CancelTurn(in *Input) { for _, value := range our.Effects { if value.Duration() > 0 && value.Alive() { //false是自身,true是对方,反转后为真就是自己的 //slice = append(slice[:i], slice[i+1:]...) value.Alive(false) } } } // // 消除全部 断回合效果,但是我放下场的时候应该断掉所有的回合类效果 // func (our *Input) CancelAll() { // our.Effects = make([]Effect, 0) // for _, value := range our.Effects { // value.Alive(false) // } // //取消到在对方的我方对对方的效果 // for _, value := range our.Opp.Effects { // if value.GetInput() == our { //false是自身,true是对方,反转后为真就是自己的 // //slice = append(slice[:i], slice[i+1:]...) // value.Alive(false) // } // } // }