feat(data): 重构颜色矩阵处理逻辑,将GlowFilter和相关功能迁移到common/data包
This commit is contained in:
18
modules/config/service/boss.go
Normal file
18
modules/config/service/boss.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type BossService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func NewBossService() *BossService {
|
||||
return &BossService{
|
||||
&cool.Service{
|
||||
Model: model.NewBossConfig(),
|
||||
},
|
||||
}
|
||||
}
|
||||
35
modules/config/service/effect.go
Normal file
35
modules/config/service/effect.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
type EffectService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func (s *EffectService) Args(id uint32) (int, []int) {
|
||||
m := cool.DBM(s.Model).Where("se_idx", id).Cache(gdb.CacheOption{
|
||||
//Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
})
|
||||
var tt model.PlayerPetSpecialEffect
|
||||
m.Scan(&tt)
|
||||
|
||||
return int(tt.Eid), tt.Args
|
||||
|
||||
}
|
||||
func NewEffectService() *EffectService {
|
||||
return &EffectService{
|
||||
&cool.Service{
|
||||
|
||||
Model: model.NewPlayerPetSpecialEffect(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var Effects = NewEffectService()
|
||||
29
modules/config/service/melee.go
Normal file
29
modules/config/service/melee.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type MELEEService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func NewMELEEService() *MELEEService {
|
||||
return &MELEEService{
|
||||
&cool.Service{
|
||||
Model: model.NewMeettConfig(),
|
||||
},
|
||||
}
|
||||
}
|
||||
func (s *MELEEService) Def() []model.MeleeConfig {
|
||||
|
||||
var pets []model.MeleeConfig
|
||||
m := cool.DBM(s.Model)
|
||||
|
||||
m.OrderRandom().Limit(3).Scan(&pets)
|
||||
|
||||
return pets
|
||||
// return ret.Interface().([]model.PetFusion)
|
||||
|
||||
}
|
||||
98
modules/config/service/monster_refresh.go
Normal file
98
modules/config/service/monster_refresh.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type MonsterService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func NewMonsterService() *MonsterService {
|
||||
return &MonsterService{
|
||||
&cool.Service{
|
||||
Model: model.NewMonsterRefresh(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MonsterService) ModifyAfter(ctx g.Ctx, method string, param g.MapStrAny) (err error) {
|
||||
|
||||
gconv.String(param["map_id"])
|
||||
cool.DBM(s.Model).Cache((gdb.CacheOption{
|
||||
Duration: -1,
|
||||
Name: model.TableNameMonsterRefresh + gconv.String(param["map_id"]),
|
||||
Force: false,
|
||||
}))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MonsterService) GetId(mapid uint32) []model.MonsterRefresh {
|
||||
|
||||
m := cool.DBM(s.Model).Where("map_id", mapid).Cache(
|
||||
gdb.CacheOption{
|
||||
Duration: time.Hour,
|
||||
Name: model.TableNameMonsterRefresh + strconv.Itoa(int(mapid)),
|
||||
Force: false,
|
||||
},
|
||||
)
|
||||
var tt []model.MonsterRefresh
|
||||
m.Scan(&tt)
|
||||
|
||||
// for _, v := range tt {
|
||||
|
||||
// if v.MapID == int32(mapid) {
|
||||
// return uint32(v.MonsterID)
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
return tt
|
||||
|
||||
}
|
||||
func Test_kick() {
|
||||
const SCRIPT = `
|
||||
function shouldRefresh(userId, day, dayOfWeek, hour, minute) {
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
`
|
||||
t, _ := goja.Compile("test.js", SCRIPT, false)
|
||||
vm := goja.New()
|
||||
_, err := vm.RunProgram(t)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sum, ok := goja.AssertFunction(vm.Get("shouldRefresh"))
|
||||
if !ok {
|
||||
panic("Not a function")
|
||||
}
|
||||
|
||||
res, err := sum(
|
||||
goja.Undefined(),
|
||||
vm.ToValue(1),
|
||||
vm.ToValue(time.Now().Day()),
|
||||
vm.ToValue(time.Now().Weekday()),
|
||||
vm.ToValue(time.Now().Hour()),
|
||||
vm.ToValue(time.Now().Minute()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(res)
|
||||
// Output: 42
|
||||
}
|
||||
90
modules/config/service/pet_fusion_material_service.go
Normal file
90
modules/config/service/pet_fusion_material_service.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/modules/config/model"
|
||||
"blazing/modules/dict/service"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
// PetFusionMaterialService 宠物融合材料子表Service(对应pet_fusion_material表)
|
||||
type PetFusionMaterialService struct {
|
||||
*cool.Service // 嵌入通用Service(继承基础CRUD方法)
|
||||
}
|
||||
|
||||
var PetFusionMaterialServiceIns = NewPetFusionMaterialService()
|
||||
|
||||
// NewPetFusionMaterialService 创建PetFusionMaterialService实例
|
||||
func NewPetFusionMaterialService() *PetFusionMaterialService {
|
||||
return &PetFusionMaterialService{
|
||||
&cool.Service{
|
||||
Model: model.NewPetFusionMaterial(), // 绑定PetFusionMaterial模型(默认参数占位)
|
||||
//Cache: gcache.New(),
|
||||
// PageQueryOp: &cool.QueryOp{KeyWordField: []string{"material1", "material2", "material3", "material4"}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 获取融合材料的特性,返回两个值,一个是指定的特性,另一个是如果配方没找到的情况下,默认的配置
|
||||
func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
|
||||
cacheKey := strings.Join(gconv.Strings(Material1[:]), ":")
|
||||
println(cacheKey, "获取融合id")
|
||||
fusions := service.DictInfoServiceS.GetData("fusion")
|
||||
|
||||
for _, v := range Material1 {
|
||||
if v < 10000 {
|
||||
//使用过小的道具
|
||||
return 0
|
||||
}
|
||||
_, ok := fusions[v]
|
||||
if !ok {
|
||||
//todo使用了非法材料
|
||||
return 0
|
||||
}
|
||||
|
||||
}
|
||||
m := cool.DBM(s.Model)
|
||||
|
||||
var effect *model.PetFusionMaterial //一个特性应该是唯一的,但是我们要获取默认随机特性
|
||||
condition := g.Map{
|
||||
"material1": Material1[0],
|
||||
"material2": Material1[1],
|
||||
"material3": Material1[2],
|
||||
"material4": Material1[3],
|
||||
"is_enable": 1,
|
||||
}
|
||||
m.Where(condition).Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&effect)
|
||||
//这时候有可能效果是空的,那么这时候就再次查询默认的特性,保证每次必会生成一个数据库有的特性
|
||||
//也许这个时候的特性配方就是随机从数据库中查找一个特性
|
||||
|
||||
if effect == nil {
|
||||
effect2s := service.DictInfoServiceS.GetData("effect")
|
||||
for _, v := range effect2s {
|
||||
return gconv.Uint32(v.Value)
|
||||
}
|
||||
|
||||
}
|
||||
r := grand.Intn(4)
|
||||
switch r {
|
||||
case 0:
|
||||
return effect.Trait1Idx
|
||||
case 1:
|
||||
return effect.Trait2Idx
|
||||
case 2:
|
||||
return effect.Trait3Idx
|
||||
case 3:
|
||||
return effect.Trait4Idx
|
||||
}
|
||||
return 0
|
||||
}
|
||||
92
modules/config/service/pet_fusion_service.go
Normal file
92
modules/config/service/pet_fusion_service.go
Normal file
@@ -0,0 +1,92 @@
|
||||
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方法)
|
||||
}
|
||||
|
||||
var PetFusionServiceS = NewPetFusionService()
|
||||
|
||||
// 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)-1)]
|
||||
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 := cool.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).Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).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)
|
||||
|
||||
}
|
||||
35
modules/config/service/talkconfig.go
Normal file
35
modules/config/service/talkconfig.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
type TalkConfigService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
var TalkConfigServiceS = NewTalkConfigService()
|
||||
|
||||
func NewTalkConfigService() *TalkConfigService {
|
||||
return &TalkConfigService{
|
||||
|
||||
Service: &cool.Service{Model: model.NewMineralCollectionConfig()},
|
||||
// Cache: gcache.New()},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig {
|
||||
|
||||
var config []model.MineralCollectionConfig
|
||||
cool.DBM(s.Model).Where("type", flag).Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&config)
|
||||
return config
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user