feat(room): 移除旧版房间控制器逻辑并重构家具展示信息结构

移除了 logic/controller/room.go 中已废弃的房间相关控制器方法,包括获取基地物品、展示精灵及房间家具的方法。同时,在 logic/service/room/FitmentShowInfo.go 中对家具展示信息结构进行了重构,引入了 model.FitmentShowInfo 并新增 SET_FITMENT 和 NullInfo 结构体以支持新的数据协议。另外,在 pet.go 中增加 PetInfo_One_ohter 方法用于查询指定用户的宠物信息,并在 user.go 中为 UserService 添加 RoomService 支持。
This commit is contained in:
2025-12-13 22:51:39 +08:00
parent fe89620efb
commit d198e7446a
11 changed files with 329 additions and 18 deletions

View File

@@ -0,0 +1,27 @@
package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/player"
"blazing/logic/service/room"
)
// 购买家具
func (h Controller) BUY_FITMENT(data *room.C2S_BUY_FITMENT, c *player.Player) (result *room.S2C_BUY_FITMENT, err errorcode.ErrorCode) {
result = &room.S2C_BUY_FITMENT{}
used := xmlres.ItemsMAP[int(data.ID)].Price * int(data.Count)
if !c.UseCoins(uint32(used)) {
return nil, errorcode.ErrorCodes.ErrPurchaseFailed
}
c.Service.Room.Add(data.ID, data.Count)
c.Info.Coins -= uint32(used)
result.ID = data.ID
result.Coins = c.Info.Coins
return
}

View File

@@ -2,6 +2,7 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/modules/blazing/model"
"blazing/logic/service/player" "blazing/logic/service/player"
"blazing/logic/service/room" "blazing/logic/service/room"
@@ -11,8 +12,11 @@ import (
func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *player.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *player.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID} result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID}
result.Fitments = make([]room.FitmentShowInfo, 0) result.Fitments = make([]model.FitmentShowInfo, 0)
result.Fitments = append(result.Fitments, room.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1}) result.Fitments = append(result.Fitments, model.FitmentShowInfo{Id: 500001, Status: 1, X: 1, Y: 1, Dir: 1})
r := c.Service.Room.Get(data.TargetUserID)
result.Fitments = append(result.Fitments, r.PlacedItems...)
return return
} }
@@ -21,6 +25,16 @@ func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *pl
func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
result = &room.PetRoomListOutboundInfo{} result = &room.PetRoomListOutboundInfo{}
result.Pets = make([]room.PetShowInfo, 0) result.Pets = make([]room.PetShowInfo, 0)
r := c.Service.Room.Get(data.TargetUserID)
for _, v := range r.ShowPokemon {
pet := c.Service.Pet.PetInfo_One_ohter(data.TargetUserID, v)
if pet.Data.ID == 0 {
continue
}
result.Pets = append(result.Pets, room.PetShowInfo{CatchTime: v, TypeId: pet.Data.ID})
}
return return
} }
@@ -29,5 +43,12 @@ func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *player
result = &room.FitmentAllOutboundInfo{} result = &room.FitmentAllOutboundInfo{}
result.Fitments = make([]room.FitmentItemInfo, 0) result.Fitments = make([]room.FitmentItemInfo, 0)
r := c.Service.Room.Get(c.Info.UserID)
for k, v := range r.OwnedItems {
result.Fitments = append(result.Fitments, room.FitmentItemInfo{Id: k, AllCount: v, UsedCount: r.UserItems[k]})
}
return return
} }

View File

@@ -0,0 +1,34 @@
package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/logic/service/room"
"github.com/jinzhu/copier"
)
// 基地设置
func (h Controller) SET_FITMENT(data *room.SET_FITMENT, c *player.Player) (result *room.NullInfo, err errorcode.ErrorCode) {
c.Service.Room.Set(data.Fitments)
return
}
func (h Controller) SET_Pet(data *room.C2S_PetShowList, c *player.Player) (result *room.S2C_PET_ROOM_SHOW, err errorcode.ErrorCode) {
c.Service.Room.Show(data.CatchTime)
result = &room.S2C_PET_ROOM_SHOW{}
r := c.Service.Room.Get(c.Info.UserID)
result.PetShowList = make([]pet.PetShortInfo, len(r.ShowPokemon))
for _, v := range r.ShowPokemon {
r1 := c.Service.Pet.PetInfo_One(v)
var r12 pet.PetShortInfo
copier.Copy(&r12, &r1)
result.PetShowList = append(result.PetShowList, r12)
}
return
}

View File

