refactor: 重构战斗效果逻辑至独立文件
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
xinian
2026-03-08 14:07:36 +08:00
committed by cnb
parent 73d7f7f062
commit 986c7f7b83
6 changed files with 164 additions and 100 deletions

View File

@@ -10,21 +10,37 @@ type NewSel405 struct {
NewSel0
}
func (e *NewSel405) ActionStartEx(fattack, sattack *action.SelectSkillAction) bool {
//魂印特性有不在场的情况,绑定时候将精灵和特性绑定
func (e *NewSel405) ComparePre(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true
}
if fattack == nil {
return true
}
//先手是自己
if fattack.PlayerID == e.Ctx().Our.UserID {
return true
}
if sattack == nil {
return true
}
if sattack == nil {
return true
}
if sattack.SkillEntity == nil {
return true
}
// n%几率触发
success, _, _ := e.Input.Player.Roll(int(e.Args()[0].IntPart()), 100)
if success && e.Ctx().SkillEntity != nil {
// 先制+1提升优先级
e.Ctx().SkillEntity.AttackTime = e.Ctx().SkillEntity.AttackTime + 1
if !success {
}
//对调
sattack.SkillEntity.Priority += 1
return true
}
func init() {
input.InitEffect(input.EffectType.NewSel, 405, &NewSel405{})
}

View File

@@ -0,0 +1,30 @@
package effect
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
"github.com/gogf/gf/v2/util/grand"
)
// 198 - 随机使对手n种能力等级-m
type Effect198 struct {
node.EffectNode
}
func (e *Effect198) OnSkill() bool {
numStats := int(e.Args()[0].IntPart()) // n种能力
reduction := int8(e.Args()[1].IntPart()) // 等级-m
// 随机选择n种能力
for i := 0; i < numStats; i++ {
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(grand.Intn(5)), reduction, info.AbilityOpType.SUB)
}
return true
}
func init() {
input.InitEffect(input.EffectType.Skill, 198, &Effect198{})
}

View File

@@ -0,0 +1,47 @@
package effect
import (
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
)
// 454 - 当自身血量少于1/n时先制+m写死了先制只能+1
type Effect454 struct {
node.EffectNode
}
func (e *Effect454) ComparePre(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) bool {
if fattack == nil {
return true
}
//先手是自己
if fattack.PlayerID == e.Ctx().Our.UserID {
return true
}
if sattack == nil {
return true
}
if sattack == nil {
return true
}
if sattack.SkillEntity == nil {
return true
}
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
currentHp := e.Ctx().Our.CurrentPet.GetHP()
threshold := maxHp.Div(e.Args()[0]) // 1/n
if currentHp.Cmp(threshold) < 0 {
sattack.SkillEntity.Priority += 1
}
//对调
return true
}
func init() {
input.InitEffect(input.EffectType.Skill, 454, &Effect454{})
}

View File

@@ -0,0 +1,29 @@
package effect
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
)
// 473 - 若造成的伤害不足m则自身XX等级+n
type Effect473 struct {
node.EffectNode
}
func (e *Effect473) SkillUseed() bool {
damageThreshold := int(e.Args()[0].IntPart())
damageDone := e.Ctx().Our.SumDamage
if damageDone.IntPart() < int64(damageThreshold) {
effectType := int(e.Args()[1].IntPart()) // XX类型
effectValue := int(e.Args()[2].IntPart()) // 等级+n
e.Ctx().Our.SetProp(e.Ctx().Our, int8(effectType), int8(effectValue), info.AbilityOpType.ADD)
}
return true
}
func init() {
input.InitEffect(input.EffectType.Skill, 473, &Effect473{})
}

View File

@@ -0,0 +1,32 @@
package effect
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/fight/node"
"github.com/alpacahq/alpacadecimal"
)
// 488 - 若对手的体力小于400则造成的伤害增加10%
type Effect488 struct {
node.EffectNode
}
func (e *Effect488) Damage_Mul(t *info.DamageZone) bool {
if e.Ctx().SkillEntity == nil {
return true
}
opponentHp := e.Ctx().Opp.CurrentPet.GetHP()
if opponentHp.Cmp(alpacadecimal.NewFromInt(400)) < 0 {
t.Damage = t.Damage.Mul(alpacadecimal.NewFromFloat(1.1))
}
return true
}
func init() {
input.InitEffect(input.EffectType.Skill, 488, &Effect488{})
}

