refactor(controller): 移除未使用的地图相关函数

- 删除了 controller 包中多个与地图相关的 Go 文件
- 移除了未使用的 MapIn、MapHot、MapOut 和 MapList 函数
- 在 space 包中添加了对玩家地图的特殊处理逻辑
This commit is contained in:
2025-08-20 22:34:45 +08:00
parent 10eed9418c
commit 43094c647c
11 changed files with 201 additions and 96 deletions

View File

@@ -0,0 +1,13 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/friend"
)
func (h Controller) OnSeeOnline(data *friend.SeeOnlineInboundInfo, c *entity.Player) (result *friend.SeeOnlineOutboundInfo, err errorcode.ErrorCode) {
result = &friend.SeeOnlineOutboundInfo{}
result.Friends = make([]friend.OnlineInfo, 0)
return
}

View File

@@ -226,7 +226,7 @@ func Recv(c *entity.Conn, data handler.TomeeHeader) {
} }
data.Version = "7" data.Version = "7"
glog.Debug(context.Background(), data.CMD, "回复数据")
c.SendPack(data.Pack(ret[0].Interface())) c.SendPack(data.Pack(ret[0].Interface()))
} }

68
logic/controller/map.go Normal file
View File

@@ -0,0 +1,68 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/common/socket/handler"
"blazing/logic/service/maphot"
"blazing/logic/service/maps"
"blazing/logic/service/space"
"time"
)
func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
c.MapId = data.MapId //登录地图
space.GetSpace(c.MapId).Set(c.UserID, c) //添加玩家
tt := maps.NewOutInfo()
tt.UserID = c.UserID
tt.Nick = c.Nick
tt.Pos = data.Point
data.Broadcast(c.MapId, *tt) //同步广播
go func() { //测试刷怪
for {
tt := handler.NewTomeeHeader()
tt.CMD = 2004
tt.Result = 0
tt.UserID = c.UserID
t1 := maps.OgreInfo{}
for i := 0; i < 9; i++ {
t1.Data[i] = 1
}
c.SendPack(tt.Pack(&t1))
<-time.After(10000 * time.Millisecond)
}
}()
return nil, -1
}
func (h Controller) MapHot(data *maphot.InInfo, c *entity.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{
HotInfos: space.GetMapHot(),
}
return
}
func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *entity.Player) (result *maps.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
data.Broadcast(c.MapId, maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}) //同步广播
space.GetSpace(c.MapId).Delete(c.UserID)
return nil, -1
}
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *entity.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &maps.ListMapPlayerOutboundInfo{}
result.Player = make([]maps.OutInfo, 0)
result1 := maps.NewOutInfo()
result1.UserID = c.UserID
//result.Pos = model.Pos{X: 500, Y: 400}
result1.Nick = c.Nick
result.Player = append(result.Player, *result1)
return
}

View File

@@ -1,40 +0,0 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/common/socket/handler"
"blazing/logic/service/maps"
"blazing/logic/service/space"
"time"
)
func (h *Controller) MapIn(data *maps.InInfo, c *entity.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
c.MapId = data.MapId //登录地图
space.GetSpace(c.MapId).Set(c.UserID, c) //添加玩家
tt := maps.NewOutInfo()
tt.UserID = c.UserID
tt.Nick = c.Nick
tt.Pos = data.Point
data.Broadcast(c.MapId, *tt) //同步广播
go func() { //测试刷怪
for {
tt := handler.NewTomeeHeader()
tt.CMD = 2004
tt.Result = 0
tt.UserID = c.UserID
t1 := maps.OgreInfo{}
for i := 0; i < 9; i++ {
t1.Data[i] = 1
}
c.SendPack(tt.Pack(&t1))
<-time.After(10000 * time.Millisecond)
}
}()
return nil, -1
}

View File

@@ -1,20 +0,0 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/maphot"
"blazing/logic/service/space"
)
func (h Controller) MapHot(data *maphot.InInfo, c *entity.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{
HotInfos: space.GetMapHot(),
}
return
}

View File

@@ -1,15 +0,0 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/maps"
"blazing/logic/service/space"
)
func (h *Controller) MapOut(data *maps.LeaveMapInboundInfo, c *entity.Player) (result *maps.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
data.Broadcast(c.MapId, maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}) //同步广播
space.GetSpace(c.MapId).Delete(c.UserID)
return nil, -1
}

View File

