``` refactor(monster): 优化怪物生成逻辑并简化OgreInfo数据结构
This commit is contained in:
@@ -165,7 +165,7 @@ func (h Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundI
|
|||||||
if !p.CanFight() {
|
if !p.CanFight() {
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
}
|
}
|
||||||
refPet := p.OgreInfo.Data[data1.Number]
|
refPet := p.OgreInfo[data1.Number]
|
||||||
if refPet.Id == 0 {
|
if refPet.Id == 0 {
|
||||||
|
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/gogf/gf/v2/util/grand"
|
"github.com/gogf/gf/v2/util/grand"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 2. 从 string 类型 slice 随机选一个元素
|
// 2. 从 string 类型 slice 随机选一个元素
|
||||||
@@ -36,72 +37,69 @@ func (p *Player) genMonster() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var oldnum, newNum int
|
var oldnum, newNum int
|
||||||
|
var replce []int
|
||||||
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
||||||
// 设置怪物信息
|
replce = []int{newNum} //产生替换新的精灵
|
||||||
t1 := OgreInfo{}
|
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)]
|
mapss, ok := xmlres.MonsterMap[gconv.Int(p.Info.MapID)]
|
||||||
|
|
||||||
if ok && mapss.Monsters != nil {
|
if ok && mapss.Monsters != nil {
|
||||||
ok, _, _ := p.PlayerCaptureContext.Roll(mapss.Monsters.WildBonusProb, mapss.Monsters.WildBonusTotalProb)
|
ok, _, _ := p.PlayerCaptureContext.Roll(mapss.Monsters.WildBonusProb, mapss.Monsters.WildBonusTotalProb)
|
||||||
for i, m := range mapss.Monsters.Monsters { //这里是9个
|
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, " ")
|
id := strings.Split(m.ID, " ")
|
||||||
lv := strings.Split(m.Lv, " ")
|
lv := strings.Split(m.Lv, " ")
|
||||||
|
|
||||||
ttt := OgrePetInfo{}
|
p.OgreInfo[i] = OgrePetInfo{}
|
||||||
ttt.Id = gconv.Uint32(RandomStringFromSlice(id))
|
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 { //测试服,百分百异色
|
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) {
|
if xmlres.PetMAP[int(p.OgreInfo[i].Id)].CatchRate != 0 && grand.Meet(1, 100) {
|
||||||
ttt.RandSHiny(int64(i))
|
p.OgreInfo[i].RandSHiny(int64(i))
|
||||||
}
|
}
|
||||||
if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥
|
if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥
|
||||||
|
|
||||||
// nier, _, _ := p.Roll(10, 1000)
|
|
||||||
// if nier {
|
|
||||||
// ttt.Ext = 77
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
nieo, _, _ := p.Roll(20, 1000)
|
nieo, _, _ := p.Roll(20, 1000)
|
||||||
if nieo {
|
if nieo {
|
||||||
ttt.Ext = 77
|
p.OgreInfo[i].Ext = 77
|
||||||
if grand.Meet(1, 2) {
|
if grand.Meet(1, 2) {
|
||||||
ttt.Ext = 416
|
p.OgreInfo[i].Ext = 416
|
||||||
}
|
}
|
||||||
|
|
||||||
ttt.Lv = 16
|
p.OgreInfo[i].Lv = 16
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ok {
|
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)
|
tt := common.NewTomeeHeader(2004, p.Info.UserID)
|
||||||
p.SendPack(tt.Pack(&p.OgreInfo))
|
p.SendPack(tt.Pack(&p.OgreInfo))
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ func CountPlayer() int {
|
|||||||
// Mainplayer 全局玩家数据存储映射
|
// Mainplayer 全局玩家数据存储映射
|
||||||
var Mainplayer = &utils.SyncMap[uint32, *Player]{}
|
var Mainplayer = &utils.SyncMap[uint32, *Player]{}
|
||||||
|
|
||||||
type OgreInfo struct {
|
|
||||||
Data [9]OgrePetInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
type OgrePetInfo struct {
|
type OgrePetInfo struct {
|
||||||
Id uint32
|
Id uint32
|
||||||
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
|
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
|
||||||
@@ -94,7 +90,7 @@ type Player struct {
|
|||||||
Fightinfo info.Fightinfo // 当前邀请的玩家ID
|
Fightinfo info.Fightinfo // 当前邀请的玩家ID
|
||||||
|
|
||||||
Logintime uint32 // 当前登录时间
|
Logintime uint32 // 当前登录时间
|
||||||
OgreInfo OgreInfo
|
OgreInfo [9]OgrePetInfo
|
||||||
|
|
||||||
Service *blservice.UserService
|
Service *blservice.UserService
|
||||||
User *service.BaseSysUserService
|
User *service.BaseSysUserService
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
|||||||
|
|
||||||
s.User.Delete(c.GetInfo().UserID)
|
s.User.Delete(c.GetInfo().UserID)
|
||||||
s.UserInfo.Delete(c.GetInfo().UserID)
|
s.UserInfo.Delete(c.GetInfo().UserID)
|
||||||
_, ok := maphot[s.Super]
|
current, ok := maphot[s.Super]
|
||||||
if ok {
|
if ok && *current > 0 {
|
||||||
atomic.AddInt32(maphot[s.Super], -1)
|
atomic.AddInt32(maphot[s.Super], -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user