This commit is contained in:
@@ -35,7 +35,7 @@ func (s *EggService) GetData(p1 uint32) []int32 {
|
||||
return petIDs
|
||||
|
||||
}
|
||||
func (s *EggService) GetResult(m, f uint32) uint32 {
|
||||
func (s *EggService) GetResult(m, f uint32) (uint32, bool) {
|
||||
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
||||
md := dbm_enable(s.Model)
|
||||
|
||||
@@ -45,10 +45,14 @@ func (s *EggService) GetResult(m, f uint32) uint32 {
|
||||
if pet != nil {
|
||||
|
||||
t, _ := utils.RandomByWeight(pet.OutputMons, pet.Probs)
|
||||
return uint32(t)
|
||||
if pet.OutputMons[len(pet.OutputMons)-1] == int32(t) {
|
||||
return uint32(t), true
|
||||
} else {
|
||||
return uint32(t), false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0
|
||||
return 0, false
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
@@ -88,6 +89,34 @@ func (s *ShinyService) FixShiny(id uint32) *model.ColorfulSkin {
|
||||
|
||||
return &v
|
||||
|
||||
}
|
||||
func (s *ShinyService) RandomByWeightShiny(id uint32) *model.ColorfulSkin {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
dbm_enable(s.Model).
|
||||
Wheref(`bind_elf_ids @> ?::jsonb`, id).
|
||||
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Scan(&ret)
|
||||
if len(ret) == 0 {
|
||||
return nil
|
||||
}
|
||||
var rets []model.ColorfulSkin
|
||||
var props []int
|
||||
|
||||
for _, v := range ret {
|
||||
rets = append(rets, v)
|
||||
props = append(props, int(v.ElfProbability))
|
||||
|
||||
}
|
||||
|
||||
r, _ := utils.RandomByWeight(rets, props)
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", r.ID)
|
||||
m.Increment("usage_count", 1)
|
||||
}
|
||||
|
||||
return &r
|
||||
|
||||
}
|
||||
func (s *ShinyService) GetShiny(id int) *data.GlowFilter {
|
||||
var ret []model.ColorfulSkin
|
||||
@@ -102,5 +131,4 @@ func (s *ShinyService) GetShiny(id int) *data.GlowFilter {
|
||||
|
||||
return &v.Color
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user