refactor: 重构怪物生成和天气处理逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

将怪物捕捉处理逻辑移至OgrePetInfo结构体
提取天气和Boss生成逻辑为独立方法
移除未使用的导入和冗余代码
This commit is contained in:
xinian
2026-02-26 13:38:57 +08:00
committed by cnb
parent d27112b5a8
commit 7ceb2fb3d6
3 changed files with 85 additions and 84 deletions

View File

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