refactor: 重构怪物生成和天气处理逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
将怪物捕捉处理逻辑移至OgrePetInfo结构体 提取天气和Boss生成逻辑为独立方法 移除未使用的导入和冗余代码
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"blazing/modules/config/service"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@@ -67,16 +65,6 @@ func (p *Player) GenMonster() {
|
||||
|
||||
p.Data[i].Lv = uint32(grand.N(v.MinLevel, v.MaxLevel))
|
||||
|
||||
if v.IsCapture != 0 {
|
||||
if handleNPCFightSpecial(p.Data[i].ID) == 0 {
|
||||
p.Data[i].IsCapture = 0
|
||||
} else {
|
||||
p.Data[i].IsCapture = handleNPCFightSpecial(p.Data[i].ID) //施加捕捉率
|
||||
}
|
||||
} else {
|
||||
p.Data[i].IsCapture = 0
|
||||
}
|
||||
|
||||
if len(v.RefreshID) == 1 { //说明这里只固定刷一个,概率变尼尔尼奥,不是稀有精灵
|
||||
|
||||
nieo := grand.Meet(20, 1000)
|
||||
@@ -88,11 +76,10 @@ func (p *Player) GenMonster() {
|
||||
|
||||
p.Data[i].Lv = 16
|
||||
|
||||
p.Data[i].IsCapture = handleNPCFightSpecial(p.Data[i].Ext) //解除捕捉限制
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
p.Data[i].HandleNPCFightSpecial(v.IsCapture)
|
||||
if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色
|
||||
p.Data[i].FixSHiny()
|
||||
} else {
|
||||
@@ -205,17 +192,3 @@ func GenerateNormalizedColorMatrix() [20]uint8 {
|
||||
|
||||
return matrix
|
||||
}
|
||||
|
||||
// handleNPCFightSpecial 处理NPC战斗特殊情况
|
||||
func handleNPCFightSpecial(petID uint32) int {
|
||||
|
||||
npcPetID := int(petID)
|
||||
petCfg, ok := xmlres.PetMAP[npcPetID]
|
||||
if !ok {
|
||||
// log.Error(context.Background(), "NPC宠物配置不存在", "petID", npcPetID)
|
||||
return 0
|
||||
}
|
||||
|
||||
catchRate := gconv.Int(petCfg.CatchRate)
|
||||
return catchRate
|
||||
}
|
||||
|
||||
@@ -71,6 +71,28 @@ func (o *OgrePetInfo) RandomByWeightShiny() {
|
||||
|
||||
}
|
||||
|
||||
// handleNPCFightSpecial 处理NPC战斗特殊情况
|
||||
func (o *OgrePetInfo) HandleNPCFightSpecial(v int) {
|
||||
if v == 0 {
|
||||
o.IsCapture = 0
|
||||
return
|
||||
|
||||
}
|
||||
npcPetID := int(o.ID)
|
||||
if o.Ext != 0 {
|
||||
npcPetID = int(o.Ext)
|
||||
}
|
||||
|
||||
petCfg, ok := xmlres.PetMAP[npcPetID]
|
||||
if !ok {
|
||||
|
||||
o.IsCapture = 0
|
||||
} else {
|
||||
o.IsCapture = gconv.Int(petCfg.CatchRate)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
MainConn gnet.Conn
|
||||
baseplayer
|
||||
|
||||
@@ -39,9 +39,9 @@ type Space struct {
|
||||
Name string //地图名称
|
||||
Owner ARENA
|
||||
info.MapBossSInfo
|
||||
IsChange bool
|
||||
|
||||
TimeBoss info.S2C_2022
|
||||
IsChange bool
|
||||
WeatherType []uint32
|
||||
TimeBoss info.S2C_2022
|
||||
//Weather uint32
|
||||
IsTime bool
|
||||
//CanWeather uint32
|
||||
@@ -100,29 +100,9 @@ func GetSpace(id uint32) *Space {
|
||||
ret.MapBossSInfo = info.MapBossSInfo{}
|
||||
ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0)
|
||||
if len(r.WeatherType) > 1 {
|
||||
ret.WeatherType = r.WeatherType
|
||||
// ret.CanWeather = 1
|
||||
cool.Cron.CustomFunc(ret, func() {
|
||||
//if ret.CanWeather == 1 {
|
||||
var neww uint32 = 0
|
||||
|
||||
if len(r.WeatherType) == 2 {
|
||||
neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{9, 1})
|
||||
} else {
|
||||
neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{8, 1, 1})
|
||||
}
|
||||
|
||||
if neww != uint32(ret.MapBossSInfo.Wer) {
|
||||
ret.IsChange = true
|
||||
ret.MapBossSInfo.Wer = int32(neww)
|
||||
println(ret.Name, "change weather", neww)
|
||||
|
||||
} else {
|
||||
ret.IsChange = false
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
})
|
||||
cool.Cron.CustomFunc(ret, ret.GenWer)
|
||||
}
|
||||
for _, v := range service.NewMapNodeService().GetData(ret.ID) {
|
||||
|
||||
@@ -142,37 +122,8 @@ func GetSpace(id uint32) *Space {
|
||||
}
|
||||
|
||||
if len(ret.MapBossSInfo.INFO) > 0 {
|
||||
cool.Cron.ScheduleFunc(10*time.Second, func() {
|
||||
|
||||
for i := 0; i < len(ret.MapBossSInfo.INFO); i++ {
|
||||
s := len(ret.MapBossSInfo.INFO[i].PosInfo)
|
||||
if s != 0 {
|
||||
ret.MapBossSInfo.INFO[i].Pos = ret.MapBossSInfo.INFO[i].PosInfo[(grand.Intn(s-1)+1+int(ret.MapBossSInfo.INFO[i].PosIndex))%s]
|
||||
}
|
||||
|
||||
_, ok := lo.Find(ret.MapBossSInfo.INFO[i].Wer, func(item int32) bool {
|
||||
return item == ret.MapBossSInfo.Wer
|
||||
})
|
||||
if ok {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 1
|
||||
if ret.IsChange {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 2
|
||||
}
|
||||
} else {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ret.Broadcast(nil, 2021, &ret.MapBossSInfo)
|
||||
|
||||
})
|
||||
cool.Cron.ScheduleFunc(300*time.Second, func() {
|
||||
for _, v := range ret.MapBossSInfo.INFO {
|
||||
atomic.StoreInt32(&v.Hp, int32(v.MaxHP))
|
||||
}
|
||||
|
||||
})
|
||||
cool.Cron.ScheduleFunc(10*time.Second, ret.GenBoss)
|
||||
cool.Cron.ScheduleFunc(300*time.Second, ret.HealHP)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -232,3 +183,58 @@ func (t *Space) Next(time.Time) time.Time {
|
||||
return time.Now().Add(grand.D(6*time.Second, 30*time.Second))
|
||||
|
||||
}
|
||||
func (ret *Space) GenBoss() {
|
||||
|
||||
for i := 0; i < len(ret.MapBossSInfo.INFO); i++ {
|
||||
s := len(ret.MapBossSInfo.INFO[i].PosInfo)
|
||||
if s != 0 {
|
||||
ret.MapBossSInfo.INFO[i].Pos = ret.MapBossSInfo.INFO[i].PosInfo[(grand.Intn(s-1)+1+int(ret.MapBossSInfo.INFO[i].PosIndex))%s]
|
||||
}
|
||||
|
||||
_, ok := lo.Find(ret.MapBossSInfo.INFO[i].Wer, func(item int32) bool {
|
||||
return item == ret.MapBossSInfo.Wer
|
||||
})
|
||||
if ok {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 1
|
||||
if ret.IsChange {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 2
|
||||
}
|
||||
} else {
|
||||
ret.MapBossSInfo.INFO[i].IsShow = 0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ret.Broadcast(nil, 2021, &ret.MapBossSInfo)
|
||||
|
||||
}
|
||||
func (ret *Space) HealHP() {
|
||||
|
||||
for _, v := range ret.MapBossSInfo.INFO {
|
||||
atomic.StoreInt32(&v.Hp, int32(v.MaxHP))
|
||||
}
|
||||
}
|
||||
func (ret *Space) GenWer() {
|
||||
|
||||
//if ret.CanWeather == 1 {
|
||||
var neww uint32 = 0
|
||||
|
||||
if len(ret.WeatherType) == 2 {
|
||||
neww, _ = utils.RandomByWeight(ret.WeatherType, []uint32{9, 1})
|
||||
} else {
|
||||
neww, _ = utils.RandomByWeight(ret.WeatherType, []uint32{8, 1, 1})
|
||||
}
|
||||
|
||||
if neww != uint32(ret.MapBossSInfo.Wer) {
|
||||
ret.IsChange = true
|
||||
ret.MapBossSInfo.Wer = int32(neww)
|
||||
ret.GenBoss()
|
||||
println(ret.Name, "change weather", neww)
|
||||
|
||||
} else {
|
||||
ret.IsChange = false
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user