All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(fight): 使用专用函数构建战斗结束数据包 为战斗结束消息创建专用的构建函数, 统一处理战斗结束信息的数据包构建逻辑, 提高代码的一致性和可维护性。 fix(config): 优化数据库查询语句以提高性能 将数组包含操作(@>)替换为 ANY 操作符, 在 Egg、MapPit、PetFusion 等服务中使用更高效 的查询方式
99 lines
2.1 KiB
Go
99 lines
2.1 KiB
Go
package service
|
||
|
||
import (
|
||
"blazing/common/utils"
|
||
"blazing/cool"
|
||
"blazing/modules/config/model"
|
||
|
||
"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模型
|
||
//Cache: gcache.New(),
|
||
PageQueryOp: &cool.QueryOp{FieldEQ: []string{"is_enable", "main_pet_id", "sub_pet_id", "result_pet_id"}},
|
||
},
|
||
}
|
||
}
|
||
|
||
//获取主副精灵融合的id,如果不存在,那就给一个保底的id
|
||
|
||
func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 {
|
||
|
||
if !grand.Meet(int(rand/2)+50, 100) {
|
||
return 0
|
||
|
||
}
|
||
|
||
pet := s.getData(p1, p2)
|
||
|
||
if pet != 0 {
|
||
|
||
return uint32(pet)
|
||
//说明是失败,直接返回失败
|
||
} else {
|
||
|
||
pets := s.def()
|
||
|
||
//到这里相当于直接失败
|
||
return pets
|
||
}
|
||
|
||
}
|
||
func (s *PetFusionService) getData(p1, p2 uint32) uint32 {
|
||
|
||
var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||
dbm_enable(s.Model).Where("main_pet_id", p1).Wheref(`? = ANY(sub_pet_ids)`, p2).Scan(&pet)
|
||
if len(pet) != 0 {
|
||
var pets, props []int
|
||
|
||
for _, v := range pet {
|
||
pets = append(pets, int(v.ResultPetID))
|
||
props = append(props, int(v.Probability))
|
||
|
||
}
|
||
t, _ := utils.RandomByWeight(pets, props)
|
||
return uint32(t)
|
||
//说明是失败,直接返回失败
|
||
}
|
||
return 0
|
||
|
||
}
|
||
|
||
func (s *PetFusionService) def() uint32 {
|
||
|
||
var pet []model.PetFusion
|
||
dbm_enable(s.Model).Where("is_default", 1).Scan(&pet)
|
||
if len(pet) != 0 {
|
||
var pets, props []int
|
||
|
||
for _, v := range pet {
|
||
pets = append(pets, int(v.ResultPetID))
|
||
props = append(props, int(v.Probability))
|
||
|
||
}
|
||
t, _ := utils.RandomByWeight(pets, props)
|
||
return uint32(t)
|
||
//说明是失败,直接返回失败
|
||
}
|
||
return 0
|
||
|
||
// return ret.Interface().([]model.PetFusion)
|
||
|
||
}
|
||
func (s *PetFusionService) All() []model.PetFusion {
|
||
|
||
var pets []model.PetFusion
|
||
dbm_enable(s.Model).Where("is_default", 0).Scan(&pets)
|
||
return pets
|
||
|
||
}
|