From 4d7064e59fb3d0dcda7457bf25b3b1fdc39ac863 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 17:06:08 +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 | 4 +--- logic/controller/pet.go | 20 +++++++++----------- logic/service/player/fight.go | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index d70efe0a..0df5b7e5 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -126,9 +126,7 @@ func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *playe // 接收战斗或者取消战斗的包 func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if !c.CanFight() { - return nil, errorcode.ErrorCodes.ErrPokemonNotEligible - } + if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok { fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, c, p1) ///开始对战,房主方以及被邀请方 } diff --git a/logic/controller/pet.go b/logic/controller/pet.go index f04cac3d..7b310c0e 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -70,23 +70,21 @@ func (h *Controller) PetRelease( switch data.Flag { case 0: - removeIndex := -1 - for i, v := range c.Info.PetList { - if v.CatchTime == uint32(data.CatchTime) { - removeIndex = i - break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 - } - - } - if removeIndex != -1 { + 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 = c.Info.PetList[removeIndex] + t.Data = *v t.InBag = 0 }) - c.Info.PetList = append(c.Info.PetList[:removeIndex], c.Info.PetList[removeIndex+1:]...) + + c.Info.PetList = append(c.Info.PetList[:n], c.Info.PetList[n+1:]...) + } + // break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 case 1: //todo 背包 c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { diff --git a/logic/service/player/fight.go b/logic/service/player/fight.go index 0470caa6..fd44749a 100644 --- a/logic/service/player/fight.go +++ b/logic/service/player/fight.go @@ -88,7 +88,7 @@ func (lw *Player) AgreeBattle(userid, flag uint32, mode info.EnumBattleMode) (bo return false, nil } if v.Info.UserID == userid && v.PVPinfo.Mode == mode { //成功找到,同意对战 - if lw.CanFight() { + if lw.CanFight() &&v.CanFight(){ ret.Result = 1 v.SendPack(t1.Pack(ret))