Files
bl/logic/controller/map.go
xinian d83cf365ac
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
更新说明
2026-04-05 23:13:06 +08:00

84 lines
2.5 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 *EnterMapInboundInfo, 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
}
// GetMapHot 处理控制器请求。
func (h Controller) GetMapHot(data *GetMapHotInboundInfo, c *player.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{
HotInfos: space.GetMapHot(),
}
return
}
// LeaveMap 处理玩家离开地图。
func (h Controller) LeaveMap(data *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 *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 *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
}