refactor(fight/effect): 将属性处理逻辑提取至Input.GetProp方法,优化OnSkill方法并移除冗余代码

This commit is contained in:
1
2025-09-23 23:35:53 +00:00
parent 6e9dc7d0a9
commit c42199a578
2 changed files with 25 additions and 18 deletions

View File

@@ -35,23 +35,8 @@ 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
})
//威力+区
//威力*区
//todo 待修复input输入
spower := skill.CalculatePower(opp.CurrentPet)
spower := e.Input.CalculatePower(opp.CurrentPet,skill)
e.Input.AttackValue.LostHp = uint32(spower.IntPart())
e.Input.Exec(func(t input.Effect) bool { //计算暴击率加成
@@ -70,8 +55,7 @@ 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

@@ -3,7 +3,9 @@ package input
import (
element "blazing/common/data/Element"
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"github.com/mohae/deepcopy"
"github.com/shopspring/decimal"
)
@@ -35,9 +37,30 @@ func (i *Input) GetAction(opp *Input) {
}
// todo获取属性待实现获取后改回原属性
func (i *Input) GetProp(opp *Input) {
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
})
e.Input.CurrentPet = oldour //恢复
opp.CurrentPet = oldouo //恢复
}
// 计算技能威力
func (i *Input) CalculatePower(deftype *info.BattlePetEntity, skill *info.SkillEntity) decimal.Decimal {
//威力+区
//威力*区
//todo 待修复input输入
// 1. 计算等级因子 (level * 0.4 + 2)
levelFactor := decimal.NewFromInt(int64(i.CurrentPet.Info.Level)).
Mul(decimal.NewFromFloat(0.4)).Add(decimal.NewFromInt(2))