diff --git a/logic/controller/fight_pvp_king.go b/logic/controller/fight_pvp_king.go index 03fce6a60..c680250b9 100644 --- a/logic/controller/fight_pvp_king.go +++ b/logic/controller/fight_pvp_king.go @@ -3,14 +3,24 @@ package controller import ( "blazing/common/socket/errorcode" "blazing/logic/service/fight" + "blazing/logic/service/fight/info" "blazing/logic/service/player" ) -//精灵王之战 +//大乱斗 -func (h Controller) PvpKingFight(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { +func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrPokemonNotEligible } + + c.PVPinfo = &info.PVPinfo{ + Mode: info.BattleMode.PET_MELEE, + Status: info.BattleStatus.FIGHT_WITH_PLAYER} + g := c.PET_MELEE() + if g != nil { + fight.NewFight(info.BattleMode.PET_MELEE, info.BattleStatus.FIGHT_WITH_PLAYER, c.PET_MELEE(), c) ///开始对战,房主方以及被邀请方 + } + return } diff --git a/logic/controller/fight_pvp_withplayer.go b/logic/controller/fight_pvp_withplayer.go index bf847cde6..e0b9e90c1 100644 --- a/logic/controller/fight_pvp_withplayer.go +++ b/logic/controller/fight_pvp_withplayer.go @@ -35,7 +35,7 @@ func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInf // 取消和他人战斗 func (h Controller) OnPlayerCanceledOtherInviteFight(data *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - c.CancelBattle() + c.PVPinfo = nil return nil, 0 } diff --git a/logic/service/fight/info/battle.go b/logic/service/fight/info/battle.go index 3dc8dd96d..602584b10 100644 --- a/logic/service/fight/info/battle.go +++ b/logic/service/fight/info/battle.go @@ -26,11 +26,13 @@ import ( type EnumBattleMode int var BattleMode = enum.New[struct { + PET_MELEE EnumBattleMode `enum:"3"` //乱斗模式 SINGLE_MODE EnumBattleMode `enum:"1"` // 单人模式 MULTI_MODE EnumBattleMode `enum:"2"` // 多人模式 }]() var BattleStatus = enum.New[struct { // 原ActionScript中的常量映射 + FIGHT_WITH_NPC EnumBattleMode `enum:"3"` // 与NPC战斗 FIGHT_WITH_BOSS EnumBattleMode `enum:"2"` // 与BOSS战斗 FIGHT_WITH_PLAYER EnumBattleMode `enum:"1"` // 与玩家战斗(PVP) diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index 9be344eca..c712a2bbc 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -6,8 +6,8 @@ import ( "blazing/logic/service/fight/action" "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" + "blazing/modules/blazing/model" "math/rand" - "sort" "sync" "time" @@ -100,81 +100,80 @@ func (f *FightC) LoadPercent(c common.PlayerI, percent int32) { }) } -func (f *FightC) initplayer(c common.PlayerI, opp bool) bool { +func (f *FightC) initplayer(c common.PlayerI) *input.Input { if len(c.GetInfo().PetList) == 0 { - return false + return nil } - temp := input.NewInput(f, c) - temp.AllPet = make([]*info.BattlePetEntity, 0) - temp.InitAttackValue() + in := input.NewInput(f, c) + in.AllPet = make([]*info.BattlePetEntity, 0) + in.InitAttackValue() for i := 0; i < len(c.GetInfo().PetList); i++ { - temp.AllPet = append(temp.AllPet, info.CreateBattlePetEntity(&c.GetInfo().PetList[i], f.rand)) + in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(&c.GetInfo().PetList[i], f.rand)) } - sort.Slice(temp.AllPet, func(i, j int) bool { - x, y := temp.AllPet[i], temp.AllPet[j] - // 若x血量>0且y血量=0,则x排在前 - if x.Info.Hp > 0 && y.Info.Hp <= 0 { - return true - } - // 若x血量=0且y血量>0,则x排在后 - if x.Info.Hp <= 0 && y.Info.Hp > 0 { - return false - } - // 同类型(都>0或都=0)保持原有顺序 - return i < j - }) + in.SortPet() switch f.Info.Mode { case info.BattleMode.SINGLE_MODE: - temp.AllPet = temp.AllPet[:1] + in.AllPet = in.AllPet[:1] + case info.BattleMode.PET_MELEE: + in.AllPet = make([]*info.BattlePetEntity, 0) + for _, v := range RandomElfIDs(3) { + p := model.GenPetInfo(v, 24, -1, -1, -1, 100) + p.CatchTime = uint32(v) + in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(p, f.rand)) + + } + //in.AllPet = in.AllPet[:3] default: } - if opp { - switch f.Info.Status { - case info.BattleStatus.FIGHT_WITH_PLAYER: - default: - temp.Finished = true //PVE 默认boss数据直接加载完成 - } - f.Opp = temp //这里是对方的 + in.CurrentPet = in.AllPet[0] + return in +} - copier.Copy(&f.Info.OpponentInfo, f.Opp.Player.GetInfo()) - f.Info.OpponentPetList = make([]info.ReadyFightPetInfo, len(temp.AllPet)) - for i := 0; i < len(temp.AllPet); i++ { +// RandomElfIDs 从1-2000中随机抽取n个不重复的精灵ID +func RandomElfIDs(n int) []int { + if n <= 0 || n > 2000 { + return nil + } - err := copier.CopyWithOption(&f.Info.OpponentPetList[i], &temp.AllPet[i].Info, copier.Option{IgnoreEmpty: true, DeepCopy: true}) - if err != nil { - panic(err) - } - } - } else { - f.Our = temp + // 用map记录已抽取的ID,避免重复 + used := make(map[int]struct{}, n) + ids := make([]int, 0, n) - copier.Copy(&f.Info.OurInfo, f.Our.Player.GetInfo()) - f.Info.OurPetList = make([]info.ReadyFightPetInfo, len(temp.AllPet)) - for i := 0; i < len(temp.AllPet); i++ { + for len(ids) < n { + // 生成1-2000的随机数 + id := rand.Intn(2000) + 1 // rand.Intn(2000)生成0-1999,+1后为1-2000 - err := copier.CopyWithOption(&f.Info.OurPetList[i], &temp.AllPet[i].Info, copier.Option{IgnoreEmpty: true, DeepCopy: true}) - if err != nil { - panic(err) - } + // 检查是否已抽取 + if _, exists := used[id]; !exists { + used[id] = struct{}{} + ids = append(ids, id) } } - for _, v := range temp.AllPet { - if v.Info.Hp == 0 { - v.NotAlive = true - - } - + return ids +} +func initfightready(in *input.Input) (info.FightUserInfo, []info.ReadyFightPetInfo) { + t := make([]info.ReadyFightPetInfo, len(in.AllPet)) + userindo := info.FightUserInfo{ + UserID: in.UserID, + Nick: in.Player.GetInfo().Nick, } - temp.CurrentPet = temp.AllPet[0] - return true + for i := 0; i < len(in.AllPet); i++ { + + err := copier.CopyWithOption(&t[i], &in.AllPet[i].Info, copier.Option{IgnoreEmpty: true, DeepCopy: true}) + if err != nil { + panic(err) + } + } + + return userindo, t } // 创建新战斗,邀请方和被邀请方,或者玩家和野怪方 @@ -192,15 +191,18 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla } f.Info.Status = status //房主 f.Info.Mode = mode - ok := f.initplayer(p1, false) - if !ok { - return nil + f.Our, f.Opp = f.initplayer(p1), f.initplayer(p2) + + f.Info.OurInfo, f.Info.OurPetList = initfightready(f.Our) + f.Info.OpponentInfo, f.Info.OpponentPetList = initfightready(f.Opp) + + switch f.Info.Status { + case info.BattleStatus.FIGHT_WITH_PLAYER: + + default: + f.Our.Finished = true //PVE 默认boss数据直接加载完成 } - ok = f.initplayer(p2, true) - if !ok { - return nil - } f.Our.SetOPP(f.Opp) f.Opp.SetOPP(f.Our) diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index af43590d3..df485b89b 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -2,6 +2,7 @@ package input import ( "blazing/common/data/xmlres" + "sort" "blazing/logic/service/common" "blazing/logic/service/fight/action" @@ -56,6 +57,29 @@ func NewInput(c common.FightI, p common.PlayerI) *Input { return ret } + +func (our *Input) SortPet() { + sort.Slice(our.AllPet, func(i, j int) bool { + x, y := our.AllPet[i], our.AllPet[j] + // 若x血量>0且y血量=0,则x排在前 + if x.Info.Hp > 0 && y.Info.Hp <= 0 { + return true + } + // 若x血量=0且y血量>0,则x排在后 + if x.Info.Hp <= 0 && y.Info.Hp > 0 { + return false + } + // 同类型(都>0或都=0)保持原有顺序 + return i < j + }) + for _, v := range our.AllPet { + if v.Info.Hp == 0 { + v.NotAlive = true + + } + + } +} func (our *Input) GetPetInfo() *info.BattlePetEntity { return our.CurrentPet @@ -66,6 +90,7 @@ func (our *Input) SetOPP(t *Input) { our.Opp = t } + func (our *Input) GenSataus() { our.Status = [20]int8{} for i := 0; i < 20; i++ { //堆叠状态剩余回合 diff --git a/logic/service/fight/node/fight.go b/logic/service/fight/node/fight.go index 037e77ad9..735c73acd 100644 --- a/logic/service/fight/node/fight.go +++ b/logic/service/fight/node/fight.go @@ -14,7 +14,8 @@ func (e *EffectNode) PreBattleEnd() bool { } func (e *EffectNode) OnBattleEnd() bool { - panic("not implemented") // TODO: Implement + // panic("not implemented") // TODO: Implement + return true } func (e *EffectNode) EFFect_Befer(in *input.Input, effEffect input.Effect) bool { diff --git a/logic/service/player/fight.go b/logic/service/player/fight.go index 1fca5a0d5..ddf1a62f8 100644 --- a/logic/service/player/fight.go +++ b/logic/service/player/fight.go @@ -2,12 +2,14 @@ package player import ( "blazing/logic/service/common" + "blazing/logic/service/fight/info" "blazing/logic/service/space" ) // 邀请玩家加入战斗 邀请者,被邀请者,邀请模式 func (lw *Player) InvitePlayerToBattle() { + pinfo := lw.PVPinfo space.GetSpace(lw.Info.MapID).User.IterCb(func(key uint32, v common.PlayerI) { @@ -28,11 +30,25 @@ func (lw *Player) InvitePlayerToBattle() { }) } +func (p *Player) PET_MELEE() *Player { + var lw *Player + //pinfo := lw.PVPinfo + space.GetSpace(p.Info.MapID).User.IterCb(func(key uint32, v common.PlayerI) { -// 取消对战邀请 -func (lw *Player) CancelBattle() { + value := v.(*Player) - lw.PVPinfo = nil + if value.PVPinfo != nil && value != p { + //确认是乱斗模式 + + if value.PVPinfo.Mode == info.BattleMode.PET_MELEE { + lw = value + return + } + + } + + }) + return lw } func (p *Player) SendLoadPercent(b info.LoadPercentOutboundInfo) {