Files
bl/modules/config/service/item.go
昔念 81c16590d6 ```
feat(pet): 实现宠物展示功能和稀有宠物塔配置

- 添加PetDisplay字段到Player结构体,用于管理宠物展示状态
- 实现PlayerShowPet方法,支持宠物展示逻辑,包括设置展示标识、
  检查宠物存在性并返回相应错误码
- 在Space中添加RefreshUserInfo方法,用于刷新用户信息并应用
  宠物展示信息到SimpleInfo
- 扩展SimpleInfo结构体,添加PetRide字段用于宠物骑乘标识
2026-04-01 02:48:09 +08:00

80 lines
1.6 KiB
Go

package service
import (
"blazing/common/data"
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/util/grand"
)
type ItemService struct {
*cool.Service
}
// 实现物品数量的获取
func (s *ItemService) GetItem(id uint32) *model.ItemGift {
var item *model.ItemGift
dbm_notenable(s.Model).Where("id", id).Scan(&item)
return item
}
func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
var item model.ItemGift
var res data.ItemInfo
dbm_notenable(s.Model).Where("id", id).Scan(&item)
if item.ItemID == 0 {
return res
}
res.ItemId = item.ItemID
res.ItemCnt = item.ItemMinCount
if item.ItemMaxCount != 0 {
res.ItemCnt = int64(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
}
return res
}
func (s *ItemService) AllEgg() []model.ItemGift {
var item []model.ItemGift
dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item)
return item
}
func (s *ItemService) GetEgg(count int) []data.ItemInfo {
var item []model.ItemGift
dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item)
var res []data.ItemInfo
for i := 0; i < count; i++ {
v := item[grand.Intn(len(item))]
if v.ItemMaxCount != 0 {
v.ItemMinCount = int64(grand.N(int(v.ItemMinCount), int(v.ItemMaxCount)))
res = append(res, data.ItemInfo{ItemId: v.ItemID, ItemCnt: v.ItemMinCount})
}
}
return res
}
func NewItemService() *ItemService {
return &ItemService{
&cool.Service{
Model: model.NewItemGift(),
ListQueryOp: &cool.QueryOp{
FieldEQ: []string{"is_egg"},
},
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"remark"},
FieldEQ: []string{"is_egg"},
},
},
}
}