@@ -1,20 +1,9 @@
package room package room
import "blazing/logic/service/common" import (
"blazing/logic/service/common"
// FitmentShowInfo 表示家具展示信息 "blazing/modules/blazing/model"
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 FitmentUseringInboundInfo类实现InboundMessage接口 // FitmentUseringInboundInfo FitmentUseringInboundInfo类实现InboundMessage接口
type FitmentUseringInboundInfo struct { type FitmentUseringInboundInfo struct {
@@ -22,6 +11,16 @@ type FitmentUseringInboundInfo struct {
// 需要获取基地信息的目标玩家账号ID // 需要获取基地信息的目标玩家账号ID
TargetUserID uint32 `json:"targetUserId"` TargetUserID uint32 `json:"targetUserId"`
} }
type SET_FITMENT struct {
// RoomID 房间ID
// 特殊规则怀旧服官服固定为1新服与用户IDuserid相同
RoomID uint32 `json:"roomID"`
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`
// UsedList 已摆放家具列表
// 包含家具ID、坐标且内嵌房间小屋ID其中小屋的坐标PosX/PosY固定为0
Fitments []model.FitmentShowInfo `json:"usedList"`
}
// FitmentUseringOutboundInfo FitmentUseringOutboundInfo实现OutboundMessage接口 // FitmentUseringOutboundInfo FitmentUseringOutboundInfo实现OutboundMessage接口
type FitmentUseringOutboundInfo struct { type FitmentUseringOutboundInfo struct {
@@ -31,7 +30,7 @@ type FitmentUseringOutboundInfo struct {
RoomId uint32 `codec:"auto" json:"roomId"` RoomId uint32 `codec:"auto" json:"roomId"`
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"` FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`
// 基地摆放物品的数组, 就算没有摆放物品, 也必带一个小屋的参数 // 基地摆放物品的数组, 就算没有摆放物品, 也必带一个小屋的参数
Fitments []FitmentShowInfo `codec:"auto" json:"fitments"` Fitments []model.FitmentShowInfo `codec:"auto" json:"fitments"`
} }
// PetShowInfo 宠物展示信息 // PetShowInfo 宠物展示信息
@@ -69,3 +68,6 @@ type FitmentItemInfo struct {
// AllCount 拥有数量默认房型id项目的拥有数量固定为1 // AllCount 拥有数量默认房型id项目的拥有数量固定为1
AllCount uint32 `json:"allCount"` AllCount uint32 `json:"allCount"`
} }
type NullInfo struct {
}

22
logic/service/room/buy.go Normal file
View File

@@ -0,0 +1,22 @@
package room
import "blazing/logic/service/common"
// C2S_BUY_FITMENT 客户端(前端)向服务端(后端)发送的「购买家具」请求结构体
// 对应前端定义的 C2S_BUY_FITMENT 结构体
type C2S_BUY_FITMENT struct {
Head common.TomeeHeader `cmd:"10004" struc:"skip"` //玩家登录
// ID 家具ID对应前端 id 字段)
ID uint32 `json:"id"` // JSON序列化tag保证与前端字段名一致
// Count 购买数量(对应前端 count 字段)
Count uint32 `json:"count"`
}
type S2C_BUY_FITMENT struct {
// Coins 购买后剩余的赛尔豆(对应前端 coins 字段)
Coins uint32 `json:"coins"`
// ID 购买的物品ID对应前端 id 字段即家具ID
ID uint32 `json:"id"`
// Count 字段说明前端未调用该参数推测为购买数量与C2S的count对应
// 若后续确认无业务意义,可标注为废弃(如 `// Deprecated: 前端未使用,暂保留字段`
Count uint32 `json:"count"`
}

Binary file not shown.

34
logic/service/room/pet.go Normal file
View File

@@ -0,0 +1,34 @@
package room
import (
"blazing/logic/service/common"
"blazing/logic/service/pet"
)
type C2S_PetShowList struct {
// CatchTime 展示精灵的捕获时间Unix时间戳/自定义时间格式,按前端规则)
CatchTime uint32 `json:"catchTime"` // C# uint → Go uint32严格匹配32位无符号整数
// PetID 展示精灵的唯一ID
PetID uint32 `json:"petID"`
}
// C2S_PET_ROOM_SHOW 客户端→服务端的「精灵房间展示」请求结构体
// 对应前端 C2S_PET_ROOM_SHOW 结构体
type C2S_PET_ROOM_SHOW struct {
Head common.TomeeHeader `cmd:"2323" struc:"skip"` //玩家登录
PetShowInfoLen uint32 `json:"PetShowInfoLen" struc:"sizeof=PetShowList"`
// PetShowList 整个展示精灵的数组
// 业务规则展示1只精灵对应数组1个元素展示多只时所有已展示精灵的结构体均包含在内
// 数据来源前端展示精灵的map数组直接转换而来
PetShowList []C2S_PetShowList `json:"PetShowList"`
}
// S2C_PET_ROOM_SHOW 服务端→客户端的「精灵房间展示」响应结构体
// 对应前端 S2C_PET_ROOM_SHOW 结构体
type S2C_PET_ROOM_SHOW struct {
// PetShowList 整个展示精灵的数组
PetShowListLen uint32 `json:"PetShowListLen" struc:"sizeof=PetShowList"`
// 数组内每个元素为 S2C_PetShowList字段顺序petID → catchTime
PetShowList []pet.PetShortInfo `json:"PetShowList"`
}

View File

@@ -0,0 +1,71 @@
package model
import (
"blazing/cool"
)
// 基地房型表名
const TableNameBaseHouse = "base_house"
// NewBaseHouse 构造函数:创建基地房型实例
func NewBaseHouse() *BaseHouse {
return &BaseHouse{
Model: cool.NewModel(),
}
}
// BaseHouse 基地房型核心结构体
// 包含:基地展示精灵、基地拥有物品、基地摆放物品三大核心字段
type BaseHouse struct {
*cool.Model // 继承基础Model包含ID、创建时间、更新时间等通用字段
// 基础关联字段
PlayerID uint64 `gorm:"not null;index:idx_player_house;comment:'所属玩家ID'" json:"player_id"`
// 核心业务字段
// ShowPokemon 基地展示精灵ID列表支持展示多个精灵
ShowPokemon []uint32 `gorm:"type:json;not null;default:'[]';comment:'基地展示精灵ID列表'" json:"show_pokemon"`
// OwnedItems 基地拥有物品key=物品IDvalue=物品数量JSON格式存储
OwnedItems string `gorm:"type:json;not null;default:'{}';comment:'基地拥有物品物品ID:数量)'" json:"owned_items"`
UserItems string `gorm:"type:json;not null;default:'{}';comment:'用户物品列表物品ID:数量)'" json:"user_items"`
// PlacedItems 基地摆放物品包含物品ID、摆放坐标、朝向等信息
PlacedItems string `gorm:"type:json;not null;default:'[]';comment:'基地摆放物品列表(含位置/朝向)'" json:"placed_items"`
}
func (*BaseHouse) TableName() string {
return TableNameBaseHouse
}
type BaseHouseEx struct {
BaseHouse
PlacedItems []FitmentShowInfo `json:"placed_items"`
OwnedItems map[uint32]uint32 `json:"owned_items"`
UserItems map[uint32]uint32 `json:"user_items"`
}
// 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"`
}
// UpdateShowPokemon 更新基地展示精灵列表
func (bh *BaseHouse) UpdateShowPokemon(pokemonIDs []uint32) {
bh.ShowPokemon = pokemonIDs
}
// --------------- 初始化创建表 ---------------
func init() {
// 初始化时创建基地房型表与现有Talk表初始化逻辑一致
cool.CreateTable(&BaseHouse{})
}

View File

@@ -62,6 +62,15 @@ func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
tt.Data.CatchTime = tt.CatchTime tt.Data.CatchTime = tt.CatchTime
return tt return tt
} }
func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.PetEX {
m := cool.DBM(s.Model).Where("player_id", userid).Where("catch_time", cachetime)
var tt model.PetEX
m.Scan(&tt)
tt.Data.CatchTime = tt.CatchTime
return tt
}
func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX { func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX {
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped() m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()

View File

@@ -0,0 +1,89 @@
package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"context"
)
func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
//todo待测试
var ttt model.BaseHouseEx
cool.DBM(s.Model).Where("player_id", userid).Scan(&ttt)
return ttt
}
func (s *RoomService) Add(id, count uint32) {
//todo待测试
var ttt model.BaseHouseEx
m := s.GModel(s.Model)
m.Scan(&ttt)
if ttt.OwnedItems == nil {
ttt.OwnedItems = make(map[uint32]uint32)
}
t, ok := ttt.OwnedItems[id]
if ok {
ttt.OwnedItems[id] = t + count
} else {
ttt.OwnedItems[id] = count
}
ttt.PlayerID = uint64(s.userid)
m.Save(ttt)
}
func (s *RoomService) Set(id []model.FitmentShowInfo) {
//todo待测试
var ttt model.BaseHouseEx
m := s.GModel(s.Model)
m.Scan(&ttt)
ttt.PlacedItems = id
ttt.PlayerID = uint64(s.userid)
m.Save(ttt)
}
func (s *RoomService) Show(cactime uint32) {
//todo待测试
var ttt model.BaseHouseEx
m := s.GModel(s.Model)
m.Scan(&ttt)
ttt.ShowPokemon = append(ttt.ShowPokemon, cactime)
ttt.PlayerID = uint64(s.userid)
m.Save(ttt)
}
// /添加进来的物品一定是保证存在的
type RoomService struct {
BaseService
}
func NewRoomService(id uint32) *RoomService {
return &RoomService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewBaseHouse(), UniqueKey: map[string]string{
"player_id": "角色名称不能重复",
}, PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"player_id"},
Where: func(ctx context.Context) [][]interface{} {
var (
//admin = cool.GetAdmin(ctx)
//userId = admin.UserId
)
return [][]interface{}{
// {"player_id", userId, true},
// {"free", 0, true},
}
},
}},
},
}
}

View File

@@ -17,6 +17,7 @@ type UserService struct {
Pet *PetService //精灵 Pet *PetService //精灵
Item *ItemService //物品 Item *ItemService //物品
Done *DoneService //完成 Done *DoneService //完成
Room *RoomService
} }
func NewUserService(id uint32) *UserService { func NewUserService(id uint32) *UserService {
@@ -28,6 +29,7 @@ func NewUserService(id uint32) *UserService {
Item: NewItemService(id), Item: NewItemService(id),
Talk: NewTalkService(id), Talk: NewTalkService(id),
Done: NewDoneService(id), Done: NewDoneService(id),
Room: NewRoomService(id),
} }
} }