feat(game): 实现扭蛋系统批量物品添加功能并优化地图逻辑 - 新增ItemAddBatch方法用于批量添加物品,支持普通道具和特殊道具的分别处理 - 优化扭蛋游戏玩法中的物品添加逻辑,使用新的批量接口提升性能 - 在扭蛋机器人命令中实现完整的物品检查和批量添加流程 refactor(map): 重构地图控制器代码结构并添加注释 - 为EnterMap、LeaveMap、GetMapPlayerList等方法添加中文注释 - 统一地图相关的命名规范,如enter
This commit is contained in:
@@ -47,9 +47,8 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
||||
}
|
||||
|
||||
items := service.NewItemService().GetEgg(int(data1.EggNum))
|
||||
for _, item := range items {
|
||||
|
||||
c.ItemAdd(item.ItemId, item.ItemCnt)
|
||||
addedItems := c.ItemAddBatch(items)
|
||||
for _, item := range addedItems {
|
||||
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
|
||||
}
|
||||
|
||||
|
||||
@@ -15,65 +15,63 @@ import (
|
||||
"blazing/logic/service/space"
|
||||
)
|
||||
|
||||
func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info.SimpleInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
// EnterMap 处理玩家进入地图。
|
||||
func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info.SimpleInfo, err errorcode.ErrorCode) {
|
||||
if c.Info.MapID != data.MapId {
|
||||
atomic.StoreUint32(&c.Canmon, 2)
|
||||
c.MapNPC.Reset(6 * time.Second)
|
||||
} else {
|
||||
atomic.StoreUint32(&c.Canmon, 1)
|
||||
}
|
||||
c.Info.MapID = data.MapId //登录地图
|
||||
|
||||
c.Info.MapID = data.MapId // 更新当前地图ID。
|
||||
c.Info.Pos = data.Point
|
||||
|
||||
if cool.Config.ServerInfo.IsDebug != 0 {
|
||||
println("进入地图", c.Info.UserID, c.Info.MapID)
|
||||
println("enter map", c.Info.UserID, c.Info.MapID)
|
||||
}
|
||||
|
||||
// copier.CopyWithOption(result, c.Info, copier.Option{DeepCopy: true})
|
||||
|
||||
c.GetSpace().EnterMap(c)
|
||||
if data.MapId > 10000 && data.MapId != c.Info.UserID {
|
||||
|
||||
c.Service.Done.UpdateRoom(1, 0)
|
||||
service.NewDoneService(data.MapId).UpdateRoom(0, 1)
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
func (h Controller) GetMapHot(data *maphot.InInfo, c *player.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
|
||||
|
||||
result = &maphot.OutInfo{
|
||||
|
||||
HotInfos: space.GetMapHot(),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
func (h Controller) LeaveMap(data *space.LeaveMapInboundInfo, c *player.Player) (result *info.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
// LeaveMap 处理玩家离开地图。
|
||||
func (h Controller) LeaveMap(data *space.LeaveMapInboundInfo, c *player.Player) (result *info.LeaveMapOutboundInfo, err errorcode.ErrorCode) {
|
||||
atomic.StoreUint32(&c.Canmon, 0)
|
||||
|
||||
c.GetSpace().LeaveMap(c) //玩家离开地图
|
||||
c.GetSpace().LeaveMap(c) // 从当前空间移除玩家。
|
||||
|
||||
// 如果有正在运行的刷怪协程,发送停止信号
|
||||
|
||||
//c.Info.MapID = 0 // 重置当前地图
|
||||
// 这里不直接清空 MapID,由后续进入地图流程接管。
|
||||
return nil, -1
|
||||
}
|
||||
func (h Controller) GetMapPlayerList(data *space.ListMapPlayerInboundInfo, c *player.Player) (result *info.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
// GetMapPlayerList 获取当前地图内的玩家列表与地图广播信息。
|
||||
func (h Controller) GetMapPlayerList(data *space.ListMapPlayerInboundInfo, c *player.Player) (result *info.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &info.ListMapPlayerOutboundInfo{
|
||||
Player: c.GetSpace().GetInfo(c),
|
||||
}
|
||||
c.SendPackCmd(2003, result)
|
||||
if atomic.LoadUint32(&c.GetSpace().TimeBoss.Flag) == 1 {
|
||||
c.SendPackCmd(2022, &c.GetSpace().TimeBoss)
|
||||
c.SendPackCmd(2021, &c.GetSpace().TimeBoss)
|
||||
}
|
||||
c.SendPackCmd(2021, c.GetSpace().GenBoss(true))
|
||||
c.SendPackCmd(2022, c.GetSpace().GenBoss(true))
|
||||
|
||||
return nil, -1
|
||||
}
|
||||
func (h Controller) AttackBoss(data *space.AttackBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||||
|
||||
// AttackBoss 调试扣减当前地图广播BOSS血量。
|
||||
func (h Controller) AttackBoss(data *space.AttackBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
for i := 0; i < len(c.GetSpace().MapBossSInfo.INFO); i++ {
|
||||
if atomic.LoadInt32(&c.GetSpace().MapBossSInfo.INFO[i].Hp) > 0 {
|
||||
atomic.AddInt32(&c.GetSpace().MapBossSInfo.INFO[i].Hp, -1)
|
||||
|
||||
@@ -205,6 +205,114 @@ func (p *Player) SendPack(b []byte) error {
|
||||
}
|
||||
|
||||
// 添加物品 返回成功添加的物品
|
||||
// ItemAddBatch 批量添加物品,普通道具先按 ItemAdd 的规则校验上限,再批量落库。
|
||||
func (p *Player) ItemAddBatch(items []data.ItemInfo) []data.ItemInfo {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sendErr := func(code errorcode.ErrorCode) {
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(code)
|
||||
p.SendPack(t1.Pack(nil))
|
||||
}
|
||||
|
||||
var (
|
||||
regularItems = make([]data.ItemInfo, 0, len(items))
|
||||
regularIndexes = make([]int, 0, len(items))
|
||||
itemIDs = make([]uint32, 0, len(items))
|
||||
seenIDs = make(map[uint32]struct{}, len(items))
|
||||
specialSuccess = make(map[int]bool, len(items))
|
||||
)
|
||||
|
||||
for idx, item := range items {
|
||||
if item.ItemCnt <= 0 {
|
||||
sendErr(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
continue
|
||||
}
|
||||
|
||||
switch item.ItemId {
|
||||
case 1, 3, 5, 9:
|
||||
if p.ItemAdd(item.ItemId, item.ItemCnt) {
|
||||
specialSuccess[idx] = true
|
||||
}
|
||||
default:
|
||||
regularItems = append(regularItems, item)
|
||||
regularIndexes = append(regularIndexes, idx)
|
||||
|
||||
itemID := uint32(item.ItemId)
|
||||
if _, ok := seenIDs[itemID]; ok {
|
||||
continue
|
||||
}
|
||||
seenIDs[itemID] = struct{}{}
|
||||
itemIDs = append(itemIDs, itemID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(regularItems) == 0 {
|
||||
result := make([]data.ItemInfo, 0, len(items))
|
||||
for idx, item := range items {
|
||||
if specialSuccess[idx] {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
currentItems := p.Service.Item.CheakItemM(itemIDs...)
|
||||
currentMap := make(map[uint32]int64, len(currentItems))
|
||||
for _, item := range currentItems {
|
||||
currentMap[item.ItemId] = item.ItemCnt
|
||||
}
|
||||
maxMap := dictrvice.NewDictInfoService().GetMaxMap(itemIDs...)
|
||||
|
||||
batchItems := make([]data.ItemInfo, 0, len(regularItems))
|
||||
pendingMap := make(map[uint32]int64, len(itemIDs))
|
||||
for _, item := range regularItems {
|
||||
itemID := uint32(item.ItemId)
|
||||
itemmax := maxMap[itemID]
|
||||
if itemmax == 0 {
|
||||
cool.Logger.Error(context.TODO(), "物品不存在", p.Info.UserID, item.ItemId)
|
||||
sendErr(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
continue
|
||||
}
|
||||
|
||||
if currentMap[itemID]+pendingMap[itemID]+item.ItemCnt > int64(itemmax) {
|
||||
println(p.Info.UserID, "物品超过拥有最大限制", item.ItemId)
|
||||
sendErr(errorcode.ErrorCodes.ErrTooManyOfItem)
|
||||
continue
|
||||
}
|
||||
|
||||
pendingMap[itemID] += item.ItemCnt
|
||||
batchItems = append(batchItems, item)
|
||||
}
|
||||
|
||||
addedRegularItems, err := p.Service.Item.AddItemsChecked(batchItems, currentMap)
|
||||
if err != nil {
|
||||
sendErr(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
return nil
|
||||
}
|
||||
|
||||
regularSuccess := make(map[int]bool, len(addedRegularItems))
|
||||
regularPos := 0
|
||||
for idx, item := range regularItems {
|
||||
if regularPos < len(addedRegularItems) &&
|
||||
addedRegularItems[regularPos].ItemId == item.ItemId &&
|
||||
addedRegularItems[regularPos].ItemCnt == item.ItemCnt {
|
||||
regularSuccess[regularIndexes[idx]] = true
|
||||
regularPos++
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]data.ItemInfo, 0, len(items))
|
||||
for idx, item := range items {
|
||||
if specialSuccess[idx] || regularSuccess[idx] {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (p *Player) ItemAdd(ItemId, ItemCnt int64) (result bool) {
|
||||
if ItemCnt <= 0 {
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
|
||||
@@ -10,94 +10,83 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ========== 1. 定义TimeBoss的定时规则(补全周四-周六,新增周日规则) ==========
|
||||
// TimeBossRule 单个BOSS的定时规则
|
||||
// TimeBossRule describes one timed boss spawn rule.
|
||||
type TimeBossRule struct {
|
||||
PetID uint32 // BOSS ID(对应XML的petID="261")
|
||||
Week int // 星期(1=周一,2=周二...7=周日)
|
||||
ShowHours []int // 出现小时(如12,17,18,24);周日填0-23表示每小时
|
||||
ShowMinute int // 出现分钟(如35,0)
|
||||
LastTime int // 持续时间(分钟)
|
||||
MapIDs []uint32 // 可选刷新地图ID列表(随机选一个)
|
||||
PetID uint32
|
||||
Week int
|
||||
ShowHours []int
|
||||
ShowMinute int
|
||||
LastTime int
|
||||
MapIDs []uint32
|
||||
}
|
||||
|
||||
// 全局:261号BOSS的规则配置(补全周四-周六,新增周日)
|
||||
// Timed boss schedule config.
|
||||
var timeBossRules = []TimeBossRule{
|
||||
// 周一规则
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 1, // 周一
|
||||
ShowHours: []int{12, 17, 18, 24}, // 12|17|18|24点35分
|
||||
ShowMinute: 35, // 35分
|
||||
LastTime: 40, // 持续40分钟
|
||||
MapIDs: []uint32{15, 105, 54}, // 随机选一个地图
|
||||
},
|
||||
|
||||
// 周二规则
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 2, // 周二
|
||||
ShowHours: []int{17, 18, 24}, // 17|18|24点0分
|
||||
ShowMinute: 0, // 0分
|
||||
LastTime: 5, // 持续5分钟
|
||||
Week: 1,
|
||||
ShowHours: []int{12, 17, 18, 24},
|
||||
ShowMinute: 35,
|
||||
LastTime: 40,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
// 周三规则
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 3, // 周三
|
||||
ShowHours: []int{17, 18, 24}, // 17|18|24点0分
|
||||
ShowMinute: 0, // 0分
|
||||
LastTime: 5, // 持续5分钟
|
||||
Week: 2,
|
||||
ShowHours: []int{17, 18, 24},
|
||||
ShowMinute: 0,
|
||||
LastTime: 5,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
// 周四规则(和周一完全一致)
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 4, // 周四
|
||||
ShowHours: []int{12, 17, 18, 24}, // 12|17|18|24点35分
|
||||
ShowMinute: 35, // 35分
|
||||
LastTime: 40, // 持续40分钟
|
||||
Week: 3,
|
||||
ShowHours: []int{17, 18, 24},
|
||||
ShowMinute: 0,
|
||||
LastTime: 5,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
// 周五规则(和周二完全一致)
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 5, // 周五
|
||||
ShowHours: []int{17, 18, 24}, // 17|18|24点0分
|
||||
ShowMinute: 0, // 0分
|
||||
LastTime: 5, // 持续5分钟
|
||||
Week: 4,
|
||||
ShowHours: []int{12, 17, 18, 24},
|
||||
ShowMinute: 35,
|
||||
LastTime: 40,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
// 周六规则(和周三完全一致)
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 6, // 周六
|
||||
ShowHours: []int{17, 18, 24}, // 17|18|24点0分
|
||||
ShowMinute: 0, // 0分
|
||||
LastTime: 5, // 持续5分钟
|
||||
Week: 5,
|
||||
ShowHours: []int{17, 18, 24},
|
||||
ShowMinute: 0,
|
||||
LastTime: 5,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
// 周日规则(特殊:每小时刷新,持续10分钟)
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 7, // 周日
|
||||
ShowHours: generateHourRange(0, 23), // 0-23点(每小时)
|
||||
ShowMinute: 0, // 每小时0分触发
|
||||
LastTime: 10, // 持续10分钟
|
||||
MapIDs: []uint32{15, 105, 54}, // 随机选一个地图
|
||||
Week: 6,
|
||||
ShowHours: []int{17, 18, 24},
|
||||
ShowMinute: 0,
|
||||
LastTime: 5,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
{
|
||||
PetID: 261,
|
||||
Week: 7,
|
||||
ShowHours: generateHourRange(0, 23),
|
||||
ShowMinute: 0,
|
||||
LastTime: 10,
|
||||
MapIDs: []uint32{15, 105, 54},
|
||||
},
|
||||
}
|
||||
|
||||
// ========== 2. 全局变量(无修改,新增随机数生成器已存在) ==========
|
||||
var (
|
||||
registeredCronIDs = make(map[string]bool) // 记录已注册的Cron任务ID
|
||||
cronMu sync.Mutex // 保护registeredCronIDs的互斥锁
|
||||
randSource = rand.New(rand.NewSource(time.Now().UnixNano())) // 安全的随机数生成器
|
||||
registeredCronIDs = make(map[string]bool)
|
||||
cronMu sync.Mutex
|
||||
randSource = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
)
|
||||
|
||||
// ========== 3. 工具函数:生成0-23小时数组(适配周日每小时规则) ==========
|
||||
// generateHourRange 生成从start到end的连续小时数组(如0-23)
|
||||
// generateHourRange builds an inclusive hour range.
|
||||
func generateHourRange(start, end int) []int {
|
||||
hours := make([]int, 0, end-start+1)
|
||||
for i := start; i <= end; i++ {
|
||||
@@ -106,57 +95,41 @@ func generateHourRange(start, end int) []int {
|
||||
return hours
|
||||
}
|
||||
|
||||
// ========== 4. 原有方法:gettimeboss(无修改,自动适配新规则) ==========
|
||||
func init() { // 忽略传入的mapid,随机选地图
|
||||
|
||||
// 遍历所有TimeBoss规则(包含周四-周六-周日)
|
||||
func init() {
|
||||
for _, rule := range timeBossRules {
|
||||
|
||||
// 为该规则的每个小时生成Cron任务
|
||||
for _, hour := range rule.ShowHours {
|
||||
// 生成唯一Cron任务ID(避免重复注册)
|
||||
cronID := genCronTaskID(rule.PetID, rule.Week, hour, rule.ShowMinute)
|
||||
cronMu.Lock()
|
||||
if registeredCronIDs[cronID] {
|
||||
cronMu.Unlock()
|
||||
continue // 已注册过,跳过
|
||||
continue
|
||||
}
|
||||
registeredCronIDs[cronID] = true
|
||||
cronMu.Unlock()
|
||||
|
||||
// 转换规则为Cron表达式
|
||||
cronExpr := genCronExpr(rule.Week, hour, rule.ShowMinute)
|
||||
|
||||
// 捕获当前循环的rule(避免闭包引用同一变量)
|
||||
currentRule := rule
|
||||
|
||||
// 注册Cron定时任务
|
||||
cool.Cron.AddFunc(cronExpr, func() {
|
||||
// 1. 随机选一个地图ID
|
||||
randomMapID := getRandomMapID(currentRule.MapIDs)
|
||||
if randomMapID == 0 {
|
||||
return // 无可用地图,跳过
|
||||
return
|
||||
}
|
||||
|
||||
sp := GetSpace(randomMapID)
|
||||
if sp != nil {
|
||||
// 2. 显示BOSS(指定随机地图广播)
|
||||
sp.refushgaiya(true)
|
||||
|
||||
// 3. 启动定时器:持续时间到后隐藏BOSS(同样指定地图)
|
||||
time.AfterFunc(time.Duration(currentRule.LastTime)*time.Minute, func() {
|
||||
sp.refushgaiya(false)
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 5. 修改后的refushgaiya(指定地图广播) ==========
|
||||
// refushgaiya updates timed boss visibility and broadcasts it.
|
||||
func (s *Space) refushgaiya(vis bool) {
|
||||
|
||||
if !vis {
|
||||
atomic.StoreUint32(&s.TimeBoss.Flag, 0)
|
||||
} else {
|
||||
@@ -164,13 +137,10 @@ func (s *Space) refushgaiya(vis bool) {
|
||||
}
|
||||
atomic.StoreUint32(&s.TimeBoss.ID, 261)
|
||||
|
||||
// 只向指定地图广播(核心:不再全局广播)
|
||||
s.Broadcast(nil, 2022, &s.TimeBoss)
|
||||
|
||||
s.Broadcast(nil, 2021, &s.TimeBoss)
|
||||
}
|
||||
|
||||
// ========== 6. 工具函数(无修改,自动适配周日规则) ==========
|
||||
// getRandomMapID 从地图列表中随机选一个
|
||||
// getRandomMapID picks one random map id from candidates.
|
||||
func getRandomMapID(mapIDs []uint32) uint32 {
|
||||
if len(mapIDs) == 0 {
|
||||
return 0
|
||||
@@ -178,32 +148,29 @@ func getRandomMapID(mapIDs []uint32) uint32 {
|
||||
return mapIDs[randSource.Intn(len(mapIDs))]
|
||||
}
|
||||
|
||||
// genCronExpr 生成Cron表达式(自动适配周日的0值)
|
||||
// genCronExpr builds a Quartz-style cron expression.
|
||||
func genCronExpr(week, hour, minute int) string {
|
||||
// 1. 处理小时:24点转为0点(Cron小时范围0-23)
|
||||
cronHour := hour
|
||||
if cronHour == 24 {
|
||||
cronHour = 0
|
||||
}
|
||||
|
||||
// 2. 处理星期:XML的7=周日 → Cron的0=周日,其余直接用
|
||||
cronWeek := week
|
||||
if cronWeek == 7 {
|
||||
cronWeek = 0
|
||||
}
|
||||
|
||||
// 3. 生成Cron表达式(秒 分 时 日 月 周)
|
||||
return strings.Join([]string{
|
||||
"0", // 秒(固定0,整分触发)
|
||||
strconv.Itoa(minute), // 分
|
||||
strconv.Itoa(cronHour), // 时
|
||||
"?", // 日(不指定)
|
||||
"*", // 月(每月)
|
||||
strconv.Itoa(cronWeek), // 周
|
||||
"0",
|
||||
strconv.Itoa(minute),
|
||||
strconv.Itoa(cronHour),
|
||||
"?",
|
||||
"*",
|
||||
strconv.Itoa(cronWeek),
|
||||
}, " ")
|
||||
}
|
||||
|
||||
// genCronTaskID 生成唯一的Cron任务ID
|
||||
// genCronTaskID builds a unique task id for dedupe.
|
||||
func genCronTaskID(petID uint32, week, hour, minute int) string {
|
||||
return strings.Join([]string{
|
||||
strconv.FormatUint(uint64(petID), 10),
|
||||
@@ -213,7 +180,7 @@ func genCronTaskID(petID uint32, week, hour, minute int) string {
|
||||
}, "_")
|
||||
}
|
||||
|
||||
// containsMapID 检查mapid是否在列表中(备用)
|
||||
// containsMapID checks whether a map id exists in the list.
|
||||
func containsMapID(mapIDs []uint32, mapid uint32) bool {
|
||||
for _, id := range mapIDs {
|
||||
if id == mapid {
|
||||
|
||||
@@ -22,34 +22,31 @@ import (
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
// 定义天气状态枚举实例
|
||||
var WeatherStatus = enum.New[struct {
|
||||
Normal uint32 `enum:"0"` // 正常
|
||||
Rain uint32 `enum:"1"` // 下雨
|
||||
Snow uint32 `enum:"2"` // 下雪
|
||||
Normal uint32 `enum:"0"`
|
||||
Rain uint32 `enum:"1"`
|
||||
Snow uint32 `enum:"2"`
|
||||
}]()
|
||||
|
||||
// Space 针对Player的并发安全map,键为uint32类型
|
||||
type Space struct {
|
||||
User *csmap.CsMap[uint32, common.PlayerI] // 存储玩家数据的map,键为玩家ID
|
||||
User *csmap.CsMap[uint32, common.PlayerI]
|
||||
UserInfo *csmap.CsMap[uint32, info.SimpleInfo]
|
||||
CanRefresh bool //是否能够刷怪
|
||||
CanRefresh bool
|
||||
Super uint32
|
||||
//SuperValue *int32
|
||||
ID uint32 // 地图ID
|
||||
Name string //地图名称
|
||||
|
||||
ID uint32
|
||||
Name string
|
||||
Owner ARENA
|
||||
info.MapBossSInfo
|
||||
//IsChange bool
|
||||
|
||||
WeatherType []uint32
|
||||
TimeBoss info.S2C_2022
|
||||
//Weather uint32
|
||||
|
||||
IsTime bool
|
||||
DropItemIds []uint32
|
||||
PitS *csmap.CsMap[int, []model.MapPit]
|
||||
}
|
||||
|
||||
// NewSyncMap 创建一个新的玩家同步map
|
||||
func NewSpace() *Space {
|
||||
|
||||
ret := &Space{
|
||||
@@ -60,7 +57,6 @@ func NewSpace() *Space {
|
||||
return ret
|
||||
}
|
||||
|
||||
// 获取星球
|
||||
func GetSpace(id uint32) *Space {
|
||||
|
||||
planet, ok := planetmap.Load(id)
|
||||
@@ -78,30 +74,26 @@ 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])
|
||||
|
||||
@@ -115,7 +107,6 @@ func ParseCoordinateString(s string) []infomodel.Pos {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 添加到切片
|
||||
points = append(points, infomodel.Pos{X: uint32(x), Y: uint32(y)})
|
||||
}
|
||||
|
||||
@@ -128,10 +119,10 @@ func (t *Space) Next(time.Time) time.Time {
|
||||
}
|
||||
func (ret *Space) init() {
|
||||
|
||||
if ret.ID < 10000 { //说明是玩家地图GetSpace
|
||||
if ret.ID < 10000 {
|
||||
|
||||
for _, v := range xmlres.MapConfig.Maps {
|
||||
if v.ID == int(ret.ID) { //找到这个地图
|
||||
if v.ID == int(ret.ID) {
|
||||
|
||||
ret.Super = uint32(v.Super)
|
||||
if ret.Super == 0 {
|
||||
@@ -148,7 +139,6 @@ func (ret *Space) init() {
|
||||
|
||||
ret.Name = v.Name
|
||||
|
||||
//ogreconfig := service.NewMapPitService().GetData(ret.ID, uint32(i))
|
||||
break
|
||||
}
|
||||
|
||||
@@ -197,7 +187,7 @@ func (ret *Space) init() {
|
||||
ret.MapBossSInfo.INFO = make([]info.MapBossInfo, 0)
|
||||
if len(r.WeatherType) > 1 {
|
||||
ret.WeatherType = r.WeatherType
|
||||
// ret.CanWeather = 1
|
||||
|
||||
cool.Cron.CustomFunc(ret, ret.GenWer)
|
||||
}
|
||||
for _, v := range service.NewMapNodeService().GetDataB(ret.ID) {
|
||||
@@ -208,7 +198,7 @@ func (ret *Space) init() {
|
||||
}
|
||||
info := info.MapBossInfo{
|
||||
Id: uint32(r.ID),
|
||||
Region: v.NodeID, //这个是注册的index
|
||||
Region: v.NodeID,
|
||||
Hp: r.HP,
|
||||
PosInfo: ParseCoordinateString(r.Pos),
|
||||
Config: v,
|
||||
@@ -235,7 +225,7 @@ func (p *Space) IsMatch(t model.Event) bool {
|
||||
return item == int32(p.MapBossSInfo.Wer)
|
||||
})
|
||||
if !ok {
|
||||
// 不在同一天气下
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
@@ -285,7 +275,6 @@ func (ret *Space) HealHP() {
|
||||
}
|
||||
func (ret *Space) GenWer() {
|
||||
|
||||
//if ret.CanWeather == 1 {
|
||||
var neww uint32 = 0
|
||||
|
||||
if len(ret.WeatherType) == 2 {
|
||||
@@ -298,13 +287,11 @@ func (ret *Space) GenWer() {
|
||||
|
||||
ret.MapBossSInfo.Wer = int32(neww)
|
||||
|
||||
ret.Broadcast(nil, 2021, ret.GenBoss(true))
|
||||
ret.Broadcast(nil, 2022, ret.GenBoss(true))
|
||||
println(ret.Name, "change weather", neww)
|
||||
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
func (ret *Space) GetDrop() int64 {
|
||||
|
||||
Reference in New Issue
Block a user