53 lines
1.1 KiB
Go
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{})
|
|
}
|