refactor(fight): 重构战斗系统

- 重构了 BattleSkillEntity 结构,改名为 SkillEntity
- 优化了 Input 结构,移除了冗余的 Effect 容器
- 调整了 Effect 接口,增加了 SetInput 和 Alive 方法
- 重构了战斗逻辑中的技能使用和效果处理流程
- 优化了代码结构,提高了可读性和可维护性
This commit is contained in:
2025-09-15 00:40:19 +08:00
parent 906bad9e21
commit d9f09aa96a
10 changed files with 108 additions and 94 deletions

View File

@@ -9,7 +9,10 @@ func (this *EffectNode) PreTurnStart() bool {
}
// 回合开始
func (this *EffectNode) OnTurnStart(attacker, defender *input.Input) bool {
func (this *EffectNode) OnTurnStart(opp *input.Input) bool {
//处理异常状态
return true
}
@@ -17,9 +20,8 @@ func (this *EffectNode) OnTurnStart(attacker, defender *input.Input) bool {
func (this *EffectNode) TurnEnd() bool {
if this.duration != 0 { // 保留 (负数表示永久)
//this.GetBattle().Effects[this.GetInput().UserID].AddEffect(this) //重新添加buff到上下文
if this.duration == 0 { // 保留 (负数表示永久)
this.NotAlive = true
}
this.duration--
return true

View File

@@ -6,17 +6,18 @@ import (
)
// 技能命中计算
func (this *EffectNode) IsHit(attacker, defender *input.Input, skill *info.BattleSkillEntity) {
func (this *EffectNode) IsHit(opp *input.Input, skill *info.SkillEntity) {
}
// 被命中计算,默认直接返回,重写这个来实现闪避率
func (this *EffectNode) TakeHit(attacker, defender *input.Input, skill *info.BattleSkillEntity) {
func (this *EffectNode) TakeHit(opp *input.Input, skill *info.SkillEntity) {
}
func (this *EffectNode) UseSkill(attacker, defender *input.Input) bool {
return true
func (this *EffectNode) UseSkill(opp *input.Input) bool {
return this.Input.CurrentPet.HP != 0
}
func (this *EffectNode) OnSkillPP() bool {
panic("not implemented") // TODO: Implement
@@ -33,7 +34,7 @@ func (this *EffectNode) BeforeHit() bool {
panic("not implemented") // TODO: Implement
}
func (this *EffectNode) OnCritPreDamage() bool {
func (this *EffectNode) OnBeforeCalculateDamage(opp *input.Input, skill *info.SkillEntity) {
panic("not implemented") // TODO: Implement
}
@@ -41,7 +42,7 @@ func (this *EffectNode) PreDamage() bool {
panic("not implemented") // TODO: Implement
}
func (this *EffectNode) CalculateDamage(attacker, defender *input.Input, skill *info.BattleSkillEntity) {
func (this *EffectNode) CalculateDamage(opp *input.Input, skill *info.SkillEntity) {
panic("not implemented") // TODO: Implement
}
@@ -58,7 +59,7 @@ func (this *EffectNode) PostDamage() bool {
}
// 正常来说,什么都不做
func (this *EffectNode) IsCrit(attacker, defender *input.Input, skill *info.BattleSkillEntity) {
func (this *EffectNode) IsCrit(opp *input.Input, skill *info.SkillEntity) {
//return skill.Crit
}

View File

@@ -2,7 +2,6 @@ package node
import (
"blazing/logic/service/fight/input"
"context"
)
// 检查,激活,延后
@@ -10,9 +9,11 @@ import (
type EffectNode struct {
//Turn int // 当前回合数 ,回合数其实从战斗的上下文中获取
//本质上Ctx还要传入战斗双方数据来判断是否是本精灵切换
Ctx context.Context //节点上下文
duration int // 默认为-1 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久) 次数相当于重写回合
//Ctx context.Context //节点上下文
//次数相当于重写回合
duration int // 默认为-1 持续回合/次0 = 即时生效,>0 = 回合数 ,负数是永久) \
Input *input.Input
stacks int // 当前层数
ArgSize int
maxStack int // 最大叠加层数 ,正常都是不允许叠加的,除了衰弱特殊效果 ,异常和能力的叠层
@@ -21,10 +22,15 @@ type EffectNode struct {
Success bool // 是否执行成功 成功XXX失败XXX
arget bool // 传出作用对象,默认0是自身,1是作用于对面
Flag int //过滤掉的战斗类型 pvp pve boss战斗,野怪全部生效
Alive bool // 是否失效 effect返回值是否被取消是否被删除
NotAlive bool // 是否失效 effect返回值是否被取消是否被删除
//增加owner target如果owner target都为自身就回合效果结束后再使用回合效果
}
func (this *EffectNode) Alive() bool {
return !this.NotAlive
}
func (this *EffectNode) ID() int {
return 0
@@ -58,10 +64,16 @@ func (this *EffectNode) Duration(t int) int {
return this.duration
}
// 设置参数,加上设置输入源
func (this *EffectNode) SetArgs(args []int) {
this.SideEffectArgs = args
}
func (this *EffectNode) SetInput(args *input.Input) {
this.Input = args
}
func (this *EffectNode) GetArgSize() int {