feat(room): 更新房间宠物展示逻辑并优化数据结构 - 修改 `OnGetRoomPetShowInfo` 方法,使用 `pet.PetShortInfo` 替代原有的 `room.PetShowInfo` 结构体 - 引入 `github.com/jinzhu/copier` 实现结构体字段自动复制 - 调整 `SET_Pet` 接口实现逻辑以支持批量设置展示中的宠物 - 更新 `PetRoomListOutboundInfo` 中 Pets 字段类型为 `[]pet.PetShortInfo` - 将 `RoomService.Show` 方法参数由单个 uint32 改为切片 []uint32 以支持多宠物展示 - 修改数据库表名常量 `TableNameBaseHouse` 从 "base_house" 更名为 "room_house
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package model
|
||
|
||
import (
|
||
"blazing/cool"
|
||
)
|
||
|
||
// 基地房型表名
|
||
const TableNameBaseHouse = "room_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=物品ID,value=物品数量,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{})
|
||
}
|