feat(common/utils): 添加时间范围检查工具函数 添加了 IsCurrentTimeInRange 函数用于判断当前时间是否在指定的 HH:MM 时间区间内,支持当前日期的时间比较功能。 refactor(logic/controller): 重构 Boss 挑战逻辑并集成配置服务 - 集成 service 模块替代原有硬编码逻辑 - 重构 PlayerFightBoss 方法,使用新的配置数据结构 - 移除已废弃的 processMonID 函数和相关注释代码 refactor(logic/space): 优化地图 Boss 信息管理和天气系统 - 更新地图 Boss 数据
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
package space
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/space/info"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
func (s *Space) getfixboss(mapid uint32) {
|
||||
|
||||
switch mapid {
|
||||
case 12:
|
||||
|
||||
s.MapBossInfo = info.MapBossInfo{
|
||||
Id: 47,
|
||||
|
||||
Hp: 10,
|
||||
}
|
||||
|
||||
cool.Cron.ScheduleFunc(10*time.Second, func() {
|
||||
s.MapBossInfo.Pos = (grand.Intn(4) + 1 + s.MapBossInfo.Pos) % 5
|
||||
println(s.Name, "pos", s.MapBossInfo.Pos, "hp", s.MapBossInfo.Hp)
|
||||
var t info.MapBossSInfo
|
||||
t.INFO = append(t.INFO, s.MapBossInfo)
|
||||
|
||||
s.Broadcast(nil, 2021, &t)
|
||||
|
||||
})
|
||||
cool.Cron.ScheduleFunc(300*time.Second, func() {
|
||||
|
||||
atomic.StoreInt32(&s.MapBossInfo.Hp, 10)
|
||||
|
||||
})
|
||||
|
||||
case 108:
|
||||
s.MapBossInfo = info.MapBossInfo{
|
||||
Id: 219,
|
||||
}
|
||||
|
||||
cool.Cron.ScheduleFunc(10*time.Second, func() {
|
||||
var t info.MapBossSInfo
|
||||
s.MapBossInfo.Pos = (grand.Intn(6) + 1 + s.MapBossInfo.Pos) % 6
|
||||
t.INFO = append(t.INFO, s.MapBossInfo)
|
||||
|
||||
s.Broadcast(nil, 2021, &t)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package space
|
||||
|
||||
import (
|
||||
"blazing/logic/service/space/info"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
func (s *Space) getwerboss() {
|
||||
println("天气变化地图", s.Name, "pos", s.MapBossInfo.Pos, "wer", s.Weather)
|
||||
switch s.ID {
|
||||
case 12:
|
||||
|
||||
case 32:
|
||||
|
||||
s.MapBossInfo = info.MapBossInfo{
|
||||
Id: 70,
|
||||
}
|
||||
|
||||
var t info.MapBossSInfo
|
||||
s.MapBossInfo.Id = 70
|
||||
if s.Weather == 1 {
|
||||
s.MapBossInfo.Pos = 0
|
||||
|
||||
} else {
|
||||
|
||||
s.MapBossInfo.Pos = 200
|
||||
|
||||
}
|
||||
t.INFO = append(t.INFO, s.MapBossInfo)
|
||||
|
||||
s.Broadcast(nil, 2021, &t)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (t *Space) Next(time.Time) time.Time {
|
||||
|
||||
return time.Now().Add(grand.D(6*time.Second, 30*time.Second))
|
||||
|
||||
}
|
||||
@@ -30,15 +30,21 @@ type WalkOutInfo struct {
|
||||
}
|
||||
|
||||
type MapBossSInfo struct {
|
||||
Wer int32 `struc:"uint32"`
|
||||
InfoLen uint32 `struc:"sizeof=INFO" json:"info_len"`
|
||||
|
||||
INFO []MapBossInfo
|
||||
}
|
||||
type MapBossInfo struct {
|
||||
Id uint32 `json:"id" protobuf:"1,req,name=id"` // 需要刷新的BOSS精灵ID
|
||||
Region uint32 `json:"region" protobuf:"2,req,name=region"` // 刷新区域(蘑菇怪为0)
|
||||
Hp int32 `struc:"uint32" json:"hp" protobuf:"3,req,name=hp"` // HP值(蘑菇怪为A,其他BOSS暂未明确用途,可能无实际作用)
|
||||
Pos int `struc:"uint32" json:"pos" protobuf:"4,req,name=pos"` // 刷新坐标(类似野怪的位置ID,蘑菇怪初始为2; pos==200时候将会删除boss显示
|
||||
Id uint32 `json:"id" protobuf:"1,req,name=id"` // 需要刷新的BOSS精灵ID
|
||||
Region uint32 `json:"region" protobuf:"2,req,name=region"` //index,直接给boss的节点ID
|
||||
Hp int32 `struc:"uint32" json:"hp" protobuf:"3,req,name=hp"` // HP值(蘑菇怪为A,其他BOSS暂未明确用途,可能无实际作用)
|
||||
Pos model.Pos
|
||||
IsShow int32 `struc:"uint32" json:"is_show"` // 雷伊首次出现的时候给2,正常精灵给1,雷伊是否首次出现的判断是否首次刷新,
|
||||
PosInfo []model.Pos `struc:"skip"`
|
||||
MaxHP int `struc:"skip"`
|
||||
PosIndex uint32 `struc:"skip"`
|
||||
Wer []int32 `struc:"skip"`
|
||||
}
|
||||
|
||||
// 这里存储星球的map
|
||||
@@ -166,10 +172,7 @@ type LeaveMapOutboundInfo struct {
|
||||
// 米米号
|
||||
UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"`
|
||||
}
|
||||
type S2C_50004 struct {
|
||||
Id uint32 `json:"id" protobuf:"1,req,name=id"` // 天气0没有,1是雨.2是雪
|
||||
|
||||
}
|
||||
type S2C_2022 struct {
|
||||
Flag uint32 `json:"flag" protobuf:"1,req,name=flag"`
|
||||
ID uint32 `json:"id" protobuf:"2,req,name=id"`
|
||||
|
||||
@@ -5,11 +5,19 @@ import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/service"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/space/info"
|
||||
|
||||
infomodel "blazing/modules/player/model"
|
||||
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
"github.com/samber/lo"
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
@@ -30,10 +38,12 @@ type Space struct {
|
||||
ID uint32 // 地图ID
|
||||
Name string //地图名称
|
||||
Owner ARENA
|
||||
info.MapBossInfo
|
||||
info.MapBossSInfo
|
||||
IsChange bool
|
||||
|
||||
TimeBoss info.S2C_2022
|
||||
Weather uint32
|
||||
IsTime bool
|
||||
//Weather uint32
|
||||
IsTime bool
|
||||
//CanWeather uint32
|
||||
}
|
||||
|
||||
@@ -67,8 +77,7 @@ func GetSpace(id uint32) *Space {
|
||||
ret.Super = uint32(v.ID)
|
||||
}
|
||||
ret.ID = uint32(v.ID)
|
||||
ret.getfixboss(uint32(v.ID))
|
||||
//t.gettimeboss(uint32(v.ID))
|
||||
|
||||
_, ok := maphot[ret.Super]
|
||||
if !ok {
|
||||
var t1 int32
|
||||
@@ -84,9 +93,12 @@ func GetSpace(id uint32) *Space {
|
||||
|
||||
r := service.NewMapService().GetData(ret.ID)
|
||||
if r != nil {
|
||||
|
||||
if r.IsTimeSpace != 0 {
|
||||
ret.IsTime = true
|
||||
}
|
||||
ret.MapBossSInfo = info.MapBossSInfo{}
|
||||
ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0)
|
||||
if len(r.WeatherType) > 1 {
|
||||
// ret.CanWeather = 1
|
||||
cool.Cron.CustomFunc(ret, func() {
|
||||
@@ -99,16 +111,67 @@ func GetSpace(id uint32) *Space {
|
||||
neww, _ = utils.RandomByWeight(r.WeatherType, []uint32{8, 1, 1})
|
||||
}
|
||||
|
||||
if neww != ret.Weather {
|
||||
ret.Broadcast(nil, 50004, &info.S2C_50004{Id: uint32(neww)})
|
||||
ret.Weather = neww
|
||||
ret.getwerboss()
|
||||
if neww != uint32(ret.MapBossSInfo.Wer) {
|
||||
ret.IsChange = true
|
||||
ret.MapBossSInfo.Wer = int32(neww)
|
||||
|
||||
} else {
|
||||
ret.IsChange = false
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
})
|
||||
}
|
||||
for _, v := range service.NewMapNodeService().GetData(ret.ID) {
|
||||
|
||||
if v.IsBroadcast != 0 { //说明是地图怪
|
||||
info := info.MapBossInfo{
|
||||
|
||||
Region: v.NodeID, //这个是注册的index
|
||||
Hp: v.HP,
|
||||
PosInfo: ParseCoordinateString(v.Pos),
|
||||
MaxHP: int(v.HP),
|
||||
Wer: v.Weather,
|
||||
}
|
||||
bossid := uint32(service.NewBossService().Get(v.BossIds[0])[0].MonID)
|
||||
info.Id = bossid
|
||||
ret.MapBossSInfo.INFO = append(ret.MapBossSInfo.INFO, info)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
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))
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,3 +180,53 @@ func GetSpace(id uint32) *Space {
|
||||
}
|
||||
|
||||
var planetmap = csmap.New[uint32, *Space]()
|
||||
|
||||
func ParseCoordinateString(s string) []infomodel.Pos {
|
||||
// 存储解析后的坐标
|
||||
var points []infomodel.Pos
|
||||
|
||||
// 空字符串处理
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return points
|
||||
}
|
||||
|
||||
// 第一步:按竖线分割成单个坐标字符串
|
||||
coordStrs := strings.Split(s, "|")
|
||||
for _, coordStr := range coordStrs {
|
||||
// 去除首尾空格(兼容可能的格式不规范)
|
||||
coordStr = strings.TrimSpace(coordStr)
|
||||
if coordStr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 第二步:按逗号分割X、Y值
|
||||
xy := strings.Split(coordStr, ",")
|
||||
if len(xy) != 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 第三步:转换为整数
|
||||
xStr := strings.TrimSpace(xy[0])
|
||||
yStr := strings.TrimSpace(xy[1])
|
||||
|
||||
x, err := strconv.Atoi(xStr)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
y, err := strconv.Atoi(yStr)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 添加到切片
|
||||
points = append(points, infomodel.Pos{X: uint32(x), Y: uint32(y)})
|
||||
}
|
||||
|
||||
return points
|
||||
}
|
||||
func (t *Space) Next(time.Time) time.Time {
|
||||
|
||||
return time.Now().Add(grand.D(6*time.Second, 30*time.Second))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user