refactor(fight/effect): 新增技能属性前后处理逻辑,实现深拷贝恢复机制并优化OnSkill方法

This commit is contained in:
1
2025-09-23 23:25:49 +00:00
parent 2855c3e773
commit 5ccb1121f9
4 changed files with 26 additions and 8 deletions

View File

@@ -5,6 +5,8 @@ import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
"github.com/gogf/gf/v2/internal/deepcopy"
)
// 施加一个基类effect
@@ -33,7 +35,21 @@ func (e *Effect0) TurnEnd(opp *input.Input) {
// 使用技能时
func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
oldour := deepcopy.Copy(e.Input.CurrentPet).(*info.BattlePetEntity)
oldouo := deepcopy.Copy(opp.CurrentPet).(*info.BattlePetEntity)
e.Input.Exec(func(t input.Effect) bool { //属性获取前
t.BeferAttr(e.Input.CurrentPet) //使XX为XX
return true
})
e.Input.Exec(func(t input.Effect) bool { //属性获取后
t.AfterAttr(opp.CurrentPet) //视为xx
return true
})
//威力+区
//威力*区
spower := skill.CalculatePower(opp.CurrentPet)
e.Input.AttackValue.LostHp = uint32(spower.IntPart())
@@ -53,7 +69,8 @@ func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
// } else {
// opp.CurrentPet.Info.Hp = opp.CurrentPet.Info.Hp - e.Input.AttackValue.LostHp
// }
e.Input.CurrentPet = oldour //恢复
opp.CurrentPet = oldouo //恢复
}
func (this *Effect0) IsCrit(opp *input.Input, skill *info.SkillEntity) {
skill.Crit = 0

View File

@@ -378,7 +378,7 @@ func (f *FightC) parseskill(attacker, defender *input.Input, id *SelectSkillActi
args := xmlres.EffectArgs[v]
t.SetArgs(temparg[:args]) //设置入参
t.SetArgs(temparg[:args]...) //设置入参
temparg = temparg[args:]
if t.GetOwner() { //如果取反,说明是给对方添加的回合效果
@@ -437,8 +437,7 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk
f.parseskill(attacker, defender, a) //命中后解析effect
attacker.Exec(func(t input.Effect) bool {
//威力+区
//威力*区
t.OnSkill(defender, a.Skill) //调用伤害计算
return true

View File

@@ -25,8 +25,8 @@ type Effect interface {
// OnDamage() bool // 造成伤害时触发
//使用技能 可以取消用技能节点
SetInput(input *Input)
AfterAttr() //在获取属性前,比如重写对方属性AfterAttr
BeferAttr() //在获取属性后,比如视为对方属性
AfterAttr(t *info.BattlePetEntity) //在获取属性前,比如重写对方属性AfterAttr
BeferAttr(t *info.BattlePetEntity) //在获取属性后,比如视为对方属性
SetArgs(param ...int)
IsCrit(opp *Input, skill *info.SkillEntity) //是否暴击
CalculateDamage(opp *Input, skill *info.SkillEntity) //击判定成功且伤害计算前触发

View File

@@ -1,14 +1,16 @@
package node
import "blazing/logic/service/fight/info"
// 返回false阻止继续运行
// 回合开始
func (this *EffectNode) AfterAttr() {
func (this *EffectNode) AfterAttr(t *info.BattlePetEntity) {
}
// 返回false阻止继续运行
// 回合开始
func (this *EffectNode) BeferAttr() {
func (this *EffectNode) BeferAttr(t *info.BattlePetEntity) {
}