Files
bl/modules/blazing/service/room.go
昔念 648e963562 ```
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
2025-12-13 23:25:04 +08:00

91 lines
1.7 KiB
Go

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 = 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},
}
},
}},
},
}
}