From 3aff7f7ad63a1dfe6a1247f056f293d0d934dfb3 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 17:19:09 +0000 Subject: [PATCH] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96=E6=88=98?= =?UTF-8?q?=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/fight.go | 10 ++++++++-- logic/controller/pet.go | 21 +++++++++++---------- logic/service/common/fight.go | 2 +- logic/service/fight/fightc.go | 4 ++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index 0df5b7e51..e718c33d2 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -162,9 +162,15 @@ func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (resu // 战斗逃跑 func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if c.FightC != nil { - c.FightC.Over(c, info.BattleOverReason.PlayerEscape) + if c.FightC == nil { + + return nil, 0 } + if !c.FightC.CanEscape() { + + return nil, 0 + } + c.FightC.Over(c, info.BattleOverReason.PlayerEscape) return nil, 0 } diff --git a/logic/controller/pet.go b/logic/controller/pet.go index 7b310c0e5..b41b05963 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -69,21 +69,22 @@ func (h *Controller) PetRelease( switch data.Flag { case 0: + var temp []model.PetInfo - n, v, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool { - return item.CatchTime == data.CatchTime - }) - if ok { - c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { - t.Data = *v - t.InBag = 0 + for _, v := range c.Info.PetList { + if v.CatchTime == uint32(data.CatchTime) { + c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { + t.Data = v + t.InBag = 0 - }) + }) - c.Info.PetList = append(c.Info.PetList[:n], c.Info.PetList[n+1:]...) + } else { + temp = append(temp, v) + } } - + c.Info.PetList = temp // break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 case 1: //todo 背包 diff --git a/logic/service/common/fight.go b/logic/service/common/fight.go index cfdbd8bd1..8f3e4f82f 100644 --- a/logic/service/common/fight.go +++ b/logic/service/common/fight.go @@ -15,6 +15,6 @@ type FightI interface { Capture(c PlayerI, id uint32) GetRand() *rand.Rand LoadPercent(c PlayerI, percent int32) - + CanEscape() bool IsFirst(c PlayerI) bool } diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 378bf8c06..e7a5ec573 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -36,6 +36,10 @@ type FightC struct { closefight bool } +func (f *FightC) CanEscape() bool { + + return f.Info.Status != info.BattleStatus.FIGHT_WITH_PLAYER +} func (f *FightC) Ownerid() uint32 { return f.ownerID