All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
fix(config): 修复宠物蛋系统中概率计算错误 - 修正了EggService中宠物产出概率计算时错误使用的字段名 - 将pet.OutputMons修正为pet.Probs以正确累加等级权重 refactor(player): 优化金币列表服务参数处理逻辑 - 移除未使用的gconv导入包 - 简化ModifyBefore方法中的用户ID验证逻辑 - 统一设置
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/common/utils"
|
|
"blazing/cool"
|
|
"blazing/modules/config/model"
|
|
)
|
|
|
|
type EggService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
func NewEggService() *EggService {
|
|
return &EggService{
|
|
&cool.Service{
|
|
Model: model.NewEgg(),
|
|
PageQueryOp: &cool.QueryOp{
|
|
KeyWordField: []string{"desc"},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (s *EggService) GetData(p1 uint32) []int32 {
|
|
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
|
m := dbm_enable(s.Model)
|
|
|
|
var pet []model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性
|
|
m.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, p1).Scan(&pet)
|
|
var petIDs []int32
|
|
for _, p := range pet {
|
|
petIDs = append(petIDs, p.FemalePetIDs...)
|
|
}
|
|
|
|
return petIDs
|
|
|
|
}
|
|
func (s *EggService) GetResult(m, f, level uint32) (uint32, bool) {
|
|
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
|
md := dbm_enable(s.Model)
|
|
|
|
var pet *model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性
|
|
md.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, m).
|
|
Wheref(`female_pet_ids @> ARRAY[?]::integer[]`, f).Scan(&pet)
|
|
if pet != nil {
|
|
pet.Probs[len(pet.OutputMons)-1] += int32(level)
|
|
t, _ := utils.RandomByWeight(pet.OutputMons, pet.Probs)
|
|
if pet.OutputMons[len(pet.OutputMons)-1] == int32(t) {
|
|
return uint32(t), true
|
|
} else {
|
|
return uint32(t), false
|
|
}
|
|
|
|
}
|
|
|
|
return 0, false
|
|
|
|
}
|