Files
bl/logic/service/fight/effect/529.go
xinian 875ad668aa
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
feat: 实现战斗效果逻辑和接口重构
2026-03-28 21:57:22 +08:00

53 lines
1.1 KiB
Go

package effect
import (
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
"github.com/alpacahq/alpacadecimal"
)
// Effect 529: 使自身体力百分比与对手体力百分比对调
type Effect529 struct {
node.EffectNode
}
func (e *Effect529) OnSkill() bool {
ourMaxHP := e.Ctx().Our.CurrentPet.GetMaxHP()
oppMaxHP := e.Ctx().Opp.CurrentPet.GetMaxHP()
if ourMaxHP.IsZero() || oppMaxHP.IsZero() {
return true
}
ourRatio := e.Ctx().Our.CurrentPet.GetHP().Div(ourMaxHP)
oppRatio := e.Ctx().Opp.CurrentPet.GetHP().Div(oppMaxHP)
newOurHP := oppRatio.Mul(ourMaxHP).IntPart()
newOppHP := ourRatio.Mul(oppMaxHP).IntPart()
if newOurHP < 0 {
newOurHP = 0
}
if newOppHP < 0 {
newOppHP = 0
}
ourMax := ourMaxHP.IntPart()
oppMax := oppMaxHP.IntPart()
if newOurHP > ourMax {
newOurHP = ourMax
}
if newOppHP > oppMax {
newOppHP = oppMax
}
e.Ctx().Our.CurrentPet.Info.Hp = uint32(alpacadecimal.NewFromInt(newOurHP).IntPart())
e.Ctx().Opp.CurrentPet.Info.Hp = uint32(alpacadecimal.NewFromInt(newOppHP).IntPart())
return true
}
func init() {
input.InitEffect(input.EffectType.Skill, 529, &Effect529{})
}