refactor: 拆分战斗规则文件为独立模块
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-03-21 00:34:47 +08:00
committed by cnb
parent afc67b0582
commit 9a1a181ecd
20 changed files with 177 additions and 153 deletions

View File

@@ -1,153 +0,0 @@
package rule
import (
"blazing/logic/service/common"
"blazing/logic/service/fight/input"
"blazing/modules/player/model"
)
func init() {
// 注册战斗规则300-316注册逻辑不变
input.InitRule(300, &Rule300{})
input.InitRule(301, &Rule301{})
input.InitRule(302, &Rule302{})
input.InitRule(303, &Rule303{})
input.InitRule(304, &Rule304{})
input.InitRule(305, &Rule305{})
input.InitRule(306, &Rule306{})
input.InitRule(307, &Rule307{})
input.InitRule(308, &Rule308{})
input.InitRule(309, &Rule309{})
input.InitRule(310, &Rule310{})
input.InitRule(311, &Rule311{})
input.InitRule(312, &Rule312{})
input.InitRule(313, &Rule313{})
input.InitRule(314, &Rule314{})
input.InitRule(315, &Rule315{})
input.InitRule(316, &Rule316{})
}
// RuleBase 规则基类:包含通用参数存储和基础方法
type RuleBase struct {
args []int // 通用参数存储,替代各个子类的 params
}
// Exec 基类默认执行方法(子类可重写)
func (r *RuleBase) Exec(f common.FightI, t *model.FightOverInfo) bool {
return true
}
// SetArgs 基类参数设置方法(所有子类继承使用)
func (r *RuleBase) SetArgs(param ...int) {
r.args = param
}
// ------------------------------
// 所有具体规则都嵌入 RuleBase 实现继承
// 移除所有 params 字段,统一使用父类的 args
// ------------------------------
// Rule300 致命一击击败后获取奖励
type Rule300 struct {
RuleBase // 嵌入基类,继承 args、SetArgs、Exec
}
func (r *Rule300) Exec(f common.FightI, t *model.FightOverInfo) bool {
if t.WinnerId == f.Ownerid() { //获胜
if f.GetAttackValue(false).IsCritical != 0 {
return true
}
}
return false
}
// Rule301 n回合内击败获取奖励
type Rule301 struct {
RuleBase // 继承基类的所有属性和方法
}
func (r *Rule301) Exec(f common.FightI, t *model.FightOverInfo) bool {
if t.WinnerId == f.Ownerid() { //获胜
if f.GetOverInfo().Round < uint32(r.args[0]) {
return true
}
}
return false
}
// Rule302 n回合后击败获取奖励
type Rule302 struct {
RuleBase
}
// Rule303 使用xx技能击败攻击致死获取奖励
type Rule303 struct {
RuleBase
}
// Rule304 使用xx技能后属性技能击败获取奖励
type Rule304 struct {
RuleBase
}
// Rule305 满血击败后获取奖励
type Rule305 struct {
RuleBase
}
// Rule306 对方在xx异常状态下击败后获取奖励
type Rule306 struct {
RuleBase
}
// Rule307 满足特定属性强化下击败后获取奖励
type Rule307 struct {
RuleBase
}
// Rule308 战斗中超过n伤害获取奖励
type Rule308 struct {
RuleBase
}
// Rule309 战斗持续n回合后获取奖励
type Rule309 struct {
RuleBase
}
// Rule310 不使用xx药剂击败获取奖励
type Rule310 struct {
RuleBase
}
// Rule311 偶数回合击败后获取奖励
type Rule311 struct {
RuleBase
}
// Rule312 奇数回合击败后获取奖励
type Rule312 struct {
RuleBase
}
// Rule313 特定回合击败后获取奖励
type Rule313 struct {
RuleBase
}
// Rule314 自身处于xx状态击败后获取奖励
type Rule314 struct {
RuleBase
}
// Rule315 自身不大于1/n血量击败
type Rule315 struct {
RuleBase
}
// Rule316 在自身所有技能都进入PP耗尽状态的情况下获胜获取精灵
type Rule316 struct {
RuleBase
}

View File

@@ -0,0 +1,21 @@
package rule
import (
"blazing/logic/service/common"
"blazing/modules/player/model"
)
// Rule300 致命一击击败后获取奖励
type Rule300 struct {
RuleBase // 嵌入基类,继承 args、SetArgs、Exec
}
func (r *Rule300) Exec(f common.FightI, t *model.FightOverInfo) bool {
if t.WinnerId == f.Ownerid() { //获胜
if f.GetAttackValue(false).IsCritical != 0 {
return true
}
}
return false
}

View File

@@ -0,0 +1,21 @@
package rule
import (
"blazing/logic/service/common"
"blazing/modules/player/model"
)
// Rule301 n回合内击败获取奖励
type Rule301 struct {
RuleBase // 继承基类的所有属性和方法
}
func (r *Rule301) Exec(f common.FightI, t *model.FightOverInfo) bool {
if t.WinnerId == f.Ownerid() { //获胜
if f.GetOverInfo().Round < uint32(r.args[0]) {
return true
}
}
return false
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule302 n回合后击败获取奖励
type Rule302 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule303 使用xx技能击败攻击致死获取奖励
type Rule303 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule304 使用xx技能后属性技能击败获取奖励
type Rule304 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule305 满血击败后获取奖励
type Rule305 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule306 对方在xx异常状态下击败后获取奖励
type Rule306 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule307 满足特定属性强化下击败后获取奖励
type Rule307 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule308 战斗中超过n伤害获取奖励
type Rule308 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule309 战斗持续n回合后获取奖励
type Rule309 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule310 不使用xx药剂击败获取奖励
type Rule310 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule311 偶数回合击败后获取奖励
type Rule311 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule312 奇数回合击败后获取奖励
type Rule312 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule313 特定回合击败后获取奖励
type Rule313 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule314 自身处于xx状态击败后获取奖励
type Rule314 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule315 自身不大于1/n血量击败
type Rule315 struct {
RuleBase
}

View File

@@ -0,0 +1,6 @@
package rule
// Rule316 在自身所有技能都进入PP耗尽状态的情况下获胜获取精灵
type Rule316 struct {
RuleBase
}

View File

@@ -0,0 +1,21 @@
package rule
import (
"blazing/logic/service/common"
"blazing/modules/player/model"
)
// RuleBase 规则基类:包含通用参数存储和基础方法
type RuleBase struct {
args []int // 通用参数存储,替代各个子类的 params
}
// Exec 基类默认执行方法(子类可重写)
func (r *RuleBase) Exec(f common.FightI, t *model.FightOverInfo) bool {
return true
}
// SetArgs 基类参数设置方法(所有子类继承使用)
func (r *RuleBase) SetArgs(param ...int) {
r.args = param
}

View File

@@ -0,0 +1,24 @@
package rule
import "blazing/logic/service/fight/input"
func init() {
// 注册战斗规则300-316
input.InitRule(300, &Rule300{})
input.InitRule(301, &Rule301{})
input.InitRule(302, &Rule302{})
input.InitRule(303, &Rule303{})
input.InitRule(304, &Rule304{})
input.InitRule(305, &Rule305{})
input.InitRule(306, &Rule306{})
input.InitRule(307, &Rule307{})
input.InitRule(308, &Rule308{})
input.InitRule(309, &Rule309{})
input.InitRule(310, &Rule310{})
input.InitRule(311, &Rule311{})
input.InitRule(312, &Rule312{})
input.InitRule(313, &Rule313{})
input.InitRule(314, &Rule314{})
input.InitRule(315, &Rule315{})
input.InitRule(316, &Rule316{})
}