From 96b5dbb4256c42ca64c9d04a4c18ddd0b8422701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Thu, 18 Dec 2025 23:57:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(fight):=20=E9=87=8D=E6=9E=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8C=E6=AD=A5=E4=B8=8E=E5=8F=8D=E8=BD=AC=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一处理效果45、51、55、56的属性同步与反转逻辑,优化代码结构并提高可维护性。新增通用效果结构体 `EffectPropSyncReverse` 和操作类型定义,集中管理不同属性操作行为。 fix(controller): 修复玩家离开地图逻辑错误 修正 `FRESH_LEAVE_FIGHT_LEVEL` 接口中 defer 调用为进入地图,并发送角色信息包给客户端以确保状态一致。 feat(effect): 新增天敌机制核心逻辑占位 在 `NewSel14` 效果中添加 `Turn_Start` 方法,实现若遇到天敌则害怕多回合的核心逻辑框架。 chore(config): 更新Boss配置怪物ID及血量 调整Boss ID为2的怪物配置,替换原有Monster ID并设置血量为10,用于测试或平衡调整。 refactor(fight): 优化战斗循环和精灵切换逻辑 整理战斗主循环中的血量赋值语句格式,调整精灵切换时变量顺序以避免潜在问题,并修复死亡标记逻辑。 refactor(node): 恢复BoolisFalse方法实现 取消注释 `BoolisFalse` 方法内容,恢复其正常功能以便其他模块正确判断布尔条件。 style(logic): 格式化代码空行和缩进 清理多余空行,对齐导入语句与其他代码块格式,增强整体代码可读性。 debug(effect): 增加烧伤伤害调试打印 在持续伤害效果中加入println语句,输出实际造成的真实伤害数值便于排查问题。 --- logic/controller/fight_tawor.go | 10 +- logic/service/fight/boss/NewSeIdx_14.go | 7 + logic/service/fight/effect/effect_45.go | 52 ------ logic/service/fight/effect/effect_51.go | 43 ----- logic/service/fight/effect/effect_55.go | 41 ----- logic/service/fight/effect/effect_56.go | 43 ----- logic/service/fight/effect/effect_attr.go | 194 ++++++++++++-------- logic/service/fight/effect/effect_status.go | 1 + logic/service/fight/fightc.go | 3 +- logic/service/fight/loop.go | 10 +- logic/service/fight/node/node.go | 18 +- public/config/地图配置野怪.xml | 6 +- 12 files changed, 155 insertions(+), 273 deletions(-) delete mode 100644 logic/service/fight/effect/effect_45.go delete mode 100644 logic/service/fight/effect/effect_51.go delete mode 100644 logic/service/fight/effect/effect_55.go delete mode 100644 logic/service/fight/effect/effect_56.go diff --git a/logic/controller/fight_tawor.go b/logic/controller/fight_tawor.go index a53a3c4a3..3c4484fdc 100644 --- a/logic/controller/fight_tawor.go +++ b/logic/controller/fight_tawor.go @@ -5,7 +5,10 @@ import ( "blazing/common/utils" "blazing/logic/service/fight" "blazing/logic/service/player" + "blazing/logic/service/space/info" "sync/atomic" + + "github.com/jinzhu/copier" ) func (h Controller) FRESH_CHOICE_FIGHT_LEVEL(data *fight.C2S_FRESH_CHOICE_FIGHT_LEVEL, c *player.Player) (result *fight.S2C_FreshChoiceLevelRequestInfo, err errorcode.ErrorCode) { @@ -38,7 +41,12 @@ func (h Controller) FRESH_LEAVE_FIGHT_LEVEL(data *fight.FRESH_LEAVE_FIGHT_LEVEL, c.Info.MapID = 108 } - defer c.GetSpace().LeaveMap(c) //玩家离开地图 + defer c.GetSpace().EnterMap(c) + + out := info.NewOutInfo() + copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true}) + + c.SendPackCmd(2001, out) return result, 0 } diff --git a/logic/service/fight/boss/NewSeIdx_14.go b/logic/service/fight/boss/NewSeIdx_14.go index ac7c2edae..37f631ac6 100644 --- a/logic/service/fight/boss/NewSeIdx_14.go +++ b/logic/service/fight/boss/NewSeIdx_14.go @@ -1,6 +1,7 @@ package effect import ( + "blazing/logic/service/fight/action" "blazing/logic/service/fight/input" ) @@ -10,6 +11,12 @@ type NewSel14 struct { NewSel0 } +func (e *NewSel14) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { + // TODO: 实现若遇到天敌, 则战斗开始时连续害怕 n 回合;(a1: n)的核心逻辑 + if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { + return + } +} func init() { input.InitEffect(input.EffectType.NewSel, 14, &NewSel14{}) } diff --git a/logic/service/fight/effect/effect_45.go b/logic/service/fight/effect/effect_45.go deleted file mode 100644 index 2e58a0ea3..000000000 --- a/logic/service/fight/effect/effect_45.go +++ /dev/null @@ -1,52 +0,0 @@ -package effect - -import ( - "blazing/logic/service/fight/action" - "blazing/logic/service/fight/input" - "blazing/logic/service/fight/node" -) - -/** - * n回合防御力和对手相同 - */ -type Effect45 struct { - node.EffectNode - oldtype uint32 -} - -func (e *Effect45) OnSkill() bool { - if !e.Hit() { - return true - } - - return true -} -func (e *Effect45) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { - if !e.Hit() { - return - } - e.oldtype = e.Ctx().Opp.CurrentPet.Info.Prop[1] - e.Ctx().Our.CurrentPet.Info.Prop[1] = e.Ctx().Opp.CurrentPet.Info.Prop[1] -} -func init() { - ret := &Effect45{} - - input.InitEffect(input.EffectType.Skill, 45, ret) - -} -func (e *Effect45) SetArgs(t *input.Input, a ...int) { - - e.EffectNode.SetArgs(t, a...) - e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]) - -} - -func (e *Effect45) Alive(t ...bool) bool { - - if e.BoolisFalse(t...) && e.Hit() { //说明到了回合结束取消节点,那么就将变化过的属性变化回来 - //还原属性 - e.Ctx().Our.CurrentPet.Info.Prop[1] = e.oldtype - } - - return e.EffectNode.Alive(t...) -} diff --git a/logic/service/fight/effect/effect_51.go b/logic/service/fight/effect/effect_51.go deleted file mode 100644 index c5c95900b..000000000 --- a/logic/service/fight/effect/effect_51.go +++ /dev/null @@ -1,43 +0,0 @@ -package effect - -import ( - "blazing/logic/service/fight/action" - "blazing/logic/service/fight/input" - "blazing/logic/service/fight/node" -) - -/** - * n回合防御力和对手相同 - */ -type Effect51 struct { - node.EffectNode - oldtype uint32 -} - -func (e *Effect51) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { - - e.oldtype = e.Ctx().Opp.CurrentPet.Info.Prop[0] - e.Ctx().Our.CurrentPet.Info.Prop[0] = e.Ctx().Opp.CurrentPet.Info.Prop[0] -} -func init() { - ret := &Effect51{} - - input.InitEffect(input.EffectType.Skill, 51, ret) - -} -func (e *Effect51) SetArgs(t *input.Input, a ...int) { - - e.EffectNode.SetArgs(t, a...) - e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]) - -} - -func (e *Effect51) Alive(t ...bool) bool { - - if e.BoolisFalse(t...) && e.Hit() { //说明到了回合结束取消节点,那么就将变化过的属性变化回来 - //还原属性 - e.Ctx().Our.CurrentPet.Info.Prop[0] = e.oldtype - } - - return e.EffectNode.Alive(t...) -} diff --git a/logic/service/fight/effect/effect_55.go b/logic/service/fight/effect/effect_55.go deleted file mode 100644 index 248d38e46..000000000 --- a/logic/service/fight/effect/effect_55.go +++ /dev/null @@ -1,41 +0,0 @@ -package effect - -import ( - "blazing/logic/service/fight/action" - "blazing/logic/service/fight/input" - "blazing/logic/service/fight/node" -) - -/** - *n 回合内,自身与对方反转战斗时属性 - */ -type Effect55 struct { - node.EffectNode -} - -func (e *Effect55) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { - - e.Ctx().Our.CurrentPet.PetInfo.Type, e.Ctx().Opp.CurrentPet.PetInfo.Type = e.Ctx().Opp.CurrentPet.PetInfo.Type, e.Ctx().Our.CurrentPet.PetInfo.Type -} -func init() { - ret := &Effect55{} - - input.InitEffect(input.EffectType.Skill, 55, ret) - -} -func (e *Effect55) SetArgs(t *input.Input, a ...int) { - - e.EffectNode.SetArgs(t, a...) - e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]) - -} - -func (e *Effect55) Alive(t ...bool) bool { - - if e.BoolisFalse(t...) && e.Hit() { //说明到了回合结束取消节点,那么就将变化过的属性变化回来 - //还原属性 - e.Ctx().Our.CurrentPet.PetInfo.Type, e.Ctx().Opp.CurrentPet.PetInfo.Type = e.Ctx().Opp.CurrentPet.PetInfo.Type, e.Ctx().Our.CurrentPet.PetInfo.Type - } - - return e.EffectNode.Alive(t...) -} diff --git a/logic/service/fight/effect/effect_56.go b/logic/service/fight/effect/effect_56.go deleted file mode 100644 index 5371ec6a5..000000000 --- a/logic/service/fight/effect/effect_56.go +++ /dev/null @@ -1,43 +0,0 @@ -package effect - -import ( - "blazing/logic/service/fight/action" - "blazing/logic/service/fight/input" - "blazing/logic/service/fight/node" -) - -/** - * n 回合内与对方战斗时属性相同 - */ -type Effect56 struct { - node.EffectNode - oldtype int -} - -func (e *Effect56) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { - - e.oldtype = e.Ctx().Our.CurrentPet.PetInfo.Type - e.Ctx().Our.CurrentPet.PetInfo.Type = e.Ctx().Opp.CurrentPet.PetInfo.Type -} -func init() { - ret := &Effect56{} - - input.InitEffect(input.EffectType.Skill, 56, ret) - -} -func (e *Effect56) SetArgs(t *input.Input, a ...int) { - - e.EffectNode.SetArgs(t, a...) - e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]) - -} - -func (e *Effect56) Alive(t ...bool) bool { - - if e.BoolisFalse(t...) && e.Hit() { //说明到了回合结束取消节点,那么就将变化过的属性变化回来 - //还原属性 - e.Ctx().Our.CurrentPet.PetInfo.Type = e.oldtype - } - - return e.EffectNode.Alive(t...) -} diff --git a/logic/service/fight/effect/effect_attr.go b/logic/service/fight/effect/effect_attr.go index d56fa424c..9a36528f1 100644 --- a/logic/service/fight/effect/effect_attr.go +++ b/logic/service/fight/effect/effect_attr.go @@ -4,99 +4,143 @@ import ( "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" "blazing/logic/service/fight/node" - "sync" ) // ----------------------------------------------------------- -// 降低对方最大体力效果 +// 通用效果:属性同步/反转类效果(45/51/55/56) // ----------------------------------------------------------- -type Effect38 struct { + +// 操作类型定义:区分不同的属性操作 +type propOpType int + +const ( + opDefenseSync propOpType = iota // 同步防御力(45) + opAttackSync // 同步攻击力(51) + opTypeReverse // 反转属性类型(55) + opTypeSync // 同步属性类型(56) +) + +// 效果上下文:存储属性修改前的原始值(用于还原) +type propOpContext struct { + oldOurProp uint32 // 我方原始属性值(45/51) + oldOurType int // 我方原始类型值(56) + oldOppType int // 对方原始类型值(55) + propIndex int // 属性索引(0=攻击,1=防御) + opType propOpType +} + +// 全局映射:关联效果ID与对应的操作配置 +var propOpMap = make(map[int]func() propOpContext) + +// EffectPropSyncReverse:属性同步/反转效果核心结构体 +type EffectPropSyncReverse struct { node.EffectNode + ctx propOpContext // 操作上下文(存储原始值) + bindpet *info.BattlePetEntity } -// 工厂函数 -func newEffect38() *Effect38 { - return &Effect38{} +// 工厂函数:创建属性同步/反转效果实例 +func newEffectPropSyncReverse() *EffectPropSyncReverse { + return &EffectPropSyncReverse{} } +// 初始化:批量注册所有属性同步/反转类效果 func init() { - // 注册降低最大体力效果 - input.InitEffect(input.EffectType.Skill, 38, newEffect38()) + registerPropSyncReverseEffects() } -// ----------------------------------------------------------- -// 技能触发时调用 -// ----------------------------------------------------------- -func (e *Effect38) OnSkill() bool { +// 批量注册:绑定效果ID与对应的操作配置 +func registerPropSyncReverseEffects() { + // 效果ID与操作配置的映射 + effectMap := map[int]func() propOpContext{ + 45: func() propOpContext { // n回合防御力和对手相同 + return propOpContext{opType: opDefenseSync, propIndex: 1} + }, + 51: func() propOpContext { // n回合攻击力和对手相同 + return propOpContext{opType: opAttackSync, propIndex: 0} + }, + 55: func() propOpContext { // n回合反转属性类型 + return propOpContext{opType: opTypeReverse} + }, + 56: func() propOpContext { // n回合同步属性类型 + return propOpContext{opType: opTypeSync} + }, + } + + // 注册到全局映射,并初始化效果 + for effectID, ctxFunc := range effectMap { + propOpMap[effectID] = ctxFunc + input.InitEffect(input.EffectType.Skill, effectID, newEffectPropSyncReverse()) + } +} + +// SetArgs:设置效果参数(回合数) +func (e *EffectPropSyncReverse) SetArgs(t *input.Input, a ...int) { + e.EffectNode.SetArgs(t, a...) + // 从SideEffectArgs[0]获取持续回合数 + e.EffectNode.Duration(e.EffectNode.SideEffectArgs[0]) + // 初始化操作上下文 + e.ctx = propOpMap[int(e.ID().Suffix())]() +} +func (e *EffectPropSyncReverse) OnSkill() bool { + + if !e.Hit() { + return true + } + if e.bindpet != nil { + return true + } + ourPet := e.Ctx().Our.CurrentPet + oppPet := e.Ctx().Opp.CurrentPet + switch e.ctx.opType { + case opDefenseSync, opAttackSync: + // 同步攻防属性:保存我方原始值,覆盖为对方值 + e.ctx.oldOurProp = ourPet.Info.Prop[e.ctx.propIndex] + ourPet.Info.Prop[e.ctx.propIndex] = oppPet.Info.Prop[e.ctx.propIndex] + + case opTypeReverse: + // 反转属性类型:保存双方原始值,交换类型 + e.ctx.oldOurType = ourPet.PetInfo.Type + e.ctx.oldOppType = oppPet.PetInfo.Type + ourPet.PetInfo.Type, oppPet.PetInfo.Type = oppPet.PetInfo.Type, ourPet.PetInfo.Type + + case opTypeSync: + // 同步属性类型:保存我方原始值,覆盖为对方值 + e.ctx.oldOurType = ourPet.PetInfo.Type + ourPet.PetInfo.Type = oppPet.PetInfo.Type + } + + //绑定对方精灵 + e.bindpet = e.Ctx().Opp.CurrentPet + return true +} + +// Alive:效果存活判定(结束时还原属性) +func (e *EffectPropSyncReverse) Alive(t ...bool) bool { if !e.Hit() { return true } - // 创建子效果实例 - ee := &Effect38Sub{} - ee.EffectNode.Duration(-1) // 给对方挂3回合子buff - - // 设置子效果ID和捕获时间 - tt := e.ID() - tt.SetEffectType(input.EffectType.Sub) - tt.SetCatchTime(e.Ctx().Opp.CurrentPet.Info.CatchTime) - - ee.ID(tt) - ee.SetArgs(e.Ctx().Our, e.SideEffectArgs...) - - // 添加子效果到对方 - e.Ctx().Opp.AddEffect(e.Ctx().Our, ee) - return true -} - -// ----------------------------------------------------------- -// 降低最大体力子效果 -// ----------------------------------------------------------- -type Effect38Sub struct { - node.EffectNode - oldMaxHP uint32 // 记录原始最大体力值 - once sync.Once // 确保只执行一次体力修改 -} - -// 回合开始时触发 -func (e *Effect38Sub) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) { - // 魂印特性不在场判断:捕获时间不匹配则返回 - if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { - return - } - - // 确保只执行一次体力扣减 - e.once.Do(func() { - // 获取要扣除的体力值和当前最大体力 - reduceHP := e.Args()[0] - currentMaxHP := e.Ctx().Our.CurrentPet.GetMaxHP() - - // 只在扣除值小于当前最大体力时执行 - if reduceHP.Cmp(currentMaxHP) == -1 { - e.oldMaxHP = e.Ctx().Our.CurrentPet.Info.MaxHp - currentMaxHP.Sub(reduceHP) - } - }) -} - -// 精灵切换时触发 -func (e *Effect38Sub) Switch(in *input.Input, at info.AttackValue, oldpet *info.BattlePetEntity) bool { - return true -} - -// 效果存活状态判断(处理属性还原) -func (e *Effect38Sub) Alive(t ...bool) bool { - if len(t) > 0 { - if t[0] == false { - return true - } - return false - } - - // 回合结束取消节点时还原属性 if e.BoolisFalse(t...) { - e.Ctx().Our.CurrentPet.Info.MaxHp = e.oldMaxHP + ourPet := e.Ctx().Our.CurrentPet + + oppPet := e.bindpet + switch e.ctx.opType { + case opDefenseSync, opAttackSync: + // 还原攻防属性 + ourPet.Info.Prop[e.ctx.propIndex] = e.ctx.oldOurProp + + case opTypeReverse: + // 还原反转的属性类型(恢复双方原始值) + ourPet.PetInfo.Type = e.ctx.oldOurType + oppPet.PetInfo.Type = e.ctx.oldOppType + + case opTypeSync: + // 还原同步的属性类型 + ourPet.PetInfo.Type = e.ctx.oldOurType + } } return e.EffectNode.Alive(t...) + } diff --git a/logic/service/fight/effect/effect_status.go b/logic/service/fight/effect/effect_status.go index 9d2d4b429..d69747d57 100644 --- a/logic/service/fight/effect/effect_status.go +++ b/logic/service/fight/effect/effect_status.go @@ -68,6 +68,7 @@ type ContinuousDamage struct { // 技能命中前触发伤害(1/8最大生命值真实伤害) func (e *ContinuousDamage) Action_start(attacker, defender *action.SelectSkillAction) bool { damage := e.calculateDamage() + println(damage.IntPart(), "烧伤") e.Ctx().Our.Damage(e.Input, &info.DamageZone{ Type: info.DamageType.True, Damage: damage, diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 4709dd37b..bca373963 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -315,6 +315,7 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { "对手剩余血量:", defender.CurrentPet.Info.Hp, ) if attacker.CurrentPet.Info.Hp <= 0 { + defender.CurrentPet.NotAlive = true if defender.CurrentPet.Info.Hp == 0 { //先手方死亡,触发反同归于尽 defender.CurrentPet.Info.Hp = 1 @@ -339,7 +340,7 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { //defender.CanAction = true //被打死就可以切精灵了 // AI自动技能 - + defender.CurrentPet.NotAlive = true if f.IsWin(attacker, defender.CurrentPet.Info.CatchTime) { //然后检查是否战斗结束 var WinnerId uint32 if i == 0 { diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index 68d2a9bfa..630684535 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -63,8 +63,8 @@ func (f *FightC) battleLoop() { } } - - ff.Player.GetInfo().PetList[j].Hp = utils.Max(ff.Player.GetInfo().PetList[j].MaxHp,ff.AllPet[i].Info.Hp) + + ff.Player.GetInfo().PetList[j].Hp = utils.Max(ff.Player.GetInfo().PetList[j].MaxHp, ff.AllPet[i].Info.Hp) ff.Player.GetInfo().PetList[j].SkillList = ff.AllPet[i].Info.SkillList } @@ -152,11 +152,11 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat selfinput.CanChange = 2 } - + oldpet := selfinput.CurrentPet + InitAttackValue := *selfinput.AttackValue selfinput.CurrentPet, ret.Reason = selfinput.GetPet(ret.Cid) selfinput.Player.SendPackCmd(2407, &ret.Reason) - InitAttackValue := *selfinput.AttackValue - oldpet := selfinput.CurrentPet + f.Switch[selfinput.UserID] = ret selfinput.InitAttackValue() //切换精灵消除能力提升 diff --git a/logic/service/fight/node/node.go b/logic/service/fight/node/node.go index 2d5cf8bf3..bc858d695 100644 --- a/logic/service/fight/node/node.go +++ b/logic/service/fight/node/node.go @@ -121,14 +121,14 @@ func (e *EffectNode) AttackTime(*input.Input, *input.Input) bool { func (e *EffectNode) Prop_Befer(in *input.Input, prop int8, level int8, ptype info.EnumAbilityOpType) bool { return true } -// func (e *EffectNode) BoolisFalse(t ...bool) bool { +func (e *EffectNode) BoolisFalse(t ...bool) bool { -// if len(t) > 0 { -// if t[0] == false { -// return true + if len(t) > 0 { + if t[0] == false { + return true -// } -// return false -// } -// return false -// } + } + return false + } + return false +} diff --git a/public/config/地图配置野怪.xml b/public/config/地图配置野怪.xml index 59db034b7..8fa0dac9b 100644 --- a/public/config/地图配置野怪.xml +++ b/public/config/地图配置野怪.xml @@ -448,9 +448,9 @@ eg: - - - + + +