From f2e69642a959a08290814cd9c6d4ecd5dbb4055e Mon Sep 17 00:00:00 2001 From: chenxi Date: Fri, 7 Apr 2023 22:23:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/common/config_manager.lua | 7 + lua/app/common/local_data.lua | 9 + lua/app/config/hero_level.lua | 36 ++-- lua/app/config/player_initial.lua | 46 +++++ lua/app/config/player_initial.lua.meta | 10 + lua/app/config/recovery.lua | 11 ++ lua/app/config/recovery.lua.meta | 10 + lua/app/config/skill_hero.lua | 6 +- lua/app/global/global_func.lua | 24 +++ lua/app/module/login/test_login_ui.lua | 8 +- lua/app/server/data/server_bag_data.lua | 67 +++++++ lua/app/server/data/server_bag_data.lua.meta | 10 + lua/app/server/data/server_base_data.lua | 16 +- lua/app/server/data/server_item_data.lua | 183 ++++++++++++++++++ lua/app/server/data/server_item_data.lua.meta | 10 + lua/app/server/server_data_const.lua | 4 + lua/app/server/server_data_manager.lua | 26 +++ lua/app/server/server_game_data.lua | 156 ++++++++++++++- lua/app/ui/common/toast.lua | 1 - 19 files changed, 607 insertions(+), 33 deletions(-) create mode 100644 lua/app/config/player_initial.lua create mode 100644 lua/app/config/player_initial.lua.meta create mode 100644 lua/app/config/recovery.lua create mode 100644 lua/app/config/recovery.lua.meta create mode 100644 lua/app/server/data/server_bag_data.lua create mode 100644 lua/app/server/data/server_bag_data.lua.meta create mode 100644 lua/app/server/data/server_item_data.lua create mode 100644 lua/app/server/data/server_item_data.lua.meta diff --git a/lua/app/common/config_manager.lua b/lua/app/common/config_manager.lua index 43d55cb6..284949e8 100644 --- a/lua/app/common/config_manager.lua +++ b/lua/app/common/config_manager.lua @@ -18,6 +18,13 @@ function ConfigManager:getConfig(configName) return config.data end +function ConfigManager:getItemConfig() + if self.itemCfg == nil then + self.itemCfg = self:getConfig("item") + end + return self.itemCfg +end + if NOT_PUBLISH then ConfigManager.__getConfig = ConfigManager.getConfig function ConfigManager:getConfig(configName) diff --git a/lua/app/common/local_data.lua b/lua/app/common/local_data.lua index 6dc3fcdf..c2e3dc9f 100644 --- a/lua/app/common/local_data.lua +++ b/lua/app/common/local_data.lua @@ -26,6 +26,7 @@ local LOCAL_DATA_KEY = { SAVE_POWER_MODE = "SAVE_POWER_MODE", -- 省电模式 LAST_MAIL_ID = "LAST_MAIL_ID", IS_NEW_PLAYER = "IS_NEW_PLAYER", + DISTINCT_ID = "DISTINCT_ID", } LocalData.KEYS = LOCAL_DATA_KEY @@ -319,4 +320,12 @@ function LocalData:setNotNewPlayer() return self:setInt(LOCAL_DATA_KEY.IS_NEW_PLAYER, 1) end +function LocalData:setDistinctId(id) + self:setString(LOCAL_DATA_KEY.DISTINCT_ID, id or "") +end + +function LocalData:getDistinctId() + return self:getString(LOCAL_DATA_KEY.DISTINCT_ID, "") +end + return LocalData \ No newline at end of file diff --git a/lua/app/config/hero_level.lua b/lua/app/config/hero_level.lua index edab7638..1007be71 100644 --- a/lua/app/config/hero_level.lua +++ b/lua/app/config/hero_level.lua @@ -10,7 +10,8 @@ local hero_level = { ["cost_2"]={ 5, 100 - } + }, + ["unlock_skill"]=1 }, [3]={ ["cost_2"]={ @@ -20,7 +21,8 @@ local hero_level = { ["cost_3"]={ 3, 0 - } + }, + ["unlock_skill"]=1 }, [4]={ ["cost_2"]={ @@ -45,7 +47,8 @@ local hero_level = { ["cost_4"]={ 3, 500 - } + }, + ["unlock_skill"]=2 }, [6]={ ["cost_2"]={ @@ -59,7 +62,8 @@ local hero_level = { ["cost_4"]={ 5, 500 - } + }, + ["unlock_skill"]=2 }, [7]={ ["cost_2"]={ @@ -73,7 +77,8 @@ local hero_level = { ["cost_4"]={ 10, 500 - } + }, + ["unlock_skill"]=2 }, [8]={ ["cost_2"]={ @@ -102,7 +107,8 @@ local hero_level = { ["cost_4"]={ 40, 10000 - } + }, + ["unlock_skill"]=3 }, [10]={ ["cost_2"]={ @@ -116,7 +122,8 @@ local hero_level = { ["cost_4"]={ 80, 10000 - } + }, + ["unlock_skill"]=3 }, [11]={ ["cost_2"]={ @@ -130,7 +137,8 @@ local hero_level = { ["cost_4"]={ 160, 10000 - } + }, + ["unlock_skill"]=3 }, [12]={ ["cost_2"]={ @@ -144,7 +152,8 @@ local hero_level = { ["cost_4"]={ 320, 10000 - } + }, + ["unlock_skill"]=3 }, [13]={ ["cost_2"]={ @@ -158,7 +167,8 @@ local hero_level = { ["cost_4"]={ 640, 10000 - } + }, + ["unlock_skill"]=3 }, [14]={ ["cost_2"]={ @@ -172,7 +182,8 @@ local hero_level = { ["cost_4"]={ 1000, 10000 - } + }, + ["unlock_skill"]=3 }, [15]={ ["cost_2"]={ @@ -186,7 +197,8 @@ local hero_level = { ["cost_4"]={ 1500, 10000 - } + }, + ["unlock_skill"]=3 } } local config = { diff --git a/lua/app/config/player_initial.lua b/lua/app/config/player_initial.lua new file mode 100644 index 00000000..d9db9ca5 --- /dev/null +++ b/lua/app/config/player_initial.lua @@ -0,0 +1,46 @@ +local player_initial = { + [1]={ + ["reward"]={ + ["type"]=1, + ["type_for_nothing"]="Vw==", + ["id"]=3, + ["id_for_nothing"]="VQ==", + ["num"]=30, + ["num_for_nothing"]="VQg=" + } + }, + [2]={ + ["reward"]={ + ["type"]=1, + ["type_for_nothing"]="Vw==", + ["id"]=5001, + ["id_for_nothing"]="UwhcAg==", + ["num"]=3, + ["num_for_nothing"]="VQ==" + } + }, + [3]={ + ["reward"]={ + ["type"]=1, + ["type_for_nothing"]="Vw==", + ["id"]=5002, + ["id_for_nothing"]="UwhcAQ==", + ["num"]=3, + ["num_for_nothing"]="VQ==" + } + }, + [4]={ + ["reward"]={ + ["type"]=1, + ["type_for_nothing"]="Vw==", + ["id"]=5003, + ["id_for_nothing"]="UwhcAA==", + ["num"]=3, + ["num_for_nothing"]="VQ==" + } + } +} +local config = { +data=player_initial,count=4 +} +return config \ No newline at end of file diff --git a/lua/app/config/player_initial.lua.meta b/lua/app/config/player_initial.lua.meta new file mode 100644 index 00000000..be1fc769 --- /dev/null +++ b/lua/app/config/player_initial.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c6e38a4ab5010ad49ade2eb95d467b9f +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/config/recovery.lua b/lua/app/config/recovery.lua new file mode 100644 index 00000000..ad3119b2 --- /dev/null +++ b/lua/app/config/recovery.lua @@ -0,0 +1,11 @@ +local recovery = { + [3]={ + ["type"]=1, + ["time"]=900, + ["limit"]=30 + } +} +local config = { +data=recovery,count=1 +} +return config \ No newline at end of file diff --git a/lua/app/config/recovery.lua.meta b/lua/app/config/recovery.lua.meta new file mode 100644 index 00000000..401852f2 --- /dev/null +++ b/lua/app/config/recovery.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 820efa75b0d798f478e9ab7f2e160986 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/config/skill_hero.lua b/lua/app/config/skill_hero.lua index bfb9e6c8..505206f6 100644 --- a/lua/app/config/skill_hero.lua +++ b/lua/app/config/skill_hero.lua @@ -34,6 +34,7 @@ local skill_hero = { }, [21]={ ["energy"]=10, + ["position"]=2, ["method"]=2, ["skill_type"]=2, ["skill_type_parameter"]=2, @@ -145,7 +146,7 @@ local skill_hero = { }, [71]={ ["energy"]=10, - ["position"]=4, + ["position"]=2, ["method"]=1, ["skill_type"]=2, ["skill_type_parameter"]=2, @@ -180,6 +181,7 @@ local skill_hero = { }, [72]={ ["energy"]=10, + ["position"]=2, ["method"]=1, ["skill_type"]=2, ["skill_type_parameter"]=2, @@ -221,6 +223,7 @@ local skill_hero = { }, [80]={ ["energy"]=10, + ["position"]=4, ["method"]=2, ["skill_type"]=0, ["effect"]={ @@ -241,6 +244,7 @@ local skill_hero = { }, [81]={ ["energy"]=10, + ["position"]=4, ["method"]=2, ["skill_type"]=1, ["boardrange"]={ diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 7fe4fb58..38bad6fe 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -1694,6 +1694,30 @@ function GFunc.goTargetPosXShake(obj, onlyKill, targetX, offset, callBack) return obj.shakeSeq end +function GFunc.getRewardId(reward) + if reward.id_for_nothing then + return CS.BF.Utils.GetRewardNumber(reward.id_for_nothing) + else + return reward.id + end +end + +function GFunc.getRewardNum(reward) + if reward.num_for_nothing then + return CS.BF.Utils.GetRewardNumber(reward.num_for_nothing) + else + return reward.num + end +end + +function GFunc.getRewardType(reward) + if reward.type_for_nothing then + return CS.BF.Utils.GetRewardNumber(reward.type_for_nothing) + else + return reward.type + end +end + --[[ 设置tabLe只速 出现改写会抛出Lua error 用法locaL readOnlyCfg = GFunc.readOnlyTab(cfg) return readOnlyCfg diff --git a/lua/app/module/login/test_login_ui.lua b/lua/app/module/login/test_login_ui.lua index 3dd02f51..35d1eea9 100644 --- a/lua/app/module/login/test_login_ui.lua +++ b/lua/app/module/login/test_login_ui.lua @@ -27,13 +27,17 @@ function TestLoginUI:onLoadRootComplete() self.progressTx = uiMap["test_login_ui.progress_tx"] self.progressTx:setText("") self.inputField = uiMap["test_login_ui.login_node.input_field"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_INPUT_FIELD) - self.inputField.text = LocalData:getLastLoginName() + self.inputField.text = LocalData:getDistinctId() uiMap["test_login_ui.loading_text"]:setText(I18N:getGlobalText(I18N.GlobalConst.LOADING_DESC)) uiMap["test_login_ui.copy_account_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_COPY_ACOUNT_DESC)) uiMap["test_login_ui.login_node.login_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.TURNTABLE_BUTTON)) uiMap["test_login_ui.login_node.login_btn"]:addClickListener(function() - Logger.logHighlight("------") + if not self.inputField.text or self.inputField.text == "" then + GFunc.showToast("请输入账号") + return + end + LocalData:setDistinctId(self.inputField.text) self:loginGame() end) diff --git a/lua/app/server/data/server_bag_data.lua b/lua/app/server/data/server_bag_data.lua new file mode 100644 index 00000000..4bd9d05d --- /dev/null +++ b/lua/app/server/data/server_bag_data.lua @@ -0,0 +1,67 @@ +local ServerBagData = class("ServerBagData", ServerBaseData) + +function ServerBagData:ctor() + self.ItemData = require("app/server/data/server_item_data"):create() +end + +function ServerBagData:loadLocalData() + self.ItemData:loadLocalData() +end + +function ServerBagData:clear() + self.ItemData:clear() +end + +function ServerBagData:getItemData() + return self.ItemData:getAllItems() +end + +function ServerBagData:tryAddItem(id, num) + return self.ItemData:tryAddItem(id, num) +end + +function ServerBagData:tryAddItemReward(item) + local id = GFunc.getRewardId(item) + local num = GFunc.getRewardNum(item) + return self.ItemData:tryAddItem(id, num) +end + +function ServerBagData:tryAddItemCost(cost) + local id = GFunc.getRewardId(cost) + local num = GFunc.getRewardNum(cost) + return self.ItemData:tryAddItem(id, -num) +end + +function ServerBagData:addItemReward(item, getType) + local id = GFunc.getRewardId(item) + local num = GFunc.getRewardNum(item) + self:addItem(id, num, getType) +end + +function ServerBagData:addItemCost(cost) + local id = GFunc.getRewardId(cost) + local num = GFunc.getRewardNum(cost) + self:addItem(id, -num) +end + +function ServerBagData:addItem(id, num, getType) + if id == GConst.ItemConst.ITEM_ID_VIT then + local maxCount = self.ItemData:getMaxVit() + local currentCount = self.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) + local isMax = currentCount >= maxCount + self.ItemData:addItem(id, num, getType) + local currentCount = currentCount + num + local isMax1 = currentCount >= maxCount + if not isMax1 then + if isMax then + self.ItemData:resetVitRecoverTime() + else + self.ItemData:recoveryItems() + end + end + else + self.ItemData:addItem(id, num, getType) + end +end + +return ServerBagData \ No newline at end of file diff --git a/lua/app/server/data/server_bag_data.lua.meta b/lua/app/server/data/server_bag_data.lua.meta new file mode 100644 index 00000000..4a111d66 --- /dev/null +++ b/lua/app/server/data/server_bag_data.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: d136d1a130b633146aadeca89f6c41a6 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/data/server_base_data.lua b/lua/app/server/data/server_base_data.lua index 88df61e4..3dda8880 100644 --- a/lua/app/server/data/server_base_data.lua +++ b/lua/app/server/data/server_base_data.lua @@ -19,8 +19,8 @@ end function ServerBaseData:init() end -function ServerBaseData:_loadLocalData() - local data = LocalData:getString("ServerBaseData_" .. self.__cname, "") +function ServerBaseData:loadLocalData() + local data = LocalData:getString("ServerData_" .. self.__cname, "") local dataObj = nil if data and data ~= "" then dataObj = json.decode(data) @@ -28,16 +28,8 @@ function ServerBaseData:_loadLocalData() self:init(dataObj) end -function ServerBaseData:_loadNewPlayerData() - for k, v in pairs(self.data) do - self.data[k] = nil - end - local dataObj = self:getNewPlayerData() - self:init(dataObj) -end - -function ServerBaseData:getNewPlayerData() - return nil +function ServerBaseData:loadNewPlayerData() + self:init() end function ServerBaseData:getCloneData() diff --git a/lua/app/server/data/server_item_data.lua b/lua/app/server/data/server_item_data.lua new file mode 100644 index 00000000..6ad902b6 --- /dev/null +++ b/lua/app/server/data/server_item_data.lua @@ -0,0 +1,183 @@ +local ServerItemData = class("ServerItemData", ServerBaseData) + +function ServerItemData:init(data) + data = data or {} + self.data.items = {} + for idStr, item in pairs(data) do + local id = tonumber(idStr) + if id == GConst.ItemConst.ITEM_ID_VIT then + local ServerGameData = require "app/server/data/server_game_data" + ServerGameData.PlayerData:setVit(item.count) + end + self.data.items[id] = {cfg_id = id, count = item.count} + end + self.data.recoveries = data.recoveries or {} + self:checkRecoveries() +end + +function ServerItemData:tryAddItem(id, num) + if not self.data.items[id] then + if num < 0 then + return false + end + else + if self.data.items[id].count + num < 0 then + return false + end + end + return true +end + +function ServerItemData:addItem(id, num, getType) + local hadNum = 0 + if self.data.items[id] then + hadNum = self.data.items[id].count + else + self.data.items[id] = {} + self.data.items[id].cfg_id = id + self.data.items[id].count = 0 + end + local finalNum = (hadNum or 0) + num + if finalNum < 0 then + finalNum = 0 + end + local ServerGameData = require "app/server/data/server_game_data" + if id == GConst.ItemConst.ITEM_ID_VIT then + ServerGameData.PlayerData:setVit(finalNum) + end + self.data.items[id].count = finalNum + if num < 0 then + if id == GConst.ItemConst.ITEM_ID_GEM then + ServerGameData.TaskData:addTaskProgress(GConst.TASK_TYPE.TASK_GEM_COST, -num) + end + end + + getType = getType or "" + if num > 0 and id == GConst.ItemConst.ITEM_ID_GOLD and + getType ~= GConst.ServerDataConst.DATA_OP_BEHAVIOR.EQUIP_RESOLVE and + getType ~= GConst.ServerDataConst.DATA_OP_BEHAVIOR.EQUIP_REBACK then + ServerGameData.TaskData:addTaskProgress(GConst.TASK_TYPE.TASK_GOLD_GET, num) + end +end + +function ServerItemData:getAllItems() + return self.data.items +end + +function ServerItemData:getItemNumById(id) + if not self.data.items[id] then + return 0 + end + local num = self.data.items[id].count or 0 + return num +end + +function ServerItemData:checkRecoveries() + local recoveryCfg = self:getRecoveryCfg() + for k, v in pairs(recoveryCfg) do + local inList = false + for ii, vv in ipairs(self.data.recoveries) do + if vv.cfg_id == k then + inList = true + end + end + if not inList then + table.insert(self.data.recoveries, {cfg_id = k, ts = Time:getServerTime()}) + end + end + self:recoveryItems() +end + +function ServerItemData:recoveryItems() + if not self.data.recoveries then + return + end + for i,v in ipairs(self.data.recoveries) do + if v.cfg_id == GConst.ItemConst.ITEM_ID_VIT then + local maxCount = self:getMaxVit() + self:recoveryItem(v, maxCount) + end + end +end + + +function ServerItemData:recoveryItem(data, maxCount) + if not CS.BF.BFMain.IsGotServerTime then + return + end + if data.cfg_id == GConst.ItemConst.ITEM_ID_VIT then + local ServerGameData = require "app/server/data/server_game_data" + local currentCount = ServerGameData.PlayerData:getVit() + if currentCount >= maxCount then -- 已经达到上限 + return + end + + local cfg = self:getRecoveryCfg()[data.cfg_id] + local nowTime = Time:getServerTime() + local diffTime = nowTime - data.ts + if diffTime <= 0 then + return + end + local addCount = math.floor(diffTime / cfg.time) + if addCount <= 0 then + return + end + end + + local currentCount = self:getItemNumById(data.cfg_id) + if currentCount >= maxCount then -- 已经达到上限 + return + end + local cfg = self:getRecoveryCfg()[data.cfg_id] + local nowTime = Time:getServerTime() + local diffTime = nowTime - data.ts + if diffTime <= 0 then + return + end + local addCount = math.floor(diffTime / cfg.time) + if addCount <= 0 then + return + end + data.ts = data.ts + cfg.time*addCount + if currentCount + addCount > maxCount then + addCount = maxCount - currentCount + end + self:addItem(data.cfg_id, addCount) + ServerDataManager:saveData() +end + +function ServerItemData:resetVitRecoverTime() + local maxCount = self:getMaxVit() + local ServerGameData = require "app/server/data/server_game_data" + local currentCount = ServerGameData.PlayerData:getVit() + if currentCount >= maxCount then -- 已经达到上限 + return + end + + local currentCount = self:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) + if currentCount >= maxCount then -- 已经达到上限 + return + end + for i,v in ipairs(self.recoveries) do + if v.cfg_id == GConst.ItemConst.ITEM_ID_VIT then + self.data.recoveries[i].ts = Time:getServerTime() + end + end +end + +function ServerItemData:getRecoveryCfg() + if self.recoveryCfg == nil then + self.recoveryCfg = ConfigManager:getConfig("recovery") + end + return self.recoveryCfg +end + +function ServerItemData:getMaxVit() + if self.maxVit == nil then + local cfg = self:getRecoveryCfg()[GConst.ItemConst.ITEM_ID_VIT] + self.maxVit = cfg.limit + end + return self.maxVit +end + +return ServerItemData \ No newline at end of file diff --git a/lua/app/server/data/server_item_data.lua.meta b/lua/app/server/data/server_item_data.lua.meta new file mode 100644 index 00000000..a6a0cd62 --- /dev/null +++ b/lua/app/server/data/server_item_data.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 21a3f0972e236154197f14df6f246f40 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/server_data_const.lua b/lua/app/server/server_data_const.lua index 2ef89377..408973a3 100644 --- a/lua/app/server/server_data_const.lua +++ b/lua/app/server/server_data_const.lua @@ -1,5 +1,9 @@ local ServerDataConst = {} +ServerDataConst.REWARD_TYPE = { + REWARD_NONE = 0, + ITEM = 1, +} ServerDataConst.DATA_OP_BEHAVIOR = { SYNC_DATA = "SYNC_DATA", diff --git a/lua/app/server/server_data_manager.lua b/lua/app/server/server_data_manager.lua index 6f331c65..291e1732 100644 --- a/lua/app/server/server_data_manager.lua +++ b/lua/app/server/server_data_manager.lua @@ -5,6 +5,32 @@ local ServerDataManager = {} function ServerDataManager:init() end +function ServerDataManager:saveData() +end + +function ServerDataManager:randomReward(weightArr, callback) + local maxWeight = 0 + for i, v in ipairs(weightArr) do + maxWeight = maxWeight + v + end + local randomWeight + if callback then + randomWeight = callback(1, maxWeight) + else + randomWeight = math.random(1, maxWeight) + end + local idx + for i, v in ipairs(weightArr) do + if randomWeight <= v then + idx = i + break + else + randomWeight = randomWeight - v + end + end + return idx +end + function ServerDataManager:dataOperate(behavior, params, callback) local opFunc = ServerDataManager.OP_FUNC[behavior] if opFunc then diff --git a/lua/app/server/server_game_data.lua b/lua/app/server/server_game_data.lua index 22fb5f70..132728d7 100644 --- a/lua/app/server/server_game_data.lua +++ b/lua/app/server/server_game_data.lua @@ -1,4 +1,8 @@ -local ServerGameData = {} +local ServerGameData = { + seed = {} +} + +local TempRewards = {} function ServerGameData:init() if self.isInit then @@ -6,20 +10,32 @@ function ServerGameData:init() end self.isInit = true self:initServerData("PlayerData", "app/server/data/server_player_data") + self:initServerData("BagData", "app/server/data/server_bag_data") self:initServerData("ChapterData", "app/server/data/server_chapter_data") end function ServerGameData:initData() self:init() + if self.distinctId == nil or self.distinctId == "" then + self.distinctId = LocalData:getDistinctId() + end local isNewPlayer = LocalData:getIsNewPlayer() if isNewPlayer then for k, v in pairs(self.dataMap) do - v:_loadNewPlayerData() + v:loadNewPlayerData() + end + local playerInitialCfg = ConfigManager:getConfig("player_initial") + if playerInitialCfg then + for k, v in pairs(playerInitialCfg) do + if v.reward then + self:addReward(v.reward) + end + end end LocalData:setNotNewPlayer() else for k, v in pairs(self.dataMap) do - v:_loadLocalData() + v:loadLocalData() end end end @@ -37,9 +53,139 @@ function ServerGameData:getData() for k, v in pairs(self.dataMap) do data[k] = v:getCloneData() end - Logger.logHighlight("ServerGameData:getData()") - Logger.printTable(data) return data end +-- 根据配置表添加奖励 +function ServerGameData:addRewards(cfgRewards, getType) + local rewards = {} + if cfgRewards then + local count = #TempRewards + for i = 1, count do + table.remove(TempRewards) + end + for _, reward in ipairs(cfgRewards) do + local rewardType = GFunc.getRewardType(reward) + if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then + local rewardId = GFunc.getRewardId(reward) + local rewardNum = GFunc.getRewardNum(reward) + local cfg = ConfigManager:getItemConfig()[rewardId] + if cfg.box_drop then + self:openRewardBox(TempRewards, cfg.box_drop, rewardNum, rewardId) + else + table.insert(TempRewards, reward) + end + else + table.insert(TempRewards, reward) + end + end + count = #TempRewards + for i = 1, count do + local reward = table.remove(TempRewards) + local newReward = self:getNewReward() + local rewardType = GFunc.getRewardType(reward) + newReward.type = rewardType + if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then + self.BagData:addItemReward(reward, getType) + local rewardId = GFunc.getRewardId(reward) + local rewardNum = GFunc.getRewardNum(reward) + if rewardId == GConst.ItemConst.ITEM_ID_EXP then + self.PlayerData:addExp(rewardNum) + end + local item = self:getNewItem() + item.cfg_id = rewardId + item.count = rewardNum + newReward.item = item + end + table.insert(rewards, newReward) + end + end + return rewards +end + +function ServerGameData:addRewards(cfgReward, getType) + if cfgReward == nil then + return + end + local count = #TempRewards + for i = 1, count do + table.remove(TempRewards) + end + local rewardType = GFunc.getRewardType(cfgReward) + if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then + local rewardId = GFunc.getRewardId(cfgReward) + local rewardNum = GFunc.getRewardNum(cfgReward) + local cfg = ConfigManager:getItemConfig()[rewardId] + if cfg.box_drop then + self:openRewardBox(TempRewards, cfg.box_drop, rewardNum, rewardId) + else + table.insert(TempRewards, cfgReward) + end + else + table.insert(TempRewards, cfgReward) + end + count = #TempRewards + for i = 1, count do + local reward = table.remove(TempRewards) + local rewardType = GFunc.getRewardType(reward) + if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then + self.BagData:addItemReward(reward, getType) + local rewardId = GFunc.getRewardId(reward) + local rewardNum = GFunc.getRewardNum(reward) + if rewardId == GConst.ItemConst.ITEM_ID_EXP then + self.PlayerData:addExp(rewardNum) + end + end + end +end + +function ServerGameData:getNewReward() + local rewards = { + type = 0, + item = {}, + } + return rewards +end + +function ServerGameData:getNewItem() + local item = { + cfg_id = 0, + count = 0 + } + return item +end + +function ServerGameData:openRewardBox(finalReward, drop, num, id) + local weightArr = {} + for _, v in ipairs(drop) do + table.insert(weightArr, v.weight) + end + for i = 1, num do + local rewardIdx = ServerDataManager:randomReward(weightArr, function (min, max) + return ServerGameData:randomItemBox(id, min, max) + end) + table.insert(finalReward, drop[rewardIdx]) + end +end + +function ServerGameData:randomItemBox(id, min, max) + id = tostring(id) + local seed = self.seed[id] + if not seed then + local str = self.distinctId .. "_ItemBox_" .. id + seed = GFunc.hash(str) + self.seed[id] = seed + end + self.seed[id] = (seed*9301 + 49297)%233280 + return min + self.seed[id]*(max - min + 1)//233280 +end + +function ServerGameData:getDistinctId() + return self.distinctId +end + +function ServerGameData:setDistinctId(distinctId) + self.distinctId = distinctId +end + return ServerGameData \ No newline at end of file diff --git a/lua/app/ui/common/toast.lua b/lua/app/ui/common/toast.lua index e254a227..dbb6cbe9 100644 --- a/lua/app/ui/common/toast.lua +++ b/lua/app/ui/common/toast.lua @@ -54,7 +54,6 @@ end function ToastManager:_showToast(params) UIManager:getToast(function(prefabObject) - AudioManager:playEffect(AudioManager.EFFECT_ID.SFX_TOAST) prefabObject._using = true if prefabObject._toastSequence then prefabObject._toastSequence:Kill()