From 7e840cbf179bed29a1368032c4df6d135d416c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Fri, 26 Dec 2025 23:46:10 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(config):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=82=AB=E5=BD=A9=E7=9A=AE=E8=82=A4=E9=85=8D=E7=BD=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=92=8C=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增ShinyService服务,提供Args方法用于根据ID查询炫彩皮肤配置 - 修改ColorfulSkin模型,将BindElfIds字段的gorm类型从json改为jsonb以支持数组查询 - 移除ColorfulSkin模型中嵌入的cool.Model的json标签,优化序列化 - 实现基于JSONB数组查询的精灵绑定功能,支持概率随机和刷新计数统计 debug(common): 添加数据库缓存清除调试信息 - 在ModifyAfter方法中添加er1变量接收ClearCache返回值 - 使用println输出缓存清除结果,便于调试缓存机制 refactor(player): 重构玩家宠物异色信息生成逻辑 - 引入config服务包,通过配置动态生成宠物炫彩效果 - 注释掉原有的固定炫彩效果生成代码 - 添加条件判断,仅当配置存在时才 --- common/cool/service.go | 3 +- help/查询是否连续包含.sql | 6 ++++ logic/service/player/player.go | 50 ++++++++++++++++++--------------- login/main.go | 1 + modules/config/model/shiny.go | 4 +-- modules/config/service/shiny.go | 35 +++++++++++++++++++++++ 6 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 help/查询是否连续包含.sql diff --git a/common/cool/service.go b/common/cool/service.go index 4dab99e3..158cdfd5 100644 --- a/common/cool/service.go +++ b/common/cool/service.go @@ -419,7 +419,8 @@ func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStr // } - g.DB().GetCore().ClearCache(context.TODO(), s.Model.TableName()) + er1 := g.DB().GetCore().ClearCache(context.TODO(), s.Model.TableName()) + println(er1) return } diff --git a/help/查询是否连续包含.sql b/help/查询是否连续包含.sql new file mode 100644 index 00000000..329ef7e9 --- /dev/null +++ b/help/查询是否连续包含.sql @@ -0,0 +1,6 @@ +-- 查询 prop 数组包含 [212, 305] 这个连续子数组的记录 +SELECT * +FROM "config_pet_melee" +WHERE prop @> '[212, 305]'::jsonb + AND jsonb_typeof(prop) = 'array' +LIMIT 50; \ No newline at end of file diff --git a/logic/service/player/player.go b/logic/service/player/player.go index f25f71f4..081c305e 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -14,6 +14,7 @@ import ( "blazing/modules/base/service" blservice "blazing/modules/blazing/service" + config "blazing/modules/config/service" "context" "github.com/antlabs/timer" @@ -49,31 +50,34 @@ type OgrePetInfo struct { } func (o *OgrePetInfo) RandSHiny(t int64) { - o.ShinyInfo = make([]data.GlowFilter, 1) - // 假设 t 是包含 ShinyInfo 字段的结构体,ShinyInfo 是 GlowFilter 类型的切片 - o.ShinyInfo[0] = data.GlowFilter{ - // 光晕颜色:白色(十六进制 0xFFFFFF),符合 uint32 类型 - Color: 65535, - // 透明度:0.8(0.0~1.0 范围内的合理值,float64 类型) - Alpha: 0.3, - // 水平模糊量:10(0~255 范围内,uint8 类型,略高于默认值6) - BlurX: 20, - // 垂直模糊量:10(与 BlurX 对称,uint8 类型) - BlurY: 20, - // 发光强度:8(0~255 范围内,uint8 类型,略高于默认值2) - Strength: 1, - // 滤镜应用次数:2(1~3 范围内,int 类型,非默认值1) - Quality: 2, - // 内侧发光:true(bool 类型,模拟开启内侧发光) - Inner: true, - // 挖空:false(bool 类型,保持默认逻辑) - Knockout: false, - // 颜色矩阵:标准 RGBA 矩阵(20个uint8,符合 [20]uint8 数组类型) - // 矩阵含义:R=100%、G=100%、B=100%、A=100%,无颜色偏移 + // o.ShinyInfo = make([]data.GlowFilter, 1) + // // 假设 t 是包含 ShinyInfo 字段的结构体,ShinyInfo 是 GlowFilter 类型的切片 + // o.ShinyInfo[0] = data.GlowFilter{ + // // 光晕颜色:白色(十六进制 0xFFFFFF),符合 uint32 类型 + // Color: 65535, + // // 透明度:0.8(0.0~1.0 范围内的合理值,float64 类型) + // Alpha: 0.3, + // // 水平模糊量:10(0~255 范围内,uint8 类型,略高于默认值6) + // BlurX: 20, + // // 垂直模糊量:10(与 BlurX 对称,uint8 类型) + // BlurY: 20, + // // 发光强度:8(0~255 范围内,uint8 类型,略高于默认值2) + // Strength: 1, + // // 滤镜应用次数:2(1~3 范围内,int 类型,非默认值1) + // Quality: 2, + // // 内侧发光:true(bool 类型,模拟开启内侧发光) + // Inner: true, + // // 挖空:false(bool 类型,保持默认逻辑) + // Knockout: false, + // // 颜色矩阵:标准 RGBA 矩阵(20个uint8,符合 [20]uint8 数组类型) + // // 矩阵含义:R=100%、G=100%、B=100%、A=100%,无颜色偏移 + // } + co := config.NewShinyService().Args(o.Id) + if co != nil { + o.ShinyInfo = append(o.ShinyInfo, *co) } - - o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get() + //o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get() //g.Dump(ttt.ShinyInfo) // ttt.Shiny = 0 //待确认是否刷新异色 } diff --git a/login/main.go b/login/main.go index a7428d57..4ff86d59 100644 --- a/login/main.go +++ b/login/main.go @@ -27,6 +27,7 @@ func init() { } func main() { + // service.NewShinyService().Args(53) //player.TestPureMatrixSplit() // for _, i := range xmlres.ItemsMAP { diff --git a/modules/config/model/shiny.go b/modules/config/model/shiny.go index 5a0ef661..e895e89e 100644 --- a/modules/config/model/shiny.go +++ b/modules/config/model/shiny.go @@ -11,7 +11,7 @@ const ( // ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配) type ColorfulSkin struct { - *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) + *cool.Model // 核心必填字段 Color string `gorm:"not null;default:'';comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"` @@ -20,7 +20,7 @@ type ColorfulSkin struct { Author string `gorm:"not null;size:64;default:'';comment:'炫彩皮肤配置作者(创建人/配置者名称)'" json:"author" description:"作者"` RefreshCount uint32 `gorm:"not null;default:0;comment:'累计刷新次数(炫彩皮肤外观刷新次数统计)'" json:"refresh_count" description:"刷新次数"` UsageCount uint32 `gorm:"not null;default:0;comment:'累计使用次数(炫彩皮肤使用次数统计)'" json:"usage_count" description:"使用次数"` - BindElfIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定精灵ID数组,关联config_pet_boss表主键,空数组表示未绑定具体精灵'" json:"bind_elf_ids" description:"绑定精灵数组"` + BindElfIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定精灵ID数组,关联config_pet_boss表主键,空数组表示未绑定具体精灵'" json:"bind_elf_ids" description:"绑定精灵数组"` //野生精灵概率 ElfProbability uint32 `gorm:"not null;default:0;comment:'野生精灵概率(0-10000)'" json:"elf_probability" description:"野生精灵概率"` diff --git a/modules/config/service/shiny.go b/modules/config/service/shiny.go index ce2d9da1..630bd9b0 100644 --- a/modules/config/service/shiny.go +++ b/modules/config/service/shiny.go @@ -1,11 +1,15 @@ package service import ( + "blazing/common/data" "blazing/cool" "blazing/modules/config/model" "context" + "encoding/json" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/grand" ) type ShinyService struct { @@ -26,3 +30,34 @@ func NewShinyService() *ShinyService { }, } } + +func (s *ShinyService) Args(id uint32) *data.GlowFilter { + var ret []model.ColorfulSkin + + // 执行 Raw SQL 并扫描返回值 + cool.DBM(s.Model).Wheref(`bind_elf_ids @> ?::jsonb`, id).Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Cache(gdb.CacheOption{ + // Duration: time.Hour, + + Force: false, + }).Scan(&ret) + + for _, v := range ret { + //print(v.ID) + + id := v.ID + + if grand.Meet(int(v.ElfProbability), 1000) { + var t data.GlowFilter + + r := json.Unmarshal([]byte(v.Color), &t) + if r == nil { + m := cool.DBM(s.Model).Where("id", id) + m.Increment("refresh_count", 1) + return &t + } + + } + } + + return nil +}