View File

@@ -543,40 +543,7 @@ func (e *Effect444) OnSkill() bool {
return true
}
// 198 - 随机使对手n种能力等级-m
type Effect198 struct {
node.EffectNode
}
func (e *Effect198) OnSkill() bool {
numStats := int(e.Args()[0].IntPart()) // n种能力
reduction := int(e.Args()[1].IntPart()) // 等级-m
// 定义可降低的能力列表
stats := []int{
int(info.PetStatus.AtkDown),
int(info.PetStatus.DefDown),
int(info.PetStatus.SpAtkDown),
int(info.PetStatus.SpDefDown),
int(info.PetStatus.SpeedDown),
int(info.PetStatus.AccuracyDown),
}
// 随机选择n种能力
for i := 0; i < numStats && i < len(stats); i++ {
randomIndex := int(e.Input.FightC.GetRand().Int31n(int32(len(stats))))
selectedStat := stats[randomIndex]
statEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, selectedStat)
if statEffect != nil {
statEffect.SetArgs(e.Ctx().Our, reduction)
e.Ctx().Opp.AddEffect(e.Ctx().Our, statEffect)
}
}
return true
}
// 475 - 若造成的伤害不足m则下n回合的攻击必定致命一击
type Effect475 struct {
node.EffectNode
@@ -643,29 +610,7 @@ func (e *Effect430) OnSkill() bool {
return true
}
// 473 - 若造成的伤害不足m则自身XX等级+n
type Effect473 struct {
node.EffectNode
}
func (e *Effect473) SkillHit_ex() bool {
damageThreshold := int(e.Args()[0].IntPart())
damageDone := e.Ctx().Our.SumDamage
if damageDone.IntPart() < int64(damageThreshold) {
effectType := int(e.Args()[1].IntPart()) // XX类型
effectValue := int(e.Args()[2].IntPart()) // 等级+n
statusEffect := e.Ctx().Our.InitEffect(input.EffectType.Status, effectType)
if statusEffect != nil {
statusEffect.SetArgs(e.Ctx().Our, effectValue)
e.Ctx().Our.AddEffect(e.Ctx().Our, statusEffect)
}
}
return true
}
// 465 - m%令对手疲惫n回合每次使用几率提升x%最高y%
type Effect465 struct {
@@ -706,24 +651,7 @@ func (e *Effect465) SetArgs(t *input.Input, a ...int) {
e.incrementPerUse = a[3] // 每次使用几率提升x%
}
// 454 - 当自身血量少于1/n时先制+m写死了先制只能+1
type Effect454 struct {
node.EffectNode
}
func (e *Effect454) Skill_Pre() bool {
maxHp := e.Ctx().Our.CurrentPet.GetMaxHP()
currentHp := e.Ctx().Our.CurrentPet.GetHP()
threshold := maxHp.Div(e.Args()[0]) // 1/n
if currentHp.Cmp(threshold) < 0 {
// 血量少于1/n先制+1固定为1
e.Ctx().Our.TempSpeedBoost = true
}
return true
}
// 501 - 若造成的伤害不足m则对手XX等级-n
type Effect501 struct {
@@ -1045,25 +973,7 @@ func (e *Effect156) SetArgs(t *input.Input, a ...int) {
e.EffectNode.Duration(a[0]) // 持续n回合
}
// 488 - 若对手的体力小于400则造成的伤害增加10%
type Effect488 struct {
node.EffectNode
}
func (e *Effect488) SkillHit() bool {
if e.Ctx().SkillEntity == nil {
return true
}
opponentHp := e.Ctx().Opp.CurrentPet.GetHP()
if opponentHp.Cmp(alpacadecimal.NewFromInt(400)) < 0 {
// 伤害增加10%
e.Ctx().SkillEntity.Power = int(float64(e.Ctx().SkillEntity.Power) * 1.1)
}
return true
}
// 437 - 若对手处于能力强化状态则对手XX等级m
type Effect437 struct {