From 3efbba3883521f1509d86bc2dfdb2032c10d8e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Wed, 31 Dec 2025 21:00:29 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(task):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A5=96=E5=8A=B1=E7=B3=BB=E7=BB=9F=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E5=A5=96=E5=8A=B1=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除废弃的任务相关代码文件,包括task/list.go和task/list_daily.go, 以及相关的模型定义config_task表和PetReward服务。 修改任务奖励获取方式,从原有的TaskResultMap改为通过数据库配置获取, 新增TaskService.Get方法用于获取任务配置信息。 --- feat(boss): 优化 --- logic/controller/fight_base.go | 9 - logic/controller/fight_boss.go | 31 +- logic/controller/user_task.go | 11 +- logic/service/fight/action.go | 3 + logic/service/task/list.go | 346 ------------------ logic/service/task/list_daily.go | 56 --- logic/service/task/task.go | 36 ++ modules/blazing/service/pet.go | 3 + .../config/model/{TaskConfig.go => task.go} | 5 +- .../config/service/{PetReward.go => pet.go} | 17 + modules/config/service/shiny.go | 19 +- modules/config/service/task.go | 14 + 12 files changed, 117 insertions(+), 433 deletions(-) delete mode 100644 logic/service/task/list.go delete mode 100644 logic/service/task/list_daily.go create mode 100644 logic/service/task/task.go rename modules/config/model/{TaskConfig.go => task.go} (79%) rename modules/config/service/{PetReward.go => pet.go} (60%) diff --git a/logic/controller/fight_base.go b/logic/controller/fight_base.go index 5547c3d3d..6dbc1f1d2 100644 --- a/logic/controller/fight_base.go +++ b/logic/controller/fight_base.go @@ -2,7 +2,6 @@ package controller import ( "blazing/common/socket/errorcode" - "sync/atomic" "blazing/logic/service/fight" "blazing/logic/service/fight/info" @@ -41,14 +40,6 @@ func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) return nil, err } - battleMode := atomic.LoadUint32(&c.Fightinfo.Mode) - if battleMode == 0 { - return nil, errorcode.ErrorCodes.ErrBattleNotStarted - } - if battleMode == 1 { - return nil, errorcode.ErrorCodes.ErrCannotFleePlayerBattle - } - defer c.FightC.Over(c, info.BattleOverReason.PlayerEscape) return nil, 0 } diff --git a/logic/controller/fight_boss.go b/logic/controller/fight_boss.go index 3d5756b68..0f0348155 100644 --- a/logic/controller/fight_boss.go +++ b/logic/controller/fight_boss.go @@ -8,6 +8,7 @@ import ( "blazing/logic/service/fight" "blazing/logic/service/fight/info" + "blazing/logic/service/task" "blazing/logic/service/player" "blazing/modules/blazing/model" @@ -140,17 +141,29 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *pla if p.Info.GetTask(taskID) == model.Unaccepted { p.Info.SetTask(taskID, model.Completed) //设置完成任务 - monsterInfo.PetList[0].Downgrade(1) - petID := monsterInfo.PetList[0].ID + gift := task.GetTaskInfo(uint32(taskID), 0) + if gift != nil { - newPet := model.GenPetInfo(int(petID), -1, -1, 0, 1, nil) - p.Service.Pet.PetAdd(newPet) + res := &info.S2C_GET_BOSS_MONSTER{ + BonusID: uint32(taskID), + } + if gift.Pet != nil { + p.Service.Pet.PetAdd(gift.Pet) + res.PetID = gift.Pet.ID + res.CaptureTm = gift.Pet.CatchTime + + } + for _, item := range gift.ItemList { + success := p.ItemAdd(item.ItemId, item.ItemCnt) + if success { + res.ItemList = append(res.ItemList, item) + } + + } + + p.SendPackCmd(8004, res) + } - p.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{ - BonusID: uint32(taskID), - PetID: petID, - CaptureTm: newPet.CatchTime, - }) } } diff --git a/logic/controller/user_task.go b/logic/controller/user_task.go index de44a1346..9b03b207f 100644 --- a/logic/controller/user_task.go +++ b/logic/controller/user_task.go @@ -59,16 +59,15 @@ func (h Controller) CompleteTask(data1 *task.CompleteTaskInboundInfo, c *player. ItemList: make([]data.ItemInfo, 0), } - taskInfo := task.Get_Task_Info(*data1) + taskInfo := task.GetTaskInfo(data1.TaskId, data1.OutState) if taskInfo == nil { return result, 0 } - if taskInfo.PetTypeId != 0 { - newPet := model.GenPetInfo(int(taskInfo.PetTypeId), 31, -1, 0, 50, nil) - result.PetTypeId = newPet.ID - c.Service.Pet.PetAdd(newPet) - result.CaptureTime = newPet.CatchTime + if taskInfo.Pet != nil { + + c.Service.Pet.PetAdd(taskInfo.Pet) + result.CaptureTime = taskInfo.Pet.CatchTime } for _, item := range taskInfo.ItemList { diff --git a/logic/service/fight/action.go b/logic/service/fight/action.go index cfe7ab9f2..08906a29e 100644 --- a/logic/service/fight/action.go +++ b/logic/service/fight/action.go @@ -33,6 +33,9 @@ func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) { cool.Logger.Debug(context.Background(), " 战斗chan已关闭") return } + if f.Info.Status != info.BattleMode.FIGHT_WITH_NPC { + return + } // case *action.EscapeAction: // f.FightOverInfo.WinnerId = b2.GetPlayerID() //对方胜利 // f.FightOverInfo.Reason = a.Reason diff --git a/logic/service/task/list.go b/logic/service/task/list.go deleted file mode 100644 index 552a14bbd..000000000 --- a/logic/service/task/list.go +++ /dev/null @@ -1,346 +0,0 @@ -package task - -import ( - "blazing/common/data" - "sync" -) - -// RegisterTask 注册任务奖励 -// 参数:任务ID、分支(OutState)、物品列表、精灵类型(0=无) -func RegisterTask(taskID uint32, outState uint32, items []data.ItemInfo, petType uint32) { - if _, ok := TaskResultMap[taskID]; !ok { - TaskResultMap[taskID] = make(map[uint32]TaskResult) - } - TaskResultMap[taskID][outState] = TaskResult{ - ItemList: items, - PetTypeId: petType, - } -} - -func init() { - // -------------------------- 新手任务 -------------------------- - RegisterTask(85, 1, []data.ItemInfo{ // 新手任务1(默认分支1) - {100027, 1}, // 新手帽 - {100028, 1}, // 新手腰带 - {500001, 1}, // 精灵仓库 - {500502, 1}, // 精灵恢复仓 - }, 0) - - RegisterTask(86, 1, []data.ItemInfo{}, 1) // 新手任务2(分支1:布布种子) - RegisterTask(86, 2, []data.ItemInfo{}, 7) // 新手任务2(分支2:小火猴) - RegisterTask(86, 3, []data.ItemInfo{}, 4) // 新手任务2(分支3:伊优) - RegisterTask(86, 0, []data.ItemInfo{}, 1) // 新手任务2(默认分支:布布种子) - - RegisterTask(87, 0, []data.ItemInfo{ // 新手任务3(默认分支) - {300001, 5}, // 普通胶囊x5 - {300011, 3}, // 初级体力药剂x3 - }, 0) - - RegisterTask(88, 1, []data.ItemInfo{ // 新手任务4(默认分支) - {1, 50000}, // 赛尔豆x50000 - {3, 50000}, // 累积经验x50000 - {5, 20}, // 金豆x20 - {300650, 3}, // 全能学习力遗忘器x3 - // {300651, 6}, // 全能学习力注入器x6 - }, 0) - - // -------------------------- 普通任务(无精灵奖励) -------------------------- - RegisterTask(90, 0, []data.ItemInfo{ // 克洛斯星的皮皮 - {1, 1000}, // 赛尔豆x1000 - {3, 1000}, // 经验x1000 - }, 0) - - RegisterTask(8, 0, []data.ItemInfo{{500510, 1}}, 0) // 西塔的珍贵回忆(记忆晶体x1) - RegisterTask(9, 0, []data.ItemInfo{{100059, 1}}, 0) // 进入神秘通道(电能锯子x1) - RegisterTask(10, 0, []data.ItemInfo{}, 0) // 神秘通道拼图(无奖励) - RegisterTask(12, 0, []data.ItemInfo{}, 0) // 精灵广场拿石头(无奖励) - RegisterTask(19, 0, []data.ItemInfo{{3, 3000}}, 0) // 先锋队招募(积累经验x3000) - RegisterTask(25, 0, []data.ItemInfo{{400501, 10}}, 0) // 新船员的考验(神奇扭蛋牌x10) - - RegisterTask(37, 0, []data.ItemInfo{ // 帕诺星系星球测绘 - {1, 3000}, // 赛尔豆x3000 - - {100178, 1}, // 勘察头盔x1 - {100179, 1}, // 勘察护腕x1 - {100180, 1}, // 勘察腰带x1 - {100181, 1}, // 勘察军靴x1 - }, 0) - - RegisterTask(47, 0, []data.ItemInfo{ // 突围磁风暴 - {3, 5000}, // 累积经验x5000 - {1, 5000}, // 赛尔豆x5000 - {500585, 1}, // 磁力光束枪台x1 - }, 0) - - RegisterTask(48, 0, []data.ItemInfo{ // 神秘失踪的爱丽丝 - {3, 3000}, // 累积经验x3000 - {1, 2000}, // 赛尔豆x2000 - //{700452, 2}, // 中型智慧芯片x2 - }, 0) - - RegisterTask(52, 0, []data.ItemInfo{ // 谁偷走了雪球能源? - {3, 3000}, // 累积经验x3000 - {400021, 10}, // 雪球能源x10 - {100254, 1}, // 斯诺纪念x1 - }, 0) - - RegisterTask(54, 0, []data.ItemInfo{ // 米鲁族的两个小不点 - {3, 5000}, // 累积经验x5000 - {400021, 10}, // 雪球能源x10 - }, 0) - - RegisterTask(57, 0, []data.ItemInfo{ // 米鲁族食王选拔赛 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(58, 0, []data.ItemInfo{ // 斯诺岩洞的不解之谜 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - {400021, 10}, // 雪球能源x10 - }, 0) - - RegisterTask(63, 0, []data.ItemInfo{ // 新型试作机SR-01同步调试 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(64, 0, []data.ItemInfo{ // 铸造斯诺冰冠 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - {400021, 10}, // 雪球能源x10 - }, 0) - - RegisterTask(65, 0, []data.ItemInfo{ // 露希欧星勘察 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(66, 0, []data.ItemInfo{ // 合金强化试验 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(68, 0, []data.ItemInfo{ // 资料室的神秘事件 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(69, 0, []data.ItemInfo{ // 宇宙遭遇站 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(70, 0, []data.ItemInfo{ // 船体紧急修复 - {3, 3000}, // 累积经验x3000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(72, 0, []data.ItemInfo{ // 船长搜救任务 - {3, 2000}, // 累积经验x2000 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(73, 0, []data.ItemInfo{ // 秘制改良机SR-02 - {100303, 1}, // SR-02铠甲x1 - {400055, 30}, // 变形能量块x30 - {3, 3000}, // 累积经验x3000 - }, 0) - - RegisterTask(74, 0, []data.ItemInfo{{3, 3000}}, 0) // 露希欧星历险(积累经验x3000) - - RegisterTask(75, 0, []data.ItemInfo{ // 哈莫的童年片段一 - {3, 3000}, // 累积经验x3000 - {100324, 1}, // 龙之纪念x1 - }, 0) - - RegisterTask(79, 0, []data.ItemInfo{ // 寻找哈莫雷特的族人 - {3, 3000}, // 累积经验x3000 - {1, 2000}, // 赛尔豆x2000 - }, 0) - - RegisterTask(80, 0, []data.ItemInfo{ // 重铸贾斯丁站长 - {3, 2000}, // 累积经验x2000 - {1, 3000}, // 赛尔豆x3000 - }, 0) - - RegisterTask(81, 0, []data.ItemInfo{ // 守候宿命的追随者 - {3, 1000}, // 累积经验x1000 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(83, 0, []data.ItemInfo{ // 光暗之迷 - {3, 1000}, // 累积经验x1000 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(84, 0, []data.ItemInfo{ // 星球改造计划 - {3, 2000}, // 累积经验x2000 - {1, 2000}, // 赛尔豆x2000 - }, 0) - - RegisterTask(89, 0, []data.ItemInfo{ // 试炼之塔的磨练 - {3, 500}, // 累积经验x500 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(91, 0, []data.ItemInfo{ // 月光下的约定 - {3, 2000}, // 累积经验x2000 - {1, 2000}, // 赛尔豆x2000 - }, 246) - - RegisterTask(93, 0, []data.ItemInfo{ // 云霄星的新来客 - {3, 1000}, // 累积经验x1000 - {1, 500}, // 赛尔豆x500 - }, 0) - - RegisterTask(94, 0, []data.ItemInfo{ // 初识星球能源 - {3, 500}, // 累积经验x500 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(96, 0, []data.ItemInfo{ // 旅途中的伙伴 - {3, 500}, // 累积经验x500 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(97, 0, []data.ItemInfo{ // 我是音乐小麦霸 - {3, 1000}, // 累积经验x1000 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(98, 0, []data.ItemInfo{ // 尼布守卫战 - {3, 2000}, // 累积经验x2000 - {1, 1000}, // 赛尔豆x1000 - }, 0) - - RegisterTask(201, 0, []data.ItemInfo{{100062, 1}}, 0) // 教官考核(教官指挥棒x1) - RegisterTask(300, 0, []data.ItemInfo{}, 300) // 领取谱尼真身(谱尼的精元x1) - - // -------------------------- 带精灵奖励的任务 -------------------------- - RegisterTask(28, 0, []data.ItemInfo{}, 102) // 遗迹中的精灵信号(奇塔,类型102) - RegisterTask(40, 0, []data.ItemInfo{}, 139) // 时空之门(迪卢卡,类型139) - - RegisterTask(49, 0, []data.ItemInfo{ // 密林中的托尼(托尼+物品) - // {700452, 2}, // 中型智慧芯片x2 - }, 158) // 托尼(类型158) - - RegisterTask(71, 0, []data.ItemInfo{ // 赛尔号大整修(TOE+物品) - {3, 1000}, // 累积经验x1000 - {1, 1000}, // 赛尔豆x1000 - }, 213) // TOE(类型213) - - RegisterTask(92, 0, []data.ItemInfo{ // 站长归来(尼布+物品) - {3, 2000}, // 累积经验x2000 - {1, 2000}, // 赛尔豆x2000 - }, 95) // 尼布(类型95) - - RegisterTask(133, 0, []data.ItemInfo{ // 寻找迷失的心(史空+物品) - {3, 2000}, // 累积经验x2000 - {1, 2000}, // 赛尔豆x2000 - }, 381) // 史空(类型381) - - // -------------------------- 多分支任务 -------------------------- - RegisterTask(95, 1, []data.ItemInfo{ // 宇宙中的黑色旋涡(分支1:刺蜂套装) - {3, 4000}, // 累积经验x4000 - {1, 2000}, // 赛尔豆x2000 - {100346, 1}, // 刺蜂重盔x1 - {100347, 1}, // 刺蜂护肩x1 - {100348, 1}, // 刺蜂腰带x1 - {100349, 1}, // 刺蜂滚轮x1 - }, 0) - - RegisterTask(95, 2, []data.ItemInfo{ // 宇宙中的黑色旋涡(分支2:锡蝶套装) - {3, 4000}, // 累积经验x4000 - {1, 2000}, // 赛尔豆x2000 - {100350, 1}, // 锡蝶重盔x1 - {100351, 1}, // 锡蝶护肩x1 - {100352, 1}, // 锡蝶腰带x1 - {100353, 1}, // 锡蝶滚轮x1 - }, 0) - -} - -// 任务触发里程碑 - -// func Test_event(b *testing.T) { - -// topic := bus.NewTopic[*Task]() //直接注册到用户 -// for i := 0; i < 1; i++ { -// isdone := false -// t := topic.Sub(func(v *Task) { //用户初始化时注册里程碑 -// if v.done { //如果任务完成 -// isdone = true -// fmt.Println(v.id, "任务完成") -// return -// } - -// // if v.cfunc != nil { -// // v.cont = v.cfunc(v.cont) //增加计数 -// // } - -// if v.cont > 5 { //如果计数达到,标记任务完成 -// v.done = true -// } -// fmt.Println(v.id, "当前任务计数", v.cont, "是否完成", v.done) - -// }) -// if isdone { //如果任务完成,取消注册 -// t.Cancel() -// } - -// } -// // task1 := &Task{id: 1, cfunc: func(t uint32) uint32 { //满足任务1后推定 - -// // //fmt.Println(1, "当前任务计数", t) -// // //实现自定义逻辑 -// // //增加用户计数 -// // //增加服务器总计数 -// // return t + 1 - -// // }} -// topic.Pub(task1) -// topic.Pub(task1) -// topic.Pub(&Task{id: 2, done: true}) - -// topic.Pub(task1) //发送事件 -// task1.Complete() - -// fmt.Println("当前任务状态", task1.IsDone()) -// } - -type TaskTree struct { - AllTasks []*Task //任务集合 - mu sync.Mutex -} - -// Various event types -const EventA = 0x01 - -type Task struct { - id uint32 - //cfunc func(uint32) uint32 - cont uint32 - done bool -} - -func (e *Task) IsDone() bool { - return e.done -} -func (e *Task) Complete() { - e.done = true -} -func (e *Task) EventID() string { - return "Task" -} - -// Event type for testing purposes -type Event struct { - Data string - type1 uint32 -} - -// Type returns the event type -func (ev Event) Type() uint32 { - return ev.type1 -} diff --git a/logic/service/task/list_daily.go b/logic/service/task/list_daily.go deleted file mode 100644 index 8ff09b1bc..000000000 --- a/logic/service/task/list_daily.go +++ /dev/null @@ -1,56 +0,0 @@ -package task - -import ( - "blazing/common/data" -) - -type TaskResult struct { - PetTypeId uint32 `json:"petTypeId" description:"发放的精灵ID"` // 发放的精灵ID, - - ItemList []data.ItemInfo `json:"itemList" description:"发放物品的数组"` // 发放物品的数组, -} - -var TaskResultMap = make(map[uint32]map[uint32]TaskResult) - -// 添加默认分支0 -func Get_Task_Info(v CompleteTaskInboundInfo) *TaskResult { - - t, ok := TaskResultMap[v.TaskId][v.OutState] - if ok { - - return &t - } else { - t, ok := TaskResultMap[v.TaskId][0] - if ok { - return &t - } - } - return nil -} -func init() { - // 定义通用奖励:经验奖励(ItemId:3,数量20000) - expReward := []data.ItemInfo{{ItemId: 3, ItemCnt: 20000}} - // 定义扭蛋牌奖励(ItemId:400501,数量5) - eggReward := []data.ItemInfo{{ItemId: 400501, ItemCnt: 5}} - - // 批量初始化任务ID 401-407(奖励均为经验) - for taskID := 401; taskID <= 407; taskID++ { - // 为每个任务ID初始化内层map - TaskResultMap[uint32(taskID)] = make(map[uint32]TaskResult) - // 设置状态0对应的奖励(与401格式一致) - TaskResultMap[uint32(taskID)][0] = TaskResult{ - ItemList: expReward, - } - } - - // 单独初始化任务462(奖励为扭蛋牌) - TaskResultMap[462] = make(map[uint32]TaskResult) - TaskResultMap[462][0] = TaskResult{ - ItemList: eggReward, - } - - // 后续若有其他任务,按相同格式添加即可 - // 例如: - // TaskResultMap[xxx] = make(map[uint32]TaskResult) - // TaskResultMap[xxx][0] = TaskResult{ItemList: ...} -} diff --git a/logic/service/task/task.go b/logic/service/task/task.go new file mode 100644 index 000000000..55610c13a --- /dev/null +++ b/logic/service/task/task.go @@ -0,0 +1,36 @@ +package task + +import ( + "blazing/common/data" + + "blazing/modules/blazing/model" + "blazing/modules/config/service" +) + +type TaskResult struct { + Pet *model.PetInfo `json:"petTypeId" description:"发放的精灵ID"` // 发放的精灵ID, + + ItemList []data.ItemInfo `json:"itemList" description:"发放物品的数组"` // 发放物品的数组, +} + +func GetTaskInfo(id, ot uint32) *TaskResult { + ret := &TaskResult{} + + r := service.NewTaskService().Get(id, ot) + if r == nil { + return nil + } + + pet := service.NewPetRewardService().Get(r.ElfRewardIds) + if pet != nil { + ret.Pet = model.GenPetInfo(int(pet.MonID), int(pet.Lv), int(pet.Nature), int(pet.Effect), int(pet.DV), nil) + } + + for _, itemID := range r.ItemRewardIds { + iteminfo := service.NewItemService().GetItemCount(itemID) + ret.ItemList = append(ret.ItemList, data.ItemInfo{ItemId: itemID, ItemCnt: iteminfo.ItemCnt}) + + } + + return nil +} diff --git a/modules/blazing/service/pet.go b/modules/blazing/service/pet.go index cd52f752e..ac8e4e639 100644 --- a/modules/blazing/service/pet.go +++ b/modules/blazing/service/pet.go @@ -94,6 +94,9 @@ func (s *PetService) Pet_del(cachetime uint32) { // 精灵真正添加后的捕捉时间才是真正的时间 func (s *PetService) PetAdd(y *model.PetInfo) { + if y == nil { + return + } sql := fmt.Sprintf(` UPDATE %s SET max_ts = CASE diff --git a/modules/config/model/TaskConfig.go b/modules/config/model/task.go similarity index 79% rename from modules/config/model/TaskConfig.go rename to modules/config/model/task.go index 87b585228..990bc6ea2 100644 --- a/modules/config/model/TaskConfig.go +++ b/modules/config/model/task.go @@ -14,7 +14,10 @@ type TaskConfig struct { *cool.Model // 核心字段 - TaskId uint32 `gorm:"not null;uniqueIndex;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"` + TaskId uint32 `gorm:"not null;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"` + OutState uint32 `gorm:"not null;default:0;comment:'任务分支'" json:"out_state" description:"任务分支"` + //父级任务 + ParentTaskId uint32 `gorm:"not null;default:0;comment:'父级任务ID'" json:"parent_task_id" description:"父级任务ID"` // 奖励配置 ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"` diff --git a/modules/config/service/PetReward.go b/modules/config/service/pet.go similarity index 60% rename from modules/config/service/PetReward.go rename to modules/config/service/pet.go index 242cbe496..a3ae57fe8 100644 --- a/modules/config/service/PetReward.go +++ b/modules/config/service/pet.go @@ -3,6 +3,8 @@ package service import ( "blazing/cool" "blazing/modules/config/model" + + "github.com/gogf/gf/v2/database/gdb" ) type PetRewardService struct { @@ -23,3 +25,18 @@ func (s *PetRewardService) GetEgg() model.PetReward { return item } +func (s *PetRewardService) Get(id uint32) *model.PetReward { + if id == 0 { + return nil + } + var item *model.PetReward + cool.DBM(s.Model).Where("id", 1). + Cache(gdb.CacheOption{ + // Duration: time.Hour, + + Force: false, + }).Scan(&item) + + return item + +} diff --git a/modules/config/service/shiny.go b/modules/config/service/shiny.go index 82c9fe385..9cf9785ae 100644 --- a/modules/config/service/shiny.go +++ b/modules/config/service/shiny.go @@ -48,7 +48,10 @@ func (s *ShinyService) RandShiny(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{ + cool.DBM(s.Model). + Wheref(`bind_elf_ids @> ?::jsonb`, id). + Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array"). + Where("is_enabled", 1).Cache(gdb.CacheOption{ // Duration: time.Hour, Force: false, @@ -78,11 +81,15 @@ func (s *ShinyService) FixShiny(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, + cool.DBM(s.Model). + Wheref(`bind_elf_ids @> ?::jsonb`, id). + Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array"). + Where("is_enabled", 1). + Cache(gdb.CacheOption{ + // Duration: time.Hour, - Force: false, - }).Scan(&ret) + Force: false, + }).Scan(&ret) rets := utils.ToMap(ret, func(t model.ColorfulSkin) uint32 { return uint32(t.ID) @@ -98,7 +105,7 @@ func (s *ShinyService) FixShiny(id uint32) *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) + m.Increment("usage_count", 1) return &t } diff --git a/modules/config/service/task.go b/modules/config/service/task.go index 4123d7407..bbaedfbb9 100644 --- a/modules/config/service/task.go +++ b/modules/config/service/task.go @@ -3,6 +3,8 @@ package service import ( "blazing/cool" "blazing/modules/config/model" + + "github.com/gogf/gf/v2/database/gdb" ) type TaskService struct { @@ -16,3 +18,15 @@ func NewTaskService() *TaskService { }, } } +func (s *TaskService) Get(id, os uint32) *model.TaskConfig { + var item *model.TaskConfig + cool.DBM(s.Model).Where("task_id", id).Where("out_state", os). + Cache(gdb.CacheOption{ + // Duration: time.Hour, + + Force: false, + }).Scan(&item) + + return item + +}