Files
bl/logic/service/fight/rule/rule1.go
昔念 4bb7477147
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(fight): 添加战斗攻击值获取接口并实现战斗规则系统

添加 GetAttackValue 方法到 FightI 接口,用于获取战斗中的攻击值信息。

新增 RuleI 接口定义战斗规则契约,包括 SetArgs 和 Exec 方法。

重构战斗规则系统:
- 创建 RuleBase 基类提供通用参数存储和基础方法
- 实现 17
2026-03-07 00:26:05 +08:00

154 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}