Files
bl/modules/config/service/pet_fusion_service.go
昔念 23027ccfde
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
```
feat(game): 完善宠物融合逻辑和野外BOSS战斗机制

- 在玩家挑战野外BOSS时添加新的ger变量控制捕捉状态
- 当BOSS被标记为已捕捉(isCapture==1)时同步设置ger为-1
- 将怪物等级参数改为使用ger变量传递
- 重构宠物融合服务的数据处理逻辑
- 优化融合结果的权重随机算法
- 添加默认融合配置的查询方法
- 统一错误处理和返回值逻辑
```
2026-03-30 21:03:00 +08:00

99 lines
2.2 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/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(`sub_pet_ids @> ARRAY[?]::integer[]`, 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
}