refactor(fight/effect): 重构技能伤害计算逻辑,将伤害处理移至Effect0.OnSkill方法并优化效果调用流程

This commit is contained in:
1
2025-09-23 18:35:23 +00:00
parent a524e651aa
commit 5a023ccd1c
6 changed files with 55 additions and 40 deletions

View File

@@ -22,6 +22,28 @@ func (this *Effect0) UseSkill(opp *input.Input) bool {
return true
}
// 使用技能时
func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
spower := skill.CalculatePower(opp.CurrentPet)
damage := e.Input.GetDamageEffect(0)
damage.Stack(int(spower.IntPart()))
e.Input.Exec(func(t input.Effect) bool { //计算暴击率加成
t.IsCrit(opp, skill)
e.Input.AttackValue.IsCritical = skill.Crit
return e.Input.AttackValue.IsCritical == 0
})
if e.Input.AttackValue.IsCritical == 1 {
damage.Stack(int(spower.IntPart() * 2)) //暴击翻倍
}
if uint32(damage.Stack()) > opp.CurrentPet.Info.Hp {
opp.CurrentPet.Info.Hp = 0
} else {
opp.CurrentPet.Info.Hp = opp.CurrentPet.Info.Hp - uint32(damage.Stack())
}
}
func (this *Effect0) IsCrit(opp *input.Input, skill *info.SkillEntity) {
skill.Crit = 0
CritRate := utils.Max(skill.CritRate, 1)

View File

@@ -372,7 +372,7 @@ func (f *FightC) parseskill(attacker, defender *input.Input, id *SelectSkillActi
temparg := id.Skill.SideEffectArgS
for _, v := range id.Skill.SideEffectS {
t, ok := attacker.GetSkillEffect(v)
t, ok := input.Geteffect(v + 1000000)
if ok { //获取成功
@@ -435,24 +435,12 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk
attacker.AttackValue.AttackTime = a.Skill.AttackTime
if attacker.AttackValue.AttackTime > 0 { //如果命中
f.parseskill(attacker, defender, a) //命中后解析effect
spower := a.Skill.CalculatePower(defender.CurrentPet)
damage := attacker.GetDamageEffect(0)
damage.Stack(int(spower.IntPart()))
attacker.Exec(func(t input.Effect) bool { //计算暴击率加成
attacker.Exec(func(t input.Effect) bool {
t.IsCrit(defender, a.Skill)
attacker.AttackValue.IsCritical = a.Skill.Crit
return attacker.AttackValue.IsCritical == 0
t.OnSkill(defender, a.Skill) //调用伤害计算
return true
})
if attacker.AttackValue.IsCritical == 1 {
damage.Stack(int(spower.IntPart() * 2)) //暴击翻倍
}
if uint32(damage.Stack()) > defender.CurrentPet.Info.Hp {
defender.CurrentPet.Info.Hp = 0
} else {
defender.CurrentPet.Info.Hp = defender.CurrentPet.Info.Hp - uint32(damage.Stack())
}
// 扣减防御方血量
} //todo 处理未命中效果

View File

@@ -8,7 +8,6 @@ import (
"github.com/gogf/gf/v2/util/gconv"
"github.com/jinzhu/copier"
"github.com/mohae/deepcopy"
)
type Input struct {
@@ -27,9 +26,9 @@ type Input struct {
func NewInput(c common.FightI, p common.PlayerI) *Input {
ret := &Input{FightC: c, Player: p}
t := ret.GetDamageEffect(0)
ret.AddEffect(deepcopy.Copy(t).(Effect)) //添加默认基类,实现继承
p.SetFightC(c) //给玩家设置战斗容器
t, _ := Geteffect(4000000)
ret.AddEffect(t) //添加默认基类,实现继承
p.SetFightC(c) //给玩家设置战斗容器
return ret
}

View File

@@ -35,7 +35,7 @@ type Effect interface {
IsHit(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断
TakeHit(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断
//() bool // 暴击伤害结算后触发
OnSkill(opp *Input, skill *info.SkillEntity) //闪避率计算,,实际上是修改命中的判断
// OnHit() bool // 技能命中时触发
// OnMiss() bool // 技能未命中时触发
// AfterAttacked() bool // 被攻击后触发(受击判定)
@@ -88,7 +88,7 @@ func InitSkillEffect(id int, t Effect) {
NodeM[id+1000000] = t
}
func (c *Input) geteffect(id int) (Effect, bool) {
func Geteffect(id int) (Effect, bool) {
//todo 获取前GetEffect
ret, ok := NodeM[id]
@@ -99,16 +99,7 @@ func (c *Input) geteffect(id int) (Effect, bool) {
return nil, false
//todo 获取后GetEffect
}
func (c *Input) GetSkillEffect(id int) (Effect, bool) {
ret, ok := c.geteffect(id)
if ok {
//todo 获取前GetEffect
return ret, ok
//todo 获取后GetEffect
}
return nil, false
}
func InitPropEffect(id int, t Effect) {
NodeM[id+2000000] = t
@@ -142,7 +133,8 @@ func InitDamageEffect(id int, t Effect) {
// 1为红伤
func (c *Input) GetDamageEffect(id int) Effect {
ret, ok := c.geteffect(id + 1000000)
ret, ok := Geteffect(id + 1000000)
if ok {
//todo 获取前GetEffect
return ret
@@ -157,7 +149,7 @@ func InitStatusEffect(id int, t Effect) {
}
func (c *Input) GetStatusEffect(id int) (Effect, bool) {
ret, ok := c.geteffect(id + 3000000)
ret, ok := Geteffect(id + 3000000)
if ok {
//todo 获取前GetEffect
return ret, true

View File

@@ -15,13 +15,7 @@ func (this *EffectNode) TakeHit(opp *input.Input, skill *info.SkillEntity) {
}
func (this *EffectNode) UseSkill(opp *input.Input) bool {
return this.Input.CurrentPet.HP != 0
}
func (this *EffectNode) OnSkillPP() bool {
panic("not implemented") // TODO: Implement
}
func (this *EffectNode) SkillUseEnd() bool {
panic("not implemented") // TODO: Implement
}

View File

@@ -0,0 +1,20 @@
package node
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
)
// 使用技能前
func (e *EffectNode) UseSkill(opp *input.Input) bool {
return e.Input.CurrentPet.HP != 0
}
// 使用技能时
func (e *EffectNode) OnSkill(opp *input.Input, skill *info.SkillEntity) {
}
func (e *EffectNode) OnSkillPP() bool {
panic("not implemented") // TODO: Implement
}