From 7508f219d29e6e415ae717b0f9b7d428d1ec99b8 Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 24 Apr 2023 10:30:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=93=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/common/bi_report.lua | 3 ++- lua/app/global/global_func.lua | 5 ++++ lua/app/module/chapter/chapter_manager.lua | 24 ++++++++++++++--- lua/app/server/data/server_item_data.lua | 4 +-- .../server/manager/server_chapter_manager.lua | 26 +++++++++++++++++++ lua/app/server/server_data_const.lua | 1 + lua/app/server/server_data_manager.lua | 1 + lua/app/ui/main_city/component/main_comp.lua | 7 ++++- lua/app/userdata/bag/item_data.lua | 4 +++ lua/app/userdata/chapter/chapter_data.lua | 10 ++----- lua/app/userdata/player/player_data.lua | 7 +++++ 11 files changed, 77 insertions(+), 15 deletions(-) diff --git a/lua/app/common/bi_report.lua b/lua/app/common/bi_report.lua index f5d48f98..687299f5 100644 --- a/lua/app/common/bi_report.lua +++ b/lua/app/common/bi_report.lua @@ -117,7 +117,8 @@ BIReport.RUNE_OPT_TYPE = { BIReport.ITEM_GET_TYPE = { NEW_PLAYER_INITIAL = "NewPlayerInitial", -- 新玩家创号自带 UPGRADE_HERO = "UpgradeHero", - FIGHT_END = "FightEnd", + CHAPTER_FIGHT_START = "ChapterFightStart", + CHAPTER_FIGHT_END = "ChapterFightEnd", CHAPTER_BOX = "ChapterBox" } diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 6a4c1c6b..3ec52c00 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -544,6 +544,11 @@ function GFunc.getConstValue(key) return ConstCfg[key] and ConstCfg[key].value or 0 end +function GFunc.getConstReward(key) + local ConstCfg = ConfigManager:getConfig("const") + return ConstCfg[key] and ConstCfg[key].reward +end + function GFunc.getTargetAnchoredPosition(targetGo, parent) local rectTransform = targetGo:getComponent(GConst.TYPEOF_UNITY_CLASS.RECTTRANSFORM) local rect = rectTransform.rect diff --git a/lua/app/module/chapter/chapter_manager.lua b/lua/app/module/chapter/chapter_manager.lua index ec539378..3d0023b3 100644 --- a/lua/app/module/chapter/chapter_manager.lua +++ b/lua/app/module/chapter/chapter_manager.lua @@ -24,8 +24,26 @@ function ChapterManager:startFight() GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_8)) return end - ---- 通信 - ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE) + local cost = DataManager.ChapterData:getFightCost() + local vitCostNum = 0 + if cost then + vitCostNum = GFunc.getRewardNum(cost) + end + if vitCostNum > DataManager.BagData.ItemData:getVit() then + GFunc.showItemNotEnough(GConst.ItemConst.ITEM_ID_VIT) + return + end + local parmas = { + id = DataManager.ChapterData:getChapterId() + } + ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.START_FIGHT, parmas, function(result) + if result.status == 0 then + if result.cost then + GFunc.addCosts(result.cost, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_START) + end + ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE) + end + end) end function ChapterManager:endFight(id, combatReport) @@ -53,7 +71,7 @@ function ChapterManager:endFight(id, combatReport) if combatReport.victory and DataManager.ChapterData:getChapterId() == DataManager.ChapterData:getMaxChapterId() + 1 then DataManager.ChapterData:goNextChapter() end - GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.FIGHT_END) + GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_END) local newRewards = {} if result.rewards then GFunc.mergeRewards2(result.rewards, newRewards) diff --git a/lua/app/server/data/server_item_data.lua b/lua/app/server/data/server_item_data.lua index e4539a96..dd907a74 100644 --- a/lua/app/server/data/server_item_data.lua +++ b/lua/app/server/data/server_item_data.lua @@ -121,7 +121,7 @@ end function ServerItemData:resetVitRecoverTime() local maxCount = self:getMaxVit() - local ServerGameData = require "app/server/data/server_game_data" + local ServerGameData = require "app/server/server_game_data" local currentCount = ServerGameData.PlayerData:getVit() if currentCount >= maxCount then -- 已经达到上限 return @@ -131,7 +131,7 @@ function ServerItemData:resetVitRecoverTime() if currentCount >= maxCount then -- 已经达到上限 return end - for i,v in ipairs(self.recoveries) do + for i,v in ipairs(self.data.recoveries) do if v.cfg_id == GConst.ItemConst.ITEM_ID_VIT then self.data.recoveries[i].ts = Time:getServerTime() end diff --git a/lua/app/server/manager/server_chapter_manager.lua b/lua/app/server/manager/server_chapter_manager.lua index 7d61a2cb..c3b2fba8 100644 --- a/lua/app/server/manager/server_chapter_manager.lua +++ b/lua/app/server/manager/server_chapter_manager.lua @@ -31,6 +31,32 @@ function ServerChapterManager:openBox(params, callback) end end +function ServerChapterManager:startFight(params, callback) + local result = { + status = 1 + } + local cost = GFunc.getConstReward("chapter_cost") + if cost == nil then + if callback then + callback(result) + end + return + end + local vitCostNum = GFunc.getRewardNum(cost) + local ServerGameData = ServerDataManager:getServerGameData() + if vitCostNum > ServerGameData.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) then + if callback then + callback(result) + end + return + end + result.cost = ServerGameData:addCosts({cost}) + result.status = 0 + if callback then + callback(result) + end +end + function ServerChapterManager:endFight(params, callback) local result = { status = 1 diff --git a/lua/app/server/server_data_const.lua b/lua/app/server/server_data_const.lua index ee4307eb..93abbc2c 100644 --- a/lua/app/server/server_data_const.lua +++ b/lua/app/server/server_data_const.lua @@ -10,6 +10,7 @@ ServerDataConst.DATA_OP_BEHAVIOR = { CROSS_DAY = "CROSS_DAY", UPDATE_FORMATION = "UPDATE_FORMATION", UPGRADE_HERO = "UPGRADE_HERO", + START_FIGHT = "START_FIGHT", END_FIGHT = "END_FIGHT", OPEN_CHAPTER_BOX = "OPEN_CHAPTER_BOX", MARK_GUIDE = "MARK_GUIDE", diff --git a/lua/app/server/server_data_manager.lua b/lua/app/server/server_data_manager.lua index 44586e4f..9caf4b33 100644 --- a/lua/app/server/server_data_manager.lua +++ b/lua/app/server/server_data_manager.lua @@ -66,6 +66,7 @@ ServerDataManager.OP_FUNC = { [GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO] = function (...) ServerDataManager.ServerHeroManager:onUpgradeHero(...) end, + [GConst.ServerDataConst.DATA_OP_BEHAVIOR.START_FIGHT] = function(...) ServerDataManager.ServerChapterManager:startFight(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT] = function(...) ServerDataManager.ServerChapterManager:endFight(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX] = function(...) ServerDataManager.ServerChapterManager:openBox(...) end, [GConst.ServerDataConst.DATA_OP_BEHAVIOR.MARK_GUIDE] = function(...) ServerDataManager.ServerTutorialManager:markGuide(...) end, diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index dbabde0b..f8f4a2f9 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -149,7 +149,12 @@ function MainComp:refreshChapter(force) end self.uiMap["main_comp.fight_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC)) - self.uiMap["main_comp.fight_btn.desc_2"]:setText(DataManager.ChapterData:getFightCost()) + local cost = DataManager.ChapterData:getFightCost() + if cost then + self.uiMap["main_comp.fight_btn.desc_2"]:setText(GFunc.getRewardNum(cost)) + else + self.uiMap["main_comp.fight_btn.desc_2"]:setText("0") + end end end diff --git a/lua/app/userdata/bag/item_data.lua b/lua/app/userdata/bag/item_data.lua index 8b44d2c2..1a8716a3 100644 --- a/lua/app/userdata/bag/item_data.lua +++ b/lua/app/userdata/bag/item_data.lua @@ -74,6 +74,10 @@ function ItemData:getItemNumById(id) return num end +function ItemData:getVit() + return self:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) +end + function ItemData:addItemReward(item, itemGetType) CACHE_ITEM.cfg_id = GFunc.getRewardId(item) CACHE_ITEM.count = GFunc.getRewardNum(item) diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index 021bc1d9..a833ff6f 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -170,14 +170,8 @@ function ChapterData:getChapterMaxWave(chapterId) return 0 end -function ChapterData:getFightCost(chapterId) - chapterId = chapterId or self:getChapterId() - local cfg = self:getChapterCfg()[chapterId] - if cfg and cfg.cost then - return cfg.cost.num - end - - return 0 +function ChapterData:getFightCost() + return GFunc.getConstReward("chapter_cost") end function ChapterData:getMaxChapterId() diff --git a/lua/app/userdata/player/player_data.lua b/lua/app/userdata/player/player_data.lua index 5a74dac1..f46baf79 100644 --- a/lua/app/userdata/player/player_data.lua +++ b/lua/app/userdata/player/player_data.lua @@ -3,6 +3,13 @@ local PlayerData = class("PlayerData", BaseData) function PlayerData:init(data) end +function PlayerData:setVit(vit) + self.vit = vit +end + +function PlayerData:getVit() + return self.vit or 0 +end function PlayerData:getMaxVit() if self.maxVit == nil then