This commit is contained in:
22
modules/config/controller/admin/egg.go
Normal file
22
modules/config/controller/admin/egg.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/service"
|
||||
)
|
||||
|
||||
type EggController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
var task_info_controller = &EggController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/config/egg",
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewEggService(),
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(task_info_controller)
|
||||
}
|
||||
@@ -4,49 +4,43 @@ import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量定义:egg配置表
|
||||
const (
|
||||
TableNameeggConfig = "config_pet_egg" // egg配置表(记录egg编号、可兑换次数、奖励配置等核心信息)
|
||||
TableNameEgg = "config_egg" // 性别配置表(替换原宠物融合表名)
|
||||
)
|
||||
|
||||
// EggConfig egg核心配置模型(含可兑换次数,满足查询`where 可兑换次数 != 0`需求)
|
||||
type EggConfig struct {
|
||||
*cool.Model
|
||||
|
||||
// Egg 性别配置模型(替换原宠物融合配方模型)
|
||||
type Egg struct {
|
||||
*cool.Model // 保留通用Model(ID/创建时间/更新时间等)
|
||||
//雄性
|
||||
|
||||
MalePet int32 `gorm:"not null;comment:'雄性宠物ID'" json:"male_pet"`
|
||||
MalePetIDs []int32 `gorm:"type:int[];comment:'雄性宠物ID列表(如:[1001,1002])'" json:"male_pet_ids"`
|
||||
//雌性
|
||||
FemalePet int32 `gorm:"not null;comment:'雌性宠物ID'" json:"female_pet"`
|
||||
FemalePetIDs []int32 `gorm:"type:int[];comment:'雌性宠物ID列表(如:[1001,1002])'" json:"female_pet_ids"`
|
||||
//子代指定性别配置表名
|
||||
OutputMons []int32 `gorm:"type:int[];not null;comment:'宠物类型ID'" json:"pet_type_id"`
|
||||
Probs []int32 `gorm:"type:int[];not null;comment:'对应子代宠物类型的概率(如:[50,50]表示均等概率)'" json:"probs"`
|
||||
|
||||
// 生成的精灵ID及对应概率
|
||||
GeneratedPetIDs []GeneratedPetID `gorm:"type:jsonb;comment:'生成的精灵ID及概率配置'" json:"generated_pet_ids"`
|
||||
|
||||
Remark string `gorm:"size:512;default:'';comment:'egg备注'" json:"remark" description:"备注信息"`
|
||||
//ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"`
|
||||
}
|
||||
type GeneratedPetID struct {
|
||||
PetID int32 `json:"pet_id" comment:"生成的精灵ID"`
|
||||
Prob float64 `json:"prob" comment:"该精灵生成概率"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"` // 保留原有逻辑
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'性别配置备注(如:默认性别规则)'" json:"remark"` // 调整注释
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法(遵循项目规范)--------------------------
|
||||
func (*EggConfig) TableName() string {
|
||||
return TableNameeggConfig
|
||||
// TableName 指定性别配置表名(替换原宠物融合表名)
|
||||
func (*Egg) TableName() string {
|
||||
return TableNameEgg
|
||||
}
|
||||
|
||||
func (*EggConfig) GroupName() string {
|
||||
// GroupName 表分组(保持原逻辑的default分组)
|
||||
func (*Egg) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func NeweggConfig() *EggConfig {
|
||||
return &EggConfig{
|
||||
// NewEgg 创建性别配置实例(替换原NewPetFusion)
|
||||
func NewEgg() *Egg {
|
||||
return &Egg{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
// init 初始化性别配置表结构(替换原宠物融合表初始化)
|
||||
func init() {
|
||||
|
||||
cool.CreateTable(&EggConfig{})
|
||||
cool.CreateTable(&Egg{})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
@@ -14,7 +15,7 @@ type ColorfulSkin struct {
|
||||
*cool.Model
|
||||
|
||||
// 核心必填字段
|
||||
Color string `gorm:"not null;default:'';comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"`
|
||||
Color data.GlowFilter `gorm:"type:jsonb;not null;;comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"`
|
||||
|
||||
IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"`
|
||||
Author string `gorm:"not null;size:64;default:'';comment:'炫彩皮肤配置作者(创建人/配置者名称)'" json:"author" description:"作者"`
|
||||
@@ -42,15 +43,6 @@ func (*ColorfulSkin) GroupName() string {
|
||||
func NewColorfulSkin() *ColorfulSkin {
|
||||
return &ColorfulSkin{
|
||||
Model: cool.NewModel(),
|
||||
Color: "",
|
||||
|
||||
IsEnabled: 1,
|
||||
Author: "",
|
||||
RefreshCount: 0,
|
||||
UsageCount: 0,
|
||||
BindElfIds: []uint32{},
|
||||
|
||||
Remark: "",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
modules/config/service/egg.go
Normal file
32
modules/config/service/egg.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"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) Get(id uint32) *model.Egg {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
var item *model.Egg
|
||||
dbm(s.Model).Where("id", id).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (s *ShinyService) ModifyBefore(ctx context.Context, method string, param g.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
func (s *ShinyService) RandShiny(id uint32) *model.ColorfulSkin {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
@@ -57,24 +57,20 @@ func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
id := v.ID
|
||||
|
||||
if grand.Meet(int(v.ElfProbability), 1000) {
|
||||
var t data.GlowFilter
|
||||
|
||||
r := json.Unmarshal([]byte(v.Color), &t)
|
||||
if r == nil {
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", id)
|
||||
m.Increment("refresh_count", 1)
|
||||
}
|
||||
|
||||
return &t
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", id)
|
||||
m.Increment("refresh_count", 1)
|
||||
}
|
||||
|
||||
return &v
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
|
||||
func (s *ShinyService) FixShiny(id uint32) *model.ColorfulSkin {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
@@ -87,17 +83,26 @@ func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
|
||||
}
|
||||
v := ret[grand.Intn(len(ret))]
|
||||
|
||||
var t data.GlowFilter
|
||||
|
||||
r := json.Unmarshal([]byte(v.Color), &t)
|
||||
if r == nil {
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", v.ID)
|
||||
m.Increment("usage_count", 1)
|
||||
}
|
||||
|
||||
return &t
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", v.ID)
|
||||
m.Increment("usage_count", 1)
|
||||
}
|
||||
|
||||
return &v
|
||||
|
||||
}
|
||||
func (s *ShinyService) GetShiny(id int) *data.GlowFilter {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
dbm(s.Model).
|
||||
Where("id", id).Scan(&ret)
|
||||
if len(ret) == 0 {
|
||||
return nil
|
||||
}
|
||||
v := ret[grand.Intn(len(ret))]
|
||||
|
||||
return &v.Color
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res
|
||||
//r = g.RequestFromCtx(ctx)
|
||||
)
|
||||
t := model.GenPetInfo(
|
||||
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.Level, nil)
|
||||
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.Level, nil, -1)
|
||||
t.FixShiny()
|
||||
|
||||
service.NewUserService(uint32(admin.UserId)).Pet.PetAdd(t)
|
||||
|
||||
@@ -49,9 +49,11 @@ type PetInfo struct {
|
||||
ID uint32 `fieldDesc:"精灵编号" `
|
||||
|
||||
// 名字:默认为全0,补齐到16字节(固定长度 → [16]byte)
|
||||
Name string `struc:"[16]byte" json:"Name,omitempty"`
|
||||
Name string `struc:"[16]byte" json:"Name,omitempty"`
|
||||
Gender int `struc:"uint16" fieldDesc:"性别" `
|
||||
//generation
|
||||
Generation uint32 `fieldDesc:"世代" `
|
||||
|
||||
Generation uint16 `fieldDesc:"世代" `
|
||||
|
||||
// 个体值(@UInt long → uint32)
|
||||
Dv uint32 `struc:"uint32" `
|
||||
@@ -101,13 +103,13 @@ type PetInfo struct {
|
||||
CatchLevel uint32 `fieldDesc:"捕获等级 默认为0" `
|
||||
EffectInfoLen uint16 `struc:"sizeof=EffectInfo" json:"-"`
|
||||
// 特性列表:长度用UShort存储(变长List → []PetEffectInfo + 长度前缀规则) 第一个一定是特性
|
||||
EffectInfo []PetEffectInfo `fieldDesc:"特性列表, 长度在头部以UShort存储" serialize:"lengthFirst,lengthType=uint16,type=structArray"`
|
||||
EffectInfo []PetEffectInfo
|
||||
|
||||
// 皮肤ID默认0(@UInt long → uint32)
|
||||
SkinID uint32 `fieldDesc:"皮肤id默认为0" `
|
||||
|
||||
// 是否闪光(@UInt long → uint32,0=否,1=是)
|
||||
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
|
||||
ShinyLen uint32 `struc:"sizeof=ShinyInfo"`
|
||||
ShinyInfo []data.GlowFilter `json:"ShinyInfo,omitempty"`
|
||||
|
||||
//时间轮转,然后effect根据type同时只共存一个,特性是1 特质是1,柱子是两种,魂印是一个,然后异色字段,然后特训技能字段
|
||||
@@ -214,7 +216,7 @@ func (pet *PetInfo) RandShiny() {
|
||||
|
||||
co := service.NewShinyService().RandShiny(pet.ID)
|
||||
if co != nil {
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *co)
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *&co.Color)
|
||||
}
|
||||
//o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get()
|
||||
//g.Dump(ttt.ShinyInfo)
|
||||
@@ -224,7 +226,7 @@ func (pet *PetInfo) FixShiny() {
|
||||
|
||||
co := service.NewShinyService().FixShiny(pet.ID)
|
||||
if co != nil {
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *co)
|
||||
pet.ShinyInfo = append(pet.ShinyInfo, *&co.Color)
|
||||
}
|
||||
//o.ShinyInfo[0].ColorMatrixFilter = GenerateRandomOffspringMatrix().Get()
|
||||
//g.Dump(ttt.ShinyInfo)
|
||||
@@ -418,6 +420,7 @@ func init() {
|
||||
func GenPetInfo(
|
||||
id int,
|
||||
dv, natureId, abilityTypeEnum, level int, shinyid []data.GlowFilter,
|
||||
gen int,
|
||||
) *PetInfo {
|
||||
// 创建随机源
|
||||
//rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
@@ -434,8 +437,21 @@ func GenPetInfo(
|
||||
if shinyid != nil {
|
||||
//todo 待实现异色字段
|
||||
p.ShinyInfo = shinyid
|
||||
// r := service.NewShinyService().GetShiny(shinyid)
|
||||
// if r != nil {
|
||||
// p.ShinyInfo = append(p.ShinyInfo, *r)
|
||||
// }
|
||||
|
||||
// p.Shiny = uint32(shinyid)
|
||||
}
|
||||
if gen == -1 {
|
||||
|
||||
p.Gender = grand.N(1, 4)
|
||||
if p.Gender == 3 || p.Gender == 4 {
|
||||
p.Gender = 0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 性格 ----
|
||||
if natureId == -1 {
|
||||
|
||||
Reference in New Issue
Block a user