feat(config): 添加服务器调试模式配置和塔配置重构 - 在ServerList结构体中添加IsDebug字段用于调试模式标识 - 修改GetServerInfoList函数增加isdebug参数支持 - 移除硬编码的rpcaddr本地地址配置 - 重构塔配置模型,将tower_500和tower_600合并到tower_110
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package service
|
||
|
||
import (
|
||
"blazing/cool"
|
||
"blazing/modules/config/model"
|
||
|
||
"github.com/alpacahq/alpacadecimal"
|
||
"github.com/gogf/gf/v2/database/gdb"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"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 {
|
||
rand = uint32(alpacadecimal.NewFromInt(int64(rand)).Mul(alpacadecimal.NewFromFloat(0.5)).IntPart())
|
||
|
||
pet := s.getData(p1, p2)
|
||
for _, v := range pet {
|
||
|
||
rr := grand.Intn(100)
|
||
if rr < int(v.Probability+int32(rand)) {
|
||
return uint32(v.ResultPetID)
|
||
}
|
||
}
|
||
//说明是失败,直接返回失败
|
||
if len(pet) > 0 {
|
||
return 0
|
||
}
|
||
pets := s.def()
|
||
res := pets[grand.Intn(len(pets))]
|
||
rr := grand.Intn(100)
|
||
if rr < int(res.Probability+int32(rand)) {
|
||
return uint32(res.ResultPetID)
|
||
}
|
||
//到这里相当于直接失败
|
||
return 0
|
||
|
||
}
|
||
func (s *PetFusionService) getData(p1, p2 uint32) []model.PetFusion {
|
||
//cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":")
|
||
m := dbm(s.Model)
|
||
|
||
var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||
condition := g.Map{
|
||
"main_pet_id": p1,
|
||
"sub_pet_id": p2,
|
||
"is_enable": 1,
|
||
// "hits between ? and ?" : g.Slice{1, 10},
|
||
// "exp > 0" : nil,
|
||
// "category" : g.Slice{100, 200},
|
||
}
|
||
m.Where(condition).Scan(&pet)
|
||
return pet
|
||
|
||
}
|
||
func (s *PetFusionService) def() []model.PetFusion {
|
||
|
||
var pets []model.PetFusion
|
||
m := cool.DBM(s.Model)
|
||
m.Where("is_enable", 1).Where("is_default", 1).Cache(gdb.CacheOption{
|
||
// Duration: time.Hour,
|
||
|
||
Force: false,
|
||
}).Scan(&pets)
|
||
|
||
return pets
|
||
// return ret.Interface().([]model.PetFusion)
|
||
|
||
}
|