diff --git a/logic/controller/fight_boss.go b/logic/controller/fight_boss.go index b80f60426..e99874489 100644 --- a/logic/controller/fight_boss.go +++ b/logic/controller/fight_boss.go @@ -165,7 +165,7 @@ func (h Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundI if !p.CanFight() { return nil, errorcode.ErrorCodes.ErrSystemError } - refPet := p.OgreInfo.Data[data1.Number] + refPet := p.OgreInfo[data1.Number] if refPet.Id == 0 { return nil, errorcode.ErrorCodes.ErrPokemonNotExists diff --git a/logic/service/player/Monster.go b/logic/service/player/Monster.go index c9caa69c3..e5f1ab699 100644 --- a/logic/service/player/Monster.go +++ b/logic/service/player/Monster.go @@ -10,6 +10,7 @@ import ( "github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/grand" + "github.com/samber/lo" ) // 2. 从 string 类型 slice 随机选一个元素 @@ -36,72 +37,69 @@ func (p *Player) genMonster() { return } var oldnum, newNum int + var replce []int p.monsters, oldnum, newNum = replaceOneNumber(p.monsters) - // 设置怪物信息 - t1 := OgreInfo{} + replce = []int{newNum} //产生替换新的精灵 + if atomic.CompareAndSwapUint32(&p.Canmon, 2, 1) { + p.MapNPC.Reset(10 * time.Second) + p.OgreInfo = [9]OgrePetInfo{} //切地图清空 + replce = p.monsters[:] //产生替换新的精灵 + + } + p.OgreInfo[oldnum] = OgrePetInfo{} //切地图清空 mapss, ok := xmlres.MonsterMap[gconv.Int(p.Info.MapID)] if ok && mapss.Monsters != nil { ok, _, _ := p.PlayerCaptureContext.Roll(mapss.Monsters.WildBonusProb, mapss.Monsters.WildBonusTotalProb) for i, m := range mapss.Monsters.Monsters { //这里是9个 + + _, rok := lo.Find(replce, func(it int) bool { + return it == i + }) + + if !rok { + continue + } + id := strings.Split(m.ID, " ") lv := strings.Split(m.Lv, " ") - ttt := OgrePetInfo{} - ttt.Id = gconv.Uint32(RandomStringFromSlice(id)) + p.OgreInfo[i] = OgrePetInfo{} + p.OgreInfo[i].Id = gconv.Uint32(RandomStringFromSlice(id)) - if ttt.Id != 0 { + if p.OgreInfo[i].Id != 0 { - ttt.Lv = gconv.Uint32(RandomStringFromSlice(lv)) + p.OgreInfo[i].Lv = gconv.Uint32(RandomStringFromSlice(lv)) if cool.Config.PortBL == 2 { //测试服,百分百异色 - ttt.RandSHiny(int64(i)) + p.OgreInfo[i].RandSHiny(int64(i)) } - if xmlres.PetMAP[int(ttt.Id)].CatchRate != 0 && grand.Meet(1, 100) { - ttt.RandSHiny(int64(i)) + if xmlres.PetMAP[int(p.OgreInfo[i].Id)].CatchRate != 0 && grand.Meet(1, 100) { + p.OgreInfo[i].RandSHiny(int64(i)) } if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥 - // nier, _, _ := p.Roll(10, 1000) - // if nier { - // ttt.Ext = 77 - - // } - nieo, _, _ := p.Roll(20, 1000) if nieo { - ttt.Ext = 77 + p.OgreInfo[i].Ext = 77 if grand.Meet(1, 2) { - ttt.Ext = 416 + p.OgreInfo[i].Ext = 416 } - ttt.Lv = 16 + p.OgreInfo[i].Lv = 16 } } if ok { - ttt.Item = uint32(mapss.Monsters.ItemBonusID) + p.OgreInfo[i].Item = uint32(mapss.Monsters.ItemBonusID) } } - t1.Data[i] = ttt - } } - if atomic.CompareAndSwapUint32(&p.Canmon, 2, 1) { - p.MapNPC.Reset(10 * time.Second) - p.OgreInfo = OgreInfo{} //切地图清空 - for i := 0; i < 3; i++ { - - p.OgreInfo.Data[p.monsters[i]] = t1.Data[p.monsters[i]] - - } - } - p.OgreInfo.Data[oldnum] = OgrePetInfo{} - p.OgreInfo.Data[newNum] = t1.Data[newNum] // 创建数据包 tt := common.NewTomeeHeader(2004, p.Info.UserID) p.SendPack(tt.Pack(&p.OgreInfo)) diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 081c305e0..e016b2057 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -36,10 +36,6 @@ func CountPlayer() int { // Mainplayer 全局玩家数据存储映射 var Mainplayer = &utils.SyncMap[uint32, *Player]{} -type OgreInfo struct { - Data [9]OgrePetInfo -} - type OgrePetInfo struct { Id uint32 ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"` @@ -94,7 +90,7 @@ type Player struct { Fightinfo info.Fightinfo // 当前邀请的玩家ID Logintime uint32 // 当前登录时间 - OgreInfo OgreInfo + OgreInfo [9]OgrePetInfo Service *blservice.UserService User *service.BaseSysUserService diff --git a/logic/service/space/in_out.go b/logic/service/space/in_out.go index 71107bb6b..51acfa56e 100644 --- a/logic/service/space/in_out.go +++ b/logic/service/space/in_out.go @@ -48,8 +48,8 @@ func (s *Space) LeaveMap(c common.PlayerI) { s.User.Delete(c.GetInfo().UserID) s.UserInfo.Delete(c.GetInfo().UserID) - _, ok := maphot[s.Super] - if ok { + current, ok := maphot[s.Super] + if ok && *current > 0 { atomic.AddInt32(maphot[s.Super], -1) }