Files
bl/logic/controller/map.go
昔念 5995f0670c
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(game): 实现扭蛋系统批量物品添加功能并优化地图逻辑

- 新增ItemAddBatch方法用于批量添加物品,支持普通道具和特殊道具的分别处理
- 优化扭蛋游戏玩法中的物品添加逻辑,使用新的批量接口提升性能
- 在扭蛋机器人命令中实现完整的物品检查和批量添加流程

refactor(map): 重构地图控制器代码结构并添加注释

- 为EnterMap、LeaveMap、GetMapPlayerList等方法添加中文注释
- 统一地图相关的命名规范,如enter
2026-04-01 20:10:29 +08:00

83 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/modules/player/service"
"sync/atomic"
"time"
"blazing/logic/service/fight"
"blazing/logic/service/maphot"
"blazing/logic/service/space/info"
"blazing/logic/service/player"
"blazing/logic/service/space"
)
// 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 // 更新当前地图ID。
c.Info.Pos = data.Point
if cool.Config.ServerInfo.IsDebug != 0 {
println("enter map", c.Info.UserID, c.Info.MapID)
}
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
}
// 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) // 从当前空间移除玩家。
// 这里不直接清空 MapID由后续进入地图流程接管。
return nil, -1
}
// 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(2021, &c.GetSpace().TimeBoss)
}
c.SendPackCmd(2022, c.GetSpace().GenBoss(true))
return nil, -1
}
// 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)
}
}
return
}