From 4bb74771471dd3225421782dd8f205f121e7bbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Sat, 7 Mar 2026 00:26:05 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(fight):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=88=98=E6=96=97=E6=94=BB=E5=87=BB=E5=80=BC=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=B9=B6=E5=AE=9E=E7=8E=B0=E6=88=98=E6=96=97?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 GetAttackValue 方法到 FightI 接口,用于获取战斗中的攻击值信息。 新增 RuleI 接口定义战斗规则契约,包括 SetArgs 和 Exec 方法。 重构战斗规则系统: - 创建 RuleBase 基类提供通用参数存储和基础方法 - 实现 17 --- logic/service/common/fight.go | 1 + logic/service/fight/input.go | 5 + logic/service/fight/input/effect.go | 1 + logic/service/fight/input/interface.go | 6 + logic/service/fight/input/rule.go | 8 ++ logic/service/fight/loop.go | 1 + logic/service/fight/rule/rule1.go | 152 +++++++++++++++++++++++++ modules/player/model/pvp.go | 7 +- 8 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 logic/service/fight/input/rule.go diff --git a/logic/service/common/fight.go b/logic/service/common/fight.go index 8a4ed09a8..670c3f72a 100644 --- a/logic/service/common/fight.go +++ b/logic/service/common/fight.go @@ -22,4 +22,5 @@ type FightI interface { Chat(c PlayerI, msg string) IsFirst(c PlayerI) bool GetOverChan() chan struct{} + GetAttackValue(bool) *model.AttackValue } diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index ebcbba63c..cc13d790d 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -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 + +} diff --git a/logic/service/fight/input/effect.go b/logic/service/fight/input/effect.go index 9dea19187..051651a69 100644 --- a/logic/service/fight/input/effect.go +++ b/logic/service/fight/input/effect.go @@ -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) diff --git a/logic/service/fight/input/interface.go b/logic/service/fight/input/interface.go index 71e91f1b4..6d5d7804f 100644 --- a/logic/service/fight/input/interface.go +++ b/logic/service/fight/input/interface.go @@ -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 +} diff --git a/logic/service/fight/input/rule.go b/logic/service/fight/input/rule.go new file mode 100644 index 000000000..feeedd43f --- /dev/null +++ b/logic/service/fight/input/rule.go @@ -0,0 +1,8 @@ +package input + +var RuleM = make(map[int64]RuleI, 0) + +func InitRule(id int64, t RuleI) { + + RuleM[id] = t +} diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index eeafb1006..a77369994 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -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 diff --git a/logic/service/fight/rule/rule1.go b/logic/service/fight/rule/rule1.go index 63ed38ed0..3351422b3 100644 --- a/logic/service/fight/rule/rule1.go +++ b/logic/service/fight/rule/rule1.go @@ -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 +} diff --git a/modules/player/model/pvp.go b/modules/player/model/pvp.go index 239bea99b..85d5f791d 100644 --- a/modules/player/model/pvp.go +++ b/modules/player/model/pvp.go @@ -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