``` feat(fight): 新增战斗回合Hook机制,实现特定条件下强制结束战斗和随机出手逻辑

This commit is contained in:
1
2025-12-10 18:37:32 +00:00
parent f6043fd9b9
commit 6b534adc07
9 changed files with 54 additions and 7 deletions

View File

@@ -9,12 +9,13 @@ type FightI interface {
Over(c PlayerI, id info.EnumBattleOverReason) //逃跑
UseSkill(c PlayerI, id uint32) //使用技能
GetCurrPET(c PlayerI) *info.BattlePetEntity //当前精灵
GetOverInfo() info.FightOverInfo
Ownerid() uint32
ReadyFight(c PlayerI) //是否准备战斗
ChangePet(c PlayerI, id uint32)
Capture(c PlayerI, id uint32)
GetRand() *rand.Rand
LoadPercent(c PlayerI, percent int32)
UseItem(c PlayerI, cacthid, itemid uint32)
Chat(c PlayerI, msg string)

View File

@@ -1,6 +1,7 @@
package effect
import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
)
@@ -10,6 +11,18 @@ type NewSel13 struct {
NewSel0
}
func (e *NewSel13) HookAction() bool {
if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime {
return true
}
r := e.Ctx().Our.FightC.GetOverInfo()
if r.Round == uint32(e.Args()[0].IntPart()) {
e.Ctx().Our.FightC.Over(e.Ctx().Our.Player, info.BattleOverReason.PlayerEscape)
return false //阻止技能释放
}
return true //阻止技能释放
}
func init() {
input.InitEffect(input.EffectType.NewSel, 13, &NewSel13{})
}

View File

@@ -9,8 +9,7 @@ import (
"github.com/alpacahq/alpacadecimal"
)
// 23. 自身体力降到N以下时, 每次(针对多宠)攻击必定秒杀对方, 且必定先手;a1: high 16, a2: low 16
// TODO: 实现自身体力降到N以下时, 每次(针对多宠)攻击必定秒杀对方, 且必定先手;a1: high 16, a2: low 16的核心逻辑
// 23. 自身体力降到N以下时, 每次(针对多宠)攻击必定秒杀对方, 且必定先手;
type NewSel23 struct {
NewSel0
}
@@ -44,7 +43,7 @@ func (e *NewSel23) Compare_Pre(fattack *action.SelectSkillAction, sattack *actio
}
func (e *NewSel23) OnSkill() bool {
//full32 := int(e.Args()[0])<<16 | int(e.Args()[1])
if int(e.Ctx().Our.CurrentPet.GetHP().Cmp(e.Args()[0])) == -1 {
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{

View File

@@ -13,6 +13,7 @@ import (
"github.com/alpacahq/alpacadecimal"
"github.com/barkimedes/go-deepcopy"
"github.com/gogf/gf/v2/util/grand"
)
// 处理技能攻击逻辑
@@ -195,9 +196,22 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
fattack, sattack = sattack, fattack //互换先手权
f.First, f.Second = f.Second, f.First
}
if f.Second.GetProp(4, false) == f.First.GetProp(4, false) {
if grand.Meet(1, 2) { //随机出手
fattack, sattack = sattack, fattack //互换先手权
f.First, f.Second = f.Second, f.First
}
}
}
}
if fattack == nil && sattack == nil {
fattack, sattack = sattack, fattack //互换先手权
f.First, f.Second = f.Second, f.First
}
var attacker, defender *input.Input
//开始回合操作

View File

@@ -37,7 +37,7 @@ type FightC struct {
rand *rand.Rand
StartTime time.Time
actionChan chan action.BattleActionI // 所有操作统一从这里进入
Round int //回合数
quit chan struct{}
over chan struct{}
First *input.Input
@@ -355,3 +355,7 @@ func (f *FightC) GetOverChan() chan struct{} {
return f.over
}
func (f *FightC) GetOverInfo() info.FightOverInfo {
return f.FightOverInfo
}

View File

@@ -190,6 +190,14 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) {
}
func (our *Input) GetAction(opp *Input) {
next := our.Exec(func(t Effect) bool {
return t.HookAction()
})
if !next {
return
}
// 获取己方当前宠物和对方当前宠物
selfPet := our.FightC.GetCurrPET(our.Player)
//没血就切换精灵

View File

@@ -45,7 +45,8 @@ type Effect interface {
// OnOwnerSwitchIn() bool // 所属玩家精灵出战时触发
// OnOwnerSwitchOut() bool // 所属玩家精灵下场时触发
Turn_End() //回合结束计算
Turn_End() //回合结束计算
HookAction() bool //出手前的hook参数返回false阻止继续出手
//PreBattleEnd() bool //战斗结束前
OnBattleEnd() bool //战斗结束
Prop_Befer(in *Input, prop, level int8, ptype info.EnumAbilityOpType) bool //锁定属性

View File

@@ -207,7 +207,10 @@ func (f *FightC) handleTimeout(ourID, oppID uint32, actions map[uint32]action.Ba
f.Reason = info.BattleOverReason.PlayerOVerTime
f.closefight = true
//对方赢
f.WinnerId = f.GetInputByPlayer(f.getPlayerByID(pid), true).Player.GetInfo().UserID
if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC {
f.WinnerId = f.GetInputByPlayer(f.getPlayerByID(pid), true).Player.GetInfo().UserID
}
}
}

View File

@@ -26,3 +26,7 @@ func (e *EffectNode) Action_end() bool {
// panic("not implemented") // TODO: Implement
return true
}
func (e *EffectNode) HookAction() bool {
// panic("not implemented") // TODO: Implement
return true
}