重构 Talk 方法中物品奖励的获取方式,使用新的配置服务以支持多物品 ID 奖励机制。 移除了对 github.com/gogf/gf/v2/util/grand 包的依赖,改为通过服务获取实际物品数量。 同时更新了相关模型定义: - 修改 MineralCollectionConfig 中 ItemID 为数组形式以支持多个物品配置 - 调整 ItemGift 模型字段
40 lines
637 B
Go
40 lines
637 B
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/config/model"
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
)
|
|
|
|
type ItemService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
//实现物品数量的获取
|
|
|
|
func (s *ItemService) GetItemCount(id uint32) uint32 {
|
|
var item model.ItemGift
|
|
cool.DBM(s.Model).Where("id", id).Scan(&item)
|
|
|
|
if item.ItemID == 0 {
|
|
return 0
|
|
}
|
|
|
|
if item.ItemMaxCount != 0 {
|
|
return uint32(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
|
|
}
|
|
return item.ItemMinCount
|
|
}
|
|
|
|
func NewItemService() *ItemService {
|
|
return &ItemService{
|
|
&cool.Service{
|
|
|
|
Model: model.NewItemGift(),
|
|
},
|
|
}
|
|
}
|
|
|
|
var Items = NewItemService()
|