2025-08-20 22:34:45 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/common/socket/errorcode"
|
2025-09-14 01:35:16 +08:00
|
|
|
|
|
2025-10-10 20:46:16 +08:00
|
|
|
|
"blazing/logic/service/common"
|
2025-08-20 22:34:45 +08:00
|
|
|
|
"blazing/logic/service/maphot"
|
|
|
|
|
|
"blazing/logic/service/maps"
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/player"
|
2025-08-20 22:34:45 +08:00
|
|
|
|
"blazing/logic/service/space"
|
2025-08-28 21:35:56 +00:00
|
|
|
|
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
2025-08-20 22:34:45 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-09-14 01:35:16 +08:00
|
|
|
|
func (h *Controller) MapEnter(data *maps.InInfo, c *player.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-08-28 21:35:56 +00:00
|
|
|
|
|
2025-10-10 04:49:23 +00:00
|
|
|
|
c.Info.MapID = data.MapId //登录地图
|
|
|
|
|
|
space.GetSpace(c.Info.MapID).User.Set(c.Info.UserID, c) //添加玩家
|
|
|
|
|
|
|
2025-08-28 21:35:56 +00:00
|
|
|
|
result = maps.NewOutInfo()
|
|
|
|
|
|
c.Info.Pos = data.Point
|
2025-08-30 00:36:08 +08:00
|
|
|
|
copier.Copy(result, c.Info)
|
2025-08-20 22:34:45 +08:00
|
|
|
|
|
2025-08-28 21:35:56 +00:00
|
|
|
|
data.Broadcast(c.Info.MapID, *result) //同步广播
|
2025-08-24 17:33:19 +08:00
|
|
|
|
|
2025-08-20 22:34:45 +08:00
|
|
|
|
return nil, -1
|
|
|
|
|
|
}
|
2025-09-14 01:35:16 +08:00
|
|
|
|
func (h Controller) MapHot(data *maphot.InInfo, c *player.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
|
2025-08-20 22:34:45 +08:00
|
|
|
|
|
|
|
|
|
|
result = &maphot.OutInfo{
|
|
|
|
|
|
|
|
|
|
|
|
HotInfos: space.GetMapHot(),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-09-14 01:35:16 +08:00
|
|
|
|
func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *player.Player) (result *space.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-08-20 22:34:45 +08:00
|
|
|
|
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
|
2025-10-13 18:51:41 +08:00
|
|
|
|
c.Canmon = false
|
|
|
|
|
|
c.Changemap = true //可以刷怪
|
2025-09-14 01:35:16 +08:00
|
|
|
|
data.Broadcast(c.Info.MapID, space.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播
|
2025-10-10 04:49:23 +00:00
|
|
|
|
space.GetSpace(c.Info.MapID).User.Remove(c.Info.UserID)
|
2025-08-23 17:44:12 +08:00
|
|
|
|
// 如果有正在运行的刷怪协程,发送停止信号
|
2025-09-21 08:00:58 +00:00
|
|
|
|
|
2025-08-28 23:23:24 +00:00
|
|
|
|
c.Info.MapID = 0 // 重置当前地图
|
2025-08-20 22:34:45 +08:00
|
|
|
|
return nil, -1
|
|
|
|
|
|
}
|
2025-09-14 01:35:16 +08:00
|
|
|
|
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *player.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-08-20 22:34:45 +08:00
|
|
|
|
|
|
|
|
|
|
result = &maps.ListMapPlayerOutboundInfo{}
|
|
|
|
|
|
result.Player = make([]maps.OutInfo, 0)
|
2025-10-10 20:46:16 +08:00
|
|
|
|
space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
|
2025-08-28 21:35:56 +00:00
|
|
|
|
result1 := maps.NewOutInfo()
|
2025-10-13 23:38:48 +08:00
|
|
|
|
copier.CopyWithOption(result1, player.GetInfo(), copier.Option{DeepCopy: true})
|
2025-08-28 21:35:56 +00:00
|
|
|
|
result.Player = append(result.Player, *result1)
|
2025-11-09 06:50:12 +00:00
|
|
|
|
result.Player = LastFourElements(result.Player)
|
2025-10-10 20:46:16 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2025-09-21 08:00:58 +00:00
|
|
|
|
c.Canmon = true //可以刷怪
|
2025-08-20 22:34:45 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-10-30 01:37:53 +00:00
|
|
|
|
func LastFourElements[T any](s []T) []T {
|
|
|
|
|
|
n := len(s)
|
|
|
|
|
|
if n <= 30 {
|
|
|
|
|
|
// 切片长度小于等于4时,返回整个切片
|
|
|
|
|
|
return s
|
|
|
|
|
|
}
|
|
|
|
|
|
// 切片长度大于4时,返回最后4个元素(从n-4索引到末尾)
|
2025-11-09 06:50:12 +00:00
|
|
|
|
return s[n-30:]
|
|
|
|
|
|
}
|