@@ -1,20 +0,0 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/maps"
)
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *entity.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &maps.ListMapPlayerOutboundInfo{}
result.Player = make([]maps.OutInfo, 0)
result1 := maps.NewOutInfo()
result1.UserID = c.UserID
//result.Pos = model.Pos{X: 500, Y: 400}
result1.Nick = c.Nick
result.Player = append(result.Player, *result1)
return
}

32
logic/controller/room.go Normal file
View File

@@ -0,0 +1,32 @@
package controller
import (
"blazing/common/data/entity"
"blazing/common/socket/errorcode"
"blazing/logic/service/room"
)
// 获取基地物品
func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *entity.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
result = &room.FitmentUseringOutboundInfo{UserId: c.GetUserID(), RoomId: data.TargetUserID}
result.Fitments = make([]room.FitmentShowInfo, 0)
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
return
}
// 获取基地展示精灵
func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *entity.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
result = &room.PetRoomListOutboundInfo{}
result.Pets = make([]room.PetShowInfo, 0)
return
}
// 获取自己房间的家具
func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *entity.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) {
result = &room.FitmentAllOutboundInfo{}
result.Fitments = make([]room.FitmentShowInfo, 0)
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
return
}

View File

@@ -0,0 +1,22 @@
package friend
import "blazing/common/socket/handler"
//基地查看好友列表
type SeeOnlineInboundInfo struct {
Head handler.TomeeHeader `cmd:"2157" struc:"[0]pad"`
UserIdsLen uint32 `json:"userIdsLen" struc:"sizeof=UserIds"`
UserIds []uint32 `json:"userIds" `
}
type OnlineInfo struct {
UserId uint32 `json:"userId" `
ServerId uint32 `json:"serverId" `
MapType uint32 `json:"mapType" `
MapId uint32 `json:"mapId" `
}
type SeeOnlineOutboundInfo struct {
FriendsLen uint32 `json:"friendsLen" struc:"sizeof=Friends"`
Friends []OnlineInfo `json:"friends" fieldDescription:"好友在线列表" `
}

View File

@@ -0,0 +1,59 @@
package room
import "blazing/common/socket/handler"
// FitmentShowInfo 表示家具展示信息
type FitmentShowInfo struct {
// 家具id 或 默认房型id: 500001
Id uint32 `json:"id"`
// x坐标
X uint32 `json:"x"`
// y坐标
Y uint32 `json:"y"`
// 默认0
Dir uint32 `json:"dir"`
// 默认0
Status uint32 `json:"status"`
}
// FitmentUseringInboundInfo 对应Java的FitmentUseringInboundInfo类实现InboundMessage接口
type FitmentUseringInboundInfo struct {
Head handler.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录
// 需要获取基地信息的目标玩家账号ID
TargetUserID uint32 `json:"targetUserId"`
}
// FitmentUseringOutboundInfo 对应Java的FitmentUseringOutboundInfo实现OutboundMessage接口
type FitmentUseringOutboundInfo struct {
// 玩家账号ID
UserId uint32 ` json:"userId"`
// 进入基地所有者的userid
RoomId uint32 `codec:"auto" json:"roomId"`
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`
// 基地摆放物品的数组, 就算没有摆放物品, 也必带一个小屋的参数
Fitments []FitmentShowInfo `codec:"auto" json:"fitments"`
}
// PetShowInfo 宠物展示信息
type PetShowInfo struct {
TypeId uint32 // 精灵类型ID
CatchTime uint32 // 精灵生成时间
}
type PetRoomListOutboundInfo struct {
PetsLen uint32 `json:"petsLen" struc:"sizeof=Pets"`
Pets []PetShowInfo `json:"pets"`
}
type PetRoomListInboundInfo struct {
Head handler.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录
// 需要获取基地信息的目标玩家账号ID
TargetUserID uint32 `json:"targetUserId"`
}
type FitmentAllInboundEmpty struct {
Head handler.TomeeHeader `cmd:"10007" struc:"[0]pad"`
}
type FitmentAllOutboundInfo struct {
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`
// 基地摆放物品的数组, 就算没有摆放物品, 也必带一个小屋的参数
Fitments []FitmentShowInfo `codec:"auto" json:"fitments"`
}

View File

@@ -80,6 +80,12 @@ func GetSpace(id uint32) *Space {
return planet return planet
} }
if id > 10000 { //说明是玩家地图GetSpace
t := NewSpace()
planetmap.Store(id, t)
return t
}
//如果不ok,说明星球未创建,那就新建星球 //如果不ok,说明星球未创建,那就新建星球
for _, v := range xml.MapConfig.Maps { for _, v := range xml.MapConfig.Maps {