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))