From cf7736a3e74a3c325fc02b0436b3fc7d6526d982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Mon, 22 Dec 2025 19:04:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(user-talk):=20=E4=BC=98=E5=8C=96=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E5=8A=9F=E8=83=BD=E4=B8=AD=E7=9A=84=E7=89=A9=E5=93=81?= =?UTF-8?q?=E5=A5=96=E5=8A=B1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构 Talk 方法中物品奖励的获取方式,使用新的配置服务以支持多物品 ID 奖励机制。 移除了对 github.com/gogf/gf/v2/util/grand 包的依赖,改为通过服务获取实际物品数量。 同时更新了相关模型定义: - 修改 MineralCollectionConfig 中 ItemID 为数组形式以支持多个物品配置 - 调整 ItemGift 模型字段 --- logic/controller/user_talk.go | 15 +++++------ modules/blazing/service/talk.go | 9 ++----- modules/config/model/cdk.go | 10 +++---- modules/config/model/item_gift.go | 7 ++--- modules/config/model/pet_base.go | 23 +++++++++------- modules/config/model/pet_gift.go | 8 ++++-- modules/config/model/tower_500.go | 6 ++--- modules/config/model/user_talk.go | 12 ++++----- modules/config/service/item.go | 39 ++++++++++++++++++++++++++++ modules/config/service/talkconfig.go | 6 ++--- 10 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 modules/config/service/item.go diff --git a/logic/controller/user_talk.go b/logic/controller/user_talk.go index 359599749..5de4cd99b 100644 --- a/logic/controller/user_talk.go +++ b/logic/controller/user_talk.go @@ -5,8 +5,6 @@ import ( "blazing/logic/service/item" "blazing/logic/service/player" "blazing/modules/config/service" - - "github.com/gogf/gf/v2/util/grand" ) func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) { @@ -31,16 +29,15 @@ func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) ( return result, errorcode.ErrorCodes.ErrResourceUnavailable } //更新次数 - config := service.TalkConfigServiceS.GetCache(int(data.ID)) + config := service.NewTalkConfigService().GetCache(int(data.ID)) - for _, v := range config { - count := grand.N(int(v.ItemMinCount), int(v.ItemMaxCount)) + //service.NewItemService().GetItemCount(config.ItemID) - // r := dict.DictInfoServiceS.DataID("fusion") - // trueitemid := gconv.Uint32(r[gconv.Uint32(v.ItemID)].Remark) - ret := c.ItemAdd(uint32(v.ItemID), uint32(count)) + for _, itemid := range config.ItemID { + ritemcount := service.NewItemService().GetItemCount(itemid) + ret := c.ItemAdd(uint32(itemid), uint32(ritemcount)) if ret { - result.OutList = append(result.OutList, item.CateInfo{ID: v.ItemID, Count: uint32(count)}) + result.OutList = append(result.OutList, item.CateInfo{ID: itemid, Count: uint32(ritemcount)}) } } diff --git a/modules/blazing/service/talk.go b/modules/blazing/service/talk.go index 7e05f94b9..46acfe4c8 100644 --- a/modules/blazing/service/talk.go +++ b/modules/blazing/service/talk.go @@ -46,15 +46,10 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) { return int(talks.Count), true } - //maps := service.DictInfoServiceS.DataRemark("mapid") - if len(config.TalkConfigServiceS.GetCache(flag)) == 0 { - return 0, false - } - - if uint32(mapid) != config.TalkConfigServiceS.GetCache(flag)[0].MapID { + if uint32(mapid) != config.NewTalkConfigService().GetCache(flag).MapID { return 0, false //没在地图 } - if talks.Count >= config.TalkConfigServiceS.GetCache(flag)[0].DailyCollectCount { + if talks.Count >= config.NewTalkConfigService().GetCache(flag).DailyCollectCount { return 0, false } return int(talks.Count), true //int(config.MaxDailyCnt - talks.Count) diff --git a/modules/config/model/cdk.go b/modules/config/model/cdk.go index 8e22f51e8..382a7303f 100644 --- a/modules/config/model/cdk.go +++ b/modules/config/model/cdk.go @@ -25,11 +25,11 @@ type CDKConfig struct { 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"` + 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 `gorm:"-" orm:"with:item_id=id"` } // -------------------------- 核心配套方法(遵循项目规范)-------------------------- diff --git a/modules/config/model/item_gift.go b/modules/config/model/item_gift.go index 105dd0259..dbeba957b 100644 --- a/modules/config/model/item_gift.go +++ b/modules/config/model/item_gift.go @@ -18,7 +18,10 @@ type ItemGift struct { Remark string `gorm:"size:512;default:'';comment:'物品奖励备注说明(如使用场景、特殊说明等)'" json:"remark"` IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled"` IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 - ItemCount uint32 `gorm:"not null;default:1;comment:'物品奖励数量'" json:"item_count"` + //ItemCount uint32 `gorm:"not null;default:1;comment:'物品奖励数量'" json:"item_count"` + ItemMinCount uint32 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"` + // ItemMaxCount 单次采集最大产出数量 + ItemMaxCount uint32 `gorm:"column:item_max_count;not null;comment:单次采集最大产出数量" json:"item_max_count"` } // TableName 指定ItemGift对应的数据库表名(遵循现有代码规范) @@ -37,8 +40,6 @@ func NewItemGift() *ItemGift { Model: cool.NewModel(), // 初始化通用Model字段(ID/创建时间/更新时间等) // 字段默认值与gorm tag中default配置保持一致 IsEnabled: 1, - - ItemCount: 1, } } diff --git a/modules/config/model/pet_base.go b/modules/config/model/pet_base.go index 213aa1dc1..148c5fc8e 100644 --- a/modules/config/model/pet_base.go +++ b/modules/config/model/pet_base.go @@ -24,17 +24,20 @@ type PetBaseConfig struct { // PrimaryScene int32 `gorm:"not null;default:0;comment:'首场景标识(0:非首场景地图;n>0:第n星系的星球且是首场景,默认0)'" json:"primary_scene"` // ===================== 战斗核心属性(BossMon节点) ===================== - MonID int32 `gorm:"not null;comment:'BOSS对应的精灵ID'" json:"mon_id"` - Hp int32 `gorm:"not null;comment:'BOSS血量值(LvHpMatchUser非0时此配置无效)'" json:"hp"` - Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"` + MonID int32 `gorm:"not null;comment:'BOSS对应的精灵ID'" json:"mon_id"` + Nature uint32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"` + Effect []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS特性'" json:"effect"` + Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"` + Color string `gorm:"comment:'BOSS颜色'" json:"color"` + Hp int32 `gorm:"not null;comment:'BOSS血量值(LvHpMatchUser非0时此配置无效)'" json:"hp"` + // ===================== BOSS属性(Boss_prop) ===================== - Prop []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS属性'" json:"prop"` - Nature uint32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"` - SKill []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS技能'" json:"skill"` - Effect []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS特性'" json:"effect"` - Color string `gorm:"comment:'BOSS颜色'" json:"color"` - IsEnable uint32 `gorm:"not null;default:0;comment:'是否启用'" json:"is_enable"` - Desc *string `gorm:"comment:'BOSS描述'" json:"desc"` + Prop []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS属性'" json:"prop"` + + SKill []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS技能'" json:"skill"` + + IsEnable uint32 `gorm:"not null;default:0;comment:'是否启用'" json:"is_enable"` + Desc *string `gorm:"comment:'BOSS描述'" json:"desc"` // ISMELEE uint32 `gorm:"not null;default:0;comment:'是否乱斗配置'" json:"is_melee"` // // ===================== BOSS奖励规则(Boss_bonus) ===================== diff --git a/modules/config/model/pet_gift.go b/modules/config/model/pet_gift.go index 6f9f3c3cb..d9da84841 100644 --- a/modules/config/model/pet_gift.go +++ b/modules/config/model/pet_gift.go @@ -13,8 +13,12 @@ const ( type PetReward struct { *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段,保持与BossConfig一致) - PetBaseConfig - IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 + MonID int32 `gorm:"not null;comment:'BOSS对应的精灵ID'" json:"mon_id"` + Nature uint32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"` + Effect []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS特性'" json:"effect"` + Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"` + Color string `gorm:"comment:'BOSS颜色'" json:"color"` + IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 } // PetRewardEX 精灵奖励扩展配置模型(用于前端/业务层的复杂数据解析,继承基础模型) diff --git a/modules/config/model/tower_500.go b/modules/config/model/tower_500.go index 47dde85ca..f526be3dd 100644 --- a/modules/config/model/tower_500.go +++ b/modules/config/model/tower_500.go @@ -21,9 +21,9 @@ type BaseTowerConfig struct { 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"` + 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 { diff --git a/modules/config/model/user_talk.go b/modules/config/model/user_talk.go index 4f36f0981..3462f90e5 100644 --- a/modules/config/model/user_talk.go +++ b/modules/config/model/user_talk.go @@ -20,14 +20,14 @@ type MineralCollectionConfig struct { DailyCollectCount uint32 `gorm:"column:daily_collect_count;not null;comment:每日可采集次数" json:"daily_collect_count"` // ItemID 物品编号(对应道具系统ID) - ItemID uint32 `gorm:"column:item_id; not null;index:idx_mineral_collection_config_item_id;comment:物品编号(对应道具系统ID)" json:"item_id"` + ItemID []uint32 `gorm:"column:item_id; not null;index:idx_mineral_collection_config_item_id;comment:物品编号(对应道具系统ID)" json:"item_id"` // ItemMinCount 单次采集最小产出数量 - ItemMinCount uint32 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"` - // ItemMaxCount 单次采集最大产出数量 - ItemMaxCount uint32 `gorm:"column:item_max_count;not null;comment:单次采集最大产出数量" json:"item_max_count"` + // ItemMinCount uint32 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"` + // // 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"` - ItemGift []*ItemGift `orm:"with:item_id=id"` + Description string `gorm:"column:description;type:varchar(128); comment:矿产描述" json:"description"` + // ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"` } // TableName 指定数据表名(必须匹配数据库表名,遵循项目规范) diff --git a/modules/config/service/item.go b/modules/config/service/item.go new file mode 100644 index 000000000..16753994c --- /dev/null +++ b/modules/config/service/item.go @@ -0,0 +1,39 @@ +package service + +import ( + "blazing/cool" + "blazing/modules/config/model" + + "github.com/gogf/gf/v2/util/grand" +) + +type ItemService struct { + *cool.Service +} + +//实现物品数量的获取 + +func (s *ItemService) GetItemCount(id uint32) uint32 { + var item model.ItemGift + cool.DBM(s.Model).Where("id", id).Scan(&item) + + if item.ItemID == 0 { + return 0 + } + + if item.ItemMaxCount != 0 { + return uint32(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount))) + } + return item.ItemMinCount +} + +func NewItemService() *ItemService { + return &ItemService{ + &cool.Service{ + + Model: model.NewItemGift(), + }, + } +} + +var Items = NewItemService() diff --git a/modules/config/service/talkconfig.go b/modules/config/service/talkconfig.go index 423248541..eb43de6a6 100644 --- a/modules/config/service/talkconfig.go +++ b/modules/config/service/talkconfig.go @@ -11,8 +11,6 @@ type TalkConfigService struct { *cool.Service } -var TalkConfigServiceS = NewTalkConfigService() - func NewTalkConfigService() *TalkConfigService { return &TalkConfigService{ @@ -22,9 +20,9 @@ func NewTalkConfigService() *TalkConfigService { } -func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig { +func (s *TalkConfigService) GetCache(flag int) model.MineralCollectionConfig { - var config []model.MineralCollectionConfig + var config model.MineralCollectionConfig cool.DBM(s.Model).Where("type", flag).Cache(gdb.CacheOption{ // Duration: time.Hour,