All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(fight): 使用专用函数构建战斗结束数据包 为战斗结束消息创建专用的构建函数, 统一处理战斗结束信息的数据包构建逻辑, 提高代码的一致性和可维护性。 fix(config): 优化数据库查询语句以提高性能 将数组包含操作(@>)替换为 ANY 操作符, 在 Egg、MapPit、PetFusion 等服务中使用更高效 的查询方式
69 lines
1.6 KiB
Go
69 lines
1.6 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(`? = ANY(male_pet_ids)`, 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(`? = ANY(male_pet_ids)`, m).
|
|
Wheref(`? = ANY(female_pet_ids)`, f).Scan(&pet)
|
|
if pet != nil {
|
|
pet.Probs[len(pet.Probs)-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
|
|
|
|
}
|
|
func (s *EggService) All() []model.Egg {
|
|
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
|
m := dbm_enable(s.Model)
|
|
|
|
var pet []model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性
|
|
m.Scan(&pet)
|
|
|
|
return pet
|
|
|
|
}
|