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:
71
modules/blazing/model/room.go
Normal file
71
modules/blazing/model/room.go
Normal 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=物品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{})
|
||||
}
|
||||
@@ -62,6 +62,15 @@ func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
|
||||
tt.Data.CatchTime = tt.CatchTime
|
||||
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 {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()
|
||||
|
||||
89
modules/blazing/service/room.go
Normal file
89
modules/blazing/service/room.go
Normal 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},
|
||||
}
|
||||
},
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ type UserService struct {
|
||||
Pet *PetService //精灵
|
||||
Item *ItemService //物品
|
||||
Done *DoneService //完成
|
||||
Room *RoomService
|
||||
}
|
||||
|
||||
func NewUserService(id uint32) *UserService {
|
||||
@@ -28,6 +29,7 @@ func NewUserService(id uint32) *UserService {
|
||||
Item: NewItemService(id),
|
||||
Talk: NewTalkService(id),
|
||||
Done: NewDoneService(id),
|
||||
Room: NewRoomService(id),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user