feat: 重构任务奖励系统并增加宠物技能和皮肤奖励
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
将任务奖励逻辑重构到单独的文件中,增加对宠物技能和皮肤奖励的支持,优化任务完成处理流程
This commit is contained in:
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
@@ -43,18 +42,52 @@ func (s *ShinyService) ModifyBefore(ctx context.Context, method string, param g.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
|
||||
func (s *ShinyService) listByPetID(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)
|
||||
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").
|
||||
Scan(&ret)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func pickColorfulSkinByWeight(items []model.ColorfulSkin) *model.ColorfulSkin {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
totalWeight := 0
|
||||
for _, item := range items {
|
||||
if item.ElfProbability > 0 {
|
||||
totalWeight += int(item.ElfProbability)
|
||||
}
|
||||
}
|
||||
if totalWeight <= 0 {
|
||||
return &items[grand.Intn(len(items))]
|
||||
}
|
||||
|
||||
randomValue := grand.Intn(totalWeight)
|
||||
for i := range items {
|
||||
weight := int(items[i].ElfProbability)
|
||||
if weight <= 0 {
|
||||
continue
|
||||
}
|
||||
if randomValue < weight {
|
||||
return &items[i]
|
||||
}
|
||||
randomValue -= weight
|
||||
}
|
||||
|
||||
return &items[0]
|
||||
}
|
||||
|
||||
func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
ret := s.listByPetID(id)
|
||||
|
||||
for _, v := range ret {
|
||||
//print(v.ID)
|
||||
|
||||
id := v.ID
|
||||
|
||||
if grand.Meet(int(v.ElfProbability), 1000) {
|
||||
@@ -74,32 +107,16 @@ func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
|
||||
var t = data.GetDef()
|
||||
|
||||
t.ColorMatrixFilter = model.GenerateRandomOffspringMatrix().Get()
|
||||
t.ColorMatrixFilter = model.GenerateRandomParentMatrix().Get()
|
||||
|
||||
return &t
|
||||
}
|
||||
|
||||
func (s *ShinyService) RandomByWeightShiny(id uint32) *data.GlowFilter {
|
||||
|
||||
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 {
|
||||
r := pickColorfulSkinByWeight(s.listByPetID(id))
|
||||
if r == nil {
|
||||
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("refresh_count", 1)
|
||||
|
||||
Reference in New Issue
Block a user