Files
bl/modules/blazing/service/pet_fusion_service.go

69 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/grand"
)
// PetFusionService 宠物融合配方主表Service对应pet_fusion表
type PetFusionService struct {
*cool.Service // 嵌入通用Service继承基础CRUD方法
}
// NewPetFusionService 创建PetFusionService实例
func NewPetFusionService() *PetFusionService {
return &PetFusionService{
&cool.Service{
Model: model.NewPetFusion(), // 绑定PetFusion模型
},
}
}
//获取主副精灵融合的id,如果不存在,那就给一个保底的id
func (s *PetFusionService) Data(p1, p2 uint32) uint32 {
m := cool.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)
for _, v := range pet {
rr := grand.Intn(100)
if rr < int(v.Probability) {
return uint32(v.ResultPetID)
}
}
//说明是失败,直接返回失败
if len(pet) > 0 {
return 0
}
var pets []model.PetFusion
m = cool.DBM(s.Model)
m.Where("is_enable", 1).Where("is_default", 1).Scan(&pets)
if len(pets) == 0 {
return 0
}
res := pets[grand.Intn(len(pets)-1)]
rr := grand.Intn(100)
if rr < int(res.Probability) {
return uint32(res.ResultPetID)
}
return 0
}