数据处理
This commit is contained in:
parent
ee3e56af2a
commit
f2e69642a9
@ -18,6 +18,13 @@ function ConfigManager:getConfig(configName)
|
|||||||
return config.data
|
return config.data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ConfigManager:getItemConfig()
|
||||||
|
if self.itemCfg == nil then
|
||||||
|
self.itemCfg = self:getConfig("item")
|
||||||
|
end
|
||||||
|
return self.itemCfg
|
||||||
|
end
|
||||||
|
|
||||||
if NOT_PUBLISH then
|
if NOT_PUBLISH then
|
||||||
ConfigManager.__getConfig = ConfigManager.getConfig
|
ConfigManager.__getConfig = ConfigManager.getConfig
|
||||||
function ConfigManager:getConfig(configName)
|
function ConfigManager:getConfig(configName)
|
||||||
|
|||||||
@ -26,6 +26,7 @@ local LOCAL_DATA_KEY = {
|
|||||||
SAVE_POWER_MODE = "SAVE_POWER_MODE", -- 省电模式
|
SAVE_POWER_MODE = "SAVE_POWER_MODE", -- 省电模式
|
||||||
LAST_MAIL_ID = "LAST_MAIL_ID",
|
LAST_MAIL_ID = "LAST_MAIL_ID",
|
||||||
IS_NEW_PLAYER = "IS_NEW_PLAYER",
|
IS_NEW_PLAYER = "IS_NEW_PLAYER",
|
||||||
|
DISTINCT_ID = "DISTINCT_ID",
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalData.KEYS = LOCAL_DATA_KEY
|
LocalData.KEYS = LOCAL_DATA_KEY
|
||||||
@ -319,4 +320,12 @@ function LocalData:setNotNewPlayer()
|
|||||||
return self:setInt(LOCAL_DATA_KEY.IS_NEW_PLAYER, 1)
|
return self:setInt(LOCAL_DATA_KEY.IS_NEW_PLAYER, 1)
|
||||||
end
|
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
|
return LocalData
|
||||||
@ -10,7 +10,8 @@ local hero_level = {
|
|||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
5,
|
5,
|
||||||
100
|
100
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=1
|
||||||
},
|
},
|
||||||
[3]={
|
[3]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -20,7 +21,8 @@ local hero_level = {
|
|||||||
["cost_3"]={
|
["cost_3"]={
|
||||||
3,
|
3,
|
||||||
0
|
0
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=1
|
||||||
},
|
},
|
||||||
[4]={
|
[4]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -45,7 +47,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
3,
|
3,
|
||||||
500
|
500
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=2
|
||||||
},
|
},
|
||||||
[6]={
|
[6]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -59,7 +62,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
5,
|
5,
|
||||||
500
|
500
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=2
|
||||||
},
|
},
|
||||||
[7]={
|
[7]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -73,7 +77,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
10,
|
10,
|
||||||
500
|
500
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=2
|
||||||
},
|
},
|
||||||
[8]={
|
[8]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -102,7 +107,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
40,
|
40,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[10]={
|
[10]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -116,7 +122,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
80,
|
80,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[11]={
|
[11]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -130,7 +137,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
160,
|
160,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[12]={
|
[12]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -144,7 +152,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
320,
|
320,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[13]={
|
[13]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -158,7 +167,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
640,
|
640,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[14]={
|
[14]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -172,7 +182,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
1000,
|
1000,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
},
|
},
|
||||||
[15]={
|
[15]={
|
||||||
["cost_2"]={
|
["cost_2"]={
|
||||||
@ -186,7 +197,8 @@ local hero_level = {
|
|||||||
["cost_4"]={
|
["cost_4"]={
|
||||||
1500,
|
1500,
|
||||||
10000
|
10000
|
||||||
}
|
},
|
||||||
|
["unlock_skill"]=3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local config = {
|
local config = {
|
||||||
|
|||||||
46
lua/app/config/player_initial.lua
Normal file
46
lua/app/config/player_initial.lua
Normal file
@ -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
|
||||||
10
lua/app/config/player_initial.lua.meta
Normal file
10
lua/app/config/player_initial.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6e38a4ab5010ad49ade2eb95d467b9f
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
11
lua/app/config/recovery.lua
Normal file
11
lua/app/config/recovery.lua
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
local recovery = {
|
||||||
|
[3]={
|
||||||
|
["type"]=1,
|
||||||
|
["time"]=900,
|
||||||
|
["limit"]=30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
local config = {
|
||||||
|
data=recovery,count=1
|
||||||
|
}
|
||||||
|
return config
|
||||||
10
lua/app/config/recovery.lua.meta
Normal file
10
lua/app/config/recovery.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 820efa75b0d798f478e9ab7f2e160986
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
@ -34,6 +34,7 @@ local skill_hero = {
|
|||||||
},
|
},
|
||||||
[21]={
|
[21]={
|
||||||
["energy"]=10,
|
["energy"]=10,
|
||||||
|
["position"]=2,
|
||||||
["method"]=2,
|
["method"]=2,
|
||||||
["skill_type"]=2,
|
["skill_type"]=2,
|
||||||
["skill_type_parameter"]=2,
|
["skill_type_parameter"]=2,
|
||||||
@ -145,7 +146,7 @@ local skill_hero = {
|
|||||||
},
|
},
|
||||||
[71]={
|
[71]={
|
||||||
["energy"]=10,
|
["energy"]=10,
|
||||||
["position"]=4,
|
["position"]=2,
|
||||||
["method"]=1,
|
["method"]=1,
|
||||||
["skill_type"]=2,
|
["skill_type"]=2,
|
||||||
["skill_type_parameter"]=2,
|
["skill_type_parameter"]=2,
|
||||||
@ -180,6 +181,7 @@ local skill_hero = {
|
|||||||
},
|
},
|
||||||
[72]={
|
[72]={
|
||||||
["energy"]=10,
|
["energy"]=10,
|
||||||
|
["position"]=2,
|
||||||
["method"]=1,
|
["method"]=1,
|
||||||
["skill_type"]=2,
|
["skill_type"]=2,
|
||||||
["skill_type_parameter"]=2,
|
["skill_type_parameter"]=2,
|
||||||
@ -221,6 +223,7 @@ local skill_hero = {
|
|||||||
},
|
},
|
||||||
[80]={
|
[80]={
|
||||||
["energy"]=10,
|
["energy"]=10,
|
||||||
|
["position"]=4,
|
||||||
["method"]=2,
|
["method"]=2,
|
||||||
["skill_type"]=0,
|
["skill_type"]=0,
|
||||||
["effect"]={
|
["effect"]={
|
||||||
@ -241,6 +244,7 @@ local skill_hero = {
|
|||||||
},
|
},
|
||||||
[81]={
|
[81]={
|
||||||
["energy"]=10,
|
["energy"]=10,
|
||||||
|
["position"]=4,
|
||||||
["method"]=2,
|
["method"]=2,
|
||||||
["skill_type"]=1,
|
["skill_type"]=1,
|
||||||
["boardrange"]={
|
["boardrange"]={
|
||||||
|
|||||||
@ -1694,6 +1694,30 @@ function GFunc.goTargetPosXShake(obj, onlyKill, targetX, offset, callBack)
|
|||||||
return obj.shakeSeq
|
return obj.shakeSeq
|
||||||
end
|
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
|
设置tabLe只速 出现改写会抛出Lua error
|
||||||
用法locaL readOnlyCfg = GFunc.readOnlyTab(cfg) return readOnlyCfg
|
用法locaL readOnlyCfg = GFunc.readOnlyTab(cfg) return readOnlyCfg
|
||||||
|
|||||||
@ -27,13 +27,17 @@ function TestLoginUI:onLoadRootComplete()
|
|||||||
self.progressTx = uiMap["test_login_ui.progress_tx"]
|
self.progressTx = uiMap["test_login_ui.progress_tx"]
|
||||||
self.progressTx:setText("")
|
self.progressTx:setText("")
|
||||||
self.inputField = uiMap["test_login_ui.login_node.input_field"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_INPUT_FIELD)
|
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.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.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.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.TURNTABLE_BUTTON))
|
||||||
uiMap["test_login_ui.login_node.login_btn"]:addClickListener(function()
|
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()
|
self:loginGame()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
67
lua/app/server/data/server_bag_data.lua
Normal file
67
lua/app/server/data/server_bag_data.lua
Normal file
@ -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
|
||||||
10
lua/app/server/data/server_bag_data.lua.meta
Normal file
10
lua/app/server/data/server_bag_data.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d136d1a130b633146aadeca89f6c41a6
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
@ -19,8 +19,8 @@ end
|
|||||||
function ServerBaseData:init()
|
function ServerBaseData:init()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerBaseData:_loadLocalData()
|
function ServerBaseData:loadLocalData()
|
||||||
local data = LocalData:getString("ServerBaseData_" .. self.__cname, "")
|
local data = LocalData:getString("ServerData_" .. self.__cname, "")
|
||||||
local dataObj = nil
|
local dataObj = nil
|
||||||
if data and data ~= "" then
|
if data and data ~= "" then
|
||||||
dataObj = json.decode(data)
|
dataObj = json.decode(data)
|
||||||
@ -28,16 +28,8 @@ function ServerBaseData:_loadLocalData()
|
|||||||
self:init(dataObj)
|
self:init(dataObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerBaseData:_loadNewPlayerData()
|
function ServerBaseData:loadNewPlayerData()
|
||||||
for k, v in pairs(self.data) do
|
self:init()
|
||||||
self.data[k] = nil
|
|
||||||
end
|
|
||||||
local dataObj = self:getNewPlayerData()
|
|
||||||
self:init(dataObj)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:getNewPlayerData()
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerBaseData:getCloneData()
|
function ServerBaseData:getCloneData()
|
||||||
|
|||||||
183
lua/app/server/data/server_item_data.lua
Normal file
183
lua/app/server/data/server_item_data.lua
Normal file
@ -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
|
||||||
10
lua/app/server/data/server_item_data.lua.meta
Normal file
10
lua/app/server/data/server_item_data.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 21a3f0972e236154197f14df6f246f40
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
local ServerDataConst = {}
|
local ServerDataConst = {}
|
||||||
|
|
||||||
|
ServerDataConst.REWARD_TYPE = {
|
||||||
|
REWARD_NONE = 0,
|
||||||
|
ITEM = 1,
|
||||||
|
}
|
||||||
|
|
||||||
ServerDataConst.DATA_OP_BEHAVIOR = {
|
ServerDataConst.DATA_OP_BEHAVIOR = {
|
||||||
SYNC_DATA = "SYNC_DATA",
|
SYNC_DATA = "SYNC_DATA",
|
||||||
|
|||||||
@ -5,6 +5,32 @@ local ServerDataManager = {}
|
|||||||
function ServerDataManager:init()
|
function ServerDataManager:init()
|
||||||
end
|
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)
|
function ServerDataManager:dataOperate(behavior, params, callback)
|
||||||
local opFunc = ServerDataManager.OP_FUNC[behavior]
|
local opFunc = ServerDataManager.OP_FUNC[behavior]
|
||||||
if opFunc then
|
if opFunc then
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
local ServerGameData = {}
|
local ServerGameData = {
|
||||||
|
seed = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
local TempRewards = {}
|
||||||
|
|
||||||
function ServerGameData:init()
|
function ServerGameData:init()
|
||||||
if self.isInit then
|
if self.isInit then
|
||||||
@ -6,20 +10,32 @@ function ServerGameData:init()
|
|||||||
end
|
end
|
||||||
self.isInit = true
|
self.isInit = true
|
||||||
self:initServerData("PlayerData", "app/server/data/server_player_data")
|
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")
|
self:initServerData("ChapterData", "app/server/data/server_chapter_data")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerGameData:initData()
|
function ServerGameData:initData()
|
||||||
self:init()
|
self:init()
|
||||||
|
if self.distinctId == nil or self.distinctId == "" then
|
||||||
|
self.distinctId = LocalData:getDistinctId()
|
||||||
|
end
|
||||||
local isNewPlayer = LocalData:getIsNewPlayer()
|
local isNewPlayer = LocalData:getIsNewPlayer()
|
||||||
if isNewPlayer then
|
if isNewPlayer then
|
||||||
for k, v in pairs(self.dataMap) do
|
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
|
end
|
||||||
LocalData:setNotNewPlayer()
|
LocalData:setNotNewPlayer()
|
||||||
else
|
else
|
||||||
for k, v in pairs(self.dataMap) do
|
for k, v in pairs(self.dataMap) do
|
||||||
v:_loadLocalData()
|
v:loadLocalData()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -37,9 +53,139 @@ function ServerGameData:getData()
|
|||||||
for k, v in pairs(self.dataMap) do
|
for k, v in pairs(self.dataMap) do
|
||||||
data[k] = v:getCloneData()
|
data[k] = v:getCloneData()
|
||||||
end
|
end
|
||||||
Logger.logHighlight("ServerGameData:getData()")
|
|
||||||
Logger.printTable(data)
|
|
||||||
return data
|
return data
|
||||||
end
|
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
|
return ServerGameData
|
||||||
@ -54,7 +54,6 @@ end
|
|||||||
|
|
||||||
function ToastManager:_showToast(params)
|
function ToastManager:_showToast(params)
|
||||||
UIManager:getToast(function(prefabObject)
|
UIManager:getToast(function(prefabObject)
|
||||||
AudioManager:playEffect(AudioManager.EFFECT_ID.SFX_TOAST)
|
|
||||||
prefabObject._using = true
|
prefabObject._using = true
|
||||||
if prefabObject._toastSequence then
|
if prefabObject._toastSequence then
|
||||||
prefabObject._toastSequence:Kill()
|
prefabObject._toastSequence:Kill()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user