``` refactor(monster): 优化怪物生成逻辑并简化OgreInfo数据结构

This commit is contained in:
1
2025-12-28 14:40:17 +00:00
parent 7e840cbf17
commit 67227f3016
4 changed files with 34 additions and 40 deletions

View File

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

View File

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