2025-08-15 22:44:28 +08:00
|
|
|
|
package space
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-30 00:36:08 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
2026-02-20 22:39:04 +08:00
|
|
|
|
"blazing/common/utils"
|
2025-12-09 16:14:47 +00:00
|
|
|
|
"blazing/cool"
|
2026-02-25 19:05:50 +08:00
|
|
|
|
"strconv"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
"time"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/common"
|
2025-12-12 19:10:09 +00:00
|
|
|
|
"blazing/logic/service/space/info"
|
2025-11-15 15:22:58 +08:00
|
|
|
|
|
2026-03-02 23:59:15 +08:00
|
|
|
|
"blazing/modules/config/model"
|
2026-03-01 13:47:56 +08:00
|
|
|
|
"blazing/modules/config/service"
|
2026-02-25 19:05:50 +08:00
|
|
|
|
infomodel "blazing/modules/player/model"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-11-15 15:22:58 +08:00
|
|
|
|
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
2026-02-25 19:05:50 +08:00
|
|
|
|
"github.com/samber/lo"
|
2025-12-09 16:14:47 +00:00
|
|
|
|
"github.com/tnnmigga/enum"
|
2025-08-15 22:44:28 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-12-09 16:14:47 +00:00
|
|
|
|
// 定义天气状态枚举实例
|
|
|
|
|
|
var WeatherStatus = enum.New[struct {
|
|
|
|
|
|
Normal uint32 `enum:"0"` // 正常
|
|
|
|
|
|
Rain uint32 `enum:"1"` // 下雨
|
|
|
|
|
|
Snow uint32 `enum:"2"` // 下雪
|
|
|
|
|
|
}]()
|
|
|
|
|
|
|
2025-08-15 22:44:28 +08:00
|
|
|
|
// Space 针对Player的并发安全map,键为uint32类型
|
|
|
|
|
|
type Space struct {
|
2025-11-15 15:22:58 +08:00
|
|
|
|
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
2026-01-17 00:47:41 +08:00
|
|
|
|
UserInfo *csmap.CsMap[uint32, info.SimpleInfo]
|
2025-11-16 11:56:57 +08:00
|
|
|
|
CanRefresh bool //是否能够刷怪
|
|
|
|
|
|
Super uint32
|
2025-11-25 21:10:52 +08:00
|
|
|
|
//SuperValue *int32
|
2025-12-09 16:52:53 +08:00
|
|
|
|
ID uint32 // 地图ID
|
2025-11-28 00:16:51 +08:00
|
|
|
|
Name string //地图名称
|
|
|
|
|
|
Owner ARENA
|
2026-02-25 19:05:50 +08:00
|
|
|
|
info.MapBossSInfo
|
2026-02-26 13:38:57 +08:00
|
|
|
|
IsChange bool
|
|
|
|
|
|
WeatherType []uint32
|
|
|
|
|
|
TimeBoss info.S2C_2022
|
2026-02-25 19:05:50 +08:00
|
|
|
|
//Weather uint32
|
|
|
|
|
|
IsTime bool
|
2026-03-02 23:59:15 +08:00
|
|
|
|
|
|
|
|
|
|
PitS *csmap.CsMap[int, []model.MapPit]
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewSyncMap 创建一个新的玩家同步map
|
|
|
|
|
|
func NewSpace() *Space {
|
2025-11-17 15:31:23 +00:00
|
|
|
|
|
2025-12-09 14:52:55 +08:00
|
|
|
|
ret := &Space{
|
2026-02-24 00:12:50 +08:00
|
|
|
|
User: csmap.New[uint32, common.PlayerI](),
|
|
|
|
|
|
UserInfo: csmap.New[uint32, info.SimpleInfo](),
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
2025-12-09 14:52:55 +08:00
|
|
|
|
|
|
|
|
|
|
return ret
|
2025-08-15 22:44:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-16 03:36:13 +00:00
|
|
|
|
// 获取星球
|
|
|
|
|
|
func GetSpace(id uint32) *Space {
|
|
|
|
|
|
|
|
|
|
|
|
planet, ok := planetmap.Load(id)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
return planet
|
|
|
|
|
|
}
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret := NewSpace()
|
2026-03-01 13:47:56 +08:00
|
|
|
|
ret.ID = id
|
|
|
|
|
|
defer ret.init()
|
|
|
|
|
|
|
|
|
|
|
|
planetmap.Store(id, ret)
|
|
|
|
|
|
return ret
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2026-03-01 13:47:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
func (ret *Space) init() {
|
|
|
|
|
|
|
|
|
|
|
|
if ret.ID < 10000 { //说明是玩家地图GetSpace
|
2025-08-20 22:34:45 +08:00
|
|
|
|
|
2025-10-10 23:16:45 +08:00
|
|
|
|
for _, v := range xmlres.MapConfig.Maps {
|
2026-03-01 13:47:56 +08:00
|
|
|
|
if v.ID == int(ret.ID) { //找到这个地图
|
2025-11-16 11:56:57 +08:00
|
|
|
|
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.Super = uint32(v.Super)
|
|
|
|
|
|
if ret.Super == 0 {
|
|
|
|
|
|
ret.Super = uint32(v.ID)
|
2025-11-26 01:33:48 +08:00
|
|
|
|
}
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.ID = uint32(v.ID)
|
2026-02-25 19:05:50 +08:00
|
|
|
|
|
2025-12-10 11:59:32 +08:00
|
|
|
|
_, ok := maphot[ret.Super]
|
2025-11-25 21:10:52 +08:00
|
|
|
|
if !ok {
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
2026-03-01 10:44:31 +08:00
|
|
|
|
maphot[ret.Super] = &MapTip{}
|
|
|
|
|
|
maphot[ret.Super].TipInfoS = make(map[uint32]*TipInfo, 0)
|
|
|
|
|
|
}
|
2026-03-02 23:59:15 +08:00
|
|
|
|
|
|
|
|
|
|
tips := &TipInfo{}
|
|
|
|
|
|
r := service.NewMapService().GetData(ret.ID)
|
|
|
|
|
|
if r != nil {
|
|
|
|
|
|
tips.Diao = service.NewMapService().GetData(ret.ID).DropItemIds
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pits := service.NewMapPitService().GetDataALL(ret.ID)
|
|
|
|
|
|
ret.PitS = csmap.New[int, []model.MapPit]()
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range pits {
|
|
|
|
|
|
|
|
|
|
|
|
tips.Pet = append(tips.Pet, v.RefreshID...)
|
|
|
|
|
|
for _, vp := range v.Pos {
|
|
|
|
|
|
t, ok := ret.PitS.Load(vp)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
t = append(t, v)
|
|
|
|
|
|
ret.PitS.Store(vp, t)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ret.PitS.Store(vp, []model.MapPit{v})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-01 11:47:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-01 10:44:31 +08:00
|
|
|
|
}
|
2026-03-02 23:59:15 +08:00
|
|
|
|
|
|
|
|
|
|
tips.Pet = lo.Union(tips.Pet)
|
|
|
|
|
|
tips.Talk = service.NewTalkConfigService().GetTip(ret.ID)
|
|
|
|
|
|
tips.Boss = service.NewMapNodeService().GetTip(ret.ID)
|
|
|
|
|
|
maphot[ret.Super].TipInfoS[ret.ID] = tips
|
|
|
|
|
|
|
2025-12-10 11:59:32 +08:00
|
|
|
|
ret.Name = v.Name
|
2026-03-02 23:59:15 +08:00
|
|
|
|
|
|
|
|
|
|
//ogreconfig := service.NewMapPitService().GetData(ret.ID, uint32(i))
|
2025-11-25 21:10:52 +08:00
|
|
|
|
break
|
2025-10-10 23:16:45 +08:00
|
|
|
|
}
|
2025-08-16 03:36:13 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-09 16:14:47 +00:00
|
|
|
|
|
2026-02-20 22:39:04 +08:00
|
|
|
|
r := service.NewMapService().GetData(ret.ID)
|
|
|
|
|
|
if r != nil {
|
2026-02-25 19:05:50 +08:00
|
|
|
|
|
2026-02-24 00:12:50 +08:00
|
|
|
|
if r.IsTimeSpace != 0 {
|
|
|
|
|
|
ret.IsTime = true
|
|
|
|
|
|
}
|
2026-02-25 19:05:50 +08:00
|
|
|
|
ret.MapBossSInfo = info.MapBossSInfo{}
|
|
|
|
|
|
ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0)
|
2026-02-20 22:39:04 +08:00
|
|
|
|
if len(r.WeatherType) > 1 {
|
2026-02-26 13:38:57 +08:00
|
|
|
|
ret.WeatherType = r.WeatherType
|
2026-02-20 22:39:04 +08:00
|
|
|
|
// ret.CanWeather = 1
|
2026-02-26 13:38:57 +08:00
|
|
|
|
cool.Cron.CustomFunc(ret, ret.GenWer)
|
2026-02-20 22:39:04 +08:00
|
|
|
|
}
|
2026-02-27 11:06:03 +08:00
|
|
|
|
for _, v := range service.NewMapNodeService().GetDataB(ret.ID) {
|
|
|
|
|
|
|
|
|
|
|
|
info := info.MapBossInfo{
|
|
|
|
|
|
Id: v.TriggerID,
|
|
|
|
|
|
Region: v.NodeID, //这个是注册的index
|
|
|
|
|
|
Hp: v.HP,
|
|
|
|
|
|
PosInfo: ParseCoordinateString(v.Pos),
|
|
|
|
|
|
MaxHP: int(v.HP),
|
|
|
|
|
|
Wer: v.Weather,
|
|
|
|
|
|
}
|
2026-02-25 22:47:16 +08:00
|
|
|
|
|
2026-02-27 11:06:03 +08:00
|
|
|
|
ret.MapBossSInfo.INFO = append(ret.MapBossSInfo.INFO, info)
|
2026-02-25 19:05:50 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(ret.MapBossSInfo.INFO) > 0 {
|
2026-02-26 13:38:57 +08:00
|
|
|
|
cool.Cron.ScheduleFunc(10*time.Second, ret.GenBoss)
|
|
|
|
|
|
cool.Cron.ScheduleFunc(300*time.Second, ret.HealHP)
|
2026-02-25 19:05:50 +08:00
|
|
|
|
}
|
2025-12-13 18:35:17 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2026-02-20 22:39:04 +08:00
|
|
|
|
|
2026-02-25 19:05:50 +08:00
|
|
|
|
}
|
2026-02-26 13:38:57 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
}
|