```
refactor(player): 重构OgreInfo数据结构并优化怪物生成逻辑 - 将Player结构体中的OgreInfo字段从[9]OgrePetInfo数组改为OgrePet结构体 - 更新所有OgreInfo的访问方式,使用OgreInfo.Data[index]替代OgreInfo[index] - 移除不再使用的common包
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[data1.Number]
|
refPet := p.OgreInfo.Data[data1.Number]
|
||||||
if refPet.Id == 0 {
|
if refPet.Id == 0 {
|
||||||
|
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package player
|
|||||||
import (
|
import (
|
||||||
"blazing/common/data/xmlres"
|
"blazing/common/data/xmlres"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/logic/service/common"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@@ -42,11 +41,11 @@ func (p *Player) genMonster() {
|
|||||||
replce = []int{newNum} //产生替换新的精灵
|
replce = []int{newNum} //产生替换新的精灵
|
||||||
if atomic.CompareAndSwapUint32(&p.Canmon, 2, 1) {
|
if atomic.CompareAndSwapUint32(&p.Canmon, 2, 1) {
|
||||||
p.MapNPC.Reset(10 * time.Second)
|
p.MapNPC.Reset(10 * time.Second)
|
||||||
p.OgreInfo = [9]OgrePetInfo{} //切地图清空
|
p.OgreInfo.Data = [9]OgrePetInfo{} //切地图清空
|
||||||
replce = p.monsters[:] //产生替换新的精灵
|
replce = p.monsters[:] //产生替换新的精灵
|
||||||
|
|
||||||
}
|
}
|
||||||
p.OgreInfo[oldnum] = OgrePetInfo{} //切地图清空
|
p.OgreInfo.Data[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 {
|
||||||
@@ -64,34 +63,34 @@ func (p *Player) genMonster() {
|
|||||||
id := strings.Split(m.ID, " ")
|
id := strings.Split(m.ID, " ")
|
||||||
lv := strings.Split(m.Lv, " ")
|
lv := strings.Split(m.Lv, " ")
|
||||||
|
|
||||||
p.OgreInfo[i] = OgrePetInfo{}
|
p.OgreInfo.Data[i] = OgrePetInfo{}
|
||||||
p.OgreInfo[i].Id = gconv.Uint32(RandomStringFromSlice(id))
|
p.OgreInfo.Data[i].Id = gconv.Uint32(RandomStringFromSlice(id))
|
||||||
|
|
||||||
if p.OgreInfo[i].Id != 0 {
|
if p.OgreInfo.Data[i].Id != 0 {
|
||||||
|
|
||||||
p.OgreInfo[i].Lv = gconv.Uint32(RandomStringFromSlice(lv))
|
p.OgreInfo.Data[i].Lv = gconv.Uint32(RandomStringFromSlice(lv))
|
||||||
if cool.Config.PortBL == 2 { //测试服,百分百异色
|
if cool.Config.PortBL == 2 { //测试服,百分百异色
|
||||||
p.OgreInfo[i].RandSHiny(int64(i))
|
p.OgreInfo.Data[i].RandSHiny()
|
||||||
}
|
}
|
||||||
if xmlres.PetMAP[int(p.OgreInfo[i].Id)].CatchRate != 0 && grand.Meet(1, 100) {
|
if xmlres.PetMAP[int(p.OgreInfo.Data[i].Id)].CatchRate != 0 && grand.Meet(1, 100) {
|
||||||
p.OgreInfo[i].RandSHiny(int64(i))
|
p.OgreInfo.Data[i].RandSHiny()
|
||||||
}
|
}
|
||||||
if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥
|
if len(id) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥
|
||||||
|
|
||||||
nieo, _, _ := p.Roll(20, 1000)
|
nieo, _, _ := p.Roll(20, 1000)
|
||||||
if nieo {
|
if nieo {
|
||||||
p.OgreInfo[i].Ext = 77
|
p.OgreInfo.Data[i].Ext = 77
|
||||||
if grand.Meet(1, 2) {
|
if grand.Meet(1, 2) {
|
||||||
p.OgreInfo[i].Ext = 416
|
p.OgreInfo.Data[i].Ext = 416
|
||||||
}
|
}
|
||||||
|
|
||||||
p.OgreInfo[i].Lv = 16
|
p.OgreInfo.Data[i].Lv = 16
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
|
|
||||||
p.OgreInfo[i].Item = uint32(mapss.Monsters.ItemBonusID)
|
p.OgreInfo.Data[i].Item = uint32(mapss.Monsters.ItemBonusID)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,10 +99,7 @@ func (p *Player) genMonster() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建数据包
|
p.SendPackCmd(2004, &p.OgreInfo)
|
||||||
tt := common.NewTomeeHeader(2004, p.Info.UserID)
|
|
||||||
p.SendPack(tt.Pack(&p.OgreInfo))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成0-9之间三个不重复的随机数 进地图5s
|
// 生成0-9之间三个不重复的随机数 进地图5s
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type OgrePetInfo struct {
|
|||||||
Ext uint32 `struc:"skip"` //是否变尼尔尼奥
|
Ext uint32 `struc:"skip"` //是否变尼尔尼奥
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OgrePetInfo) RandSHiny(t int64) {
|
func (o *OgrePetInfo) RandSHiny() {
|
||||||
// o.ShinyInfo = make([]data.GlowFilter, 1)
|
// o.ShinyInfo = make([]data.GlowFilter, 1)
|
||||||
// // 假设 t 是包含 ShinyInfo 字段的结构体,ShinyInfo 是 GlowFilter 类型的切片
|
// // 假设 t 是包含 ShinyInfo 字段的结构体,ShinyInfo 是 GlowFilter 类型的切片
|
||||||
// o.ShinyInfo[0] = data.GlowFilter{
|
// o.ShinyInfo[0] = data.GlowFilter{
|
||||||
@@ -90,7 +90,7 @@ type Player struct {
|
|||||||
Fightinfo info.Fightinfo // 当前邀请的玩家ID
|
Fightinfo info.Fightinfo // 当前邀请的玩家ID
|
||||||
|
|
||||||
Logintime uint32 // 当前登录时间
|
Logintime uint32 // 当前登录时间
|
||||||
OgreInfo [9]OgrePetInfo
|
OgreInfo OgrePet
|
||||||
|
|
||||||
Service *blservice.UserService
|
Service *blservice.UserService
|
||||||
User *service.BaseSysUserService
|
User *service.BaseSysUserService
|
||||||
@@ -101,6 +101,10 @@ type Player struct {
|
|||||||
Canmon uint32 // 可以刷怪
|
Canmon uint32 // 可以刷怪
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OgrePet struct {
|
||||||
|
Data [9]OgrePetInfo
|
||||||
|
}
|
||||||
|
|
||||||
// PlayerOption 定义配置 Player 的函数类型
|
// PlayerOption 定义配置 Player 的函数类型
|
||||||
type PlayerOption func(*Player)
|
type PlayerOption func(*Player)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user