feat(fight): 添加战斗攻击值获取接口并实现战斗规则系统 添加 GetAttackValue 方法到 FightI 接口,用于获取战斗中的攻击值信息。 新增 RuleI 接口定义战斗规则契约,包括 SetArgs 和 Exec 方法。 重构战斗规则系统: - 创建 RuleBase 基类提供通用参数存储和基础方法 - 实现 17
This commit is contained in:
@@ -22,4 +22,5 @@ type FightI interface {
|
||||
Chat(c PlayerI, msg string)
|
||||
IsFirst(c PlayerI) bool
|
||||
GetOverChan() chan struct{}
|
||||
GetAttackValue(bool) *model.AttackValue
|
||||
}
|
||||
|
||||
@@ -295,3 +295,8 @@ func (f *FightC) GetOverInfo() model.FightOverInfo {
|
||||
return f.FightOverInfo
|
||||
|
||||
}
|
||||
|
||||
func (f *FightC) GetAttackValue(b bool) *model.AttackValue {
|
||||
return f.GetInputByPlayer(f.Our.Player, b).AttackValue
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ var EffectType = enum.New[struct {
|
||||
Skill EnumEffectType `enum:"7"` // 技能
|
||||
Status EnumEffectType `enum:"8"` // 状态
|
||||
Sub EnumEffectType `enum:"9"` // 子效果
|
||||
|
||||
}]()
|
||||
|
||||
var NodeM = make(map[int64]Effect, 0)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/modules/player/model"
|
||||
|
||||
"github.com/alpacahq/alpacadecimal"
|
||||
)
|
||||
@@ -72,3 +74,7 @@ type Effect interface {
|
||||
ID(...EffectIDCombiner) EffectIDCombiner
|
||||
//GetSkill() *BattleSkillEntity //获得技能ctx
|
||||
}
|
||||
type RuleI interface {
|
||||
SetArgs(param ...int)
|
||||
Exec(common.FightI, *model.FightOverInfo) bool
|
||||
}
|
||||
|
||||
8
logic/service/fight/input/rule.go
Normal file
8
logic/service/fight/input/rule.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package input
|
||||
|
||||
var RuleM = make(map[int64]RuleI, 0)
|
||||
|
||||
func InitRule(id int64, t RuleI) {
|
||||
|
||||
RuleM[id] = t
|
||||
}
|
||||
@@ -97,6 +97,7 @@ func (f *FightC) battleLoop() {
|
||||
|
||||
})
|
||||
if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC {
|
||||
|
||||
addpet := f.Opp.Player.GetInfo().PetList[0]
|
||||
if f.Reason == model.BattleOverReason.Cacthok {
|
||||
f.WinnerId = f.ownerID
|
||||
|
||||
@@ -1 +1,153 @@
|
||||
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
|
||||
}
|
||||
|
||||
@@ -127,10 +127,9 @@ type FightOverInfo struct {
|
||||
// 4=isSysError 系统错误
|
||||
// 5=isNpcEscape 精灵主动逃跑
|
||||
|
||||
Winpet *PetInfo `struc:"skip"`
|
||||
Round uint32 `struc:"skip"`
|
||||
LastAttavue AttackValue `struc:"skip"`
|
||||
Duration uint32 `struc:"skip"` // 对局时长(秒)
|
||||
Winpet *PetInfo `struc:"skip"`
|
||||
Round uint32 `struc:"skip"`
|
||||
// Duration uint32 `struc:"skip"` // 对局时长(秒)
|
||||
//7 切磋结束
|
||||
Reason EnumBattleOverReason // 固定值0
|
||||
WinnerId uint32 // 胜者的米米号 野怪为0
|
||||
|
||||
Reference in New Issue
Block a user