`` refactor(fight/effect): 重构效果系统,优化效果存储结构和叠层逻辑,移除EffectID结构``

This commit is contained in:
1
2025-10-31 11:21:24 +00:00
parent 7bc7776074
commit f1ff5a8dbc
9 changed files with 80 additions and 86 deletions

View File

@@ -57,8 +57,8 @@ func (e *Effect10) OnSkill(ctx input.Ctx) bool {
t1 := e.Input.FightC.GetRand().Int31n(3)
eff := input.Geteffect(input.EffectType.Status, int(e.Status))
if eff.ID != 0 {
eff.Effect.Duration(int(t1))
if eff.ID() != 0 {
eff.Duration(int(t1))
ctx.AddEffect(eff)
}

View File

@@ -20,7 +20,7 @@ func NewEffectStat(b bool) input.Effect {
EffectNode: node.EffectNode{},
Etype: b,
}
ret.MaxStack(-1) //无限叠加
return ret
}

View File

@@ -21,11 +21,11 @@ type StatusNotSkill struct {
// 不能出手
func (e *StatusNotSkill) Skill_Hit_Pre(ctx input.Ctx) bool {
if e.EffectStatus.Status == info.PetStatus.Sleep {
// tt := &StatusSleep{}
// tt.SetArgs(e.Input, 0) //睡眠没参数
// tt.ID((- int(info.PetStatus.Sleep))) //添加ID
ctx.AddEffect(&input.EffectID{ //对对方添加出手解除效果
ID: -1,
Effect: &StatusSleep{},
})
// ctx.AddEffect(tt)
}
return false

View File

@@ -710,12 +710,12 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
for i := 0; i < 20; i++ { //堆叠状态剩余回合
t := f.First.GetEffect(input.EffectType.Status, i)
if t.ID != 0 {
ret.FAttack.Status[i] = int8(t.Effect.Duration())
if t[0].ID() != 0 { //状态都是叠层类的
ret.FAttack.Status[i] = int8(t[0].Duration())
}
t = f.Second.GetEffect(input.EffectType.Status, i)
if t.ID != 0 {
ret.SAttack.Status[i] = int8(t.Effect.Duration())
if t[0].ID() != 0 {
ret.SAttack.Status[i] = int8(t[0].Duration())
}
}

View File

@@ -45,7 +45,7 @@ type Effect interface {
//boss是进入防守方才被添加抵御异常状态效果的boss免疫的实质是给挑战者挂载一个阻止添加给对手的debuff
EFFect_Befer()
SetArgs(input *Input, param ...int)
GetArgs() []int
// 治疗相关触发
Heal_Pre(action.BattleActionI) bool // 治疗前触发 回复翻倍效果
Heal(action.BattleActionI) bool // 治疗生效时触发 药剂反噬
@@ -59,5 +59,6 @@ type Effect interface {
NotALive()
GetOwner() bool // 技能属主,比如寄生和镇魂歌,属主是对方)
GetInput() *Input
ID(...int) int
//GetSkill() *BattleSkillEntity //获得技能ctx
}

View File

@@ -2,7 +2,6 @@ package input
import (
"blazing/common/data/xmlres"
"blazing/common/utils"
"blazing/logic/service/common"
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/info"
@@ -21,7 +20,7 @@ type Input struct {
*info.AttackValue
FightC common.FightI
// info.BattleActionI
Effects *utils.OrderMap[int, Effect] //effects 实际上全局就是effect无限回合 //effects容器 技能的
Effects []Effect //effects 实际上全局就是effect无限回合 //effects容器 技能的
DamageZone struct {
Damage decimal.Decimal //伤害
BeforeADD decimal.Decimal //攻击伤害
@@ -40,7 +39,7 @@ type Input struct {
func NewInput(c common.FightI, p common.PlayerI) *Input {
ret := &Input{FightC: c, Player: p}
ret.Effects = utils.NewOrderedMap[int, Effect](nil)
ret.Effects = make([]Effect, 0)
// t := Geteffect(EffectType.Damage, 0)
// t.Effect.SetArgs(ret)
@@ -95,7 +94,7 @@ func (i *Input) GetStatusBonus() float64 {
t := Geteffect(EffectType.Status, statusIdx)
// 检查状态是否存在数组中值为1表示存在该状态
if t.ID != 0 && t.Effect.Stack() > 0 {
if t != nil && t.Stack() > 0 {
if bonus, exists := statusBonuses[info.EnumBattleStatus(statusIdx)]; exists && bonus > maxBonus {
maxBonus = bonus
}
@@ -116,21 +115,22 @@ func (i *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) {
args := xmlres.EffectArgs[v]
//这里是给双方添加buff
if t.ID != 0 {
t.Effect.SetArgs(i, temparg[:args]...) //设置入参,施加方永远是我方
if t != nil {
t.SetArgs(i, temparg[:args]...) //设置入参,施加方永远是我方
t.ID(v)
if t.Effect.GetOwner() { //如果取反,说明是给对方添加的回合效果
if t.GetOwner() { //如果取反,说明是给对方添加的回合效果
//实际上,owner永远为反,说明是对方给我添加的
t.Effect.SetArgs(i, temparg[:args]...) //设置入参,施加方永远是我方
t.SetArgs(i, temparg[:args]...) //设置入参,施加方永远是我方
//给双方添加
defender.AddEffect(t)
} else {
t.Effect.SetArgs(i, temparg[:args]...) //设置入参
t.SetArgs(i, temparg[:args]...) //设置入参
i.AddEffect(t)
}
//这里是临时缓存buff,后面确认命中后修改HIT状态
i.EffectCache = append(i.EffectCache, t.Effect)
i.EffectCache = append(i.EffectCache, t)
}
temparg = temparg[args:]

View File

@@ -25,7 +25,7 @@ func InitEffect(etype EnumEffectType, id int, t Effect) {
NodeM[id+int(etype)] = t
}
func Geteffect(etype EnumEffectType, id int) *EffectID {
func Geteffect(etype EnumEffectType, id int) Effect {
//todo 获取前GetEffect
ret, ok := NodeM[id+int(etype)]
@@ -34,13 +34,10 @@ func Geteffect(etype EnumEffectType, id int) *EffectID {
eff := deep.MustCopy(ret)
return &EffectID{
ID: id + int(etype),
Effect: eff.(Effect),
}
return eff.(Effect)
//todo 获取后GetEffect
}
return &EffectID{}
return nil
}
// * battle_lv: atk(0), def(1), sp_atk(2), sp_def(3), spd(4), accuracy(5)
@@ -68,35 +65,30 @@ func (c *Input) GetProp(id int, istue bool) int {
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,
func (c *Input) CountEffect(etype EnumEffectType, id int) int {
return len(c.GetEffect(etype, id))
}
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)
}
//todo 获取后GetEffect
}
return &EffectID{}
return ret
}
func (c *Input) StatEffect_Exist(id int) bool {
rer, ok := c.Effects.Get(id + int(EffectType.Status))
if ok && rer.Alive() {
return true
for _, v := range c.Effects {
if v.ID() == id && v.Alive() {
return true
}
}
return false
}
type EffectID struct {
ID int
Effect Effect
}
func (c *Input) GetCurrAttr(id int) *model.PetInfo {
//todo 获取前GetEffect
@@ -105,41 +97,30 @@ func (c *Input) GetCurrAttr(id int) *model.PetInfo {
//todo 获取后GetEffect
}
func (c *Input) AddEffect(e *EffectID) {
if e.ID == 0 {
return
}
func (c *Input) AddEffect(e Effect) {
//todo 免疫
//TODO 先激活
fmt.Println("产生回合数", e.ID, e.Effect.Duration())
fmt.Println("产生回合数", e.ID(), e.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())
for _, v := range c.Effects {
if v.ID() == e.ID() && v.Alive() {
if v.MaxStack() >= 0 {
v.NotALive() //取消之前效果
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 false
return
}
return true
})
}
//无限叠加比如能力提升类buff
// 如果没有同 ID 的效果,直接添加
c.Effects = append(c.Effects, e)
}
@@ -148,8 +129,7 @@ func (c *Input) AddEffect(e *EffectID) {
// 返回值:所有 Effect 的方法返回值列表
func (c *Input) Exec(fn func(Effect) bool) bool {
result := true
c.Effects.Range(func(key int, value Effect) bool {
for _, value := range c.Effects {
if value.Alive() {
result1 := fn(value)
if !result1 {
@@ -158,20 +138,20 @@ func (c *Input) Exec(fn func(Effect) bool) bool {
}
return true
})
}
return result
}
// 消除回合类效果 efftype 输入是消对方的还是自己的,false是自己,true是对方
func (c *Input) CancelTurn(efftype bool) {
c.Effects.Range(func(key int, value Effect) bool {
for _, value := range c.Effects {
if value.Duration() > 0 { //false是自身,true是对方,反转后为真就是自己的
//slice = append(slice[:i], slice[i+1:]...)
value.NotALive()
}
return true
})
return
}
}

View File

@@ -10,9 +10,9 @@ import (
type EffectNode struct {
duration int // 默认为-1 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久) \
Input *input.Input
stacks int // 当前层数
Input *input.Input
stacks int // 当前层数
id int
maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 ,异常和能力的叠层
SideEffectArgs []int // 附加效果参数
Owner bool //是否作用自身
@@ -56,6 +56,14 @@ func (this *EffectNode) Stack(t ...int) int {
return this.stacks
}
func (this *EffectNode) ID(t ...int) int {
if len(t) > 0 {
this.id = t[0]
}
return this.id
}
func (this *EffectNode) Hit(t ...bool) bool {
if len(t) > 0 {
@@ -86,6 +94,11 @@ func (this *EffectNode) SetArgs(t *input.Input, a ...int) {
this.Input = t
this.SideEffectArgs = a
}
func (this *EffectNode) GetArgs() []int {
return this.SideEffectArgs
}
func (this *EffectNode) AttackTime(*input.Input, *input.Input) bool {

BIN
login/login → public/login Normal file → Executable file

Binary file not shown.