From 09e3d419281c01fc08a4997a230bbcf8cc2f45fd Mon Sep 17 00:00:00 2001 From: chenxi Date: Thu, 11 May 2023 20:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/controller/battle_controller.lua | 1 + lua/app/module/task/task_manager.lua | 44 +++++++++++++++++-- lua/app/userdata/bag/item_data.lua | 22 +++++++--- lua/app/userdata/bag/item_entity.lua | 9 +--- lua/app/userdata/hero/hero_entity.lua | 1 + lua/app/userdata/task/daily_task_data.lua | 9 ++-- 6 files changed, 66 insertions(+), 20 deletions(-) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 42389623..fce378e1 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -2154,6 +2154,7 @@ function BattleController:battleEnd() self.battleUI:enableUITouch() end self:controllBattleEnd() + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_BATTLE_VICTORY) end, 1) end diff --git a/lua/app/module/task/task_manager.lua b/lua/app/module/task/task_manager.lua index db893148..5eb73141 100644 --- a/lua/app/module/task/task_manager.lua +++ b/lua/app/module/task/task_manager.lua @@ -90,14 +90,14 @@ function TaskManager:clear() self.registerTaskInfo = nil end -function TaskManager:addTaskProgress(type, params1) +function TaskManager:addTaskProgress(type, ...) if not self.registerTaskInfo then return end local func = TaskManager.TYPE_DEAL_FUNC[type] if func then - func(self, params1) + func(self, ...) end end @@ -126,7 +126,7 @@ function TaskManager:xKillMonster(params) self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER, num) end -function TaskManager:xWatchAd(params) +function TaskManager:xWatchAd() self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_WATCH_AD, 1) end @@ -134,11 +134,47 @@ function TaskManager:completeDailyTask() self:dispatchTask(GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK, 1) end +function TaskManager:xGoldGot(count) + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GOLD_GOT, count) +end + +function TaskManager:xGoldCost(count) + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GOLD_COST, count) +end + +function TaskManager:xGemGot(count) + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GEM_GOT, count) +end + +function TaskManager:xGemCost(count) + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GEM_COST, count) +end + +function TaskManager:xBattleVictory() + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_BATTLE_VICTORY, 1) +end + +function TaskManager:xHeroLvUp() + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP, 1) +end + +function TaskManager:xHeroFragmentGot(count) + self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_HERO_FRAGMENT_GOT, count) +end + ---- 没有特殊说明,方法均返回任务增量 TaskManager.TYPE_DEAL_FUNC = { - [GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER] = TaskManager.xKillMonster, [GConst.TaskConst.TASK_TYPE.X_WATCH_AD] = TaskManager.xWatchAd, + [GConst.TaskConst.TASK_TYPE.X_GOLD_GOT] = TaskManager.xGoldGot, + [GConst.TaskConst.TASK_TYPE.X_GEM_GOT] = TaskManager.xGemGot, + [GConst.TaskConst.TASK_TYPE.X_GOLD_COST] = TaskManager.xGoldCost, + [GConst.TaskConst.TASK_TYPE.X_GEM_COST] = TaskManager.xGemCost, + [GConst.TaskConst.TASK_TYPE.X_BATTLE_VICTORY] = TaskManager.xBattleVictory, + [GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP] = TaskManager.xHeroLvUp, + [GConst.TaskConst.TASK_TYPE.X_HERO_FRAGMENT_GOT] = TaskManager.xHeroFragmentGot, [GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK] = TaskManager.completeDailyTask, + + -- [GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER] = TaskManager.xKillMonster, } function TaskManager:taskGoto(taskType) diff --git a/lua/app/userdata/bag/item_data.lua b/lua/app/userdata/bag/item_data.lua index a4f3eb36..00205f59 100644 --- a/lua/app/userdata/bag/item_data.lua +++ b/lua/app/userdata/bag/item_data.lua @@ -134,17 +134,24 @@ function ItemData:addItem(data, itemGetType) self:_addItemNumById(data.id, data.count) - if data.id == GConst.ItemConst.ITEM_ID_GEM or data.id == GConst.ItemConst.ITEM_ID_GOLD then + if data.id == GConst.ItemConst.ITEM_ID_GEM then if data.count < 0 then + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_GEM_COST, -data.count) BIReport:postGemUse(data.count, itemGetType, data.id) else + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_GEM_GOT, data.count) BIReport:postGemGet(data.count, itemGetType, data.id) end - if data.id == GConst.ItemConst.ITEM_ID_GEM then - CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserAdd("user_gem", data.count) - elseif data.id == GConst.ItemConst.ITEM_ID_GOLD then - CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserAdd("user_gold", data.count) + CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserAdd("user_gem", data.count) + elseif data.id == GConst.ItemConst.ITEM_ID_GOLD then + if data.count < 0 then + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_GOLD_COST, -data.count) + BIReport:postGemUse(data.count, itemGetType, data.id) + else + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_GOLD_GOT, data.count) + BIReport:postGemGet(data.count, itemGetType, data.id) end + CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserAdd("user_gold", data.count) elseif data.id == GConst.ItemConst.ITEM_ID_VIT then if data.count < 0 then BIReport:postVitUse(data.count) @@ -179,11 +186,14 @@ function ItemData:_addItemNumById(id, num) if self.items[id] then self.items[id]:addNum(num) else - if id == GConst.ItemConst.ITEM_ID_VIT then + if id == ItemConst.ITEM_ID_VIT then DataManager.PlayerData:setVit(num) end self:_add(id, num) end + if num > 0 and self.items[id]:getItemType() == ItemConst.ITEM_TYPE.HERO_FRAGMENT then + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_HERO_FRAGMENT_GOT, num) + end if id == ItemConst.ITEM_ID_VIT and isFull then local maxVit = DataManager.PlayerData:getMaxVit() local currentCount = DataManager.PlayerData:getVit() diff --git a/lua/app/userdata/bag/item_entity.lua b/lua/app/userdata/bag/item_entity.lua index a954c63f..02a0e9ec 100644 --- a/lua/app/userdata/bag/item_entity.lua +++ b/lua/app/userdata/bag/item_entity.lua @@ -72,11 +72,6 @@ function ItemEntity:getIconRes() return GConst.ATLAS_PATH.ICON_ITEM, self.config.icon end --- 类型 -function ItemEntity:getType() - return GConst.ENTITY_TYPE.ITEM -end - -- 其他参数 function ItemEntity:getParam() return self.config.parameter @@ -92,8 +87,8 @@ function ItemEntity:getDesc() return I18N:getText("item", self.data.id, "desc") end -function ItemEntity:getEntityType() - return GConst.ENTITY_TYPE.ITEM_ENTITY +function ItemEntity:getItemType() + return self.config.type end return ItemEntity \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index 71698934..98291d5a 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -31,6 +31,7 @@ function HeroEntity:setLv(lv) return end self.data.lv = lv + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP) self:setDirty() end diff --git a/lua/app/userdata/task/daily_task_data.lua b/lua/app/userdata/task/daily_task_data.lua index 55f64cb1..457bcf81 100644 --- a/lua/app/userdata/task/daily_task_data.lua +++ b/lua/app/userdata/task/daily_task_data.lua @@ -206,18 +206,21 @@ function DailyTaskData:getIfCanClaimTask(task) return task.progress <= task.needProgress end -function DailyTaskData:addTaskProgress(task, count) +function DailyTaskData:addTaskProgress(task, taskType, count) local currProgress = task.progress if currProgress >= task.needProgress then return end local can = self:getIfCanClaimTask(task) task.progress = task.progress + count - self:markDailyTaskDirty() if not can and self:getIfCanClaimTask(task) then EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.DAILY_TASK_ADD_PROGRESS, task.id, task.taskId, currProgress, task.needProgress) + if task.type == 1 and task.reset == 1 and taskType ~= GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK then + ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK) + end BIReport:postDailyTaskFinish(BIReport.TASK_TYPE.DAILY, task.id, task.taskId, task.refresh) end + self:markDailyTaskDirty() end function DailyTaskData:registerTask(taskType) @@ -225,7 +228,7 @@ function DailyTaskData:registerTask(taskType) local list = self:getTaskListByType(taskType) if #list > 0 then for _, task in ipairs(list) do - self:addTaskProgress(task, count) + self:addTaskProgress(task, taskType, count) end end end)