This commit is contained in:
@@ -12,13 +12,14 @@ const (
|
||||
type PetFusion struct {
|
||||
*cool.Model // 嵌入通用Model(ID/创建时间/更新时间等)
|
||||
|
||||
MainPetID int32 `gorm:"not null;comment:'主宠物ID(如:尼尔)'" json:"main_pet_id"`
|
||||
SubPetID int32 `gorm:"not null;comment:'副宠物ID(如:闪皮)'" json:"sub_pet_id"`
|
||||
Probability int32 `gorm:"not null;comment:'融合成功率(百分比,如80代表80%)'" json:"probability"`
|
||||
ResultPetID int32 `gorm:"not null;comment:'融合结果宠物ID(如:卡鲁、闪尼)'" json:"result_pet_id"`
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'融合配方备注(如:尼尔+闪皮=闪尼)'" json:"remark"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"`
|
||||
IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"`
|
||||
MainPetID int32 `gorm:"not null;comment:'主宠物ID(如:尼尔)'" json:"main_pet_id"`
|
||||
SubPetID int32 `gorm:"not null;comment:'副宠物ID(如:闪皮)'" json:"sub_pet_id"`
|
||||
SubPetIDs []int32 `gorm:"type:int[];comment:'副宠物IDs(如:1,2,3)'" json:"sub_pet_ids"`
|
||||
Probability int32 `gorm:"not null;comment:'融合成功率(百分比,如80代表80%)'" json:"probability"`
|
||||
ResultPetID int32 `gorm:"not null;comment:'融合结果宠物ID(如:卡鲁、闪尼)'" json:"result_pet_id"`
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'融合配方备注(如:尼尔+闪皮=闪尼)'" json:"remark"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"`
|
||||
IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"`
|
||||
|
||||
// 关联:一个配方对应多个材料(gorm 一对多关联,查询时可预加载)
|
||||
//Materials []*PetFusionMaterial `gorm:"foreignKey:PetFusionID;references:ID" json:"materials,omitempty"`
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -27,6 +28,12 @@ func NewPetFusionService() *PetFusionService {
|
||||
|
||||
//获取主副精灵融合的id,如果不存在,那就给一个保底的id
|
||||
|
||||
func init() {
|
||||
g.DB().SetDebug(true)
|
||||
r := NewPetFusionService().getData(577, 2083)
|
||||
fmt.Println(r)
|
||||
|
||||
}
|
||||
func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 {
|
||||
|
||||
if !grand.Meet(int((rand)/2), 100) {
|
||||
@@ -61,18 +68,13 @@ func (s *PetFusionService) getData(p1, p2 uint32) []model.PetFusion {
|
||||
m := dbm(s.Model)
|
||||
|
||||
var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||
condition := g.Map{
|
||||
"main_pet_id": p1,
|
||||
"sub_pet_id": p2,
|
||||
"is_enable": 1,
|
||||
// "hits between ? and ?" : g.Slice{1, 10},
|
||||
// "exp > 0" : nil,
|
||||
// "category" : g.Slice{100, 200},
|
||||
}
|
||||
m.Where(condition).Scan(&pet)
|
||||
m.Where("main_pet_id", p1).Wheref(`sub_pet_ids @> ARRAY[?]::integer[]`, p2).
|
||||
Where("is_enable", 1).Scan(&pet)
|
||||
|
||||
return pet
|
||||
|
||||
}
|
||||
|
||||
func (s *PetFusionService) def() []model.PetFusion {
|
||||
|
||||
var pets []model.PetFusion
|
||||
|
||||
Reference in New Issue
Block a user