From edee754a22d44f1ce53b634d5fb5412cebd58154 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Sun, 21 Dec 2025 18:13:54 +0000 Subject: [PATCH] =?UTF-8?q?feat(model):=20=E6=96=B0=E5=A2=9E=E9=87=91?= =?UTF-8?q?=E8=B1=86=E6=B6=88=E8=B4=B9=E3=80=81CDK=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E3=80=81=E7=82=AB=E5=BD=A9=E7=9A=AE=E8=82=A4=E5=8F=8A=E5=8F=8C?= =?UTF-8?q?=E5=A1=94=E6=A8=A1=E5=9E=8B=EF=BC=8C=E4=BC=98=E5=8C=96=E7=89=A9?= =?UTF-8?q?=E5=93=81=E5=A5=96=E5=8A=B1=E5=92=8CBOSS=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/info/BattlePetEntity.go | 13 +- logic/service/fight/input/effect.go | 4 +- modules/blazing/model/GoldBeanConsume.go | 68 ++++++++++ modules/config/model/boss_pet.go | 1 + modules/config/model/cdk.go | 115 ++++++++++++++++ modules/config/model/item_gift.go | 13 +- modules/config/model/pet_gift.go | 2 +- modules/config/model/server_list.go | 1 + modules/config/model/shiny.go | 120 ++++++++++++++++ modules/config/model/tower_500.go | 143 ++++++++++++++++++++ modules/config/model/tower_600.go | 122 +++++++++++++++++ modules/config/model/user_talk.go | 3 +- 12 files changed, 579 insertions(+), 26 deletions(-) create mode 100644 modules/blazing/model/GoldBeanConsume.go create mode 100644 modules/config/model/cdk.go create mode 100644 modules/config/model/shiny.go create mode 100644 modules/config/model/tower_500.go create mode 100644 modules/config/model/tower_600.go diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index 4b5b00d58..78757b641 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -3,10 +3,9 @@ package info import ( element "blazing/common/data/Element" "blazing/common/data/xmlres" - "blazing/modules/blazing/model" + "math/rand" - "sync" "github.com/alpacahq/alpacadecimal" ) @@ -14,20 +13,12 @@ import ( // 战斗属性类型 type EnumAttrType int -// 辅助函数:取整数绝对值(处理负等级) -func abs(x int8) int8 { - if x < 0 { - return -x - } - return x -} - type BattlePetEntity struct { xmlres.PetInfo Info model.PetInfo //通过偏移赋值 //*input.Input //PType int - statusConditions sync.Map // key: StatusCondition, value: int (剩余回合) + Skills map[uint32]*SkillEntity // 技能槽(最多4个技能) //Status StatusDict //精灵的状态 //能力提升属性 diff --git a/logic/service/fight/input/effect.go b/logic/service/fight/input/effect.go index be72c9d32..d790e621a 100644 --- a/logic/service/fight/input/effect.go +++ b/logic/service/fight/input/effect.go @@ -3,11 +3,10 @@ package input import ( "blazing/common/utils" "blazing/logic/service/fight/info" + "blazing/modules/blazing/model" "fmt" - "blazing/modules/blazing/model" - "github.com/alpacahq/alpacadecimal" "github.com/brunoga/deep" "github.com/gogf/gf/v2/util/gconv" @@ -18,6 +17,7 @@ import ( // 战斗结束原因枚举 type EnumEffectType uint16 +// 繁殖加成,体力提升加成 // var EffectType = enum.New[struct { diff --git a/modules/blazing/model/GoldBeanConsume.go b/modules/blazing/model/GoldBeanConsume.go new file mode 100644 index 000000000..80344e128 --- /dev/null +++ b/modules/blazing/model/GoldBeanConsume.go @@ -0,0 +1,68 @@ +package model + +import ( + "blazing/cool" + "errors" +) + +// 表名常量定义:金豆消费记录表 +const ( + TableNameGoldBeanConsume = "gold_bean_consume_record" // 金豆消费记录表(记录用户金豆消耗的明细、类型、关联业务等信息) +) + +// 通过金豆消费时间来确认金豆物品的购买重置周期 +// GoldBeanConsume 金豆消费核心模型(与数据库表字段一一对应,存储消费明细) +type GoldBeanConsume struct { + *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) + + UID uint32 `gorm:"not null;default:0;index;comment:'玩家唯一ID,关联玩家表主键'" json:"uid" description:"玩家ID"` + ConsumeNum uint32 `gorm:"not null;default:0;comment:'金豆消费数量(非负数)'" json:"consume_num" description:"消费金豆数量"` + BizID uint32 `gorm:"not null;default:0;comment:'关联业务ID(如道具ID/扭蛋池ID,无则填0)'" json:"biz_id" description:"关联业务ID"` + BeforeBalance uint32 `gorm:"not null;default:0;comment:'消费前金豆余额'" json:"before_balance" description:"消费前余额"` +} + +// GoldBeanConsumeEX 金豆消费扩展模型(用于前端/业务层展示,补充非存储字段) +type GoldBeanConsumeEX struct { + GoldBeanConsume // 嵌入核心消费模型 + UserName string `json:"user_name" description:"玩家昵称"` // 关联玩家表查询,前端展示用 + ConsumeTypeDesc string `json:"consume_type_desc" description:"消费类型描述"` // 如"购买道具"/"扭蛋抽奖" +} + +// -------------------------- 核心配套方法 -------------------------- + +// TableName 指定GoldBeanConsume对应的数据库表名(遵循项目规范) +func (*GoldBeanConsume) TableName() string { + return TableNameGoldBeanConsume +} + +// GroupName 指定表所属分组(与其他精灵/玩家相关表保持一致) +func (*GoldBeanConsume) GroupName() string { + return "default" +} + +// NewGoldBeanConsume 创建金豆消费记录实例(初始化通用Model及默认值) +func NewGoldBeanConsume() *GoldBeanConsume { + return &GoldBeanConsume{ + Model: cool.NewModel(), + } +} + +// ValidateConsume 校验消费记录的合法性(避免无效/非法数据) +func (g *GoldBeanConsume) ValidateConsume() error { + // 校验玩家ID + if g.UID == 0 { + return errors.New("玩家ID不能为空") + } + // 校验消费数量 + if g.ConsumeNum <= 0 { + return errors.New("金豆消费数量必须大于0") + } + + return nil +} + +// -------------------------- 表结构自动同步 -------------------------- +func init() { + // 程序启动时自动创建/同步金豆消费记录表 + cool.CreateTable(&GoldBeanConsume{}) +} diff --git a/modules/config/model/boss_pet.go b/modules/config/model/boss_pet.go index 98e7af0f0..d51b640f3 100644 --- a/modules/config/model/boss_pet.go +++ b/modules/config/model/boss_pet.go @@ -13,6 +13,7 @@ const ( type BossConfig struct { *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段) PetBaseConfig + Script string `gorm:"size:1024;default:'';comment:'BOSS脚本'" json:"script"` //boss出招逻辑做成js脚本 // ISboss uint32 `gorm:"not null;default:0;comment:'是否是Boss'" json:"is_boss"` // ISgift uint32 `gorm:"not null;default:0;comment:'是否是礼物'" json:"is_gif"` diff --git a/modules/config/model/cdk.go b/modules/config/model/cdk.go new file mode 100644 index 000000000..8e22f51e8 --- /dev/null +++ b/modules/config/model/cdk.go @@ -0,0 +1,115 @@ +package model + +import ( + "blazing/cool" + "errors" + "fmt" + "time" +) + +// 表名常量定义:CDK配置表 +const ( + TableNameCDKConfig = "cdk_config" // CDK配置表(记录CDK编号、可兑换次数、奖励配置等核心信息) +) + +// CDKConfig CDK核心配置模型(含可兑换次数,满足查询`where 可兑换次数 != 0`需求) +type CDKConfig struct { + *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) + + // 核心字段 + CDKCode string `gorm:"not null;size:64;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"` + + //cdk可兑换次数,where不等于0 + ExchangeRemainCount uint32 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"` + ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"` + ElfRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"奖励精灵数组"` + + // 辅助配置字段 + ValidStartTime time.Time `gorm:"not null;comment:'CDK有效开始时间'" json:"valid_start_time" description:"有效开始时间"` + ValidEndTime time.Time `gorm:"not null;comment:'CDK有效结束时间'" json:"valid_end_time" description:"有效结束时间"` + IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该CDK(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"` + Remark string `gorm:"size:512;default:'';comment:'CDK备注'" json:"remark" description:"备注信息"` + ItemGift []ItemGift `orm:"with:item_id=id"` +} + +// -------------------------- 核心配套方法(遵循项目规范)-------------------------- +func (*CDKConfig) TableName() string { + return TableNameCDKConfig +} + +func (*CDKConfig) GroupName() string { + return "default" +} + +func NewCDKConfig() *CDKConfig { + return &CDKConfig{ + Model: cool.NewModel(), + CDKCode: "", + + ExchangeRemainCount: 1, // 剩余可兑换次数默认1,确保不为0 + ItemRewardIds: []uint32{}, + ElfRewardIds: []uint32{}, + ValidStartTime: time.Now(), + ValidEndTime: time.Now().AddDate(1, 0, 0), // 默认有效期1年 + IsEnabled: 1, + Remark: "", + } +} + +// -------------------------- 业务操作方法(适配可兑换次数 != 0 需求)-------------------------- + +// SetExchangeTotalCount 设置总可兑换次数(确保不为0,满足where !=0 约束) +func (c *CDKConfig) SetExchangeTotalCount(total uint32) error { + if total == 0 { + return errors.New("CDK总可兑换次数不能为0,请设置大于0的数值") + } + // 若剩余次数大于新的总次数,同步更新剩余次数为总次数 + if c.ExchangeRemainCount > total { + c.ExchangeRemainCount = total + } + + return nil +} + +// DeductRemainCount 扣减剩余可兑换次数(扣减后仍保证非负,且仅当剩余次数>0时可扣减) +func (c *CDKConfig) DeductRemainCount(deductNum uint32) error { + if deductNum <= 0 { + return errors.New("扣减的兑换次数必须大于0") + } + // 校验剩余次数是否大于0(满足where !=0 前置条件) + if c.ExchangeRemainCount == 0 { + return errors.New("CDK剩余可兑换次数为0,无法继续扣减") + } + // 校验扣减后是否为负 + if c.ExchangeRemainCount < deductNum { + return fmt.Errorf("剩余可兑换次数不足(当前剩余%d,需扣减%d)", c.ExchangeRemainCount, deductNum) + } + c.ExchangeRemainCount -= deductNum + return nil +} + +// IsAvailable 判断CDK是否可用(剩余次数!=0 + 启用 + 在有效期内) +func (c *CDKConfig) IsAvailable() (bool, string) { + now := time.Now() + // 校验剩余次数是否!=0 + if c.ExchangeRemainCount == 0 { + return false, "CDK剩余可兑换次数为0,已失效" + } + // 校验是否启用 + if c.IsEnabled == 0 { + return false, "CDK已被禁用,无法使用" + } + // 校验有效期 + if now.Before(c.ValidStartTime) { + return false, "CDK尚未到有效时间,暂无法使用" + } + if now.After(c.ValidEndTime) { + return false, "CDK已过有效期,已失效" + } + return true, "CDK可用" +} + +// -------------------------- 表结构自动同步 -------------------------- +func init() { + cool.CreateTable(&CDKConfig{}) +} diff --git a/modules/config/model/item_gift.go b/modules/config/model/item_gift.go index 0ac81fc9b..105dd0259 100644 --- a/modules/config/model/item_gift.go +++ b/modules/config/model/item_gift.go @@ -17,19 +17,10 @@ type ItemGift struct { ItemID uint32 `gorm:"not null;default:0;comment:'物品ID,关联物品配置表主键'" json:"item_id"` Remark string `gorm:"size:512;default:'';comment:'物品奖励备注说明(如使用场景、特殊说明等)'" json:"remark"` IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled"` - IsGacha uint32 `gorm:"not null;default:0;comment:'是否为扭蛋物品(0-否 1-是)'" json:"is_gacha"` + IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 ItemCount uint32 `gorm:"not null;default:1;comment:'物品奖励数量'" json:"item_count"` } -// ItemGiftEX 物品奖励扩展配置模型(用于前端/业务层复杂数据展示,非数据库存储字段) -type ItemGiftEX struct { - ItemGift // 嵌入基础物品奖励模型 - ItemName string `json:"item_name"` // 物品名称(前端展示用,关联物品表查询得到) - ItemIcon string `json:"item_icon"` // 物品图标路径(前端展示用,非数据库存储字段) - StatusDesc string `json:"status_desc"` // 启用状态描述(如"启用"/"禁用",前端展示用) - GachaDesc string `json:"gacha_desc"` // 扭蛋标识描述(如"扭蛋专属"/"普通物品",前端展示用) -} - // TableName 指定ItemGift对应的数据库表名(遵循现有代码规范) func (*ItemGift) TableName() string { return TableNameItemGift @@ -46,7 +37,7 @@ func NewItemGift() *ItemGift { Model: cool.NewModel(), // 初始化通用Model字段(ID/创建时间/更新时间等) // 字段默认值与gorm tag中default配置保持一致 IsEnabled: 1, - IsGacha: 0, + ItemCount: 1, } } diff --git a/modules/config/model/pet_gift.go b/modules/config/model/pet_gift.go index 76219dc73..6f9f3c3cb 100644 --- a/modules/config/model/pet_gift.go +++ b/modules/config/model/pet_gift.go @@ -14,7 +14,7 @@ type PetReward struct { *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段,保持与BossConfig一致) PetBaseConfig - ISegg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 + IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 } // PetRewardEX 精灵奖励扩展配置模型(用于前端/业务层的复杂数据解析,继承基础模型) diff --git a/modules/config/model/server_list.go b/modules/config/model/server_list.go index dcef8461e..e6c182605 100644 --- a/modules/config/model/server_list.go +++ b/modules/config/model/server_list.go @@ -6,6 +6,7 @@ import ( const TableNameServerList = "server_list" +// 服务器设置天气地图|地图是否显示其他人,设置异色概率|ip // ServerList mapped from table type ServerList struct { *cool.Model diff --git a/modules/config/model/shiny.go b/modules/config/model/shiny.go new file mode 100644 index 000000000..5d4eb5206 --- /dev/null +++ b/modules/config/model/shiny.go @@ -0,0 +1,120 @@ +package model + +import ( + "blazing/common/data" + "blazing/cool" + "errors" + "fmt" +) + +// 表名常量定义:炫彩皮肤表 +const ( + TableNameColorfulSkin = "colorful_skin" // 炫彩皮肤表(记录炫彩皮肤颜色、光环、绑定精灵等核心配置) +) + +// ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配) +type ColorfulSkin struct { + *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) + + // 核心必填字段 + Color string `gorm:"not null;default:'';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:"作者"` + 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:"绑定精灵数组"` + //野生精灵概率 + ElfProbability uint32 `gorm:"not null;default:0;comment:'野生精灵概率(0-10000)'" json:"elf_probability" description:"野生精灵概率"` + + // 辅助备注字段 + Remark string `gorm:"size:512;default:'';comment:'炫彩皮肤备注'" json:"remark" description:"备注信息"` +} + +// ColorfulSkinEX 炫彩皮肤扩展模型(用于前端/业务层展示,非数据库存储字段) +type ColorfulSkinEX struct { + ColorfulSkin // 嵌入核心炫彩皮肤模型 + + ColorS data.GlowFilter `json:"color" description:"光环名称(前端展示用,关联光环配置表查询)"` + BindElfNames []string `json:"bind_elf_names" description:"绑定精灵名称列表"` + IsEnabledDesc string `json:"is_enabled_desc" description:"启用状态描述"` + IsUniversalDesc string `json:"is_universal_desc" description:"通用状态描述"` +} + +// -------------------------- 核心配套方法(仅更名适配,逻辑不变)-------------------------- +func (*ColorfulSkin) TableName() string { + return TableNameColorfulSkin +} + +func (*ColorfulSkin) GroupName() string { + return "default" +} + +func NewColorfulSkin() *ColorfulSkin { + return &ColorfulSkin{ + Model: cool.NewModel(), + Color: "", + + IsEnabled: 1, + Author: "", + RefreshCount: 0, + UsageCount: 0, + BindElfIds: []uint32{}, + + Remark: "", + } +} + +// -------------------------- 业务操作方法(逻辑不变,仅调整提示信息标识)-------------------------- + +// AddBindElfId 为炫彩皮肤添加单个绑定精灵ID(避免重复添加) +func (c *ColorfulSkin) AddBindElfId(elfId uint32) error { + if elfId == 0 { + return errors.New("绑定精灵ID不能为空(不能为0)") + } + // 检查是否已绑定,避免重复 + for _, id := range c.BindElfIds { + if id == elfId { + return fmt.Errorf("精灵ID%d已绑定当前炫彩皮肤配置,无需重复添加", elfId) + } + } + c.BindElfIds = append(c.BindElfIds, elfId) + return nil +} + +// RemoveBindElfId 从炫彩皮肤移除单个绑定精灵ID +func (c *ColorfulSkin) RemoveBindElfId(elfId uint32) error { + if elfId == 0 { + return errors.New("绑定精灵ID不能为空(不能为0)") + } + for i, id := range c.BindElfIds { + if id == elfId { + c.BindElfIds = append(c.BindElfIds[:i], c.BindElfIds[i+1:]...) + return nil + } + } + return fmt.Errorf("当前炫彩皮肤配置未绑定精灵ID%d,无法移除", elfId) +} + +// AddRefreshCount 增加刷新次数(支持批量累加,默认累加1) +func (c *ColorfulSkin) AddRefreshCount(addNum uint32) error { + if addNum <= 0 { + return errors.New("增加的刷新次数必须大于0") + } + c.RefreshCount += addNum + return nil +} + +// AddUsageCount 增加使用次数(支持批量累加,默认累加1) +func (c *ColorfulSkin) AddUsageCount(addNum uint32) error { + if addNum <= 0 { + return errors.New("增加的使用次数必须大于0") + } + c.UsageCount += addNum + return nil +} + +// -------------------------- 表结构自动同步 -------------------------- +func init() { + cool.CreateTable(&ColorfulSkin{}) +} diff --git a/modules/config/model/tower_500.go b/modules/config/model/tower_500.go new file mode 100644 index 000000000..47dde85ca --- /dev/null +++ b/modules/config/model/tower_500.go @@ -0,0 +1,143 @@ +package model + +import ( + "blazing/cool" + "errors" + "fmt" +) + +// 表名常量定义:试炼之塔配置表 +const ( + TableNameTrialTowerConfig = "trial_tower_config" // 试炼之塔配置表(核心记录层数、BOSS数组、奖励物品/精灵) +) + +type BaseTowerConfig struct { + *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) + + // 核心必填字段(与勇者之塔完全一致,仅表名和标识不同) + TowerLevel uint32 `gorm:"not null;default:0;uniqueIndex;comment:'试炼之塔层数(唯一标识每层配置)'" json:"tower_level" description:"试炼之塔层数"` + BossIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定BOSS ID数组,关联config_pet_boss表主键'" json:"boss_ids" description:"绑定BOSS数组"` + ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"绑定奖励物品数组"` + ElfRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"绑定奖励精灵数组"` + + // 通用辅助字段(与勇者之塔完全一致,无额外添加) + IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该层配置(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"` + Remark string `gorm:"size:512;default:'';comment:'试炼之塔层备注'" json:"remark" description:"备注信息"` + ItemGift []ItemGift `orm:"with:item_id=id"` +} + +func NewBaseTowerConfig() BaseTowerConfig { + return BaseTowerConfig{ + Model: cool.NewModel(), + } +} + +// TrialTowerConfig 试炼之塔核心配置模型(与勇者之塔结构完全一致,无额外专属字段) +type TrialTowerConfig struct { + BaseTowerConfig +} + +// -------------------------- 核心配套方法(与勇者之塔完全一致)-------------------------- +func (*TrialTowerConfig) TableName() string { + return TableNameTrialTowerConfig +} + +func (*TrialTowerConfig) GroupName() string { + return "default" +} + +func NewTrialTowerConfig() *TrialTowerConfig { + return &TrialTowerConfig{ + BaseTowerConfig: NewBaseTowerConfig(), + } +} + +// -------------------------- 业务操作方法(与勇者之塔逻辑完全一致,仅模型标识不同)-------------------------- +// AddBossId 为试炼之塔添加单个BOSS ID(避免重复) +func (t *TrialTowerConfig) AddBossId(bossId uint32) error { + if bossId == 0 { + return errors.New("BOSS ID不能为空(不能为0)") + } + for _, id := range t.BossIds { + if id == bossId { + return fmt.Errorf("BOSS ID%d已绑定试炼之塔%d层,无需重复添加", bossId, t.TowerLevel) + } + } + t.BossIds = append(t.BossIds, bossId) + return nil +} + +// AddItemRewardId 为试炼之塔添加单个奖励物品ID(避免重复) +func (t *TrialTowerConfig) AddItemRewardId(itemId uint32) error { + if itemId == 0 { + return errors.New("奖励物品ID不能为空(不能为0)") + } + for _, id := range t.ItemRewardIds { + if id == itemId { + return fmt.Errorf("奖励物品ID%d已绑定试炼之塔%d层,无需重复添加", itemId, t.TowerLevel) + } + } + t.ItemRewardIds = append(t.ItemRewardIds, itemId) + return nil +} + +// AddElfRewardId 为试炼之塔添加单个奖励精灵ID(避免重复) +func (t *TrialTowerConfig) AddElfRewardId(elfId uint32) error { + if elfId == 0 { + return errors.New("奖励精灵ID不能为空(不能为0)") + } + for _, id := range t.ElfRewardIds { + if id == elfId { + return fmt.Errorf("奖励精灵ID%d已绑定试炼之塔%d层,无需重复添加", elfId, t.TowerLevel) + } + } + t.ElfRewardIds = append(t.ElfRewardIds, elfId) + return nil +} + +// RemoveBossId 从试炼之塔移除单个BOSS ID +func (t *TrialTowerConfig) RemoveBossId(bossId uint32) error { + if bossId == 0 { + return errors.New("BOSS ID不能为空(不能为0)") + } + for i, id := range t.BossIds { + if id == bossId { + t.BossIds = append(t.BossIds[:i], t.BossIds[i+1:]...) + return nil + } + } + return fmt.Errorf("试炼之塔%d层未绑定BOSS ID%d,无法移除", t.TowerLevel, bossId) +} + +// RemoveItemRewardId 从试炼之塔移除单个奖励物品ID +func (t *TrialTowerConfig) RemoveItemRewardId(itemId uint32) error { + if itemId == 0 { + return errors.New("奖励物品ID不能为空(不能为0)") + } + for i, id := range t.ItemRewardIds { + if id == itemId { + t.ItemRewardIds = append(t.ItemRewardIds[:i], t.ItemRewardIds[i+1:]...) + return nil + } + } + return fmt.Errorf("试炼之塔%d层未绑定奖励物品ID%d,无法移除", t.TowerLevel, itemId) +} + +// RemoveElfRewardId 从试炼之塔移除单个奖励精灵ID +func (t *TrialTowerConfig) RemoveElfRewardId(elfId uint32) error { + if elfId == 0 { + return errors.New("奖励精灵ID不能为空(不能为0)") + } + for i, id := range t.ElfRewardIds { + if id == elfId { + t.ElfRewardIds = append(t.ElfRewardIds[:i], t.ElfRewardIds[i+1:]...) + return nil + } + } + return fmt.Errorf("试炼之塔%d层未绑定奖励精灵ID%d,无法移除", t.TowerLevel, elfId) +} + +// -------------------------- 表结构自动同步 -------------------------- +func init() { + cool.CreateTable(&TrialTowerConfig{}) +} diff --git a/modules/config/model/tower_600.go b/modules/config/model/tower_600.go new file mode 100644 index 000000000..d54393798 --- /dev/null +++ b/modules/config/model/tower_600.go @@ -0,0 +1,122 @@ +package model + +import ( + "blazing/cool" + "errors" + "fmt" +) + +// 表名常量定义:勇者之塔配置表 +const ( + TableNameBraveTowerConfig = "brave_tower_config" // 勇者之塔配置表(核心记录层数、BOSS数组、奖励物品/精灵) +) + +// BraveTowerConfig 勇者之塔核心配置模型(结构简洁,无额外专属字段) +type BraveTowerConfig struct { + BaseTowerConfig +} + +// -------------------------- 核心配套方法(结构与试炼之塔完全一致)-------------------------- +func (*BraveTowerConfig) TableName() string { + return TableNameBraveTowerConfig +} + +func (*BraveTowerConfig) GroupName() string { + return "default" +} + +func NewBraveTowerConfig() *BraveTowerConfig { + return &BraveTowerConfig{ + BaseTowerConfig: NewBaseTowerConfig(), + } +} + +// -------------------------- 业务操作方法(两个塔方法逻辑完全一致)-------------------------- +// AddBossId 为勇者之塔添加单个BOSS ID(避免重复) +func (b *BraveTowerConfig) AddBossId(bossId uint32) error { + if bossId == 0 { + return errors.New("BOSS ID不能为空(不能为0)") + } + for _, id := range b.BossIds { + if id == bossId { + return fmt.Errorf("BOSS ID%d已绑定勇者之塔%d层,无需重复添加", bossId, b.TowerLevel) + } + } + b.BossIds = append(b.BossIds, bossId) + return nil +} + +// AddItemRewardId 为勇者之塔添加单个奖励物品ID(避免重复) +func (b *BraveTowerConfig) AddItemRewardId(itemId uint32) error { + if itemId == 0 { + return errors.New("奖励物品ID不能为空(不能为0)") + } + for _, id := range b.ItemRewardIds { + if id == itemId { + return fmt.Errorf("奖励物品ID%d已绑定勇者之塔%d层,无需重复添加", itemId, b.TowerLevel) + } + } + b.ItemRewardIds = append(b.ItemRewardIds, itemId) + return nil +} + +// AddElfRewardId 为勇者之塔添加单个奖励精灵ID(避免重复) +func (b *BraveTowerConfig) AddElfRewardId(elfId uint32) error { + if elfId == 0 { + return errors.New("奖励精灵ID不能为空(不能为0)") + } + for _, id := range b.ElfRewardIds { + if id == elfId { + return fmt.Errorf("奖励精灵ID%d已绑定勇者之塔%d层,无需重复添加", elfId, b.TowerLevel) + } + } + b.ElfRewardIds = append(b.ElfRewardIds, elfId) + return nil +} + +// RemoveBossId 从勇者之塔移除单个BOSS ID +func (b *BraveTowerConfig) RemoveBossId(bossId uint32) error { + if bossId == 0 { + return errors.New("BOSS ID不能为空(不能为0)") + } + for i, id := range b.BossIds { + if id == bossId { + b.BossIds = append(b.BossIds[:i], b.BossIds[i+1:]...) + return nil + } + } + return fmt.Errorf("勇者之塔%d层未绑定BOSS ID%d,无法移除", b.TowerLevel, bossId) +} + +// RemoveItemRewardId 从勇者之塔移除单个奖励物品ID +func (b *BraveTowerConfig) RemoveItemRewardId(itemId uint32) error { + if itemId == 0 { + return errors.New("奖励物品ID不能为空(不能为0)") + } + for i, id := range b.ItemRewardIds { + if id == itemId { + b.ItemRewardIds = append(b.ItemRewardIds[:i], b.ItemRewardIds[i+1:]...) + return nil + } + } + return fmt.Errorf("勇者之塔%d层未绑定奖励物品ID%d,无法移除", b.TowerLevel, itemId) +} + +// RemoveElfRewardId 从勇者之塔移除单个奖励精灵ID +func (b *BraveTowerConfig) RemoveElfRewardId(elfId uint32) error { + if elfId == 0 { + return errors.New("奖励精灵ID不能为空(不能为0)") + } + for i, id := range b.ElfRewardIds { + if id == elfId { + b.ElfRewardIds = append(b.ElfRewardIds[:i], b.ElfRewardIds[i+1:]...) + return nil + } + } + return fmt.Errorf("勇者之塔%d层未绑定奖励精灵ID%d,无法移除", b.TowerLevel, elfId) +} + +// -------------------------- 表结构自动同步 -------------------------- +func init() { + cool.CreateTable(&BraveTowerConfig{}) +} diff --git a/modules/config/model/user_talk.go b/modules/config/model/user_talk.go index ed7990e13..4f36f0981 100644 --- a/modules/config/model/user_talk.go +++ b/modules/config/model/user_talk.go @@ -26,7 +26,8 @@ type MineralCollectionConfig struct { // ItemMaxCount 单次采集最大产出数量 ItemMaxCount uint32 `gorm:"column:item_max_count;not null;comment:单次采集最大产出数量" json:"item_max_count"` // Description 矿产描述 - Description string `gorm:"column:description;type:varchar(128); comment:矿产描述" json:"description"` + Description string `gorm:"column:description;type:varchar(128); comment:矿产描述" json:"description"` + ItemGift []*ItemGift `orm:"with:item_id=id"` } // TableName 指定数据表名(必须匹配数据库表名,遵循项目规范)