Initial version - 1.2.0.60

EN: 1.2.0.60
CN: 1.2.0.61
JP: 1.2.0.63
KR: 1.2.0.67
This commit is contained in:
SL1900
2025-12-03 01:00:00 +09:00
commit 5e0d58cfad
3595 changed files with 9373562 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
local cacheTable = {}
local GetCache = function(name)
if name == nil then
traceback("获取缓存数据时, name 参数不能为空!!!")
return
end
if cacheTable[name] == nil then
cacheTable[name] = {}
end
return cacheTable[name]
end
local SetCache = function(name, tb)
if name == nil then
traceback("写入缓存数据时, name 参数不能为空!!!")
return
end
cacheTable[name] = tb
end
local GetCacheData = function(name, key)
if key == nil then
traceback("获取缓存数据时, key 参数不能为空!!!")
return
end
local tb = GetCache(name)
if tb == nil then
return
end
return tb[key]
end
local SetCacheData = function(name, key, data)
if name == nil then
traceback("写入缓存数据时, name 参数不能为空!!!")
return
end
if key == nil then
traceback("写入缓存数据时, key 参数不能为空!!!")
return
end
local tb = GetCache(name)
tb[key] = data
end
local SetCacheField = function(name, key, field, data)
if name == nil then
traceback("写入缓存数据时, name 参数不能为空!!!")
return
end
if key == nil then
traceback("写入缓存数据时, key 参数不能为空!!!")
return
end
if field == nil then
traceback("写入缓存数据时, field 参数不能为空!!!")
return
end
local tb = GetCache(name)
if tb == nil then
return
end
if tb[key] == nil then
tb[key] = {}
end
tb[key][field] = data
end
local InsertCacheData = function(name, key, data)
if name == nil then
traceback("写入缓存数据时, name 参数不能为空!!!")
return
end
if key == nil then
traceback("写入缓存数据时, key 参数不能为空!!!")
return
end
local tb = GetCache(name)
if tb == nil then
return
end
if tb[key] == nil then
tb[key] = {}
end
table.insert(tb[key], data)
end
_G.CacheTable = {
Get = GetCache,
Set = SetCache,
GetData = GetCacheData,
SetData = SetCacheData,
SetField = SetCacheField,
InsertData = InsertCacheData
}
+118
View File
@@ -0,0 +1,118 @@
local RapidJson = require("rapidjson")
local GameTableDefine = require("Game.CodeGen.GAME_TABLE_DEFINE")
local ClientManager = CS.ClientManager.Instance
require("GameCore.Data.ConfigTable")
require("GameCore.Data.CacheTable")
local ConfigData = {IntFloatPrecision = 1.0E-4}
local PreProcess = function()
end
function ConfigData.Load(sLanguage)
NovaAPI.LoadAllDataTable(sLanguage)
require("GameCore.Data.LanguageTable")
LanguageTable.Init(sLanguage)
if NovaAPI.IsBinFormatEnabled() then
require("GameCore.Data.GameBinTable")
LoadGameBinTable(sLanguage)
else
require("GameCore.Data.GameJsonTable")
LoadGameJsonTable(sLanguage)
end
PreProcess()
printLog("Config data loaded.")
end
function ConfigData.Unload()
NovaAPI.UnLoadAllDataTable()
printLog("Config data unload.")
end
local GenLanguageTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" then
local jsonObject = {}
for _, v in ipairs(jsonArray) do
local id = v.Key
jsonObject[id] = v.Value
end
return jsonObject
end
return nil
end
local ConvertKeyTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
local jsonObject = {}
for i, v in ipairs(jsonArray.list) do
local id = v.Id
jsonObject[id] = v
end
return jsonObject
end
return nil
end
local ConvertNoKeyTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
local jsonObject = {}
for i, v in ipairs(jsonArray.list) do
jsonObject[i] = v
end
return jsonObject
end
return nil
end
local HandleLanguage = function(jsonArray, sLanguage, tableName, langDefine)
if langDefine == nil then
return
end
local languageTab = ConfigData.LoadLanguageTable(sLanguage, tableName)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
for _, v in ipairs(jsonArray.list) do
for _, d in ipairs(langDefine) do
local lang = v[d]
if lang ~= nil then
v[d] = languageTab[lang] or ""
end
end
end
end
end
function ConfigData.LoadLanguageTable(lang, tableName)
local jsonText = NovaAPI.LoadTableData("language/" .. lang .. "/" .. tableName .. ".json") or ""
local tab = RapidJson.decode(jsonText) or {}
return tab
end
function ConfigData.LoadCommonJsonTable(tableName, define, sLanguage)
local jsonText = NovaAPI.LoadTableData("json/" .. tableName .. ".json") or ""
local tab = RapidJson.decode(jsonText)
local lang = define.Lang
if NovaAPI.IsLQA() then
lang = nil
end
HandleLanguage(tab, sLanguage, tableName, lang)
local tab1
if define.Key then
tab1 = ConvertKeyTable(tab)
else
tab1 = ConvertNoKeyTable(tab)
end
return tab1
end
function ConfigData.LoadCommonBinTable(tableName, define, sLanguage)
local tab = {}
NovaAPI.LoadCommonBinData("bin/" .. tableName .. ".bytes", tab)
local langs = define.Lang
if NovaAPI.IsLQA() then
langs = nil
end
local lang
local loaded = false
if not ClientManager:GetMemoryType() and langs ~= nil then
lang = ConfigData.LoadLanguageTable(sLanguage, tableName)
loaded = true
end
local meta = {
pbName = tableName,
langs = langs,
lang = lang,
loaded = loaded
}
local tab1 = LoadDataTable(meta, tab)
return tab1
end
return ConfigData
+239
View File
@@ -0,0 +1,239 @@
local warn_color_tag = "<color=#FFFF00>"
local error_color_tag = "<color=#FF0000>"
local end_color_tag = "</color>"
local table_tag = "<color=#00FF00><b>☀️策划数据表☀️</b></color>"
local cache = {}
local ClearCache = function()
cache = {}
end
local ClearTableCache = function(name)
if name == nil then
traceback("获取策划数据表数据时, name 参数不能为空!!!")
return
end
cache[name] = {}
end
local GetTable = function(name, post_warn)
if name == nil then
traceback("获取策划数据表数据时, name 参数不能为空!!!")
return
end
local tb = _G.DataTable[name]
if tb == nil then
if post_warn == true then
printWarn(table_tag .. " [" .. warn_color_tag .. name .. end_color_tag .. "] 不存在!!!")
else
traceback(table_tag .. " [" .. error_color_tag .. name .. end_color_tag .. "] 不存在!!!")
end
return
end
if cache[name] == nil then
cache[name] = {}
end
return tb
end
local GetTableData = function(name, key, post_warn)
if key == nil then
traceback("获取策划数据表数据时, key 参数不能为空!!!")
return
end
local tb = GetTable(name, post_warn)
if tb == nil then
return
end
local cacheTb = cache[name]
local line = cacheTb[key]
if line ~= nil then
return line
end
line = tb[key]
if line == nil then
if post_warn == true then
printWarn(table_tag .. " [" .. warn_color_tag .. name .. end_color_tag .. "] 中没找到 Id = [" .. warn_color_tag .. key .. end_color_tag .. "] 的数据行!!!")
else
traceback(table_tag .. " [" .. error_color_tag .. name .. end_color_tag .. "] 中没找到 Id = [" .. error_color_tag .. key .. end_color_tag .. "] 的数据行!!!")
end
return
end
cacheTb[key] = line
return line
end
local GetTableField = function(name, key, field, post_warn)
local line = GetTableData(name, key, post_warn)
if line == nil then
return
end
if field == nil then
traceback("获取策划数据表数据时, field 参数不能为空!!!")
return
end
local field_obj = line[field]
if field_obj == nil then
if post_warn == true then
printWarn(table_tag .. " [" .. warn_color_tag .. name .. end_color_tag .. "] 中 Id = [" .. warn_color_tag .. key .. end_color_tag .. "] 的数据行中没找到字段 [" .. warn_color_tag .. field .. end_color_tag .. "] !!!")
else
traceback(table_tag .. " [" .. error_color_tag .. name .. end_color_tag .. "] 中 Id = [" .. error_color_tag .. key .. end_color_tag .. "] 的数据行中没找到字段 [" .. error_color_tag .. field .. end_color_tag .. "] !!!")
end
end
return field_obj
end
local GetUITextData = function(key, post_warn)
return GetTableField("UIText", key, "Text", post_warn) or ""
end
local configCache = {}
local GetTableConfigData = function(key, post_warn)
if key == nil then
traceback("获取策划数据表数据时, key 参数不能为空!!!")
return
end
local data = configCache[key]
if data ~= nil then
return data
end
data = GetTableField("Config", key, "Value", post_warn)
if data == nil then
return
end
configCache[key] = data
return data
end
local GetTableConfigNumber = function(key, post_warn)
if key == nil then
traceback("获取策划数据表数据时, key 参数不能为空!!!")
return
end
local data = configCache[key]
if data ~= nil then
return data
end
data = GetTableField("Config", key, "Value", post_warn)
if data == nil then
return
end
local num = tonumber(data)
if num == nil then
if post_warn == true then
printWarn(table_tag .. " [" .. warn_color_tag .. "Config" .. end_color_tag .. "] 中 Id = [" .. warn_color_tag .. key .. end_color_tag .. "] 的数据行中的字段 [" .. warn_color_tag .. "Value" .. end_color_tag .. "] 不是数字!!!")
else
traceback(table_tag .. " [" .. error_color_tag .. "Config" .. end_color_tag .. "] 中 Id = [" .. error_color_tag .. key .. end_color_tag .. "] 的数据行中的字段 [" .. error_color_tag .. "Value" .. end_color_tag .. "] 不是数字!!!")
end
return
end
configCache[key] = num
return num
end
local GetTableConfigArray = function(key, post_warn)
if key == nil then
traceback("获取策划数据表数据时, key 参数不能为空!!!")
return
end
local data = configCache[key]
if data ~= nil then
return data
end
data = GetTableField("Config", key, "Value", post_warn)
if data == nil then
return
end
local arr = string.split(data, ",")
configCache[key] = arr
return arr
end
local GetTableConfigNumberArray = function(key, post_warn)
if key == nil then
traceback("获取策划数据表数据时, key 参数不能为空!!!")
return
end
local data = configCache[key]
if data ~= nil then
return data
end
data = GetTableField("Config", key, "Value", post_warn)
if data == nil then
return
end
local arr = string.split(data, ",") or {}
if #arr == 0 then
configCache[key] = {}
return {}
end
local res = {}
for _, v in ipairs(arr) do
local num = tonumber(v)
if num == nil then
if post_warn == true then
printWarn(table_tag .. " [" .. warn_color_tag .. "Config" .. end_color_tag .. "] 中 Id = [" .. warn_color_tag .. key .. end_color_tag .. "] 的数据行中的字段 [" .. warn_color_tag .. "Value" .. end_color_tag .. "] 不是数字数组!!!")
else
traceback(table_tag .. " [" .. error_color_tag .. "Config" .. end_color_tag .. "] 中 Id = [" .. error_color_tag .. key .. end_color_tag .. "] 的数据行中的字段 [" .. error_color_tag .. "Value" .. end_color_tag .. "] 不是数字数组!!!")
end
return res
end
table.insert(res, num)
end
configCache[key] = res
return res
end
local GetTableData_Character = function(key, post_warn)
return GetTableData("Character", key, post_warn)
end
local GetTableData_Skill = function(key, post_warn)
return GetTableData("Skill", key, post_warn)
end
local GetTableData_Item = function(key, post_warn)
return GetTableData("Item", key, post_warn)
end
local GetTableData_World = function(key, post_warn)
return GetTableData("World", key, post_warn)
end
local GetTableData_HitDamage = function(key, post_warn)
return GetTableData("HitDamage", key, post_warn)
end
local GetTableData_Attribute = function(key, post_warn)
return GetTableData("Attribute", key, post_warn)
end
local GetTableData_Buff = function(key, post_warn)
return GetTableData("Buff", key, post_warn)
end
local GetTableData_Effect = function(key, post_warn)
return GetTableData("Effect", key, post_warn)
end
local GetTableData_Mainline = function(key, post_warn)
return GetTableData("Mainline", key, post_warn)
end
local GetTableData_Perk = function(key, post_warn)
return GetTableData("Perk", key, post_warn)
end
local GetTableData_Story = function(key, post_warn)
return GetTableData("Story", key, post_warn)
end
local GetTableData_CharacterSkin = function(key, post_warn)
return GetTableData("CharacterSkin", key, post_warn)
end
local GetTableData_Trap = function(key, post_warn)
return GetTableData("Trap", key, post_warn)
end
_G.ConfigTable = {
ClearCache = ClearCache,
ClearTableCache = ClearTableCache,
Get = GetTable,
GetData = GetTableData,
GetField = GetTableField,
GetUIText = GetUITextData,
GetConfigValue = GetTableConfigData,
GetConfigNumber = GetTableConfigNumber,
GetConfigArray = GetTableConfigArray,
GetConfigNumberArray = GetTableConfigNumberArray,
GetData_Character = GetTableData_Character,
GetData_Skill = GetTableData_Skill,
GetData_Item = GetTableData_Item,
GetData_World = GetTableData_World,
GetData_HitDamage = GetTableData_HitDamage,
GetData_Attribute = GetTableData_Attribute,
GetData_Buff = GetTableData_Buff,
GetData_Effect = GetTableData_Effect,
GetData_Mainline = GetTableData_Mainline,
GetData_Perk = GetTableData_Perk,
GetData_Story = GetTableData_Story,
GetData_CharacterSkin = GetTableData_CharacterSkin,
GetData_Trap = GetTableData_Trap
}
@@ -0,0 +1,340 @@
local ActivityAvgData = class("ActivityAvgData")
local File = CS.System.IO.File
local TimerManager = require("GameCore.Timer.TimerManager")
local LocalData = require("GameCore.Data.LocalData")
function ActivityAvgData:Init()
self.tbActivityAvgList = {}
self.tbCachedReadedActAvg = {}
self.tbActAvgList = {}
self:ParseConfig()
end
function ActivityAvgData:ParseConfig()
self.tbFirstNode = {}
local foreachActivityAvgLevel = function(mapData)
if self.tbActivityAvgList[mapData.ActivityId] == nil then
self.tbActivityAvgList[mapData.ActivityId] = {}
end
if mapData.PreLevelId == 0 then
self.tbFirstNode[mapData.ActivityId] = mapData.Id
end
table.insert(self.tbActivityAvgList[mapData.ActivityId], mapData.Id)
end
ForEachTableLine(ConfigTable.Get("ActivityAvgLevel"), foreachActivityAvgLevel)
end
function ActivityAvgData:CacheActivityAvgData(msgData)
if self.tbActAvgList[msgData.Id] == nil then
self.tbActAvgList[msgData.Id] = {}
end
self.tbActAvgList[msgData.Id].nOpenTime = msgData.StartTime
self.tbActAvgList[msgData.Id].nEndTime = msgData.EndTime
end
function ActivityAvgData:RefreshActivityAvgData(nActId, msgData)
self.tbCachedReadedActAvg[nActId] = {}
for _, avgId in ipairs(msgData.RewardIds) do
table.insert(self.tbCachedReadedActAvg[nActId], avgId)
end
self:RefreshAvgRedDot()
end
function ActivityAvgData:GetStoryIdListByActivityId(activityId)
if self.tbActivityAvgList[activityId] == nil then
return {}
end
local list = self:SortStoryList(activityId)
return list
end
function ActivityAvgData:SortStoryList(activityId)
local list = self.tbActivityAvgList[activityId]
if self.tbFirstNode[activityId] == nil then
return list
end
local sortedList = {}
table.insert(sortedList, self.tbFirstNode[activityId])
for i = 2, #list do
for _, storyId in ipairs(list) do
local cfg = ConfigTable.GetData("ActivityAvgLevel", storyId)
if cfg.PreLevelId == sortedList[i - 1] then
table.insert(sortedList, storyId)
break
end
end
end
self.tbActivityAvgList[activityId] = sortedList
self.tbFirstNode[activityId] = nil
return sortedList
end
function ActivityAvgData:CalcPersonality(nId)
local cfgData_SRP = ConfigTable.GetData("StoryRolePersonality", nId)
local tbPersonalityBaseNum = cfgData_SRP.BaseValue
local nTotalCount = tbPersonalityBaseNum[1] + tbPersonalityBaseNum[2] + tbPersonalityBaseNum[3]
local tbPData = {
{
nIndex = 1,
nCount = tbPersonalityBaseNum[1],
nPercent = 0
},
{
nIndex = 2,
nCount = tbPersonalityBaseNum[2],
nPercent = 0
},
{
nIndex = 3,
nCount = tbPersonalityBaseNum[3],
nPercent = 0
}
}
local tbPersonality = self.mapPersonality
local tbPersonalityFactor = self.mapPersonalityFactor
local nFactor = 1
for sAvgId, v in pairs(tbPersonality) do
for nGroupId, vv in pairs(v) do
nFactor = 1
if tbPersonalityFactor[sAvgId] ~= nil then
nFactor = tbPersonalityFactor[sAvgId][nGroupId] or 1
end
nTotalCount = nTotalCount + nFactor
local _idx = vv
if _idx == 4 then
_idx = 3
end
tbPData[_idx].nCount = tbPData[_idx].nCount + nFactor
end
end
for i, v in ipairs(tbPData) do
tbPData[i].nPercent = tbPData[i].nCount / nTotalCount
end
local tbRetPercent = {
tbPData[1].nPercent,
tbPData[2].nPercent,
tbPData[3].nPercent
}
local sTitle, sFace, sHead
table.sort(tbPData, function(a, b)
return a.nCount > b.nCount
end)
local nMaxIndex = tbPData[1].nIndex
local nMaxPercent = tbPData[1].nPercent
if 0.9 <= nMaxPercent then
local tbTitle = {
cfgData_SRP.Amax,
cfgData_SRP.Bmax,
cfgData_SRP.Cmax
}
local tbFace = {
cfgData_SRP.AmaxFace,
cfgData_SRP.BmaxFace,
cfgData_SRP.CmaxFace
}
local tbHead = {
cfgData_SRP.AmaxHead,
cfgData_SRP.BmaxHead,
cfgData_SRP.CmaxHead
}
sTitle = tbTitle[nMaxIndex]
sFace = tbFace[nMaxIndex]
sHead = tbHead[nMaxIndex]
elseif 0.5 <= nMaxPercent then
local tbTitle = {
cfgData_SRP.Aplus,
cfgData_SRP.Bplus,
cfgData_SRP.Cplus
}
local tbFace = {
cfgData_SRP.AplusFace,
cfgData_SRP.BplusFace,
cfgData_SRP.CplusFace
}
local tbHead = {
cfgData_SRP.AplusHead,
cfgData_SRP.BplusHead,
cfgData_SRP.CplusHead
}
sTitle = tbTitle[nMaxIndex]
sFace = tbFace[nMaxIndex]
sHead = tbHead[nMaxIndex]
elseif math.abs(tbPData[2].nPercent - tbPData[3].nPercent) < 0.1 then
sTitle = cfgData_SRP.Normal
sFace = cfgData_SRP.NormalFace
sHead = cfgData_SRP.NormalHead
else
local tbTitleFace = {
{
tbIdxs = {1, 2},
sTitle = cfgData_SRP.Ab,
sFace = cfgData_SRP.AbFace,
sHead = cfgData_SRP.AbHead
},
{
tbIdxs = {1, 3},
sTitle = cfgData_SRP.Ac,
sFace = cfgData_SRP.AcFace,
sHead = cfgData_SRP.AcHead
},
{
tbIdxs = {2, 3},
sTitle = cfgData_SRP.Bc,
sFace = cfgData_SRP.BcFace,
sHead = cfgData_SRP.BcHead
}
}
local nBiggerIndex = tbPData[2].nIndex
for i, v in ipairs(tbTitleFace) do
if 0 < table.indexof(v.tbIdxs, nMaxIndex) and 0 < table.indexof(v.tbIdxs, nBiggerIndex) then
sTitle = v.sTitle
sFace = v.sFace
sHead = v.sHead
break
end
end
end
return tbRetPercent, sTitle, sFace, tbPData, nTotalCount, sHead
end
function ActivityAvgData:IsActivityAvgReaded(activityId, storyId)
if self.tbCachedReadedActAvg[activityId] == nil then
return false
end
for _, avgId in ipairs(self.tbCachedReadedActAvg[activityId]) do
if avgId == storyId then
return true
end
end
return false
end
function ActivityAvgData:HasActivityData(activityId)
return self.tbActAvgList[activityId] ~= nil
end
function ActivityAvgData:IsActivityAvgUnlock(activityId, storyId)
if self.tbActAvgList[activityId] == nil then
return false
end
local cfg = ConfigTable.GetData("ActivityAvgLevel", storyId)
local isPreReaded = self:IsActivityAvgReaded(activityId, cfg.PreLevelId) or cfg.PreLevelId == 0
local nOpenTime = self.tbActAvgList[activityId].nOpenTime
nOpenTime = CS.ClientManager.Instance:GetNextRefreshTime(nOpenTime) - 86400
local curTime = CS.ClientManager.Instance.serverTimeStamp
local days = math.floor((curTime - nOpenTime) / 86400)
return days >= cfg.DayOpen, isPreReaded, nOpenTime
end
function ActivityAvgData:GetActivityOpenTime(activityId)
if self.tbActAvgList[activityId] == nil then
return 0
end
return self.tbActAvgList[activityId].nOpenTime, self.tbActAvgList[activityId].nEndTime
end
function ActivityAvgData:IsNew(activityId, storyId)
local isTimeUnlock, isPreReaded, nOpenTime = self:IsActivityAvgUnlock(activityId, storyId)
if not isTimeUnlock or not isPreReaded then
return false
end
if self:IsActivityAvgReaded(activityId, storyId) then
return false
end
return true
end
function ActivityAvgData:GetRecentAcvitityIndex(activityId)
local list = self:GetStoryIdListByActivityId(activityId)
if list == nil then
return 0
end
for i = 1, #list do
if not self:IsActivityAvgReaded(activityId, list[i]) then
return i
end
end
return 1
end
function ActivityAvgData:RefreshAvgRedDot()
for k, v in pairs(self.tbActivityAvgList) do
local actId = k
if self.tbActAvgList[actId] ~= nil then
for _, avgId in pairs(v) do
local bInActGroup, nActGroupId = PlayerData.Activity:IsActivityInActivityGroup(actId)
if bInActGroup then
local isClicked = LocalData.GetPlayerLocalData("Act_Story_New" .. actId .. avgId)
local isNew = self:IsNew(actId, avgId)
local curTime = CS.ClientManager.Instance.serverTimeStamp
local isOpen = curTime < self.tbActAvgList[actId].nEndTime and curTime > self.tbActAvgList[actId].nOpenTime
local actGroupData = PlayerData.Activity:GetActivityGroupDataById(nActGroupId)
local bActGroupUnlock = actGroupData:IsUnlock()
RedDotManager.SetValid(RedDotDefine.Activity_GroupNew_Avg_Group, {
nActGroupId,
actId,
avgId
}, isNew and not isClicked and isOpen and bActGroupUnlock)
end
end
end
end
end
function ActivityAvgData:EnterAvg(avgId, actId)
self.CURRENT_STORY_ID = avgId
self.CURRENT_ACTIVITY_ID = actId
local mapCfgData_Story = ConfigTable.GetData("ActivityAvgLevel", avgId)
if NovaAPI.IsEditorPlatform() == true then
local nLanIdx = GetLanguageIndex(Settings.sCurrentTxtLanguage)
local sRequireRootPath = GetAvgLuaRequireRoot(nLanIdx) .. "Config/"
local filePath = NovaAPI.ApplicationDataPath .. "/../Lua/" .. sRequireRootPath .. mapCfgData_Story.StoryId .. ".lua"
if not File.Exists(filePath) then
EventManager.Hit(EventId.OpenMessageBox, "找不到AVG配置文件,请检查配置表!,Avg名:" .. mapCfgData_Story.StoryId)
printError("找不到AVG配置文件,请检查配置表!,Avg名:" .. mapCfgData_Story.StoryId)
return
end
end
printLog("进AVG演出了 " .. mapCfgData_Story.StoryId)
EventManager.Add("StoryDialog_DialogEnd", self, self.OnEvent_AvgSTEnd)
EventManager.Hit("StoryDialog_DialogStart", mapCfgData_Story.StoryId)
end
function ActivityAvgData:OnEvent_AvgSTEnd()
if not self:IsActivityAvgReaded(self.CURRENT_ACTIVITY_ID, self.CURRENT_STORY_ID) then
self:SendMsg_STORY_DONE(self.CURRENT_STORY_ID, self.CURRENT_ACTIVITY_ID)
else
EventManager.Hit("Activity_Story_Done", false)
end
EventManager.Remove("StoryDialog_DialogEnd", self, self.OnEvent_AvgSTEnd)
self:RefreshAvgRedDot()
end
function ActivityAvgData:SendMsg_STORY_DONE(nStoryId, nActId)
local mapSendMsgData = {
ActivityId = nActId,
LevelId = nStoryId,
Events = {
List = {}
}
}
local func_succ = function(_, mapChangeInfo)
table.insert(self.tbCachedReadedActAvg[nActId], nStoryId)
local bHasReward = mapChangeInfo and mapChangeInfo.Props and #mapChangeInfo.Props > 0
if bHasReward then
local tbItem = {}
local tbRewardDisplay = UTILS.DecodeChangeInfo(mapChangeInfo)
for _, v in pairs(tbRewardDisplay) do
for k, value in pairs(v) do
table.insert(tbItem, {
Tid = value.Tid,
Qty = value.Qty,
rewardType = AllEnum.RewardType.First
})
end
end
local AfterRewardDisplay = function()
EventManager.Hit("Activity_Story_RewardClosed")
end
local delayOpen = function()
UTILS.OpenReceiveByDisplayItem(tbItem, mapChangeInfo, AfterRewardDisplay)
end
local nDelayTime = 1.5
EventManager.Hit(EventId.TemporaryBlockInput, nDelayTime)
TimerManager.Add(1, nDelayTime, self, delayOpen, true, true, true)
end
EventManager.Hit("Activity_Story_Done", bHasReward)
printLog("通关结算完成")
if #self.tbCachedReadedActAvg[nActId] == #self.tbActivityAvgList[nActId] then
EventManager.Hit("ActivityStory_All_Complate")
end
self:RefreshAvgRedDot()
end
printLog("发送通关消息")
HttpNetHandler.SendMsg(NetMsgId.Id.activity_avg_reward_receive_req, mapSendMsgData, nil, func_succ)
self.CURRENT_STORY_ID = 0
end
return ActivityAvgData
@@ -0,0 +1,148 @@
local ActivityDataBase = class("ActivityDataBase")
local LocalData = require("GameCore.Data.LocalData")
function ActivityDataBase:ctor(mapActData)
self.nActId = mapActData.Id
self.actCfg = nil
self.nOpenTime = mapActData.StartTime
self.nEndTime = mapActData.EndTime
self.bRedDot = false
self.bBanner = false
self.actCfg = ConfigTable.GetData("Activity", self.nActId)
self.bPlay = self:CheckActPlay()
self:Init()
end
function ActivityDataBase:Init()
end
function ActivityDataBase:UpdateActivityState(mapState)
self.bRedDot = mapState.RedDot
self.bBanner = mapState.Banner
end
function ActivityDataBase:RefreshActivityData(mapActData)
self.nOpenTime = mapActData.StartTime
self.nEndTime = mapActData.EndTime
end
function ActivityDataBase:GetActId()
return self.nActId
end
function ActivityDataBase:GetActCfgData()
return self.actCfg
end
function ActivityDataBase:GetActType()
return self.actCfg.ActivityType
end
function ActivityDataBase:CheckActivityOpen()
local curTime = CS.ClientManager.Instance.serverTimeStamp
if self.actCfg.EndType == GameEnum.activityEndType.NoLimit then
return self.nOpenTime > 0
else
return curTime < self.nEndTime and self.nOpenTime > 0
end
end
function ActivityDataBase:CheckActShow()
if self.actCfg.PreLimit == GameEnum.activityPreLimit.WorldClass then
local nCurWorldClass = PlayerData.Base:GetWorldClass()
local nNeedWorldClass = tonumber(self.actCfg.LimitParam)
if nCurWorldClass < nNeedWorldClass then
return false
end
elseif self.actCfg.PreLimit == GameEnum.activityPreLimit.questLimit then
local nStoryId = tonumber(self.actCfg.LimitParam)
local bReaded = PlayerData.Avg:IsStoryReaded(nStoryId)
if not bReaded then
return false
end
end
if self.actCfg.EndType == GameEnum.activityEndType.NoLimit then
return not self.bBanner and self:CheckActivityOpen()
else
return self:CheckActivityOpen()
end
end
function ActivityDataBase:GetPlayState()
return self.bPlay
end
function ActivityDataBase:RefreshPlayState()
self.bPlay = self:CheckActPlay()
end
function ActivityDataBase:CheckActPlay()
if self.actCfg.PlayCond == GameEnum.activityPreLimit.WorldClass then
local nCurWorldClass = PlayerData.Base:GetWorldClass()
local nNeedWorldClass = tonumber(self.actCfg.PlayCondParams)
if nCurWorldClass < nNeedWorldClass then
return false
end
elseif self.actCfg.PlayCond == GameEnum.activityPreLimit.questLimit then
local nStoryId = tonumber(self.actCfg.PlayCondParams)
local bReaded = PlayerData.Avg:IsStoryReaded(nStoryId)
if not bReaded then
return false
end
end
if self.actCfg.EndType == GameEnum.activityEndType.NoLimit then
return not self.bBanner and self:CheckActivityOpen()
else
return self:CheckActivityOpen()
end
end
function ActivityDataBase:CheckActJumpCond(bShowTips)
local bPlayCond = true
local sTips = ""
if self.actCfg.PlayCond == GameEnum.activityPreLimit.WorldClass then
local nCurWorldClass = PlayerData.Base:GetWorldClass()
local nNeedWorldClass = tonumber(self.actCfg.PlayCondParams)
if nCurWorldClass < nNeedWorldClass then
bPlayCond = false
sTips = orderedFormat(ConfigTable.GetUIText("Activity_Play_Cond_Tip_1"), nNeedWorldClass)
end
elseif self.actCfg.PlayCond == GameEnum.activityPreLimit.questLimit then
local nStoryId = tonumber(self.actCfg.LimitParam)
local bReaded = PlayerData.Avg:IsStoryReaded(nStoryId)
if not bReaded then
bPlayCond = false
local cfgData = ConfigTable.GetData_Story(nStoryId)
local sName = ""
if cfgData ~= nil then
sName = cfgData.Title
end
sTips = orderedFormat(ConfigTable.GetUIText("Activity_Play_Cond_Tip_2"), sName)
end
end
if not bPlayCond and bShowTips then
EventManager.Hit(EventId.OpenMessageBox, sTips)
end
return bPlayCond, sTips
end
function ActivityDataBase:CheckRewardAllReceive()
return false
end
function ActivityDataBase:GetActivityRedDot()
return self.bRedDot
end
function ActivityDataBase:GetActEndTime()
return self.nEndTime
end
function ActivityDataBase:GetActSortId()
return self.actCfg.SortId
end
function ActivityDataBase:CheckPopUp()
local localData = LocalData.GetPlayerLocalData("Act_PopUp_DontShow" .. self.nActId)
if localData then
return false
end
return PlayerData.PopUp:IsNeedActPopUp(self.nActId)
end
function ActivityDataBase:CheckShowBanner()
return self:CheckActPlay() and self.actCfg.BannerRes ~= "" and self.bBanner == false
end
function ActivityDataBase:GetBannerPng()
return self.actCfg.BannerRes
end
function ActivityDataBase:RefreshRedDot()
end
function ActivityDataBase:RefreshStateData(bRedDot, bBanner)
self.bRedDot = bRedDot
self.bBanner = bBanner
end
function ActivityDataBase:UpdateStatus()
end
return ActivityDataBase
@@ -0,0 +1,113 @@
local LocalData = require("GameCore.Data.LocalData")
local ActivityGroupDataBase = class("ActivityGroupDataBase")
function ActivityGroupDataBase:ctor(mapActGroupData)
self.nActGroupId = mapActGroupData.Id
self.actGroupCfg = mapActGroupData
self.bRedDot = false
self.bBanner = false
self.nOpenTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.StartTime)
self.nEndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.EndTime)
self.nEndEnterTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.EnterEndTime)
self:Init()
end
function ActivityGroupDataBase:Init()
end
function ActivityGroupDataBase:UpdateActivityGroupState(mapState)
self.bRedDot = mapState.RedDot
self.bBanner = mapState.Banner
end
function ActivityGroupDataBase:RefreshActivityData(mapActGroupData)
self.actGroupCfg = mapActGroupData
self.nOpenTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.StartTime)
self.nEndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.EndTime)
self.nEndEnterTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(self.actGroupCfg.EnterEndTime)
end
function ActivityGroupDataBase:GetActGroupId()
return self.nActGroupId
end
function ActivityGroupDataBase:GetActGroupCfgData()
return self.actGroupCfg
end
function ActivityGroupDataBase:IsUnlock()
if self.actGroupCfg.StartCondType == GameEnum.questAcceptCond.WorldClassSpecific then
local nWorldCalss = PlayerData.Base:GetWorldClass()
if nWorldCalss < self.actGroupCfg.StartCondParams[1] then
local txtLock = orderedFormat(ConfigTable.GetUIText("Activity_Cond_WorldClass"), self.actGroupCfg.StartCondParams[1])
return false, txtLock
end
end
return true
end
function ActivityGroupDataBase:IsUnlockShow()
if self.actGroupCfg.PreLimit == GameEnum.activityPreLimit.WorldClass then
local nWorldCalss = PlayerData.Base:GetWorldClass()
if nWorldCalss < tonumber(self.actGroupCfg.LimitParam) then
return false
end
elseif self.actGroupCfg.PreLimit == GameEnum.activityPreLimit.questLimit then
return PlayerData.Avg:IsStoryReaded(self.actGroupCfg.LimitParam)
end
return true
end
function ActivityGroupDataBase:CheckActivityGroupOpen()
if not self:IsUnlockShow() then
return false
end
local curTime = CS.ClientManager.Instance.serverTimeStamp
return curTime < self.nEndTime and self.nOpenTime > 0
end
function ActivityGroupDataBase:CheckActGroupShow()
if not self:IsUnlockShow() then
return false
end
local curTime = CS.ClientManager.Instance.serverTimeStamp
return curTime < self.nEndEnterTime
end
function ActivityGroupDataBase:CheckActGroupPopUpShow()
if not self:IsUnlock() then
return false
end
local curTime = CS.ClientManager.Instance.serverTimeStamp
return curTime < self.nEndTime
end
function ActivityGroupDataBase:GetActGroupEndTime()
return self.nEndTime
end
function ActivityGroupDataBase:GetActGroupEnterEndTime()
return self.nEndEnterTime
end
function ActivityGroupDataBase:GetActGroupRemainTime()
local curTime = CS.ClientManager.Instance.serverTimeStamp
return self.nEndTime - curTime
end
function ActivityGroupDataBase:GetActGroupDate()
local nOpenYear = tonumber(os.date("%Y", self.nOpenTime))
local nOpenMonth = tonumber(os.date("%m", self.nOpenTime))
local nOpenDay = tonumber(os.date("%d", self.nOpenTime))
local nEndYear = tonumber(os.date("%Y", self.nEndTime))
local nEndMonth = tonumber(os.date("%m", self.nEndTime))
local nEndDay = tonumber(os.date("%d", self.nEndTime))
return nOpenMonth, nOpenDay, nEndMonth, nEndDay, nOpenYear, nEndYear
end
function ActivityGroupDataBase:CheckPopUp()
local localData = LocalData.GetPlayerLocalData("Act_PopUp_DontShow" .. self.actGroupCfg.Id)
if localData then
return false
end
return PlayerData.PopUp:IsNeedActPopUp(self.nActGroupId)
end
function ActivityGroupDataBase:CheckShowBanner()
return self:CheckActGroupShow() and self.actCfg.BannerRes ~= "" and self.bBanner == false
end
function ActivityGroupDataBase:GetBannerPng()
end
function ActivityGroupDataBase:RefreshRedDot()
end
function ActivityGroupDataBase:RefreshStateData(bRedDot, bBanner)
self.bRedDot = bRedDot
self.bBanner = bBanner
end
function ActivityGroupDataBase:IsActivityInActivityGroup(nActivityId)
return false
end
return ActivityGroupDataBase
@@ -0,0 +1,443 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local ActivityLevelTypeData = class("ActivityLevelTypeData", ActivityDataBase)
local newDayTime = UTILS.GetDayRefreshTimeOffset()
local LocalData = require("GameCore.Data.LocalData")
function ActivityLevelTypeData:Init()
self.nActId = 0
self.startTime = 0
self.startTimeRefreshTime = 0
self.exploreLevelCount = 0
self.adventureLevelCount = 0
self.levelTabExplore = {}
self.levelTabExploreDifficulty = {}
self.levelTabAdventure = {}
self.levelTabAdventureDifficulty = {}
self.tabCachedBuildId = {}
EventManager.Add("ActivityLevels_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function ActivityLevelTypeData:OnEvent_Time(nTime)
self._TotalTime = nTime
end
function ActivityLevelTypeData:RefreshActivityLevelGameActData(actId, msgData)
self:Init()
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local isEnding = false
if nCurTime > self.nEndTime then
isEnding = true
end
local openTime = self.nOpenTime
self.startTimeRefreshTime = CS.ClientManager.Instance:GetNextRefreshTime(openTime) - 86400
self.nActId = actId
local foreach_Base = function(baseData)
if actId == baseData.ActivityId then
if baseData.Type == GameEnum.ActivityLevelType.Explore then
self.exploreLevelCount = self.exploreLevelCount + 1
self.levelTabExplore[baseData.Id] = {}
self.levelTabExplore[baseData.Id].baseData = baseData
self.levelTabExplore[baseData.Id].Star = 0
self.levelTabExplore[baseData.Id].BuildId = 0
self.levelTabExploreDifficulty[baseData.Difficulty] = baseData.Id
else
self.adventureLevelCount = self.adventureLevelCount + 1
self.levelTabAdventure[baseData.Id] = {}
self.levelTabAdventure[baseData.Id].baseData = baseData
self.levelTabAdventure[baseData.Id].Star = 0
self.levelTabAdventure[baseData.Id].BuildId = 0
self.levelTabAdventureDifficulty[baseData.Difficulty] = baseData.Id
end
self:CheckRedDot(baseData.Type, baseData.Id, baseData.DayOpen, isEnding)
end
end
ForEachTableLine(DataTable.ActivityLevelsLevel, foreach_Base)
if msgData ~= nil then
for i, v in ipairs(msgData.levels) do
local tmpData = ConfigTable.GetData("ActivityLevelsLevel", v.Id)
if tmpData then
if tmpData.Type == GameEnum.ActivityLevelType.Explore then
if self.levelTabExplore[v.Id] then
self.levelTabExplore[v.Id].Star = v.Star
self.levelTabExplore[v.Id].BuildId = v.BuildId
end
elseif self.levelTabAdventure[v.Id] then
self.levelTabAdventure[v.Id].Star = v.Star
self.levelTabAdventure[v.Id].BuildId = v.BuildId
end
end
end
end
end
function ActivityLevelTypeData:CheckRedDot(nType, levelId, dayOpen, isEnding)
local tmpKey = self.nActId .. "_" .. levelId
if isEnding then
LocalData.SetPlayerLocalData(tmpKey, "0")
return
end
local sLocalVal = LocalData.GetPlayerLocalData(tmpKey)
local nState = tonumber(sLocalVal == nil and "0" or sLocalVal)
if nState == 2 then
return
end
if nState == 1 then
local bInActGroup, nActGroupId = PlayerData.Activity:IsActivityInActivityGroup(self.nActId)
if bInActGroup then
local actGroupData = PlayerData.Activity:GetActivityGroupDataById(nActGroupId)
local bActGroupUnlock = actGroupData:IsUnlock()
if nType == GameEnum.ActivityLevelType.Explore then
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Explore_Level, {nActGroupId, levelId}, bActGroupUnlock)
else
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Adventure_Level, {nActGroupId, levelId}, bActGroupUnlock)
end
end
return
end
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local openTime = self.startTimeRefreshTime + dayOpen * 86400
local openTimeNextDay = self.startTimeRefreshTime + dayOpen * 86400 + 86400
if nCurTime >= openTime and nCurTime <= openTimeNextDay then
LocalData.SetPlayerLocalData(tmpKey, "1")
local bInActGroup, nActGroupId = PlayerData.Activity:IsActivityInActivityGroup(self.nActId)
if bInActGroup then
local actGroupData = PlayerData.Activity:GetActivityGroupDataById(nActGroupId)
local bActGroupUnlock = actGroupData:IsUnlock()
if nType == GameEnum.ActivityLevelType.Explore then
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Explore_Level, {nActGroupId, levelId}, bActGroupUnlock)
else
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Adventure_Level, {nActGroupId, levelId}, bActGroupUnlock)
end
end
end
end
function ActivityLevelTypeData:ChangeRedDot(nType, levelId)
local tmpKey = self.nActId .. "_" .. levelId
local sLocalVal = LocalData.GetPlayerLocalData(tmpKey)
local nState = tonumber(sLocalVal == nil and "0" or sLocalVal)
if nState == 1 then
LocalData.SetPlayerLocalData(tmpKey, "2")
local bInActGroup, nActGroupId = PlayerData.Activity:IsActivityInActivityGroup(self.nActId)
if bInActGroup then
if nType == GameEnum.ActivityLevelType.Explore then
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Explore_Level, {nActGroupId, levelId}, false)
else
RedDotManager.SetValid(RedDotDefine.ActivityLevel_Adventure_Level, {nActGroupId, levelId}, false)
end
end
end
end
function ActivityLevelTypeData:ChangeAllRedHot()
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local isEnding = false
if nCurTime >= self.nEndTime then
isEnding = true
end
if not isEnding then
return
end
for i, v in pairs(self.levelTabExploreDifficulty) do
self:ChangeRedDot(GameEnum.ActivityLevelType.Explore, v)
end
for i, v in pairs(self.levelTabAdventureDifficulty) do
self:ChangeRedDot(GameEnum.ActivityLevelType.Adventure, v)
end
end
function ActivityLevelTypeData:GetLevelStarMsg(nType)
if nType == GameEnum.ActivityLevelType.Explore then
local star = 0
for i, v in pairs(self.levelTabExplore) do
star = star + v.Star
end
return self.exploreLevelCount * 3, star
else
local star = 0
for i, v in pairs(self.levelTabAdventure) do
star = star + v.Star
end
return self.adventureLevelCount * 3, star
end
end
function ActivityLevelTypeData:GetLevelDayOpen(nType, id)
if nType == GameEnum.ActivityLevelType.Explore then
if self.levelTabExplore[id] ~= nil then
local dayOpen = self.levelTabExplore[id].baseData.DayOpen
local openTime = self.startTimeRefreshTime + dayOpen * 86400
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
if openTime <= nCurTime then
return true
end
end
elseif self.levelTabAdventure[id] ~= nil then
local dayOpen = self.levelTabAdventure[id].baseData.DayOpen
local openTime = self.startTimeRefreshTime + dayOpen * 86400
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
if openTime <= nCurTime then
return true
end
end
return false
end
function ActivityLevelTypeData:GetUnLockDay(nType, id)
if nType == GameEnum.ActivityLevelType.Explore then
local dayOpen = self.levelTabExplore[id].baseData.DayOpen
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local nDay = math.floor((self.startTimeRefreshTime + dayOpen * 86400 - nCurTime) / 86400)
return nDay
else
local dayOpen = self.levelTabAdventure[id].baseData.DayOpen
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local nDay = math.floor((self.startTimeRefreshTime + dayOpen * 86400 - nCurTime) / 86400)
return nDay
end
return 1
end
function ActivityLevelTypeData:GetUnLockHour(nType, id)
if nType == GameEnum.ActivityLevelType.Explore then
local dayOpen = self.levelTabExplore[id].baseData.DayOpen
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local openTime = self.startTimeRefreshTime + dayOpen * 86400
local nRemainTime = openTime - nCurTime
local hour = math.floor(nRemainTime / 3600)
local min = math.floor((nRemainTime - hour * 3600) / 60)
local sec = nRemainTime - hour * 3600 - min * 60
return hour, min, sec
else
local dayOpen = self.levelTabAdventure[id].baseData.DayOpen
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local openTime = self.startTimeRefreshTime + dayOpen * 86400
local nRemainTime = openTime - nCurTime
local hour = math.floor(nRemainTime / 3600)
local min = math.floor((nRemainTime - hour * 3600) / 60)
local sec = nRemainTime - hour * 3600 - min * 60
return hour, min, sec
end
return 1, 0, 0
end
function ActivityLevelTypeData:GetLevelUnLock(nType, id)
if nType == GameEnum.ActivityLevelType.Explore then
if self.levelTabExplore[id] ~= nil then
local preLevelId = self.levelTabExplore[id].baseData.PreLevelId
if preLevelId == 0 then
return true
else
local preLevelData = self.levelTabExplore[preLevelId]
local preLevelStar = self.levelTabExplore[id].baseData.PreLevelStar
if preLevelData and preLevelStar <= preLevelData.Star then
return true
end
end
end
elseif self.levelTabAdventure[id] ~= nil then
local preLevelId = self.levelTabAdventure[id].baseData.PreLevelId
if preLevelId == 0 then
return true
else
local preLevelData = self.levelTabAdventure[preLevelId]
if preLevelData == nil then
preLevelData = self.levelTabExplore[preLevelId]
end
local preLevelStar = self.levelTabAdventure[id].baseData.PreLevelStar
if preLevelData and preLevelStar <= preLevelData.Star then
return true
end
end
end
return false
end
function ActivityLevelTypeData:GetDefaultSelectionType()
for i, v in pairs(self.levelTabAdventureDifficulty) do
local isOpen = self:GetLevelDayOpen(GameEnum.ActivityLevelType.Adventure, v)
local isLevelUnLock = self:GetLevelUnLock(GameEnum.ActivityLevelType.Adventure, v)
local star = self.levelTabAdventure[v].Star
if isOpen and isLevelUnLock and star == 0 then
return GameEnum.ActivityLevelType.Adventure
end
end
return GameEnum.ActivityLevelType.Explore
end
function ActivityLevelTypeData:GetDefaultSelectionDifficulty(nType)
local index = 1
if nType == GameEnum.ActivityLevelType.Explore then
for i, v in pairs(self.levelTabExploreDifficulty) do
local isOpen = self:GetLevelDayOpen(nType, v)
local isLevelUnLock = self:GetLevelUnLock(nType, v)
if isOpen and isLevelUnLock then
index = i
end
end
else
for i, v in pairs(self.levelTabAdventureDifficulty) do
local isOpen = self:GetLevelDayOpen(nType, v)
local isLevelUnLock = self:GetLevelUnLock(nType, v)
if isOpen and isLevelUnLock then
index = i
end
end
end
return index
end
function ActivityLevelTypeData:GetLevelFirstPass(nType, id)
if nType == GameEnum.ActivityLevelType.Explore then
if self.levelTabExplore[id] ~= nil and self.levelTabExplore[id].Star >= 1 then
return true
end
elseif self.levelTabAdventure[id] ~= nil and 1 <= self.levelTabAdventure[id].Star then
return true
end
return false
end
function ActivityLevelTypeData:SendEnterActivityLevelsApplyReq(nActivityId, nLevelId, nBuildId)
if nActivityId ~= self.nActId then
return
end
self.entryLevelId = nLevelId
self.entryBuildId = nBuildId
local msg = {}
msg.ActivityId = nActivityId
msg.LevelId = nLevelId
msg.BuildId = nBuildId
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local msgCallback = function(_, msgData)
self:SetCachedSelBuildId(nBuildId, nLevelId)
self:EnterActivityLevelInstance(nActivityId, nLevelId, nBuildId)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(msgData)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_levels_apply_req, msg, nil, msgCallback)
end
function ActivityLevelTypeData:EnterActivityLevelInstance(nActivityId, nLevelId, nBuildId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local luaClass = require("Game.Adventure.ActivityLevels.ActivityLevelsInstanceLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nActivityId, nLevelId, nBuildId)
end
end
function ActivityLevelTypeData:SendActivityLevelSettleReq(nActivityId, nStar, callback)
if 0 < nStar then
self:EventUpload(1)
else
self:EventUpload(2)
end
local msg = {}
msg.ActivityId = nActivityId
msg.Star = nStar
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.ActivityLevels, 0 < nStar)
}
local msgCallback = function(_, msgData)
if callback ~= nil then
if self.levelTabExplore[self.entryLevelId] then
self.levelTabExplore[self.entryLevelId].Star = nStar > self.levelTabExplore[self.entryLevelId].Star and nStar or self.levelTabExplore[self.entryLevelId].Star
self.levelTabExplore[self.entryLevelId].BuildId = self.entryBuildId
end
if self.levelTabAdventure[self.entryLevelId] then
self.levelTabAdventure[self.entryLevelId].Star = nStar > self.levelTabAdventure[self.entryLevelId].Star and nStar or self.levelTabAdventure[self.entryLevelId].Star
self.levelTabAdventure[self.entryLevelId].BuildId = self.entryBuildId
end
if callback ~= nil then
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(msgData.ChangeInfo)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
callback(msgData.Fixed, msgData.First, msgData.Exp, msgData.ChangeInfo)
end
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_levels_settle_req, msg, nil, msgCallback)
end
function ActivityLevelTypeData:EventUpload(result)
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self._TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self.entryBuildId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self.entryLevelId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
NovaAPI.UserEventUpload("activity_battle", tabUpLevel)
end
function ActivityLevelTypeData:SendActivityLevelsSweepReq(nActivityId, nLevelId, nTimes, callback)
if nActivityId ~= self.nActId then
return
end
local msg = {}
msg.ActivityId = self.nActId
msg.LevelId = nLevelId
msg.Times = nTimes
local successCallback = function(_, mapMainData)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMainData.ChangeInfo)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
callback(mapMainData.Rewards, mapMainData.ChangeInfo)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_levels_sweep_req, msg, nil, successCallback)
end
function ActivityLevelTypeData:LevelEnd()
self.curLevel = nil
end
function ActivityLevelTypeData:GetCachedBuildId(nLevelId)
return self.tabCachedBuildId[nLevelId] or 0
end
function ActivityLevelTypeData:SetCachedSelBuildId(nBuildId, levelId)
self.tabCachedBuildId[levelId] = nBuildId
end
function ActivityLevelTypeData:GetLevelBuild(nLevelId)
if self.levelTabExplore[nLevelId] then
if self.levelTabExplore[nLevelId].BuildId ~= 0 then
return self.levelTabExplore[nLevelId].BuildId
else
local PreLevelId = self.levelTabExplore[nLevelId].baseData.PreLevelId
if PreLevelId ~= 0 then
return self.levelTabExplore[PreLevelId].BuildId
end
end
end
if self.levelTabAdventure[nLevelId] then
if self.levelTabAdventure[nLevelId].BuildId ~= 0 then
return self.levelTabAdventure[nLevelId].BuildId
else
local PreLevelId = self.levelTabAdventure[nLevelId].baseData.PreLevelId
if PreLevelId ~= 0 then
if self.levelTabAdventure[PreLevelId] then
return self.levelTabAdventure[PreLevelId].BuildId
else
return self.levelTabExplore[PreLevelId].BuildId
end
end
end
end
return 0
end
function ActivityLevelTypeData:GetLevelStar(nLevelId)
if self.levelTabExplore[nLevelId] then
return self.levelTabExplore[nLevelId].Star
end
if self.levelTabAdventure[nLevelId] then
return self.levelTabAdventure[nLevelId].Star
end
return 0
end
return ActivityLevelTypeData
@@ -0,0 +1,347 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local ActivityShopData = class("ActivityShopData", ActivityDataBase)
local ClientManager = CS.ClientManager.Instance
local DisplayMode = {
Hide = 0,
End = 1,
Stay = 2
}
function ActivityShopData:Init()
self.tbShops = {}
self.tbGoods = {}
self.tbServerData = {}
self.bFirstInShop = true
self:ParseConfig()
end
function ActivityShopData:ParseConfig()
local mapCfg = ConfigTable.GetData("ActivityShopControl", self.nActId)
if not mapCfg then
return
end
self.mapShopControlCfg = mapCfg
end
function ActivityShopData:RefreshActivityShopData(mapData)
if mapData and mapData.Shops then
self:ProcessServerData(mapData.Shops)
end
if next(self.tbShops) == nil then
self:CreateData()
else
local tbShopIds = self:GetNeedToRefreshShops()
if 0 < #tbShopIds then
self:UpdateData(tbShopIds)
end
end
end
function ActivityShopData:CheckGoodsData(nShopId)
local tbGoods = self:GetNeedToRefreshGoods(nShopId)
if #tbGoods == 0 then
return
end
for _, mapGoods in pairs(tbGoods) do
self:UpdateGoodsData(nShopId, mapGoods.nId)
end
end
function ActivityShopData:GetShopList()
local tbList = {}
for _, mapShop in pairs(self.tbShops) do
if mapShop.bUnlock and mapShop.bOpenAble then
table.insert(tbList, mapShop)
end
end
table.sort(tbList, function(a, b)
return a.nSequence < b.nSequence
end)
return tbList
end
function ActivityShopData:GetGoodsList(nShopId)
local tbList = {}
for _, mapGoods in pairs(self.tbGoods[nShopId]) do
if mapGoods.bUnlock and (not mapGoods.bSoldOut or mapGoods.nDisplayMode ~= DisplayMode.Hide) then
table.insert(tbList, mapGoods)
end
end
local comp = function(a, b)
if (a.bSoldOut and a.nDisplayMode == DisplayMode.End) ~= (b.bSoldOut and b.nDisplayMode == DisplayMode.End) then
return (not a.bSoldOut or a.nDisplayMode ~= DisplayMode.End) and b.bSoldOut and b.nDisplayMode == DisplayMode.End
else
return a.nSaleNumber < b.nSaleNumber
end
end
table.sort(tbList, comp)
return tbList
end
function ActivityShopData:GetShopAutoUpdateTime()
local tbTime = {}
for _, mapShop in pairs(self.tbShops) do
if mapShop.nNextRefreshTime > 0 then
table.insert(tbTime, mapShop.nNextRefreshTime)
end
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function ActivityShopData:GetGoodsAutoUpdateTime(nShopId)
local tbTime = {}
for _, mapGoods in pairs(self.tbGoods[nShopId]) do
if mapGoods.nNextRefreshTime > 0 then
table.insert(tbTime, mapGoods.nNextRefreshTime)
end
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function ActivityShopData:GetShopFirstIn()
local bFirst = self.bFirstInShop
if self.bFirstInShop == true then
self.bFirstInShop = false
end
return bFirst
end
function ActivityShopData:CreateData()
if not self.mapShopControlCfg then
return
end
local nServerTimeStamp = ClientManager.serverTimeStamp
local nCloseTime = self.nEndTime
local bExpired = nCloseTime ~= 0 and nServerTimeStamp >= nCloseTime
if bExpired then
return
end
for _, nShopId in ipairs(self.mapShopControlCfg.ShopIds) do
local mapCfg = ConfigTable.GetData("ActivityShop", nShopId)
if mapCfg then
self:CreateShopData(mapCfg)
end
end
local func_ForEach_Goods = function(mapCfgData)
if self.tbShops[mapCfgData.ShopId] then
self:CreateGoodsData(mapCfgData)
end
end
ForEachTableLine(DataTable.ActivityGoods, func_ForEach_Goods)
end
function ActivityShopData:CreateShopData(mapCfgData)
local mapShop = {
nId = mapCfgData.Id,
nSequence = mapCfgData.Sequence,
nRefreshTimeType = mapCfgData.RefreshTimeType,
nRefreshInterval = mapCfgData.RefreshInterval,
nUnlockCondType = mapCfgData.UnlockCondType,
tbUnlockCondParams = decodeJson(mapCfgData.UnlockCondParams),
bUnlock = false,
bOpenAble = false,
nServerRefreshTime = 0,
nNextRefreshTime = 0
}
self.tbShops[mapCfgData.Id] = mapShop
self:UpdateShopData(mapCfgData.Id)
end
function ActivityShopData:CreateGoodsData(mapCfgData)
local mapGoods = {
nId = mapCfgData.Id,
nSaleNumber = mapCfgData.SaleNumber,
nMaximumLimit = mapCfgData.MaximumLimit,
nAppearCondType = mapCfgData.AppearCondType,
tbAppearCondParams = decodeJson(mapCfgData.AppearCondParams),
nPurchaseCondType = mapCfgData.PurchaseCondType,
tbPurchaseCondParams = decodeJson(mapCfgData.PurchaseCondParams),
nUnlockPurchaseTime = self:ChangeToTimeStamp(mapCfgData.UnlockPurchaseTime),
nDisplayMode = mapCfgData.DisplayMode,
bUnlock = false,
bPurchasable = false,
bPurchasTime = false,
bSoldOut = false,
nBoughtCount = 0,
nNextRefreshTime = 0
}
if not self.tbGoods[mapCfgData.ShopId] then
self.tbGoods[mapCfgData.ShopId] = {}
end
self.tbGoods[mapCfgData.ShopId][mapCfgData.Id] = mapGoods
self:UpdateGoodsData(mapCfgData.ShopId, mapCfgData.Id)
end
function ActivityShopData:ChangeToTimeStamp(sTime)
return sTime == "" and 0 or ClientManager:ISO8601StrToTimeStamp(sTime)
end
function ActivityShopData:UpdateData(tbShopIds)
local nServerTimeStamp = ClientManager.serverTimeStamp
local nCloseTime = self.nEndTime
local bExpired = nCloseTime ~= 0 and nServerTimeStamp >= nCloseTime
if bExpired then
self.tbShops = {}
self.tbGoods = {}
return
end
for _, nShopId in pairs(tbShopIds) do
self:UpdateShopData(nShopId)
for nGoodsId, _ in pairs(self.tbGoods[nShopId]) do
self:UpdateGoodsData(nShopId, nGoodsId)
end
end
end
function ActivityShopData:UpdateShopData(nId)
self.tbShops[nId].bUnlock = self:CheckShopCond(self.tbShops[nId].nUnlockCondType, self.tbShops[nId].tbUnlockCondParams)
self.tbShops[nId].bOpenAble = ClientManager.serverTimeStamp >= self.nOpenTime
self.tbShops[nId].nServerRefreshTime = self.tbServerData[nId] and self.tbServerData[nId].RefreshTime or 0
self.tbShops[nId].nNextRefreshTime = self:UpdateNextShopRefreshTime(nId, self.tbShops[nId].nServerRefreshTime)
end
function ActivityShopData:UpdateGoodsData(nShopId, nGoodsId)
local mapGoods = self.tbGoods[nShopId][nGoodsId]
local nBoughtCount = self:GetBoughtCount(nGoodsId)
self.tbGoods[nShopId][nGoodsId].bUnlock = self:CheckShopCond(mapGoods.nAppearCondType, mapGoods.tbAppearCondParams)
self.tbGoods[nShopId][nGoodsId].bPurchasable = self:CheckShopCond(mapGoods.nPurchaseCondType, mapGoods.tbPurchaseCondParams)
self.tbGoods[nShopId][nGoodsId].bPurchasTime = ClientManager.serverTimeStamp >= mapGoods.nUnlockPurchaseTime
self.tbGoods[nShopId][nGoodsId].bSoldOut = nBoughtCount ~= 0 and nBoughtCount == mapGoods.nMaximumLimit
self.tbGoods[nShopId][nGoodsId].nBoughtCount = nBoughtCount
self.tbGoods[nShopId][nGoodsId].nNextRefreshTime = self:UpdateNextGoodsRefreshTime(nShopId, nGoodsId)
end
function ActivityShopData:UpdateNextShopRefreshTime(nId, nServerRefreshTime)
local mapShop = self.tbShops[nId]
local nOpenTime = self.nOpenTime
if 0 < nOpenTime and 0 < nOpenTime - ClientManager.serverTimeStamp then
return nOpenTime
end
local nNextRefreshTime = 0
local nCloseTime = self.nEndTime
if 0 < nCloseTime then
nNextRefreshTime = nCloseTime
end
if 0 < mapShop.nRefreshTimeType then
local nTime = nServerRefreshTime
nNextRefreshTime = (nNextRefreshTime == 0 or nNextRefreshTime > nTime) and nTime or nNextRefreshTime
end
return nNextRefreshTime
end
function ActivityShopData:UpdateNextGoodsRefreshTime(nShopId, nGoodsId)
local mapGoods = self.tbGoods[nShopId][nGoodsId]
local nNextRefreshTime = 0
if 0 < mapGoods.nUnlockPurchaseTime then
local nTime = mapGoods.nUnlockPurchaseTime
nNextRefreshTime = (nNextRefreshTime == 0 or nNextRefreshTime > nTime) and nTime or nNextRefreshTime
end
return nNextRefreshTime
end
function ActivityShopData:ProcessServerData(mapServerData)
for _, mapShop in ipairs(mapServerData) do
self.tbServerData[mapShop.Id] = {}
self.tbServerData[mapShop.Id].RefreshTime = mapShop.RefreshTime or 0
for _, mapBoughtGoods in ipairs(mapShop.Infos) do
self.tbServerData[mapShop.Id][mapBoughtGoods.Id] = mapBoughtGoods.Number
end
end
end
function ActivityShopData:GetBoughtCount(nGoodsId)
local mapGoods = ConfigTable.GetData("ActivityGoods", nGoodsId)
if mapGoods == nil then
printError("商品配置不存在" .. nGoodsId)
return 0
end
local nShopId = mapGoods.ShopId
if self.tbServerData[nShopId] and self.tbServerData[nShopId][nGoodsId] then
return self.tbServerData[nShopId][nGoodsId]
else
return 0
end
end
function ActivityShopData:GetNeedToRefreshShops()
local tbShopIds = {}
local nServerTimeStamp = ClientManager.serverTimeStamp
for _, mapShop in pairs(self.tbShops) do
if not mapShop.bUnlock then
local bUnlock = self:CheckShopCond(mapShop.nUnlockCondType, mapShop.tbUnlockCondParams)
if bUnlock then
table.insert(tbShopIds, mapShop.nId)
end
elseif mapShop.nNextRefreshTime > 0 and nServerTimeStamp >= mapShop.nNextRefreshTime then
table.insert(tbShopIds, mapShop.nId)
end
end
return tbShopIds
end
function ActivityShopData:GetNeedToRefreshGoods(nShopId)
local tbGoods = {}
local nServerTimeStamp = ClientManager.serverTimeStamp
if self.tbGoods[nShopId] then
for _, mapGoods in pairs(self.tbGoods[nShopId]) do
if not mapGoods.bUnlock then
local bUnlock = self:CheckShopCond(mapGoods.nAppearCondType, mapGoods.tbAppearCondParams)
if bUnlock then
table.insert(tbGoods, mapGoods)
end
elseif not mapGoods.bPurchasable then
local bPurchasable = self:CheckShopCond(mapGoods.nPurchaseCondType, mapGoods.tbPurchaseCondParams)
if bPurchasable then
table.insert(tbGoods, mapGoods)
end
elseif mapGoods.nNextRefreshTime > 0 and nServerTimeStamp >= mapGoods.nNextRefreshTime then
table.insert(tbGoods, mapGoods)
end
end
end
return tbGoods
end
function ActivityShopData:CheckShopCond(eCond, tbParam)
if eCond == 0 then
return true
elseif eCond == GameEnum.shopCond.WorldClassSpecific and #tbParam == 1 then
local worldClass = PlayerData.Base:GetWorldClass()
return worldClass >= tbParam[1]
elseif eCond == GameEnum.shopCond.ShopPreGoodsSellOut and #tbParam == 2 then
local nBeforeId = tbParam[2]
local nBoughtCount = self:GetBoughtCount(nBeforeId)
local mapCfg = ConfigTable.GetData("ActivityGoods", nBeforeId)
if not mapCfg then
return false
end
local bSoldOut = nBoughtCount ~= 0 and nBoughtCount == mapCfg.MaximumLimit
return bSoldOut
elseif eCond == GameEnum.shopCond.ActivityShopPreGoodsSellOut and #tbParam == 3 then
local nBeforeId = tbParam[3]
local nBoughtCount = self:GetBoughtCount(nBeforeId)
local mapCfg = ConfigTable.GetData("ActivityGoods", nBeforeId)
if not mapCfg then
return false
end
local bSoldOut = nBoughtCount ~= 0 and nBoughtCount == mapCfg.MaximumLimit
return bSoldOut
else
printError("条件配置错误:")
return false
end
end
function ActivityShopData:SendActivityShopPurchaseReq(nShopId, nGoodsId, nCount, callback)
local mapMsg = {
ActivityId = self.nActId,
GoodsId = nGoodsId,
Number = nCount,
RefreshTime = self.tbShops[nShopId].nServerRefreshTime,
ShopId = nShopId
}
local successCallback = function(_, mapData)
if mapData.IsRefresh then
self:ProcessServerData({
mapData.Shop
})
EventManager.Hit("ActivityShopTimeRefresh")
else
if not self.tbServerData[nShopId] then
self.tbServerData[nShopId] = {}
end
self.tbServerData[nShopId][nGoodsId] = mapData.PurchasedNumber
end
self:UpdateData({nShopId})
UTILS.OpenReceiveByChangeInfo(mapData.Change)
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_shop_purchase_req, mapMsg, nil, successCallback)
end
return ActivityShopData
@@ -0,0 +1,177 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local ActivityTaskData = class("ActivityTaskData", ActivityDataBase)
local MAPSTATUS = {
[0] = AllEnum.ActQuestStatus.UnComplete,
[1] = AllEnum.ActQuestStatus.Complete,
[2] = AllEnum.ActQuestStatus.Received
}
function ActivityTaskData:Init()
self.tbActivityTaskGroupIds = {}
self.tbActivityTaskIds = {}
self.mapActivityTaskDatas = {}
self.mapActivityTaskGroupData = {}
self:InitConfig()
end
function ActivityTaskData:InitConfig()
local func_Parse_ActivityTaskGroup = function(mapData)
if mapData.ActivityId == self.nActId then
self.mapActivityTaskGroupData[mapData.Id] = {}
end
end
ForEachTableLine(DataTable.ActivityTaskGroup, func_Parse_ActivityTaskGroup)
local func_Parse_ActivityTask = function(mapData)
local nGroupId = mapData.ActivityTaskGroupId
local nTaskId = mapData.Id
if self.mapActivityTaskGroupData[nGroupId] ~= nil then
table.insert(self.mapActivityTaskGroupData[nGroupId], nTaskId)
end
end
ForEachTableLine(DataTable.ActivityTask, func_Parse_ActivityTask)
end
function ActivityTaskData:CacheData(mapData)
for _, nActivityTaskGroupId in ipairs(mapData.GroupIds) do
table.insert(self.tbActivityTaskGroupIds, nActivityTaskGroupId)
end
for _, Quest in ipairs(mapData.ActivityTasks.List) do
local nActivityTaskId = Quest.Id
if table.indexof(self.tbActivityTaskIds, nActivityTaskId) <= 0 then
table.insert(self.tbActivityTaskIds, nActivityTaskId)
end
local _nCur, _nMax = 0, 0
for __, QuestProgress in ipairs(Quest.Progress) do
_nCur = _nCur + QuestProgress.Cur
_nMax = _nMax + QuestProgress.Max
end
self.mapActivityTaskDatas[nActivityTaskId] = {
nStatus = MAPSTATUS[Quest.Status],
nExpire = Quest.Expire,
nCur = Quest.Status == 2 and _nMax or _nCur,
nMax = _nMax
}
end
self:RefreshTaskRedDot()
end
function ActivityTaskData:RefreshSingleQuest(questData)
if type(self.tbActivityTaskIds) ~= "table" or type(self.mapActivityTaskDatas) ~= "table" then
return
end
local nActivityTaskId = questData.Id
if table.indexof(self.tbActivityTaskIds, nActivityTaskId) <= 0 then
table.insert(self.tbActivityTaskIds, nActivityTaskId)
end
local data = self.mapActivityTaskDatas[nActivityTaskId]
if data == nil then
local _nCur, _nMax = 0, 0
for __, QuestProgress in ipairs(questData.Progress) do
_nCur = _nCur + QuestProgress.Cur
_nMax = _nMax + QuestProgress.Max
end
self.mapActivityTaskDatas[nActivityTaskId] = {
nStatus = MAPSTATUS[questData.Status],
nExpire = questData.Expire,
nCur = questData.Status == 2 and _nMax or _nCur,
nMax = _nMax
}
data = self.mapActivityTaskDatas[nActivityTaskId]
end
data.nStatus = MAPSTATUS[questData.Status]
local _nCur, _nMax = 0, 0
for __, QuestProgress in ipairs(questData.Progress) do
_nCur = _nCur + QuestProgress.Cur
_nMax = _nMax + QuestProgress.Max
end
data.nCur = questData.Status == 2 and _nMax or _nCur
data.nMax = _nMax
self:RefreshTaskRedDot()
end
function ActivityTaskData:RefreshTaskRedDot()
local bActOpen = self:CheckActivityOpen()
for nGroupId, tbList in pairs(self.mapActivityTaskGroupData) do
local nAllCount = #tbList
local nReceivedCount = 0
local nCompleteCount = 0
for _, nTaskId in ipairs(tbList) do
local mapData = self.mapActivityTaskDatas[nTaskId]
if mapData ~= nil then
if mapData.nStatus == AllEnum.ActQuestStatus.Complete then
nCompleteCount = nCompleteCount + 1
elseif mapData.nStatus == AllEnum.ActQuestStatus.Received then
nReceivedCount = nReceivedCount + 1
end
end
end
local bTotalReceived = 0 < table.indexof(self.tbActivityTaskGroupIds, nGroupId)
local bHasReward = false
local mapGroupCfg = ConfigTable.GetData("ActivityTaskGroup", nGroupId)
if mapGroupCfg ~= nil then
for i = 1, 6 do
local nTid = mapGroupCfg["Reward" .. i]
local nCount = mapGroupCfg["RewardQty" .. i]
if nTid ~= 0 and 0 < nCount then
bHasReward = true
break
end
end
end
if bHasReward == false then
bTotalReceived = true
end
local bCanReceive = 0 < nCompleteCount or nReceivedCount == nAllCount and not bTotalReceived
local bInActGroup, nActGroupId = PlayerData.Activity:IsActivityInActivityGroup(self.nActId)
local bActGroupUnlock = true
if bInActGroup then
local actGroupData = PlayerData.Activity:GetActivityGroupDataById(nActGroupId)
bActGroupUnlock = actGroupData:IsUnlock()
end
RedDotManager.SetValid(RedDotDefine.Activity_Group_Task_Group, {
nActGroupId,
self.nActId,
nGroupId
}, bCanReceive and bActOpen and bActGroupUnlock)
end
end
function ActivityTaskData:SendMsg_ActivityTaskRewardReceiveReq(nActivityTaskGroupId, nActivityTaskId, nTabType, ui_ctrl_callback)
local mapSend = {}
mapSend.GroupId = nActivityTaskGroupId
mapSend.TabType = nTabType
mapSend.QuestId = nActivityTaskId
local succ_cb = function(_, mapData)
local receiveCallback = function()
if type(ui_ctrl_callback) == "function" then
ui_ctrl_callback()
end
end
UTILS.OpenReceiveByChangeInfo(mapData, receiveCallback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_task_reward_receive_req, mapSend, nil, succ_cb)
end
function ActivityTaskData:SendMsg_ActivityTaskGroupRewardReceiveReq(nActivityTaskGroupId, ui_ctrl_callback)
local mapSend = {}
mapSend.Value = nActivityTaskGroupId
local succ_cb = function(_, mapData)
if table.indexof(self.tbActivityTaskGroupIds, nActivityTaskGroupId) <= 0 then
table.insert(self.tbActivityTaskGroupIds, nActivityTaskGroupId)
end
if type(ui_ctrl_callback) == "function" then
ui_ctrl_callback()
end
UTILS.OpenReceiveByChangeInfo(mapData)
self:RefreshTaskRedDot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_task_group_reward_receive_req, mapSend, nil, succ_cb)
end
function ActivityTaskData:CalcTotalProgress()
local nDone = 0
local nTotal = 0
for k, v in pairs(self.mapActivityTaskDatas) do
nTotal = nTotal + 1
if v.nStatus == AllEnum.ActQuestStatus.Received then
nDone = nDone + 1
end
end
return nDone, nTotal
end
function ActivityTaskData:GetAllTaskList()
return self.mapActivityTaskGroupData, self.mapActivityTaskDatas
end
return ActivityTaskData
@@ -0,0 +1,34 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local AdvertiseActData = class("AdvertiseActData", ActivityDataBase)
function AdvertiseActData:Init()
self.nStatus = 0
self.jointDrillActCfg = nil
self.bIsMove = ConfigTable.GetData("AdControl", self.actCfg.Id).IsMove
self:InitConfig()
end
function AdvertiseActData:InitConfig()
end
function AdvertiseActData:RefreshInfinityTowerActData(msgData)
end
function AdvertiseActData:GetActOpenTime()
return self.nOpenTime
end
function AdvertiseActData:GetActCloseTime()
return self.nEndTime
end
function AdvertiseActData:GetActSortId()
if self.bIsMove and self:isFinishAllTasks() then
return 9999
else
return self.actCfg.SortId
end
end
function AdvertiseActData:isFinishAllTasks()
local nTotalCount, nReceivedCount = PlayerData.TutorialData:GetProgress()
local bHasReceiveAllGroup = PlayerData.Quest:CheckTourGroupReward(PlayerData.Quest:GetMaxTourGroupOrderIndex())
if bHasReceiveAllGroup and nTotalCount == nReceivedCount then
return true
end
return false
end
return AdvertiseActData
@@ -0,0 +1,509 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local BdConvertData = class("BdConvertData", ActivityDataBase)
local LocalData = require("GameCore.Data.LocalData")
local RapidJson = require("rapidjson")
local RedDotManager = require("GameCore.RedDot.RedDotManager")
local ClientManager = CS.ClientManager.Instance
function BdConvertData:Init()
self:InitData()
self:AddListeners()
end
function BdConvertData:InitData()
self.allQuestData = {}
self.bdCfgData = nil
self.tbBdData = {}
self.AllBuild = {}
self:InitBuildRank()
end
function BdConvertData:UpdateStatus()
end
function BdConvertData:AddListeners()
end
function BdConvertData:GetActConfig()
self.actCfgData = ConfigTable.GetData("BdConvertControl", self.nActId)
return self.actCfgData
end
function BdConvertData:GetBdConvertConfig()
return self.bdCfgData
end
function BdConvertData:CreateBuildData(mapBuildMsg)
if nil ~= self.AllBuild[mapBuildMsg.Id] then
printLog(string.format("编队信息重复!!!id= [%s]", mapBuildMsg.Id))
end
local mapBuildData = {
nBuildId = mapBuildMsg.Brief.Id,
sName = mapBuildMsg.Brief.Name,
tbChar = {},
nScore = mapBuildMsg.Brief.Score,
mapRank = self:CalBuildRank(mapBuildMsg.Brief.Score),
bLock = mapBuildMsg.Brief.Lock,
bPreference = mapBuildMsg.Brief.Preference,
bDetail = false,
tbDisc = mapBuildMsg.Brief.DiscIds,
tbSecondarySkill = mapBuildMsg.Detail.ActiveSecondaryIds,
tbPotentials = {},
tbNotes = {},
nTowerId = mapBuildMsg.Brief.StarTowerId
}
for i = 1, 3 do
table.insert(mapBuildData.tbChar, {
nTid = mapBuildMsg.Brief.Chars[i].CharId,
nPotentialCount = mapBuildMsg.Brief.Chars[i].PotentialCnt
})
end
mapBuildData.tbDisc = mapBuildMsg.Brief.DiscIds
self.AllBuild[mapBuildMsg.Brief.Id] = mapBuildData
for _, v in ipairs(mapBuildMsg.Detail.Potentials) do
local potentialCfg = ConfigTable.GetData("Potential", v.PotentialId)
if potentialCfg then
local nCharId = potentialCfg.CharId
if nil == self.AllBuild[mapBuildMsg.Brief.Id].tbPotentials[nCharId] then
self.AllBuild[mapBuildMsg.Brief.Id].tbPotentials[nCharId] = {}
end
table.insert(self.AllBuild[mapBuildMsg.Brief.Id].tbPotentials[nCharId], {
nPotentialId = v.PotentialId,
nLevel = v.Level
})
end
end
local tbNotes = {}
for _, v in pairs(mapBuildMsg.Detail.SubNoteSkills) do
tbNotes[v.Tid] = v.Qty
end
self.AllBuild[mapBuildMsg.Brief.Id].tbNotes = tbNotes
self.AllBuild[mapBuildMsg.Brief.Id].bDetail = true
end
function BdConvertData:CalBuildRank(nScore)
local nMin = 1
local nMax = self._nBuildRankCount
local mapRank = self._tbBuildRank[1]
while nMin <= nMax do
local nMiddle = math.floor((nMin + nMax) / 2)
if nMiddle == self._nBuildRankCount or nScore >= self._tbBuildRank[nMiddle].MinGrade and nScore < self._tbBuildRank[nMiddle + 1].MinGrade then
mapRank = self._tbBuildRank[nMiddle]
break
elseif nScore < self._tbBuildRank[nMiddle].MinGrade then
nMax = nMiddle - 1
else
nMin = nMiddle + 1
end
end
return mapRank
end
function BdConvertData:InitBuildRank()
self._tbBuildRank = {}
local foreach = function(line)
self._tbBuildRank[line.Id] = line
end
ForEachTableLine(DataTable.StarTowerBuildRank, foreach)
self._nBuildRankCount = #self._tbBuildRank
end
function BdConvertData:GetAllBuildByOpId(nOptionId)
local contentCfg = ConfigTable.GetData("BdConvertContent", nOptionId)
if contentCfg == nil then
return nil
end
local tbBuild = {}
for _, mapData in pairs(self.AllBuild) do
local bResult = true
for _, conditionId in ipairs(contentCfg.ConvertConditionList) do
local bPass = self:CheckBuildData(mapData, conditionId)
if not bPass then
bResult = false
break
end
end
if bResult then
table.insert(tbBuild, mapData)
end
end
return tbBuild
end
function BdConvertData:CheckBuildData(mapData, nCondId)
local condiCfg = ConfigTable.GetData("BdConvertCondition", nCondId)
if condiCfg == nil then
return false
end
local bResult = false
local nBdRequest = condiCfg.Cond
if nBdRequest == GameEnum.BdRequest.BdMaxLevel then
bResult = mapData.nScore >= condiCfg.CondParams[1]
elseif nBdRequest == GameEnum.BdRequest.BdNoteAllKindNum then
local nNoteCount = 0
if mapData.tbNotes ~= nil then
for _, value in pairs(mapData.tbNotes) do
nNoteCount = nNoteCount + value
end
end
bResult = nNoteCount >= condiCfg.CondParams[1]
elseif nBdRequest == GameEnum.BdRequest.BdNoteOneKindNum then
if mapData.tbNotes ~= nil then
local noteId = condiCfg.CondParams[1]
local noteCount = mapData.tbNotes[noteId] or 0
bResult = noteCount >= condiCfg.CondParams[2]
end
elseif nBdRequest == GameEnum.BdRequest.BdPotentialNum then
if mapData.tbChar ~= nil then
local nPotentialCount = 0
for _, value in ipairs(mapData.tbChar) do
nPotentialCount = nPotentialCount + value.nPotentialCount
end
bResult = nPotentialCount >= condiCfg.CondParams[1]
end
elseif nBdRequest == GameEnum.BdRequest.BdPotentialLevelNum then
if mapData.tbPotentials ~= nil then
local nPotentialCount = 0
for _, charData in pairs(mapData.tbPotentials) do
for _, value in ipairs(charData) do
if value.nLevel >= condiCfg.CondParams[2] then
nPotentialCount = nPotentialCount + 1
end
end
end
bResult = nPotentialCount >= condiCfg.CondParams[1]
end
elseif nBdRequest == GameEnum.BdRequest.BdMainCharElementNum then
if mapData.tbChar ~= nil then
local mainCharId = mapData.tbChar[1].nTid
local charCfg = ConfigTable.GetData("Character", mainCharId)
if charCfg ~= nil then
bResult = charCfg.EET == condiCfg.CondParams[1]
end
end
elseif nBdRequest == GameEnum.BdRequest.BdCharElementNum then
if mapData.tbChar ~= nil then
local nCount = 0
for _, charData in ipairs(mapData.tbChar) do
local charCfg = ConfigTable.GetData("Character", charData.nTid)
if charCfg ~= nil and charCfg.EET == condiCfg.CondParams[2] then
nCount = nCount + 1
end
end
bResult = nCount >= condiCfg.CondParams[1]
end
elseif nBdRequest == GameEnum.BdRequest.BdCharJobNum then
if mapData.tbChar ~= nil then
local nCount = 0
for _, charData in ipairs(mapData.tbChar) do
local charCfg = ConfigTable.GetData("Character", charData.nTid)
if charCfg ~= nil and charCfg.Class == condiCfg.CondParams[2] then
nCount = nCount + 1
end
end
bResult = nCount >= condiCfg.CondParams[1]
end
elseif nBdRequest == GameEnum.BdRequest.BdActivateSkillLevelNum and mapData.tbSecondarySkill ~= nil then
local nCount = 0
for _, skillId in ipairs(mapData.tbSecondarySkill) do
local skillCfg = ConfigTable.GetData("SecondarySkill", skillId)
if skillCfg ~= nil and skillCfg.Level >= condiCfg.CondParams[2] then
nCount = nCount + 1
end
end
bResult = nCount >= condiCfg.CondParams[1]
end
return bResult
end
function BdConvertData:ChangeBuildLock(nBuildId, bLock, callback)
self:RequestChangeBuildLock(nBuildId, bLock, callback)
end
function BdConvertData:RefreshBdConvertData(actId, msgData)
self:InitData()
self.nActId = actId
self.bdCfgData = ConfigTable.GetData("BdConvert", self.nActId)
for _, optionId in ipairs(self.bdCfgData.OptionList) do
local optionData = ConfigTable.GetData("BdConvertContent", optionId)
if optionData ~= nil then
self:UpdateBdData({
nId = optionId,
nCurSub = 0,
nMaxSub = optionData.MaxSub,
bIsOpen = true
})
end
end
for _, contentData in ipairs(msgData.Contents) do
local optionData = ConfigTable.GetData("BdConvertContent", contentData.Id)
if optionData ~= nil then
self:UpdateBdData({
nId = contentData.Id,
nCurSub = contentData.Num,
nMaxSub = optionData.MaxSub,
bIsOpen = true
})
end
end
local foreach_questTable = function(data)
if data.GroupId == self.bdCfgData.RewardGroup then
self:UpdateQuest({
nId = data.Id,
nState = AllEnum.ActQuestStatus.UnComplete,
nCur = 0,
nMax = data.CompleteCondParams[2]
})
end
end
ForEachTableLine(DataTable.BdConvertRewardGroup, foreach_questTable)
local nCur = 0
local nMax = 0
for _, quest in pairs(msgData.Quests) do
if self:QuestStateServer2Client(quest.Status) == AllEnum.ActQuestStatus.UnComplete then
nCur = quest.Progress[1].Cur
nMax = quest.Progress[1].Max
else
local questCfg = ConfigTable.GetData("BdConvertRewardGroup", quest.Id)
if questCfg ~= nil then
nMax = questCfg.CompleteCondParams[2]
nCur = nMax
self:UpdateQuest({
nId = quest.Id,
nState = self:QuestStateServer2Client(quest.Status),
nCur = nCur,
nMax = nMax
})
end
end
end
self:RefreshRedDot()
end
function BdConvertData:GetBuildCount()
local nCount = 0
for _, data in pairs(self.AllBuild) do
if data ~= nil then
nCount = nCount + 1
end
end
return nCount
end
function BdConvertData:CheckBuildsData()
local bResult = false
if not PlayerData.Build:CheckHasBuild() then
bResult = true
else
local callback = function(tbBuildId, _)
if #tbBuildId ~= self:GetBuildCount() then
bResult = false
else
for _, buildId in ipairs(tbBuildId) do
if self.AllBuild[buildId] == nil then
bResult = false
break
end
end
end
end
PlayerData.Build:GetAllBuildBriefData(callback)
end
return bResult
end
function BdConvertData:UpdateBdData(bdData)
self.tbBdData[bdData.nId] = bdData
end
function BdConvertData:GetAllBdData()
return self.tbBdData
end
function BdConvertData:GetBdDataBy(id)
return self.tbBdData[id]
end
function BdConvertData:SubmitBuild(mapDataList)
end
function BdConvertData:UpdateQuest(questData)
local questConfig = ConfigTable.GetData("BdConvertRewardGroup", questData.nId)
if questConfig == nil then
return
end
if self.allQuestData == nil then
self.allQuestData = {}
end
self.allQuestData[questData.nId] = questData
RedDotManager.SetValid(RedDotDefine.Activity_BdConvert_Quest, questData.nId, questData.nState == AllEnum.ActQuestStatus.Complete)
EventManager.Hit("BdConvertQuestUpdate")
end
function BdConvertData:GetAllQuestCount()
local nResult = 0
for _, _ in pairs(self.allQuestData) do
nResult = nResult + 1
end
return nResult
end
function BdConvertData:GetAllReceivedCount()
local nResult = 0
for _, quest in pairs(self.allQuestData) do
if quest.nState == AllEnum.ActQuestStatus.Received then
nResult = nResult + 1
end
end
return nResult
end
function BdConvertData:GetQuestIdList()
local questIdList = {}
for _, data in pairs(self.allQuestData) do
table.insert(questIdList, data.nId)
end
local sortFunc = function(a, b)
local aData = self:GetQuestDataById(a)
local bData = self:GetQuestDataById(b)
if aData ~= nil and bData ~= nil and aData.nState ~= bData.nState then
return aData.nState < bData.nState
end
return a < b
end
table.sort(questIdList, sortFunc)
return questIdList
end
function BdConvertData:GetQuestDataById(nId)
return self.allQuestData[nId]
end
function BdConvertData:GetScore()
local nItemId = self.bdCfgData.ScoreItemId
return PlayerData.Item:GetItemCountByID(nItemId)
end
function BdConvertData:QuestStateServer2Client(nStatus)
if nStatus == 0 then
return AllEnum.ActQuestStatus.UnComplete
elseif nStatus == 1 then
return AllEnum.ActQuestStatus.Complete
else
return AllEnum.ActQuestStatus.Received
end
end
function BdConvertData:RefreshQuestData(questData)
local nCur = 0
local nMax = 0
if self:QuestStateServer2Client(questData.Status) == AllEnum.ActQuestStatus.UnComplete then
nCur = questData.Progress[1].Cur
nMax = questData.Progress[1].Max
else
local questCfg = ConfigTable.GetData("BdConvertRewardGroup", questData.Id)
if questCfg == nil then
return
end
nMax = questCfg.CompleteCondParams[2]
nCur = nMax
end
self:UpdateQuest({
nId = questData.Id,
nState = self:QuestStateServer2Client(questData.Status),
nCur = nCur,
nMax = nMax
})
self:RefreshRedDot()
end
function BdConvertData:CheckHasComQuest()
local bHasCompleteQuest = false
for _, questData in pairs(self.allQuestData) do
if questData.nState == AllEnum.ActQuestStatus.Complete then
bHasCompleteQuest = true
break
end
end
return bHasCompleteQuest
end
function BdConvertData:RefreshRedDot()
if not self:GetPlayState() then
return
end
local bReddot = false
for _, questData in pairs(self.allQuestData) do
bReddot = bReddot or questData.nState == AllEnum.ActQuestStatus.Complete
if bReddot then
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bReddot)
return
end
end
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, false)
end
function BdConvertData:RequestReceiveQuest(callback)
local bHasCompleteQuest = self:CheckHasComQuest()
if not bHasCompleteQuest then
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("BdConvert_NoComQuest"))
return
end
local mapMsg = {
Value = self.nActId
}
local cb = function(_, mapMsgData)
for _, questId in pairs(mapMsgData.Ids) do
local config = ConfigTable.GetData("BdConvertRewardGroup", questId)
if config ~= nil then
local data = {
nId = questId,
nState = AllEnum.ActQuestStatus.Received,
nCur = config.CompleteCondParams[2],
nMax = config.CompleteCondParams[2]
}
self:UpdateQuest(data)
end
end
self:RefreshRedDot()
UTILS.OpenReceiveByChangeInfo(mapMsgData.Change)
if callback ~= nil then
callback()
end
EventManager.Hit("BdConvertQuestReceived")
end
HttpNetHandler.SendMsg(NetMsgId.Id.build_convert_group_reward_receive_req, mapMsg, nil, cb)
end
function BdConvertData:RequestSubmitBuild(nContentId, tbBuildId)
local mapMsg = {
ActivityId = self.nActId,
BuildIds = tbBuildId,
ContentId = nContentId
}
local cb = function(_, mapMsgData)
for _, buildId in ipairs(tbBuildId) do
self.AllBuild[buildId] = nil
end
PlayerData.Build:DeleteBuildByActivity(tbBuildId)
local optionData = ConfigTable.GetData("BdConvertContent", nContentId)
if optionData ~= nil then
self:UpdateBdData({
nId = nContentId,
nCurSub = mapMsgData.Number,
nMaxSub = optionData.MaxSub,
bIsOpen = true
})
end
if mapMsgData.AwardItems ~= nil then
local tbReward = {}
for _, reward in ipairs(mapMsgData.AwardItems) do
table.insert(tbReward, {
id = reward.Tid,
rewardType = AllEnum.RewardType.Three,
count = reward.Qty,
nHasCount = PlayerData.Item:GetItemCountByID(reward.Tid)
})
end
EventManager.Hit("BdConvert_ShowReward", mapMsgData.AwardItems, optionData.Icon)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.build_convert_submit_req, mapMsg, nil, cb)
end
function BdConvertData:RequestAllBuildData(callback)
local mapMsg = {}
local cb = function(_, mapMsgData)
self.AllBuild = {}
for _, buildData in pairs(mapMsgData.Details) do
self:CreateBuildData(buildData)
end
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.build_convert_detail_list_get_req, mapMsg, nil, cb)
end
function BdConvertData:RequestChangeBuildLock(nBuildId, bLock, callback)
local msg = {BuildId = nBuildId, Lock = bLock}
local callBack = function()
self.AllBuild[nBuildId].bLock = bLock
if callback ~= nil then
callback()
end
end
if PlayerData.Build:CheckHasBuild() then
PlayerData.Build:ChangeBuildLock(nBuildId, bLock, callBack)
else
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_lock_unlock_req, msg, nil, callBack)
end
end
return BdConvertData
@@ -0,0 +1,61 @@
local ActivityGroupDataBase = require("GameCore.Data.DataClass.Activity.ActivityGroupDataBase")
local BreakOut_30101Data = class("BreakOut_30101Data", ActivityGroupDataBase)
function BreakOut_30101Data:Init()
self.tbAllActivity = {}
self.nCGActivityId = 0
self.sCGPath = ""
self.bPlayedCG = false
self:ParseActivity()
end
function BreakOut_30101Data:ParseActivity()
if self.actGroupConfig == nil then
self.actGroupConfig = ConfigTable.GetData("ActivityGroup", self.nActGroupId)
end
local sJson = self.actGroupConfig.Enter
local tbJson = decodeJson(sJson)
for _, activity in pairs(tbJson) do
local data = {
ActivityId = activity[1],
Index = activity[2],
PanelId = activity[3]
}
table.insert(self.tbAllActivity, data)
end
local sCgJson = self.actGroupConfig.CG
if sCgJson ~= nil then
local tbCGJson = decodeJson(sCgJson)
self.nCGActivityId = tonumber(tbCGJson[1])
self.sCGPath = tbCGJson[2]
end
end
function BreakOut_30101Data:GetActivityDataByIndex(nIndex)
for _, activity in pairs(self.tbAllActivity) do
if activity.Index == nIndex then
return activity
end
end
end
function BreakOut_30101Data:PlayCG()
self:SendMsg_CG_READ(self.nCGActivityId)
end
function BreakOut_30101Data:GetActivityGroupCGPlayed()
if self.bPlayedCG then
return true
end
return PlayerData.Activity:IsCGPlayed(self.nCGActivityId)
end
function BreakOut_30101Data:IsActivityInActivityGroup(nActivityId)
for _, activity in pairs(self.tbAllActivity) do
if activity.ActivityId == nActivityId then
return true, self.nActGroupId
end
end
return false
end
function BreakOut_30101Data:SendMsg_CG_READ(nActivityId)
local Callback = function()
self.bPlayedCG = true
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cg_read_req, {nActivityId}, nil, Callback)
end
return BreakOut_30101Data
@@ -0,0 +1,74 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local LocalData = require("GameCore.Data.LocalData")
local BreakOutData = class("BreakOutData", ActivityDataBase)
function BreakOutData:Init()
self.allLevelData = {}
end
function BreakOutData:RefreshBreakOutData(actId, msgData)
self:Init()
self.nActId = actId
self.mapActData = PlayerData.Activity:GetActivityDataById(self.nActId)
if self.mapActData ~= nil then
self.nEndTime = self.mapActData:GetActEndTime() or 0
self.nOpenTime = self.mapActData:GetActOpenTime() or 0
end
if msgData ~= nil then
self:CacheAllLevelData(msgData.Levels)
self:CacheAllCharacterData(msgData.Characters)
end
end
function BreakOutData:CacheAllLevelData(levelListData)
self.tbLevelDataList = {}
for _, v in pairs(levelListData) do
local levelData = {
nId = v.Id,
bFirstComplete = v.FirstCompelete,
nDifficultyType = ConfigTable.GetData("BreakOutLevel", v.Id).Difficulty
}
table.insert(self.tbLevelDataList, levelData)
end
end
function BreakOutData:GetLevelData()
return self.tbLevelDataList
end
function BreakOutData:GetLevelDataById(nId)
local levelData
for _, v in pairs(self.tbLevelDataList) do
if v.nId == nId then
levelData = v
break
end
end
return levelData
end
function BreakOutData:GetDetailLevelDataById(nId)
local levelData
for _, v in pairs(self.tbLevelDataList) do
if v.nId == nId then
levelData = ConfigTable.GetData("BreakOutLevel", self.nId)
break
end
end
return levelData
end
function BreakOutData:GetDetailLevelsDataByTab(nSelectedTabIndex)
local DifficultyLevelData = {}
for _, v in pairs(self.tbLevelDataList) do
if v.nDifficultyType == nSelectedTabIndex then
table.insert(DifficultyLevelData, ConfigTable.GetData("BreakOutLevel", self.nId))
end
end
return DifficultyLevelData
end
function BreakOutData:IsLevelUnlocked(nLevelId)
local bTimeUnlock, bPreComplete = false, false
local mapData = self:GetLevelDataById(nLevelId)
local curTime = CS.ClientManager.Instance.serverTimeStamp
local remainTime = curTime - (self.nOpenTime or 0 + mapData.DayOpen * 86400)
local nPreLevelId = mapData.PreLevelId or 0
local mapLevelStatus = self:GetLevelDataById(nPreLevelId)
bTimeUnlock = 0 <= remainTime
bPreComplete = nPreLevelId == 0 or mapLevelStatus ~= nil and mapLevelStatus.bFirstComplete
return bTimeUnlock, bPreComplete
end
return DifficultyLevelData
@@ -0,0 +1,252 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local CookieActData = class("CookieActData", ActivityDataBase)
local LocalData = require("GameCore.Data.LocalData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
local nLastPath = 0
function CookieActData:GetCookieControlCfg(...)
if not self.tbConfig then
self.tbConfig = ConfigTable.GetData("CookieControl", self.nActId)
end
return self.tbConfig
end
function CookieActData:GetLevelCfg(nPlayGroupId)
local mapConfig = ConfigTable.GetData("CookieLevel", nPlayGroupId)
if mapConfig == nil then
return nil
end
return mapConfig
end
function CookieActData:Init()
self.nTotalScore = 0
self.nActCredit = 0
self.nActId = 0
self.nNightmareModeHighScore = 0
self.tbLevelScore = {}
self.tbLevelBox = {}
self.tbModeComp = {}
self.tbModeBox = {}
self.tbModePerfect = {}
self.tbModeExcellent = {}
self.tbModeCookie = {}
self:AddListeners()
end
function CookieActData:AddListeners()
EventManager.Add("Cookie_Game_Complete", self, self.OnEvent_GameComplete)
EventManager.Add("Cookie_Quest_Claim", self, self.OnEvent_QuestClaim)
end
function CookieActData:RefreshCookieGameActData(actId, msgData)
self:Init()
self.nActId = actId
self.mapActData = PlayerData.Activity:GetActivityDataById(self.nActId)
if self.mapActData ~= nil then
self.nEndTime = self.mapActData:GetActEndTime() or 0
self.nOpenTime = self.mapActData:GetActOpenTime() or 0
end
if msgData ~= nil then
self:CacheAllQuestData(msgData.Quests)
self:CacheAllLevelData(msgData.Levels)
end
end
function CookieActData:CacheAllQuestData(questListData)
self.tbQuestDataList = {}
for _, v in pairs(questListData) do
local questData = {
nId = v.Id,
nStatus = self:QuestServer2Client(v.Status),
progress = {
Cur = #v.Progress > 0 and v.Progress[1].Cur or 1,
Max = #v.Progress > 0 and v.Progress[1].Max or 1
}
}
table.insert(self.tbQuestDataList, questData)
end
end
function CookieActData:GetQuestData()
local tbData = {}
for _, v in pairs(self.tbQuestDataList) do
table.insert(tbData, v)
end
return tbData
end
function CookieActData:CacheAllLevelData(levelListData)
self.tbLevelDataList = {}
for _, v in pairs(levelListData) do
local levelData = {
nId = v.LevelId,
nMaxScore = v.MaxScore or 0,
bFirstComplete = v.FirstComplete
}
table.insert(self.tbLevelDataList, levelData)
end
end
function CookieActData:GetLevelData()
return self.tbLevelDataList
end
function CookieActData:GetLevelDataById(nId)
local levelData
for _, v in pairs(self.tbLevelDataList) do
if v.nId == nId then
levelData = v
break
end
end
return levelData
end
function CookieActData:SetLevelData(nLevelId, nLevelScore)
local oldLevelData = self:GetLevelDataById(nLevelId)
if oldLevelData == nil then
return
end
oldLevelData.nMaxScore = math.max(oldLevelData.nMaxScore or 0, nLevelScore or 0)
local mapCfg = self:GetLevelCfg(nLevelId)
local bFirstComplete = nLevelScore >= (mapCfg and mapCfg.FirstCompletionScore or 0)
oldLevelData.bFirstComplete = oldLevelData.bFirstComplete or bFirstComplete
end
function CookieActData:GetQuestDataById(nId)
local questData
if self.tbQuestDataList ~= nil then
for _, v in pairs(self.tbQuestDataList) do
if v.nId == nId then
questData = v
break
end
end
end
return questData
end
function CookieActData:RefreshQuestData(questData)
local oldQuestData = self:GetQuestDataById(questData.Id)
if oldQuestData == nil then
return
end
oldQuestData.nStatus = self:QuestServer2Client(questData.Status)
oldQuestData.progress = {
Cur = questData.Progress[1].Cur,
Max = questData.Progress[1].Max
}
EventManager.Hit("CookieQuestUpdate")
end
function CookieActData:RefreshQuestReddot()
local bTabReddot = false
if next(self.tbQuestDataList) ~= nil then
for _, v in pairs(self.tbQuestDataList) do
local bReddot = v.nStatus == AllEnum.ActQuestStatus.Complete
RedDotManager.SetValid(RedDotDefine.Activity_Cookie_Quest, v.nId, bReddot)
bTabReddot = bTabReddot or bReddot
end
end
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bTabReddot or self.bIsFirst)
end
function CookieActData:SendQuestReceive(nQuestId)
local callback = function(_, msgData)
UTILS.OpenReceiveByChangeInfo(msgData, nil)
if nQuestId == 0 then
for _, v in pairs(self.tbQuestDataList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete then
v.nStatus = AllEnum.ActQuestStatus.Received
end
end
else
local questData = self:GetQuestDataById(nQuestId)
if questData then
questData.nStatus = AllEnum.ActQuestStatus.Received
end
end
EventManager.Hit("CookieQuestUpdate")
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cookie_quest_reward_receive_req, {
ActivityId = self.nActId,
QuestId = nQuestId
}, nil, callback)
end
function CookieActData:QuestServer2Client(nStatus)
if nStatus == 0 then
return AllEnum.ActQuestStatus.UnComplete
elseif nStatus == 1 then
return AllEnum.ActQuestStatus.Complete
else
return AllEnum.ActQuestStatus.Received
end
end
function CookieActData:IsLevelUnlocked(nLevelId)
local bTimeUnlock, bPreComplete = false, false
local mapData = self:GetLevelCfg(nLevelId)
local curTime = CS.ClientManager.Instance.serverTimeStamp
local openTime = CS.ClientManager.Instance:GetNextRefreshTime(self.nOpenTime) - 86400
local remainTime = openTime + mapData.DayOpen * 86400 - curTime
local nPreLevelId = mapData.PreLevelId or 0
local mapLevelStatus = self:GetLevelDataById(nPreLevelId)
bTimeUnlock = remainTime <= 0
bPreComplete = nPreLevelId == 0 or mapLevelStatus ~= nil and mapLevelStatus.bFirstComplete
return bTimeUnlock, bPreComplete
end
function CookieActData:GetActEndTime()
return self.nEndTime
end
function CookieActData:GetActOpenTime()
return self.nOpenTime
end
function CookieActData:SetLevelReward(changeInfo)
if changeInfo ~= nil and #changeInfo.Props > 0 then
self.tbLevelReward = changeInfo
else
self.tbLevelReward = nil
end
end
function CookieActData:GetLevelReward()
return self.tbLevelReward
end
function CookieActData:GetNMHighScoreToday()
local bToday = false
local TipsTime = LocalData.GetPlayerLocalData("Cookie_Nightmare_HighScoreDay")
local _tipDay = 0
if TipsTime ~= nil then
_tipDay = tonumber(TipsTime)
end
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nYear = tonumber(os.date("!%Y", fixedTimeStamp))
local nMonth = tonumber(os.date("!%m", fixedTimeStamp))
local nDay = tonumber(os.date("!%d", fixedTimeStamp))
local nowD = nYear * 366 + nMonth * 31 + nDay
if nowD == _tipDay then
bToday = true
end
return bToday
end
function CookieActData:SetNMHighScoreDay()
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nYear = tonumber(os.date("!%Y", fixedTimeStamp))
local nMonth = tonumber(os.date("!%m", fixedTimeStamp))
local nDay = tonumber(os.date("!%d", fixedTimeStamp))
local nDayCount = nYear * 366 + nMonth * 31 + nDay
LocalData.SetPlayerLocalData("Cookie_Nightmare_HighScoreDay", nDayCount)
end
function CookieActData:RequestLevelResult(nLevelId, nScore, nBoxCount, nCookieCount, nGoodCount, nPerfectCount, nExcellentCount, nMissCount, callback)
local callbackFunc = function(_, msgData)
self:SetLevelData(nLevelId, nScore)
self:SetLevelReward(msgData)
if callback then
callback(msgData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cookie_settle_req, {
ActivityId = self.nActId,
LevelId = nLevelId,
Score = nScore,
PackageNum = nBoxCount,
CookieNum = nCookieCount,
PerfectNum = nPerfectCount,
ExcellentNum = nExcellentCount,
MissNum = nMissCount,
Good = nGoodCount
}, nil, callbackFunc)
end
function CookieActData:OnEvent_GameComplete(nLevelId, nScore, nBoxCount, nCookieCount, nGoodCount, nPerfectCount, nExcellentCount, nMissCount, callback)
self:RequestLevelResult(nLevelId, nScore, nBoxCount, nCookieCount, nGoodCount, nPerfectCount, nExcellentCount, nMissCount, callback)
end
function CookieActData:OnEvent_QuestClaim(nQuestId)
self:SendQuestReceive(nQuestId)
end
return CookieActData
@@ -0,0 +1,61 @@
local ActivityGroupDataBase = require("GameCore.Data.DataClass.Activity.ActivityGroupDataBase")
local Dream_10102Data = class("Dream_10102Data", ActivityGroupDataBase)
function Dream_10102Data:Init()
self.tbAllActivity = {}
self.nCGActivityId = 0
self.sCGPath = ""
self.bPlayedCG = false
self:ParseActivity()
end
function Dream_10102Data:ParseActivity()
if self.actGroupConfig == nil then
self.actGroupConfig = ConfigTable.GetData("ActivityGroup", self.nActGroupId)
end
local sJson = self.actGroupConfig.Enter
local tbJson = decodeJson(sJson)
for _, activity in pairs(tbJson) do
local data = {
ActivityId = activity[1],
Index = activity[2],
PanelId = activity[3]
}
table.insert(self.tbAllActivity, data)
end
local sCgJson = self.actGroupConfig.CG
if sCgJson ~= nil then
local tbCGJson = decodeJson(sCgJson)
self.nCGActivityId = tonumber(tbCGJson[1])
self.sCGPath = tbCGJson[2]
end
end
function Dream_10102Data:GetActivityDataByIndex(nIndex)
for _, activity in pairs(self.tbAllActivity) do
if activity.Index == nIndex then
return activity
end
end
end
function Dream_10102Data:PlayCG()
self:SendMsg_CG_READ(self.nCGActivityId)
end
function Dream_10102Data:GetActivityGroupCGPlayed()
if self.bPlayedCG then
return true
end
return PlayerData.Activity:IsCGPlayed(self.nCGActivityId)
end
function Dream_10102Data:IsActivityInActivityGroup(nActivityId)
for _, activity in pairs(self.tbAllActivity) do
if activity.ActivityId == nActivityId then
return true, self.nActGroupId
end
end
return false
end
function Dream_10102Data:SendMsg_CG_READ(nActivityId)
local Callback = function()
self.bPlayedCG = true
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cg_read_req, {nActivityId}, nil, Callback)
end
return Dream_10102Data
@@ -0,0 +1,37 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local JointDrillActData = class("JointDrillActData", ActivityDataBase)
function JointDrillActData:Init()
self.nStatus = 0
self.jointDrillActCfg = nil
self:InitConfig()
end
function JointDrillActData:InitConfig()
local mapActCfg = ConfigTable.GetData("JointDrillControl", self.nActId)
if nil == mapActCfg then
return
end
self.jointDrillActCfg = mapActCfg
end
function JointDrillActData:GetJointDrillActCfg()
return self.jointDrillActCfg
end
function JointDrillActData:RefreshJointDrillActData(msgData)
PlayerData.JointDrill:CacheJointDrillData(self.nActId, msgData)
end
function JointDrillActData:GetActOpenTime()
return self.nOpenTime
end
function JointDrillActData:GetActCloseTime()
return self.nEndTime
end
function JointDrillActData:GetChallengeStartTime()
if self.jointDrillActCfg ~= nil then
return self.nOpenTime + self.jointDrillActCfg.DrillStartTime
end
end
function JointDrillActData:GetChallengeEndTime()
if self.jointDrillActCfg ~= nil then
return self.nOpenTime + self.jointDrillActCfg.DrillStartTime + self.jointDrillActCfg.DrillDurationTime
end
end
return JointDrillActData
@@ -0,0 +1,57 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local LoginRewardActData = class("LoginRewardActData", ActivityDataBase)
function LoginRewardActData:Init()
self.nCanReceives = 0
self.nActual = 0
self.tbRewardList = {}
self.loginRewardActCfg = nil
self:InitRewardList()
end
function LoginRewardActData:InitRewardList()
local mapActCfg = ConfigTable.GetData("LoginRewardControl", self.nActId)
if nil == mapActCfg then
return
end
self.loginRewardActCfg = mapActCfg
local tbRewardList = CacheTable.GetData("_LoginRewardGroup", mapActCfg.RewardsGroup)
if tbRewardList == nil then
printError(string.format("LoginRewardGroup表中不存在奖励组id为 %s 的配置!!!", mapActCfg.RewardsGroup))
return
end
table.sort(tbRewardList, function(a, b)
return a.Order < b.Order
end)
self.tbRewardList = tbRewardList
end
function LoginRewardActData:RefreshLoginData(nReceive, nActual)
self.nCanReceives = nReceive
self.nActual = nActual
for k, v in ipairs(self.tbRewardList) do
v.Status = 0
if k <= nReceive then
v.Status = 1
end
if k <= nActual then
v.Status = 2
end
end
end
function LoginRewardActData:ReceiveRewardSuc()
self:RefreshLoginData(self.nCanReceives, self.nCanReceives)
end
function LoginRewardActData:GetActLoginRewardList()
return self.tbRewardList
end
function LoginRewardActData:GetCanReceive()
return self.nCanReceives
end
function LoginRewardActData:GetReceived()
return self.nActual
end
function LoginRewardActData:CheckCanReceive()
return self.nCanReceives > self.nActual
end
function LoginRewardActData:GetLoginRewardControlCfg()
return self.loginRewardActCfg
end
return LoginRewardActData
@@ -0,0 +1,402 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local LocalData = require("GameCore.Data.LocalData")
local MiningGameData = class("MiningGameData", ActivityDataBase)
function MiningGameData:Init()
self.tbQuestDataList = {}
self.bIsFirst = true
self.nScore = 0
self.tbGridDataList = {}
self.nCurLevel = 0
self.tbCurReward = {}
self.bCanGoNext = false
self.tbSupList = {}
self.nAddAxeCount_Daliy = 0
self.nAddAxeCount_LongTime = 0
self.tbConfig = {}
self.nConfigId = 0
self.tbCurDicGroupId = {}
self.tbCurStoryGroupData = {}
self.tbCurStoryListData = {}
self.nAxeId = 0
self:AddListeners()
end
function MiningGameData:AddListeners()
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Add("Mining_Daily_Reward", self, self.On_DailyReward_Update)
EventManager.Add("Mining_Supplement_Reward", self, self.On_SupplementReward_Update)
EventManager.Add("Mining_UpdateLevelData", self, self.OnEvent_Mining_UpdateLevelData)
EventManager.Add("Mining_UpdateRigResult", self, self.OnEvent_Mining_UpdateDigResult)
end
function MiningGameData:OnEvent_NewDay()
self.nAddAxeCount = 0
end
function MiningGameData:CacheAllQuestData(questListData)
self.tbQuestDataList = {}
for _, v in pairs(questListData) do
local questData = {
nId = v.Id,
nStatus = self:QuestServer2Client(v.Status),
progress = v.Progress
}
table.insert(self.tbQuestDataList, questData)
end
self:RefreshQuestReddot()
end
function MiningGameData:GetAllQuestData()
return self.tbQuestDataList
end
function MiningGameData:GetQuestData(nQuestId)
local questData
for _, v in pairs(self.tbQuestDataList) do
if v.nId == nQuestId then
questData = v
end
end
return questData
end
function MiningGameData:GetCompleteCount()
local nCount = 0
for _, v in pairs(self.tbQuestDataList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete or v.nStatus == AllEnum.ActQuestStatus.Received then
nCount = nCount + 1
end
end
return nCount
end
function MiningGameData:RefreshQuestData(questData)
end
function MiningGameData:RefreshQuestReddot()
local bTabReddot = false
if next(self.tbQuestDataList) ~= nil then
for _, v in pairs(self.tbQuestDataList) do
local bReddot = v.nStatus == AllEnum.ActQuestStatus.Complete
RedDotManager.SetValid(RedDotDefine.Activity_Mining_Quest, v.nId, bReddot)
bTabReddot = bTabReddot or bReddot
end
end
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bTabReddot or self.bIsFirst)
end
function MiningGameData:HasFinishQuest(...)
local bHasFinish = false
for _, v in pairs(self.tbQuestDataList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete then
bHasFinish = true
break
end
end
return bHasFinish
end
function MiningGameData:QuestServer2Client(nStatus)
if nStatus == 0 then
return AllEnum.ActQuestStatus.UnComplete
elseif nStatus == 1 then
return AllEnum.ActQuestStatus.Complete
else
return AllEnum.ActQuestStatus.Received
end
end
function MiningGameData:InitCurDicData()
local GetRewardsByGroupId = function(lineData)
if lineData.ActivityId == self.nActId then
table.insert(self.tbCurDicGroupId, lineData.Id)
end
end
ForEachTableLine(DataTable.MiningTreasure, GetRewardsByGroupId)
end
function MiningGameData:GetDicGroupId()
return self.tbCurDicGroupId
end
function MiningGameData:InitStoryData(readStoryList)
local GetRewardsByGroupId = function(lineData)
if lineData.ActivityId == self.nActId then
table.insert(self.tbCurStoryListData, {
nId = lineData.Id,
config = lineData
})
local isRead = function(id)
for _, v in ipairs(readStoryList) do
if v == id then
return true
end
end
return false
end
self.tbCurStoryGroupData[lineData.Id] = {
nId = lineData.Id,
bIsRead = isRead(lineData.Id),
self.nCurLevel < lineData.UnlockLayer
}
end
end
ForEachTableLine(DataTable.MiningStory, GetRewardsByGroupId)
table.sort(self.tbCurStoryListData, function(a, b)
return a.config.UnlockLayer < b.config.UnlockLayer
end)
end
function MiningGameData:GetGroupStoryData()
return self.tbCurStoryGroupData
end
function MiningGameData:GetStoryConfigIdList()
return self.tbCurStoryListData
end
function MiningGameData:UpdateStoryLockState(...)
for k, v in pairs(self.tbCurStoryGroupData) do
if v.bIsLock then
local config = DataTable.GetData("MiningStory", v.id)
if self.nCurLevel >= config.UnlockLayer then
v.bIsLock = false
end
end
end
end
function MiningGameData:ChangeStoryState(storyId)
if self.tbCurStoryGroupData[storyId] ~= nil then
self.tbCurStoryGroupData[storyId].bIsRead = true
end
end
function MiningGameData:GetSupDataList()
return self.tbSupList
end
function MiningGameData:GetCellData()
return self.tbGridDataList
end
function MiningGameData:RefreshMiningGameActData(actId, msgData)
self:Init()
self.nActId = actId
self.nCurLevel = msgData.Layer
self.tbConfig = ConfigTable.GetData("MiningControl", self.nActId)
self.nAxeId = self.tbConfig.DigConsumeItemId
local sKey = tostring(self.nActId) .. "IsFirst"
self.bIsFirst = LocalData.GetPlayerLocalData(sKey)
if self.bIsFirst == nil then
self.bIsFirst = true
end
self:InitCurDicData()
self.nScore = msgData.Score
end
function MiningGameData:GetIsFirstIn()
return self.bIsFirst
end
function MiningGameData:SetIsFirstIn()
self.bIsFirst = false
local sKey = tostring(self.nActId) .. "IsFirst"
LocalData.SetPlayerLocalData(sKey, self.bIsFirst)
end
function MiningGameData:GetLevel(...)
return self.nCurLevel
end
function MiningGameData:GetCurLevelRewardData()
return self.tbCurReward
end
function MiningGameData:GetCanGoNext(...)
return self.bCanGoNext
end
function MiningGameData:GetMiningCfg(...)
if not self.tbConfig then
self.tbConfig = ConfigTable.GetData("MiningControl", self.nActId)
end
return self.tbConfig
end
function MiningGameData:GetScore()
return self.nScore
end
function MiningGameData:AddScore(addValue)
self.nScore = self.nScore + addValue
EventManager.Hit("MiningGameUpdateScore", self.nScore)
end
function MiningGameData:ResponseLevelData(msgData, callback)
local layer = msgData.Layer
self.nCurLevel = layer.Layer
self.nMapId = layer.Map.Id
self.tbGridDataList = {}
for _, v in pairs(layer.Map.Grids) do
local cellData = {
nId = v.Id,
nIndex = v.PosIndex + 1,
nStatus = GameEnum.miningGridType[v.GridType],
bMark = v.Marked
}
table.insert(self.tbGridDataList, v.PosIndex + 1, cellData)
end
self.tbCurlevelEnterChange = msgData.MiningChangeInfo
self.tbCurReward = {}
for _, v in pairs(layer.Map.Treasures) do
local tbPosIndex = {}
for _, n in pairs(v.PosIndex) do
table.insert(tbPosIndex, n + 1)
end
local rewardData = {
nId = v.Id,
bIsGet = v.Received,
tbPosIndex = tbPosIndex
}
table.insert(self.tbCurReward, rewardData)
end
self.tbSupList = {}
for _, v in pairs(layer.Supports) do
table.insert(self.tbSupList, {
nId = v.Id
})
end
EventManager.Hit("MiningUpdateLevel")
if callback ~= nil then
callback()
end
end
function MiningGameData:DoEnterResult()
self:DoResult(self.tbCurlevelEnterChange)
end
function MiningGameData:DoResult(changeInfo)
if changeInfo == nil then
return
end
local tbSkillData = {}
for k, v in pairs(changeInfo.Processes) do
local tbUpdateGrid = {}
for _, m in pairs(v.EffectedGrids) do
self.tbGridDataList[m.PosIndex + 1].nStatus = GameEnum.miningGridType[m.GridType]
self.tbGridDataList[m.PosIndex + 1].bMark = m.Marked
table.insert(tbUpdateGrid, {
nIndex = m.PosIndex + 1,
nStatus = GameEnum.miningGridType[m.GridType],
bMark = m.Marked
})
end
local skillData = {
nEffectType = v.EffectType,
tbUpdateGrid = tbUpdateGrid
}
table.insert(tbSkillData, skillData)
end
for k, v in pairs(changeInfo.ReceivedTreasures) do
self:UpdateReward(v)
end
self:UpdateAxe()
self:AddScore(changeInfo.Score)
EventManager.Hit("MiningKnockResult", tbSkillData)
end
function MiningGameData:UpdateReward(nId)
for key, value in pairs(self.tbCurReward) do
if nId == value.nId then
value.bIsGet = true
end
end
EventManager.Hit("MiningUpdateReward", nId)
end
function MiningGameData:GetAxeId()
return self.nAxeId
end
function MiningGameData:GetAxeCount(...)
return PlayerData.Item:GetItemCountByID(self.nAxeId)
end
function MiningGameData:UpdateAxe(...)
EventManager.Hit("MiningAxeUpdate", PlayerData.Item:GetItemCountByID(self.nAxeId))
end
function MiningGameData:GetPassAllLevelResult()
local nMaxLevel = self.tbConfig.ConfigMaxLayer
if nMaxLevel > self.nCurLevel then
return false
end
for _, data in pairs(self.tbCurReward) do
if not data.bIsGet then
return false
end
end
return true
end
function MiningGameData:On_DailyReward_Update(msgData)
local tbItemList = PlayerData.Item:ProcessRewardChangeInfo(msgData)
for _, v in pairs(tbItemList) do
if v.nId == self.nAxeId then
self.nAddAxeCount_Daliy = v.nCount
break
end
end
end
function MiningGameData:On_SupplementReward_Update(msgData)
local tbItemList = PlayerData.Item:ProcessRewardChangeInfo(msgData)
for _, v in pairs(tbItemList) do
if v.nId == self.nAxeId then
self.nAddAxeCount_LongTime = v.nCount
break
end
end
end
function MiningGameData:GetAddAxeCount()
return self.nAddAxeCount_Daliy + self.nAddAxeCount_LongTime
end
function MiningGameData:ResetAddAxeCount()
self.nAddAxeCount_Daliy = 0
self.nAddAxeCount_LongTime = 0
end
function MiningGameData:OnEvent_Mining_UpdateLevelData(mapMsgData)
self:ResponseLevelData(mapMsgData)
end
function MiningGameData:OnEvent_Mining_UpdateDigResult(mapMsgData)
self:DoResult(mapMsgData.MiningChangeInfo)
end
function MiningGameData:RequestLevelData(nStatus, callback)
if nStatus == 0 then
local callbackFunc = function(_, msgData)
self:ResponseLevelData(msgData, callback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_mining_apply_req, {
ActivityId = self.nActId
}, nil, callbackFunc)
elseif nStatus == 1 then
local callbackFunc = function(_, msgData)
self:ResponseLevelData(msgData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_mining_move_to_next_layer_req, {
ActivityId = self.nActId
}, nil, callbackFunc)
end
end
function MiningGameData:RequestKnockCell(nId)
local nAxeCount = PlayerData.Item:GetItemCountByID(self.nAxeId)
if nAxeCount <= 0 then
return
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_mining_dig_req, {
ActivityId = self.nActId,
GridId = nId
}, nil, nil)
end
function MiningGameData:RequestFinishAvg(storyId, callback)
local msgCallback = function(_, mapMsgData)
self:ChangeStoryState(storyId)
EventManager.Hit(EventId.ClosePanel, PanelId.PureAvgStory)
if callback ~= nil then
callback(mapMsgData)
end
EventManager.Hit("MiningStoryFinish")
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_mining_story_reward_receive_req, {
ActivityId = self.nActId,
StoryId = storyId
}, nil, msgCallback)
end
function MiningGameData:SendQuestReceive(nQuestId)
local callback = function(_, msgData)
UTILS.OpenReceiveByChangeInfo(msgData.ChangeInfo, nil)
if nQuestId == 0 then
for _, v in pairs(self.tbQuestDataList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete then
v.nStatus = AllEnum.ActQuestStatus.Received
end
end
else
local questData = self:GetQuestData(nQuestId)
if questData then
questData.nStatus = AllEnum.ActQuestStatus.Received
end
end
EventManager.Hit("MiningQuestUpdate")
self:RefreshQuestReddot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_mining_quest_reward_receive_req, {
ActivityId = self.nActId,
QuestId = nQuestId
}, nil, callback)
end
return MiningGameData
@@ -0,0 +1,61 @@
local ActivityGroupDataBase = require("GameCore.Data.DataClass.Activity.ActivityGroupDataBase")
local OurRegiment_10101Data = class("OurRegiment_10101Data", ActivityGroupDataBase)
function OurRegiment_10101Data:Init()
self.tbAllActivity = {}
self.nCGActivityId = 0
self.sCGPath = ""
self.bPlayedCG = false
self:ParseActivity()
end
function OurRegiment_10101Data:ParseActivity()
if self.actGroupConfig == nil then
self.actGroupConfig = ConfigTable.GetData("ActivityGroup", self.nActGroupId)
end
local sJson = self.actGroupConfig.Enter
local tbJson = decodeJson(sJson)
for _, activity in pairs(tbJson) do
local data = {
ActivityId = activity[1],
Index = activity[2],
PanelId = activity[3]
}
table.insert(self.tbAllActivity, data)
end
local sCgJson = self.actGroupConfig.CG
if sCgJson ~= nil then
local tbCGJson = decodeJson(sCgJson)
self.nCGActivityId = tonumber(tbCGJson[1])
self.sCGPath = tbCGJson[2]
end
end
function OurRegiment_10101Data:GetActivityDataByIndex(nIndex)
for _, activity in pairs(self.tbAllActivity) do
if activity.Index == nIndex then
return activity
end
end
end
function OurRegiment_10101Data:PlayCG()
self:SendMsg_CG_READ(self.nCGActivityId)
end
function OurRegiment_10101Data:GetActivityGroupCGPlayed()
if self.bPlayedCG then
return true
end
return PlayerData.Activity:IsCGPlayed(self.nCGActivityId)
end
function OurRegiment_10101Data:IsActivityInActivityGroup(nActivityId)
for _, activity in pairs(self.tbAllActivity) do
if activity.ActivityId == nActivityId then
return true, self.nActGroupId
end
end
return false
end
function OurRegiment_10101Data:SendMsg_CG_READ(nActivityId)
local Callback = function()
self.bPlayedCG = true
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cg_read_req, {nActivityId}, nil, Callback)
end
return OurRegiment_10101Data
@@ -0,0 +1,216 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local PeriodicQuestActData = class("PeriodicQuestActData", ActivityDataBase)
local ClientManager = CS.ClientManager.Instance
function PeriodicQuestActData:Init()
self.tbAllQuestList = {}
self.bFinalStatus = false
self.perQuestActCfg = ConfigTable.GetData("PeriodicQuestControl", self.nActId)
self.nMaxQuestDay = self:GetMaxOpenDay()
end
function PeriodicQuestActData:CreateQuest(mapQuestData)
local tbQuestData = {}
tbQuestData.Id = mapQuestData.Id
if nil ~= mapQuestData.Progress[1] then
tbQuestData.nCurProcess = mapQuestData.Progress[1].Cur
tbQuestData.nTotalProcess = mapQuestData.Progress[1].Max
else
tbQuestData.nCurProcess = 0
tbQuestData.nTotalProcess = 0
end
if mapQuestData.Status == 0 then
tbQuestData.nStatus = AllEnum.ActQuestStatus.UnComplete
elseif mapQuestData.Status == 1 then
tbQuestData.nStatus = AllEnum.ActQuestStatus.Complete
elseif mapQuestData.Status == 2 then
tbQuestData.nStatus = AllEnum.ActQuestStatus.Received
end
local questCfg = ConfigTable.GetData("PeriodicQuest", mapQuestData.Id)
local nGroupId = questCfg.Groupid
tbQuestData.nGroupId = nGroupId
local nDay = CacheTable.GetData("_PeriodicQuestDay", self.nActId)[nGroupId]
tbQuestData.nDay = nDay
return tbQuestData
end
function PeriodicQuestActData:RefreshQuestList(mapQuestList)
for _, v in ipairs(mapQuestList) do
local tbQuestData = self:CreateQuest(v)
self.tbAllQuestList[v.Id] = tbQuestData
end
self:RefreshRedDot()
end
function PeriodicQuestActData:RefreshQuestData(questData)
self.tbAllQuestList[questData.Id] = self:CreateQuest(questData)
self:RefreshRedDot()
local bAllQuestComplete = self:CheckAllQuestComplete()
if bAllQuestComplete then
PlayerData.Base:UserEventUpload_PC("pc_start_mission_minerva")
end
end
function PeriodicQuestActData:RefreshQuestStatus(nQuestId)
local tbQuestList = {}
if 0 == nQuestId then
for questId, v in pairs(self.tbAllQuestList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete then
table.insert(tbQuestList, questId)
v.nStatus = AllEnum.ActQuestStatus.Received
end
end
elseif nil ~= self.tbAllQuestList[nQuestId] then
table.insert(tbQuestList, nQuestId)
self.tbAllQuestList[nQuestId].nStatus = AllEnum.ActQuestStatus.Received
end
self:RefreshRedDot()
return tbQuestList
end
function PeriodicQuestActData:RefreshFinalStatus(bFinalStatus)
self.bFinalStatus = bFinalStatus
self:RefreshRedDot()
end
function PeriodicQuestActData:GetQuestListByGroup()
local tbQuestList = {}
for _, v in pairs(self.tbAllQuestList) do
if nil == tbQuestList[v.nGroupId] then
tbQuestList[v.nGroupId] = {}
end
table.insert(tbQuestList[v.nGroupId], v)
end
return tbQuestList
end
function PeriodicQuestActData:GetQuestListByDay()
local tbQuestList = {}
for _, v in pairs(self.tbAllQuestList) do
if nil == tbQuestList[v.nDay] then
tbQuestList[v.nDay] = {}
end
table.insert(tbQuestList[v.nDay], v)
end
return tbQuestList
end
function PeriodicQuestActData:GetCurOpenDay()
local nMaxDay = CacheTable.GetData("_PeriodicQuestMaxDay", self.nActId)
if nil == nMaxDay then
printError("读取PeriodicQuestGroup配置失败!!!actId = " .. tostring(self.nActId))
return 1
end
local nCurTime = ClientManager.serverTimeStamp
local nOpenTime = self.nOpenTime
local nCurDay = 0
local nNextRefreshTime = ClientManager:GetNextRefreshTime(nOpenTime)
while nOpenTime < nNextRefreshTime and nCurTime > nOpenTime and nMaxDay >= nCurDay do
nOpenTime = nNextRefreshTime
nCurDay = nCurDay + 1
nNextRefreshTime = ClientManager:GetNextRefreshTime(nOpenTime)
end
nCurDay = math.min(nCurDay, nMaxDay)
return nCurDay
end
function PeriodicQuestActData:GetMaxOpenDay()
local nMaxDay = 0
local groupCfg = CacheTable.GetData("_PeriodicQuestDay", self.nActId)
if nil ~= groupCfg then
for _, v in pairs(groupCfg) do
if v > nMaxDay then
nMaxDay = v
end
end
end
return nMaxDay
end
function PeriodicQuestActData:GetCanReceiveRewardGroup()
local nGroupId = 0
local nCurDay = self:GetCurOpenDay()
for _, v in pairs(self.tbAllQuestList) do
if nCurDay >= v.nDay and v.nStatus == AllEnum.ActQuestStatus.Complete and nGroupId < v.nGroupId then
nGroupId = v.nGroupId
end
end
return nGroupId
end
function PeriodicQuestActData:GetCanRecRewardDay()
for _, v in pairs(self.tbAllQuestList) do
if v.nStatus == AllEnum.ActQuestStatus.Complete then
return v.nDay
end
end
return 0
end
function PeriodicQuestActData:GetDayQuestStatus(nDay)
local nAllQuest, nReceivedQuest = 0, 0
for _, v in pairs(self.tbAllQuestList) do
if v.nDay == nDay then
nAllQuest = nAllQuest + 1
if v.nStatus == AllEnum.ActQuestStatus.Received then
nReceivedQuest = nReceivedQuest + 1
end
end
end
return nAllQuest, nReceivedQuest
end
function PeriodicQuestActData:GetNextDayOpenTime()
local nextRefreshTime = ClientManager:GetNextRefreshTime(ClientManager.serverTimeStamp)
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local nRemainTime = nextRefreshTime - nCurTime
return math.floor(nRemainTime / 3600)
end
function PeriodicQuestActData:GetPerQuestCfg()
return self.perQuestActCfg
end
function PeriodicQuestActData:GetQuestProgress()
local curProgress = 0
local allProgress = #CacheTable.GetData("_PeriodicQuest", self.nActId)
local canReceive = 0
local nCurDay = self:GetCurOpenDay()
for _, v in pairs(self.tbAllQuestList) do
if nCurDay >= v.nDay then
if v.nStatus == AllEnum.ActQuestStatus.Received then
curProgress = curProgress + 1
elseif v.nStatus == AllEnum.ActQuestStatus.Complete then
canReceive = canReceive + 1
end
end
end
return curProgress, allProgress, canReceive
end
function PeriodicQuestActData:CheckFinalReward()
return self.bFinalStatus
end
function PeriodicQuestActData:CheckAllQuestComplete()
local bAllComplete = true
for nId, v in pairs(self.tbAllQuestList) do
if v.nStatus == AllEnum.ActQuestStatus.UnComplete then
bAllComplete = false
break
end
end
return bAllComplete
end
function PeriodicQuestActData:RefreshRedDot()
local bOpen = self:CheckActShow()
local bQuestReward = false
local tbGroupStatus = {}
local nCurDay = self:GetCurOpenDay()
if nil ~= next(self.tbAllQuestList) then
for _, v in pairs(self.tbAllQuestList) do
if nCurDay >= v.nDay then
if nil == tbGroupStatus[v.nGroupId] then
tbGroupStatus[v.nGroupId] = 0
end
if v.nStatus == AllEnum.ActQuestStatus.Complete then
tbGroupStatus[v.nGroupId] = tbGroupStatus[v.nGroupId] + 1
bQuestReward = true
end
end
end
for group, v in pairs(tbGroupStatus) do
RedDotManager.SetValid(RedDotDefine.Activity_Periodic_Quest_Group, {
self.nActId,
group
}, 0 < v and bOpen)
end
local nCur, nAll = self:GetQuestProgress()
local bFinalReward = nAll <= nCur and not self.bFinalStatus
RedDotManager.SetValid(RedDotDefine.Activity_Periodic_Final_Reward, self.nActId, bFinalReward and bOpen)
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, (bQuestReward or bFinalReward) and bOpen)
end
end
return PeriodicQuestActData
@@ -0,0 +1,626 @@
local PlayerActivityData = class("PlayerActivityData")
local PeriodicQuestActData = require("GameCore.Data.DataClass.Activity.PeriodicQuestActData")
local LoginRewardActData = require("GameCore.Data.DataClass.Activity.LoginRewardActData")
local MiningGameData = require("GameCore.Data.DataClass.Activity.MiningGameData")
local TrialActData = require("GameCore.Data.DataClass.Activity.TrialActData")
local CookieActData = require("GameCore.Data.DataClass.Activity.CookieActData")
local TowerDefenseData = require("GameCore.Data.DataClass.Activity.TowerDefenseData")
local JointDrillActData = require("GameCore.Data.DataClass.Activity.JointDrillActData")
local ActivityLevelTypeData = require("GameCore.Data.DataClass.Activity.ActivityLevelTypeData")
local ActivityTaskData = require("GameCore.Data.DataClass.Activity.ActivityTaskData")
local ActivityShopData = require("GameCore.Data.DataClass.Activity.ActivityShopData")
local AdvertiseActData = require("GameCore.Data.DataClass.Activity.AdvertiseActData")
local LocalData = require("GameCore.Data.LocalData")
local SwimThemeData = require("GameCore.Data.DataClass.Activity.SwimThemeData")
local OurRegiment_10101Data = require("GameCore.Data.DataClass.Activity.OurRegiment_10101Data")
local Dream_10102Data = require("GameCore.Data.DataClass.Activity.Dream_10102Data")
local TimerManager = require("GameCore.Timer.TimerManager")
local BdConvertData = require("GameCore.Data.DataClass.Activity.BdConvertData")
local BreakOut_30101Data = require("GameCore.Data.DataClass.Activity.BreakOut_30101Data")
local BreakOutData = require("GameCore.Data.DataClass.Activity.BreakOutData")
function PlayerActivityData:Init()
self.bCacheActData = false
self.tbAllActivity = {}
self.tbAllActivityGroup = {}
self.tbActivityPopUp = {}
self.tbLoginRewardPopUp = {}
self.tbReadedCG = {}
self:InitActivityCfg()
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Add(EventId.UpdateWorldClass, self, self.OnEvent_UpdateWorldClass)
EventManager.Add("Story_RewardClosed", self, self.OnEvent_StoryEnd)
end
function PlayerActivityData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Remove(EventId.UpdateWorldClass, self, self.OnEvent_UpdateWorldClass)
EventManager.Remove("Story_RewardClosed", self, self.OnEvent_StoryEnd)
end
function PlayerActivityData:InitActivityCfg()
local foreachTableLine = function(line)
if nil == CacheTable.GetData("_PeriodicQuestGroup", line.Belong) then
CacheTable.SetData("_PeriodicQuestGroup", line.Belong, {})
end
if nil == CacheTable.GetData("_PeriodicQuestGroup", line.Belong)[line.UnlockTime + 1] then
CacheTable.GetData("_PeriodicQuestGroup", line.Belong)[line.UnlockTime + 1] = {}
end
table.insert(CacheTable.GetData("_PeriodicQuestGroup", line.Belong)[line.UnlockTime + 1], line.GroupId)
if nil == CacheTable.GetData("_PeriodicQuestDay", line.Belong) then
CacheTable.SetData("_PeriodicQuestDay", line.Belong, {})
end
CacheTable.GetData("_PeriodicQuestDay", line.Belong)[line.GroupId] = line.UnlockTime + 1
if nil == CacheTable.GetData("_PeriodicQuestMaxDay", line.Belong) then
CacheTable.SetData("_PeriodicQuestMaxDay", line.Belong, 0)
end
if line.UnlockTime + 1 > CacheTable.GetData("_PeriodicQuestMaxDay", line.Belong) then
CacheTable.SetData("_PeriodicQuestMaxDay", line.Belong, line.UnlockTime + 1)
end
end
ForEachTableLine(DataTable.PeriodicQuestGroup, foreachTableLine)
local foreachTableLine = function(line)
CacheTable.InsertData("_PeriodicQuest", line.Belong, line)
end
ForEachTableLine(DataTable.PeriodicQuest, foreachTableLine)
local foreachLoginRewardGroup = function(line)
CacheTable.InsertData("_LoginRewardGroup", line.RewardGroupId, line)
end
ForEachTableLine(DataTable.LoginRewardGroup, foreachLoginRewardGroup)
local foreachTableLine = function(line)
CacheTable.SetData("_ActivityTaskControl", line.ActivityId, line)
end
ForEachTableLine(DataTable.ActivityTaskControl, foreachTableLine)
end
function PlayerActivityData:CacheAllActivityData(mapNetMsg)
if mapNetMsg.List ~= nil then
for _, v in ipairs(mapNetMsg.List) do
local nActId = v.Id
local actCfg = ConfigTable.GetData("Activity", nActId)
if nil ~= actCfg and actCfg.ActivityType == GameEnum.activityType.Avg then
self:RefreshActivityAvgData(nActId, v.Avg)
end
if nil ~= actCfg then
if actCfg.ActivityType == GameEnum.activityType.PeriodicQuest then
self:RefreshPeriodicActQuest(nActId, v.Periodic)
elseif actCfg.ActivityType == GameEnum.activityType.LoginReward then
self:RefreshLoginRewardActData(nActId, v.Login)
elseif actCfg.ActivityType == GameEnum.activityType.Mining then
self:RefreshMiningGameActData(nActId, v.Mining)
elseif actCfg.ActivityType == GameEnum.activityType.Cookie then
self:RefreshCookieGameActData(nActId, v.Cookie)
elseif actCfg.ActivityType == GameEnum.activityType.TowerDefense then
self:RefreshTowerDefenseActData(nActId, v.TowerDefense)
elseif actCfg.ActivityType == GameEnum.activityType.JointDrill then
self:RefreshJointDrillActData(nActId, v.JointDrill)
elseif actCfg.ActivityType == GameEnum.activityType.Levels then
self:RefreshActivityLevelGameActData(nActId, v.Levels)
elseif actCfg.ActivityType == GameEnum.activityType.Trial then
self:RefreshTrialActData(nActId, v.Trial)
elseif actCfg.ActivityType == GameEnum.activityType.CG then
self:RefreshActivityCGData(v.CG)
elseif actCfg.ActivityType == GameEnum.activityType.Task then
local actIns = self.tbAllActivity[nActId]
if actIns == nil then
local mapActData = {}
mapActData.Id = nActId
mapActData.StartTime = 0
mapActData.EndTime = 0
actIns = ActivityTaskData.new(mapActData)
self.tbAllActivity[nActId] = actIns
end
actIns:CacheData(v.Task)
EventManager.Hit("RefreshActivityTask")
elseif actCfg.ActivityType == GameEnum.activityType.Shop then
self:RefreshActivityShopData(nActId, v.Shop)
elseif actCfg.ActivityType == GameEnum.activityType.Advertise then
self:RefreshInfinityTowerActData(nActId, v.Shop)
elseif actCfg.ActivityType == GameEnum.activityType.BDConvert then
self:RefreshBdConvertData(nActId, v.BdConvert)
elseif actCfg.ActivityType == GameEnum.activityType.Breakout then
self:RefreshBreakoutData(nActId, v.Breakout)
end
end
end
end
self:RefreshLoginRewardPopUpList()
self:RefreshActivityRedDot()
end
function PlayerActivityData:CacheActivityData(mapNetMsg)
if nil == mapNetMsg then
return
end
for _, v in ipairs(mapNetMsg) do
self:CreateActivityIns(v)
end
end
function PlayerActivityData:UpdateActivityState(mapNetMsg)
if nil == mapNetMsg then
return
end
for _, v in ipairs(mapNetMsg) do
if self.tbAllActivity[v.Id] ~= nil then
self.tbAllActivity[v.Id]:UpdateActivityState(v)
end
end
self:RefreshPopUpList()
self:RefreshActivityRedDot()
end
function PlayerActivityData:RefreshActivityData(mapNetMsg)
if nil == self.tbAllActivity[mapNetMsg.Id] then
self:CreateActivityIns(mapNetMsg)
self:SendActivityDetailMsg(nil, true)
else
self.tbAllActivity[mapNetMsg.Id]:RefreshActivityData(mapNetMsg)
end
self:RefreshPopUpList()
self:RefreshActivityRedDot()
end
function PlayerActivityData:RefreshActivityStateData(mapNetMsg)
if nil ~= self.tbAllActivity[mapNetMsg.Id] then
self.tbAllActivity[mapNetMsg.Id]:RefreshStateData(mapNetMsg.RedDot, mapNetMsg.Banner)
self:RefreshActivityRedDot()
end
end
function PlayerActivityData:RefreshActStatus()
for _, actData in pairs(self.tbAllActivity) do
local bPlay = actData:GetPlayState()
if not bPlay then
actData:RefreshPlayState()
local bPlay_new = actData:GetPlayState()
if bPlay_new then
actData:UpdateStatus()
end
end
end
end
function PlayerActivityData:CreateActivityIns(actData)
local actIns
local actCfg = ConfigTable.GetData("Activity", actData.Id)
if actCfg == nil then
return
end
if actCfg.ActivityType == GameEnum.activityType.PeriodicQuest then
actIns = PeriodicQuestActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.LoginReward then
actIns = LoginRewardActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Mining then
actIns = MiningGameData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Trial then
actIns = TrialActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Cookie then
actIns = CookieActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.TowerDefense then
actIns = TowerDefenseData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.JointDrill then
actIns = JointDrillActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Levels then
actIns = ActivityLevelTypeData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Avg then
PlayerData.ActivityAvg:CacheActivityAvgData(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Task then
actIns = ActivityTaskData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Shop then
actIns = ActivityShopData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Advertise then
actIns = AdvertiseActData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.BDConvert then
actIns = BdConvertData.new(actData)
elseif actCfg.ActivityType == GameEnum.activityType.Breakout then
actIns = BreakOutData.new(actData)
end
if actIns ~= nil then
self.tbAllActivity[actData.Id] = actIns
end
end
function PlayerActivityData:RefreshActivityRedDot()
local bHasNewRedDot = false
for _, v in pairs(self.tbAllActivity) do
RedDotManager.SetValid(RedDotDefine.Activity_Tab, v:GetActId(), v:CheckActShow() and v:GetActivityRedDot())
if type(v.RefreshRedDot) == "function" then
v:RefreshRedDot()
end
local bInActGroup = false
if v:GetActCfgData().ActivityThemeType > 0 or self:IsActivityInActivityGroup(v:GetActId()) then
bInActGroup = true
end
if not bInActGroup and v:CheckActShow() then
local bTabRedDot = RedDotManager.GetValid(RedDotDefine.Activity_Tab, v:GetActId())
local sData = LocalData.GetPlayerLocalData("Activity_Tab_New_" .. v:GetActId())
local nValue = tonumber(sData == nil and "0" or sData)
local bNewRedDot = nValue == 0 and not bTabRedDot
if bNewRedDot then
bHasNewRedDot = true
end
RedDotManager.SetValid(RedDotDefine.Activity_New_Tab, v:GetActId(), bNewRedDot)
end
end
local bHasGroupNewRedDot = false
for nId, v in pairs(self.tbAllActivityGroup) do
if v:CheckActGroupShow() and RedDotManager.GetValid(RedDotDefine.Activity_New_Tab, nId) then
bHasGroupNewRedDot = true
end
end
local bHasRedDot = RedDotManager.GetValid(RedDotDefine.Activity)
RedDotManager.SetValid(RedDotDefine.Activity_New, nil, not bHasRedDot and (bHasNewRedDot or bHasGroupNewRedDot))
end
function PlayerActivityData:GetActivityList()
return self.tbAllActivity
end
function PlayerActivityData:GetSortedActList()
local tbActList = {}
for k, v in pairs(self.tbAllActivity) do
if v:CheckActShow() then
local bInActGroup = false
if v:GetActCfgData().ActivityThemeType > 0 or self:IsActivityInActivityGroup(v:GetActId()) then
bInActGroup = true
end
if not bInActGroup then
table.insert(tbActList, v)
end
end
end
table.sort(tbActList, function(a, b)
if a:GetActSortId() == b:GetActSortId() then
return a:GetActId() < b:GetActId()
end
return a:GetActSortId() < b:GetActSortId()
end)
return tbActList
end
function PlayerActivityData:GetActivityDataById(nActId)
return self.tbAllActivity[nActId] or nil
end
function PlayerActivityData:CacheActivityGroupData()
local foreachActGroup = function(mapData)
self:CreateActivityGroupIns(mapData)
end
ForEachTableLine(ConfigTable.Get("ActivityGroup"), foreachActGroup)
self:RefreshPopUpList()
self:RefreshActGroupNewRedDot()
end
function PlayerActivityData:CreateActivityGroupIns(actData)
local actIns
local actCfg = actData
if actCfg == nil then
return
end
local nOpenTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(actCfg.StartTime)
local nEndEnterTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(actCfg.EnterEndTime)
local curTime = CS.ClientManager.Instance.serverTimeStamp
if nOpenTime <= curTime and nEndEnterTime > curTime then
if actCfg.ActivityThemeType == GameEnum.activityThemeType.Swim then
actIns = SwimThemeData.new(actData)
elseif actCfg.ActivityThemeType == GameEnum.activityThemeType.OurRegiment_10101 then
actIns = OurRegiment_10101Data.new(actData)
elseif actCfg.ActivityThemeType == GameEnum.activityThemeType.Dream_10102 then
actIns = Dream_10102Data.new(actData)
elseif actCfg.ActivityThemeType == GameEnum.activityThemeType.BreakOut_30101 then
actIns = BreakOut_30101Data.new(actData)
end
self.tbAllActivityGroup[actData.Id] = actIns
PlayerData.ActivityAvg:RefreshAvgRedDot()
elseif nOpenTime > curTime then
TimerManager.Add(1, nOpenTime - curTime, nil, function()
self:RefreshActivityGroupData(actData)
end, true, true, true)
end
end
function PlayerActivityData:RefreshActivityGroupData(actData)
if nil == self.tbAllActivityGroup[actData.Id] then
self:CreateActivityGroupIns(actData)
else
self.tbAllActivityGroup[actData.Id]:RefreshActivityData(actData)
end
self:RefreshActGroupNewRedDot()
end
function PlayerActivityData:RefreshActGroupNewRedDot()
for _, actIns in pairs(self.tbAllActivityGroup) do
if actIns:CheckActGroupShow() then
local sData = LocalData.GetPlayerLocalData("Activity_Tab_New_" .. actIns:GetActGroupId())
local nValue = tonumber(sData == nil and "0" or sData)
local bNewRedDot = nValue == 0
RedDotManager.SetValid(RedDotDefine.Activity_New_Tab, actIns:GetActGroupId(), bNewRedDot)
end
end
end
function PlayerActivityData:GetSortedActGroupList()
local tbActGroupList = {}
for k, v in pairs(self.tbAllActivityGroup) do
if v:CheckActGroupShow() then
table.insert(tbActGroupList, v)
end
end
table.sort(tbActGroupList, function(a, b)
if not a:CheckActivityGroupOpen() and b:CheckActivityGroupOpen() then
return false
elseif a:CheckActivityGroupOpen() and not b:CheckActivityGroupOpen() then
return true
end
return a:GetActGroupId() < b:GetActGroupId()
end)
return tbActGroupList
end
function PlayerActivityData:GetActivityGroupDataById(nActGroupId)
return self.tbAllActivityGroup[nActGroupId]
end
function PlayerActivityData:GetMainviewShowActivityGroup()
local tbShowList = {}
for _, actGroupData in pairs(self.tbAllActivityGroup) do
if actGroupData:CheckActGroupShow() and actGroupData:IsUnlockShow() then
table.insert(tbShowList, actGroupData)
end
end
table.sort(tbShowList, function(a, b)
if not a:CheckActivityGroupOpen() and b:CheckActivityGroupOpen() then
return false
elseif a:CheckActivityGroupOpen() and not b:CheckActivityGroupOpen() then
return true
end
return a:GetActGroupId() < b:GetActGroupId()
end)
return tbShowList
end
function PlayerActivityData:IsActivityInActivityGroup(nActId)
local isInGroup, getActId
for _, actGroupData in pairs(self.tbAllActivityGroup) do
if actGroupData:CheckActGroupShow() then
isInGroup, getActId = actGroupData:IsActivityInActivityGroup(nActId)
if isInGroup == true then
return isInGroup, getActId
end
end
end
return false
end
function PlayerActivityData:RefreshPeriodicActQuest(nActId, mapMsgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshQuestList(mapMsgData.Quests)
self.tbAllActivity[nActId]:RefreshFinalStatus(mapMsgData.FinalStatus)
end
end
function PlayerActivityData:RefreshSingleQuest(questData)
local actCfg = ConfigTable.GetData("Activity", questData.ActivityId)
if not actCfg then
return
end
if actCfg.ActivityType == GameEnum.activityType.PeriodicQuest then
local questCfg = ConfigTable.GetData("PeriodicQuest", questData.Id)
if questCfg then
local nActId = questCfg.Belong
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshQuestData(questData)
end
EventManager.Hit("RefreshPeriodicAct", nActId)
end
elseif actCfg.ActivityType == GameEnum.activityType.Mining then
if nil ~= self.tbAllActivity[questData.ActivityId] then
self.tbAllActivity[questData.ActivityId]:RefreshQuestData(questData)
end
elseif actCfg.ActivityType == GameEnum.activityType.Cookie then
if nil ~= self.tbAllActivity[questData.ActivityId] then
self.tbAllActivity[questData.ActivityId]:RefreshQuestData(questData)
end
elseif actCfg.ActivityType == GameEnum.activityType.JointDrill then
PlayerData.JointDrill:RefreshQuestData(questData)
elseif actCfg.ActivityType == GameEnum.activityType.Task then
self.tbAllActivity[questData.ActivityId]:RefreshSingleQuest(questData)
EventManager.Hit("RefreshActivityTask")
elseif actCfg.ActivityType == GameEnum.activityType.BDConvert then
if nil ~= self.tbAllActivity[questData.ActivityId] then
self.tbAllActivity[questData.ActivityId]:RefreshQuestData(questData)
end
elseif actCfg.ActivityType == GameEnum.activityType.TowerDefense and nil ~= self.tbAllActivity[questData.ActivityId] then
self.tbAllActivity[questData.ActivityId]:RefreshQuestData(questData)
end
end
function PlayerActivityData:CacheLoginRewardActData(nActId, mapMsgData)
self:RefreshLoginRewardActData(nActId, mapMsgData)
self:RefreshLoginRewardPopUpList()
end
function PlayerActivityData:RefreshLoginRewardActData(nActId, actData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshLoginData(actData.Receive, actData.Actual)
end
end
function PlayerActivityData:ReceiveLoginRewardSuc(nActId)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:ReceiveRewardSuc()
end
self:RefreshLoginRewardPopUpList()
end
function PlayerActivityData:RefreshPopUpList()
self.tbActivityPopUp = {}
local bFuncOpen = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Activity)
if not bFuncOpen then
return
end
for _, v in pairs(self.tbAllActivity) do
if v:CheckPopUp() and v:CheckActPlay() then
table.insert(self.tbActivityPopUp, v:GetActId())
end
end
for _, v in pairs(self.tbAllActivityGroup) do
if v:CheckPopUp() and v:CheckActGroupPopUpShow() and v:IsUnlock() then
table.insert(self.tbActivityPopUp, v:GetActGroupId())
end
end
if #self.tbActivityPopUp > 0 then
PlayerData.PopUp:InsertPopUpQueue(self.tbActivityPopUp)
end
end
function PlayerActivityData:RefreshLoginRewardPopUpList()
self.tbLoginRewardPopUp = {}
local bFuncOpen = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Activity)
if not bFuncOpen then
return
end
for nActId, data in pairs(self.tbAllActivity) do
local nActType = data:GetActType()
if nActType == GameEnum.activityType.LoginReward and data:CheckCanReceive() and data:CheckActivityOpen() then
table.insert(self.tbLoginRewardPopUp, data)
end
end
table.sort(self.tbLoginRewardPopUp, function(a, b)
if a:GetActSortId() == b:GetActSortId() then
return a:GetActId() < b:GetActId()
end
return a:GetActSortId() < b:GetActSortId()
end)
if #self.tbLoginRewardPopUp > 0 then
PopUpManager.PopUpEnQueue(GameEnum.PopUpSeqType.ActivityLogin, self.tbLoginRewardPopUp)
end
end
function PlayerActivityData:RefreshMiningGameActData(nActId, msgMapData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshMiningGameActData(nActId, msgMapData)
end
end
function PlayerActivityData:RefreshCookieGameActData(nActId, msgMapData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshCookieGameActData(nActId, msgMapData)
end
end
function PlayerActivityData:RefreshJointDrillActData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshJointDrillActData(msgData)
end
end
function PlayerActivityData:RefreshTowerDefenseActData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshTowerDefenseActData(nActId, msgData)
end
end
function PlayerActivityData:RefreshBdConvertData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshBdConvertData(nActId, msgData)
end
end
function PlayerActivityData:RefreshBreakoutData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshBreakoutData(nActId, msgData)
end
end
function PlayerActivityData:RefreshActivityLevelGameActData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshActivityLevelGameActData(nActId, msgData)
end
end
function PlayerActivityData:SetActivityLevelActId(nActId)
self.nActivityLevelActId = nActId
end
function PlayerActivityData:GetActivityLevelActId()
return self.nActivityLevelActId
end
function PlayerActivityData:RefreshTrialActData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshTrialActData(msgData)
end
end
function PlayerActivityData:RefreshActivityAvgData(nActId, msgData)
PlayerData.ActivityAvg:RefreshActivityAvgData(nActId, msgData)
end
function PlayerActivityData:RefreshActivityShopData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshActivityShopData(msgData)
end
end
function PlayerActivityData:RefreshActivityCGData(msgData)
self.tbReadedCG = {}
for _, actId in pairs(msgData) do
table.insert(self.tbReadedCG, actId)
end
end
function PlayerActivityData:IsCGPlayed(nActId)
return table.indexof(self.tbReadedCG, nActId) > 0
end
function PlayerActivityData:GetActivityBannerList()
local tbList = {}
for _, v in pairs(self.tbAllActivity) do
if v:CheckShowBanner() then
table.insert(tbList, v)
end
end
table.sort(tbList, function(a, b)
return a:GetActId() < b:GetActId()
end)
return tbList
end
function PlayerActivityData:RefreshInfinityTowerActData(nActId, msgData)
if nil ~= self.tbAllActivity[nActId] then
self.tbAllActivity[nActId]:RefreshInfinityTowerActData(nActId, msgData)
end
end
function PlayerActivityData:SendActivityDetailMsg(callback, bForceGet)
local callFunc = function()
self.bCacheActData = true
if callback ~= nil then
callback()
end
end
if not self.bCacheActData or bForceGet then
HttpNetHandler.SendMsg(NetMsgId.Id.activity_detail_req, {}, nil, callFunc)
elseif callback ~= nil then
callback()
end
end
function PlayerActivityData:SendReceivePerQuest(nActId, nQuestId, callback)
local callFunc = function(_, mapChangeInfo)
local actData = self.tbAllActivity[nActId]
local tbQuestList = actData:RefreshQuestStatus(nQuestId)
UTILS.OpenReceiveByChangeInfo(mapChangeInfo, callback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_periodic_reward_receive_req, {ActivityId = nActId, QuestId = nQuestId}, nil, callFunc)
end
function PlayerActivityData:SendReceiveFinalReward(nActId, callback)
local callFunc = function(_, mapMsgData)
self:ReceiveFinalRewardSuc(nActId, mapMsgData)
if nil ~= callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_periodic_final_reward_receive_req, {Value = nActId}, nil, callFunc)
end
function PlayerActivityData:ReceiveQuestReward(mapMsgData)
UTILS.OpenReceiveByChangeInfo(mapMsgData)
end
function PlayerActivityData:ReceiveFinalRewardSuc(actId, mapMsgData)
local actData = self.tbAllActivity[actId]
if nil ~= actData then
actData:RefreshFinalStatus(true)
UTILS.OpenReceiveByChangeInfo(mapMsgData)
end
end
function PlayerActivityData:SendReceiveLoginRewardMsg(nActId, callFunc)
local callback = function(_, mapMsgData)
self:ReceiveLoginRewardSuc(nActId)
UTILS.OpenReceiveByChangeInfo(mapMsgData, callFunc)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_login_reward_receive_req, {Value = nActId}, nil, callback)
end
function PlayerActivityData:OpenActivityPanel(nActId)
local tbList = self:GetSortedActList()
if nil == next(tbList) then
self:RefreshActivityRedDot()
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("Activity_Empty"))
return
end
local openFunc = function()
local func = function()
EventManager.Hit(EventId.OpenPanel, PanelId.ActivityList, nActId)
end
EventManager.Hit(EventId.SetTransition, 5, func)
end
self:SendActivityDetailMsg(openFunc)
end
function PlayerActivityData:OnEvent_NewDay()
self.bCacheActData = false
end
function PlayerActivityData:OnEvent_UpdateWorldClass()
self:RefreshPopUpList()
self:RefreshActStatus()
self:RefreshActGroupNewRedDot()
end
function PlayerActivityData:OnEvent_StoryEnd()
self:RefreshPopUpList()
self:RefreshActStatus()
self:RefreshActGroupNewRedDot()
end
return PlayerActivityData
@@ -0,0 +1,61 @@
local ActivityGroupDataBase = require("GameCore.Data.DataClass.Activity.ActivityGroupDataBase")
local SwimThemeData = class("SwimThemeData", ActivityGroupDataBase)
function SwimThemeData:Init()
self.tbAllActivity = {}
self.nCGActivityId = 0
self.sCGPath = ""
self.bPlayedCG = false
self:ParseActivity()
end
function SwimThemeData:ParseActivity()
if self.actGroupConfig == nil then
self.actGroupConfig = ConfigTable.GetData("ActivityGroup", self.nActGroupId)
end
local sJson = self.actGroupConfig.Enter
local tbJson = decodeJson(sJson)
for _, activity in pairs(tbJson) do
local data = {
ActivityId = activity[1],
Index = activity[2],
PanelId = activity[3]
}
table.insert(self.tbAllActivity, data)
end
local sCgJson = self.actGroupConfig.CG
if sCgJson ~= nil then
local tbCGJson = decodeJson(sCgJson)
self.nCGActivityId = tonumber(tbCGJson[1])
self.sCGPath = tbCGJson[2]
end
end
function SwimThemeData:GetActivityDataByIndex(nIndex)
for _, activity in pairs(self.tbAllActivity) do
if activity.Index == nIndex then
return activity
end
end
end
function SwimThemeData:PlayCG()
self:SendMsg_CG_READ(self.nCGActivityId)
end
function SwimThemeData:GetActivityGroupCGPlayed()
if self.bPlayedCG then
return true
end
return PlayerData.Activity:IsCGPlayed(self.nCGActivityId)
end
function SwimThemeData:IsActivityInActivityGroup(nActivityId)
for _, activity in pairs(self.tbAllActivity) do
if activity.ActivityId == nActivityId then
return true, self.nActGroupId
end
end
return false
end
function SwimThemeData:SendMsg_CG_READ(nActivityId)
local Callback = function()
self.bPlayedCG = true
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_cg_read_req, {nActivityId}, nil, Callback)
end
return SwimThemeData
@@ -0,0 +1,675 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local TowerDefenseData = class("TowerDefenseData", ActivityDataBase)
local LocalData = require("GameCore.Data.LocalData")
local RapidJson = require("rapidjson")
local RedDotManager = require("GameCore.RedDot.RedDotManager")
local ClientManager = CS.ClientManager.Instance
local TowerDefenseLevelData = require("GameCore.Data.DataClass.Activity.TowerDefenseLevelData")
function TowerDefenseData:Init()
self:InitData()
self:AddListeners()
end
function TowerDefenseData:InitData()
self.allLevelData = {}
self.teamData = {}
self.allQuestData = {}
self.allStoryData = {}
self.guideData = {}
self.cacheEnterLevelList = {}
self.TowerDefenseLevelData = TowerDefenseLevelData.new()
self.TempLevelTeamData = {}
end
function TowerDefenseData:UpdateStatus()
for _, levelData in pairs(self.allLevelData) do
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelData.nLevelId)
if levelConfig ~= nil and self:IsLevelUnlock(levelData.nLevelId) then
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Level, {
levelConfig.LevelPage,
levelData.nLevelId
}, self:GetlevelIsNew(levelData.nLevelId))
end
end
for _, storyData in pairs(self.allStoryData) do
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Story, {
storyData.nId
}, self:GetStoryIsNew(storyData.nId))
end
self:RefreshRedDot()
end
function TowerDefenseData:AddListeners()
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function TowerDefenseData:GetActConfig()
self.actCfgData = ConfigTable.GetData("TowerDefenseControl", self.nActId)
return self.actCfgData
end
function TowerDefenseData:RefreshTowerDefenseActData(actId, msgData)
self:InitData()
self.nActId = actId
local sJson = LocalData.GetPlayerLocalData("TowerDefenseLevel")
local tb = decodeJson(sJson)
if type(tb) == "table" then
self.cacheEnterLevelList = tb
end
for _, level in pairs(msgData.Levels) do
self:UpdateLevelData(level)
end
local curActLevelIds = {}
local foreachTable = function(data)
if data.activityId == self.nActId then
table.insert(curActLevelIds, data.Id)
end
end
ForEachTableLine(DataTable.TowerDefenseLevel, foreachTable)
for _, levelId in pairs(curActLevelIds) do
if self.allLevelData[levelId] == nil then
self:UpdateLevelData({Id = levelId, Star = 0})
end
end
local allStoryConfigList = {}
local foreach_storyTable = function(data)
if data.ActivityIdId == self.nActId then
table.insert(allStoryConfigList, data.Id)
end
end
ForEachTableLine(DataTable.TowerDefenseStory, foreach_storyTable)
local tempStoryData = {}
for _, value in pairs(allStoryConfigList) do
tempStoryData[value] = {nId = value, bIsRead = false}
end
for _, value in pairs(msgData.Stories) do
tempStoryData[value] = {nId = value, bIsRead = true}
end
for _, value in pairs(tempStoryData) do
self:UpdateStoryData(value)
end
local foreach_questGroupTable = function(data)
if data.ActivityId == self.nActId then
self.allQuestData[data.Id] = {}
end
end
ForEachTableLine(DataTable.TowerDefenseQuestGroup, foreach_questGroupTable)
local foreach_questTable = function(data)
if self.allQuestData[data.QuestGroupId] ~= nil then
local nMax = 1
if data.QuestType == GameEnum.towerDefenseCond.TowerDefenseClear then
nMax = 1
elseif data.QuestType == GameEnum.towerDefenseCond.TowerDefenseClearSpecificStar then
nMax = 1
end
local progressData = {}
table.insert(progressData, {Cur = 0, Max = nMax})
self:UpdateQuest({
nId = data.Id,
nState = AllEnum.ActQuestStatus.UnComplete,
progress = progressData
})
end
end
ForEachTableLine(DataTable.TowerDefenseQuest, foreach_questTable)
for _, quest in pairs(msgData.Quests) do
self:UpdateQuest({
nId = quest.Id,
nState = self:QuestStateServer2Client(quest.Status),
progress = quest.Progress
})
end
self:RefreshRedDot()
end
function TowerDefenseData:GetLevelStartTime(levelId)
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return 0
end
local openActDayNextTime = ClientManager:GetNextRefreshTime(self.nOpenTime)
local nTempDay = 0
if openActDayNextTime > self.nOpenTime then
nTempDay = 1
end
local nDay = (ClientManager.serverTimeStamp - openActDayNextTime) // 86400 + nTempDay
if nDay >= levelConfig.ActiveTime then
return 0
end
local openDayNextTime = ClientManager:GetNextRefreshTime(ClientManager.serverTimeStamp)
return openDayNextTime + (levelConfig.ActiveTime - nDay - 1) * 86400
end
function TowerDefenseData:UpdateLevelData(levelData)
self.allLevelData[levelData.Id] = {
nLevelId = levelData.Id,
nStar = levelData.Star
}
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelData.Id)
if levelConfig == nil then
return
end
if self:GetPlayState() and self:IsLevelUnlock(levelData.Id) then
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Level, {
levelConfig.LevelPage,
levelData.Id
}, self:GetlevelIsNew(levelData.Id))
end
EventManager.Hit("TowerDefenseLevelUpdate")
end
function TowerDefenseData:GetAllLevelData()
return self.allLevelData
end
function TowerDefenseData:GetLevelsByTab(nTabIndex)
local levelsData = {}
for _, level in pairs(self.allLevelData) do
local config = ConfigTable.GetData("TowerDefenseLevel", level.nLevelId)
if config.LevelPage == nTabIndex then
table.insert(levelsData, level)
end
end
return levelsData
end
function TowerDefenseData:GetLevelData(levelId)
return self.allLevelData[levelId]
end
function TowerDefenseData:IsLevelPass(levelId)
local bResult = false
local levelData = self:GetLevelData(levelId)
if levelData ~= nil and levelData.nStar > 0 then
bResult = true
end
return bResult
end
function TowerDefenseData:IsLevelUnlock(levelId)
if levelId == 0 then
return true
end
local bResult = false
local levelData = self:GetLevelData(levelId)
local time = CS.ClientManager.Instance.serverTimeStamp
if levelData ~= nil and time >= self:GetLevelStartTime(levelData.nLevelId) then
bResult = true
end
return bResult
end
function TowerDefenseData:IsPreLevelPass(levelId)
if levelId == 0 then
return true
end
local bResult = false
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return bResult
end
local preLevelId = levelConfig.PreLevel
if preLevelId == 0 then
bResult = true
else
local levelData = self:GetLevelData(preLevelId)
if levelData ~= nil and 0 < levelData.nStar then
bResult = true
end
end
return bResult
end
function TowerDefenseData:GetlevelIsNew(levelId)
local bResult = false
local levelData = self:GetLevelData(levelId)
if levelData ~= nil and levelData.nStar == 0 and table.indexof(self.cacheEnterLevelList, levelId) == 0 then
bResult = true
end
return bResult
end
function TowerDefenseData:EnterLevelSelect(levelId)
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return
end
if table.indexof(self.cacheEnterLevelList, levelId) == 0 then
table.insert(self.cacheEnterLevelList, levelId)
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Level, {
levelConfig.LevelPage,
levelId
}, false)
LocalData.SetPlayerLocalData("TowerDefenseLevel", RapidJson.encode(self.cacheEnterLevelList))
self:RefreshRedDot()
end
end
function TowerDefenseData:RefreshRedDotbyTab(nTabIndex)
for levelId, _ in pairs(self.allLevelData) do
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return
end
if levelConfig.LevelPage == nTabIndex and table.indexof(self.cacheEnterLevelList, levelId) == 0 then
table.insert(self.cacheEnterLevelList, levelId)
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Level, {
levelConfig.LevelPage,
levelId
}, false)
end
end
LocalData.SetPlayerLocalData("TowerDefenseLevel", RapidJson.encode(self.cacheEnterLevelList))
self:RefreshRedDot()
end
function TowerDefenseData:GetNextLevelUnlockTime()
local nextlevelStartTime = 9999999999
local curTime = CS.ClientManager.Instance.serverTimeStamp
for _, level in pairs(self.allLevelData) do
local startTime = self:GetLevelStartTime(level.nLevelId)
if curTime < startTime then
nextlevelStartTime = math.min(nextlevelStartTime, startTime)
end
end
nextlevelStartTime = 0
return nextlevelStartTime
end
function TowerDefenseData:GetLevelTempTeamData(levelId)
return self.TempLevelTeamData[levelId]
end
function TowerDefenseData:SetLevelTeamData(levelId, tbCharGuideId, itemGuideId)
self.TempLevelTeamData[levelId] = {tbCharGuideId = tbCharGuideId, itemGuideId = itemGuideId}
end
function TowerDefenseData:UpdateStoryData(storyData)
self.allStoryData[storyData.nId] = {
nId = storyData.Id,
bIsRead = storyData.bIsRead
}
if self:GetPlayState() then
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Story, {
storyData.Id
}, self:GetStoryIsNew(storyData.nId))
end
EventManager.Hit("TowerDefenseStoryUpdate")
end
function TowerDefenseData:GetAllStoryData()
return self.allStoryData
end
function TowerDefenseData:GetStoryData(storyId)
return self.allStoryData[storyId]
end
function TowerDefenseData:IsStoryUnlock(storyId)
local bResult = false
local storyConfig = ConfigTable.GetData("TowerDefenseStory", storyId)
if storyConfig == nil then
return bResult
end
if storyConfig.LevelId == 0 then
return true
end
local blevelConditionPass = self:IsLevelUnlock(storyConfig.LevelId) and self:IsPreLevelPass(storyConfig.LevelId)
bResult = blevelConditionPass
return bResult
end
function TowerDefenseData:GetStoryIsNew(storyId)
local bResult = false
local storyData = self:GetStoryData(storyId)
if storyData ~= nil and not storyData.bIsRead and self:IsStoryUnlock(storyId) and self:IsPreStoryRead(storyId) then
bResult = true
end
return bResult
end
function TowerDefenseData:IsPreStoryRead(storyId)
local bResult = false
local storyConfig = ConfigTable.GetData("TowerDefenseStory", storyId)
if storyConfig == nil then
return bResult
end
local preStoryId = storyConfig.PreStoryId
if preStoryId == 0 then
bResult = true
else
local preStoryData = self:GetStoryData(preStoryId)
if preStoryData ~= nil and preStoryData.bIsRead then
bResult = true
end
end
return bResult
end
function TowerDefenseData:PlayAvg(storyId, avgId)
local function avgEndCallback()
EventManager.Remove("StoryDialog_DialogEnd", self, avgEndCallback)
if self.allStoryData[storyId].bIsRead == false then
self:RequestReadAVG(storyId)
end
end
EventManager.Add("StoryDialog_DialogEnd", self, avgEndCallback)
EventManager.Hit("StoryDialog_DialogStart", avgId)
end
function TowerDefenseData:UpdateQuest(questData)
local questConfig = ConfigTable.GetData("TowerDefenseQuest", questData.nId)
if questConfig == nil then
return
end
if self.allQuestData[questConfig.QuestGroupId] == nil then
self.allQuestData[questConfig.QuestGroupId] = {}
end
local progress = {}
local progressData = {}
if questData.nState == AllEnum.ActQuestStatus.Complete or questData.nState == AllEnum.ActQuestStatus.Received then
if questConfig.QuestType == GameEnum.towerDefenseCond.TowerDefenseClear then
progressData.Cur = 1
progressData.Max = 1
elseif questConfig.QuestType == GameEnum.towerDefenseCond.TowerDefenseClearSpecificStar then
progressData.Cur = 1
progressData.Max = 1
else
progressData.Cur = questConfig.QuestParam[2]
progressData.Max = questConfig.QuestParam[2]
end
table.insert(progress, progressData)
self.allQuestData[questConfig.QuestGroupId][questData.nId] = {
nId = questData.nId,
nState = questData.nState,
progress = progress
}
else
self.allQuestData[questConfig.QuestGroupId][questData.nId] = {
nId = questData.nId,
nState = questData.nState,
progress = questData.progress
}
end
RedDotManager.SetValid(RedDotDefine.Activity_TowerDefense_Quest, {
questConfig.QuestGroupId,
questData.nId
}, questData.nState == AllEnum.ActQuestStatus.Complete)
EventManager.Hit("TowerDefenseQuestUpdate")
end
function TowerDefenseData:GetQuestbyGroupId(nGroupId)
return self.allQuestData[nGroupId]
end
function TowerDefenseData:GetGroupQuestReceiveCount(nGroupId)
local nResult = 0
if self.allQuestData[nGroupId] == nil then
return nResult
end
for _, quest in pairs(self.allQuestData[nGroupId]) do
if quest.nState == AllEnum.ActQuestStatus.Received then
nResult = nResult + 1
end
end
return nResult
end
function TowerDefenseData:GetAllQuestCount()
local nResult = 0
for _, groupQuestList in pairs(self.allQuestData) do
for key, value in pairs(groupQuestList) do
nResult = nResult + 1
end
end
return nResult
end
function TowerDefenseData:GetAllReceivedCount()
local nResult = 0
for _, groupQuestList in pairs(self.allQuestData) do
for _, quest in pairs(groupQuestList) do
if quest.nState == AllEnum.ActQuestStatus.Received then
nResult = nResult + 1
end
end
end
return nResult
end
function TowerDefenseData:QuestStateServer2Client(nStatus)
if nStatus == 0 then
return AllEnum.ActQuestStatus.UnComplete
elseif nStatus == 1 then
return AllEnum.ActQuestStatus.Complete
else
return AllEnum.ActQuestStatus.Received
end
end
function TowerDefenseData:RefreshQuestData(questData)
self:UpdateQuest({
nId = questData.Id,
nState = self:QuestStateServer2Client(questData.Status),
progress = questData.Progress
})
self:RefreshRedDot()
end
function TowerDefenseData:InitTeam(levelId)
self.teamData = {
characterList = {},
itemId = 0
}
if self:IsLockTeam(levelId) then
self.teamData.characterList, self.teamData.itemId = self:GetLockCharacterAndItem(levelId)
end
end
function TowerDefenseData:IsLockTeam(levelId)
local bResult = false
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return bResult
end
local floorConfig = ConfigTable.GetData("TowerDefenseFloor", levelConfig.FloorId)
if floorConfig == nil then
return bResult
end
bResult = floorConfig.TeamGroup ~= nil and #floorConfig.TeamGroup > 0
return bResult
end
function TowerDefenseData:GetLockCharacterAndItem(levelId)
local characterList = {}
local itemId = 0
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", levelId)
if levelConfig == nil then
return characterList, itemId
end
local floorConfig = ConfigTable.GetData("TowerDefenseFloor", levelConfig.FloorId)
if floorConfig == nil then
return characterList, itemId
end
characterList = floorConfig.TeamGroup or {}
itemId = floorConfig.ItemID
return characterList, itemId
end
function TowerDefenseData:RefreshRedDot()
if not self:GetPlayState() then
return
end
local bReddot = false
for _, levelData in pairs(self.allLevelData) do
if self:IsLevelUnlock(levelData.nLevelId) then
bReddot = bReddot or self:GetlevelIsNew(levelData.nLevelId)
if bReddot then
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bReddot)
return
end
end
end
for _, questGroupData in pairs(self.allQuestData) do
for _, questData in pairs(questGroupData) do
bReddot = bReddot or questData.nState == AllEnum.ActQuestStatus.Complete
if bReddot then
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bReddot)
return
end
end
end
for _, storyData in pairs(self.allStoryData) do
bReddot = bReddot or self:GetStoryIsNew(storyData.nId)
if bReddot then
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bReddot)
return
end
end
RedDotManager.SetValid(RedDotDefine.Activity_Tab, self.nActId, bReddot)
end
function TowerDefenseData:RequestEnterLevel(levelId, characterList, itemId, callback)
local mapMsg = {
Level = levelId,
Characters = characterList,
ItemId = itemId
}
local cb = function()
if callback ~= nil then
callback()
end
local result = {
action = 1,
nActId = self.nActId,
nlevelId = levelId,
nStar = 0,
nHp = 0,
bIsFirstPass = false
}
self:EventUpload(result)
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_tower_defense_level_apply_req, mapMsg, nil, cb)
self.TempLevelTeamData[levelId] = {
charList = clone(characterList),
itemId = itemId
}
end
function TowerDefenseData:RequestFinishLevel(levelId, bResult, nHp, cb)
local levelData = self:GetLevelData(levelId)
if not bResult then
local mapMsg = {LevelId = levelId, Star = 0}
HttpNetHandler.SendMsg(NetMsgId.Id.activity_tower_defense_level_settle_req, mapMsg, nil, function()
if cb ~= nil then
cb(levelData.nStar, levelData.nStar)
end
local result = {
action = 5,
nActId = self.nActId,
nlevelId = levelId,
nStar = 0,
nHp = 0,
bIsFirstPass = false
}
self:EventUpload(result)
end)
return
end
local nStar = 1
local config = ConfigTable.GetData("TowerDefenseLevel", levelId)
if nHp > config.Condition2 then
nStar = nStar + 1
end
if nHp > config.Condition3 then
nStar = nStar + 1
end
local mapMsg = {LevelId = levelId, Star = nStar}
local oldStar = levelData.nStar
HttpNetHandler.SendMsg(NetMsgId.Id.activity_tower_defense_level_settle_req, mapMsg, nil, function(_, mapMsgData)
cb(nStar, levelData.nStar, mapMsgData)
self:UpdateLevelData({
Id = levelId,
Star = math.max(nStar, levelData.nStar)
})
local result = {
action = 2,
nActId = self.nActId,
nlevelId = levelId,
nStar = nStar,
nHp = nHp
}
if oldStar == 0 and levelData.nStar > 0 then
result.bIsFirstPass = true
else
result.bIsFirstPass = false
end
self:EventUpload(result)
end)
end
function TowerDefenseData:EventUpload(result)
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"action",
tostring(result.action)
})
table.insert(tabUpLevel, {
"activity_id",
tostring(result.nActId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(result.nlevelId)
})
table.insert(tabUpLevel, {
"first_clear",
tostring(result.bIsFirstPass and 1 or 0)
})
table.insert(tabUpLevel, {
"result_star",
tostring(result.nStar)
})
table.insert(tabUpLevel, {
"hp_result",
tostring(result.nHp)
})
NovaAPI.UserEventUpload("activity_tower_defense", tabUpLevel)
end
function TowerDefenseData:RequestReadAVG(storyId)
local mapMsg = {Value = storyId}
local cb = function(_, mapMsgData)
local data = {nId = storyId, bIsRead = true}
self:UpdateStoryData(data)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData)
UTILS.OpenReceiveByDisplayItem(mapDecodedChangeInfo["proto.Res"], mapMsgData)
self:RefreshRedDot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_tower_defense_story_reward_receive_req, mapMsg, nil, cb)
end
function TowerDefenseData:RequestReceiveQuest(nGroupId, nQuestId)
local mapMsg = {
ActivityId = self.nActId,
GroupId = nQuestId == 0 and nGroupId or 0,
QuestId = nQuestId
}
local cb = function(_, mapMsgData)
if nQuestId == 0 then
local quests = self:GetQuestbyGroupId(nGroupId)
for _, quest in pairs(quests) do
if quest.nState == AllEnum.ActQuestStatus.Complete then
local config = ConfigTable.GetData("TowerDefenseQuest", quest.nId)
local progress = {}
local progressData = {}
if config.QuestType == GameEnum.towerDefenseCond.TowerDefenseClear then
progressData.Cur = 1
progressData.Max = 1
elseif config.QuestType == GameEnum.towerDefenseCond.TowerDefenseClearSpecificStar then
progressData.Cur = 1
progressData.Max = 1
else
progressData.Cur = config.QuestParam[2]
progressData.Max = config.QuestParam[2]
end
table.insert(progress, progressData)
local data = {
nId = quest.nId,
nState = AllEnum.ActQuestStatus.Received,
progress = progress
}
self:UpdateQuest(data)
end
end
else
local config = ConfigTable.GetData("TowerDefenseQuest", nQuestId)
local progress = {}
local progressData = {}
if config.QuestType == GameEnum.towerDefenseCond.TowerDefenseClear then
progressData.Cur = 1
progressData.Max = 1
elseif config.QuestType == GameEnum.towerDefenseCond.TowerDefenseClearSpecificStar then
progressData.Cur = 1
progressData.Max = 1
else
progressData.Cur = config.QuestParam[2]
progressData.Max = config.QuestParam[2]
end
table.insert(progress, progressData)
local data = {
nId = nQuestId,
nState = AllEnum.ActQuestStatus.Received,
progress = progress
}
self:UpdateQuest(data)
end
self:RefreshRedDot()
UTILS.OpenReceiveByChangeInfo(mapMsgData)
EventManager.Hit("TowerDefenseQuestReceived")
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_tower_defense_quest_reward_receive_req, mapMsg, nil, cb)
end
return TowerDefenseData
@@ -0,0 +1,149 @@
local TowerDefenseLevelData = class("TowerDefenseLevelData")
local mapEventConfig = {
LoadLevelRefresh = "OnEvent_LoadLevelRefresh",
AdventureModuleEnter = "OnEvent_AdventureModuleEnter",
BattlePause = "OnEvent_Pause",
JointDrill_StartTiming = "OnEvent_BattleStart",
JointDrill_MonsterSpawn = "OnEvent_MonsterSpawn",
JointDrill_BattleLvsToggle = "OnEvent_BattleLvsToggle",
ADVENTURE_LEVEL_UNLOAD_COMPLETE = "OnEvent_UnloadComplete",
JointDrill_Gameplay_Time = "OnEvent_JointDrill_Gameplay_Time",
JointDrill_DamageValue = "OnEvent_GiveUpBattle",
RestartJointDrill = "OnEvent_RestartJointDrill",
RetreatJointDrill = "OnEvent_RetreatJointDrill",
JointDrill_Result = "OnEvent_JointDrill_Result",
InputEnable = "OnEvent_InputEnable"
}
function TowerDefenseLevelData:ctor()
end
function TowerDefenseLevelData:InitData(nLevelId, tbCharacter, nItemId, nActId)
self.nLevelId = nLevelId
self.tbCharacterData = {}
self.nActId = nActId
self.tbCharacterId = tbCharacter
self.nItemId = nItemId
self.bRestart = false
self:BindEvent()
end
function TowerDefenseLevelData:Restart()
self.tbCharacterData = {}
self.bRestart = true
end
function TowerDefenseLevelData:AddCharacter(nCharacterId, nEntityId)
local characterData = {
nCharacterId = nCharacterId,
nEntityId = nEntityId,
nLevel = 1,
tbPotentialList = {},
nCD = ConfigTable.GetData("TowerDefenseCharacter", nCharacterId).SkillCd // 10000
}
self.tbCharacterData[nCharacterId] = characterData
end
function TowerDefenseLevelData:CharacterLevelUp(nCharacterId)
if self.tbCharacterData[nCharacterId] == nil then
return
end
local nLevel = self.tbCharacterData[nCharacterId].nLevel
nLevel = math.min(6, nLevel + 1)
self.tbCharacterData[nCharacterId].nLevel = nLevel
EventManager.Hit("TowerDefenseChar_levelUp", nCharacterId, self.tbCharacterData[nCharacterId].nLevel)
end
function TowerDefenseLevelData:AddPotential(nCharacterId, nPotentialId)
if self.tbCharacterData[nCharacterId] == nil then
return
end
local stPerkInfo = CS.Lua2CSharpInfo_TPPerkInfo()
stPerkInfo.perkId = nPotentialId
stPerkInfo.nCount = 1
local bChange = false
if 1 <= #self.tbCharacterData[nCharacterId].tbPotentialList then
bChange = true
end
safe_call_cs_func(CS.AdventureModuleHelper.ChangePersonalPerkIds, {stPerkInfo}, nCharacterId, bChange)
table.insert(self.tbCharacterData[nCharacterId].tbPotentialList, nPotentialId)
end
function TowerDefenseLevelData:RefreshCharSkillCd(nCharacterId, nCD)
if self.tbCharacterData[nCharacterId] == nil then
return
end
self.tbCharacterData[nCharacterId].nCD = nCD
end
function TowerDefenseLevelData:GetCharSkillCD(nCharacterId)
if self.tbCharacterData[nCharacterId] == nil then
return nil
end
return self.tbCharacterData[nCharacterId].nCD
end
function TowerDefenseLevelData:GetPotentialByChar(nCharacterId)
if self.tbCharacterData[nCharacterId] == nil then
return nil
end
return self.tbCharacterData[nCharacterId].tbPotentialList
end
function TowerDefenseLevelData:GetCharacterLevel(nCharacterId)
if self.tbCharacterData[nCharacterId] == nil then
return nil
end
return self.tbCharacterData[nCharacterId].nLevel
end
function TowerDefenseLevelData:GetCharacterEntityId(nCharacterId)
if self.tbCharacterData[nCharacterId] == nil then
return nil
end
return self.tbCharacterData[nCharacterId].nEntityId
end
function TowerDefenseLevelData:OnEvent_UnloadComplete()
if not self.bRestart then
NovaAPI.EnterModule("MainMenuModuleScene", true)
self:UnBindEvent()
return
end
if self.nLevelId == 0 or self.nLevelId == nil then
return
end
self.bRestart = false
local levelConfig = ConfigTable.GetData("TowerDefenseLevel", self.nLevelId)
if levelConfig == nil then
return
end
EventManager.Hit(EventId.ClosePanel, PanelId.TowerDefensePanel)
local sItem = tostring(self.nItemId)
local sChar = ""
for index, value in ipairs(self.tbCharacterId) do
sChar = sChar .. tostring(value)
if index ~= #self.tbCharacterId then
sChar = sChar .. ","
end
end
local param = {}
table.insert(param, sItem)
table.insert(param, sChar)
CS.AdventureModuleHelper.EnterTowerDefenseLevel(levelConfig.FloorId, param)
EventManager.Hit(EventId.OpenPanel, PanelId.TowerDefensePanel, self.nActId, self.nLevelId)
end
function TowerDefenseLevelData:OnEvent_AdventureModuleEnter()
EventManager.Hit(EventId.OpenPanel, PanelId.TowerDefensePanel, self.nActId, self.nLevelId)
end
function TowerDefenseLevelData:BindEvent()
if type(mapEventConfig) ~= "table" then
return
end
for nEventId, sCallbackName in pairs(mapEventConfig) do
local callback = self[sCallbackName]
if type(callback) == "function" then
EventManager.Add(nEventId, self, callback)
end
end
end
function TowerDefenseLevelData:UnBindEvent()
if type(mapEventConfig) ~= "table" then
return
end
for nEventId, sCallbackName in pairs(mapEventConfig) do
local callback = self[sCallbackName]
if type(callback) == "function" then
EventManager.Remove(nEventId, self, callback)
end
end
end
return TowerDefenseLevelData
@@ -0,0 +1,52 @@
local ActivityDataBase = require("GameCore.Data.DataClass.Activity.ActivityDataBase")
local TrialActData = class("TrialActData", ActivityDataBase)
local LocalData = require("GameCore.Data.LocalData")
function TrialActData:Init()
self.mapTrialActCfg = nil
self.tbCompleteGroupId = {}
self:ParseConfig()
end
function TrialActData:ParseConfig()
local mapCfg = ConfigTable.GetData("TrialControl", self.nActId)
if not mapCfg then
return
end
self.mapTrialActCfg = mapCfg
end
function TrialActData:GetTrialControlCfg()
return self.mapTrialActCfg
end
function TrialActData:RefreshTrialActData(msgData)
self.tbCompleteGroupId = msgData.CompletedGroupIds
end
function TrialActData:CheckGroupReceived(nGroupId)
return table.indexof(self.tbCompleteGroupId, nGroupId) > 0
end
function TrialActData:GetNextUnreceiveGroup()
local tbGroup = self.mapTrialActCfg.GroupIds
for _, v in ipairs(tbGroup) do
local bReceived = self:CheckGroupReceived(v)
if not bReceived then
return v
end
end
end
function TrialActData:SendActivityTrialRewardReceiveReq(nGroupId, callback)
if self:CheckGroupReceived(nGroupId) then
printError("试玩奖励已领取过" .. nGroupId)
callback()
return
end
local msgData = {
ActivityId = self.nActId,
GroupId = nGroupId
}
local successCallback = function(_, mapMainData)
table.insert(self.tbCompleteGroupId, nGroupId)
if callback then
callback(mapMainData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.activity_trial_reward_receive_req, msgData, nil, successCallback)
end
return TrialActData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,233 @@
local CharacterAttrData = class("CharacterAttrData")
local ConfigData = require("GameCore.Data.ConfigData")
local AttrConfig = require("GameCore.Common.AttrConfig")
function CharacterAttrData:ctor(nId, mapCustom)
self.nId = nId
self.tbAttr = {}
self.CharAttrList = AttrConfig.GetCharAttrList()
for _, v in pairs(self.CharAttrList) do
if v.bAllEffectSub then
self.tbAttr["_" .. v.sKey] = nil
self.tbAttr["_" .. v.sKey .. "PercentAmend"] = nil
self.tbAttr["_" .. v.sKey .. "Amend"] = nil
else
self.tbAttr["_origin" .. v.sKey] = nil
end
self.tbAttr[v.sKey] = nil
self.tbAttr["base" .. v.sKey] = nil
end
self.eetType = nil
self.eet = nil
self.baseEET = nil
self.attrList = nil
self:ParseConfig(mapCustom)
end
function CharacterAttrData:ParseConfig(mapCustom)
if not self.nId then
return
end
local config = ConfigTable.GetData_Character(self.nId)
if not config then
return
end
local mapChar
if mapCustom == nil then
mapChar = PlayerData.Char:GetCharDataByTid(self.nId)
else
mapChar = mapCustom.mapChar
end
local nAttributeId = UTILS.GetCharacterAttributeId(tonumber(config.AttributeId), mapChar.nAdvance, mapChar.nLevel)
local attrConfig = ConfigTable.GetData_Attribute(tostring(nAttributeId))
if not attrConfig then
printError("角色表属性id配置不对,角色" .. self.nId)
return
end
local skillConfig = ConfigTable.GetData_Skill(config.UltimateId)
if not skillConfig then
printError("角色Skill表大招没配" .. config.UltimateId)
return
end
for _, v in pairs(self.CharAttrList) do
local mapCfg = attrConfig
if v.nConfigType == AllEnum.CharConfigType.Attr then
mapCfg = attrConfig
elseif v.nConfigType == AllEnum.CharConfigType.Char then
mapCfg = config
elseif v.nConfigType == AllEnum.CharConfigType.Skill then
mapCfg = skillConfig
end
local originVale = mapCfg[v.sKey] or 0
if v.bAllEffectSub then
self.tbAttr["_" .. v.sKey] = originVale
self.tbAttr["_" .. v.sKey .. "PercentAmend"] = 0
self.tbAttr["_" .. v.sKey .. "Amend"] = 0
self.tbAttr["base" .. v.sKey] = self.tbAttr["_" .. v.sKey]
else
self.tbAttr["_origin" .. v.sKey] = v.bIntFloat and originVale * ConfigData.IntFloatPrecision or originVale
self.tbAttr["base" .. v.sKey] = v.bPercent and self.tbAttr["_origin" .. v.sKey] * 100 or self.tbAttr["_origin" .. v.sKey]
end
self.tbAttr[v.sKey] = self.tbAttr["base" .. v.sKey]
end
self.eetType = AllEnum.EET[config.EET]
self.baseEET = attrConfig[self.eetType] or 0
self.eet = self.baseEET
self:AddAttr()
self:AddEffect(mapCustom)
self:UpdateAttrList()
end
function CharacterAttrData:SetCharacter(nId, mapCustom)
self.nId = nId
self:ParseConfig(mapCustom)
end
function CharacterAttrData:AddAttr()
for _, v in ipairs(AllEnum.AttachAttr) do
if self.tbAttr["base" .. v.sKey] then
if self.CharAttrList[v.sKey].bDifferentiate then
self.tbAttr["base" .. v.sKey] = self.tbAttr["base" .. v.sKey]
else
self.tbAttr["base" .. v.sKey] = self.tbAttr["base" .. v.sKey]
end
end
if self.tbAttr["_" .. v.sKey] then
self.tbAttr["_" .. v.sKey] = self.tbAttr["_" .. v.sKey]
end
if self.tbAttr[v.sKey] and not self.tbAttr["_" .. v.sKey] then
self.tbAttr[v.sKey] = self.tbAttr[v.sKey]
end
end
end
function CharacterAttrData:AddEffect(mapCustom)
local tbAllEfts = {}
if not mapCustom then
local tbAffinityEfts = PlayerData.Char:GetCharAffinityEffects(self.nId)
local tbTalentEfts = PlayerData.Talent:GetTalentEffect(self.nId)
local tbEquipmentEfts = PlayerData.Equipment:GetCharEquipmentEffect(self.nId)
if tbAffinityEfts then
for _, value in pairs(tbAffinityEfts) do
table.insert(tbAllEfts, value)
end
end
if tbTalentEfts then
for _, value in pairs(tbTalentEfts) do
table.insert(tbAllEfts, value)
end
end
if tbEquipmentEfts then
for _, value in pairs(tbEquipmentEfts) do
table.insert(tbAllEfts, value)
end
end
else
tbAllEfts = mapCustom.tbEffect or {}
end
self:AddAttrEffect(tbAllEfts)
self:AddEquipmentRandomAttr(mapCustom)
self:CalAllEffectSubAttr()
end
function CharacterAttrData:AddAttrEffect(tbAttrEffect)
for _, attrEffectId in ipairs(tbAttrEffect) do
local config = ConfigTable.GetData_Effect(attrEffectId)
local valueConfig = ConfigTable.GetData("EffectValue", attrEffectId)
if valueConfig ~= nil and config ~= nil then
local bAttrFix = valueConfig.EffectType == GameEnum.effectType.ATTR_FIX or valueConfig.EffectType == GameEnum.effectType.PLAYER_ATTR_FIX
if bAttrFix and config.Trigger == GameEnum.trigger.NOTHING then
local mapAttr = AttrConfig.GetAttrByEffectType(valueConfig.EffectType, valueConfig.EffectTypeFirstSubtype)
if mapAttr then
if mapAttr.bAllEffectSub then
self:AddAttrEffect_AllEffectSub(valueConfig.EffectTypeSecondSubtype, valueConfig.EffectTypeParam1, mapAttr)
else
self:AddAttrEffect_BaseValue(valueConfig.EffectTypeSecondSubtype, valueConfig.EffectTypeParam1, mapAttr)
end
else
local value = tonumber(valueConfig.EffectTypeParam1) or 0
if valueConfig.EffectTypeFirstSubtype == self.eetType and valueConfig.EffectTypeSecondSubtype == GameEnum.parameterType.BASE_VALUE then
self.baseEET = self.baseEET + value
self.eet = self.eet + value
end
end
end
end
end
end
function CharacterAttrData:AddEquipmentRandomAttr(mapCustom)
local tbRandomAttr = {}
if mapCustom then
tbRandomAttr = mapCustom.tbRandomAttr or {}
else
tbRandomAttr = PlayerData.Equipment:GetCharEquipmentRandomAttr(self.nId)
end
for nAttrId, v in pairs(tbRandomAttr) do
local mapAttrCfg = ConfigTable.GetData("CharGemAttrValue", nAttrId)
if mapAttrCfg then
local attrType = mapAttrCfg.AttrType
local attrSubType1 = mapAttrCfg.AttrTypeFirstSubtype
local attrSubType2 = mapAttrCfg.AttrTypeSecondSubtype
local bAttrFix = attrType == GameEnum.effectType.ATTR_FIX or attrType == GameEnum.effectType.PLAYER_ATTR_FIX
if bAttrFix then
local mapAttr = AttrConfig.GetAttrByEffectType(attrType, attrSubType1)
if mapAttr then
if mapAttr.bAllEffectSub then
self:AddAttrEffect_AllEffectSub(attrSubType2, v.Value, mapAttr)
else
self:AddAttrEffect_BaseValue(attrSubType2, v.Value, mapAttr)
end
else
local value = tonumber(v.CfgValue) or 0
if attrSubType1 == self.eetType and attrSubType2 == GameEnum.parameterType.BASE_VALUE then
self.baseEET = self.baseEET + value
self.eet = self.eet + value
end
end
end
end
end
end
function CharacterAttrData:AddAttrEffect_AllEffectSub(nSubType, nValue, mapAttr)
local value = tonumber(nValue) or 0
if nSubType == GameEnum.parameterType.PERCENTAGE then
self.tbAttr["_" .. mapAttr.sKey .. "PercentAmend"] = self.tbAttr["_" .. mapAttr.sKey .. "PercentAmend"] + value * 100
elseif nSubType == GameEnum.parameterType.ABSOLUTE_VALUE then
self.tbAttr["_" .. mapAttr.sKey .. "Amend"] = self.tbAttr["_" .. mapAttr.sKey .. "Amend"] + value
elseif nSubType == GameEnum.parameterType.BASE_VALUE then
self.tbAttr["_" .. mapAttr.sKey] = self.tbAttr["_" .. mapAttr.sKey] + value
end
end
function CharacterAttrData:AddAttrEffect_BaseValue(nSubType, nValue, mapAttr)
local value = tonumber(nValue) or 0
if nSubType == GameEnum.parameterType.BASE_VALUE then
local nAdd = mapAttr.bPercent and value * 100 or value
if not mapAttr.bDifferentiate then
self.tbAttr["base" .. mapAttr.sKey] = self.tbAttr["base" .. mapAttr.sKey] + nAdd
end
self.tbAttr[mapAttr.sKey] = self.tbAttr[mapAttr.sKey] + nAdd
end
end
function CharacterAttrData:CalAllEffectSubAttr()
for _, v in pairs(self.CharAttrList) do
if v.bAllEffectSub then
self.tbAttr[v.sKey] = self.tbAttr["_" .. v.sKey] * (1 + self.tbAttr["_" .. v.sKey .. "PercentAmend"] / 100) + self.tbAttr["_" .. v.sKey .. "Amend"]
self.tbAttr[v.sKey] = math.floor(self.tbAttr[v.sKey])
end
end
end
function CharacterAttrData:UpdateAttrList()
if not self.attrList then
self.attrList = {}
end
for k, v in pairs(AllEnum.CharAttr) do
if not self.attrList[k] then
self.attrList[k] = {}
end
self.attrList[k].totalValue, self.attrList[k].baseValue = self.tbAttr[v.sKey], self.tbAttr["base" .. v.sKey]
end
end
function CharacterAttrData:GetEETType()
return self.eetType
end
function CharacterAttrData:GetEET()
return self.eet, self.baseEET
end
function CharacterAttrData:GetAttrList()
return self.attrList
end
return CharacterAttrData
+157
View File
@@ -0,0 +1,157 @@
local DepotData = class("DepotData")
function DepotData:ctor()
self.tbConsumables = {}
self.tbBasicItem = {}
self.tbMaterial = {}
self.nConsumablesCount = 0
self.nBasicItemCount = 0
self.nMaterialCount = 0
end
function DepotData:Init(nType)
if nType == nil then
self:InitConsumables()
self:InitBasicItem()
self:InitMaterial()
elseif nType == GameEnum.packMark.Consumables then
self:InitConsumables()
elseif nType == GameEnum.packMark.BasicItem then
self:InitBasicItem()
elseif nType == GameEnum.packMark.Material then
self:InitMaterial()
end
end
function DepotData:Init()
self:InitConsumables()
self:InitBasicItem()
self:InitMaterial()
end
function DepotData:InitConsumables()
local tbItem = PlayerData.Item:GetItemsByMark(GameEnum.packMark.Consumables)
self.tbConsumables = self:InitItemList(tbItem)
self.nConsumablesCount = #self.tbConsumables
end
function DepotData:InitBasicItem()
local tbItem = PlayerData.Item:GetItemsByMark(GameEnum.packMark.BasicItem)
self.tbBasicItem = self:InitItemList(tbItem)
self.nBasicItemCount = #self.tbBasicItem
end
function DepotData:InitMaterial()
local tbItem = PlayerData.Item:GetItemsByMark(GameEnum.packMark.Material)
self.tbMaterial = self:InitItemList(tbItem)
self.nMaterialCount = #self.tbMaterial
end
function DepotData:InitItemList(tbItem)
local tbAfter = {}
local curTime = CS.ClientManager.Instance.serverTimeStamp
for _, mapItem in ipairs(tbItem) do
for nExpire, mapExpiresData in pairs(mapItem.mapExpires) do
if 0 < nExpire and 0 < nExpire - curTime or nExpire == 0 then
local mapAfter = {
nTid = mapItem.Tid,
nId = mapItem.Tid,
nRarity = ConfigTable.GetData_Item(mapItem.Tid).Rarity,
sType = ConfigTable.GetData_Item(mapItem.Tid).Stype,
nExpire = nExpire,
nCount = mapExpiresData.nTotalCount,
bDisplay = ConfigTable.GetData_Item(mapItem.Tid).Display
}
table.insert(tbAfter, mapAfter)
end
end
end
return tbAfter
end
function DepotData:GetGridCount(nType)
local tbItem = {}
if nType == GameEnum.packMark.Consumables then
tbItem = self.tbConsumables
elseif nType == GameEnum.packMark.BasicItem then
tbItem = self.tbBasicItem
elseif nType == GameEnum.packMark.Material then
tbItem = self.tbMaterial
end
local tbDisplayItem = self:GetDisplayItemList(tbItem)
return #tbDisplayItem
end
function DepotData:GetSortedList(nType, mapSort, tbFilter)
if nType == GameEnum.packMark.Consumables then
self:GetSortedConsumables()
return self:GetDisplayItemList(self.tbConsumables)
elseif nType == GameEnum.packMark.BasicItem then
self:GetSortedBasicItem()
return self:GetDisplayItemList(self.tbBasicItem)
elseif nType == GameEnum.packMark.Material then
self:GetSortedMaterial()
return self:GetDisplayItemList(self.tbMaterial)
end
end
function DepotData:GetSortedConsumables(nSortType, bOrder)
if nSortType == nil then
return self:SortItem_Rarity(self.tbConsumables, true)
end
end
function DepotData:GetSortedBasicItem(nSortType, bOrder)
if nSortType == nil then
return self:SortItem_Rarity(self.tbBasicItem, true)
end
end
function DepotData:GetSortedMaterial(nSortType, bOrder)
if nSortType == nil then
return self:SortItem_Rarity(self.tbMaterial, true)
end
end
function DepotData:SortItem_Rarity(tbItem, bOrder)
local comp = function(a, b)
if a.nRarity == b.nRarity then
if a.sType == b.sType then
if a.nExpire == b.nExpire then
if bOrder then
return a.nTid < b.nTid
else
return a.nTid > b.nTid
end
end
if a.nExpire == 0 or b.nExpire == 0 then
if bOrder then
return a.nExpire > b.nExpire
else
return a.nExpire < b.nExpire
end
elseif bOrder then
return a.nExpire < b.nExpire
else
return a.nExpire > b.nExpire
end
end
if bOrder then
return a.sType < b.sType
else
return a.sType > b.sType
end
end
if bOrder then
return a.nRarity < b.nRarity
else
return a.nRarity > b.nRarity
end
end
table.sort(tbItem, comp)
end
function DepotData:GetDisplayItemList(tbItem)
local tbShowItem = {}
for _, v in ipairs(tbItem) do
if v.bDisplay then
table.insert(tbShowItem, v)
end
end
return tbShowItem
end
function DepotData:Clear()
self.tbConsumables = nil
self.tbBasicItem = nil
self.tbMaterial = nil
self.nConsumablesCount = nil
self.nBasicItemCount = nil
self.nMaterialCount = nil
end
return DepotData
+475
View File
@@ -0,0 +1,475 @@
local ConfigData = require("GameCore.Data.ConfigData")
local DiscData = class("DiscData")
function DiscData:ctor(mapDisc)
self.nId = nil
self.sName = nil
self.sDesc = nil
self.nRarity = nil
self.sIcon = nil
self.bRead = nil
self.bAvgRead = nil
self.nCreateTime = nil
self.nEET = nil
self.tbTag = nil
self.nLevel = nil
self.nMaxLv = nil
self.nStrengthenGroupId = nil
self.nAttrBaseGroupId = nil
self.nAttrExtraGroupId = nil
self.mapAttrBase = nil
self.mapAttrExtra = nil
self.nExp = nil
self.nPhase = nil
self.nMaxPhase = nil
self.nPromoteGroupId = nil
self.nPromoteGoldReq = nil
self.tbPromoteItemInfoReq = nil
self.bUnlockL2D = nil
self.nStar = nil
self.nMaxStar = nil
self.nTransformItemId = nil
self.mapMaxStarTransformItem = nil
self.nMainSkillGroupId = nil
self.nMainSkillId = nil
self.tbSubSkillGroupId = nil
self.sSkillScript = nil
self.tbSubNoteSkills = nil
self.tbSkillNeedNote = nil
self.nSubNoteSkillGroupId = nil
self.nSubNoteSkillId = nil
self.tbShowNote = nil
self.mapReadReward = nil
self.mapAvgReward = nil
self:Parse(mapDisc)
end
function DiscData:Parse(mapDisc)
self.nId = mapDisc.Id
local mapItemCfgData = ConfigTable.GetData_Item(mapDisc.Id)
if not mapItemCfgData then
printError("星盘Id有误, 道具表中未找到数据, Id: " .. tostring(mapDisc.Id))
return
end
local mapDiscCfgData = ConfigTable.GetData("Disc", mapDisc.Id)
if mapDiscCfgData == nil then
printError("星盘Id有误, 未找到配置表数据, Id: " .. tostring(mapDisc.Id))
return
end
self:ParseConfigData(mapItemCfgData, mapDiscCfgData)
self:ParseServerData(mapDisc)
end
function DiscData:ParseConfigData(mapItemCfgData, mapDiscCfgData)
self.sName = mapItemCfgData.Title
self.sDesc = mapItemCfgData.Desc
self.nRarity = mapItemCfgData.Rarity
self.sIcon = mapItemCfgData.Icon
self.nEET = mapDiscCfgData.EET
self.tbTag = mapDiscCfgData.Tags
self.nStrengthenGroupId = mapDiscCfgData.StrengthenGroupId
self.nAttrBaseGroupId = mapDiscCfgData.AttrBaseGroupId
self.nAttrExtraGroupId = mapDiscCfgData.AttrExtraGroupId
self.nPromoteGroupId = mapDiscCfgData.PromoteGroupId
self:ParseMaxPhase()
self.nTransformItemId = mapDiscCfgData.TransformItemId
self.mapMaxStarTransformItem = mapDiscCfgData.MaxStarTransformItem
self.nMaxStar = PlayerData.Disc:GetDiscMaxStar(self.nRarity)
self.nMainSkillGroupId = mapDiscCfgData.MainSkillGroupId
self.tbSubSkillGroupId = {}
if mapDiscCfgData.SecondarySkillGroupId1 > 0 then
table.insert(self.tbSubSkillGroupId, mapDiscCfgData.SecondarySkillGroupId1)
end
if 0 < mapDiscCfgData.SecondarySkillGroupId2 then
table.insert(self.tbSubSkillGroupId, mapDiscCfgData.SecondarySkillGroupId2)
end
self.sSkillScript = mapDiscCfgData.SkillScript
self.nSubNoteSkillGroupId = mapDiscCfgData.SubNoteSkillGroupId
self.tbSkillNeedNote = {}
local mapNote = {}
for _, nSkillGroupId in ipairs(self.tbSubSkillGroupId) do
local tbGroup = CacheTable.GetData("_SecondarySkill", nSkillGroupId)
if tbGroup and tbGroup[1] then
local tbActiveNote = decodeJson(tbGroup[1].NeedSubNoteSkills)
if tbActiveNote ~= nil then
for k, v in pairs(tbActiveNote) do
local nNoteId = tonumber(k)
local nNoteCount = tonumber(v)
if nNoteId ~= nil and nNoteCount ~= nil then
if mapNote[nNoteId] == nil then
mapNote[nNoteId] = 0
end
mapNote[nNoteId] = nNoteCount > mapNote[nNoteId] and nNoteCount or mapNote[nNoteId]
end
end
end
end
end
for nNoteId, nCount in pairs(mapNote) do
table.insert(self.tbSkillNeedNote, {nId = nNoteId, nCount = nCount})
end
self.mapReadReward = {
nId = mapDiscCfgData.ReadReward[1],
nCount = mapDiscCfgData.ReadReward[2]
}
self.mapAvgReward = {
nId = mapDiscCfgData.AVGReadReward[1],
nCount = mapDiscCfgData.AVGReadReward[2]
}
end
function DiscData:ParseMaxPhase()
self.nMaxPhase = self.nMaxPhase or 0
local foreachDiscPromoteLimit = function(mapData)
if mapData.Rarity == self.nRarity and tonumber(mapData.Phase) > self.nMaxPhase then
self.nMaxPhase = tonumber(mapData.Phase)
end
end
ForEachTableLine(DataTable.DiscPromoteLimit, foreachDiscPromoteLimit)
end
function DiscData:ParseServerData(mapDisc)
if not mapDisc then
printError("DiscData ParseServerData Failed")
return
end
local bPhaseChange, bStarChange = false, false
if mapDisc.Phase ~= nil then
bPhaseChange = self.nPhase ~= mapDisc.Phase
end
if mapDisc.Star ~= nil then
bStarChange = self.nStar ~= mapDisc.Star
end
if mapDisc.Exp ~= nil then
self.nExp = mapDisc.Exp
end
if mapDisc.Level ~= nil then
self.nLevel = mapDisc.Level
end
if mapDisc.Phase ~= nil then
self.nPhase = mapDisc.Phase
end
if mapDisc.Star ~= nil then
self.nStar = mapDisc.Star
end
if mapDisc.Read ~= nil then
self.bRead = mapDisc.Read
end
if mapDisc.Avg ~= nil then
self.bAvgRead = mapDisc.Avg
end
if mapDisc.CreateTime ~= nil then
self.nCreateTime = mapDisc.CreateTime
end
self:UpdateMaxLv()
self:UpdateAttr()
if bPhaseChange then
self:UpdatePromoteGoldCountReq()
self:UpdatePromoteItemInfoReq()
self:UpdateNoteData()
self:UpdateUnlockData()
end
if bStarChange then
self:UpdateMainSkillData()
end
end
function DiscData:UpdateMaxLv()
self.nMaxLv = self.nMaxLv or 1
local foreachDiscPromoteLimit = function(mapData)
if mapData.Rarity == self.nRarity and tonumber(mapData.Phase) == self.nPhase and tonumber(mapData.Phase) == self.nPhase then
self.nMaxLv = tonumber(mapData.MaxLevel)
end
end
ForEachTableLine(DataTable.DiscPromoteLimit, foreachDiscPromoteLimit)
end
function DiscData:UpdateAttr()
self.mapAttrBase, self.mapAttrExtra = {}, {}
for _, v in ipairs(AllEnum.AttachAttr) do
self.mapAttrExtra[v.sKey] = {
Key = v.sKey,
Value = 0,
CfgValue = 0
}
end
if 0 < self.nStar and 0 < self.nAttrExtraGroupId then
local nExtraId = UTILS.GetDiscExtraAttributeId(self.nAttrExtraGroupId, self.nStar)
local mapExtra = ConfigTable.GetData("DiscExtraAttribute", tostring(nExtraId))
if mapExtra and type(mapExtra) == "table" then
for _, v in ipairs(AllEnum.AttachAttr) do
local nParamValue = mapExtra[v.sKey] or 0
self.mapAttrExtra[v.sKey] = {
Key = v.sKey,
Value = v.bPercent and nParamValue * ConfigData.IntFloatPrecision * 100 or nParamValue,
CfgValue = mapExtra[v.sKey] or 0
}
end
end
end
local nAttrBaseId = UTILS.GetDiscAttributeId(self.nAttrBaseGroupId, self.nPhase, self.nLevel)
local mapAttribute = ConfigTable.GetData_Attribute(tostring(nAttrBaseId))
if type(mapAttribute) == "table" then
for _, v in ipairs(AllEnum.AttachAttr) do
local nParamValue = mapAttribute[v.sKey] or 0
local nValue = v.bPercent and nParamValue * ConfigData.IntFloatPrecision * 100 or nParamValue
self.mapAttrBase[v.sKey] = {
Key = v.sKey,
Value = nValue + self.mapAttrExtra[v.sKey].Value,
CfgValue = nParamValue + self.mapAttrExtra[v.sKey].CfgValue
}
end
else
printError("星盘属性配置错误:" .. nAttrBaseId)
for _, v in ipairs(AllEnum.AttachAttr) do
self.mapAttrBase[v.sKey] = {
Key = v.sKey,
Value = 0,
CfgValue = 0
}
end
end
end
function DiscData:UpdatePromoteGoldCountReq()
if self.nMaxPhase == self.nPhase then
self.nPromoteGoldReq = 0
return
end
if self.nPromoteGroupId == 0 then
printError("无星盘进阶组" .. self.nId)
self.nPromoteGoldReq = 0
return
end
local nDiscPromoteId = self.nPromoteGroupId * 1000 + (self.nPhase + 1)
local mapCfgData = ConfigTable.GetData("DiscPromote", nDiscPromoteId)
self.nPromoteGoldReq = 0
if type(mapCfgData) == "table" then
self.nPromoteGoldReq = mapCfgData.ExpenseGold
end
end
function DiscData:UpdatePromoteItemInfoReq()
if self.nMaxPhase == self.nPhase then
self.tbPromoteItemInfoReq = {}
return
end
if not self.tbPromoteItemInfoReq then
self.tbPromoteItemInfoReq = {}
end
for index, _ in pairs(self.tbPromoteItemInfoReq) do
self.tbPromoteItemInfoReq[index] = nil
end
if self.nPromoteGroupId == 0 then
printError("无星盘进阶组" .. self.nId)
return
end
local nDiscPromoteId = self.nPromoteGroupId * 1000 + (self.nPhase + 1)
local mapCfgData = ConfigTable.GetData("DiscPromote", nDiscPromoteId)
if type(mapCfgData) == "table" then
for i = 1, 4 do
local item = {}
local nItemId = mapCfgData[string.format("ItemId%d", i)]
local nItemNum = mapCfgData[string.format("Num%d", i)]
if type(nItemId) == "number" and type(nItemNum) == "number" and 0 < nItemId and 0 < nItemNum then
item.nItemId = nItemId
item.nItemNum = nItemNum
table.insert(self.tbPromoteItemInfoReq, item)
end
end
end
end
function DiscData:UpdateMainSkillData()
if self.nMainSkillGroupId <= 0 then
return
end
local mapGroup = CacheTable.GetData("_MainSkill", self.nMainSkillGroupId)
if mapGroup then
local mapCfg = mapGroup[self.nStar + 1]
if not mapCfg then
printError("MainSkill缺失配置,GroupId:" .. self.nMainSkillGroupId .. " Level:" .. self.nStar + 1)
return
end
self.nMainSkillId = mapCfg.Id
end
end
function DiscData:UpdateNoteData()
self.tbSubNoteSkills = {}
self.tbShowNote = {}
if self.nSubNoteSkillGroupId <= 0 then
return
end
local mapGroup = CacheTable.GetData("_SubNoteSkillPromoteGroup", self.nSubNoteSkillGroupId)
if not mapGroup then
return
end
local nCurPhase = self.nPhase
local mapCfg
while type(nCurPhase) == "number" and 0 <= nCurPhase do
mapCfg = mapGroup[nCurPhase]
if mapCfg then
self.nSubNoteSkillId = mapCfg.Id
break
else
nCurPhase = nCurPhase - 1
end
end
if not mapCfg then
return
end
local tbNote = decodeJson(mapCfg.SubNoteSkills)
for k, v in pairs(tbNote) do
local nNoteId = tonumber(k)
local nNoteCount = tonumber(v)
if nNoteId then
table.insert(self.tbSubNoteSkills, {nId = nNoteId, nCount = nNoteCount})
table.insert(self.tbShowNote, nNoteId)
end
end
end
function DiscData:UpdateUnlockData()
self.bUnlockL2D = false
if self.nRarity == GameEnum.itemRarity.SSR then
local nLimit = ConfigTable.GetConfigNumber("DiscL2dUnlock")
if nLimit <= self.nPhase then
self.bUnlockL2D = true
end
end
end
function DiscData:CheckSubSkillActive(tbNote, mapCfg)
local tbActiveNote = decodeJson(mapCfg.NeedSubNoteSkills)
local tbNoteAble = {}
for k, v in pairs(tbActiveNote) do
local nNoteId = tonumber(k)
local nNoteCount = tonumber(v)
if nNoteId then
tbNoteAble[nNoteId] = false
local nHas = tbNote[nNoteId]
if nHas and nNoteCount <= nHas then
tbNoteAble[nNoteId] = true
end
end
end
local bActive = true
for _, v in pairs(tbNoteAble) do
if v == false then
bActive = false
break
end
end
if bActive and next(tbNoteAble) ~= nil then
return true
end
return false
end
function DiscData:GetAllSubSkill(tbNote)
local tbSkill = {}
for _, nSubSkillGroupId in pairs(self.tbSubSkillGroupId) do
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if tbGroup then
local nCurLayer = 1
local nMaxLayer = #tbGroup
for i = nMaxLayer, 1, -1 do
if tbGroup[i] then
local bActive = self:CheckSubSkillActive(tbNote, tbGroup[i])
if bActive then
nCurLayer = i
break
end
end
end
if tbGroup[nCurLayer] then
table.insert(tbSkill, tbGroup[nCurLayer].Id)
end
end
end
return tbSkill
end
function DiscData:GetSubSkillMaxLevel(nSubSkillGroupId)
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if not tbGroup then
return 0
end
local nMaxLayer = #tbGroup
return nMaxLayer
end
function DiscData:GetSubSkillLevel(nSubSkillGroupId, tbNote)
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if not tbGroup then
return 0, 0
end
local nCurLayer = 0
local nMaxLayer = #tbGroup
for i = nMaxLayer, 1, -1 do
if tbGroup[i] then
local bActive = self:CheckSubSkillActive(tbNote, tbGroup[i])
if bActive then
nCurLayer = i
break
end
end
end
return nCurLayer, nMaxLayer
end
function DiscData:GetSkillEffect(tbNote)
local tbEffectId = {}
local add = function(tbEfId)
if not tbEfId then
return
end
for _, nEfId in pairs(tbEfId) do
if type(nEfId) == "number" and 0 < nEfId then
table.insert(tbEffectId, {nEfId, 0})
end
end
end
local mapMainCfg = ConfigTable.GetData("MainSkill", self.nMainSkillId)
if mapMainCfg then
add(mapMainCfg.EffectId)
end
for _, nSubSkillGroupId in pairs(self.tbSubSkillGroupId) do
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if tbGroup then
local nMaxLayer = #tbGroup
for i = nMaxLayer, 1, -1 do
if tbGroup[i] then
local bActive = self:CheckSubSkillActive(tbNote, tbGroup[i])
if bActive then
add(tbGroup[i].EffectId)
break
end
end
end
end
end
return tbEffectId
end
function DiscData:GetDiscInfo(tbNote)
local tbSkillInfo = {}
local skillInfoMain = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfoMain.skillId = self.nMainSkillId
skillInfoMain.skillLevel = 1
table.insert(tbSkillInfo, skillInfoMain)
for _, nSubSkillGroupId in pairs(self.tbSubSkillGroupId) do
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if tbGroup then
local nLayer = 0
local nSubSkillId = tbGroup[1].Id
local nMaxLayer = #tbGroup
for i = nMaxLayer, 1, -1 do
if tbGroup[i] then
local bActive = self:CheckSubSkillActive(tbNote, tbGroup[i])
if bActive then
nLayer = i
nSubSkillId = tbGroup[i].Id
break
end
end
end
if 0 < nLayer then
local skillInfo = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfo.skillId = nSubSkillId
skillInfo.skillLevel = nLayer
table.insert(tbSkillInfo, skillInfo)
end
end
end
local discInfo = CS.Lua2CSharpInfo_DiscInfo()
discInfo.discId = self.nId
discInfo.discScript = self.sSkillScript
discInfo.skillInfos = tbSkillInfo
discInfo.discLevel = self.nLevel
return discInfo
end
return DiscData
@@ -0,0 +1,508 @@
local dailycheckinctrl = require("Game.UI.CheckIn.DailyCheckInCtrl")
local DispatchData = class("DispatchData")
local tbAllDispatchData = {}
local tbWeeklyDispatchDataIds = {}
local tbCompletedDailyDispatchIds = {}
local tbCompletedWeeklyDispatchIds = {}
local bReqApplyAgent = false
local OnEvent_NewDay = function()
tbCompletedDailyDispatchIds = {}
EventManager.Hit("UpdateDispatchData")
end
local Init = function()
EventManager.Add(EventId.IsNewDay, DispatchData, OnEvent_NewDay)
end
local UnInit = function()
EventManager.Remove(EventId.IsNewDay, DispatchData, OnEvent_NewDay)
end
local CacheDispatchData = function(data)
if data == nil or data.Infos == nil then
return
end
for k, v in pairs(data.Infos) do
local state = AllEnum.DispatchState.Accepting
if v.ProcessTime * 60 + v.StartTime <= CS.ClientManager.Instance.serverTimeStamp then
state = AllEnum.DispatchState.Complete
end
tbAllDispatchData[v.Id] = {Data = v, State = state}
end
tbCompletedDailyDispatchIds = data.DailyIds
tbCompletedWeeklyDispatchIds = data.WeeklyIds
tbWeeklyDispatchDataIds = data.NewAgentIds
for i = #tbWeeklyDispatchDataIds, 1, -1 do
if table.indexof(tbCompletedWeeklyDispatchIds, tbWeeklyDispatchDataIds[i]) > 0 then
table.remove(tbWeeklyDispatchDataIds, i)
end
end
end
local GetAllDispatchingData = function()
return tbAllDispatchData
end
local GetAccpectingDispatchCount = function()
local count = 0
for k, v in pairs(tbAllDispatchData) do
local agentData = ConfigTable.GetData("Agent", v.Data.Id)
if agentData.Tab ~= GameEnum.AgentType.Emergency and (v.State == AllEnum.DispatchState.Accepting or v.State == AllEnum.DispatchState.Complete) then
count = count + 1
end
end
return count
end
local GetDispatchState = function(dispatchId)
if tbAllDispatchData[dispatchId] ~= nil then
if tbAllDispatchData[dispatchId].Data.ProcessTime * 60 + tbAllDispatchData[dispatchId].Data.StartTime <= CS.ClientManager.Instance.serverTimeStamp then
tbAllDispatchData[dispatchId].State = AllEnum.DispatchState.Complete
end
return tbAllDispatchData[dispatchId].State
end
if table.indexof(tbCompletedDailyDispatchIds, dispatchId) > 0 then
return AllEnum.DispatchState.Done
end
if table.indexof(tbCompletedWeeklyDispatchIds, dispatchId) > 0 then
return AllEnum.DispatchState.Done
end
return AllEnum.DispatchState.CanAccept
end
local GetAllTabData = function()
local tabDispatchData = {}
local allTab = ConfigTable.Get("AgentTab")
local foreachAgentTab = function(mapData)
table.insert(tabDispatchData, mapData.Id)
end
ForEachTableLine(allTab, foreachAgentTab)
return tabDispatchData
end
local GetAllDispatchItemList = function()
local allDispatch = ConfigTable.Get("Agent")
local tbDispatchList = {}
local foreachAgent = function(mapData)
if mapData.Tab ~= GameEnum.AgentType.Emergency then
if tbDispatchList[mapData.Tab] == nil then
tbDispatchList[mapData.Tab] = {}
end
if mapData.RefreshType ~= GameEnum.AgentRefreshType.Daily or table.indexof(tbCompletedDailyDispatchIds, mapData.Id) <= 0 then
table.insert(tbDispatchList[mapData.Tab], mapData.Id)
end
end
end
ForEachTableLine(allDispatch, foreachAgent)
tbDispatchList[GameEnum.AgentType.Emergency] = tbWeeklyDispatchDataIds
for k, v in pairs(tbAllDispatchData) do
local data = ConfigTable.GetData("Agent", k)
if data ~= nil and data.Tab == GameEnum.AgentType.Emergency and table.indexof(tbDispatchList[GameEnum.AgentType.Emergency], k) < 1 then
table.insert(tbDispatchList[GameEnum.AgentType.Emergency], data.Id)
end
end
return tbDispatchList
end
local CheckTabUnlock = function(tabIndex, dispatchListData)
local txtLockCondition = ""
local bDispatchUnlock = false
if dispatchListData == nil then
dispatchListData = {}
local foreachAgent = function(mapData)
if mapData.Tab == tabIndex then
table.insert(dispatchListData, mapData.Id)
end
end
ForEachTableLine(ConfigTable.Get("Agent"), foreachAgent)
end
for k, v in pairs(dispatchListData) do
bDispatchUnlock, txtLockCondition = PlayerData.Dispatch.CheckDispatchItemUnlock(v)
if bDispatchUnlock then
return true
end
end
return bDispatchUnlock, txtLockCondition
end
local GetDispatchCharList = function(dispatchId)
if tbAllDispatchData[dispatchId] then
return tbAllDispatchData[dispatchId].Data.CharIds
end
return {}
end
local GetDispatchBuildData = function(dispatchId, callback)
local _mapAllBuild = {}
local buildId = -1
if tbAllDispatchData[dispatchId] ~= nil then
buildId = tbAllDispatchData[dispatchId].Data.BuildId
end
local GetDataCallback = function(tbBuildData, mapAllBuild)
_mapAllBuild = mapAllBuild
if callback ~= nil then
callback(_mapAllBuild[buildId])
end
end
PlayerData.Build:GetAllBuildBriefData(GetDataCallback)
end
local CheckDispatchItemUnlock = function(dispatchId)
local agentData = ConfigTable.GetData("Agent", dispatchId)
local tbCond = decodeJson(agentData.UnlockConditions)
if tbCond == nil then
return true
else
for _, tbCondInfo in ipairs(tbCond) do
if tbCondInfo[1] == 1 then
local nCondLevelId = tbCondInfo[2]
if 1 > table.indexof(PlayerData.StarTower.tbPassedId, nCondLevelId) then
return false, nCondLevelId, tbCondInfo[2]
end
elseif tbCondInfo[1] == 2 then
local nWorldCalss = PlayerData.Base:GetWorldClass()
local nCondClass = tbCondInfo[2]
if nWorldCalss < nCondClass then
return false, orderedFormat(ConfigTable.GetUIText("Agent_Cond_WorldClass"), nCondClass), tbCondInfo[2]
end
elseif tbCondInfo[1] == 3 then
local nCondLevelId = tbCondInfo[2]
if not PlayerData.Avg:IsStoryReaded(nCondLevelId) then
local config = ConfigTable.GetData("Story", nCondLevelId)
return false, orderedFormat(ConfigTable.GetUIText("Plot_Limit_MainLine") or "", config.Index), tbCondInfo[2]
end
end
end
end
return true
end
local GetCharOrBuildState = function(id)
if tbAllDispatchData ~= nil then
for k, v in pairs(tbAllDispatchData) do
if v.Data.CharIds ~= nil then
for _, charid in ipairs(v.Data.CharIds) do
if charid == id then
return AllEnum.DispatchState.Accepting
end
end
end
if v.Data.BuildId == id then
return AllEnum.DispatchState.Accepting
end
end
end
return AllEnum.DispatchState.CanAccept
end
local GetSameTagCount = function(dispatchId, bBuild, nId, bExtra)
local data = ConfigTable.GetData("Agent", dispatchId)
local charTagList = {}
local count = 0
if bBuild then
local _mapAllBuild = {}
local GetDataCallback = function(tbBuildData, mapAllBuild)
_mapAllBuild = mapAllBuild
end
PlayerData.Build:GetAllBuildBriefData(GetDataCallback)
local buildData = _mapAllBuild[nId]
for i = 1, 3 do
if buildData.tbChar[i] ~= nil then
local mapCharDescCfg = ConfigTable.GetData("CharacterDes", buildData.tbChar[i].nTid)
for _, v in ipairs(mapCharDescCfg.Tag) do
table.insert(charTagList, v)
end
end
end
else
local mapCharDescCfg = ConfigTable.GetData("CharacterDes", nId)
for _, v in ipairs(mapCharDescCfg.Tag) do
table.insert(charTagList, v)
end
end
local tagList = bExtra and data.ExtraTags or data.Tags
for k, v in ipairs(tagList) do
if 0 < table.indexof(charTagList, v) then
table.removebyvalue(charTagList, v)
count = count + 1
end
end
return count
end
local IsSpecialDispatch = function(dispatchId)
if table.indexof(tbWeeklyDispatchDataIds, dispatchId) > 0 then
return true
end
if table.indexof(tbCompletedDailyDispatchIds, dispatchId) > 0 then
return true
end
if table.indexof(tbCompletedWeeklyDispatchIds, dispatchId) > 0 then
return true
end
return false
end
local IsBuildDispatching = function(buildId)
for k, v in pairs(tbAllDispatchData) do
if v.Data.BuildId == buildId then
return true
end
end
return false
end
local RandomSpecialPerformance = function(charIds)
local tbEligible = {}
local totalWeight = 0
local foreachAgentSpecialPerformance = function(mapData)
if #mapData.CharId <= #charIds then
local hasAll = true
for k, v in ipairs(mapData.CharId) do
if table.indexof(charIds, v) <= 0 then
hasAll = false
break
end
end
if hasAll then
totalWeight = totalWeight + mapData.Weight
table.insert(tbEligible, {
Id = mapData.Id,
Weight = totalWeight
})
end
end
end
ForEachTableLine(ConfigTable.Get("AgentSpecialPerformance"), foreachAgentSpecialPerformance)
local randomWeight = math.random(1, totalWeight)
for k, v in ipairs(tbEligible) do
if randomWeight <= v.Weight then
return v.Id
end
end
if 0 < #tbEligible then
return tbEligible[1].Id
end
return -1
end
local CheckReddot = function()
for k, v in pairs(tbAllDispatchData) do
local dispatchData = ConfigTable.GetData("Agent", k)
local bComplete = v.Data.ProcessTime * 60 + v.Data.StartTime <= CS.ClientManager.Instance.serverTimeStamp
RedDotManager.SetValid(RedDotDefine.Dispatch_Reward, {
dispatchData.Tab,
dispatchData.Id
}, bComplete)
end
end
local GetCurrentYearInfo = function(time_s)
local day = os.date("%d", time_s)
local weekIndex = os.date("%W", time_s)
local month = os.date("%m", time_s)
local yearNum = os.date("%Y", time_s)
return {
year = yearNum,
month = month,
weekIdx = weekIndex,
day = day
}
end
local IsSameDay = function(stampA, stampB, resetHour)
resetHour = resetHour or 5
local resetSeconds = resetHour * 3600
stampA = stampA - resetSeconds
stampB = stampB - resetSeconds
local dateA = GetCurrentYearInfo(stampA)
local dateB = GetCurrentYearInfo(stampB)
return dateA.day == dateB.day and dateA.month == dateB.month and dateA.year == dateB.year
end
local IsSameWeek = function(stampA, stampB, resetHour)
resetHour = resetHour or 5
local resetSeconds = resetHour * 3600
stampA = stampA - resetSeconds
stampB = stampB - resetSeconds
local dateA = GetCurrentYearInfo(stampA)
local dateB = GetCurrentYearInfo(stampB)
return dateA.weekIdx == dateB.weekIdx and dateA.year == dateB.year
end
local ReqApplyAgent = function(agentList, agentData, callback)
local count = PlayerData.Dispatch.GetAccpectingDispatchCount()
local maxCount = tonumber(ConfigTable.GetConfigValue("AgentMaximumQuantity"))
if count >= maxCount then
local agentData = agentList[1]
if agentData ~= nil then
local configData = ConfigTable.GetData("Agent", agentData.Id)
if configData.Tab ~= GameEnum.AgentType.Emergency then
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("Agent_Max_Accepted"))
return
end
else
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("Agent_Max_Accepted"))
return
end
end
local func_callback = function(_, msgData)
for k, v in ipairs(msgData.Infos) do
if agentData[v.Id] ~= nil then
local agentInfo = {
Id = v.Id,
StartTime = v.BeginTime,
CharIds = agentData[v.Id].CharIds,
BuildId = agentData[v.Id].BuildId,
ProcessTime = agentData[v.Id].ProcessTime
}
tbAllDispatchData[v.Id] = {
Data = agentInfo,
State = AllEnum.DispatchState.Accepting
}
end
if callback ~= nil then
callback()
end
end
EventManager.Hit(EventId.DispatchRefreshPanel, AllEnum.DispatchState.Accepting)
bReqApplyAgent = false
end
local mapData = {Apply = agentList}
if bReqApplyAgent ~= true then
HttpNetHandler.SendMsg(NetMsgId.Id.agent_apply_req, mapData, nil, func_callback)
end
bReqApplyAgent = true
end
local ResetReqLock = function()
bReqApplyAgent = false
end
local ReqGiveUpAgent = function(dispatchId, callback)
local mapData = {Id = dispatchId}
local func_callback = function(msgData)
if tbAllDispatchData[dispatchId] ~= nil then
local dispatchData = tbAllDispatchData[dispatchId]
local dispathcConfig = ConfigTable.GetData("Agent", dispatchId)
local nTime = CS.ClientManager.Instance.serverTimeStamp
if dispathcConfig.RefreshType == GameEnum.AgentRefreshType.NonRefresh and IsSameWeek(dispatchData.Data.StartTime, nTime, 5) == false and table.indexof(tbWeeklyDispatchDataIds, dispatchId) > 0 then
table.removebyvalue(tbWeeklyDispatchDataIds, dispatchId)
end
tbAllDispatchData[dispatchId] = nil
end
if callback ~= nil then
callback()
end
EventManager.Hit(EventId.DispatchRefreshPanel)
end
HttpNetHandler.SendMsg(NetMsgId.Id.agent_give_up_req, mapData, nil, func_callback)
end
local ReqReceiveReward = function(dispatchId, callback)
local mapData = {Id = dispatchId}
local func_callback = function(_, msgData)
local data = {}
local tbSpecialPerformanceId = {}
local nTime = CS.ClientManager.Instance.serverTimeStamp
for k, v in ipairs(msgData.RewardShows) do
local dispatchData = ConfigTable.GetData("Agent", v.Id)
local time = tbAllDispatchData[v.Id] ~= nil and tbAllDispatchData[v.Id].Data.ProcessTime or 0
local Item = {}
for _, item in ipairs(v.Rewards) do
if Item[item.Tid] ~= nil then
Item[item.Tid].nCount = Item[item.Tid].nCount + item.Qty
else
Item[item.Tid] = {
nId = item.Tid,
nCount = item.Qty,
bBonus = false
}
end
end
for _, item in ipairs(v.Bonus) do
if Item[item.Tid] ~= nil then
Item[item.Tid].nCount = Item[item.Tid].nCount + item.Qty
else
Item[item.Tid] = {
nId = item.Tid,
nCount = item.Qty,
bBonus = true
}
end
end
local rewardItem = {}
for k, v in pairs(Item) do
table.insert(rewardItem, v)
end
table.insert(data, {
Id = v.Id,
CharIds = tbAllDispatchData[v.Id].Data.CharIds,
BuildId = tbAllDispatchData[v.Id].Data.BuildId,
Name = dispatchData.Name,
Time = time,
Item = rewardItem
})
if 0 < table.indexof(tbWeeklyDispatchDataIds, v.Id) then
table.removebyvalue(tbWeeklyDispatchDataIds, v.Id)
table.insert(tbCompletedWeeklyDispatchIds, v.Id)
end
RedDotManager.SetValid(RedDotDefine.Dispatch_Reward, {
dispatchData.Tab,
dispatchData.Id
}, false)
if dispatchData.RefreshType == GameEnum.AgentRefreshType.Daily and IsSameDay(tbAllDispatchData[v.Id].Data.StartTime, nTime, 5) then
printLog("Dispatch:" .. "每日任务完成")
table.insert(tbCompletedDailyDispatchIds, v.Id)
RedDotManager.UnRegisterNode(RedDotDefine.Dispatch_Reward, {
dispatchData.Tab,
dispatchData.Id
})
end
if 0 < #v.SpecialRewards then
for _, item in ipairs(v.SpecialRewards) do
local performanceId = PlayerData.Dispatch.RandomSpecialPerformance(tbAllDispatchData[v.Id].Data.CharIds)
if 0 < performanceId then
table.insert(tbSpecialPerformanceId, {
itemId = item.Tid,
nCount = item.Qty,
performanceId = performanceId
})
end
end
end
if tbAllDispatchData[v.Id] ~= nil then
tbAllDispatchData[v.Id] = nil
end
end
EventManager.Hit(EventId.DispatchReceiveReward, data, tbSpecialPerformanceId)
if callback ~= nil then
callback()
end
EventManager.Hit(EventId.DispatchRefreshPanel)
end
HttpNetHandler.SendMsg(NetMsgId.Id.agent_reward_receive_req, mapData, nil, func_callback)
end
local RefreshWeeklyDispatchs = function(msgData)
if msgData ~= nil then
tbWeeklyDispatchDataIds = msgData
end
for i = #tbCompletedWeeklyDispatchIds, 1, -1 do
if table.indexof(tbWeeklyDispatchDataIds, tbCompletedWeeklyDispatchIds[i]) > 0 then
table.remove(tbCompletedWeeklyDispatchIds, i)
end
end
end
local RefreshAgentInfos = function(data)
for k, v in pairs(data.Infos) do
local state = AllEnum.DispatchState.Accepting
if v.ProcessTime * 60 + v.StartTime <= CS.ClientManager.Instance.serverTimeStamp then
state = AllEnum.DispatchState.Complete
end
tbAllDispatchData[v.Id] = {Data = v, State = state}
end
end
local DispatchData = {
Init = Init,
UnInit = UnInit,
CacheDispatchData = CacheDispatchData,
GetAccpectingDispatchCount = GetAccpectingDispatchCount,
GetAllDispatchingData = GetAllDispatchingData,
GetDispatchState = GetDispatchState,
GetAllTabData = GetAllTabData,
CheckTabUnlock = CheckTabUnlock,
GetAllDispatchItemList = GetAllDispatchItemList,
GetDispatchCharList = GetDispatchCharList,
GetDispatchBuildData = GetDispatchBuildData,
CheckDispatchItemUnlock = CheckDispatchItemUnlock,
GetCharOrBuildState = GetCharOrBuildState,
GetSameTagCount = GetSameTagCount,
IsSpecialDispatch = IsSpecialDispatch,
ReqApplyAgent = ReqApplyAgent,
ReqGiveUpAgent = ReqGiveUpAgent,
ReqReceiveReward = ReqReceiveReward,
RefreshWeeklyDispatchs = RefreshWeeklyDispatchs,
RandomSpecialPerformance = RandomSpecialPerformance,
IsBuildDispatching = IsBuildDispatching,
CheckReddot = CheckReddot,
IsSameDay = IsSameDay,
IsSameWeek = IsSameWeek,
ResetReqLock = ResetReqLock,
RefreshAgentInfos = RefreshAgentInfos
}
return DispatchData
@@ -0,0 +1,150 @@
local ConfigData = require("GameCore.Data.ConfigData")
local AttrConfig = require("GameCore.Common.AttrConfig")
local EquipmentData = class("EquipmentData")
function EquipmentData:ctor(mapEquipment, nCharId, nGemId)
self:Clear()
self:InitEquip(mapEquipment, nCharId, nGemId)
end
function EquipmentData:Clear()
self.nCharId = nil
self.nGemId = nil
self.sName = nil
self.sIcon = nil
self.sDesc = nil
self.nType = nil
self.nGenerateId = nil
self.nRefreshId = nil
self.bLock = nil
self.tbAffix = nil
self.tbAlterAffix = nil
self.tbPotentialAffix = nil
self.tbSkillAffix = nil
self.tbRandomAttr = nil
self.tbEffect = nil
end
function EquipmentData:InitEquip(mapEquipment, nCharId, nGemId)
self.nCharId = nCharId
self.nGemId = nGemId
local equipmentCfg = ConfigTable.GetData("CharGem", nGemId)
if nil == equipmentCfg then
printError(string.format("获取装备表配置失败!!!id = [%s]", nGemId))
return
end
self:ParseConfigData(equipmentCfg)
self:ParseServerData(mapEquipment)
end
function EquipmentData:ParseConfigData(equipmentCfg)
self.sName = equipmentCfg.Title
self.sIcon = equipmentCfg.Icon
self.sDesc = equipmentCfg.Desc
self.nType = equipmentCfg.Type
self.nGenerateId = equipmentCfg.GenerateCostTid
self.nRefreshId = equipmentCfg.RefreshCostTid
self.tbRandomAttr = {}
end
function EquipmentData:ParseServerData(mapEquipment)
self.bLock = mapEquipment.Lock
self:UpdateAffix(mapEquipment.Attributes)
self:UpdateAlterAffix(mapEquipment.AlterAttributes)
end
function EquipmentData:UpdateAffix(tbAttributes)
self.tbAffix = tbAttributes
self:UpdateRandomAttr(self.tbAffix)
end
function EquipmentData:UpdateAlterAffix(tbAttributes)
self.tbAlterAffix = tbAttributes
end
function EquipmentData:ReplaceRandomAttr()
if not self.tbAlterAffix or next(self.tbAlterAffix) == nil then
return
end
self.tbAffix = clone(self.tbAlterAffix)
for k, _ in ipairs(self.tbAlterAffix) do
self.tbAlterAffix[k] = 0
end
self:UpdateRandomAttr(self.tbAffix)
end
function EquipmentData:UpdateRandomAttr(mapAttrs)
self.tbPotentialAffix = {}
self.tbSkillAffix = {}
self.tbRandomAttr = {}
self.tbEffect = {}
for _, v in ipairs(mapAttrs) do
if 0 < v then
local mapCfg = ConfigTable.GetData("CharGemAttrValue", v)
if mapCfg then
if mapCfg.AttrType == GameEnum.CharGemEffectType.Potential then
table.insert(self.tbPotentialAffix, mapCfg)
elseif mapCfg.AttrType == GameEnum.CharGemEffectType.SkillLevel then
table.insert(self.tbSkillAffix, mapCfg)
elseif mapCfg.AttrType == GameEnum.effectType.ATTR_FIX or mapCfg.AttrType == GameEnum.effectType.PLAYER_ATTR_FIX then
if mapCfg.AttrTypeSecondSubtype == GameEnum.parameterType.BASE_VALUE then
local value = tonumber(mapCfg.Value) or 0
local mapData = {
AttrId = v,
Value = value,
CfgValue = value / ConfigData.IntFloatPrecision
}
table.insert(self.tbRandomAttr, mapData)
else
table.insert(self.tbEffect, mapCfg.EffectId)
end
end
end
end
end
end
function EquipmentData:UpdateLockState(bLock)
self.bLock = bLock
end
function EquipmentData:GetEnhancedPotential()
local tbPotential = {}
for _, v in ipairs(self.tbPotentialAffix) do
local nPotentialId = UTILS.GetPotentialId(self.nCharId, v.AttrTypeFirstSubtype)
if not tbPotential[nPotentialId] then
tbPotential[nPotentialId] = 0
end
tbPotential[nPotentialId] = tbPotential[nPotentialId] + tonumber(v.Value)
end
return tbPotential
end
function EquipmentData:GetEnhancedSkill()
local tbSkillId = PlayerData.Char:GetSkillIds(self.nCharId)
local tbSkill = {}
for _, v in ipairs(self.tbSkillAffix) do
local nSkillId = tbSkillId[v.AttrTypeFirstSubtype]
if not tbSkill[nSkillId] then
tbSkill[nSkillId] = 0
end
tbSkill[nSkillId] = tbSkill[nSkillId] + tonumber(v.Value)
end
return tbSkill
end
function EquipmentData:GetRandomAttr()
return self.tbRandomAttr
end
function EquipmentData:GetEffect()
return self.tbEffect
end
function EquipmentData:CheckAlterEmpty()
if not self.tbAlterAffix or next(self.tbAlterAffix) == nil then
return true
end
for _, v in pairs(self.tbAlterAffix) do
if v == 0 then
return true
end
end
return false
end
function EquipmentData:GetTypeDesc()
local sLanguage = AllEnum.EquipmentType[self.nType].Language
return ConfigTable.GetUIText(sLanguage)
end
function EquipmentData:GetTypeIcon()
return AllEnum.EquipmentType[self.nType].Icon
end
function EquipmentData:GetEffectDescId(attrSybType1, attrSybType2)
return GameEnum.effectType.ATTR_FIX * 10000 + attrSybType1 * 10 + attrSybType2
end
return EquipmentData
+254
View File
@@ -0,0 +1,254 @@
local FilterData = class("FilterData")
local LocalData = require("GameCore.Data.LocalData")
function FilterData:ctor()
end
function FilterData:Init()
self.tbCacheFilter = {}
self.tbFilter = {}
for fKey, v in pairs(AllEnum.ChooseOptionCfg) do
self.tbFilter[fKey] = {}
for sKey, _ in pairs(v.items) do
self.tbFilter[fKey][sKey] = false
end
end
self.nFormationCharSrotType = AllEnum.SortType.Level
self.bFormationCharOrder = false
self.nFormationDiscSrotType = AllEnum.SortType.Level
self.bFormationDiscOrder = false
end
function FilterData:Reset(tbOption)
if tbOption == nil then
return
end
self.tbCacheFilter = {}
for fKey, _ in pairs(self.tbFilter) do
if table.indexof(tbOption, fKey) > 0 then
for sKey, _ in pairs(self.tbFilter[fKey]) do
self.tbFilter[fKey][sKey] = false
end
end
end
end
function FilterData:IsDirty(optionType)
if optionType == AllEnum.OptionType.Char then
local dirty = self:_IsDirty(AllEnum.ChooseOption.Char_Element)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Char_Rarity)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Char_PowerStyle)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Char_TacticalStyle)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Char_AffiliatedForces)
return dirty
elseif optionType == AllEnum.OptionType.Disc then
local dirty = self:_IsDirty(AllEnum.ChooseOption.Star_Element)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Star_Rarity)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Star_Note)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Star_Tag)
return dirty
elseif optionType == AllEnum.OptionType.Equipment then
local dirty = self:_IsDirty(AllEnum.ChooseOption.Equip_Rarity)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_Type)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_Theme_Circle)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_Theme_Square)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_Theme_Pentagon)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_PowerStyle)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_TacticalStyle)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_AffiliatedForces)
dirty = dirty or self:_IsDirty(AllEnum.ChooseOption.Equip_Match)
return dirty
end
return false
end
function FilterData:_IsDirty(fKey)
for _, result in pairs(self.tbFilter[fKey]) do
if result == true then
return true
end
end
return false
end
function FilterData:CheckFilterByChar(charId)
local charData = ConfigTable.GetData_Character(charId)
local mapCharDescCfg = ConfigTable.GetData("CharacterDes", charId)
local isFilter = true
if mapCharDescCfg == nil or charData == nil then
return isFilter
end
isFilter = self:_GetFilterByKey(AllEnum.ChooseOption.Char_Element, charData.EET)
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Char_Rarity, charData.Grade)
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Char_PowerStyle, charData.Class)
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Char_TacticalStyle, mapCharDescCfg.Tag[2])
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Char_AffiliatedForces, mapCharDescCfg.Tag[3])
return isFilter
end
function FilterData:CheckFilterByDisc(discId)
local discCfg = ConfigTable.GetData("Disc", discId)
local discData = PlayerData.Disc:GetDiscById(discId)
local isFilter = true
isFilter = self:_GetFilterByKey(AllEnum.ChooseOption.Star_Element, discData.nEET)
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Star_Rarity, discData.nRarity)
local isFilter2 = true
local A = {}
for _, noteId in ipairs(discData.tbShowNote or {}) do
A[noteId] = true
end
for sKey, v in pairs(self.tbFilter[AllEnum.ChooseOption.Star_Note]) do
if v == true and A[sKey] == nil then
isFilter2 = false
end
end
isFilter = isFilter and isFilter2
local isFilter3 = true
local B = {}
for _, tagId in pairs(discData.tbTag or {}) do
B[tagId] = true
end
for sKey, v in pairs(self.tbFilter[AllEnum.ChooseOption.Star_Tag]) do
if v == true and B[sKey] == nil then
isFilter3 = false
end
end
isFilter = isFilter and isFilter3
return isFilter
end
function FilterData:CheckFilerByEquip(equipId, nCharId)
local equipmentData = PlayerData.Equipment:GetEquipmentById(equipId)
local isFilter = true
local nEquipType = equipmentData:GetType()
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Equip_Rarity, equipmentData:GetRarity())
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Equip_Type, nEquipType)
local tbBaseAttrDescId = equipmentData:GetBaseAttrDescId()
local tbSelectAttr = {}
local tbCurAttr = {}
if nEquipType == GameEnum.equipmentType.Square then
tbCurAttr = self.tbFilter[AllEnum.ChooseOption.Equip_Theme_Square]
elseif nEquipType == GameEnum.equipmentType.Circle then
tbCurAttr = self.tbFilter[AllEnum.ChooseOption.Equip_Theme_Circle]
elseif nEquipType == GameEnum.equipmentType.Pentagon then
tbCurAttr = self.tbFilter[AllEnum.ChooseOption.Equip_Theme_Pentagon]
end
for nKey, v in pairs(tbCurAttr) do
if v then
tbSelectAttr[nKey] = 1
end
end
local bAttr = true
if next(tbSelectAttr) ~= nil then
bAttr = false
for _, id in ipairs(tbBaseAttrDescId) do
if tbSelectAttr[id] ~= nil then
bAttr = true
break
end
end
isFilter = isFilter and bAttr
end
local tbTag = equipmentData:GetTag()
local tbSelectTag = {}
for nKey, v in pairs(self.tbFilter[AllEnum.ChooseOption.Equip_PowerStyle]) do
if v then
tbSelectTag[nKey] = 1
end
end
local bTag = true
if next(tbSelectTag) ~= nil then
bTag = false
for _, tag in ipairs(tbTag) do
if tbSelectTag[tag] ~= nil then
bTag = true
break
end
end
isFilter = isFilter and bTag
end
tbSelectTag = {}
for nKey, v in pairs(self.tbFilter[AllEnum.ChooseOption.Equip_TacticalStyle]) do
if v then
tbSelectTag[nKey] = 1
end
end
if next(tbSelectTag) ~= nil then
bTag = false
for _, tag in ipairs(tbTag) do
if tbSelectTag[tag] ~= nil then
bTag = true
break
end
end
isFilter = isFilter and bTag
end
tbSelectTag = {}
for nKey, v in pairs(self.tbFilter[AllEnum.ChooseOption.Equip_AffiliatedForces]) do
if v then
tbSelectTag[nKey] = 1
end
end
if next(tbSelectTag) ~= nil then
bTag = false
for _, tag in ipairs(tbTag) do
if tbSelectTag[tag] ~= nil then
bTag = true
break
end
end
isFilter = isFilter and bTag
end
if nCharId ~= nil then
local nMatchCount = equipmentData:GetTagMatchCount(nCharId)
isFilter = isFilter and self:_GetFilterByKey(AllEnum.ChooseOption.Equip_Match, nMatchCount)
end
return isFilter
end
function FilterData:_GetFilterByKey(fKey, sKey)
local isAllFalse = false
for optionKey, _ in pairs(self.tbFilter[fKey]) do
isAllFalse = isAllFalse or self.tbFilter[fKey][optionKey]
end
if not isAllFalse then
return true
end
return self.tbFilter[fKey][sKey]
end
function FilterData:GetFilterByKey(fKey, sKey)
return self.tbFilter[fKey][sKey]
end
function FilterData:SetCacheFilterByKey(fKey, sKey, flag)
if self.tbCacheFilter[fKey] == nil then
self.tbCacheFilter[fKey] = {}
end
self.tbCacheFilter[fKey][sKey] = flag
end
function FilterData:SyncFilterByCache()
for fKey, v in pairs(self.tbCacheFilter) do
for sKey, vv in pairs(v) do
self.tbFilter[fKey][sKey] = vv
end
end
end
function FilterData:GetCacheFilterByKey(fKey, sKey)
if nil ~= self.tbCacheFilter[fKey] and nil ~= self.tbCacheFilter[fKey][sKey] then
return self.tbCacheFilter[fKey][sKey], true
end
return self:GetFilterByKey(fKey, sKey), false
end
function FilterData:CacheCharSort(nType, bOrder)
self.nFormationCharSrotType = nType
self.bFormationCharOrder = bOrder
LocalData.SetPlayerLocalData("FormationCharSrotType", self.nFormationCharSrotType)
LocalData.SetPlayerLocalData("FormationCharOrder", self.bFormationCharOrder)
end
function FilterData:CacheDiscSort(nType, bOrder)
self.nFormationDiscSrotType = nType
self.bFormationDiscOrder = bOrder
LocalData.SetPlayerLocalData("FormationDiscSrotType", self.nFormationDiscSrotType)
LocalData.SetPlayerLocalData("FormationDiscOrder", self.bFormationDiscOrder)
end
function FilterData:InitSortData()
self.nFormationCharSrotType = AllEnum.SortType.Level
self.bFormationCharOrder = false
self.nFormationDiscSrotType = AllEnum.SortType.Level
self.bFormationDiscOrder = false
self.nFormationCharSrotType = LocalData.GetPlayerLocalData("FormationCharSrotType") or AllEnum.SortType.Level
self.bFormationCharOrder = LocalData.GetPlayerLocalData("FormationCharOrder") or false
self.nFormationDiscSrotType = LocalData.GetPlayerLocalData("FormationDiscSrotType") or AllEnum.SortType.Level
self.bFormationDiscOrder = LocalData.GetPlayerLocalData("FormationDiscOrder") or false
end
return FilterData
@@ -0,0 +1,335 @@
local GameAnnouncementData = class("GameAnnouncementData")
local LocalData = require("GameCore.Data.LocalData")
local AnnServerChannel_CN = {
[1] = "cn_android_official",
[2] = "cn_ios_official",
[4] = "cn_android_bilibili",
[8] = "cn_harmony_official",
[16] = "cn_pc_official",
[32] = "cn_pc_bilibili"
}
local AnnServerChannel_JP = {
[1] = "jp_android_official",
[2] = "jp_ios_official",
[4] = "jp_android_onestore",
[8] = "jp_pc_official"
}
local AnnServerChannel_US = {
[1] = "us_android_official",
[2] = "us_ios_official",
[4] = "us_android_onestore",
[8] = "us_pc_official"
}
local AnnServerChannel_KR = {
[1] = "kr_android_official",
[2] = "kr_ios_official",
[4] = "kr_android_onestore",
[8] = "kr_pc_official"
}
local AnnServerChannel_TW = {
[1] = "tw_android_official",
[2] = "tw_ios_official",
[4] = "tw_android_onestore",
[8] = "tw_pc_official"
}
local htmlConfigId = 1
function GameAnnouncementData:ctor()
end
function GameAnnouncementData:Init()
self.tbLastAnnList = LocalData.GetLocalData("Announcement_", "LastList") or {}
self.tbCurAnnList = {}
EventManager.Add("AllAnnDataRequestDone", self, self.AllAnnResponse)
EventManager.Add("AnnContentRequestDone", self, self.AnnContentResponse)
EventManager.Add("AllAnnDataRequestFail", self, self.AllAnnResponse_Fail)
end
function GameAnnouncementData:ClearCache()
self.tbTypeList = {}
self.tbAnnBaseInfo = {}
self.tbAnnContentCache = {}
end
function GameAnnouncementData:SetAutoOpen(autoOpen)
LocalData.SetLocalData("Announcement_", "AutoOpen", autoOpen)
end
function GameAnnouncementData:GetAutoOpen()
local bAutoOpen = true
if LocalData.GetLocalData("Announcement_", "AutoOpen") == nil then
bAutoOpen = true
else
bAutoOpen = LocalData.GetLocalData("Announcement_", "AutoOpen")
end
local nTime = CS.ClientManager.Instance.serverTimeStamp
local nLastTime = LocalData.GetLocalData("Announcement_", "Time") or 0
if nTime > nLastTime then
if not self:IsSameWeek(nTime, nLastTime) then
bAutoOpen = true
end
LocalData.SetLocalData("Announcement_", "Time", nTime)
else
end
return bAutoOpen
end
function GameAnnouncementData:GetTodayisOpen()
local bTodayIsOpen = false
local nTime = CS.ClientManager.Instance.serverTimeStamp
local nLastOpenTime = LocalData.GetLocalData("Announcement_", "LastOpenTime") or 0
if self:IsSameDay(nTime, nLastOpenTime) then
if LocalData.GetLocalData("Announcement_", "TodayOpened") == nil then
bTodayIsOpen = false
else
bTodayIsOpen = LocalData.GetLocalData("Announcement_", "TodayOpened")
end
else
bTodayIsOpen = false
end
return bTodayIsOpen
end
function GameAnnouncementData:GetIsNeedAutoOpen()
local bHasNew = self:CheckHasNewAnn()
if bHasNew then
return true
end
return self:GetAutoOpen() and not self:GetTodayisOpen()
end
function GameAnnouncementData:GetAnnInfoByType(nType)
if self.tbTypeList[nType] == nil then
return nil
end
return self.tbTypeList[nType]
end
function GameAnnouncementData:HasAnnouncement()
if self.tbTypeList == {} or self.tbTypeList == nil then
return false
end
if #self.tbTypeList > 4 or #self.tbTypeList < 2 then
return false
end
return true
end
function GameAnnouncementData:GetHtmlData(nId)
if self.tbAnnContentCache[nId] ~= nil then
return self.tbAnnContentCache[nId]
else
self:SendAnnContentQuest(nId)
return nil
end
end
function GameAnnouncementData:SetAnnRead(nType, nId)
if nId == 0 then
local list = self.tbTypeList[nType]
if list ~= nil then
for _, v in pairs(list) do
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {
nType,
v.Id
}, false)
LocalData.SetLocalData("AnnouncementIsRead", tostring(v.Id), true)
end
end
else
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {nType, nId}, false)
LocalData.SetLocalData("AnnouncementIsRead", tostring(nId), true)
end
end
function GameAnnouncementData:UpdateLastAnnData()
self.tbLastAnnList = self.tbCurAnnList
LocalData.SetLocalData("Announcement_", "LastList", self.tbLastAnnList)
LocalData.SetLocalData("Announcement_", "TodayOpened", true)
local nTime = CS.ClientManager.Instance.serverTimeStamp
LocalData.SetLocalData("Announcement_", "LastOpenTime", nTime)
end
function GameAnnouncementData:CheckHasNewAnn()
if self.tbCurAnnList == nil then
return false
end
for _, value in pairs(self.tbCurAnnList) do
if table.keyof(self.tbLastAnnList, value) == nil then
return true
end
end
return false
end
function GameAnnouncementData:AllAnnResponse(listData)
self.tbAnnBaseInfo = {}
self.tbTypeList = {}
self.tbAnnContentCache = {}
self.tbCurAnnList = {}
for i = 0, listData.System.Length - 1 do
local v = listData.System[i]
if UTILS.CheckChannelList(v.Channel) and v.ContentUrl ~= "" then
self.tbAnnBaseInfo[v.Id] = {
info = v,
nType = AllEnum.AnnType.SystemAnn
}
if self.tbTypeList[AllEnum.AnnType.SystemAnn] == nil then
local list = {}
table.insert(list, v)
self.tbTypeList[AllEnum.AnnType.SystemAnn] = list
else
table.insert(self.tbTypeList[AllEnum.AnnType.SystemAnn], v)
end
local bIsRead = false
if LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id)) == nil then
bIsRead = false
else
bIsRead = LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id))
end
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {
AllEnum.AnnType.SystemAnn,
v.Id
}, not bIsRead)
table.insert(self.tbCurAnnList, v.Id)
end
end
for i = 0, listData.Activity.Length - 1 do
local v = listData.Activity[i]
if UTILS.CheckChannelList(v.Channel) and v.ContentUrl ~= "" then
self.tbAnnBaseInfo[v.Id] = {
info = v,
nType = AllEnum.AnnType.ActivityAnn
}
if self.tbTypeList[AllEnum.AnnType.ActivityAnn] == nil then
local list = {}
table.insert(list, v)
self.tbTypeList[AllEnum.AnnType.ActivityAnn] = list
else
table.insert(self.tbTypeList[AllEnum.AnnType.ActivityAnn], v)
end
local bIsRead = false
if LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id)) == nil then
bIsRead = false
else
bIsRead = LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id))
end
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {
AllEnum.AnnType.ActivityAnn,
v.Id
}, not bIsRead)
end
table.insert(self.tbCurAnnList, v.Id)
end
for i = 0, listData.Other1.Length - 1 do
local v = listData.Other1[i]
if UTILS.CheckChannelList(v.Channel) and v.ContentUrl ~= "" then
self.tbAnnBaseInfo[v.Id] = {
info = v,
nType = AllEnum.AnnType.Other1
}
if self.tbTypeList[AllEnum.AnnType.Other1] == nil then
local list = {}
table.insert(list, v)
self.tbTypeList[AllEnum.AnnType.Other1] = list
else
table.insert(self.tbTypeList[AllEnum.AnnType.Other1], v)
end
local bIsRead = false
if LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id)) == nil then
bIsRead = false
else
bIsRead = LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id))
end
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {
AllEnum.AnnType.Other1,
v.Id
}, not bIsRead)
end
table.insert(self.tbCurAnnList, v.Id)
end
for i = 0, listData.Other2.Length - 1 do
local v = listData.Other2[i]
if UTILS.CheckChannelList(v.Channel) and v.ContentUrl ~= "" then
self.tbAnnBaseInfo[v.Id] = {
info = v,
nType = AllEnum.AnnType.Other2
}
if self.tbTypeList[AllEnum.AnnType.Other2] == nil then
local list = {}
table.insert(list, v)
self.tbTypeList[AllEnum.AnnType.Other2] = list
else
table.insert(self.tbTypeList[AllEnum.AnnType.Other2], v)
end
local bIsRead = false
if LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id)) == nil then
bIsRead = false
else
bIsRead = LocalData.GetLocalData("AnnouncementIsRead", tostring(v.Id))
end
RedDotManager.SetValid(RedDotDefine.Announcement_Content, {
AllEnum.AnnType.Other2,
v.Id
}, not bIsRead)
end
table.insert(self.tbCurAnnList, v.Id)
end
if self.requestAllDataCallback then
self.requestAllDataCallback()
self.requestAllDataCallback = nil
end
self.bLoadAllData = false
EventManager.Hit("AnnAllDataReady")
end
function GameAnnouncementData:AllAnnResponse_Fail()
if self.requestAllDataCallback then
self.requestAllDataCallback()
self.requestAllDataCallback = nil
end
self.bLoadAllData = false
end
function GameAnnouncementData:AnnContentResponse(nId, content)
self.tbAnnContentCache[nId] = content
EventManager.Hit("AnnContentReady", nId)
end
function GameAnnouncementData:SendAllDataQuest(callback_success)
if self.bLoadAllData then
return
end
self.bLoadAllData = true
self.requestAllDataCallback = callback_success
CS.HttpNetworkManager:RequestAllAnnData()
end
function GameAnnouncementData:SendAnnContentQuest(nId)
local annInfo = self.tbAnnBaseInfo[nId]
CS.HttpNetworkManager.RequestAnnContent(nId, annInfo.info.ContentUrl)
end
function GameAnnouncementData:GetHtmlFrame()
local htmlFrame = ConfigTable.GetData("HtmlConfig", htmlConfigId)
if htmlFrame ~= nil then
return htmlFrame.HtmlFrame
end
return ""
end
local GetCurrentYearInfo = function(time_s)
local day = os.date("%d", time_s)
local weekIndex = os.date("%W", time_s)
local month = os.date("%m", time_s)
local yearNum = os.date("%Y", time_s)
return {
year = yearNum,
month = month,
weekIdx = weekIndex,
day = day
}
end
function GameAnnouncementData:IsSameDay(stampA, stampB, resetHour)
resetHour = resetHour or 5
local resetSeconds = resetHour * 3600
stampA = stampA - resetSeconds
stampB = stampB - resetSeconds
stampA = math.max(stampA, 0)
stampB = math.max(stampB, 0)
local dateA = GetCurrentYearInfo(stampA)
local dateB = GetCurrentYearInfo(stampB)
return dateA.day == dateB.day and dateA.month == dateB.month and dateA.year == dateB.year
end
function GameAnnouncementData:IsSameWeek(stampA, stampB, resetHour)
resetHour = resetHour or 5
local resetSeconds = resetHour * 3600
stampA = stampA - resetSeconds
stampB = stampB - resetSeconds
stampA = math.max(stampA, 0)
stampB = math.max(stampB, 0)
local dateA = GetCurrentYearInfo(stampA)
local dateB = GetCurrentYearInfo(stampB)
return dateA.weekIdx == dateB.weekIdx and dateA.year == dateB.year
end
return GameAnnouncementData
@@ -0,0 +1,25 @@
local HandbookDataBase = class("HandbookDataBase")
function HandbookDataBase:ctor(id, unlock)
self.nId = id
self.tbCfgData = ConfigTable.GetData("Handbook", self.nId)
self.nUnlock = unlock
if nil == self.tbCfgData then
printError("Get handbook data fail!!! id = " .. id)
return
end
self.nIndex = self.tbCfgData.Index
self:Init()
end
function HandbookDataBase:UpdateUnlockState(unlock)
self.nUnlock = unlock
end
function HandbookDataBase:GetType()
return self.tbCfgData.Type
end
function HandbookDataBase:GetId()
return self.nId
end
function HandbookDataBase:CheckUnlock()
return self.nUnlock == 1
end
return HandbookDataBase
@@ -0,0 +1,48 @@
local HandbookDataBase = require("GameCore.Data.DataClass.HandBookData.HandbookDataBase")
local HandbookDiscData = class("HandbookDiscData", HandbookDataBase)
function HandbookDiscData:Init()
self.nDiscId = self:GetId()
end
function HandbookDiscData:GetDiscId()
return self.nDiscId
end
function HandbookDiscData:GetDiscCfgData()
local discCfgData = ConfigTable.GetData("Disc", self.nDiscId)
if nil == discCfgData then
printError("Get disc data fail!!! id = " .. self.nDiscId)
return
end
return discCfgData
end
function HandbookDiscData:GetDiscBg()
local cfgData = self:GetDiscCfgData()
if nil ~= cfgData then
return cfgData.DiscBg .. AllEnum.DiscBgSurfix.Image
end
end
function HandbookDiscData:GetDiscItemCfgData()
local itemCfgData = ConfigTable.GetData_Item(self.nDiscId)
if nil == itemCfgData then
printError("Get item.disc data fail!!! id = " .. self.nDiscId)
return
end
return itemCfgData
end
function HandbookDiscData:GetRarity()
local discItemCfgData = self:GetDiscItemCfgData()
if nil ~= discItemCfgData then
return discItemCfgData.Rarity
end
end
function HandbookDiscData:GetCreateTime()
local createTime = 0
local mapDiscData = PlayerData.Disc:GetDiscById(self.nDiscId)
if nil ~= mapDiscData then
createTime = mapDiscData.nCreateTime or 0
end
return createTime
end
function HandbookDiscData:CheckDiscL2D()
return PlayerData.Disc:CheckDiscL2D(self.nDiscId)
end
return HandbookDiscData
@@ -0,0 +1,27 @@
local HandbookDataBase = require("GameCore.Data.DataClass.HandBookData.HandbookDataBase")
local HandbookPlotData = class("HandbookPlotData", HandbookDataBase)
function HandbookPlotData:Init()
self.nPlotId = self:GetId()
end
function HandbookPlotData:GetPlotId()
return self.nPlotId
end
function HandbookPlotData:GetPlotCfgData()
local plotCfgData = ConfigTable.GetData("MainScreenCG", self.nPlotId)
if nil == plotCfgData then
printError("Get plot data fail!!! id = " .. self.nPlotId)
return
end
return plotCfgData
end
function HandbookPlotData:CheckPlotL2d()
local config = self:GetPlotCfgData()
if config == nil then
return false
end
if config.FullScreenL2D == "" then
return false
end
return true
end
return HandbookPlotData
@@ -0,0 +1,49 @@
local HandbookDataBase = require("GameCore.Data.DataClass.HandBookData.HandbookDataBase")
local HandbookSkinData = class("HandbookSkinData", HandbookDataBase)
function HandbookSkinData:Init()
self.nSkinId = self.tbCfgData.SkinId
self.nCharId = self.tbCfgData.CharId
end
function HandbookSkinData:GetSkinId()
return self.nSkinId
end
function HandbookSkinData:GetSkinCfgData()
local cfgData = ConfigTable.GetData_CharacterSkin(self.nSkinId)
if nil == cfgData then
printError("Get skin cfg fail!!! charId = " .. self.nSkinId)
return
end
return cfgData
end
function HandbookSkinData:GetCharId()
return self.nCharId
end
function HandbookSkinData:GetCharCfgData()
local cfgData = ConfigTable.GetData_Character(self.nCharId)
if nil == cfgData then
printError("Get char cfg fail!!! charId = " .. self.nCharId)
return
end
return cfgData
end
function HandbookSkinData:CheckDefaultSkin()
return self.tbCfgData.Cond == GameEnum.handBookCond.CharacterAcquire or self.tbCfgData.Cond == GameEnum.handBookCond.CharacterSpecific
end
function HandbookSkinData:CheckFavorCG()
local skinData = PlayerData.CharSkin:GetSkinDataBySkinId(self.nSkinId)
if nil ~= skinData then
return skinData:CheckFavorCG()
end
return false
end
function HandbookSkinData:GetCharAffinityLevel()
local nLevel = 0
if self.nCharId ~= 0 then
local mapData = PlayerData.Char:GetCharAffinityData(self.nCharId)
if mapData ~= nil then
nLevel = mapData.Level
end
end
return nLevel
end
return HandbookSkinData
@@ -0,0 +1,27 @@
local HandbookDataBase = require("GameCore.Data.DataClass.HandBookData.HandbookDataBase")
local HandbookStorySetData = class("HandbookStorySetData", HandbookDataBase)
function HandbookStorySetData:Init()
self.nStorySetId = self:GetId()
end
function HandbookStorySetData:GetPlotId()
return self.nStorySetId
end
function HandbookStorySetData:GetPlotCfgData()
local plotCfgData = ConfigTable.GetData("MainScreenCG", self.nStorySetId)
if nil == plotCfgData then
printError("Get plot data fail!!! id = " .. self.nStorySetId)
return
end
return plotCfgData
end
function HandbookStorySetData:CheckPlotL2d()
local config = self:GetPlotCfgData()
if config == nil then
return false
end
if config.FullScreenL2D == "" then
return false
end
return true
end
return HandbookStorySetData
@@ -0,0 +1,357 @@
local ConfigData = require("GameCore.Data.ConfigData")
local AchievementChecker = require("Game.Adventure.AchievementCheck.AchievementChecker")
local PlayerAchievementData = class("PlayerAchievementData")
local Status = {
Unreceived = 1,
Uncompleted = 2,
Received = 3
}
function PlayerAchievementData:Init()
self._tbAchievementList = {}
self._tbTypeCount = {}
self._tbBattleAchievement = {}
self._bNeedUpdate = true
self._tbUnreceivedCountList = {}
self:InitAchievementData()
end
function PlayerAchievementData:InitAchievementData()
local func_ForEach = function(mapCfg)
if not self._tbAchievementList[mapCfg.Type] then
self._tbAchievementList[mapCfg.Type] = {}
end
local bTime = true
if bTime then
self._tbAchievementList[mapCfg.Type][mapCfg.Id] = {
sTime = "",
nId = mapCfg.Id,
nCur = 0,
nMax = mapCfg.AimNumShow,
nStatus = Status.Uncompleted,
bHide = mapCfg.Hide
}
if not self._tbTypeCount[mapCfg.Type] then
self._tbTypeCount[mapCfg.Type] = {
nCompleted = 0,
nTotal = 0,
tbRarity = {
[GameEnum.itemRarity.SSR] = 0,
[GameEnum.itemRarity.SR] = 0,
[GameEnum.itemRarity.R] = 0
}
}
end
if not mapCfg.Hide then
self._tbTypeCount[mapCfg.Type].nTotal = self._tbTypeCount[mapCfg.Type].nTotal + 1
end
end
end
ForEachTableLine(DataTable.Achievement, func_ForEach)
end
function PlayerAchievementData:CacheBattleAchievementData(sByte)
self.tbSpecialBattle = nil
local tbList = {}
local tbSpecialBattle = {}
local tbData = UTILS.ParseByteString(sByte)
local func_ForEach = function(mapLineData)
if mapLineData.CompleteCondClient > 999 then
local bCompleted = UTILS.IsBitSet(tbData, mapLineData.Id)
if not bCompleted then
table.insert(tbSpecialBattle, mapLineData.Id)
end
end
if #mapLineData.LevelType > 1 and table.indexof(mapLineData.LevelType, GameEnum.levelType.All) > 0 then
printError("禁止全部类型和其它关卡类型同时配置!该成就不生效!ID:" .. mapLineData.Id)
elseif mapLineData.CompleteCond == GameEnum.achievementCond.ClientReport and #mapLineData.LevelType > 0 then
local bCompleted = UTILS.IsBitSet(tbData, mapLineData.Id)
if not bCompleted then
table.insert(tbList, mapLineData.Id)
end
end
end
ForEachTableLine(DataTable.Achievement, func_ForEach)
for _, nId in pairs(tbList) do
local mapCfg = ConfigTable.GetData("Achievement", nId)
for _, nLevelType in ipairs(mapCfg.LevelType) do
if not self._tbBattleAchievement[nLevelType] then
self._tbBattleAchievement[nLevelType] = {}
end
table.insert(self._tbBattleAchievement[nLevelType], nId)
end
end
self.tbSpecialBattle = tbSpecialBattle
end
function PlayerAchievementData:SetSpecialBattleAchievement(nLevelType)
local tbCond = {}
if self.tbSpecialBattle == nil then
return
end
for _, nId in ipairs(self.tbSpecialBattle) do
local mapCfg = ConfigTable.GetData("Achievement", nId)
if mapCfg ~= nil and (table.indexof(mapCfg.LevelType, GameEnum.levelType.All) > 0 or table.indexof(mapCfg.LevelType, nLevelType) > 0) and table.indexof(tbCond, mapCfg.CompleteCondClient) < 1 then
table.insert(tbCond, mapCfg.CompleteCondClient)
end
end
safe_call_cs_func(CS.AdventureModuleHelper.SetUnFinishedAchievementInfo, tbCond)
end
function PlayerAchievementData:CacheAchievementData(mapMsgData)
self._tbUnreceivedCountList = {}
for _, mapAchievement in pairs(mapMsgData.List) do
local mapCfg = ConfigTable.GetData("Achievement", mapAchievement.Id)
local nStatus = self:SetStatus(mapAchievement.Status)
local nBeforeStatus = self._tbAchievementList[mapCfg.Type][mapAchievement.Id].nStatus
self._tbAchievementList[mapCfg.Type][mapAchievement.Id] = {
sTime = os.date("%Y/%m/%d", mapAchievement.Completed),
nId = mapAchievement.Id,
nCur = #mapAchievement.Progress > 0 and mapAchievement.Progress[1].Cur or mapCfg.AimNumShow,
nMax = #mapAchievement.Progress > 0 and mapAchievement.Progress[1].Max or mapCfg.AimNumShow,
nStatus = nStatus,
bHide = mapCfg.Hide
}
local mapCur = self._tbAchievementList[mapCfg.Type][mapAchievement.Id]
if nBeforeStatus ~= nStatus then
if mapCur.nStatus == Status.Received then
self._tbTypeCount[mapCfg.Type].nCompleted = self._tbTypeCount[mapCfg.Type].nCompleted + 1
self._tbTypeCount[mapCfg.Type].tbRarity[mapCfg.Rarity] = self._tbTypeCount[mapCfg.Type].tbRarity[mapCfg.Rarity] + 1
end
if mapCur.bHide and mapCur.nStatus ~= Status.Uncompleted then
self._tbTypeCount[mapCfg.Type].nTotal = self._tbTypeCount[mapCfg.Type].nTotal + 1
end
if mapCur.nStatus == Status.Unreceived then
local nCount = self._tbUnreceivedCountList[mapCfg.Type] or 0
nCount = nCount + 1
self._tbUnreceivedCountList[mapCfg.Type] = nCount
end
end
end
end
function PlayerAchievementData:GetBattleAchievement(nLevelType, bBattleSuccess)
local tbRet = {}
if self._tbBattleAchievement[nLevelType] and #self._tbBattleAchievement[nLevelType] > 0 then
AchievementChecker:CheckBattleAchievement(self._tbBattleAchievement[nLevelType], tbRet, bBattleSuccess)
end
if self._tbBattleAchievement[GameEnum.levelType.All] and 0 < #self._tbBattleAchievement[GameEnum.levelType.All] then
AchievementChecker:CheckBattleAchievement(self._tbBattleAchievement[GameEnum.levelType.All], tbRet, bBattleSuccess)
end
return tbRet
end
function PlayerAchievementData:GetAchievementTypeCount(nType)
return self._tbTypeCount[nType]
end
function PlayerAchievementData:GetAchievementAllTypeCount()
local ret = {
nTotal = 0,
nCompleted = 0,
nSSR = 0,
nSR = 0,
nR = 0
}
for _, mapCount in pairs(self._tbTypeCount) do
ret.nTotal = ret.nTotal + mapCount.nTotal
ret.nCompleted = ret.nCompleted + mapCount.nCompleted
ret.nSSR = ret.nSSR + mapCount.tbRarity[GameEnum.itemRarity.SSR]
ret.nSR = ret.nSR + mapCount.tbRarity[GameEnum.itemRarity.SR]
ret.nR = ret.nR + mapCount.tbRarity[GameEnum.itemRarity.R]
end
return ret
end
function PlayerAchievementData:GetAchievementTypeList(nType)
return self._tbAchievementList[nType]
end
function PlayerAchievementData:GetReceiveList(nType)
local tbId = {}
for _, mapData in pairs(self._tbAchievementList[nType]) do
if mapData.nStatus == Status.Unreceived then
table.insert(tbId, mapData.nId)
end
end
return tbId
end
function PlayerAchievementData:JudgeHide(nType, mapData)
local bUncompleted = mapData.nStatus == Status.Uncompleted
if not bUncompleted then
return false
end
local mapCfg = ConfigTable.GetData("Achievement", mapData.nId)
local bHide = mapData.bHide
local bPreReceived = true
if mapCfg ~= nil and #mapCfg.Prerequisites > 0 then
for _, nId in ipairs(mapCfg.Prerequisites) do
if self._tbAchievementList[nType] == nil or self._tbAchievementList[nType][nId] == nil then
printError("AchievementCfg Missing:" .. nId .. "," .. nType)
break
end
if self._tbAchievementList[nType][nId].nStatus ~= Status.Received then
bPreReceived = false
break
end
end
end
return bHide or not bPreReceived
end
function PlayerAchievementData:ChangeAchievementData(mapAchievement)
self:ChangeBattleAchievementData(mapAchievement.Id, mapAchievement.Status)
local nStatus = self:SetStatus(mapAchievement.Status)
if nStatus ~= Status.Uncompleted then
PlayerData.SideBanner:AddAchievement(mapAchievement.Id)
end
if #mapAchievement.Progress == 0 then
self._bNeedUpdate = true
return
end
if self._bNeedUpdate then
return
end
local mapCfg = ConfigTable.GetData("Achievement", mapAchievement.Id)
if mapCfg == nil then
return
end
if not self._tbAchievementList[mapCfg.Type] then
self._tbAchievementList[mapCfg.Type] = {}
end
self._tbAchievementList[mapCfg.Type][mapAchievement.Id] = {
sTime = os.date("%Y/%m/%d", mapAchievement.Completed),
nId = mapAchievement.Id,
nCur = mapAchievement.Progress[1].Cur,
nMax = mapAchievement.Progress[1].Max,
nStatus = nStatus,
bHide = mapCfg.Hide
}
local mapCur = self._tbAchievementList[mapCfg.Type][mapAchievement.Id]
if not self._tbTypeCount[mapCfg.Type] then
self._tbTypeCount[mapCfg.Type] = {
nCompleted = 0,
nTotal = 0,
tbRarity = {
[GameEnum.itemRarity.SSR] = 0,
[GameEnum.itemRarity.SR] = 0,
[GameEnum.itemRarity.R] = 0
}
}
end
if mapCur.bHide then
self._tbTypeCount[mapCfg.Type].nTotal = self._tbTypeCount[mapCfg.Type].nTotal + 1
end
if nStatus == Status.Unreceived then
local nCount = self._tbUnreceivedCountList[mapCfg.Type] or 0
nCount = nCount + 1
self._tbUnreceivedCountList[mapCfg.Type] = nCount
end
end
function PlayerAchievementData:ChangeBattleAchievementData(nId, nStatus)
if nStatus ~= Status.Unreceived then
return
end
local mapCfg = ConfigTable.GetData("Achievement", nId)
if mapCfg == nil then
return
end
if mapCfg.CompleteCond ~= GameEnum.achievementCond.ClientReport or #mapCfg.LevelType == 0 then
return
end
if mapCfg.CompleteCondClient > 999 then
local nIdx = table.indexof(self.tbSpecialBattle, nId)
if 0 < nIdx then
table.remove(self.tbSpecialBattle, nIdx)
end
end
for _, nType in ipairs(mapCfg.LevelType) do
if self._tbBattleAchievement[nType] then
for key, value in pairs(self._tbBattleAchievement[nType]) do
if value == nId then
table.remove(self._tbBattleAchievement[nType], key)
break
end
end
end
end
end
function PlayerAchievementData:CheckReddot()
if self._bNeedUpdate then
local bRedddot = PlayerData.State.bNewAchievement or false
RedDotManager.SetValid(RedDotDefine.Achievement_Tab, {
GameEnum.achievementType.Overview
}, bRedddot)
else
RedDotManager.SetValid(RedDotDefine.Achievement_Tab, {
GameEnum.achievementType.Overview
}, false)
for k, v in pairs(self._tbUnreceivedCountList) do
local bRedddot = 0 < v
RedDotManager.SetValid(RedDotDefine.Achievement_Tab, {k}, bRedddot)
end
end
end
function PlayerAchievementData:CheckAchieveId(nId)
for nAchieveType, mapAchieveInfo in pairs(self._tbAchievementList) do
for nAchieveId, mapInfo in pairs(mapAchieveInfo) do
if nAchieveId == nId and mapInfo.nStatus ~= Status.Uncompleted then
return true
end
end
end
return false
end
function PlayerAchievementData:CheckAchieveIds(tbIds)
local bResult = true
local mapAchieveInfo = {}
if tbIds == nil then
return bResult, mapAchieveInfo
end
if #tbIds <= 0 then
return bResult, mapAchieveInfo
end
for i, nId in ipairs(tbIds) do
mapAchieveInfo[nId] = self:CheckAchieveId(nId)
bResult = bResult == true and mapAchieveInfo[nId] == true
end
return bResult, mapAchieveInfo
end
function PlayerAchievementData:GetTimeLimit(sStart, sEnd)
end
function PlayerAchievementData:SetStatus(nStatus)
if nStatus == 0 then
nStatus = Status.Uncompleted
elseif nStatus == 1 then
nStatus = Status.Unreceived
elseif nStatus == 2 then
nStatus = Status.Received
end
return nStatus
end
function PlayerAchievementData:UpdateStatus(tbId, nType)
for _, nId in pairs(tbId) do
local mapCfg = ConfigTable.GetData("Achievement", nId)
self._tbAchievementList[nType][nId].nStatus = Status.Received
self._tbTypeCount[nType].nCompleted = self._tbTypeCount[nType].nCompleted + 1
self._tbTypeCount[nType].tbRarity[mapCfg.Rarity] = self._tbTypeCount[nType].tbRarity[mapCfg.Rarity] + 1
local nCount = self._tbUnreceivedCountList[nType]
nCount = math.max(0, nCount - 1)
self._tbUnreceivedCountList[nType] = nCount
end
end
function PlayerAchievementData:SendAchievementInfoReq(callback)
if self._bNeedUpdate then
self._bNeedUpdate = false
local successCallback = function(_, mapMainData)
self:CacheAchievementData(mapMainData)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.achievement_info_req, {}, nil, successCallback)
else
callback()
end
end
function PlayerAchievementData:SendAchievementRewardReq(tbId, nType, callback)
local msgData = {Ids = tbId}
local successCallback = function(_, mapMainData)
UTILS.OpenReceiveByChangeInfo(mapMainData)
self:UpdateStatus(tbId, nType)
EventManager.Hit("AchievementRefresh")
if callback then
callback(mapMainData)
end
self:CheckReddot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.achievement_reward_receive_req, msgData, nil, successCallback)
end
return PlayerAchievementData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,326 @@
local PlayerBattlePassData = class("PlayerBattlePassData")
function PlayerBattlePassData:Init()
self.nSeasonId = 0
self.nCurMode = 0
self.nVersion = 0
self.nDeadlineTS = 0
self.nLevel = 0
self.nExp = 0
self.nMaxLevel = 0
self.nExpThisWeek = 0
self.tbBaseReward = nil
self.tbPremiumReward = nil
self.hasData = false
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Add("BattlePassNeedRefresh", self, self.OnEvent_NeedRefresh)
self:InitConfig()
end
function PlayerBattlePassData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerBattlePassData:InitConfig()
local forEachBattlePassLevel = function(mapData)
if mapData.ID > self.nMaxLevel then
self.nMaxLevel = mapData.ID
end
end
ForEachTableLine(DataTable.BattlePassLevel, forEachBattlePassLevel)
self.mapBattlePassName = {}
local func_ForEach_Line = function(mapData)
self.mapBattlePassName[mapData.LuxuryProductId] = ConfigTable.GetUIText("BattlePassRewardLuxury")
self.mapBattlePassName[mapData.PremiumProductId] = ConfigTable.GetUIText("BattlePassRewardPremium")
self.mapBattlePassName[mapData.ComplementaryProductId] = ConfigTable.GetUIText("BattlePassRewardLuxury")
end
ForEachTableLine(DataTable.BattlePass, func_ForEach_Line)
end
function PlayerBattlePassData:CacheBattlePassInfo(mapData)
if mapData == nil then
return
end
print("当前赛季ID" .. mapData.Id)
self.nSeasonId = mapData.Id
self.nCurMode = mapData.Mode
self.nVersion = mapData.Version
self.nDeadlineTS = mapData.Deadline
self.nLevel = mapData.Level
self.nExp = mapData.Exp
self.nExpThisWeek = mapData.ExpThisWeek
self.tbBaseReward = UTILS.ParseByteString(mapData.BasicReward)
self.tbPremiumReward = UTILS.ParseByteString(mapData.PremiumReward)
local nExpLimit = ConfigTable.GetConfigNumber("BattlePassWeeklyExpLimit")
if nExpLimit < self.nExpThisWeek then
self.nExpThisWeek = self.nExpThisWeek
end
self:UpdateRewardRedDot()
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Server, nil, false)
if mapData.DailyQuests ~= nil then
PlayerData.Quest:CacheAllQuest(mapData.DailyQuests.List)
end
if mapData.WeeklyQuests ~= nil then
PlayerData.Quest:CacheAllQuest(mapData.WeeklyQuests.List)
end
self.hasData = true
end
function PlayerBattlePassData:UpdateQuestRedDot(bCanDailyReceive, bCanWeekReceive)
local nExpLimit = ConfigTable.GetConfigNumber("BattlePassWeeklyExpLimit")
self.nExpThisWeek = self.nExpThisWeek
if nExpLimit <= self.nExpThisWeek then
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Daily, nil, false)
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Week, nil, false)
else
local bMaxLevel = self.nLevel >= self.nMaxLevel
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Daily, nil, bCanDailyReceive and not bMaxLevel)
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Week, nil, bCanWeekReceive and not bMaxLevel)
end
end
function PlayerBattlePassData:UpdateRewardRedDot()
local bCanReceive = false
local mapReward = {}
local nRewardCount = 0
local foreachReward = function(mapData)
if mapData.ID == self.nSeasonId then
mapReward[mapData.Level] = mapData
nRewardCount = nRewardCount + 1
end
end
ForEachTableLine(DataTable.BattlePassReward, foreachReward)
for i = 1, nRewardCount do
if mapReward[i] ~= nil then
local bNormalReceive = UTILS.IsBitSet(self.tbBaseReward, i)
local bVipReceive = UTILS.IsBitSet(self.tbPremiumReward, i)
if i <= self.nLevel and (not bNormalReceive or 0 < self.nCurMode and not bVipReceive) then
bCanReceive = true
break
end
end
end
RedDotManager.SetValid(RedDotDefine.BattlePass_Reward, nil, bCanReceive)
local nExpLimit = ConfigTable.GetConfigNumber("BattlePassWeeklyExpLimit")
if self.nLevel >= self.nMaxLevel or nExpLimit <= self.nExpThisWeek then
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Week, nil, false)
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Daily, nil, false)
end
end
function PlayerBattlePassData:OnPremiumBuySuccess(mapData)
if self.nLevel ~= mapData.Level then
local mapLevelData = {
nOldLevel = self.nLevel,
nOldExp = self.nExp,
nLevel = mapData.Level,
nExp = self.nExp
}
local function callback()
EventManager.Remove("MallOrderClear", self, callback)
local levelupCallback = function()
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(mapData.CollectResp.Items)
local tbSelectedItem = {}
for _, mapItemData in ipairs(mapReward.tbReward) do
local mapItemCfgData = ConfigTable.GetData_Item(mapItemData.id)
if mapItemCfgData ~= nil and mapItemCfgData.Stype == GameEnum.itemStype.OutfitCYO then
table.insert(tbSelectedItem, mapItemData.id)
end
end
if 0 < #tbSelectedItem then
EventManager.Hit(EventId.OpenPanel, PanelId.Consumable, tbSelectedItem)
end
EventManager.Hit("BattlePassLevelUpPanelClose")
end
EventManager.Hit(EventId.OpenPanel, PanelId.BattlePassUpgrade, levelupCallback, mapLevelData)
end
EventManager.Add("MallOrderClear", self, callback)
else
local function callback()
EventManager.Remove("MallOrderClear", self, callback)
if mapData.Mode == 1 then
local msg = {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("BattlePassRewardPremium_ReceiveTip")
}
EventManager.Hit(EventId.OpenMessageBox, msg)
end
end
EventManager.Add("MallOrderClear", self, callback)
end
self.nVersion = mapData.Version
self.nCurMode = mapData.Mode
self.nLevel = mapData.Level
self:UpdateRewardRedDot()
EventManager.Hit("BattlePassPremiumSuccess")
end
function PlayerBattlePassData:OnQuestReceive(msgData)
self.nLevel = msgData.Level
self.nExp = msgData.Exp
local nExpLimit = ConfigTable.GetConfigNumber("BattlePassWeeklyExpLimit")
self.nExpThisWeek = msgData.ExpThisWeek
if nExpLimit < self.nExpThisWeek then
self.nExpThisWeek = self.nExpThisWeek
end
self:UpdateRewardRedDot()
end
function PlayerBattlePassData:GetBattlePassName(sId)
return self.mapBattlePassName[sId]
end
function PlayerBattlePassData:OnEvent_NewDay()
self.hasData = false
end
function PlayerBattlePassData:OnEvent_NeedRefresh()
self.hasData = false
end
function PlayerBattlePassData:NetMsg_BuyBattlePassLevel(nLevel, callback)
local msg = {
Value = nLevel,
Version = self.nVersion
}
local mapLevelData = {
nOldLevel = self.nLevel,
nOldExp = self.nExp
}
local msgCallback = function(_, msgData)
self.nLevel = msgData.Level
mapLevelData.nLevel = self.nLevel
mapLevelData.nExp = self.nExp
local callabck = function()
EventManager.Hit("BattlePassLevelUpPanelClose")
end
EventManager.Hit(EventId.OpenPanel, PanelId.BattlePassUpgrade, callabck, mapLevelData)
EventManager.Hit("BattlePassBuyLevel")
if callback ~= nil and type(callback) == "function" then
callback()
end
self:UpdateRewardRedDot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_level_buy_req, msg, nil, msgCallback)
end
function PlayerBattlePassData:NetMsg_BattlePassRewardReceive(bAll, nLevel, bBasic, callback)
local msg = {}
if bAll then
msg.All = {}
elseif bBasic then
msg.Basic = nLevel
else
msg.Premium = nLevel
end
msg.Version = self.nVersion
local msgCallback = function(_, msgData)
self.tbBaseReward = UTILS.ParseByteString(msgData.BasicReward)
self.tbPremiumReward = UTILS.ParseByteString(msgData.PremiumReward)
EventManager.Hit("UpdateBattlePassReward", msgData.Change)
self:UpdateRewardRedDot()
if callback ~= nil and type(callback) == "function" then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_reward_receive_req, msg, nil, msgCallback)
end
function PlayerBattlePassData:GetBattlePassInfo(callback)
local GetMsgCallback = function()
if not self.hasData then
printError("未获取到战令数据")
return
end
local mapRet = {}
local mapReward = {}
local nRewardCount = 0
local foreachReward = function(mapData)
if mapData.ID == self.nSeasonId then
mapReward[mapData.Level] = mapData
nRewardCount = nRewardCount + 1
end
end
ForEachTableLine(DataTable.BattlePassReward, foreachReward)
mapRet.nSeasonId = self.nSeasonId
mapRet.nCurMode = self.nCurMode
mapRet.nVersion = self.nVersion
mapRet.nDeadlineTS = self.nDeadlineTS
mapRet.nLevel = self.nLevel
mapRet.nExp = self.nExp
mapRet.nExpThisWeek = self.nExpThisWeek
mapRet.tbReward = {}
for i = 1, nRewardCount do
if mapReward[i] ~= nil then
local bNormalReceive = UTILS.IsBitSet(self.tbBaseReward, i)
local bVipReceive = UTILS.IsBitSet(self.tbPremiumReward, i)
table.insert(mapRet.tbReward, {
nLevel = i,
nNormalTid = mapReward[i].Tid1,
nNormalQty = mapReward[i].Qty1,
nVipTid1 = mapReward[i].Tid2,
nVipQty1 = mapReward[i].Qty2,
nVipTid2 = mapReward[i].Tid3,
nVipQty2 = mapReward[i].Qty3,
bNormalReceive = bNormalReceive,
bVipReceive = bVipReceive,
bFocus = mapReward[i].Focus
})
end
end
callback(mapRet)
end
if self.hasData then
GetMsgCallback()
else
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_info_req, {}, nil, GetMsgCallback)
end
end
function PlayerBattlePassData:GetRefreshTime()
if self.nSeasonId == 0 then
return "-"
end
local mapSeasonCfgData = ConfigTable.GetData("BattlePass", self.nSeasonId)
if mapSeasonCfgData == nil then
return "-"
end
local nEndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapSeasonCfgData.EndTime)
local curTime = CS.ClientManager.Instance.serverTimeStamp
local remainTime = nEndTime - curTime
if remainTime < 0 then
return "-"
end
local sTimeStr = "-"
local remainTime = nEndTime - curTime
if 86400 <= remainTime then
local day = math.floor(remainTime / 86400)
local hour = math.floor((remainTime - day * 86400) / 3600)
if hour == 0 then
day = day - 1
hour = 24
end
sTimeStr = orderedFormat(ConfigTable.GetUIText("Energy_LeftTime_Day"), day, hour)
elseif 3600 <= remainTime then
local hour = math.floor(remainTime / 3600)
local min = math.floor((remainTime - hour * 3600) / 60)
if min == 0 then
hour = hour - 1
min = 60
end
sTimeStr = orderedFormat(ConfigTable.GetUIText("Energy_LeftTime_Hour"), hour, min)
else
sTimeStr = ConfigTable.GetUIText("Energy_LeftTime_LessThenHour")
end
return sTimeStr
end
function PlayerBattlePassData:GetHasBattlePass()
if self.hasData then
return self.nSeasonId > 0
else
local IsOpenCardPool = function(sStartTime, sEndTime)
if string.len(sStartTime) == 0 or string.len(sEndTime) == 0 then
return true
end
local nowTime = CS.ClientManager.Instance.serverTimeStamp
return nowTime > String2Time(sStartTime) and nowTime < String2Time(sEndTime)
end
local ret = false
local func_ForEach_Gacha = function(mapGacha)
if IsOpenCardPool(mapGacha.StartTime, mapGacha.EndTime) then
ret = true
end
end
ForEachTableLine(DataTable.BattlePass, func_ForEach_Gacha)
return ret
end
end
function PlayerBattlePassData:GetMaxLevel()
return self.nMaxLevel
end
return PlayerBattlePassData
@@ -0,0 +1,294 @@
local Actor2DManager = require("Game.Actor2D.Actor2DManager")
local PlayerBoardData = class("PlayerBoardData")
local PlayerHandbookData = PlayerData.Handbook
local LocalData = require("GameCore.Data.LocalData")
local max_select_count = 5
function PlayerBoardData:Init()
self.tbSelectBoardList = {}
self.tbTmpSelectBoardList = {}
self.tbTmpSelectSkinList = {}
self.nBoardPanelShowId = 0
self.nBoardPanelCGType = 0
self.nCurBoardIdx = 1
end
function PlayerBoardData:CacheBoardData(mapMagData)
local nLocalIdx = LocalData.GetPlayerLocalData("MainBoardIndex")
if nil == nLocalIdx then
LocalData.SetPlayerLocalData("MainBoardIndex", "1")
end
self.nCurBoardIdx = tonumber(LocalData.GetPlayerLocalData("MainBoardIndex"))
self.tbSelectBoardList = mapMagData
self:ResetBoardList()
end
function PlayerBoardData:GetSelectBoardData()
return self.tbSelectBoardList
end
function PlayerBoardData:CheckSelectBoardChar()
for _, nId in ipairs(self.tbSelectBoardList) do
local handbookData = PlayerHandbookData:GetHandbookDataById(nId)
if handbookData ~= nil and handbookData:GetType() == GameEnum.handbookType.SKIN then
return true
end
end
return false
end
function PlayerBoardData:GetCurBoardData()
if #self.tbSelectBoardList < self.nCurBoardIdx then
self:ResetBoardIndex()
end
if self.tbSelectBoardList[self.nCurBoardIdx] ~= nil then
local nId = self.tbSelectBoardList[self.nCurBoardIdx]
if nil ~= nId then
local handbookData = PlayerHandbookData:GetHandbookDataById(nId)
return handbookData
end
end
end
function PlayerBoardData:GetCurBoardCharID()
local curBoardData = self:GetCurBoardData()
if nil ~= curBoardData and curBoardData:GetType() == GameEnum.handbookType.SKIN then
return curBoardData:GetCharId()
end
end
function PlayerBoardData:GetTempBoardData()
if self.tbSelectBoardList[self.nCurBoardIdx] ~= nil then
local nId = self.tbSelectBoardList[self.nCurBoardIdx]
if nil ~= nId then
return PlayerHandbookData:GetTempHandbookDataById(nId)
end
end
end
function PlayerBoardData:ChangeNextBoard()
if #self.tbSelectBoardList <= 1 then
return false
end
self.nCurBoardIdx = self.nCurBoardIdx + 1
if self.nCurBoardIdx > #self.tbSelectBoardList then
self.nCurBoardIdx = 1
end
LocalData.SetPlayerLocalData("MainBoardIndex", tostring(self.nCurBoardIdx))
return true
end
function PlayerBoardData:ChangeLastBoard()
if #self.tbSelectBoardList <= 1 then
return false
end
self.nCurBoardIdx = self.nCurBoardIdx - 1
if self.nCurBoardIdx <= 0 then
self.nCurBoardIdx = #self.tbSelectBoardList
end
LocalData.SetPlayerLocalData("MainBoardIndex", tostring(self.nCurBoardIdx))
return true
end
function PlayerBoardData:ResetBoardIndex()
self.nCurBoardIdx = 1
LocalData.SetPlayerLocalData("MainBoardIndex", tostring(self.nCurBoardIdx))
end
function PlayerBoardData:GetMaxSelectCount()
return max_select_count
end
function PlayerBoardData:GetBoardDragThreshold()
return ConfigTable.GetConfigNumber("MainViewDragThreshold")
end
function PlayerBoardData:ResetBoardList()
self.tbTmpSelectBoardList = clone(self.tbSelectBoardList)
end
function PlayerBoardData:SetTmpBoardList(tbList)
self.tbTmpSelectBoardList = tbList
end
function PlayerBoardData:CheckInTmpBoardList(nHandbookId)
for _, v in pairs(self.tbTmpSelectBoardList) do
if v == nHandbookId then
return true
end
end
return false
end
function PlayerBoardData:GetTmpBoardIndexById(nHandbookId)
for k, v in pairs(self.tbTmpSelectBoardList) do
if v == nHandbookId then
return k
end
end
return 0
end
function PlayerBoardData:InsertTmpBoard(nHandbookId)
if #self.tbTmpSelectBoardList >= max_select_count then
return false
end
table.insert(self.tbTmpSelectBoardList, nHandbookId)
return true
end
function PlayerBoardData:RemoveTmpBoard(nHandbookId)
local removeIdx = 0
for k, v in pairs(self.tbTmpSelectBoardList) do
if v == nHandbookId then
removeIdx = k
break
end
end
if 0 ~= removeIdx then
table.remove(self.tbTmpSelectBoardList, removeIdx)
end
end
function PlayerBoardData:ChangeTmpCharSkin(nCharId, nHandbookId)
self:SetTmpSkinSelect(nCharId, nHandbookId)
for k, v in pairs(self.tbTmpSelectBoardList) do
local handbookData = PlayerHandbookData:GetHandbookDataById(v)
if nil ~= handbookData and handbookData:GetType() == GameEnum.handbookType.SKIN and handbookData:GetCharId() == nCharId then
self.tbTmpSelectBoardList[k] = nHandbookId
break
end
end
end
function PlayerBoardData:GetTmpBoardList()
return self.tbTmpSelectBoardList
end
function PlayerBoardData:SetTmpSkinSelect(nCharId, handbookId)
self.tbTmpSelectSkinList[nCharId] = handbookId
end
function PlayerBoardData:ResetTmpSkinSelect()
self.tbTmpSelectSkinList = {}
end
function PlayerBoardData:GetTmpSkinSelect()
return self.tbTmpSelectSkinList
end
function PlayerBoardData:SetBoardPanelSelectId(nId)
self.nBoardPanelShowId = nId
end
function PlayerBoardData:GetBoardPanelSelectId()
return self.nBoardPanelShowId
end
function PlayerBoardData:SetBoardPanelL2DType(nType)
self.nBoardPanelCGType = nType
end
function PlayerBoardData:GetBoardPanelL2DType()
return self.nBoardPanelCGType
end
function PlayerBoardData:SendBoardSet(callback)
if nil ~= self.tbTmpSelectBoardList and nil ~= next(self.tbTmpSelectBoardList) then
local sendBoardList = {}
for _, v in pairs(self.tbTmpSelectBoardList) do
if nil ~= v then
table.insert(sendBoardList, v)
end
end
local bChange = false
if #sendBoardList ~= #self.tbSelectBoardList then
bChange = true
else
for k, v in ipairs(sendBoardList) do
if nil == self.tbSelectBoardList[k] or self.tbSelectBoardList[k] ~= v then
bChange = true
break
end
end
end
local callbackFunc = function()
local nSelectId = self:GetBoardPanelSelectId()
for k, v in ipairs(self.tbSelectBoardList) do
if v == nSelectId then
self.nCurBoardIdx = k
break
end
end
if nil ~= callback then
callback()
end
end
if bChange then
local msgData = {Ids = sendBoardList}
HttpNetHandler.SendMsg(NetMsgId.Id.player_board_set_req, msgData, nil, callbackFunc)
else
callbackFunc()
end
end
end
function PlayerBoardData:SetBoardSuccess()
self.tbSelectBoardList = {}
for _, v in pairs(self.tbTmpSelectBoardList) do
if nil ~= v then
table.insert(self.tbSelectBoardList, v)
end
end
self:ResetBoardList()
self:ResetBoardIndex()
end
function PlayerBoardData:SetBoardFail()
self:ResetBoardList()
end
function PlayerBoardData:GetUsableBoardCharId()
local curBoardData = self:GetCurBoardData()
if curBoardData:GetType() == GameEnum.handbookType.SKIN then
return curBoardData:GetCharId(), curBoardData:GetSkinId()
end
local tbBoardChar = {}
for _, nId in ipairs(self.tbSelectBoardList) do
local handbookData = PlayerHandbookData:GetHandbookDataById(nId)
if handbookData:GetType() == GameEnum.handbookType.SKIN then
table.insert(tbBoardChar, handbookData)
end
end
if 0 < #tbBoardChar then
local nRandomIndex = math.random(1, #tbBoardChar)
local boardData = tbBoardChar[nRandomIndex]
if boardData ~= nil then
return boardData:GetCharId(), boardData:GetSkinId()
end
else
local ownedChar = PlayerData.Char:GetDataForCharList()
local tbAllChar = {}
for _, v in pairs(ownedChar) do
local mapCfg = ConfigTable.GetData_Character(v.nId)
if mapCfg ~= nil and mapCfg.Visible then
table.insert(tbAllChar, v)
end
end
local nRandomIndex = math.random(1, #tbAllChar)
local charData = tbAllChar[nRandomIndex]
if charData ~= nil then
return charData.nId, PlayerData.Char:GetCharUsedSkinId(charData.nId)
end
end
end
function PlayerBoardData:GetNPCDefaultSkinId(nNPCId)
local tbNPCCfg = ConfigTable.GetData("BoardNPC", nNPCId)
if nil == tbNPCCfg then
printError("读取BoardNPC表格失败!!!NPCId = " .. nNPCId)
return
end
return tbNPCCfg.DefaultSkinId
end
function PlayerBoardData:GetNPCUsingSkinId(nNPCId)
return self:GetNPCDefaultSkinId(nNPCId)
end
function PlayerBoardData:ChooseBoardList()
local tbHandBook = PlayerData.Handbook:GetAllHandbookData()
local tbAllCharHandBook = {}
for _, v in pairs(tbHandBook) do
if v:GetType() == GameEnum.handbookType.SKIN and v:CheckUnlock() then
table.insert(tbAllCharHandBook, v)
end
end
local remaining = #tbAllCharHandBook
local tbResult = {}
for i = 1, math.min(remaining, 5) do
local index = math.random(1, remaining)
table.insert(tbResult, tbAllCharHandBook[index]:GetId())
tbAllCharHandBook[index] = tbAllCharHandBook[remaining]
remaining = remaining - 1
end
local msgData = {Ids = tbResult}
self.tbTmpSelectBoardList = tbResult
local callbackFunc = function()
local nSelectId = self:GetBoardPanelSelectId()
for k, v in ipairs(self.tbSelectBoardList) do
if v == nSelectId then
self.nCurBoardIdx = k
break
end
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_board_set_req, msgData, nil, callbackFunc)
end
return PlayerBoardData
@@ -0,0 +1,643 @@
local LocalData = require("GameCore.Data.LocalData")
local ConfigData = require("GameCore.Data.ConfigData")
local PlayerBuildData = class("PlayerBuildData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
function PlayerBuildData:Init()
self._MapBuildData = {}
self.hasData = false
self:InitBuildRank()
end
function PlayerBuildData:InitBuildRank()
self._tbBuildRank = {}
local foreach = function(line)
self._tbBuildRank[line.Id] = line
end
ForEachTableLine(DataTable.StarTowerBuildRank, foreach)
self._nBuildRankCount = #self._tbBuildRank
end
function PlayerBuildData:GetBuildRank()
return self._tbBuildRank
end
function PlayerBuildData:CreateBuildBriefData(mapBuildBriefMsg)
if nil ~= self._MapBuildData[mapBuildBriefMsg.Id] then
printLog(string.format("编队信息重复!!!id= [%s]", mapBuildBriefMsg.Id))
end
local mapBuildData = {
nBuildId = mapBuildBriefMsg.Id,
sName = mapBuildBriefMsg.Name,
tbChar = {},
nScore = mapBuildBriefMsg.Score,
mapRank = self:CalBuildRank(mapBuildBriefMsg.Score),
bLock = mapBuildBriefMsg.Lock,
bPreference = mapBuildBriefMsg.Preference,
bDetail = false,
tbDisc = {},
tbSecondarySkill = {},
tbPotentials = {},
tbNotes = {},
nTowerId = mapBuildBriefMsg.StarTowerId
}
for i = 1, 3 do
table.insert(mapBuildData.tbChar, {
nTid = mapBuildBriefMsg.Chars[i].CharId,
nPotentialCount = mapBuildBriefMsg.Chars[i].PotentialCnt
})
end
mapBuildData.tbDisc = mapBuildBriefMsg.DiscIds
self._MapBuildData[mapBuildBriefMsg.Id] = mapBuildData
end
function PlayerBuildData:CreateBuildDetailData(nBuildId, mapBuildDetailMsg)
if nil == mapBuildDetailMsg or nil == next(mapBuildDetailMsg) then
return
end
if nil == self._MapBuildData[nBuildId] then
printLog(string.format("找不到编队信息!!!id= [%s]", nBuildId))
return
end
self._MapBuildData[nBuildId].tbSecondarySkill = mapBuildDetailMsg.ActiveSecondaryIds
for _, v in ipairs(mapBuildDetailMsg.Potentials) do
local potentialCfg = ConfigTable.GetData("Potential", v.PotentialId)
if potentialCfg then
local nCharId = potentialCfg.CharId
if nil == self._MapBuildData[nBuildId].tbPotentials[nCharId] then
self._MapBuildData[nBuildId].tbPotentials[nCharId] = {}
end
table.insert(self._MapBuildData[nBuildId].tbPotentials[nCharId], {
nPotentialId = v.PotentialId,
nLevel = v.Level
})
end
end
local tbNotes = {}
for _, v in pairs(mapBuildDetailMsg.SubNoteSkills) do
tbNotes[v.Tid] = v.Qty
end
self._MapBuildData[nBuildId].tbNotes = tbNotes
self._MapBuildData[nBuildId].bDetail = true
end
function PlayerBuildData:GetAllBuildBriefData(callback)
if not self.hasData then
self:NetMsg_GetBuildBriefData(self.GetBuildBriefDataCallback, callback)
return false
end
self:GetBuildBriefDataCallback(callback)
return true
end
function PlayerBuildData:GetBuildCount(callback)
if not self.hasData then
self:NetMsg_GetBuildBriefData(self.GetBuildCountCallBack, callback)
return false
end
self:GetBuildCountCallBack(callback)
return true
end
function PlayerBuildData:GetBuildDetailData(callback, nBuildId)
if self._MapBuildData[nBuildId] == nil then
if self.hasData then
printWarn("没有该id的build,大概率已被分解:" .. nBuildId)
if callback then
callback()
end
return false
end
local callBack = function()
self:GetBuildDetailData(callback, nBuildId)
end
self:NetMsg_GetBuildBriefData(self.GetBuildBriefDataCallback, callBack)
return false
end
if not self._MapBuildData[nBuildId].bDetail then
self:NetMsg_GetBuildDetailData(nBuildId, self.GetBuildDetailDataCallback, callback, nBuildId)
return false
end
self:GetBuildDetailDataCallback(callback, nBuildId)
return true
end
function PlayerBuildData:ChangeBuildName(nBuildId, sName, callback)
self:NetMsg_ChangeBuildName(nBuildId, sName, callback)
end
function PlayerBuildData:ChangeBuildLock(nBuildId, bLock, callback)
self:NetMsg_ChangeBuildLock(nBuildId, bLock, callback)
end
function PlayerBuildData:DeleteBuild(tbBuildId, callback, cbClose)
self:NetMsg_BuildDelete(tbBuildId, callback, cbClose)
end
function PlayerBuildData:DeleteBuildByActivity(tbBuildId)
for _, bBuildId in ipairs(tbBuildId) do
self._MapBuildData[bBuildId] = nil
end
end
function PlayerBuildData:SetBuildPreference(tbCheckInIds, tbCheckOutIds, callback)
self:NetMsg_BuildPreference(tbCheckInIds, tbCheckOutIds, callback)
end
function PlayerBuildData:SaveBuild(nBuildID, bDelete, bLock, bPreference, sName, callback)
self:NetMsg_SaveBuild(nBuildID, bDelete, bLock, bPreference, sName, callback)
end
function PlayerBuildData:CheckHasBuild()
return next(self._MapBuildData) ~= nil
end
function PlayerBuildData:GetBuildAllEft(nBuildId)
local ret = {}
local mapBuildData = self._MapBuildData[nBuildId]
if mapBuildData == nil or not mapBuildData.bDetail then
print("没有对应build 或未获取该build详细数据")
return ret
end
local mapCharEffect = {}
local mapPotentialAddLevel = {}
for _, mapChar in ipairs(mapBuildData.tbChar) do
mapCharEffect[mapChar.nTid] = {}
mapCharEffect[mapChar.nTid][AllEnum.EffectType.Affinity] = PlayerData.Char:CalcAffinityEffect(mapChar.nTid)
mapCharEffect[mapChar.nTid][AllEnum.EffectType.Talent] = PlayerData.Char:CalcTalentEffect(mapChar.nTid)
mapCharEffect[mapChar.nTid][AllEnum.EffectType.Equipment] = PlayerData.Equipment:GetCharEquipmentEffect(mapChar.nTid)
mapPotentialAddLevel[mapChar.nTid] = PlayerData.Char:GetCharEnhancedPotential(mapChar.nTid)
end
for nCharId, tbPerk in pairs(mapBuildData.tbPotentials) do
for _, mapPerkInfo in ipairs(tbPerk) do
local nPotentialId = mapPerkInfo.nPotentialId
local nPotentialCount = mapPerkInfo.nLevel
if mapPotentialAddLevel[nCharId] ~= nil and mapPotentialAddLevel[nCharId][nPotentialId] ~= nil then
nPotentialCount = nPotentialCount + mapPotentialAddLevel[nCharId][nPotentialId]
end
if mapCharEffect[nCharId][AllEnum.EffectType.Potential] == nil then
mapCharEffect[nCharId][AllEnum.EffectType.Potential] = {}
end
local mapPotentialCfgData = ConfigTable.GetData("Potential", nPotentialId)
if mapPotentialCfgData == nil then
printError("Potential CfgData Missing:" .. nPotentialId)
else
mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId] = {
{},
nPotentialCount
}
if mapPotentialCfgData.EffectId1 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId1)
end
if mapPotentialCfgData.EffectId2 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId2)
end
if mapPotentialCfgData.EffectId3 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId3)
end
if mapPotentialCfgData.EffectId4 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId4)
end
end
end
end
local mapDiscEffect = {}
for nIndex, nDiscId in ipairs(mapBuildData.tbDisc) do
if nIndex <= 3 then
local tbDiscEft = PlayerData.Disc:CalcDiscEffectInBuild(nDiscId, mapBuildData.tbSecondarySkill)
mapDiscEffect[nDiscId] = tbDiscEft
end
end
local tbNoteInfo, mapNoteEffect = {}, {}
for i, v in pairs(mapBuildData.tbNotes) do
local noteInfo = CS.Lua2CSharpInfo_NoteInfo()
noteInfo.noteId = i
noteInfo.noteCount = v
table.insert(tbNoteInfo, noteInfo)
local mapCfg = ConfigTable.GetData("SubNoteSkill", i)
if mapCfg then
local tbEft = {}
for _, nEftId in pairs(mapCfg.EffectId) do
table.insert(tbEft, {nEftId, v})
end
mapNoteEffect[i] = tbEft
end
end
return mapCharEffect, mapDiscEffect, mapNoteEffect, tbNoteInfo
end
function PlayerBuildData:GetBuildAttrBase(nBuildId, bTrial)
local ret = {}
local mapBuildData = bTrial and self:GetTrialBuild(nBuildId) or self._MapBuildData[nBuildId]
if mapBuildData == nil or not mapBuildData.bDetail then
print("没有对应build 或未获取该build详细数据")
return ret
end
local tbAttrList = {}
for _, v in ipairs(AllEnum.AttachAttr) do
tbAttrList[v.sKey] = {
Key = v.sKey,
Value = 0,
CfgValue = 0
}
end
local mapRank = mapBuildData.mapRank
local nAttrId = UTILS.GetBuildAttributeId(mapRank.AttrBaseGroupId, mapRank.Level)
if 0 < nAttrId then
local mapAttribute = ConfigTable.GetData_Attribute(tostring(nAttrId))
if mapAttribute then
for _, v in ipairs(AllEnum.AttachAttr) do
local nParamValue = mapAttribute[v.sKey] or 0
local nValue = v.bPercent and nParamValue * ConfigData.IntFloatPrecision * 100 or nParamValue
tbAttrList[v.sKey] = {
Key = v.sKey,
Value = nValue,
CfgValue = nParamValue
}
end
end
end
return tbAttrList
end
function PlayerBuildData:CalBuildRank(nScore)
local nMin = 1
local nMax = self._nBuildRankCount
local mapRank = self._tbBuildRank[1]
while nMin <= nMax do
local nMiddle = math.floor((nMin + nMax) / 2)
if nMiddle == self._nBuildRankCount or nScore >= self._tbBuildRank[nMiddle].MinGrade and nScore < self._tbBuildRank[nMiddle + 1].MinGrade then
mapRank = self._tbBuildRank[nMiddle]
break
elseif nScore < self._tbBuildRank[nMiddle].MinGrade then
nMax = nMiddle - 1
else
nMin = nMiddle + 1
end
end
return mapRank
end
function PlayerBuildData:CheckCoinMax(nCoin, confirmDelete)
local nLimit = PlayerData.StarTower:GetStarTowerRewardLimit()
local nCur = PlayerData.StarTower:GetStarTowerTicket()
local confirm = function()
if confirmDelete ~= nil and type(confirmDelete) == "function" then
confirmDelete()
end
end
if nLimit < nCoin + nCur then
local TipsTime = LocalData.GetPlayerLocalData("Build_Tips_Time")
local _tipDay = 0
if TipsTime ~= nil then
_tipDay = tonumber(TipsTime)
end
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp + newDayTime * 3600
local nYear = tonumber(os.date("!%Y", fixedTimeStamp))
local nMonth = tonumber(os.date("!%m", fixedTimeStamp))
local nDay = tonumber(os.date("!%d", fixedTimeStamp))
local nowD = nYear * 366 + nMonth * 31 + nDay
if nowD == _tipDay then
confirm()
else
local isSelectAgain = false
local confirmCallback = function()
if isSelectAgain then
local _curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local _fixedTimeStamp = _curTimeStamp + newDayTime * 3600
local _nYear = tonumber(os.date("!%Y", _fixedTimeStamp))
local _nMonth = tonumber(os.date("!%m", _fixedTimeStamp))
local _nDay = tonumber(os.date("!%d", _fixedTimeStamp))
local _nowD = _nYear * 366 + _nMonth * 31 + _nDay
LocalData.SetPlayerLocalData("Build_Tips_Time", tostring(_nowD))
end
confirm()
end
local againCallback = function(isSelect)
isSelectAgain = isSelect
end
local msg = {
nType = AllEnum.MessageBox.Confirm,
sContent = ConfigTable.GetUIText("BUILD_11"),
callbackConfirm = confirmCallback,
callbackAgain = againCallback,
bBlur = false
}
EventManager.Hit(EventId.OpenMessageBox, msg)
end
else
confirm()
end
end
function PlayerBuildData:CacheRogueBuild(mapBuildInfo)
self:CreateBuildBriefData(mapBuildInfo.Brief)
self:CreateBuildDetailData(mapBuildInfo.Brief.Id, mapBuildInfo.Detail)
end
function PlayerBuildData:GetBuildBriefDataCallback(callBack)
local ret = {}
for _, mapBuild in pairs(self._MapBuildData) do
table.insert(ret, mapBuild)
end
callBack(ret, self._MapBuildData)
end
function PlayerBuildData:GetBuildDetailDataCallback(callBack, nBuildId)
callBack(self._MapBuildData[nBuildId])
end
function PlayerBuildData:GetBuildCountCallBack(callBack)
local ret = 0
for _, _ in pairs(self._MapBuildData) do
ret = ret + 1
end
callBack(ret)
end
function PlayerBuildData:NetMsg_GetBuildBriefData(func, ...)
local arg = {
...
}
local MsgCallBack = function(_, msgData)
self.hasData = true
for _, mapBuild in ipairs(msgData.Briefs) do
self:CreateBuildBriefData(mapBuild)
end
func(self, table.unpack(arg))
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_brief_list_get_req, {}, nil, MsgCallBack)
end
function PlayerBuildData:NetMsg_GetBuildDetailData(nBuildId, func, ...)
local arg = {
...
}
local MsgCallBack = function(_, msgData)
self._MapBuildData[nBuildId].tbSecondarySkill = msgData.Detail.ActiveSecondaryIds
for _, v in ipairs(msgData.Detail.Potentials) do
local potentialCfg = ConfigTable.GetData("Potential", v.PotentialId)
if potentialCfg then
local nCharId = potentialCfg.CharId
if nil == self._MapBuildData[nBuildId].tbPotentials[nCharId] then
self._MapBuildData[nBuildId].tbPotentials[nCharId] = {}
end
table.insert(self._MapBuildData[nBuildId].tbPotentials[nCharId], {
nPotentialId = v.PotentialId,
nLevel = v.Level
})
end
end
local tbNotes = {}
for _, v in pairs(msgData.Detail.SubNoteSkills) do
tbNotes[v.Tid] = v.Qty
end
self._MapBuildData[nBuildId].tbNotes = tbNotes
self._MapBuildData[nBuildId].bDetail = true
func(self, table.unpack(arg))
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_detail_get_req, {BuildId = nBuildId}, nil, MsgCallBack)
end
function PlayerBuildData:NetMsg_ChangeBuildName(nBuildId, sName, callback)
local msg = {BuildId = nBuildId, Name = sName}
local callBack = function()
self._MapBuildData[nBuildId].sName = sName
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_name_set_req, msg, nil, callBack)
end
function PlayerBuildData:NetMsg_ChangeBuildLock(nBuildId, bLock, callback)
local msg = {BuildId = nBuildId, Lock = bLock}
local callBack = function()
self._MapBuildData[nBuildId].bLock = bLock
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_lock_unlock_req, msg, nil, callBack)
end
function PlayerBuildData:NetMsg_BuildDelete(tbBuildId, callback, cbClose)
local msg = {BuildIds = tbBuildId}
local callBack = function(_, mapMainData)
for _, bBuildId in ipairs(tbBuildId) do
self._MapBuildData[bBuildId] = nil
end
UTILS.OpenReceiveByChangeInfo(mapMainData.Change, cbClose)
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_delete_req, msg, nil, callBack)
end
function PlayerBuildData:NetMsg_BuildPreference(tbCheckInIds, tbCheckOutIds, callback)
local msg = {CheckInIds = tbCheckInIds, CheckOutIds = tbCheckOutIds}
local callBack = function()
for _, bBuildId in ipairs(tbCheckInIds) do
self._MapBuildData[bBuildId].bPreference = true
end
for _, bBuildId in ipairs(tbCheckOutIds) do
self._MapBuildData[bBuildId].bPreference = false
end
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_preference_set_req, msg, nil, callBack)
end
function PlayerBuildData:NetMsg_SaveBuild(nBuildID, bDelete, bLock, bPreference, sName, callback)
local msg = {}
msg.Delete = bDelete
msg.Lock = bLock
msg.Preference = bPreference
msg.BuildName = sName
local callBack = function(_, mapMainData)
if callback ~= nil then
if bDelete then
self._MapBuildData[nBuildID] = nil
else
self._MapBuildData[nBuildID].bLock = bLock
self._MapBuildData[nBuildID].bPreference = bPreference
self._MapBuildData[nBuildID].sName = sName
end
callback(mapMainData.Change)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_build_whether_save_req, msg, nil, callBack)
end
function PlayerBuildData:CreateTrialBuild(nTrialId)
self._mapTrialBuild = {}
local mapTrialData = ConfigTable.GetData("TrialBuild", nTrialId)
if mapTrialData == nil then
printError("试用编组数据没有找到:" .. nTrialId)
return
end
self._mapTrialBuild = {
nBuildId = nTrialId,
sName = mapTrialData.Name,
tbChar = {},
nScore = mapTrialData.Score,
mapRank = self:CalBuildRank(mapTrialData.Score),
bLock = false,
bPreference = false,
bDetail = true,
tbDisc = {},
tbSecondarySkill = {},
tbPotentials = {},
tbNotes = {},
nTowerId = 0
}
local tbCharTrialId = {}
for _, v in ipairs(mapTrialData.Char) do
table.insert(self._mapTrialBuild.tbChar, {
nTrialId = v,
nTid = 0,
nPotentialCount = 0
})
table.insert(tbCharTrialId, v)
end
self._mapTrialBuild.tbDisc = mapTrialData.Disc
self._mapTrialBuild.tbSecondarySkill = mapTrialData.ActiveSecondaryIds
local tbPotentials = decodeJson(mapTrialData.Potential)
for _, v in pairs(tbPotentials) do
local potentialCfg = ConfigTable.GetData("Potential", v.Tid)
if potentialCfg then
local nCharId = potentialCfg.CharId
if not self._mapTrialBuild.tbPotentials[nCharId] then
self._mapTrialBuild.tbPotentials[nCharId] = {}
end
table.insert(self._mapTrialBuild.tbPotentials[nCharId], {
nPotentialId = v.Tid,
nLevel = v.Level
})
end
end
local tbNoteJson = decodeJson(mapTrialData.Note)
local tbNotes = {}
for _, v in pairs(tbNoteJson) do
tbNotes[v.Id] = v.Qty
end
self._mapTrialBuild.tbNotes = tbNotes
PlayerData.Char:CreateTrialChar(tbCharTrialId)
PlayerData.Disc:CreateTrialDisc(mapTrialData.Disc)
for k, v in pairs(self._mapTrialBuild.tbChar) do
local mapTrialChar = PlayerData.Char:GetTrialCharById(v.nTrialId)
self._mapTrialBuild.tbChar[k].nTid = mapTrialChar ~= nil and mapTrialChar.nId or 0
end
return self._mapTrialBuild
end
function PlayerBuildData:DeleteTrialBuild()
self._mapTrialBuild = {}
PlayerData.Char:DeleteTrialChar()
PlayerData.Disc:DeleteTrialDisc()
end
function PlayerBuildData:GetTrialBuild(nTrialId)
if self._mapTrialBuild then
if self._mapTrialBuild.nBuildId == nTrialId then
return self._mapTrialBuild
else
self:DeleteTrialBuild()
end
end
return self:CreateTrialBuild(nTrialId)
end
function PlayerBuildData:GetTrialBuildAllEft()
local ret = {}
local mapBuildData = self._mapTrialBuild
if mapBuildData == nil or not mapBuildData.bDetail then
print("没有对应build 或未获取该build详细数据")
return ret
end
local mapCharEffect = {}
local mapTalentAddLevel = {}
for _, mapChar in ipairs(mapBuildData.tbChar) do
mapCharEffect[mapChar.nTid] = {}
mapCharEffect[mapChar.nTid][AllEnum.EffectType.Talent] = PlayerData.Talent:GetTrialTalentEffect(mapChar.nTrialId)
mapTalentAddLevel[mapChar.nTid] = PlayerData.Talent:GetTrialEnhancedPotential(mapChar.nTrialId)
end
local tbCharIdToTrial = {}
for _, mapChar in ipairs(mapBuildData.tbChar) do
tbCharIdToTrial[mapChar.nTid] = mapChar.nTrialId
end
for nCharId, tbPerk in pairs(mapBuildData.tbPotentials) do
if tbCharIdToTrial[nCharId] then
for _, mapPerkInfo in ipairs(tbPerk) do
local nPotentialId = mapPerkInfo.nPotentialId
local nPotentialCount = mapPerkInfo.nLevel
if mapTalentAddLevel[nCharId] ~= nil and mapTalentAddLevel[nCharId][nPotentialId] ~= nil then
nPotentialCount = nPotentialCount + mapTalentAddLevel[nCharId][nPotentialId]
end
if mapCharEffect[nCharId][AllEnum.EffectType.Potential] == nil then
mapCharEffect[nCharId][AllEnum.EffectType.Potential] = {}
end
local mapPotentialCfgData = ConfigTable.GetData("Potential", nPotentialId)
if mapPotentialCfgData == nil then
printError("Potential CfgData Missing:" .. nPotentialId)
else
mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId] = {
{},
nPotentialCount
}
if mapPotentialCfgData.EffectId1 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId1)
end
if mapPotentialCfgData.EffectId2 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId2)
end
if mapPotentialCfgData.EffectId3 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId3)
end
if mapPotentialCfgData.EffectId4 ~= 0 then
table.insert(mapCharEffect[nCharId][AllEnum.EffectType.Potential][nPotentialId][1], mapPotentialCfgData.EffectId4)
end
end
end
else
printError("体验build内,有多余角色的潜能" .. nCharId)
end
end
local mapDiscEffect = {}
for nIndex, nTrialDiscId in ipairs(mapBuildData.tbDisc) do
if nIndex <= 3 then
local tbDiscEft = PlayerData.Disc:CalcTrialEffectInBuild(nTrialDiscId, mapBuildData.tbSecondarySkill)
mapDiscEffect[nTrialDiscId] = tbDiscEft
end
end
local tbNoteInfo, mapNoteEffect = {}, {}
for i, v in pairs(mapBuildData.tbNotes) do
local noteInfo = CS.Lua2CSharpInfo_NoteInfo()
noteInfo.noteId = i
noteInfo.noteCount = v
table.insert(tbNoteInfo, noteInfo)
local mapCfg = ConfigTable.GetData("SubNoteSkill", i)
if mapCfg then
local tbEft = {}
for _, nEftId in pairs(mapCfg.EffectId) do
table.insert(tbEft, {nEftId, v})
end
mapNoteEffect[i] = tbEft
end
end
return mapCharEffect, mapDiscEffect, mapNoteEffect, tbNoteInfo
end
function PlayerBuildData:SetBuildReportInfo(nBuildId)
local mapDetailData = self._MapBuildData[nBuildId]
if mapDetailData == nil or not self._MapBuildData[nBuildId].bDetail then
printError("No Build Detail Data")
return
end
local tbNotes = {}
for nTid, nQty in pairs(mapDetailData.tbNotes) do
table.insert(tbNotes, {nTid, nQty})
end
local tbSkills = mapDetailData.tbSecondarySkill
local tbDiscData = {}
for _, nDiscId in ipairs(mapDetailData.tbDisc) do
local stBuildDisc = CS.BuildDiscData()
stBuildDisc.discId = nDiscId
local mapDiscData = PlayerData.Disc:GetDiscById(nDiscId)
if mapDetailData ~= nil then
stBuildDisc.level = mapDiscData.nLevel
stBuildDisc.breakCount = mapDiscData.nStar
stBuildDisc.advance = mapDiscData.nPhase
end
table.insert(tbDiscData, stBuildDisc)
end
local tbCharData = {}
for _, mapChar in ipairs(mapDetailData.tbChar) do
local stBuildCharData = CS.BuildCharData()
stBuildCharData.charId = mapChar.nTid
local tbEquipment = PlayerData.Equipment:GetCharEquipmentEffect(mapChar.nTid)
stBuildCharData.equipmentEffects = tbEquipment
local tbPotentials = {}
if mapDetailData.tbPotentials[mapChar.nTid] ~= nil then
for _, mapPotential in ipairs(mapDetailData.tbPotentials[mapChar.nTid]) do
table.insert(tbPotentials, {
mapPotential.nPotentialId,
mapPotential.nLevel
})
end
end
stBuildCharData.potentialIds = tbPotentials
table.insert(tbCharData, stBuildCharData)
end
NovaAPI.SetBuildReportInfo(nBuildId, mapDetailData.sName or "", tbCharData, tbDiscData, tbSkills, tbNotes)
end
return PlayerBuildData
@@ -0,0 +1,13 @@
local PlayerCampingData = class("PlayerCampingData")
local Actor2DManager = require("Game.Actor2D.Actor2DManager")
function PlayerCampingData:Init()
EventManager.Add("OnEvent_CampingEnter", self, self.OnEvent_CampingEnter)
EventManager.Add("OnEvent_CampingLevelLoadComplete", self, self.LevelLoadComplete)
end
function PlayerCampingData:OnEvent_CampingEnter()
NovaAPI.EnterModule("CampingModuleScene", true)
end
function PlayerCampingData:LevelLoadComplete()
EventManager.Hit(EventId.OpenPanel, PanelId.CampingJoystick)
end
return PlayerCampingData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,86 @@
local PlayerHandbookData = PlayerData.Handbook
local PlayerCharSkinData = class("PlayerCharSkinData")
local TimerManager = require("GameCore.Timer.TimerManager")
local TimerScaleType = require("GameCore.Timer.TimerScaleType")
local LocalData = require("GameCore.Data.LocalData")
local RapidJson = require("rapidjson")
local ClientManager = CS.ClientManager.Instance
local tableInsert = table.insert
local tableRemove = table.remove
local SkinData = require("GameCore.Data.DataClass.SkinData")
function PlayerCharSkinData:Init()
self.tbSkinDataList = {}
self.tbSkinGainQueue = {}
end
function PlayerCharSkinData:UpdateSkinData(skinId, handbookId, unlock)
if nil == self.tbSkinDataList[skinId] then
local skinData = SkinData.new(skinId, handbookId, unlock)
self.tbSkinDataList[skinId] = skinData
else
self.tbSkinDataList[skinId]:UpdateUnlockState(unlock)
end
end
function PlayerCharSkinData:GetSkinListByCharacterId(charId)
local tbSkinList = {}
for skinId, skin in pairs(self.tbSkinDataList) do
if skin:GetCharId() == charId then
tbSkinList[skinId] = skin
end
end
return tbSkinList
end
function PlayerCharSkinData:GetSkinDataBySkinId(skinId)
return self.tbSkinDataList[skinId]
end
function PlayerCharSkinData:CheckSkinUnlock(skinId)
if self.tbSkinDataList[skinId] ~= nil then
return self.tbSkinDataList[skinId]:CheckUnlock()
end
return false
end
function PlayerCharSkinData:SkinGainEnqueue(mapMsgData)
local bNew = nil ~= mapMsgData.New
local nSkinId = nil ~= mapMsgData.New and mapMsgData.New.Value or mapMsgData.Duplicated.ID
local tbItemList = {}
if nil ~= mapMsgData.Duplicated then
tbItemList = mapMsgData.Duplicated.Items
end
local tbData = {
nId = nSkinId,
bNew = bNew,
tbItemList = tbItemList or {}
}
tableInsert(self.tbSkinGainQueue, tbData)
end
function PlayerCharSkinData:RemoveSkinQueue(nId)
for i = #self.tbSkinGainQueue, 1, -1 do
if self.tbSkinGainQueue[i].nId == nId then
tableRemove(self.tbSkinGainQueue, i)
end
end
end
function PlayerCharSkinData:TryOpenSkinShowPanel(callback)
if #self.tbSkinGainQueue == 0 then
if callback ~= nil then
callback()
end
return false
end
EventManager.Hit(EventId.OpenPanel, PanelId.ReceiveSpecialReward, self.tbSkinGainQueue, callback)
return true
end
function PlayerCharSkinData:CheckNewSkin()
return #self.tbSkinGainQueue > 0
end
function PlayerCharSkinData:GetSkinForReward()
local tbSpReward = {}
if #self.tbSkinGainQueue == 0 then
return tbSpReward
end
tbSpReward = clone(self.tbSkinGainQueue)
self.tbSkinGainQueue = {}
return tbSpReward
end
function PlayerCharSkinData:UpdateSkinUnlock(unlockList)
end
return PlayerCharSkinData
@@ -0,0 +1,52 @@
local PlayerCoinData = class("PlayerCoinData")
function PlayerCoinData:Init()
self._mapCoin = nil
end
function PlayerCoinData:CacheCoin(mapData)
if self._mapCoin == nil then
self._mapCoin = {}
end
for _, mapCoinInfo in ipairs(mapData) do
self._mapCoin[mapCoinInfo.Tid] = mapCoinInfo.Qty
end
end
function PlayerCoinData:GetCoinCount(nCoinItemId)
if type(self._mapCoin) == "table" then
local nCoinCount = self._mapCoin[nCoinItemId]
if type(nCoinCount) == "number" then
return nCoinCount
else
self._mapCoin[nCoinItemId] = 0
return 0
end
else
self._mapCoin = {}
self._mapCoin[nCoinItemId] = 0
return 0
end
end
function PlayerCoinData:ChangeCoin(mapCoinChange)
if type(mapCoinChange) == "table" then
for i, v in ipairs(mapCoinChange) do
local nCoinItemId = v.Tid
local nChangeCount = v.Qty
local nCurCount = self:GetCoinCount(nCoinItemId)
self._mapCoin[nCoinItemId] = nCurCount + nChangeCount
EventManager.Hit(EventId.CoinResChange, nCoinItemId, nCurCount, nChangeCount)
if nCoinItemId == AllEnum.CoinItemId.STONE then
EventManager.Hit(EventId.CoinResChange, AllEnum.CoinItemId.FREESTONE)
end
end
end
end
function PlayerCoinData:SendGemConvertReqReq(nCount, callback)
local mapMsg = {Value = nCount}
local successCallback = function(_, mapData)
if callback then
callback(mapData)
end
UTILS.OpenReceiveByChangeInfo(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.gem_convert_req, mapMsg, nil, successCallback)
end
return PlayerCoinData
@@ -0,0 +1,128 @@
local PlayerCraftingData = class("PlayerCraftingData")
function PlayerCraftingData:Init()
self:InitCfgData()
end
function PlayerCraftingData:InitCfgData()
local foreachProduction = function(line)
local lineData = line
local tbMaterialList = {}
for i = 1, 4 do
local nMtId = line["RawMaterialId" .. i]
local nMtCount = line["RawMaterialCount" .. i]
if 0 < nMtId then
local tbMtInfo = {nItemId = nMtId, nCount = nMtCount}
table.insert(tbMaterialList, tbMtInfo)
end
end
line.MaterialList = tbMaterialList
CacheTable.InsertData("_ProductionPage", line.Tag, lineData)
CacheTable.InsertData("_ProductionGroup", line.Group, lineData)
CacheTable.SetData("_Production", line.Id, lineData)
end
ForEachTableLine(DataTable.Production, foreachProduction)
end
function PlayerCraftingData:GetProductionListByPage(nPageType)
local productionList = {}
local nWorldClass = PlayerData.Base:GetWorldClass()
local tbList = CacheTable.GetData("_ProductionPage", nPageType)
if nil ~= tbList then
for _, v in ipairs(tbList) do
if v.IsActivated and nWorldClass >= v.IsShowWorldLevel then
table.insert(productionList, v)
end
end
end
table.sort(productionList, function(a, b)
if a.SortId == b.SortId then
return a.Id < b.Id
end
return a.SotId < b.SortId
end)
return productionList
end
function PlayerCraftingData:GetProductionPageList()
local tbPageList = {}
local nWorldClass = PlayerData.Base:GetWorldClass()
local _ProductionPage = CacheTable.Get("_ProductionPage") or {}
for type, list in pairs(_ProductionPage) do
if nil ~= list and nil ~= next(list) then
local tbList = {}
for _, v in ipairs(list) do
if v.IsActived and nWorldClass >= v.IsShowWorldLevel then
table.insert(tbList, v)
end
end
table.sort(tbList, function(a, b)
if a.SortId == b.SortId then
return a.Id > b.Id
end
return a.SortId < b.SortId
end)
if nil ~= next(tbList) then
local tbPage = {}
tbPage.nType = type
local typeCfg = ConfigTable.GetData("ProductionType", type)
tbPage.nSortId = typeCfg.SortId
tbPage.tbList = tbList
table.insert(tbPageList, tbPage)
end
end
end
table.sort(tbPageList, function(a, b)
if a.nSortId == b.nSortId then
return a.nType < b.nType
end
return a.nSortId < b.nSortId
end)
return tbPageList
end
function PlayerCraftingData:GetProductionById(nId)
return CacheTable.GetData("_Production", nId)
end
function PlayerCraftingData:CheckProductionUnlock(nProductionId)
local bUnlock = false
local tbCfg = ConfigTable.GetData("Production", nProductionId)
if nil ~= tbCfg and tbCfg.IsActived then
local nWorldClass = PlayerData.Base:GetWorldClass()
bUnlock = nWorldClass >= tbCfg.IsShowWorldLevel and nWorldClass >= tbCfg.UnlockWorldLevel
end
return bUnlock
end
function PlayerCraftingData:GetProductionListByGroup(nGroupId)
local tbGroupList = {}
local tbList = CacheTable.GetData("_ProductionGroup", nGroupId)
if nil ~= tbList then
local nWorldClass = PlayerData.Base:GetWorldClass()
for _, v in ipairs(tbList) do
if v.IsActived and nWorldClass >= v.IsShowWorldLevel then
table.insert(tbGroupList, v)
end
end
end
table.sort(tbGroupList, function(a, b)
if a.SortId == b.SortId then
return a.Id > b.Id
end
return a.SortId < b.SortId
end)
return tbGroupList
end
function PlayerCraftingData:SendMaterialCrafting(nProductionId, nCount, callback)
local successCallback = function(MsgSend, mapMsgData)
UTILS.OpenReceiveByChangeInfo(mapMsgData)
if nil ~= callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.item_product_req, {Id = nProductionId, Num = nCount}, nil, successCallback)
end
function PlayerCraftingData:SendPresentsCrafting(nProductionId, tbMatList, callback)
local successCallback = function(MsgSend, mapMsgData)
UTILS.OpenReceiveByChangeInfo(mapMsgData)
if nil ~= callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.presents_crafting_req, {Id = nProductionId, PresentsIds = tbMatList}, nil, successCallback)
end
return PlayerCraftingData
@@ -0,0 +1,115 @@
local TimerManager = require("GameCore.Timer.TimerManager")
local TimerScaleType = require("GameCore.Timer.TimerScaleType")
local ClientManager = CS.ClientManager.Instance
local _bManual = false
local _nDailyCheckInIndex = 0
local templateDailyCheckInData
local ProcessMonthlyCard = function(mapMsgData)
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(mapMsgData.Change)
local nEndTime = mapMsgData.EndTime
local nId = mapMsgData.Id
local mapNext = {
mapReward = mapReward,
nEndTime = nEndTime,
nRemaining = mapMsgData.Remaining,
nId = nId
}
PopUpManager.PopUpEnQueue(GameEnum.PopUpSeqType.MonthlyCard, mapNext)
end
local CacheDailyCheckIn = function(nIndex)
if nIndex == nil then
return
end
_nDailyCheckInIndex = nIndex
end
local ProcessDailyCheckIn = function(mapMsgData)
_nDailyCheckInIndex = mapMsgData.Index
if not PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.SignIn) then
templateDailyCheckInData = mapMsgData
return
end
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(mapMsgData.Change)
PopUpManager.PopUpEnQueue(GameEnum.PopUpSeqType.DailyCheckIn, mapReward)
end
local CheckDailyCheckIn = function()
local bOpen = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.SignIn)
if templateDailyCheckInData ~= nil and bOpen then
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(templateDailyCheckInData.Change)
PopUpManager.PopUpEnQueue(GameEnum.PopUpSeqType.DailyCheckIn, mapReward)
templateDailyCheckInData = nil
end
end
local GetDailyCheckInList = function(nDays)
local tbReward = CacheTable.GetData("_SignIn", nDays)
if not tbReward then
printError("当前月的天数是" .. nDays .. ",没有相关配置,拿31天的数据顶了")
tbReward = CacheTable.GetData("_SignIn", 31)
end
return tbReward
end
local GetMonthAndDays = function()
local nServerTimeStampWithTimeZone = ClientManager.serverTimeStampWithTimeZone
local nYear = tonumber(os.date("!%Y", nServerTimeStampWithTimeZone))
local nMonth = tonumber(os.date("!%m", nServerTimeStampWithTimeZone))
local nDay = tonumber(os.date("!%d", nServerTimeStampWithTimeZone))
local nHour = tonumber(os.date("!%H", nServerTimeStampWithTimeZone))
if nDay == 1 and nHour < 5 then
nMonth = nMonth == 1 and 12 or nMonth - 1
end
local nNextMonthTime = os.time({
year = tostring(nYear),
month = nMonth + 1,
day = 0
})
local nDays = tonumber(os.date("!%d", nNextMonthTime))
return nMonth, nDays
end
local GetDailyCheckInIndex = function()
if _nDailyCheckInIndex == 0 then
printError("签到:没有签到数据,不知道是签到第几天")
end
return _nDailyCheckInIndex
end
local ProcessTableData = function()
local _SignIn = {}
local func_ForEach = function(mapLineData)
local mapLine = {
ItemId = mapLineData.ItemId,
ItemQty = mapLineData.ItemQty
}
if not _SignIn[mapLineData.Group] then
_SignIn[mapLineData.Group] = {}
end
_SignIn[mapLineData.Group][mapLineData.Day] = mapLine
end
ForEachTableLine(DataTable.SignIn, func_ForEach)
CacheTable.Set("_SignIn", _SignIn)
end
local Init = function()
_bManual = false
_nDailyCheckInIndex = 0
ProcessTableData()
end
local UnInit = function()
_bManual = false
_nDailyCheckInIndex = 0
end
local CacheDailyData = function(nIndex)
CacheDailyCheckIn(nIndex)
end
local SetManualPanel = function(state)
_bManual = state
end
local PlayerDailyData = {
Init = Init,
UnInit = UnInit,
GetMonthAndDays = GetMonthAndDays,
GetDailyCheckInIndex = GetDailyCheckInIndex,
GetDailyCheckInList = GetDailyCheckInList,
SetManualPanel = SetManualPanel,
CacheDailyData = CacheDailyData,
ProcessMonthlyCard = ProcessMonthlyCard,
ProcessDailyCheckIn = ProcessDailyCheckIn,
CheckDailyCheckIn = CheckDailyCheckIn
}
return PlayerDailyData
@@ -0,0 +1,418 @@
local PlayerDailyInstanceData = class("PlayerDailyInstanceData")
local LocalData = require("GameCore.Data.LocalData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
local SDKManager = CS.SDKManager.Instance
function PlayerDailyInstanceData:Init()
self.curLevel = nil
self.mapAllLevel = {}
self.bInSettlement = false
self.tbLastMaxHard = {}
self.mapLevelCfg = {}
self:InitConfigData()
EventManager.Add("Daily_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function PlayerDailyInstanceData:OnEvent_Time(nTime)
self._TotalTime = nTime
end
function PlayerDailyInstanceData:InitConfigData()
local funcForeachLine = function(line)
if nil == self.mapLevelCfg[line.DailyType] then
self.mapLevelCfg[line.DailyType] = {}
end
self.mapLevelCfg[line.DailyType][line.Id] = line
end
ForEachTableLine(DataTable.DailyInstance, funcForeachLine)
end
function PlayerDailyInstanceData:EnterDailyInstanceEditor(nFloor, tbChar, tbDisc, tbNote)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.DailyInstance.DailyInstanceEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nFloor, tbChar, tbDisc, tbNote)
end
end
function PlayerDailyInstanceData:EnterDailyInstance(nLevelId, nBuildId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.DailyInstance.DailyInstanceLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId)
end
end
function PlayerDailyInstanceData:SetSelBuildId(nBuildId)
self.selBuildId = nBuildId
end
function PlayerDailyInstanceData:GetCachedBuildId(nLevelId)
if PlayerData.Guide:GetGuideState() then
if self.selBuildId ~= 0 and self.selBuildId ~= nil then
local ret = self.selBuildId
return ret
end
return 0
end
if self.selBuildId ~= 0 and self.selBuildId ~= nil then
local ret = self.selBuildId
return ret
end
if nLevelId == 0 then
return 0
end
if self.mapAllLevel[nLevelId] == nil then
local mapLevelCfgData = ConfigTable.GetData("DailyInstance", nLevelId)
if mapLevelCfgData == nil then
return 0
end
if mapLevelCfgData.PreLevelId ~= 0 then
if self.mapAllLevel[mapLevelCfgData.PreLevelId] ~= nil then
return self.mapAllLevel[mapLevelCfgData.PreLevelId].nBuildId
else
return 0
end
else
return 0
end
end
return self.mapAllLevel[nLevelId].nBuildId
end
function PlayerDailyInstanceData:CacheDailyInstanceLevel(tbData)
if tbData == nil then
return
end
for _, mapData in ipairs(tbData) do
local b1 = 1
local b2 = 2
local b3 = 4
local t1 = mapData.Star & b1 > 0
local t2 = mapData.Star & b2 > 0
local t3 = mapData.Star & b3 > 0
local nStar = self.CalStar(mapData.Star)
self.mapAllLevel[mapData.Id] = {
nStar = nStar,
nBuildId = mapData.BuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
end
function PlayerDailyInstanceData:GetDailyInstanceLevelUnlock(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("DailyInstance", nLevelId)
if mapLevelCfgData == nil then
return false
end
if mapLevelCfgData.PreLevelId == 0 then
return true
end
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
return false, mapLevelCfgData.NeedWorldClass
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil then
return false
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar >= mapLevelCfgData.PreLevelStar then
return true
end
return false
end
function PlayerDailyInstanceData:GetDailyInstanceUnlockMsg(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("DailyInstance", nLevelId)
if mapLevelCfgData.PreLevelId == 0 then
return true
end
local isWorldClass = true
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
isWorldClass = false
end
local isPreLevelStar = true
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil or self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar < mapLevelCfgData.PreLevelStar then
isPreLevelStar = false
end
if isWorldClass == false or isPreLevelStar == false then
return false, isWorldClass, isPreLevelStar
end
return true
end
function PlayerDailyInstanceData:GetDailyInstanceStar(nLevelId)
if nLevelId == nil then
return 0, {
false,
false,
false
}
end
if self.mapAllLevel[nLevelId] == nil then
return 0, {
false,
false,
false
}
end
return self.mapAllLevel[nLevelId].nStar, self.mapAllLevel[nLevelId].tbTarget == nil and {
false,
false,
false
} or self.mapAllLevel[nLevelId].tbTarget
end
function PlayerDailyInstanceData:MsgEnterDailyInstance(nLevelId, nBuildId, callback)
local msg = {}
msg.Id = nLevelId
msg.BuildId = nBuildId
msg.RewardType = self.lastRewardType
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local msgCallback = function()
self:EnterDailyInstance(nLevelId, nBuildId)
if self.mapAllLevel[nLevelId] == nil then
self.mapAllLevel[nLevelId] = {nStar = 0, nBuildId = 0}
end
self.mapAllLevel[nLevelId].nBuildId = nBuildId
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.daily_instance_apply_req, msg, nil, msgCallback)
end
function PlayerDailyInstanceData:MsgSettleDailyInstance(nLevelId, nBuildId, nStar, callback)
if nStar == 0 then
if callback ~= nil then
callback({}, {}, {})
end
if PlayerData.Guide:GetGuideState() then
EventManager.Hit("Guide_DailyInstance_Fail")
end
self:EventUpload(2, nLevelId, nBuildId)
return
end
local msg = {}
msg.Star = nStar
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.DailyInstance, 0 < nStar)
}
local msgCallback = function(_, mapMsgData)
local b1 = 1
local b2 = 2
local b3 = 4
local t1 = 0 < nStar & b1
local t2 = 0 < nStar & b2
local t3 = 0 < nStar & b3
local nStarCount = (t1 and 1 or 0) + (t2 and 1 or 0) + (t3 and 1 or 0)
if self.mapAllLevel[nLevelId] ~= nil then
if nStarCount > self.mapAllLevel[nLevelId].nStar then
self.mapAllLevel[nLevelId].nStar = nStarCount
end
if self.mapAllLevel[nLevelId].tbTarget == nil then
self.mapAllLevel[nLevelId].tbTarget = {
false,
false,
false
}
end
self.mapAllLevel[nLevelId].tbTarget[1] = t1 or self.mapAllLevel[nLevelId].tbTarget[1]
self.mapAllLevel[nLevelId].tbTarget[2] = t2 or self.mapAllLevel[nLevelId].tbTarget[2]
self.mapAllLevel[nLevelId].tbTarget[3] = t3 or self.mapAllLevel[nLevelId].tbTarget[3]
else
self.mapAllLevel[nLevelId] = {
nStar = nStar,
nBuildId = nBuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
if callback ~= nil then
callback(mapMsgData.Select, mapMsgData.First, mapMsgData.Exp, mapMsgData.Change)
end
self:EventUpload(1, nLevelId, nBuildId)
end
HttpNetHandler.SendMsg(NetMsgId.Id.daily_instance_settle_req, msg, nil, msgCallback)
if PlayerData.Guide:GetGuideState() then
EventManager.Hit("Guide_DailyInstance_Settle")
end
end
function PlayerDailyInstanceData:EventUpload(result, nLevelId, nBuildId)
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self._TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(nBuildId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(nLevelId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
NovaAPI.UserEventUpload("daily_instance_battle", tabUpLevel)
end
function PlayerDailyInstanceData:LevelEnd()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerDailyInstanceData.CalStar(nOrigin)
nOrigin = (nOrigin & 1431655765) + (nOrigin >> 1 & 1431655765)
nOrigin = (nOrigin & 858993459) + (nOrigin >> 2 & 858993459)
nOrigin = (nOrigin & 252645135) + (nOrigin >> 4 & 252645135)
nOrigin = nOrigin * 16843009 >> 24
return nOrigin
end
function PlayerDailyInstanceData:GetCurLevel()
if self.curLevel == nil then
return 0
end
return self.curLevel.nLevelId
end
function PlayerDailyInstanceData:SetLastMaxHard(nGroupId, nMaxHard)
self.tbLastMaxHard[nGroupId] = nMaxHard
end
function PlayerDailyInstanceData:GetLastMaxHard(nGroupId)
return self.tbLastMaxHard[nGroupId] or 0
end
function PlayerDailyInstanceData:GetMaxDailyInstanceHard(nType)
local retHard = 1
local tbLevelList = self.mapLevelCfg[nType]
if nil ~= tbLevelList then
for nLevelId, mapLevel in pairs(tbLevelList) do
if self:GetDailyInstanceLevelUnlock(nLevelId) then
retHard = math.max(mapLevel.Difficulty, retHard)
end
end
end
return retHard
end
function PlayerDailyInstanceData:GetLevelOpenState(nType)
nType = GameEnum.dailyType.Common
local mapData = ConfigTable.GetData("DailyInstanceType", nType)
if nil ~= mapData then
local bMainLine = true
if mapData.MainLineId > 0 then
local nStar = PlayerData.Mainline:GetMianlineLevelStar(mapData.MainLineId)
bMainLine = 0 < nStar
end
local worldClass = PlayerData.Base:GetWorldClass()
local bWorldClass = worldClass >= mapData.WorldClassLevel
local bUnlock = bMainLine and bWorldClass
if not bMainLine then
return AllEnum.DailyInstanceState.Not_MainLine, bUnlock
end
if not bWorldClass then
return AllEnum.DailyInstanceState.Not_WorldClass, bUnlock
end
return AllEnum.DailyInstanceState.Open, bUnlock
end
return AllEnum.DailyInstanceState.None
end
function PlayerDailyInstanceData:GetUnOpenTipText(nLevelState, nType)
nType = GameEnum.dailyType.Common
local sTipStr
if nLevelState == AllEnum.DailyInstanceState.Not_MainLine then
local mapData = ConfigTable.GetData("DailyInstanceType", nType)
local mapLevelData = ConfigTable.GetData_Mainline(mapData.MainLineId)
if mapLevelData ~= nil then
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock") or "", mapLevelData.Num, mapLevelData.Name)
else
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock") or "", tostring(mapData.MainLineId), "")
end
elseif nLevelState == AllEnum.DailyInstanceState.Not_WorldClass then
local mapData = ConfigTable.GetData("DailyInstanceType", nType)
sTipStr = orderedFormat(ConfigTable.GetUIText("WorldClass_Lock") or "", mapData.WorldClassLevel)
elseif nLevelState == AllEnum.DailyInstanceState.Not_HardUnlock then
sTipStr = ConfigTable.GetUIText("Level_Lock")
end
return sTipStr or ""
end
function PlayerDailyInstanceData:CheckLevelOpen(nType, nHard, bShowTips)
if nType == 0 then
return AllEnum.DailyInstanceState.Open
end
local nLevelState, bUnlock = self:GetLevelOpenState(nType)
if nil ~= nHard and nLevelState == AllEnum.DailyInstanceState.Open then
local nMaxUnlockHard = self:GetMaxDailyInstanceHard(nType)
if nHard > nMaxUnlockHard then
nLevelState = AllEnum.DailyInstanceState.Not_HardUnlock
end
end
if true == bShowTips then
local sTipStr = self:GetUnOpenTipText(nLevelState, nType)
if nil ~= sTipStr and "" ~= sTipStr then
EventManager.Hit(EventId.OpenMessageBox, sTipStr)
end
end
return nLevelState == AllEnum.DailyInstanceState.Open, bUnlock
end
function PlayerDailyInstanceData:SetSettlementState(bInSettlement)
self.bInSettlement = bInSettlement
end
function PlayerDailyInstanceData:GetSettlementState()
return self.bInSettlement
end
function PlayerDailyInstanceData:GetLastRewardType()
if self.lastRewardType == nil then
local lastType = LocalData.GetPlayerLocalData("DailyRewardType")
if lastType == nil then
self:SetRewardType(GameEnum.DailyRewardType.CharExp)
else
self.lastRewardType = lastType
end
end
return tonumber(self.lastRewardType)
end
function PlayerDailyInstanceData:SetRewardType(nType)
self.lastRewardType = nType
LocalData.SetPlayerLocalData("DailyRewardType", nType)
end
function PlayerDailyInstanceData:SendDailyInstanceRaidReq(nId, nCount, callback)
local Events = {}
local msgData = {
Id = nId,
RewardType = self.lastRewardType,
Times = nCount
}
if 0 < #Events then
msgData.Events = {
List = {}
}
msgData.Events.List = Events
end
local successCallback = function(_, mapMainData)
callback(mapMainData.Rewards, mapMainData.Change)
end
HttpNetHandler.SendMsg(NetMsgId.Id.daily_instance_raid_req, msgData, nil, successCallback)
end
return PlayerDailyInstanceData
@@ -0,0 +1,247 @@
local PlayerDatingData = class("PlayerDatingData")
function PlayerDatingData:Init()
self.tbDatingCharIds = 0
self.nAllDatingCount = 0
self.tbLandmarkCfg = {}
self.mapCharLimitedEvent = {}
self.mapCharStartEvent = {}
self.mapCharEndEvent = {}
self.mapCharLandmark = {}
self.nCurSelectLandmark = 0
self.mapDelay = nil
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
self:InitConfig()
end
function PlayerDatingData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerDatingData:InitConfig()
self.nAllDatingCount = ConfigTable.GetConfigNumber("Dating_Max_Daily_Count")
local funcForeachLandmark = function(mapData)
table.insert(self.tbLandmarkCfg, mapData)
end
ForEachTableLine(DataTable.DatingLandmark, funcForeachLandmark)
local funcForeachCharEvent = function(mapData)
if mapData.DatingEventType == GameEnum.DatingEventType.LimitedLandmark then
local param = decodeJson(mapData.DatingEventParams)
if mapData.DatingEventParams ~= nil and #mapData.DatingEventParams == 2 then
local nCharId = tonumber(mapData.DatingEventParams[1])
local nLandmark = tonumber(mapData.DatingEventParams[2])
if self.mapCharLimitedEvent[nCharId] == nil then
self.mapCharLimitedEvent[nCharId] = {}
end
local data = {
Id = mapData.Id,
LandMark = nLandmark,
Status = AllEnum.DatingEventStatus.Lock
}
self.mapCharLimitedEvent[nCharId][mapData.Id] = data
RedDotManager.SetValid(RedDotDefine.Phone_Dating_Reward, {
nCharId,
mapData.Id
}, false)
if self.mapCharLandmark[nCharId] == nil then
self.mapCharLandmark[nCharId] = {}
end
if self.mapCharLandmark[nCharId][nLandmark] == nil then
self.mapCharLandmark[nCharId][nLandmark] = {}
end
table.insert(self.mapCharLandmark[nCharId][nLandmark], mapData.Id)
end
end
end
ForEachTableLine(ConfigTable.Get("DatingCharacterEvent"), funcForeachCharEvent)
local funcForeachStartEndEvent = function(mapData)
if mapData.DatingEventType == GameEnum.DatingEventType.Start then
local nCharId = tonumber(mapData.DatingEventParams[1])
if self.mapCharStartEvent[nCharId] == nil then
self.mapCharStartEvent[nCharId] = {}
end
table.insert(self.mapCharStartEvent[nCharId], mapData.Id)
elseif mapData.DatingEventType == GameEnum.DatingEventType.End then
local nCharId = tonumber(mapData.DatingEventParams[1])
if self.mapCharEndEvent[nCharId] == nil then
self.mapCharEndEvent[nCharId] = {}
end
table.insert(self.mapCharEndEvent[nCharId], mapData.Id)
end
end
ForEachTableLine(ConfigTable.Get("DatingStartEndEvent"), funcForeachStartEndEvent)
local foreachResponse = function(line)
if nil == CacheTable.GetData("_DatingCharResponse", line.CharId) then
CacheTable.SetData("_DatingCharResponse", line.CharId, {})
end
CacheTable.GetData("_DatingCharResponse", line.CharId)[line.Type] = line
end
ForEachTableLine(DataTable.DatingCharResponse, foreachResponse)
end
function PlayerDatingData:RefreshDatingCharIds(tbChar)
self.tbDatingCharIds = tbChar
end
function PlayerDatingData:AddDatingCharId(nCharId)
for _, v in ipairs(self.tbDatingCharIds) do
if v == nCharId then
printError("重复邀约!!!")
return
end
end
table.insert(self.tbDatingCharIds, nCharId)
end
function PlayerDatingData:CacheDatingCharIds(tbChar)
self.tbDatingCharIds = tbChar
end
function PlayerDatingData:GetRandomLandmark()
if #self.tbLandmarkCfg <= 3 then
return self.tbLandmarkCfg
end
local tbResult = {}
local tbRandom = {}
for i = 1, #self.tbLandmarkCfg do
tbRandom[i] = i
end
for i = 1, 3 do
local randomIndex = math.random(#tbRandom)
local nSelectIndex = tbRandom[randomIndex]
table.insert(tbResult, self.tbLandmarkCfg[nSelectIndex])
table.remove(tbRandom, randomIndex)
end
return tbResult
end
function PlayerDatingData:CheckHasNewEvent(nCharId, nLandmark)
local charData = PlayerData.Char:GetCharDatingEvent(nCharId)
if charData ~= nil and self.mapCharLimitedEvent[nCharId] ~= nil then
for nEId, v in pairs(self.mapCharLimitedEvent[nCharId]) do
if v.LandMark == nLandmark and v.Status == AllEnum.DatingEventStatus.Lock then
return true
end
end
end
return false
end
function PlayerDatingData:RefreshLimitedEventList(nCharId, tbDatingEventIds, tbDatingEventRewardIds)
if self.mapCharLimitedEvent[nCharId] ~= nil then
for nEId, v in pairs(self.mapCharLimitedEvent[nCharId]) do
for _, nId in ipairs(tbDatingEventIds) do
if nId == nEId and self.mapCharLimitedEvent[nCharId][nEId].Status == AllEnum.DatingEventStatus.Lock then
self.mapCharLimitedEvent[nCharId][nEId].Status = AllEnum.DatingEventStatus.Unlock
RedDotManager.SetValid(RedDotDefine.Phone_Dating_Reward, {nCharId, nEId}, true)
break
end
end
if tbDatingEventRewardIds ~= nil then
for _, nId in ipairs(tbDatingEventRewardIds) do
if nId == nEId then
self.mapCharLimitedEvent[nCharId][nEId].Status = AllEnum.DatingEventStatus.Received
RedDotManager.SetValid(RedDotDefine.Phone_Dating_Reward, {nCharId, nEId}, false)
break
end
end
end
end
end
if PlayerData.Phone ~= nil then
PlayerData.Phone:RefreshRedDot()
end
end
function PlayerDatingData:GetLimitedEventList(nCharId)
local mapData = {}
if self.mapCharLimitedEvent[nCharId] ~= nil then
for nEId, v in pairs(self.mapCharLimitedEvent[nCharId]) do
table.insert(mapData, v)
end
end
table.sort(mapData, function(a, b)
return a.Id < b.Id
end)
return mapData
end
function PlayerDatingData:GetDatingCount()
return #self.tbDatingCharIds, self.nAllDatingCount
end
function PlayerDatingData:CheckDating(nCharId)
local bDating = false
for _, v in ipairs(self.tbDatingCharIds) do
if v == nCharId then
bDating = true
break
end
end
return bDating
end
function PlayerDatingData:SetCurLandmarkId(nLandmarkId)
self.nCurSelectLandmark = nLandmarkId
end
function PlayerDatingData:GetCurLandmarkId()
return self.nCurSelectLandmark
end
function PlayerDatingData:SetCharFavourLevelUpDelay(mapData)
self.mapDelay = mapData
end
function PlayerDatingData:GetCharFavourLevelUpDelay()
return self.mapDelay
end
function PlayerDatingData:GetCharStartEventId(nCharId)
if self.mapCharStartEvent[nCharId] ~= nil then
local nRandom = math.random(1, #self.mapCharStartEvent[nCharId])
return self.mapCharStartEvent[nCharId][nRandom]
end
end
function PlayerDatingData:GetCharBranchEventId(nCharId, bFirstBranch)
local nEventId = 0
local funcForeachEvent = function(mapData)
if #mapData.DatingEventParams > 0 and mapData.DatingEventParams[1] == self.nCurSelectLandmark then
for k, v in pairs(mapData.DatingEventExclude) do
if v == nCharId then
return
end
end
local last_digit = math.abs(mapData.Id) % 10
local nBranchFlag = bFirstBranch and 0 or 1
if last_digit == nBranchFlag then
nEventId = mapData.Id
end
end
end
ForEachTableLine(ConfigTable.Get("DatingBranch"), funcForeachEvent)
return nEventId
end
function PlayerDatingData:GetCharEndEventId(nCharId)
if self.mapCharEndEvent[nCharId] ~= nil then
local nRandom = math.random(1, #self.mapCharEndEvent[nCharId])
return self.mapCharEndEvent[nCharId][nRandom]
end
end
function PlayerDatingData:SendDatingLandmarkSelectMsg(nCharId, nLandmarkId, callback)
local successCallback = function(_, msgData)
self:SetCurLandmarkId(nLandmarkId)
self:AddDatingCharId(nCharId)
if callback ~= nil then
callback(msgData)
end
end
local sendData = {CharId = nCharId, LandmarkId = nLandmarkId}
HttpNetHandler.SendMsg(NetMsgId.Id.char_dating_landmark_select_req, sendData, nil, successCallback)
end
function PlayerDatingData:SendReceiveDatingEventRewardMsg(nCharId, nEventId, callback)
local successCallback = function(_, msgData)
self.mapCharLimitedEvent[nCharId][nEventId].Status = AllEnum.DatingEventStatus.Received
RedDotManager.SetValid(RedDotDefine.Phone_Dating_Reward, {nCharId, nEventId}, false)
PlayerData.Phone:RefreshRedDot()
UTILS.OpenReceiveByChangeInfo(msgData, callback)
end
local sendData = {CharId = nCharId, EventId = nEventId}
HttpNetHandler.SendMsg(NetMsgId.Id.char_dating_event_reward_receive_req, sendData, nil, successCallback)
end
function PlayerDatingData:SendDatingSendGiftMsg(nCharId, tbItems, callback)
local successCallback = function(_, msgData)
if callback ~= nil then
callback(msgData)
end
end
local sendData = {CharId = nCharId, Items = tbItems}
HttpNetHandler.SendMsg(NetMsgId.Id.char_dating_gift_send_req, sendData, nil, successCallback)
end
function PlayerDatingData:OnEvent_NewDay()
self.tbDatingCharIds = {}
end
return PlayerDatingData
@@ -0,0 +1,107 @@
local PlayerDictionaryData = class("PlayerDictionaryData")
local Status = {
Uncompleted = 0,
Unreceived = 1,
Received = 2
}
function PlayerDictionaryData:Init()
self._tbEntryStatus = {}
self._tbEntryId = {}
self:ProcessTableData()
end
function PlayerDictionaryData:ProcessTableData()
local func_ForEach_DictionaryEntry = function(mapData)
if self._tbEntryId[mapData.Tab] == nil then
self._tbEntryId[mapData.Tab] = {}
end
self._tbEntryId[mapData.Tab][mapData.Index] = mapData.Id
if mapData.FinishType == GameEnum.questCompleteCond.ClientReport then
self._tbEntryStatus[mapData.Id] = Status.Uncompleted
end
end
ForEachTableLine(DataTable.DictionaryEntry, func_ForEach_DictionaryEntry)
end
function PlayerDictionaryData:GetEntryStatus(nId)
return self._tbEntryStatus[nId] or Status.Uncompleted
end
function PlayerDictionaryData:GetCompletedEntry(bAll)
local tbList = {}
for nId, nStatus in pairs(self._tbEntryStatus) do
if nStatus == Status.Received or nStatus == Status.Unreceived then
local mapCfg = ConfigTable.GetData("DictionaryEntry", nId)
local mapTab = ConfigTable.GetData("DictionaryTab", mapCfg.Tab)
if bAll or not mapTab.HideInBattle then
local mapData = {
nId = nId,
nIndex = mapCfg.Index,
nSort = mapCfg.Sort,
sTitle = mapCfg.Title,
nTab = mapCfg.Tab,
bUnreceived = nStatus == Status.Unreceived
}
table.insert(tbList, mapData)
end
end
end
return tbList
end
function PlayerDictionaryData:GetUncompletedEntry()
local tbList = {}
for nId, nStatus in pairs(self._tbEntryStatus) do
if nStatus == Status.Uncompleted then
table.insert(tbList, nId)
end
end
return tbList
end
function PlayerDictionaryData:CacheDictionaryData(tbData)
if not tbData then
return
end
for _, mapTab in pairs(tbData) do
for _, mapEntry in pairs(mapTab.Entries) do
local nId = self._tbEntryId[mapTab.TabId][mapEntry.Index]
if nId then
self._tbEntryStatus[nId] = mapEntry.Status
self:UpdateDictionarySubRedDot(mapTab.TabId, mapEntry.Index, mapEntry.Status)
else
printError("DictionaryEntry表变更,TabId" .. mapTab.TabId .. ";Index" .. mapEntry.Index .. "对应的词条未找到")
end
end
end
end
function PlayerDictionaryData:ChangeDictionaryData(mapData)
local nId = self._tbEntryId[mapData.TabId][mapData.Index]
if not self._tbEntryStatus[nId] or self._tbEntryStatus[nId] == Status.Uncompleted then
local mapCfg = ConfigTable.GetData("DictionaryEntry", nId)
if mapCfg ~= nil and mapCfg.Popup == true then
PlayerData.SideBanner:AddDictionaryEntry(nId)
end
end
self._tbEntryStatus[nId] = mapData.Status
self:UpdateDictionarySubRedDot(mapData.TabId, mapData.Index, mapData.Status)
end
function PlayerDictionaryData:SendDictRewardReq(nTabId, nIndex, callback)
local mapMsg = {TabId = nTabId, Index = nIndex}
local successCallback = function(_, mapData)
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(mapData)
if nIndex == 0 then
for nEntryIndex, nId in pairs(self._tbEntryId[nTabId]) do
self._tbEntryStatus[nId] = Status.Received
self:UpdateDictionarySubRedDot(nTabId, nEntryIndex, Status.Received)
end
else
local nId = self._tbEntryId[nTabId][nIndex]
self._tbEntryStatus[nId] = Status.Received
self:UpdateDictionarySubRedDot(nTabId, nIndex, Status.Received)
end
if callback then
callback(mapReward)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.dictionary_reward_receive_req, mapMsg, nil, successCallback)
end
function PlayerDictionaryData:UpdateDictionarySubRedDot(nTabId, nIndex, nStatus)
RedDotManager.SetValid(RedDotDefine.Dictionary_Sub, {nTabId, nIndex}, nStatus == Status.Unreceived)
end
return PlayerDictionaryData
@@ -0,0 +1,861 @@
local ConfigData = require("GameCore.Data.ConfigData")
local DiscData = require("GameCore.Data.DataClass.DiscData")
local WwiseAudioMgr = CS.WwiseAudioManager.Instance
local PlayerDiscData = class("PlayerDiscData")
function PlayerDiscData:Init()
self._mapDisc = {}
self.nMaxBreakLimitMat = 5
self:ProcessTableData()
end
function PlayerDiscData:ProcessTableData()
self:ProcessExpTable()
self:ProcessConfigTable()
self:ProcessDiscTable()
end
function PlayerDiscData:ProcessExpTable()
self.tbItemExp = {}
local foreachDiscItemExp = function(mapData)
table.insert(self.tbItemExp, {
nItemId = mapData.ItemId,
nExpValue = mapData.Exp
})
end
ForEachTableLine(DataTable.DiscItemExp, foreachDiscItemExp)
local sort = function(a, b)
return a.nExpValue > b.nExpValue
end
table.sort(self.tbItemExp, sort)
end
function PlayerDiscData:ProcessConfigTable()
self.tbExpPerGold = {}
local tbGold = ConfigTable.GetConfigNumberArray("DiscStrengthenGoldFactor")
if type(tbGold) == "table" then
for nRarity, sValue in ipairs(tbGold) do
self.tbExpPerGold[nRarity] = sValue / 1000
end
end
self.tbMaxStar = {}
local tbBreak = ConfigTable.GetConfigNumberArray("DiscRarityLimitBreakMax")
if type(tbBreak) == "table" then
for nRarity, sValue in ipairs(tbBreak) do
self.tbMaxStar[nRarity] = sValue
end
end
end
function PlayerDiscData:ProcessDiscTable()
self.ItemToDisc = {}
local func_ForEach = function(mapData)
self.ItemToDisc[mapData.TransformItemId] = mapData.Id
end
ForEachTableLine(DataTable.Disc, func_ForEach)
local func_ForEach_main = function(mapData)
CacheTable.SetField("_MainSkill", mapData.GroupId, mapData.Level, mapData)
end
ForEachTableLine(DataTable.MainSkill, func_ForEach_main)
local func_ForEach_Note = function(mapData)
CacheTable.SetField("_SubNoteSkillPromoteGroup", mapData.GroupId, mapData.Phase, mapData)
end
ForEachTableLine(DataTable.SubNoteSkillPromoteGroup, func_ForEach_Note)
local func_ForEach_Secondary = function(mapData)
CacheTable.SetField("_SecondarySkill", mapData.GroupId, mapData.Level, mapData)
end
ForEachTableLine(DataTable.SecondarySkill, func_ForEach_Secondary)
end
function PlayerDiscData:GetAllDisc()
local discList = {}
for _, discData in pairs(self._mapDisc) do
table.insert(discList, discData)
end
return discList
end
function PlayerDiscData:GetDiscById(nId)
if not nId or nId == 0 then
return
end
if self._mapDisc[nId] == nil then
end
return self._mapDisc[nId]
end
function PlayerDiscData:GetDiscSkillScore(nId, tbNote)
local mapDisc = self._mapDisc[nId]
local nScore = 0
for i = 1, 2 do
if mapDisc.tbSubSkillGroupId[i] then
local tbGroup = CacheTable.GetData("_SecondarySkill", mapDisc.tbSubSkillGroupId[i])
if tbGroup then
local nMaxLayer = #tbGroup
for j = nMaxLayer, 1, -1 do
if tbGroup[j] then
local bActive = mapDisc:CheckSubSkillActive(tbNote, tbGroup[j])
if bActive then
nScore = nScore + tbGroup[j].Score
break
end
end
end
end
end
end
return nScore
end
function PlayerDiscData:GetDiscSkillByNote(tbDisc, tbHasNote, nNeedNote)
local tbSkill = {}
local sNote = tostring(nNeedNote)
for _, nDiscId in pairs(tbDisc) do
local mapData = self:GetDiscById(nDiscId)
if mapData == nil then
return {}
end
for _, nSubSkillGroupId in pairs(mapData.tbSubSkillGroupId) do
local tbGroup = CacheTable.GetData("_SecondarySkill", nSubSkillGroupId)
if tbGroup then
local nCurLayer = 0
local nMaxLayer = #tbGroup
for i = nMaxLayer, 1, -1 do
if tbGroup[i] then
local bActive = mapData:CheckSubSkillActive(tbHasNote, tbGroup[i])
if bActive then
nCurLayer = i
break
end
end
end
local nNextLayer = nCurLayer == nMaxLayer and nMaxLayer or nCurLayer + 1
if tbGroup[nNextLayer] then
local nSubSkillId = tbGroup[nNextLayer].Id
local tbActiveNote = decodeJson(tbGroup[nNextLayer].NeedSubNoteSkills)
if tbActiveNote[sNote] then
local tbNote = {}
for k, v in pairs(tbActiveNote) do
local nNoteId = tonumber(k)
local nNoteCount = tonumber(v)
if nNoteId then
tbNote[nNoteId] = nNoteCount
end
end
table.insert(tbSkill, {nId = nSubSkillId, tbNote = tbNote})
end
end
end
end
end
return tbSkill
end
function PlayerDiscData:GetBGMDisc()
return self.nBGMDisc or 0
end
function PlayerDiscData:CheckDiscL2D(nId)
local discData = self._mapDisc[nId]
if not discData then
return false
end
return discData.bUnlockL2D
end
function PlayerDiscData:CalcDiscEffect(nId)
local discData = self._mapDisc[nId]
local tbEft = {}
if discData ~= nil then
for _, mapEft in ipairs(discData:GetSkillEffect()) do
table.insert(tbEft, mapEft)
end
end
return tbEft
end
function PlayerDiscData:CalcDiscEffectInBuild(nId, tbSecondarySkill)
local discData = self._mapDisc[nId]
local tbEffectId = {}
if discData == nil then
return tbEffectId
end
local add = function(tbEfId)
if not tbEfId then
return
end
for _, nEfId in pairs(tbEfId) do
if type(nEfId) == "number" and 0 < nEfId then
table.insert(tbEffectId, {nEfId, 0})
end
end
end
local mapMainCfg = ConfigTable.GetData("MainSkill", discData.nMainSkillId)
if mapMainCfg then
add(mapMainCfg.EffectId)
end
for _, v in ipairs(tbSecondarySkill) do
local mapSubCfg = ConfigTable.GetData("SecondarySkill", v)
if mapSubCfg and table.indexof(discData.tbSubSkillGroupId, mapSubCfg.GroupId) > 0 then
add(mapSubCfg.EffectId)
end
end
return tbEffectId
end
function PlayerDiscData:CalcDiscInfoInBuild(nId, tbSecondarySkill)
local discData = self._mapDisc[nId]
local discInfo = CS.Lua2CSharpInfo_DiscInfo()
if discData == nil then
return discInfo
end
local tbSkillInfo = {}
for _, v in ipairs(tbSecondarySkill) do
local mapSubCfg = ConfigTable.GetData("SecondarySkill", v, true)
if mapSubCfg and table.indexof(discData.tbSubSkillGroupId, mapSubCfg.GroupId) > 0 then
local skillInfo = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfo.skillId = v
skillInfo.skillLevel = mapSubCfg.Level
table.insert(tbSkillInfo, skillInfo)
end
end
local mapMainCfg = ConfigTable.GetData("MainSkill", discData.nMainSkillId, true)
if mapMainCfg then
local skillInfo = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfo.skillId = discData.nMainSkillId
skillInfo.skillLevel = 1
table.insert(tbSkillInfo, skillInfo)
end
discInfo.discId = nId
discInfo.discScript = discData.sSkillScript
discInfo.skillInfos = tbSkillInfo
discInfo.discLevel = discData.nLevel
return discInfo
end
function PlayerDiscData:GenerateLocalDiscData(configId, nExp, nLevel, nPhase, nStar)
if not configId then
printError("GenerateLocalDiscData Failed!")
return
end
local mapDisc = {}
mapDisc.Id = configId
mapDisc.Exp = nExp or 0
mapDisc.Level = nLevel or 1
mapDisc.Phase = nPhase or 0
mapDisc.Star = nStar or 0
mapDisc.Read = false
local discData = DiscData.new(mapDisc)
return discData
end
function PlayerDiscData:GetAttrBase(nGroupId, nPhase, nTargetLv, nExtraGroupId, nStar)
local mapExtra
if 0 < nStar and 0 < nExtraGroupId then
local nExtraId = UTILS.GetDiscExtraAttributeId(nExtraGroupId, nStar)
mapExtra = ConfigTable.GetData("DiscExtraAttribute", tostring(nExtraId))
end
local nAttrId = UTILS.GetDiscAttributeId(nGroupId, nPhase, nTargetLv)
local mapAttribute = ConfigTable.GetData_Attribute(tostring(nAttrId))
local mapAttr = {}
if mapAttribute then
for _, v in ipairs(AllEnum.AttachAttr) do
local nParamValue = mapAttribute[v.sKey] or 0
mapAttr[v.sKey] = {
Key = v.sKey,
Value = v.bPercent and nParamValue * ConfigData.IntFloatPrecision * 100 or nParamValue,
CfgValue = mapAttribute[v.sKey] or 0
}
if mapExtra then
local nExtraParamValue = mapExtra[v.sKey] or 0
local nExtraValue = v.bPercent and nExtraParamValue * ConfigData.IntFloatPrecision * 100 or nExtraParamValue
mapAttr[v.sKey].Value = mapAttr[v.sKey].Value + nExtraValue
mapAttr[v.sKey].CfgValue = mapAttr[v.sKey].CfgValue + nExtraParamValue
end
end
end
return mapAttr
end
function PlayerDiscData:GetDiscMaxStar(nRarity)
return self.tbMaxStar[nRarity]
end
function PlayerDiscData:GetBreakLimitMat(nId)
local discData = self._mapDisc[nId]
local nMatId = discData.nTransformItemId
local nCount = PlayerData.Item:GetItemCountByID(nMatId)
return nMatId, nCount
end
function PlayerDiscData:GetAllBreakLimitMat()
local tbMat = {}
for nId, discData in pairs(self._mapDisc) do
local nMatId, nCount = self:GetBreakLimitMat(nId)
if nCount > discData.nMaxStar - discData.nStar then
nCount = discData.nMaxStar - discData.nStar
end
if 0 < nCount then
table.insert(tbMat, {nTid = nMatId, nCount = nCount})
end
end
table.sort(tbMat, function(a, b)
local rarityA = ConfigTable.GetData_Item(a.nTid).Rarity
local rarityB = ConfigTable.GetData_Item(b.nTid).Rarity
if rarityA ~= rarityB then
return rarityA < rarityB
elseif a.nCount ~= b.nCount then
return a.nCount > b.nCount
else
return a.nTid < b.nTid
end
end)
return tbMat
end
function PlayerDiscData:GetIndexOfNewBreakLimitMat(tbMat)
local nCurCount = 0
for _, _ in pairs(tbMat) do
nCurCount = nCurCount + 1
end
if nCurCount == self.nMaxBreakLimitMat then
return 0
end
local nIndex = 0
for _, v in pairs(tbMat) do
if nIndex < v.nAddIndex then
nIndex = v.nAddIndex
end
end
return nIndex + 1
end
function PlayerDiscData:GetMaxLv(nRarity, nCurPhase)
local nMaxLv = 1
local foreachDiscPromoteLimit = function(mapData)
if mapData.Rarity == nRarity and tonumber(mapData.Phase) == nCurPhase then
nMaxLv = mapData.MaxLevel
end
end
ForEachTableLine(DataTable.DiscPromoteLimit, foreachDiscPromoteLimit)
return tonumber(nMaxLv)
end
function PlayerDiscData:GetUpgradeNote(nId)
local tbShowNote = {}
local mapDisc = self._mapDisc[nId]
local mapGroup = CacheTable.GetData("_SubNoteSkillPromoteGroup", mapDisc.nSubNoteSkillGroupId)
if not mapGroup then
return tbShowNote
end
local nNextPhase = mapDisc.nPhase + 1
local mapCfg
while type(nNextPhase) == "number" and 0 <= nNextPhase do
mapCfg = mapGroup[nNextPhase]
if mapCfg then
break
end
nNextPhase = nNextPhase - 1
end
if not mapCfg then
return tbShowNote
end
local tbCurSubNoteSkills = mapDisc.tbSubNoteSkills
local tbNextSubNoteSkills = {}
local tbNote = decodeJson(mapCfg.SubNoteSkills)
for k, v in pairs(tbNote) do
local nNoteId = tonumber(k)
local nNoteCount = tonumber(v)
if nNoteId then
table.insert(tbNextSubNoteSkills, {nId = nNoteId, nCount = nNoteCount})
end
end
for _, mapNextNote in pairs(tbNextSubNoteSkills) do
local bNew = true
for _, mapCurNote in pairs(tbCurSubNoteSkills) do
if mapNextNote.nId == mapCurNote.nId then
bNew = false
if mapNextNote.nCount > mapCurNote.nCount then
table.insert(tbShowNote, {
mapNextNote.nId,
mapCurNote.nCount,
mapNextNote.nCount
})
end
break
end
end
if bNew then
table.insert(tbShowNote, {
mapNextNote.nId,
mapNextNote.nCount
})
end
end
return tbShowNote
end
function PlayerDiscData:GetUpgradeMatList()
local tbMat = {}
for _, value in ipairs(self.tbItemExp) do
table.insert(tbMat, {
nItemId = value.nItemId,
nExpValue = value.nExpValue,
nCost = 0
})
end
return tbMat
end
function PlayerDiscData:GetCustomizeLevelExp(nId, nLevel)
local mapDisc = self._mapDisc[nId]
local nUpgradeGroupId = mapDisc.nStrengthenGroupId
local nTargetLevel = nLevel >= mapDisc.nMaxLv and mapDisc.nMaxLv or nLevel
local nNextExp = self:CalUpgradeExp(nUpgradeGroupId, mapDisc.nLevel, nTargetLevel, mapDisc.nExp)
return nNextExp
end
function PlayerDiscData:GetMaxLevelExp(nId)
local mapDisc = self._mapDisc[nId]
local nUpgradeGroupId = mapDisc.nStrengthenGroupId
local nNextExp = self:CalUpgradeExp(nUpgradeGroupId, mapDisc.nLevel, mapDisc.nMaxLv, mapDisc.nExp)
return nNextExp
end
function PlayerDiscData:GetCustomizeLevelDataAndCost(nId, nLevel)
local nTargetExp = self:GetCustomizeLevelExp(nId, nLevel)
local tbMat = self:CalUpgradeMat(nTargetExp)
local mapTargetLevel, nGoldCost = self:GetLevelDataAndCostByMat(nId, tbMat)
return mapTargetLevel, tbMat, nGoldCost
end
function PlayerDiscData:GetMaxLevelDataAndCost(nId)
local nTargetExp = self:GetMaxLevelExp(nId)
local tbMat = self:CalUpgradeMat(nTargetExp)
local mapTargetLevel, nGoldCost = self:GetLevelDataAndCostByMat(nId, tbMat)
return mapTargetLevel, tbMat, nGoldCost
end
function PlayerDiscData:GetMaxMatCost(nId, tbMat, mapMat)
local nMatExp = mapMat.nExpValue
local nMaxExp = self:GetMaxLevelExp(nId)
local nHasExp = self:GetMatExp(tbMat)
local nCount = math.ceil((nMaxExp - nHasExp) / nMatExp)
return nCount
end
function PlayerDiscData:GetMatExp(tbMat)
local nTotalExp = 0
for _, mapMat in pairs(tbMat) do
nTotalExp = nTotalExp + mapMat.nExpValue * mapMat.nCost
end
return nTotalExp
end
function PlayerDiscData:GetLevelDataAndCostByMat(nId, tbMat)
local mapDisc = self._mapDisc[nId]
local nMatExp = self:GetMatExp(tbMat)
local nExpPerGold = self.tbExpPerGold[mapDisc.nRarity]
local nGoldCost = nMatExp * nExpPerGold
local nTotalExp = nMatExp + mapDisc.nExp
local nUpgradeGroupId = mapDisc.nStrengthenGroupId
local nStartLevel = mapDisc.nLevel
local nMaxLevel = mapDisc.nMaxLv
local nTargetLevel = nStartLevel
for i = nStartLevel, nMaxLevel - 1 do
local nUpgradeId = nUpgradeGroupId * 1000 + i + 1
local mapUpgrade = ConfigTable.GetData("DiscStrengthen", nUpgradeId, true)
local nExp = 0
if mapUpgrade then
nExp = mapUpgrade.Exp
end
if nTotalExp >= nExp then
nTotalExp = nTotalExp - nExp
nTargetLevel = nTargetLevel + 1
else
break
end
end
if nTargetLevel == nMaxLevel then
nGoldCost = nGoldCost - nTotalExp * nExpPerGold
nMatExp = nMatExp - nTotalExp
nTotalExp = 0
end
local mapLevelData = {
nLevel = nTargetLevel,
nExp = math.ceil(nTotalExp),
nMaxLevel = nMaxLevel,
nMaxExp = self:GetMaxExp(nUpgradeGroupId, nTargetLevel),
nMatExp = nMatExp
}
return mapLevelData, nGoldCost
end
function PlayerDiscData:CalUpgradeExp(nUpgradeGroupId, nStartLevel, nTargetLevel, nStartExp)
local nTotalExp = 0
for i = nStartLevel, nTargetLevel - 1 do
local nUpgradeId = nUpgradeGroupId * 1000 + i + 1
local mapUpgrade = ConfigTable.GetData("DiscStrengthen", nUpgradeId, true)
local nExp = 0
if mapUpgrade then
nExp = mapUpgrade.Exp
end
nTotalExp = nTotalExp + nExp
end
nTotalExp = nTotalExp - nStartExp
return nTotalExp
end
function PlayerDiscData:GetMaxExp(nUpgradeGroupId, nLevel)
local nUpgradeId = nUpgradeGroupId * 1000 + nLevel + 1
local mapUpgrade = ConfigTable.GetData("DiscStrengthen", nUpgradeId, true)
if not mapUpgrade then
return 0
end
local nExp = mapUpgrade.Exp
return nExp
end
function PlayerDiscData:CalCostProportion(nTarget, tbMatType, tbHas)
local nTypeCount = #tbMatType
local GetProportionedSum = function(tbProportioned)
local nSum = 0
for i = 1, nTypeCount do
nSum = nSum + tbMatType[i] * tbProportioned[i]
end
return nSum
end
local tbCost = tbHas
local nMinTarget = GetProportionedSum(tbHas)
if nTarget >= nMinTarget then
return tbHas
end
local tbSumOfTypeFollowing = {}
tbSumOfTypeFollowing[nTypeCount + 1] = 0
for i = nTypeCount, 1, -1 do
local nCurTypeSum = tbMatType[i] * tbHas[i]
tbSumOfTypeFollowing[i] = nCurTypeSum + tbSumOfTypeFollowing[i + 1]
end
local GetLargeFaceValue = function(tbCost1, tbCost2)
for i = 1, #tbCost1 do
if tbCost1[i] > tbCost2[i] then
return tbCost1
elseif tbCost1[i] < tbCost2[i] then
return tbCost2
end
end
return tbCost1
end
local function Proportion(tbProportioned, nCurMatType, nRemain)
if nCurMatType > nTypeCount or nRemain <= 0 then
local nSum = GetProportionedSum(tbProportioned)
if nSum >= nTarget then
if nSum < nMinTarget then
nMinTarget = nSum
tbCost = tbProportioned
elseif nSum == nMinTarget then
tbCost = GetLargeFaceValue(tbCost, tbProportioned)
end
end
else
local nMaxUse = math.ceil(nRemain / tbMatType[nCurMatType])
nMaxUse = math.min(nMaxUse, tbHas[nCurMatType])
local nMinUse = math.max(nMaxUse - 1, 0)
for i = nMaxUse, nMinUse, -1 do
local tbCopy = {
table.unpack(tbProportioned)
}
tbCopy[nCurMatType] = i
local nSum = GetProportionedSum(tbCopy)
if nSum > nMinTarget then
return
end
local nNextRemain = nRemain - i * tbMatType[nCurMatType]
Proportion(tbCopy, nCurMatType + 1, nNextRemain)
end
end
end
local tbProportioned = {}
for i = 1, nTypeCount do
tbProportioned[i] = 0
end
Proportion(tbProportioned, 1, nTarget)
return tbCost
end
function PlayerDiscData:CalUpgradeMat(nTargetExp)
local tbMatType, tbHas = {}, {}
for _, value in ipairs(self.tbItemExp) do
table.insert(tbMatType, value.nExpValue)
table.insert(tbHas, PlayerData.Item:GetItemCountByID(value.nItemId))
end
local tbCostCount = self:CalCostProportion(nTargetExp, tbMatType, tbHas)
local tbMat = {}
for nIndex, value in ipairs(self.tbItemExp) do
table.insert(tbMat, {
nItemId = value.nItemId,
nExpValue = value.nExpValue,
nCost = tbCostCount[nIndex]
})
end
return tbMat
end
function PlayerDiscData:GetDiscIdList()
local tbDisc = {}
for nId, _ in pairs(self._mapDisc) do
table.insert(tbDisc, nId)
end
return tbDisc
end
function PlayerDiscData:SendDiscStrengthenReq(nId, tbMat, callback)
if self._mapDisc[nId] == nil then
printError(string.format("星盘不存在, id为: %d", nId))
return
end
local tbItems = {}
for _, mapMat in pairs(tbMat) do
if mapMat.nCost > 0 then
table.insert(tbItems, {
Id = 0,
Qty = mapMat.nCost,
Tid = mapMat.nItemId
})
end
end
local msgData = {Id = nId, Items = tbItems}
local successCallback = function(_, mapMainData)
self:UpdateDiscData(nId, {
Level = mapMainData.Level,
Exp = mapMainData.Exp
})
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.disc_strengthen_req, msgData, nil, successCallback)
end
function PlayerDiscData:SendDiscPromoteReq(nId, callback)
if self._mapDisc[nId] == nil then
printError(string.format("星盘不存在, id为: %d", nId))
return
end
local successCallback = function(_, mapMainData)
self:UpdateDiscData(nId, {
Phase = mapMainData.Phase
})
self:UpdateStoryReddot(self._mapDisc[nId])
self:UpdateAvgReddot(self._mapDisc[nId])
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.disc_promote_req, {Id = nId}, nil, successCallback)
end
function PlayerDiscData:SendDiscLimitBreakReq(nId, nCount, callback)
if self._mapDisc[nId] == nil then
printError(string.format("星盘不存在, id为: %d", nId))
return
end
local successCallback = function(_, mapMainData)
self:UpdateDiscData(nId, {
Star = mapMainData.Star
})
self:UpdateBreakLimitReddot(self._mapDisc[nId])
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.disc_limit_break_req, {Id = nId, Qty = nCount}, nil, successCallback)
end
function PlayerDiscData:SendAllDiscLimitBreakReq(callback)
local successCallback = function(_, mapMainData)
for _, mapData in ipairs(mapMainData.LimitBreaks) do
self:UpdateDiscData(mapData.Id, {
Star = mapData.Star
})
self:UpdateBreakLimitReddot(self._mapDisc[mapData.Id])
end
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.disc_all_limit_break_req, {}, nil, successCallback)
end
function PlayerDiscData:SendDiscReadRewardReceiveReq(nId, nType, callback)
if self._mapDisc[nId] == nil then
printError(string.format("星盘不存在, id为: %d", nId))
return
end
local msgData = {Id = nId, ReadType = nType}
local successCallback = function(_, mapMainData)
if nType == AllEnum.DiscReadType.DiscStory then
self:UpdateDiscData(nId, {Read = true})
self:UpdateStoryReddot(self._mapDisc[nId])
UTILS.OpenReceiveByChangeInfo(mapMainData)
elseif nType == AllEnum.DiscReadType.DiscAvg then
self:UpdateDiscData(nId, {Avg = true})
self:UpdateAvgReddot(self._mapDisc[nId])
end
if callback then
callback(mapMainData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.disc_read_reward_receive_req, msgData, nil, successCallback)
end
function PlayerDiscData:SendPlayerMusicSetReq(nId, callback)
local successCallback = function(_, mapMainData)
self:CacheBGMDisc(nId)
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_music_set_req, {Value = nId}, nil, successCallback)
end
function PlayerDiscData:CacheBGMDisc(nId)
self.nBGMDisc = nId
if nId == 0 then
WwiseAudioMgr.DiscUIBgm = ""
return
end
local mapCfg = ConfigTable.GetData("DiscIP", nId)
if not mapCfg then
WwiseAudioMgr.DiscUIBgm = ""
return
end
WwiseAudioMgr.DiscUIBgm = mapCfg.VoFile
end
function PlayerDiscData:CacheDiscData(tbData)
for nId, _ in pairs(self._mapDisc) do
self._mapDisc[nId] = nil
end
self:CreateNewDisc(tbData)
end
function PlayerDiscData:CreateNewDisc(tbData)
if tbData == nil then
return
end
for _, mapDisc in ipairs(tbData) do
if self._mapDisc[mapDisc.Id] == nil then
self:CreateDiscData(mapDisc)
else
printError(string.format("星盘唯一Id重复, 唯一Id: %d", mapDisc.Id))
end
end
end
function PlayerDiscData:UpdateDiscData(nId, mapData)
if self._mapDisc[nId] == nil then
printLog(string.format("该星盘不存在/是新星盘, 唯一Id: %d", nId))
self:CreateDiscData(mapData)
else
self._mapDisc[nId]:ParseServerData(mapData)
end
end
function PlayerDiscData:CreateDiscData(mapDisc)
local discData = DiscData.new(mapDisc)
local nId = discData.nId
self._mapDisc[nId] = discData
self:UpdateStoryReddot(discData)
self:UpdateAvgReddot(discData)
self:UpdateBreakLimitReddot(discData)
end
function PlayerDiscData:UpdateStoryReddot(mapDisc)
local mapCfg = ConfigTable.GetData("Disc", mapDisc.nId)
local nLimit = ConfigTable.GetConfigNumber("DiscStoryReadLimit")
if mapCfg ~= nil and mapCfg.Visible then
RedDotManager.SetValid(RedDotDefine.Disc_SideB_Read, {
mapDisc.nId
}, mapDisc.bRead == false and nLimit <= mapDisc.nPhase)
end
end
function PlayerDiscData:UpdateAvgReddot(mapDisc)
local mapCfg = ConfigTable.GetData("Disc", mapDisc.nId)
local mapIPCfg = ConfigTable.GetData("DiscIP", mapDisc.nId)
local nLimit = ConfigTable.GetConfigNumber("DiscAVGStoryReadLimit")
if mapCfg ~= nil and mapCfg.Visible and mapIPCfg ~= nil then
RedDotManager.SetValid(RedDotDefine.Disc_SideB_Avg, {
mapDisc.nId
}, mapIPCfg.AvgId ~= "" and mapDisc.bAvgRead == false and nLimit <= mapDisc.nPhase)
end
end
function PlayerDiscData:UpdateBreakLimitReddot(mapDisc)
local mapCfg = ConfigTable.GetData("Disc", mapDisc.nId)
if mapCfg ~= nil and mapCfg.Visible then
local _, nMatCount = self:GetBreakLimitMat(mapDisc.nId)
RedDotManager.SetValid(RedDotDefine.Disc_BreakBtn, {
mapDisc.nId
}, 0 < nMatCount and mapDisc.nStar < mapDisc.nMaxStar)
end
end
function PlayerDiscData:UpdateBreakLimitRedDotByItem(mapChange)
for _, v in ipairs(mapChange) do
local nId = self.ItemToDisc[v.Tid]
if nId and self._mapDisc[nId] and v.Qty > 0 then
self:UpdateBreakLimitReddot(self._mapDisc[nId])
end
end
end
function PlayerDiscData:CreateTrialDisc(tbTrialId)
self._mapTrialDisc = {}
for _, nTrialId in ipairs(tbTrialId) do
local mapCfg = ConfigTable.GetData("TrialDisc", nTrialId)
if mapCfg == nil then
printError("体验星盘数据没有找到:" .. nTrialId)
return
end
local discData = self:GenerateLocalDiscData(mapCfg.DiscId, 0, mapCfg.Level, mapCfg.Phase, mapCfg.Star)
self._mapTrialDisc[nTrialId] = discData
end
end
function PlayerDiscData:GetTrialDiscById(nId)
if not nId then
return
end
if self._mapTrialDisc[nId] == nil then
printLog(string.format("该星盘不存在或新获得, 唯一Id: %d", nId))
end
return self._mapTrialDisc[nId]
end
function PlayerDiscData:DeleteTrialDisc()
self._mapTrialDisc = {}
end
function PlayerDiscData:CalcTrialEffectInBuild(nTrialId, tbSecondarySkill)
local discData = self._mapTrialDisc[nTrialId]
local tbEffectId = {}
if discData == nil then
return tbEffectId
end
local add = function(tbEfId)
if not tbEfId then
return
end
for _, nEfId in pairs(tbEfId) do
if type(nEfId) == "number" and 0 < nEfId then
table.insert(tbEffectId, {nEfId, 0})
end
end
end
local mapMainCfg = ConfigTable.GetData("MainSkill", discData.nMainSkillId)
if mapMainCfg then
add(mapMainCfg.EffectId)
end
for _, v in ipairs(tbSecondarySkill) do
local mapSubCfg = ConfigTable.GetData("SecondarySkill", v)
if mapSubCfg and table.indexof(discData.tbSubSkillGroupId, mapSubCfg.GroupId) > 0 then
add(mapSubCfg.EffectId)
end
end
return tbEffectId
end
function PlayerDiscData:CalcTrialInfoInBuild(nTrialId, tbSecondarySkill)
local discData = self._mapTrialDisc[nTrialId]
local discInfo = CS.Lua2CSharpInfo_DiscInfo()
if discData == nil then
return discInfo
end
local tbSkillInfo = {}
for _, v in ipairs(tbSecondarySkill) do
local mapSubCfg = ConfigTable.GetData("SecondarySkill", v, true)
if mapSubCfg and table.indexof(discData.tbSubSkillGroupId, mapSubCfg.GroupId) > 0 then
local skillInfo = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfo.skillId = v
skillInfo.skillLevel = mapSubCfg.Level
table.insert(tbSkillInfo, skillInfo)
end
end
local mapMainCfg = ConfigTable.GetData("MainSkill", discData.nMainSkillId, true)
if mapMainCfg then
local skillInfo = CS.Lua2CSharpInfo_DiscSkillInfo()
skillInfo.skillId = discData.nMainSkillId
skillInfo.skillLevel = 1
table.insert(tbSkillInfo, skillInfo)
end
discInfo.discId = discData.nId
discInfo.discScript = discData.sSkillScript
discInfo.skillInfos = tbSkillInfo
discInfo.discLevel = discData.nLevel
return discInfo
end
local tbSortNameTextCfg = {
"CharList_Sort_Toggle_Level",
"CharList_Sort_Toggle_Rare",
"CharList_Sort_Toggle_Time"
}
local tbSortType = {
[1] = AllEnum.SortType.Level,
[2] = AllEnum.SortType.Rarity,
[3] = AllEnum.SortType.Time,
[100] = AllEnum.SortType.ElementType,
[101] = AllEnum.SortType.Id
}
local tbDefaultSortField = {
"nLevel",
"nRarity",
"nEET",
"nId"
}
function PlayerDiscData:GetDiscSortNameTextCfg()
return tbSortNameTextCfg
end
function PlayerDiscData:GetDiscSortType()
return tbSortType
end
function PlayerDiscData:GetDiscSortField()
return tbDefaultSortField
end
return PlayerDiscData
@@ -0,0 +1,353 @@
local PlayerEquipmentData = class("PlayerEquipmentData")
local ConfigData = require("GameCore.Data.ConfigData")
local EquipmentData = require("GameCore.Data.DataClass.EquipmentDataEx")
function PlayerEquipmentData:Init()
self.tbCharPreset = {}
self.tbCharSelectPreset = {}
self.tbCharEquipment = {}
self.bRollWarning = true
self:ProcessTableData()
end
function PlayerEquipmentData:ProcessTableData()
self.nCharGemPresetNum = ConfigTable.GetConfigNumber("CharGemPresetNum")
self.tbSlotControl = {}
local func_ForEach_Slot = function(mapData)
table.insert(self.tbSlotControl, {
Id = mapData.Id,
UnlockLevel = mapData.UnlockLevel
})
end
ForEachTableLine(DataTable.CharGemSlotControl, func_ForEach_Slot)
table.sort(self.tbSlotControl, function(a, b)
return a.UnlockLevel < b.UnlockLevel
end)
end
function PlayerEquipmentData:CreateNewPresetData(tbPreset)
local tbAllPreset = {}
for i = 1, self.nCharGemPresetNum do
tbAllPreset[i] = {
sName = orderedFormat(ConfigTable.GetUIText("Equipment_PresetDefaultName"), i),
tbSlot = {}
}
end
for i, v in ipairs(tbPreset) do
if v.Name ~= "" then
tbAllPreset[i].sName = v.Name
end
for nSlotId, nGemIndex in pairs(v.SlotGem) do
tbAllPreset[i].tbSlot[nSlotId] = nGemIndex + 1
end
end
return tbAllPreset
end
function PlayerEquipmentData:CreateNewEquipmentData(tbSlotData, nCharId)
local mapCharEquipment = {}
for i, mapControl in ipairs(self.tbSlotControl) do
mapCharEquipment[mapControl.Id] = {}
end
for _, mapSlot in ipairs(tbSlotData) do
for i, mapInfo in ipairs(mapSlot.AlterGems) do
local nGemId = self:GetGemIdBySlot(nCharId, mapSlot.Id)
local equipmentData = EquipmentData.new(mapInfo, nCharId, nGemId)
table.insert(mapCharEquipment[mapSlot.Id], equipmentData)
end
end
return mapCharEquipment
end
function PlayerEquipmentData:CacheEquipmentData(mapMsgData)
if self.tbCharPreset == nil then
self.tbCharPreset = {}
end
if self.tbCharSelectPreset == nil then
self.tbCharSelectPreset = {}
end
if self.tbCharEquipment == nil then
self.tbCharEquipment = {}
end
for _, mapCharInfo in ipairs(mapMsgData) do
local nCharId = mapCharInfo.Tid
local mapPresetList = mapCharInfo.CharGemPresets
self.tbCharSelectPreset[nCharId] = mapPresetList.InUsePresetIndex + 1
self.tbCharPreset[nCharId] = self:CreateNewPresetData(mapPresetList.CharGemPresets)
self.tbCharEquipment[nCharId] = self:CreateNewEquipmentData(mapCharInfo.CharGemSlots, nCharId)
end
end
function PlayerEquipmentData:GetSelectPreset(nCharId)
return self.tbCharSelectPreset[nCharId]
end
function PlayerEquipmentData:GetEquipmentByGemIndex(nCharId, nSlotId, nGemIndex)
if nGemIndex == 0 then
return
end
return self.tbCharEquipment[nCharId][nSlotId][nGemIndex]
end
function PlayerEquipmentData:GetEquipmentBySlot(nCharId, nSlotId)
return self.tbCharEquipment[nCharId][nSlotId]
end
function PlayerEquipmentData:GetSlotWithIndex(nCharId, nPresetIndex)
local mapPreset = self.tbCharPreset[nCharId][nPresetIndex]
local nCharLevel = PlayerData.Char:GetCharLv(nCharId)
local tbSlot = {}
for i, mapControl in ipairs(self.tbSlotControl) do
tbSlot[i] = {
nSlotId = mapControl.Id,
nLevel = mapControl.UnlockLevel,
bUnlock = nCharLevel >= mapControl.UnlockLevel,
nGemIndex = mapPreset.tbSlot[mapControl.Id]
}
end
return tbSlot
end
function PlayerEquipmentData:GetSlotCfgWithIndex()
local tbSlot = {}
for i, mapControl in ipairs(self.tbSlotControl) do
tbSlot[i] = {
nSlotId = mapControl.Id,
nLevel = mapControl.UnlockLevel
}
end
return tbSlot
end
function PlayerEquipmentData:GetAllPresetName(nCharId)
local tbName = {}
for _, v in ipairs(self.tbCharPreset[nCharId]) do
table.insert(tbName, v.sName)
end
return tbName
end
function PlayerEquipmentData:GetGemIdBySlot(nCharId, nSlotId)
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
if not mapCharCfg then
return 0
end
local nSlotIndex = 1
for i, mapControl in ipairs(self.tbSlotControl) do
if nSlotId == mapControl.Id then
nSlotIndex = i
break
end
end
local nGemId = mapCharCfg.GemSlots[nSlotIndex]
return nGemId
end
function PlayerEquipmentData:GetEquipedGem(nCharId)
local nSelectPreset = self.tbCharSelectPreset[nCharId]
if not nSelectPreset or not self.tbCharPreset[nCharId] then
return {}
end
local mapPreset = self.tbCharPreset[nCharId][nSelectPreset]
local tbEquipedGem, mapSlotData = {}, {}
for _, mapControl in ipairs(self.tbSlotControl) do
local nSlotId = mapControl.Id
local nGemIndex = mapPreset.tbSlot[nSlotId]
local mapEquipment = self.tbCharEquipment[nCharId][nSlotId][nGemIndex]
if mapEquipment then
table.insert(tbEquipedGem, mapEquipment)
table.insert(mapSlotData, {nSlotId = nSlotId, nGemIndex = nGemIndex})
end
end
return tbEquipedGem, mapSlotData
end
function PlayerEquipmentData:GetEnhancedPotential(nCharId)
local tbEnhancedPotential = {}
local tbEquipedGem = self:GetEquipedGem(nCharId)
for _, v in pairs(tbEquipedGem) do
local tbPotential = v:GetEnhancedPotential()
for nPotentialId, nAdd in pairs(tbPotential) do
if not tbEnhancedPotential[nPotentialId] then
tbEnhancedPotential[nPotentialId] = 0
end
tbEnhancedPotential[nPotentialId] = tbEnhancedPotential[nPotentialId] + nAdd
end
end
return tbEnhancedPotential
end
function PlayerEquipmentData:GetEnhancedSkill(nCharId)
local charCfgData = ConfigTable.GetData_Character(nCharId)
if not charCfgData then
printError("Character表找不到该角色" .. nCharId)
return {}
end
local tbEnhancedSkill = {
[charCfgData.NormalAtkId] = 0,
[charCfgData.SkillId] = 0,
[charCfgData.AssistSkillId] = 0,
[charCfgData.UltimateId] = 0
}
local tbEquipedGem = self:GetEquipedGem(nCharId)
for _, v in pairs(tbEquipedGem) do
local tbSkill = v:GetEnhancedSkill()
for nSkillId, nAdd in pairs(tbSkill) do
if not tbEnhancedSkill[nSkillId] then
tbEnhancedSkill[nSkillId] = 0
end
tbEnhancedSkill[nSkillId] = tbEnhancedSkill[nSkillId] + nAdd
end
end
return tbEnhancedSkill
end
function PlayerEquipmentData:GetCharEquipmentRandomAttr(nCharId)
local tbEquipedGem = self:GetEquipedGem(nCharId)
if not tbEquipedGem or #tbEquipedGem == 0 then
return {}
end
local tbRandomAttrList = {}
for _, mapEquipment in pairs(tbEquipedGem) do
local mapRandomAttr = mapEquipment:GetRandomAttr()
for k, v in ipairs(mapRandomAttr) do
local nAttrId = v.AttrId
if nAttrId ~= nil then
local nCfgValue = v.CfgValue
local nValue = v.Value
if nil == tbRandomAttrList[nAttrId] then
tbRandomAttrList[nAttrId] = {CfgValue = nCfgValue, Value = nValue}
else
tbRandomAttrList[nAttrId].CfgValue = tbRandomAttrList[nAttrId].CfgValue + nCfgValue
tbRandomAttrList[nAttrId].Value = tbRandomAttrList[nAttrId].Value + nValue
end
end
end
end
for _, v in pairs(tbRandomAttrList) do
v.CfgValue = clearFloat(v.CfgValue)
end
return tbRandomAttrList
end
function PlayerEquipmentData:GetCharEquipmentEffect(nCharId)
local tbEquipedGem = self:GetEquipedGem(nCharId)
if not tbEquipedGem or #tbEquipedGem == 0 then
return {}
end
local tbAllEffect = {}
for _, mapEquipment in pairs(tbEquipedGem) do
local tbEffect = mapEquipment:GetEffect()
for _, v in pairs(tbEffect) do
table.insert(tbAllEffect, v)
end
end
return tbAllEffect
end
function PlayerEquipmentData:GetRollWarning()
return self.bRollWarning
end
function PlayerEquipmentData:SetRollWarning(bAble)
self.bRollWarning = bAble
end
function PlayerEquipmentData:UpdateRedDot()
end
function PlayerEquipmentData:SendCharGemEquipGemReq(nCharId, nSlotId, nGemIndex, nPresetId, callback)
local msgData = {
CharId = nCharId,
SlotId = nSlotId,
GemIndex = nGemIndex - 1,
PresetId = nPresetId - 1
}
local successCallback = function(_, mapMainData)
self.tbCharPreset[nCharId][nPresetId].tbSlot[nSlotId] = nGemIndex
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_equip_gem_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemRenamePresetReq(nCharId, nPresetId, sNewName, callback)
local msgData = {
CharId = nCharId,
PresetId = nPresetId - 1,
NewName = sNewName
}
local successCallback = function(_, mapMainData)
self.tbCharPreset[nCharId][nPresetId].sName = sNewName
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_rename_preset_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemReplaceAttributeReq(nCharId, nSlotId, nGemIndex, callback)
local msgData = {
CharId = nCharId,
SlotId = nSlotId,
GemIndex = nGemIndex - 1
}
local successCallback = function(_, mapMainData)
self.tbCharEquipment[nCharId][nSlotId][nGemIndex]:ReplaceRandomAttr()
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_replace_attribute_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemUpdateGemLockStatusReq(nCharId, nSlotId, nGemIndex, bLock, callback)
local msgData = {
CharId = nCharId,
SlotId = nSlotId,
GemIndex = nGemIndex - 1,
Lock = bLock
}
local successCallback = function(_, mapMainData)
self.tbCharEquipment[nCharId][nSlotId][nGemIndex]:UpdateLockState(bLock)
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_update_gem_lock_status_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemUsePresetReq(nCharId, nPresetId, callback)
local msgData = {
CharId = nCharId,
PresetId = nPresetId - 1
}
local successCallback = function(_, mapMainData)
self.tbCharSelectPreset[nCharId] = nPresetId
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_use_preset_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemRefreshReq(nCharId, nSlotId, nGemIndex, tbLockAttrs, callback)
local msgData = {
CharId = nCharId,
SlotId = nSlotId,
GemIndex = nGemIndex - 1,
LockAttrs = tbLockAttrs
}
local successCallback = function(_, mapMainData)
self.tbCharEquipment[nCharId][nSlotId][nGemIndex]:UpdateAlterAffix(mapMainData.Attributes)
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_refresh_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:SendCharGemGenerateReq(nCharId, nSlotId, callback)
local msgData = {CharId = nCharId, SlotId = nSlotId}
local successCallback = function(_, mapMainData)
local nGemId = self:GetGemIdBySlot(nCharId, nSlotId)
local equipmentData = EquipmentData.new(mapMainData.CharGem, nCharId, nGemId)
table.insert(self.tbCharEquipment[nCharId][nSlotId], equipmentData)
local nNewIndex = #self.tbCharEquipment[nCharId][nSlotId]
if callback then
callback(nNewIndex)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_generate_req, msgData, nil, successCallback)
end
function PlayerEquipmentData:CacheEquipmentDataForChar(mapMsgData)
if self.tbCharPreset == nil then
self.tbCharPreset = {}
end
if self.tbCharSelectPreset == nil then
self.tbCharSelectPreset = {}
end
if self.tbCharEquipment == nil then
self.tbCharEquipment = {}
end
local nCharId = mapMsgData.CharId
local mapPresetList = mapMsgData.CharGemPresets
self.tbCharSelectPreset[nCharId] = mapPresetList.InUsePresetIndex + 1
self.tbCharPreset[nCharId] = self:CreateNewPresetData(mapPresetList.CharGemPresets)
self.tbCharEquipment[nCharId] = self:CreateNewEquipmentData(mapMsgData.CharGemSlots, nCharId)
end
return PlayerEquipmentData
@@ -0,0 +1,345 @@
local PlayerEquipmentInstanceData = class("PlayerEquipmentInstanceData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
function PlayerEquipmentInstanceData:Init()
self.curLevel = nil
self.mapAllLevel = {}
self.bInSettlement = false
self.tbLastMaxHard = {}
self.mapLevelCfg = {}
self:InitConfigData()
EventManager.Add("Equipment_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function PlayerEquipmentInstanceData:OnEvent_Time(nTime)
self._TotalTime = nTime
end
function PlayerEquipmentInstanceData:UnInit()
EventManager.Remove("Equipment_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function PlayerEquipmentInstanceData:InitConfigData()
local funcForeachLine = function(line)
if nil == self.mapLevelCfg[line.Type] then
self.mapLevelCfg[line.Type] = {}
end
self.mapLevelCfg[line.Type][line.Id] = line
end
ForEachTableLine(ConfigTable.Get("CharGemInstance"), funcForeachLine)
end
function PlayerEquipmentInstanceData:EnterEquipmentInstanceEditor(nFloor, tbChar, tbDisc, tbNote)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.EquipmentInstance.EquipmentInstanceEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nFloor, tbChar, tbDisc, tbNote)
end
end
function PlayerEquipmentInstanceData:EnterEquipmentInstance(nLevelId, nBuildId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.EquipmentInstance.EquipmentInstanceLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId)
end
end
function PlayerEquipmentInstanceData:SetSelBuildId(nBuildId)
self.selBuildId = nBuildId
end
function PlayerEquipmentInstanceData:GetCachedBuildId(nLevelId)
if self.selBuildId ~= 0 and self.selBuildId ~= nil then
local ret = self.selBuildId
return ret
end
if nLevelId == 0 then
return 0
end
if self.mapAllLevel[nLevelId] == nil then
local mapLevelCfgData = ConfigTable.GetData("CharGemInstance", nLevelId)
if mapLevelCfgData == nil then
return 0
end
if mapLevelCfgData.PreLevelId ~= 0 then
if self.mapAllLevel[mapLevelCfgData.PreLevelId] ~= nil then
return self.mapAllLevel[mapLevelCfgData.PreLevelId].nBuildId
else
return 0
end
else
return 0
end
end
return self.mapAllLevel[nLevelId].nBuildId
end
function PlayerEquipmentInstanceData:CacheEquipmentInstanceLevel(tbData)
if tbData == nil then
return
end
for _, mapData in ipairs(tbData) do
local t1 = mapData.Star >= 1
local t2 = mapData.Star >= 2
local t3 = mapData.Star >= 3
local nStar = mapData.Star
self.mapAllLevel[mapData.Id] = {
nStar = nStar,
nBuildId = mapData.BuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
end
function PlayerEquipmentInstanceData:GetEquipmentInstanceLevelUnlock(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("CharGemInstance", nLevelId)
if mapLevelCfgData == nil then
return false
end
if mapLevelCfgData.PreLevelId == 0 then
return true
end
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
return false, mapLevelCfgData.NeedWorldClass
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil then
return false
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar >= mapLevelCfgData.PreLevelStar then
return true
end
return false
end
function PlayerEquipmentInstanceData:GetEquipmentInstanceUnlockMsg(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("CharGemInstance", nLevelId)
if mapLevelCfgData.PreLevelId == 0 then
return true
end
local isWorldClass = true
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
isWorldClass = false
end
local isPreLevelStar = true
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil or self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar < mapLevelCfgData.PreLevelStar then
isPreLevelStar = false
end
if isWorldClass == false or isPreLevelStar == false then
return false, isWorldClass, isPreLevelStar
end
return true
end
function PlayerEquipmentInstanceData:GetEquipmentInstanceStar(nLevelId)
if nLevelId == nil then
return 0, {
false,
false,
false
}
end
if self.mapAllLevel[nLevelId] == nil then
return 0, {
false,
false,
false
}
end
return self.mapAllLevel[nLevelId].nStar, self.mapAllLevel[nLevelId].tbTarget == nil and {
false,
false,
false
} or self.mapAllLevel[nLevelId].tbTarget
end
function PlayerEquipmentInstanceData:MsgEnterEquipmentInstance(nLevelId, nBuildId, callback)
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
self._Build_id = nBuildId
self._Level_id = nLevelId
local msg = {}
msg.Id = nLevelId
msg.BuildId = nBuildId
local msgCallback = function(_, mapChangeInfo)
self:EnterEquipmentInstance(nLevelId, nBuildId)
if self.mapAllLevel[nLevelId] == nil then
self.mapAllLevel[nLevelId] = {nStar = 0, nBuildId = 0}
end
self.mapAllLevel[nLevelId].nBuildId = nBuildId
if callback ~= nil then
callback(mapChangeInfo)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_instance_apply_req, msg, nil, msgCallback)
end
function PlayerEquipmentInstanceData:MsgSettleEquipmentInstance(nLevelId, nBuildId, nStar, callback)
local msg = {}
msg.Star = nStar
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.EquipmentInstance, 0 < nStar)
}
local msgCallback = function(_, mapMsgData)
local t1 = 1 <= nStar
local t2 = 2 <= nStar
local t3 = 3 <= nStar
if self.mapAllLevel[nLevelId] ~= nil then
if self.mapAllLevel[nLevelId].nStar < nStar then
self.mapAllLevel[nLevelId].nStar = nStar
end
if self.mapAllLevel[nLevelId].tbTarget == nil then
self.mapAllLevel[nLevelId].tbTarget = {
false,
false,
false
}
end
self.mapAllLevel[nLevelId].tbTarget[1] = t1 or self.mapAllLevel[nLevelId].tbTarget[1]
self.mapAllLevel[nLevelId].tbTarget[2] = t2 or self.mapAllLevel[nLevelId].tbTarget[2]
self.mapAllLevel[nLevelId].tbTarget[3] = t3 or self.mapAllLevel[nLevelId].tbTarget[3]
else
self.mapAllLevel[nLevelId] = {
nStar = nStar,
nBuildId = nBuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
if callback ~= nil then
callback(mapMsgData.AwardItems, mapMsgData.FirstItems, mapMsgData.SurpriseItems, mapMsgData.Exp, mapMsgData.Change)
end
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self._TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self._Build_id)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self._Level_id)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(1)
})
NovaAPI.UserEventUpload("equipment_instance_battle", tabUpLevel)
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_instance_settle_req, msg, nil, msgCallback)
end
function PlayerEquipmentInstanceData:LevelEnd()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerEquipmentInstanceData.CalStar(nOrigin)
nOrigin = (nOrigin & 1431655765) + (nOrigin >> 1 & 1431655765)
nOrigin = (nOrigin & 858993459) + (nOrigin >> 2 & 858993459)
nOrigin = (nOrigin & 252645135) + (nOrigin >> 4 & 252645135)
nOrigin = nOrigin * 16843009 >> 24
return nOrigin
end
function PlayerEquipmentInstanceData:GetCurLevel()
if self.curLevel == nil then
return 0
end
return self.curLevel.nLevelId
end
function PlayerEquipmentInstanceData:SetLastMaxHard(nGroupId, nMaxHard)
self.tbLastMaxHard[nGroupId] = nMaxHard
end
function PlayerEquipmentInstanceData:GetLastMaxHard(nGroupId)
return self.tbLastMaxHard[nGroupId] or 0
end
function PlayerEquipmentInstanceData:GetMaxEquipmentInstanceHard(nType)
local retHard = 1
local tbLevelList = self.mapLevelCfg[nType]
if nil ~= tbLevelList then
for nLevelId, mapLevel in pairs(tbLevelList) do
if self:GetEquipmentInstanceLevelUnlock(nLevelId) then
retHard = math.max(mapLevel.Difficulty, retHard)
end
end
end
return retHard
end
function PlayerEquipmentInstanceData:GetLevelOpenState(nType)
local mapData = ConfigTable.GetData("CharGemInstanceType", nType)
if nil ~= mapData then
return AllEnum.EquipmentInstanceState.Open, true
end
return AllEnum.EquipmentInstanceState.None
end
function PlayerEquipmentInstanceData:GetUnOpenTipText(nLevelState, nType)
local sTipStr = ""
if nLevelState == AllEnum.EquipmentInstanceState.Not_WorldClass then
elseif nLevelState == AllEnum.EquipmentInstanceState.Not_HardUnlock then
sTipStr = ConfigTable.GetUIText("Level_Lock")
end
return sTipStr
end
function PlayerEquipmentInstanceData:CheckLevelOpen(nType, nHard, bShowTips)
if nType == 0 then
return AllEnum.EquipmentInstanceState.Open
end
local nLevelState, bUnlock = self:GetLevelOpenState(nType)
if nil ~= nHard and nLevelState == AllEnum.EquipmentInstanceState.Open then
local nMaxUnlockHard = self:GetMaxEquipmentInstanceHard(nType)
if nHard > nMaxUnlockHard then
nLevelState = AllEnum.EquipmentInstanceState.Not_HardUnlock
end
end
if true == bShowTips then
local sTipStr = self:GetUnOpenTipText(nLevelState, nType)
if nil ~= sTipStr and "" ~= sTipStr then
EventManager.Hit(EventId.OpenMessageBox, sTipStr)
end
end
return nLevelState == AllEnum.EquipmentInstanceState.Open, bUnlock
end
function PlayerEquipmentInstanceData:SetSettlementState(bInSettlement)
self.bInSettlement = bInSettlement
end
function PlayerEquipmentInstanceData:GetSettlementState()
return self.bInSettlement
end
function PlayerEquipmentInstanceData:SendEquipmentInstanceRaidReq(nId, nCount, callback)
local Events = {}
local msgData = {Id = nId, Times = nCount}
if 0 < #Events then
msgData.Events = {
List = {}
}
msgData.Events.List = Events
end
local successCallback = function(_, mapMainData)
callback(mapMainData.Rewards, mapMainData.Change)
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_gem_instance_sweep_req, msgData, nil, successCallback)
end
return PlayerEquipmentInstanceData
@@ -0,0 +1,375 @@
local PlayerFriendData = class("PlayerFriendData")
local TimerManager = require("GameCore.Timer.TimerManager")
local EnergyState = {
None = 0,
Able = 1,
Received = 2
}
function PlayerFriendData:Init()
self._tbFriendList = {}
self._tbFriendRequest = {}
self._nFriendListNum = 0
self._nFriendRequestNum = 0
self._nEnergyCount = 0
self._nPerReceiveEnergyConfig = ConfigTable.GetConfigNumber("FriendReceiveEnergyCount")
self._nMaxReceiveEnergyConfig = ConfigTable.GetConfigNumber("FriendReceiveEnergyMax")
end
function PlayerFriendData:CacheFriendData(mapMsgData)
self._tbFriendList = {}
self._nFriendListNum = 0
if mapMsgData.ReceiveEnergyCnt then
self._nEnergyCount = mapMsgData.ReceiveEnergyCnt
end
for _, mapFriendInfo in pairs(mapMsgData.Friends) do
local nId = mapFriendInfo.Base and mapFriendInfo.Base.Id or mapFriendInfo.Id
self._tbFriendList[nId] = {}
self:ParseFriendData(self._tbFriendList[nId], mapFriendInfo)
self._nFriendListNum = self._nFriendListNum + 1
end
self._tbFriendRequest = {}
self._nFriendRequestNum = 0
for nIndex, mapFriendInfo in pairs(mapMsgData.Invites) do
self._tbFriendRequest[nIndex] = {}
self:ParseFriendData(self._tbFriendRequest[nIndex], mapFriendInfo)
self._nFriendRequestNum = self._nFriendRequestNum + 1
end
self:UpdateFriendApplyRedDot()
self:UpdateFriendEnergyRedDot()
end
function PlayerFriendData:ParseFriendData(tbData, tbServer)
if tbServer.Base then
self:ParseFriendDetail(tbData, tbServer.Base)
tbData.nGetEnergy = tbServer.GetEnergy
tbData.bSendEnergy = tbServer.SendEnergy
tbData.bStar = tbServer.Star
else
self:ParseFriendDetail(tbData, tbServer)
end
end
function PlayerFriendData:ParseFriendDetail(tbData, tbServer)
tbData.nHashtag = tbServer.Hashtag
tbData.nHeadIconId = tbServer.HeadIcon
tbData.nUId = tbServer.Id
tbData.nLogin = tbServer.LastLoginTime
tbData.sName = tbServer.NickName
tbData.nTitlePrefix = tbServer.TitlePrefix
tbData.nTitleSuffix = tbServer.TitleSuffix
tbData.sName = tbServer.NickName
tbData.nWorldClass = tbServer.WorldClass
tbData.tbChar = tbServer.CharShows
tbData.sSign = tbServer.Signature
tbData.tbHonorTitle = tbServer.Honors
end
function PlayerFriendData:GetFriendListData()
local tbList = {}
if not self._tbFriendList then
return tbList
end
for _, v in pairs(self._tbFriendList) do
table.insert(tbList, v)
end
table.sort(tbList, function(a, b)
if a.bStar ~= b.bStar then
return a.bStar and not b.bStar
else
return a.nUId < b.nUId
end
end)
return tbList
end
function PlayerFriendData:GetFriendListNum()
return self._nFriendListNum
end
function PlayerFriendData:GetFriendRequestData()
return self._tbFriendRequest
end
function PlayerFriendData:GetFriendRequestNum()
return self._nFriendRequestNum
end
function PlayerFriendData:JudgeIsFriend(nUId)
return self._tbFriendList and self._tbFriendList[nUId]
end
function PlayerFriendData:GetEnergyCount()
return self._nEnergyCount
end
function PlayerFriendData:JudgeEnergyGetAble()
if not self._tbFriendList then
return false
end
for _, v in pairs(self._tbFriendList) do
if v.nGetEnergy == EnergyState.Able then
return true
end
end
return false
end
function PlayerFriendData:JudgeEnergySendAble()
if not self._tbFriendList then
return false
end
for _, v in pairs(self._tbFriendList) do
if v.bSendEnergy == false then
return true
end
end
return false
end
function PlayerFriendData:JudgeLogin(nNanoTime)
local nTime = math.floor(nNanoTime / 1.0E9)
local nYear = tonumber(os.date("%Y", nTime))
local nMonth = tonumber(os.date("%m", nTime))
local nDay = tonumber(os.date("%d", nTime))
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
if nCurTime - nTime <= 86400 then
return ConfigTable.GetUIText("Friend_Today"), AllEnum.LoginTime.Today
else
return nYear .. "." .. nMonth .. "." .. nDay
end
end
function PlayerFriendData:DeleteFriend(nUId)
if not self._tbFriendList then
return
end
if self._tbFriendList[nUId] then
self._tbFriendList[nUId] = nil
self._nFriendListNum = self._nFriendListNum - 1
end
self:UpdateFriendEnergyRedDot()
end
function PlayerFriendData:AddFriend(mapMainData)
if not self._tbFriendList then
self._tbFriendList = {}
end
if self._tbFriendList[mapMainData.Friend.Id] then
return
end
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("add_friend", tab)
self._tbFriendList[mapMainData.Friend.Id] = {}
self:ParseFriendData(self._tbFriendList[mapMainData.Friend.Id], mapMainData.Friend)
self._nFriendListNum = self._nFriendListNum + 1
self:UpdateFriendEnergyRedDot()
end
function PlayerFriendData:DeleteRequest(nUId)
if not self._tbFriendRequest then
return
end
for nIndex, mapFriendInfo in pairs(self._tbFriendRequest) do
if nUId == mapFriendInfo.nUId then
table.remove(self._tbFriendRequest, nIndex)
self._nFriendRequestNum = self._nFriendRequestNum - 1
return
end
end
self:UpdateFriendApplyRedDot()
end
function PlayerFriendData:UpdateFriendState(mapFriendState)
local nAction = mapFriendState.Action
local nUId = mapFriendState.Id
if nAction == 2 then
self:DeleteRequest(nUId)
EventManager.Hit("FriendRefreshRequest")
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("add_friend", tab)
elseif nAction == 3 then
self:DeleteFriend(nUId)
EventManager.Hit("FriendRefreshList")
end
if nAction == 1 then
RedDotManager.SetValid(RedDotDefine.Friend_Apply, nil, true)
end
end
function PlayerFriendData:UpdateFriendEnergy(mapData)
RedDotManager.SetValid(RedDotDefine.Friend_Energy, nil, mapData.State)
end
function PlayerFriendData:SetTimer(nTime)
if nTime <= 0 then
return
end
self.bCD = true
if self.timer ~= nil then
self.timer:Cancel(false)
self.timer = nil
end
self.nCd = nTime
self.timer = TimerManager.Add(1, nTime, self, function()
self.bCD = false
end, true, true, false)
end
function PlayerFriendData:SendFriendListGetReq(callback)
if self.bCD then
callback()
return
end
local successCallback = function(_, mapMainData)
self:SetTimer(2)
self:CacheFriendData(mapMainData)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_list_get_req, {}, nil, successCallback)
end
function PlayerFriendData:SendFriendDeleteReq(nUId, callback)
local msgData = {UId = nUId}
local successCallback = function(_, mapMainData)
self:DeleteFriend(nUId)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_delete_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendAddAgreeReq(nUId, callback)
local msgData = {UId = nUId}
local successCallback = function(_, mapMainData)
self:AddFriend(mapMainData)
self:DeleteRequest(nUId)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_add_agree_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendAllAgreeReq(callback)
local successCallback = function(_, mapMainData)
self:CacheFriendData(mapMainData)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_all_agree_req, {}, nil, successCallback)
end
function PlayerFriendData:SendFriendInvitesDeleteReq(tbUId, callback)
local msgData = {UIds = tbUId}
local successCallback = function(_, mapMainData)
for _, nUId in pairs(tbUId) do
self:DeleteRequest(nUId)
end
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_invites_delete_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendAddFriendReq(nUId, callback)
local msgData = {UId = nUId}
local successCallback = function(_, mapMainData)
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_add_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendNameSearchReq(sName, callback)
local msgData = {Name = sName}
local successCallback = function(_, mapMainData)
if not mapMainData.Friends or #mapMainData.Friends == 0 then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Friend_SearchNone")
})
else
local tbSearch = {}
for nIndex, mapFriendInfo in pairs(mapMainData.Friends) do
tbSearch[nIndex] = {}
self:ParseFriendData(tbSearch[nIndex], mapFriendInfo)
end
callback(tbSearch)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_name_search_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendUIdSearchReq(nUId, callback)
local msgData = {Id = nUId}
local successCallback = function(_, mapMainData)
if not mapMainData.Friend then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Friend_SearchNone")
})
else
local tbSearch = {}
tbSearch[1] = {}
self:ParseFriendData(tbSearch[1], mapMainData.Friend)
callback(tbSearch)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_uid_search_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendReceiveEnergyReq(tbUId, callback)
local msgData = {UIds = tbUId}
local successCallback = function(_, mapMainData)
local nBefore = self._nEnergyCount
for _, nId in pairs(mapMainData.UIds) do
if self._tbFriendList[nId] then
self._tbFriendList[nId].nGetEnergy = EnergyState.Received
end
end
self._nEnergyCount = mapMainData.ReceiveEnergyCnt
EventManager.Hit(EventId.OpenPanel, PanelId.ReceivePropsTips, {
{
id = AllEnum.CoinItemId.Energy,
count = self._nEnergyCount - nBefore
}
})
callback(mapMainData.UIds)
self:UpdateFriendEnergyRedDot()
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_receive_energy_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendSendEnergyReq(tbUId, callback)
local msgData = {UIds = tbUId}
local successCallback = function(_, mapMainData)
for _, nId in pairs(mapMainData.UIds) do
if self._tbFriendList[nId] then
self._tbFriendList[nId].bSendEnergy = true
end
end
callback(mapMainData.UIds)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_send_energy_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendStarSetReq(tbUId, bStar, callback)
local msgData = {UIds = tbUId, Star = bStar}
local successCallback = function(_, mapMainData)
for _, nId in pairs(tbUId) do
if self._tbFriendList[nId] then
self._tbFriendList[nId].bStar = bStar
end
end
callback(mapMainData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_star_set_req, msgData, nil, successCallback)
end
function PlayerFriendData:SendFriendRecommendationGetReq(callback)
local successCallback = function(_, mapMainData)
if not mapMainData.Friends or #mapMainData.Friends == 0 then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Friend_NoneRecommend")
})
else
local tbSearch = {}
for nIndex, mapFriendInfo in pairs(mapMainData.Friends) do
tbSearch[nIndex] = {}
self:ParseFriendData(tbSearch[nIndex], mapFriendInfo)
end
callback(tbSearch)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.friend_recommendation_get_req, {}, nil, successCallback)
end
function PlayerFriendData:UpdateFriendApplyRedDot()
RedDotManager.SetValid(RedDotDefine.Friend_Apply, nil, self._nFriendRequestNum > 0)
end
function PlayerFriendData:UpdateFriendEnergyRedDot()
local bCheck = false
local bMax = PlayerData.Friend:GetEnergyCount() >= self._nMaxReceiveEnergyConfig
if self._tbFriendList and not bMax then
for _, v in pairs(self._tbFriendList) do
if v.nGetEnergy == EnergyState.Able then
bCheck = true
break
end
end
end
RedDotManager.SetValid(RedDotDefine.Friend_Energy, nil, bCheck)
end
return PlayerFriendData
@@ -0,0 +1,583 @@
local RapidJson = require("rapidjson")
local PlayerGachaData = class("PlayerGachaData")
function IsOpenCardPool(sStartTime, sEndTime)
if string.len(sStartTime) == 0 or string.len(sEndTime) == 0 then
return true
end
local nowTime = CS.ClientManager.Instance.serverTimeStamp
return nowTime > String2Time(sStartTime) and nowTime < String2Time(sEndTime)
end
function String2Time(sTime)
if sTime ~= "" then
return CS.ClientManager.Instance:ISO8601StrToTimeStamp(sTime)
else
return 0
end
end
function PlayerGachaData:Init()
self.hadData = false
self._openedPool = {}
self:RefreshOpenedPool()
self._mapGachaCount = {}
self._mapAupMissTimes = {}
self._mapAMissTimes = {}
self._AupGuaranteeTimes = {}
self._mapTotalGachaTimes = {}
self._mapRecvFirstTenReward = {}
self._mapRecvGuaranteeReward = {}
self._mapGachaTotalTimes = {}
self._mapGachaHistory = {}
self._mapPoolProbCache = {}
self._mapNewbieData = {}
local func_ForEach_Gacha = function(mapGacha)
if type(mapGacha.OnceTicket) == "string" then
mapGacha.OnceTicket = RapidJson.decode(mapGacha.OnceTicket)
end
if type(mapGacha.TenTimesTicket) == "string" then
mapGacha.TenTimesTicket = RapidJson.decode(mapGacha.TenTimesTicket)
end
end
ForEachTableLine(DataTable.Gacha, func_ForEach_Gacha)
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerGachaData:RefreshOpenedPool()
self._openedPool = {}
local func_ForEach_Gacha = function(mapGacha)
if IsOpenCardPool(mapGacha.StartTime, mapGacha.EndTime) then
table.insert(self._openedPool, mapGacha.ID)
end
end
ForEachTableLine(DataTable.Gacha, func_ForEach_Gacha)
end
function PlayerGachaData:GetOpenedPool()
local ret = {}
local func_ForEach_Gacha = function(mapGacha)
if mapGacha.StorageId == GameEnum.gachaStorageType.BeginnerCardPool then
local newbieData = self:GetGachaNewbieData(mapGacha.Id)
if newbieData ~= nil and not newbieData.Receive then
table.insert(ret, mapGacha.Id)
end
elseif IsOpenCardPool(mapGacha.StartTime, mapGacha.EndTime) then
table.insert(ret, mapGacha.Id)
end
end
ForEachTableLine(DataTable.Gacha, func_ForEach_Gacha)
return ret
end
function PlayerGachaData:CacheGachaData(mapData)
for k, v in pairs(mapData) do
self._mapGachaCount[v.Id] = v.DaysCount
self._mapAupMissTimes[v.Id] = v.AupMissTimes
self._mapTotalGachaTimes[v.Id] = v.TotalTimes
self._AupGuaranteeTimes[v.Id] = v.AupGuaranteeTimes
self._mapRecvFirstTenReward[v.Id] = v.ReveFirstTenReward
self._mapRecvGuaranteeReward[v.Id] = v.RecvGuaranteeReward
self._mapGachaTotalTimes[v.Id] = v.GachaTotalTimes
self._mapAMissTimes[v.Id] = v.AMissTimes
end
end
function PlayerGachaData:CacheGachaHistory(nSaveId, mapData)
if self._mapGachaHistory[nSaveId] == nil then
self._mapGachaHistory[nSaveId] = {}
end
for _, mapHistory in ipairs(mapData.List) do
table.insert(self._mapGachaHistory[nSaveId], mapHistory)
end
end
function PlayerGachaData:AddGachaHistory(nSaveId, nGachaId, mapData)
if self._mapGachaHistory[nSaveId] == nil then
return
end
local Ids = {}
for _, mapCard in ipairs(mapData.Cards) do
table.insert(Ids, mapCard.Card.Tid)
end
table.insert(self._mapGachaHistory[nSaveId], {
Ids = Ids,
Time = mapData.Time,
Gid = nGachaId
})
end
function PlayerGachaData:GetGachaCountById(nPoolID)
if self._mapGachaCount[nPoolID] == nil then
return 0
else
return self._mapGachaCount[nPoolID]
end
end
function PlayerGachaData:GetGachaTotalCountById(nPoolID)
if self._mapTotalGachaTimes[nPoolID] == nil then
return 0
else
return self._mapTotalGachaTimes[nPoolID]
end
end
function PlayerGachaData:GetAupMissTimesById(nPoolID)
local mapPoolCfgData = ConfigTable.GetData("Gacha", nPoolID)
if self._mapAupMissTimes[nPoolID] == nil then
if mapPoolCfgData ~= nil then
for nId, nCount in pairs(self._mapAupMissTimes) do
local mapPoolCfg = ConfigTable.GetData("Gacha", nId)
if mapPoolCfg ~= nil and mapPoolCfg.StorageId == mapPoolCfgData.StorageId then
self._mapAupMissTimes[nPoolID] = nCount
return self._mapAupMissTimes[nPoolID]
end
end
else
return 0
end
else
return self._mapAupMissTimes[nPoolID]
end
return 0
end
function PlayerGachaData:GetAMissTimesById(nPoolID)
local mapPoolCfgData = ConfigTable.GetData("Gacha", nPoolID)
if self._mapAMissTimes[nPoolID] == nil then
if mapPoolCfgData ~= nil then
for nId, nCount in pairs(self._mapAMissTimes) do
local mapPoolCfg = ConfigTable.GetData("Gacha", nId)
if mapPoolCfg ~= nil and mapPoolCfg.StorageId == mapPoolCfgData.StorageId then
self._mapAMissTimes[nPoolID] = nCount
return self._mapAMissTimes[nPoolID]
end
end
else
return 0
end
else
return self._mapAMissTimes[nPoolID]
end
return 0
end
function PlayerGachaData:GetAupGuaranteeById(nPoolID)
local mapPoolCfgData = ConfigTable.GetData("Gacha", nPoolID)
if self._AupGuaranteeTimes[nPoolID] == nil then
if mapPoolCfgData ~= nil then
for nId, nCount in pairs(self._AupGuaranteeTimes) do
local mapPoolCfg = ConfigTable.GetData("Gacha", nId)
if mapPoolCfg ~= nil and mapPoolCfg.StorageId == mapPoolCfgData.StorageId then
self._AupGuaranteeTimes[nPoolID] = nCount
return self._AupGuaranteeTimes[nPoolID]
end
end
else
return 0
end
else
return self._AupGuaranteeTimes[nPoolID]
end
return 0
end
function PlayerGachaData:GetRecvFirstTenReward(nPoolID)
if self._mapRecvFirstTenReward[nPoolID] == nil then
return false
else
return self._mapRecvFirstTenReward[nPoolID]
end
end
function PlayerGachaData:GetRecvGuaranteeReward(nPoolID)
if self._mapRecvGuaranteeReward[nPoolID] == nil then
return false
else
return self._mapRecvGuaranteeReward[nPoolID]
end
end
function PlayerGachaData:GetGachaTotalTimes(nPoolID)
if self._mapGachaTotalTimes[nPoolID] == nil then
return 0
else
return self._mapGachaTotalTimes[nPoolID]
end
end
function PlayerGachaData:GachaCountChanged(nPoolID, nDayCount)
self._mapGachaCount[nPoolID] = nDayCount
end
function PlayerGachaData:AupMissTimesCountChanged(nPoolID, nCount)
local mapPoolCfgData = ConfigTable.GetData("Gacha", nPoolID)
if mapPoolCfgData ~= nil then
if nCount == nil then
nCount = 0
end
for nId, _ in pairs(self._mapAupMissTimes) do
local mapPoolCfg = ConfigTable.GetData("Gacha", nId)
if mapPoolCfg ~= nil and mapPoolCfg.StorageId == mapPoolCfgData.StorageId then
self._mapAupMissTimes[nId] = nCount
end
end
end
self._mapAupMissTimes[nPoolID] = nCount
end
function PlayerGachaData:AMissTimesCountChanged(nPoolID, nCount)
local mapPoolCfgData = ConfigTable.GetData("Gacha", nPoolID)
if mapPoolCfgData ~= nil then
if nCount == nil then
nCount = 0
end
for nId, _ in pairs(self._mapAMissTimes) do
local mapPoolCfg = ConfigTable.GetData("Gacha", nId)
if mapPoolCfg ~= nil and mapPoolCfg.StorageId == mapPoolCfgData.StorageId then
self._mapAMissTimes[nId] = nCount
end
end
end
self._mapAMissTimes[nPoolID] = nCount
end
function PlayerGachaData:TotalCountChanged(nPoolID, nCount)
self._mapTotalGachaTimes[nPoolID] = nCount
end
function PlayerGachaData:AupGuaranteeTimesChanged(nPoolID, nCount)
self._AupGuaranteeTimes[nPoolID] = nCount
end
function PlayerGachaData:RecvFirstTenReward(nPoolID, bValue)
self._mapRecvFirstTenReward[nPoolID] = bValue
end
function PlayerGachaData:RecvGuaranteeReward(nPoolID, bValue)
self._mapRecvGuaranteeReward[nPoolID] = bValue
end
function PlayerGachaData:GachaTotalTimes(nPoolID, nCount)
self._mapGachaTotalTimes[nPoolID] = nCount
end
function PlayerGachaData:GetGachaInfomation(callback)
local GetInfoCallback = function(_, mapData)
self.hadData = true
self:CacheGachaData(mapData.Information)
if type(callback) == "function" then
callback()
end
end
if self.hadData then
if type(callback) == "function" then
callback()
end
else
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_information_req, {}, nil, GetInfoCallback)
end
end
function PlayerGachaData:GetGachaHistory(nSaveId, callback)
if self._mapGachaHistory[nSaveId] ~= nil then
if type(callback) == "function" then
callback(self._mapGachaHistory[nSaveId])
end
return
end
local GetHistoryCallback = function(_, mapData)
self:CacheGachaHistory(nSaveId, mapData)
if type(callback) == "function" then
callback(self._mapGachaHistory[nSaveId])
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_histories_req, {Value = nSaveId}, nil, GetHistoryCallback)
end
function PlayerGachaData:SendGachaReq(nId, nMode, callback)
local GachaCallback = function(_, mapData)
self:GachaCountChanged(nId, mapData.DaysCount)
self:AupMissTimesCountChanged(nId, mapData.AupMissTimes)
self:AMissTimesCountChanged(nId, mapData.AMissTimes)
self:TotalCountChanged(nId, mapData.TotalTimes)
self:AupGuaranteeTimesChanged(nId, mapData.AupGuaranteeTimes)
self:GachaTotalTimes(nId, mapData.GachaTotalTimes)
if nMode == 2 then
self:RecvFirstTenReward(nId, true)
end
local mapGacha = ConfigTable.GetData("Gacha", nId)
if mapGacha ~= nil and mapGacha.StorageId > 0 then
self:AddGachaHistory(mapGacha.StorageId, nId, mapData)
end
if type(callback) == "function" then
callback(mapData)
end
if nMode == 2 then
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
if mapGacha.StorageId == GameEnum.gachaStorageType.CharacterCardPool then
NovaAPI.UserEventUpload("standard_trekker_gacha10", tab)
elseif mapGacha.StorageId == GameEnum.gachaStorageType.DiscCardPool then
NovaAPI.UserEventUpload("standard_disc_gacha10", tab)
elseif mapGacha.StorageId == GameEnum.gachaStorageType.CharacterUpCardPool then
NovaAPI.UserEventUpload("limited_trekker_gacha10", tab)
elseif mapGacha.StorageId == GameEnum.gachaStorageType.DiscUpCardPool then
NovaAPI.UserEventUpload("limited_disc_gacha10", tab)
elseif mapGacha.StorageId == GameEnum.gachaStorageType.BeginnerCardPool then
NovaAPI.UserEventUpload("guaranteed5star_gacha10", tab)
end
end
end
local mapMsgData = {Id = nId, Mode = nMode}
EventManager.Hit("GachaProcessStart", true)
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_spin_req, mapMsgData, nil, GachaCallback)
end
function PlayerGachaData:GetPoolProbData(nPoolId)
if self._mapPoolProbCache[nPoolId] ~= nil then
return self._mapPoolProbCache[nPoolId]
else
local probUpItem, probItem = self:GetPoolProbDetail(nPoolId)
self._mapPoolProbCache[nPoolId] = {tbProbUpItem = probUpItem, tbProbItem = probItem}
end
end
function PlayerGachaData:GetPoolProbDetail(nPoolID)
local tbUpItemList = {}
local tbItemList = {}
local gachaConfig = ConfigTable.GetData("Gacha", nPoolID)
local nStorageType = gachaConfig.StorageId
local gachaStorageConfig = ConfigTable.GetData("GachaStorage", nStorageType)
local nBTypeProb = gachaStorageConfig.BTypeProb
local gachaATypeProbConfig
local func_ForEach_GachaATypeProb = function(mapData)
if mapData.Group == gachaStorageConfig.ATypeGroup and mapData.Times == 0 then
gachaATypeProbConfig = mapData
end
end
ForEachTableLine(DataTable.GachaATypeProb, func_ForEach_GachaATypeProb)
local nATypeProb = gachaATypeProbConfig.Prob
local nCTypeProb = 10000 - nATypeProb - nBTypeProb
local nATypePkgUpProb = nATypeProb * gachaStorageConfig.ATypeUpProb / 10000
local nATypePkgProb = nATypeProb * (1 - gachaStorageConfig.ATypeUpProb / 10000)
local nBTypePkgUpProb = nBTypeProb * gachaStorageConfig.BTypeUpProb / 10000
local nBTypePkgGuaranteeProb = nBTypeProb * gachaStorageConfig.BTypeGuaranteeProb / 10000
local nBTypePkgProb = nBTypeProb * (1 - (gachaStorageConfig.BTypeUpProb + gachaStorageConfig.BTypeGuaranteeProb) / 10000)
local nCTypePkgProb = 10000 - nATypePkgUpProb - nATypePkgProb - nBTypePkgUpProb - nBTypePkgProb - nBTypePkgGuaranteeProb
local tbATypeItem = {}
local tbBTypeItem = {}
local tbCTypeItem = {}
local tbATypeUpItem = {}
local tbBTypeUpItem = {}
local tbBTypeGuaranteeItem = {}
local nATypeTotalWeight = 0
local nBTypeTotalWeight = 0
local nCTypeTotalWeight = 0
local nATypeUpTotalWeight = 0
local nBTypeUpTotalWeight = 0
local nBTypeGuaranteeWeight = 0
local func_ForEachGachaPkg = function(mapData)
if mapData.PkgId == gachaConfig.ATypePkg then
table.insert(tbATypeItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nATypeTotalWeight = nATypeTotalWeight + mapData.Weight
elseif mapData.PkgId == gachaConfig.BTypePkg then
table.insert(tbBTypeItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nBTypeTotalWeight = nBTypeTotalWeight + mapData.Weight
elseif mapData.PkgId == gachaConfig.BGuaranteePkg then
table.insert(tbBTypeGuaranteeItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nBTypeGuaranteeWeight = nBTypeGuaranteeWeight + mapData.Weight
elseif mapData.PkgId == gachaConfig.CTypePkg then
table.insert(tbCTypeItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nCTypeTotalWeight = nCTypeTotalWeight + mapData.Weight
elseif mapData.PkgId == gachaConfig.ATypeUpPkg then
table.insert(tbATypeUpItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nATypeUpTotalWeight = nATypeUpTotalWeight + mapData.Weight
elseif mapData.PkgId == gachaConfig.BTypeUpPkg then
table.insert(tbBTypeUpItem, {
nGoodsId = mapData.GoodsId,
nWeight = mapData.Weight
})
nBTypeUpTotalWeight = nBTypeUpTotalWeight + mapData.Weight
end
end
ForEachTableLine(DataTable.GachaPkg, func_ForEachGachaPkg)
for _, v in pairs(tbATypeItem) do
local nProb = v.nWeight / nATypeTotalWeight * nATypePkgProb / 10000 * 100
table.insert(tbItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
for _, v in pairs(tbBTypeItem) do
local nProb = v.nWeight / nBTypeTotalWeight * nBTypePkgProb / 10000 * 100
table.insert(tbItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
for _, v in pairs(tbBTypeGuaranteeItem) do
local nProb = v.nWeight / nBTypeGuaranteeWeight * nBTypePkgGuaranteeProb / 10000 * 100
table.insert(tbItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
for _, v in pairs(tbCTypeItem) do
local nProb = v.nWeight / nCTypeTotalWeight * nCTypePkgProb / 10000 * 100
table.insert(tbItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
for _, v in pairs(tbATypeUpItem) do
local nProb = v.nWeight / nATypeUpTotalWeight * nATypePkgUpProb / 10000 * 100
table.insert(tbUpItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
for _, v in pairs(tbBTypeUpItem) do
local nProb = v.nWeight / nBTypeUpTotalWeight * nBTypePkgUpProb / 10000 * 100
table.insert(tbUpItemList, {
nGoodsId = v.nGoodsId,
nProbValue = nProb
})
end
local sortItem = function(a, b)
local aItemConfig = ConfigTable.GetData_Item(a.nGoodsId)
local bItemConfig = ConfigTable.GetData_Item(b.nGoodsId)
if aItemConfig.Rarity < bItemConfig.Rarity then
return true
elseif aItemConfig.Rarity > bItemConfig.Rarity then
return false
elseif aItemConfig.Type == GameEnum.itemType.Char and bItemConfig.Type == GameEnum.itemType.Disc then
return true
elseif aItemConfig.Type == GameEnum.itemType.Disc and bItemConfig.Type == GameEnum.itemType.Char then
return false
else
return aItemConfig.Id < bItemConfig.Id
end
end
table.sort(tbUpItemList, sortItem)
table.sort(tbItemList, sortItem)
return tbUpItemList, tbItemList
end
function PlayerGachaData:SendGachaGuaranteeRewardReq(nId, callback)
local GachaCallback = function(_, mapData)
self:RecvGuaranteeReward(nId, true)
if type(callback) == "function" then
callback(mapData)
end
end
local mapMsgData = {Value = nId}
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_guarantee_reward_receive_req, mapMsgData, nil, GachaCallback)
end
function PlayerGachaData:OnEvent_NewDay()
self.hadData = false
end
function PlayerGachaData:CacheGachaNewbieData(mapData)
for _, v in ipairs(mapData) do
local newbie = {}
newbie.Id = v.Id
newbie.Receive = v.Receive
newbie.Times = v.Times
newbie.Cards = {}
for _, v1 in ipairs(v.Cards) do
local cards = {}
for _, v2 in ipairs(v1.Values) do
table.insert(cards, v2)
end
table.insert(newbie.Cards, cards)
end
newbie.Temp = {}
if v.Temp ~= nil then
for _, v2 in ipairs(v.Temp.Values) do
table.insert(newbie.Temp, v2)
end
end
self._mapNewbieData[v.Id] = newbie
end
printTable(self._mapNewbieData)
end
function PlayerGachaData:GetGachaNewbieData(nId)
if self._mapNewbieData[nId] == nil then
local newbie = {}
newbie.Id = nId
newbie.Receive = false
newbie.Times = 0
newbie.Cards = {}
newbie.Temp = {}
self._mapNewbieData[nId] = newbie
end
return self._mapNewbieData[nId]
end
function PlayerGachaData:GetGachaNewbieInfomation(callback)
local GetInfoCallback = function(_, mapData)
self.hadNewbieData = true
self:CacheGachaNewbieData(mapData.List)
if type(callback) == "function" then
callback()
end
end
if self.hadNewbieData then
if type(callback) == "function" then
callback()
end
else
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_newbie_info_req, {}, nil, GetInfoCallback)
end
end
function PlayerGachaData:SendGachaNewbieReq(nId, callback)
local GachaCallback = function(_, mapData)
local data = self._mapNewbieData[nId]
data.Times = data.Times + 1
data.Temp = {}
for _, v in ipairs(mapData.Cards) do
table.insert(data.Temp, v)
end
self._mapNewbieData[nId] = data
if type(callback) == "function" then
callback(mapData)
end
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("guaranteed5star_gacha10", tab)
end
local mapMsgData = {Value = nId}
EventManager.Hit("GachaProcessStart", true)
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_newbie_spin_req, mapMsgData, nil, GachaCallback)
end
function PlayerGachaData:SendGachaNewbieSaveReq(nId, idx, callback)
local GachaCallback = function(_, mapData)
local data = self._mapNewbieData[nId]
local cards = {}
for _, v in ipairs(data.Temp) do
table.insert(cards, v)
end
if idx == 0 then
table.insert(data.Cards, cards)
elseif 0 < idx then
data.Cards[idx] = cards
end
data.Temp = {}
self._mapNewbieData[nId] = data
if type(callback) == "function" then
callback(mapData)
end
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("guaranteed5star_gacha10", tab)
end
local mapMsgData = {Id = nId, Idx = idx}
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_newbie_save_req, mapMsgData, nil, GachaCallback)
end
function PlayerGachaData:SendGachaNewbieObtainReq(nId, idx, callback)
local GachaCallback = function(_, mapData)
local data = self._mapNewbieData[nId]
data.Receive = true
self._mapNewbieData[nId] = data
if type(callback) == "function" then
callback(mapData)
end
end
local mapMsgData = {Id = nId, Idx = idx}
HttpNetHandler.SendMsg(NetMsgId.Id.gacha_newbie_obtain_req, mapMsgData, nil, GachaCallback)
end
return PlayerGachaData
@@ -0,0 +1,292 @@
local PlayerGuideData = class("PlayerGuideData")
PanelId = require("GameCore.UI.PanelId")
function PlayerGuideData:Init()
self.isProcessing = false
self.openPanelId = 0
EventManager.Add("OnEvent_PanelOnEnableById", self, self.OnEvent_PanelOnEnableById)
EventManager.Add("Guide_CloseDisposablePanel", self, self.OnEvent_CloseDisposablePanel)
EventManager.Add("Event_MainViewPopUpEnd", self, self.Event_PopUpEndCheckMainView)
EventManager.Add("Guide_CloseWorldClassPopUp", self, self.OnEvent_UpdateWorldClass)
EventManager.Add("Guide_PassiveCheck_Msg", self, self.Event_PassiveCheckMsg)
self.runGroupId = 0
self.runStepId = 0
self._guideInitiativeTableData = {}
self._guidePassiveTableData = {}
self.tabGuideNewbie = {}
self:HandleTableMsg()
end
function PlayerGuideData:UnInit()
EventManager.Remove("OnEvent_PanelOnEnableById", self, self.OnEvent_PanelOnEnableById)
EventManager.Remove("Guide_CloseDisposablePanel", self, self.OnEvent_CloseDisposablePanel)
EventManager.Remove("Event_MainViewPopUpEnd", self, self.Event_PopUpEndCheckMainView)
EventManager.Remove("Guide_CloseWorldClassPopUp", self, self.OnEvent_UpdateWorldClass)
EventManager.Remove("Guide_PassiveCheck_Msg", self, self.Event_PassiveCheckMsg)
end
function PlayerGuideData:HandleTableMsg()
local foreach = function(guideData)
if guideData.GuideDetectionType == GameEnum.guideDetectionType.InitiativeCheck then
self._guideInitiativeTableData[guideData.Id] = guideData
else
self._guidePassiveTableData[guideData.Id] = guideData
end
end
if self._guideInitiativeTableData == nil then
self._guideInitiativeTableData = {}
end
if self._guidePassiveTableData == nil then
self._guidePassiveTableData = {}
end
ForEachTableLine(DataTable.GuideGroup, foreach)
end
function PlayerGuideData:SetGuideNewbie(newbie)
if newbie == nil then
return
end
for i, v in pairs(newbie) do
self.tabGuideNewbie[v.GroupId] = v.StepId
end
end
function PlayerGuideData:GetGuideNewbie(groupId)
if self.tabGuideNewbie[groupId] then
return self.tabGuideNewbie[groupId]
end
return 0
end
function PlayerGuideData:GetGuideState()
return self.isProcessing
end
function PlayerGuideData:CheckInGuideGroup(nId)
return self.isProcessing and self.runGroupId == nId
end
function PlayerGuideData:SetPlayerLearnReq(groupId, stepId)
self.tabGuideNewbie[groupId] = stepId
if stepId == -1 then
local callallback = function()
if stepId == -1 and not self.isProcessing and groupId ~= 1 then
self:CheckHaveGuideData()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_learn_req, {GroupId = groupId, StepId = stepId}, nil, callallback)
end
end
function PlayerGuideData:OnEvent_PanelOnEnableById(_panelId)
if EditorSettings and EditorSettings.bJumpGuide then
return
end
if _panelId == PanelId.MainView then
return
end
self.openPanelId = _panelId
if self.isProcessing then
return
end
self:CheckHaveGuideData()
end
function PlayerGuideData:OnEvent_CloseDisposablePanel(nPanelId)
if self.openPanelId == nPanelId then
self.openPanelId = PanelManager.GetCurPanelId()
end
end
function PlayerGuideData:Event_PopUpEndCheckMainView()
if EditorSettings and EditorSettings.bJumpGuide then
return
end
if self.isProcessing then
return
end
if PanelManager.GetCurPanelId() == PanelId.MainView then
if PlayerData.State:CheckState() then
return
end
self.openPanelId = PanelId.MainView
self:CheckHaveGuideData()
end
end
function PlayerGuideData:OnEvent_UpdateWorldClass()
if EditorSettings and EditorSettings.bJumpGuide then
return
end
if self.isProcessing then
return
end
self:CheckHaveGuideData()
end
function PlayerGuideData:CheckHaveGuideData()
for i, v in pairs(self._guideInitiativeTableData) do
if (self.tabGuideNewbie[v.Id] == nil or self.tabGuideNewbie[v.Id] ~= -1) and v.IsActive then
local bGuide = true
if v.GuidePrepose ~= nil and bGuide then
bGuide = self:CheckGuidePrePose(v.GuidePrepose, v.PreposeParams)
end
if v.GuidePrepose2 ~= nil and bGuide then
bGuide = self:CheckGuidePrePose(v.GuidePrepose2, v.PreposeParams2)
end
bGuide = bGuide and self:CheckGuidePost(v) and self:CheckGuidetrigger(v)
if bGuide then
self.runGroupId = v.Id
self.runStepId = self.tabGuideNewbie[v.Id] or 0
self:OpenGuidePanel()
break
end
end
end
end
function PlayerGuideData:CheckGuidePrePose(nPoseType, param)
if nPoseType == GameEnum.guideprepose.PreGuide then
local _prepose = decodeJson(param)
local _tmpGId = _prepose[1]
if self.tabGuideNewbie[_tmpGId] and self.tabGuideNewbie[_tmpGId] == -1 then
return true
end
elseif nPoseType == GameEnum.guideprepose.FinishDungeon then
local _prepose = decodeJson(param)
local nStar = PlayerData.Mainline:GetMianlineLevelStar(_prepose[1])
if type(nStar) == "number" then
return true
end
elseif nPoseType == GameEnum.guideprepose.WorldClass then
local _prepose = decodeJson(param)
local nWorldClass = PlayerData.Base:GetWorldClass()
if nWorldClass >= _prepose[1] then
return true
end
elseif nPoseType == GameEnum.guideprepose.UnlockFunction then
local _prepose = decodeJson(param)
local funId = _prepose[1]
if PlayerData.Base:CheckFunctionUnlock(funId, false) then
return true
end
elseif nPoseType == GameEnum.guideprepose.HoldItem then
local _prepose = decodeJson(param)
local _itemId = _prepose[1]
local _itemCount = _prepose[2]
local hasCount = PlayerData.Item:GetItemCountByID(_itemId)
if _itemCount <= hasCount then
return true
end
elseif nPoseType == GameEnum.guideprepose.FinishStarTowerQuest then
local _prepose = decodeJson(param)
local _taskId = _prepose[1]
local tbCore, tbNormal = PlayerData.Quest:GetStarTowerQuestData()
for i1, v1 in pairs(tbCore) do
if v1.nTid == _taskId and v1.nStatus > 0 then
return true
end
end
for i1, v1 in pairs(tbNormal) do
if v1.nTid == _taskId and v1.nStatus > 0 then
return true
end
end
elseif nPoseType == GameEnum.guideprepose.UnFinishCharacterPlot then
local _prepose = decodeJson(param)
local data = ConfigTable.GetData("Plot", _prepose[1])
local charid = data.Char
local isFinish = PlayerData.Char:IsCharPlotFinish(charid, _prepose[1])
if isFinish == false then
return true
end
else
return true
end
end
function PlayerGuideData:CheckGuidePost(data)
if data.GuidePost == GameEnum.guidepost.UnDoneGuide then
local _prepose = decodeJson(data.PostParams)
local _tmpGId = _prepose[1]
if self.tabGuideNewbie[_tmpGId] == nil or self.tabGuideNewbie[_tmpGId] ~= -1 then
return true
end
return false
else
return true
end
end
function PlayerGuideData:CheckGuidetrigger(data)
if data.TowerState then
local bState = PlayerData.State.mapStarTowerState and PlayerData.State.mapStarTowerState.Id ~= 0
if bState then
return false
end
end
if data.GuideTrigger == GameEnum.guidetrigger.PreGuide then
local _triggerParams = decodeJson(data.TriggerParams)
if self.tabGuideNewbie[_triggerParams[1]] and self.tabGuideNewbie[_triggerParams[1]] == -1 then
return true
end
elseif data.GuideTrigger == GameEnum.guidetrigger.WorldClass then
local _triggerParams = decodeJson(data.TriggerParams)
local nWorldClass = PlayerData.Base:GetWorldClass()
if nWorldClass >= _triggerParams[1] then
return true
end
elseif data.GuideTrigger == GameEnum.guidetrigger.OpenInterface then
local _triggerParams = decodeJson(data.TriggerParams)
if _triggerParams[1] == self.openPanelId then
return true
end
elseif data.GuideTrigger == GameEnum.guidetrigger.FinishLastStep then
return true
elseif data.GuideTrigger == GameEnum.guidetrigger.FinishDungeon then
local _triggerParams = decodeJson(data.TriggerParams)
local nStar = PlayerData.Mainline:GetMianlineLevelStar(_triggerParams[1])
if type(nStar) == "number" then
return true
end
elseif data.GuideTrigger == GameEnum.guidetrigger.UnlockFunction then
local _triggerParams = decodeJson(data.TriggerParams)
local funId = _triggerParams[1]
if PlayerData.Base:CheckFunctionUnlock(funId, false) then
return true
end
else
return true
end
end
function PlayerGuideData:OpenGuidePanel()
print("[新手引导]当前触发的引导组Id:" .. tostring(self.runGroupId))
self.isProcessing = true
EventManager.Hit("Event_ActiveGuidePanel")
end
function PlayerGuideData:FinishCurrentGroup(isCheck)
print("[新手引导]引导结束,引导组Id:" .. tostring(self.runGroupId))
self.isProcessing = false
if isCheck then
self:CheckHaveGuideData()
end
if PanelManager.GetCurPanelId() == PanelId.MainView then
end
end
function PlayerGuideData:Event_PassiveCheckMsg(msg)
if EditorSettings and EditorSettings.bJumpGuide then
return
end
if self.isProcessing then
return
end
for i, v in pairs(self._guidePassiveTableData) do
if (self.tabGuideNewbie[v.Id] == nil or self.tabGuideNewbie[v.Id] ~= -1) and v.IsActive and v.PassiveMsg == msg then
local bGuide = true
if v.GuidePrepose ~= nil and bGuide then
bGuide = self:CheckGuidePrePose(v.GuidePrepose, v.PreposeParams)
end
if v.GuidePrepose2 ~= nil and bGuide then
bGuide = self:CheckGuidePrePose(v.GuidePrepose2, v.PreposeParams2)
end
bGuide = bGuide and self:CheckGuidePost(v) and self:CheckGuidetrigger(v)
if bGuide then
self.runGroupId = v.Id
self.runStepId = self.tabGuideNewbie[v.Id] or 0
self:OpenGuidePanel()
break
end
end
end
end
function PlayerGuideData:CheckGuideFinishById(id)
if self.tabGuideNewbie[id] == nil or self.tabGuideNewbie[id] ~= -1 then
return false
end
return true
end
return PlayerGuideData
@@ -0,0 +1,167 @@
local PlayerHandbookData = class("PlayerHandbookData")
local GameResourceLoader = require("Game.Common.Resource.GameResourceLoader")
local femaleSurfix = "_FP"
local maleSurfix = "_MP"
local HandbookSkinData = require("GameCore.Data.DataClass.HandBookData.HandbookSkinData")
local HandbookDiscData = require("GameCore.Data.DataClass.HandBookData.HandbookDiscData")
local HandbookPlotData = require("GameCore.Data.DataClass.HandBookData.HandbookPlotData")
local HandbookStorySetData = require("GameCore.Data.DataClass.HandBookData.HandbookStorySetData")
function PlayerHandbookData:ParseBitMapData(bitMap)
local bitMapData = {}
for k, v in ipairs(bitMap) do
for i = 1, 64 do
bitMapData[(k - 1) * 64 + i] = v & 1 << i - 1 ~= 0 and 1 or 0
end
end
return bitMapData
end
function PlayerHandbookData:Init()
self.tbHandbookMsgData = {}
self.tbHandbookData = {}
self.tbHandbookCfgData = {}
self:InitHandbookTableData()
end
function PlayerHandbookData:InitHandbookTableData()
local func_ForEach = function(line)
local handbookData = self:CreateHandbook(line.Type, line.Id, 0)
self.tbHandbookData[line.Id] = handbookData
if nil == self.tbHandbookCfgData[line.Type] then
self.tbHandbookCfgData[line.Type] = {}
end
self.tbHandbookCfgData[line.Type][line.Index] = line.Id
end
ForEachTableLine(DataTable.Handbook, func_ForEach)
end
function PlayerHandbookData:CreateHandbook(type, id, unlock)
local handbookData
if type == GameEnum.handbookType.SKIN then
handbookData = HandbookSkinData.new(id, unlock)
elseif type == GameEnum.handbookType.OUTFIT then
handbookData = HandbookDiscData.new(id, unlock)
elseif type == GameEnum.handbookType.PLOT then
handbookData = HandbookPlotData.new(id, unlock)
elseif type == GameEnum.handbookType.StorySet then
handbookData = HandbookStorySetData.new(id, unlock)
end
return handbookData
end
function PlayerHandbookData:UpdateHandbook(msgData)
local tbLastData = self.tbHandbookMsgData[msgData.Type] or {}
local tbData = UTILS.ParseByteString(msgData.Data)
local nByteTableLength = #tbData
local n64Count = math.ceil(nByteTableLength / 8)
for j = 1, n64Count do
for i = 1, 64 do
local nIndex = (j - 1) * 64 + i
local lastResult = UTILS.IsBitSet(tbLastData, nIndex)
local curResult = UTILS.IsBitSet(tbData, nIndex)
if lastResult ~= curResult and nil ~= self.tbHandbookCfgData[msgData.Type] then
local id = self.tbHandbookCfgData[msgData.Type][nIndex]
if nil == self.tbHandbookData[id] then
local handbookData = self:CreateHandbook(msgData.Type, id, 1)
self.tbHandbookData[id] = handbookData
else
self.tbHandbookData[id]:UpdateUnlockState(1)
end
end
end
end
self.tbHandbookMsgData[msgData.Type] = tbData
end
function PlayerHandbookData:CacheHandbookData(mapMsgData)
for _, v in pairs(mapMsgData) do
self:UpdateHandbook(v)
end
self:UpdateSkinData()
end
function PlayerHandbookData:UpdateHandbookData(msgData)
self:UpdateHandbook(msgData)
self:UpdateSkinData()
end
function PlayerHandbookData:UpdateSkinData()
local tbSkinHandbook = self:GetUnlockHandbookByType(GameEnum.handbookType.SKIN)
local tbSkinCfgData = self.tbHandbookCfgData[GameEnum.handbookType.SKIN]
if nil ~= tbSkinCfgData then
for idx, id in pairs(tbSkinCfgData) do
local cfgData = ConfigTable.GetData("Handbook", id)
local nUnlock = nil ~= tbSkinHandbook[id] and 1 or 0
PlayerData.CharSkin:UpdateSkinData(cfgData.SkinId, id, nUnlock)
end
end
end
function PlayerHandbookData:GetUnlockHandbookByType(typeParam)
local tbType = {}
if type(typeParam) ~= "table" then
table.insert(tbType, typeParam)
else
tbType = typeParam
end
local tbDataList = {}
for _, v in pairs(self.tbHandbookData) do
for _, nType in ipairs(tbType) do
if v:GetType() == nType and v:CheckUnlock() then
tbDataList[v:GetId()] = v
end
end
end
return tbDataList
end
function PlayerHandbookData:GetHandbookDataById(id)
return self.tbHandbookData[id]
end
function PlayerHandbookData:GetAllHandbookData()
return self.tbHandbookData
end
function PlayerHandbookData:CheckHandbookUnlock(id)
local handbookData = self:GetHandbookDataById(id)
if nil == handbookData then
return false
end
return handbookData:CheckUnlock()
end
function PlayerHandbookData:GetTempHandbookDataById(id)
local cfgData = ConfigTable.GetData("Handbook", id)
if nil == cfgData then
printError("Get Handbook data fail!!! id = " .. id)
return self:GetTempHandbookDataById(410301)
end
local data = self:CreateHandbook(cfgData.Type, id, 1)
return data
end
function PlayerHandbookData:GetBoardCharList()
local tbCharList = {}
local tbUnlockSkinList = self:GetUnlockHandbookByType(GameEnum.handbookType.SKIN)
if nil ~= tbUnlockSkinList then
for id, data in pairs(tbUnlockSkinList) do
local charId = data:GetCharId()
if nil == tbCharList[charId] then
tbCharList[charId] = {}
end
table.insert(tbCharList[charId], data)
end
end
return tbCharList
end
function PlayerHandbookData:GetPlotResourcePath(nId)
local bSecDiff = false
local mapCfg = ConfigTable.GetData("MainScreenCG", nId)
if mapCfg ~= nil then
local sFemale = Settings.AB_ROOT_PATH .. mapCfg.FullScreenImg .. femaleSurfix .. ".png"
local sMale = Settings.AB_ROOT_PATH .. mapCfg.FullScreenImg .. maleSurfix .. ".png"
if GameResourceLoader.ExistsAsset(sFemale) or GameResourceLoader.ExistsAsset(sMale) then
bSecDiff = true
end
end
local sSurfix = ""
if bSecDiff then
local bIsMale = PlayerData.Base:GetPlayerSex()
sSurfix = bIsMale and maleSurfix or femaleSurfix
end
local tbResourcePath = {
FullScreenImg = mapCfg.FullScreenImg .. sSurfix,
ListImg = mapCfg.ListImg .. sSurfix,
Icon = mapCfg.Icon .. sSurfix
}
return tbResourcePath
end
return PlayerHandbookData
@@ -0,0 +1,79 @@
local PlayerHeadData = class("PlayerHeadData")
function PlayerHeadData:Init()
self.tbHeadList = {}
self:InitConfig()
end
function PlayerHeadData:UnInit()
end
function PlayerHeadData:InitConfig()
local foreachHead = function(mapData)
self.tbHeadList[mapData.Id] = {mapCfg = mapData, bUnlock = false}
end
ForEachTableLine(DataTable.PlayerHead, foreachHead)
end
function PlayerHeadData:DelHeadId(nId)
if self.tbHeadList[nId] ~= nil then
self.tbHeadList[nId].bUnlock = false
end
end
function PlayerHeadData:ChangePlayerHead(mapData)
if not mapData then
return
end
for _, v in pairs(mapData) do
if self.tbHeadList[v.Tid] ~= nil then
self.tbHeadList[v.Tid].bUnlock = true
end
RedDotManager.SetValid(RedDotDefine.Friend_Head_Item, v.Tid, true)
end
end
function PlayerHeadData:GetPlayerHeadList()
local tbHeadList = {}
local nCurId = PlayerData.Base:GetPlayerHeadId()
for nId, v in pairs(self.tbHeadList) do
local mapData = {}
if v.mapCfg.IsShow and (v.bUnlock or not v.bUnlock and v.mapCfg.IsLockShow) then
mapData.nId = nId
mapData.mapCfg = v.mapCfg
mapData.nUnlock = v.bUnlock and 1 or 0
if nId == nCurId then
mapData.nSort = 1
else
mapData.nSort = 0
end
table.insert(tbHeadList, mapData)
end
end
table.sort(tbHeadList, function(a, b)
if a.nSort == b.nSort then
if a.nUnlock == b.nUnlock then
return a.nId < b.nId
end
return a.nUnlock > b.nUnlock
end
return a.nSort > b.nSort
end)
return tbHeadList
end
function PlayerHeadData:SendGetHeadListMsg(callback)
local netCallback = function(_, netMsgData)
for nId, v in pairs(self.tbHeadList) do
v.bUnlock = table.indexof(netMsgData.List, nId) > 0
end
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_head_icon_info_req, {}, nil, netCallback)
end
function PlayerHeadData:SendPlayerHeadIconSetReq(nHeadIconId, callback)
local msgData = {HeadIcon = nHeadIconId}
local successCallback = function(_, mapMainData)
PlayerData.Base:ChangePlayerHeadId(nHeadIconId)
if callback then
callback(mapMainData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_head_icon_set_req, msgData, nil, successCallback)
end
return PlayerHeadData
@@ -0,0 +1,939 @@
local PlayerInfinityTowerData = class("PlayerInfinityTowerData")
local LocalData = require("GameCore.Data.LocalData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
function PlayerInfinityTowerData:Init()
self.selBuildId = {}
self.againOrNextLv = 0
self.itDifficultyData = {}
self:HandleITDifficultyData()
self:HandleMsgData()
self.InfinityTowerRewardsTab = {}
self.isGetITInfo = false
self.BountyLevel = 0
self.tabPlotsIds = {}
self.tabUnLockPlotsIds = {}
self.UnLockTower = {}
self.NextLevelId = 0
self.cacheCharTid = nil
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
self.isAutoNextLv = false
self.TwinNpcId = 173174
self.TabVoiceNpc = {}
end
function PlayerInfinityTowerData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerInfinityTowerData:OnEvent_NewDay()
self:UpdateBountyRewardState(self.BountyLevel)
end
function PlayerInfinityTowerData:HandleITDifficultyData()
local itLevelData = {}
local itTowrtDiffFloorCount = {}
local itTowrtDiffFirstFloor = {}
local itTowrtDiffEndFloor = {}
local foreach_Base = function(baseData)
if itLevelData[baseData.DifficultyId] == nil then
itLevelData[baseData.DifficultyId] = {}
end
if itTowrtDiffFloorCount[baseData.DifficultyId] == nil then
itTowrtDiffFloorCount[baseData.DifficultyId] = 0
itTowrtDiffFirstFloor[baseData.DifficultyId] = 9999
itTowrtDiffEndFloor[baseData.DifficultyId] = 0
end
if baseData.Floor < itTowrtDiffFirstFloor[baseData.DifficultyId] then
itTowrtDiffFirstFloor[baseData.DifficultyId] = baseData.Floor
end
if baseData.Floor > itTowrtDiffEndFloor[baseData.DifficultyId] then
itTowrtDiffEndFloor[baseData.DifficultyId] = baseData.Floor
end
itTowrtDiffFloorCount[baseData.DifficultyId] = itTowrtDiffFloorCount[baseData.DifficultyId] + 1
itLevelData[baseData.DifficultyId][baseData.Floor] = baseData
end
ForEachTableLine(DataTable.InfinityTowerLevel, foreach_Base)
local foreach_Base = function(baseData)
if self.itDifficultyData[baseData.TowerId] == nil then
self.itDifficultyData[baseData.TowerId] = {}
self.itDifficultyData[baseData.TowerId].LastLvId = 0
self.itDifficultyData[baseData.TowerId].ChallengeIds = {}
self.itDifficultyData[baseData.TowerId].Diff = {}
self.itDifficultyData[baseData.TowerId].totalLevleCount = 0
end
local tab = {
diff = baseData,
level = itLevelData[baseData.Id],
diffLevelCount = itTowrtDiffFloorCount[baseData.Id] or 0,
firstFloor = itTowrtDiffFirstFloor[baseData.Id] or 0,
endFloor = itTowrtDiffEndFloor[baseData.Id] or 0
}
self.itDifficultyData[baseData.TowerId].Diff[baseData.Sort] = tab
self.itDifficultyData[baseData.TowerId].totalLevleCount = self.itDifficultyData[baseData.TowerId].totalLevleCount + tab.diffLevelCount
end
ForEachTableLine(DataTable.InfinityTowerDifficulty, foreach_Base)
end
function PlayerInfinityTowerData:InfinityTowerRewardsStateNotify(mapMsgData)
local rewardLv = mapMsgData.Value
self:UpdateBountyRewardState(rewardLv)
end
function PlayerInfinityTowerData:UpdateBountyRewardState(lv)
local foreach_Base = function(baseData)
if baseData.Level == lv and baseData.RewardDropId ~= 0 then
self:UpdateInfinityDaily(true)
end
end
ForEachTableLine(DataTable.InfinityTowerBountyLevel, foreach_Base)
end
function PlayerInfinityTowerData:UpdateInfinityDaily(isHave)
self.isHaveDailyReward = isHave
local worldClass = PlayerData.Base:GetWorldClass()
local openClass = ConfigTable.GetData("OpenFunc", GameEnum.OpenFuncType.InfinityTower).NeedWorldClass
if worldClass >= openClass then
end
end
function PlayerInfinityTowerData:GetITInfoReq()
local msgCallback = function(_, mapMsgData)
self:CacheInfinityData(mapMsgData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.infinity_tower_info_req, {}, nil, msgCallback)
end
function PlayerInfinityTowerData:CacheInfinityData(mapMsgData)
self.BountyLevel = 0
for i, v in pairs(mapMsgData.PlotsIds) do
self.tabPlotsIds[v] = true
end
for i, v in pairs(mapMsgData.Infos) do
self.itDifficultyData[v.Id].LastLvId = v.LevelId
for i1, v1 in pairs(v.ChallengeIds) do
table.insert(self.itDifficultyData[v.Id].ChallengeIds, v1)
end
end
if not self.isGetITInfo then
EventManager.Hit("Get_InfinityTower_InfoReq")
end
self.isGetITInfo = true
self:HandPlotMsg()
end
function PlayerInfinityTowerData:EnterITApplyReq(nLevelId, nBuildId, isTip)
if self.nPrevBuildId ~= nBuildId then
self:ClearCharDamageData()
end
self.nPrevBuildId = nBuildId
if isTip then
local TipsTime = LocalData.GetPlayerLocalData("IntinityT_Tips_Time")
local _tipDay = 0
if TipsTime ~= nil then
_tipDay = tonumber(TipsTime)
end
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nYear = tonumber(os.date("!%Y", fixedTimeStamp))
local nMonth = tonumber(os.date("!%m", fixedTimeStamp))
local nDay = tonumber(os.date("!%d", fixedTimeStamp))
local nowD = nYear * 366 + nMonth * 31 + nDay
if nowD == _tipDay then
self:SendEnterITApplyReq(nLevelId, nBuildId, false)
else
local GetBuildCallback = function(mapBuildData)
local recLv = ConfigTable.GetData("InfinityTowerLevel", nLevelId).RecommendLv
local recRank = ConfigTable.GetData("InfinityTowerLevel", nLevelId).RecommendBuildRank
local charTid = mapBuildData.tbChar[1].nTid
local charData = PlayerData.Char:GetCharDataByTid(charTid)
if charData ~= nil then
if recLv <= charData.nLevel and recRank <= PlayerData.Build:CalBuildRank(mapBuildData.nScore).Id then
self:SendEnterITApplyReq(nLevelId, nBuildId, false)
else
local isSelectAgain = false
local confirmCallback = function()
if isSelectAgain then
local _curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local _fixedTimeStamp = _curTimeStamp - newDayTime * 3600
local _nYear = tonumber(os.date("!%Y", _fixedTimeStamp))
local _nMonth = tonumber(os.date("!%m", _fixedTimeStamp))
local _nDay = tonumber(os.date("!%d", _fixedTimeStamp))
local _nowD = _nYear * 366 + _nMonth * 31 + _nDay
LocalData.SetPlayerLocalData("IntinityT_Tips_Time", tostring(_nowD))
end
self:SendEnterITApplyReq(nLevelId, nBuildId, false)
end
local againCallback = function(isSelect)
isSelectAgain = isSelect
end
local msg = {
nType = AllEnum.MessageBox.Confirm,
sContent = ConfigTable.GetUIText("InfinityTower_Recommend_Tips"),
callbackConfirm = confirmCallback,
callbackAgain = againCallback,
bBlur = false
}
EventManager.Hit(EventId.OpenMessageBox, msg)
end
else
self:SendEnterITApplyReq(nLevelId, nBuildId, false)
end
end
PlayerData.Build:GetBuildDetailData(GetBuildCallback, nBuildId)
end
else
self:SendEnterITApplyReq(nLevelId, nBuildId, false)
end
end
function PlayerInfinityTowerData:SendEnterITApplyReq(nLevelId, nBuildId, isAgainNext)
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
self._Build_id = nBuildId
self._Level_id = nLevelId
local msg = {}
msg.LevelId = nLevelId
msg.BuildId = nBuildId
local msgCallback = function()
if isAgainNext then
EventManager.Hit("Infinity_Tower_AgainOrNext")
CS.AdventureModuleHelper.LevelStateChanged(false)
else
self:EnterInfinityTower(nLevelId, nBuildId, false)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.infinity_tower_apply_req, msg, nil, msgCallback)
end
function PlayerInfinityTowerData:EnterInfinityTowerAgainNext()
if self.againOrNextLv ~= 0 then
local lvData = ConfigTable.GetData("InfinityTowerLevel", self.againOrNextLv)
local _diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _towerId = diffData.TowerId
local build = self.selBuildId[_towerId] or 0
self:EnterInfinityTower(self.againOrNextLv, build, true)
end
end
function PlayerInfinityTowerData:RefreshCharDamageData(tbCharId)
self.tbCharDamage = {}
local tbCurrDamage = {}
for i = 1, #tbCharId do
local damage = CS.AdventureModuleHelper.GetCharacterDamage(tbCharId[i], true)
local actorInfo = {}
actorInfo.nCharId = tbCharId[i]
actorInfo.nDamage = damage
table.insert(self.tbCharDamage, actorInfo)
end
CS.AdventureModuleHelper.ClearCharacterDamageRecord(true)
end
function PlayerInfinityTowerData:ClearCharDamageData()
self.tbPrevDamage = nil
self.tbCharDamage = nil
end
function PlayerInfinityTowerData:ITSettleReq(val, time, tbCharId)
local msg = {}
msg.Value = val
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.InfinityTower, val == 1)
}
self:RefreshCharDamageData(tbCharId)
local msgCallback = function(_, mapMsgData)
local lvData = ConfigTable.GetData("InfinityTowerLevel", self.currentLevel)
local _diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _towerId = diffData.TowerId
self:SetSelectLvSortId(diffData.Sort)
if val == 1 then
local lastLvId = self.itDifficultyData[_towerId].LastLvId
if lastLvId ~= 0 then
local lastlvData = ConfigTable.GetData("InfinityTowerLevel", lastLvId)
local _lastdiff = lastlvData.DifficultyId
if _lastdiff == _diff then
if lastlvData.Floor < lvData.Floor then
if lvData.LevelType ~= GameEnum.InfinityTowerLevelType.Challenge then
self.itDifficultyData[_towerId].LastLvId = self.currentLevel
else
table.insert(self.itDifficultyData[_towerId].ChallengeIds, self.currentLevel)
end
end
elseif _diff > _lastdiff then
if lvData.LevelType ~= GameEnum.InfinityTowerLevelType.Challenge then
self.itDifficultyData[_towerId].LastLvId = self.currentLevel
else
table.insert(self.itDifficultyData[_towerId].ChallengeIds, self.currentLevel)
end
end
elseif lvData.LevelType ~= GameEnum.InfinityTowerLevelType.Challenge then
self.itDifficultyData[_towerId].LastLvId = self.currentLevel
else
table.insert(self.itDifficultyData[_towerId].ChallengeIds, self.currentLevel)
end
self.NextLevelId = mapMsgData.NextLevelId
self.LastBountyLevel = self.BountyLevel
self.BountyLevel = 0
local tabItem = {}
for k, v in pairs(mapMsgData.Show) do
table.insert(tabItem, {
Tid = v.Tid,
Qty = v.Qty,
rewardType = AllEnum.RewardType.First
})
end
local tmpPlotId = self:CheckLevelSetPlot()
EventManager.Hit("Infinity_Tower_SettleSuccess", true, time, tabItem, mapMsgData.Change, tmpPlotId, self.tbCharDamage)
self:SetBreakoutMsgData(self.currentLevel)
self.isLevelClear = true
elseif val == 2 then
EventManager.Hit("Infinity_Tower_SettleSuccess", false, time, nil, nil, nil, self.tbCharDamage)
self.isLevelClear = false
elseif val == 3 then
EventManager.Hit("Infinity_Tower_SettleSuccess", false, time, nil, nil, nil, self.tbCharDamage)
self.isLevelClear = false
end
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
local tmpAuto = self:GetAutoNextLv() and "1" or "2"
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {"is_auto", tmpAuto})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(time)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self._Build_id)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self._Level_id)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(val)
})
NovaAPI.UserEventUpload("infinity_tower_battle", tabUpLevel)
end
HttpNetHandler.SendMsg(NetMsgId.Id.infinity_tower_settle_req, msg, nil, msgCallback)
end
function PlayerInfinityTowerData:ITDailyRewardReq()
local msgCallback = function(_, mapMsgData)
local tabItem = {}
for k, v in pairs(mapMsgData.Show) do
table.insert(tabItem, {
Tid = v.Tid,
Qty = v.Qty
})
end
UTILS.OpenReceiveByDisplayItem(tabItem, mapMsgData.Change)
self:UpdateInfinityDaily(false)
EventManager.Hit("InfinityTower_DailyCallback")
end
HttpNetHandler.SendMsg(NetMsgId.Id.infinity_tower_daily_reward_receive_req, {}, nil, msgCallback)
end
function PlayerInfinityTowerData:ITPlotRewardReq(plotId)
local msg = {}
msg.Value = plotId
local msgCallback = function(_, mapMsgData)
local tabItem = {}
for k, v in pairs(mapMsgData.Show) do
table.insert(tabItem, {
Tid = v.Tid,
Qty = v.Qty,
rewardType = AllEnum.RewardType.First
})
end
UTILS.OpenReceiveByDisplayItem(tabItem, mapMsgData.Change)
self.tabPlotsIds[plotId] = true
local isHave = false
for i, v in pairs(self.tabUnLockPlotsIds) do
if self.tabPlotsIds[i] == nil then
isHave = true
break
end
end
RedDotManager.SetValid(RedDotDefine.Map_InfinityTowerPlot, nil, isHave)
EventManager.Hit("Refresh_Infinity_PlotList")
end
HttpNetHandler.SendMsg(NetMsgId.Id.infinity_tower_plot_reward_receive_req, msg, nil, msgCallback)
end
function PlayerInfinityTowerData:EnterInfinityTower(lvId, buildId, isContinue)
self.isContinue = isContinue
self.currentLevel = lvId
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
if lvData == nil then
printError("无尽塔floorData 为空,lvData id === " .. lvId)
return
end
local floorData = ConfigTable.GetData("InfinityTowerFloor", lvData.FloorId)
if floorData == nil then
printError("无尽塔floorData 为空,floor id === " .. lvData.FloorId)
return
end
if self.curLevel == nil then
local luaClass = require("Game.Adventure.InfinityTower.InfinityTowerLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
end
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
local _diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _towerId = diffData.TowerId
LocalData.SetPlayerLocalData("IntinityT_Select_Build_" .. _towerId, buildId)
self.selBuildId[_towerId] = buildId
if type(self.curLevel.BindEvent) == "function" and self.againOrNextLv == 0 then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, floorData.Id, buildId, self.againOrNextLv, isContinue)
end
self.againOrNextLv = 0
self.NextLevelId = 0
end
function PlayerInfinityTowerData:CacheBuildCharTid(tab)
self.cacheCharTid = tab
end
function PlayerInfinityTowerData:EnterInfinityTowerEditor(floorId, tbChar, tbDisc, tbNote)
self.currentLevel = 11001
local floorData = ConfigTable.GetData("InfinityTowerFloor", floorId)
if floorData == nil then
printError("无尽塔floorData 为空,floor id === " .. floorId)
return
end
local luaClass = require("Game.Editor.InfinityTower.InfinityTowerEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, floorId, tbChar, tbDisc, tbNote)
end
end
function PlayerInfinityTowerData:GetFloorAffixBuff(tbCharId, floorId)
local floorData = ConfigTable.GetData("InfinityTowerFloor", floorId)
local tabAffix = floorData.AffixId
local tabBuff = {}
if 0 < #tabAffix then
for i = 1, #tabAffix do
local itAffixData = ConfigTable.GetData("InfinityTowerAffix", tabAffix[i])
if itAffixData.TriggerCondition == 1 then
local param = decodeJson(itAffixData.TriggerParam)
local paramEET = param[1]
local paramCount = param[2] or 0
local tmpCount = 0
for i, v in pairs(tbCharId) do
local tmpCharacter = ConfigTable.GetData_Character(v)
if tmpCharacter and tmpCharacter.EET == paramEET then
tmpCount = tmpCount + 1
end
end
if paramCount <= tmpCount then
for i, v in pairs(itAffixData.AddCamp) do
table.insert(tabBuff, v)
end
end
elseif itAffixData.TriggerCondition == 2 then
elseif itAffixData.TriggerCondition == 0 then
for i, v in pairs(itAffixData.AddCamp) do
table.insert(tabBuff, v)
end
end
end
end
return tabBuff
end
function PlayerInfinityTowerData:LevelEnd()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
self.againOrNextLv = 0
self:ClearCharDamageData()
self.nPrevBuildId = nil
end
function PlayerInfinityTowerData:GetCurrentLv()
return self.currentLevel
end
function PlayerInfinityTowerData:CheckOpenDay(index)
local mapData = ConfigTable.GetData("InfinityTower", index)
if mapData == nil then
return false
end
if #mapData.OpenDay == 0 then
return false
end
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nWeek = tonumber(os.date("!%w", fixedTimeStamp))
return 0 < table.indexof(mapData.OpenDay, nWeek)
end
function PlayerInfinityTowerData:GetNextDaySec(index)
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local weekday_utc = tonumber(os.date("!%w", fixedTimeStamp))
local target_weekday = 0
local mapData = ConfigTable.GetData("InfinityTower", index)
for i, v in pairs(mapData.OpenDay) do
if v > weekday_utc then
target_weekday = v
break
end
end
local days_to_target = (target_weekday - weekday_utc + 7) % 7
local nHour = tonumber(os.date("!%H", fixedTimeStamp))
local nMin = tonumber(os.date("!%M", fixedTimeStamp))
local nSec = tonumber(os.date("!%S", fixedTimeStamp))
local totalSec = days_to_target * 86400 - (nHour * 3600 + nMin * 60 + nSec)
return totalSec
end
function PlayerInfinityTowerData:CheckTowerUnLock(towerId, PreTowerLevelId)
if self.UnLockTower[towerId] then
return true
end
if PreTowerLevelId == 0 then
self.UnLockTower[towerId] = true
return true
end
local lvData = ConfigTable.GetData("InfinityTowerLevel", PreTowerLevelId)
local _diff = lvData.DifficultyId
local _diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _towerId = _diffData.TowerId
local _lastLvId = self.itDifficultyData[_towerId].LastLvId
if _lastLvId == 0 then
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
local _lastDiff = lvLastData.DifficultyId
if _diff < _lastDiff then
self.UnLockTower[towerId] = true
return true
elseif _lastDiff == _diff then
if lvData.Floor <= lvLastData.Floor then
self.UnLockTower[towerId] = true
return true
else
return false
end
else
return false
end
end
function PlayerInfinityTowerData:CheckLockWorldClass(ChooseLevelId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", ChooseLevelId)
local _diff = lvData.DifficultyId
local _diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _unlockWorldClass = _diffData.UnlockWorldClass
local worldClass = PlayerData.Base:GetWorldClass()
if _unlockWorldClass <= worldClass then
return false
end
return true
end
function PlayerInfinityTowerData:GetTowerPassAll(towerId)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
if _lastLvId == 0 then
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
local lvLastFloor = lvLastData.Floor
local towerTotalLvCount = self.itDifficultyData[towerId].totalLevleCount
if lvLastFloor == towerTotalLvCount then
return true
end
return false
end
function PlayerInfinityTowerData:GetTowerDiffPassAll(towerId, diffSort)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
if _lastLvId == 0 then
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
local diffData = self:GetTowerDiffData(towerId, diffSort)
if lvLastData.Floor >= diffData.endFloor then
return true
end
return false
end
function PlayerInfinityTowerData:JudgeLevelPass(towerId, levelId)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
if _lastLvId == 0 then
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", levelId)
if lvData.Floor <= lvLastData.Floor then
return true
end
return false
end
function PlayerInfinityTowerData:JudgeLevelCanChallenge(towerId, levelId)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
local lvData = ConfigTable.GetData("InfinityTowerLevel", levelId)
if _lastLvId == 0 then
if lvData.Floor == 1 then
return true
end
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
if lvData.Floor == lvLastData.Floor + 1 then
return true
end
return false
end
function PlayerInfinityTowerData:JudgeLevelLock(towerId, levelId)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
local lvData = ConfigTable.GetData("InfinityTowerLevel", levelId)
if _lastLvId == 0 then
if lvData.Floor > 1 then
return true
end
return false
end
local lvLastData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
if lvData.Floor >= lvLastData.Floor + 2 then
return true
end
return false
end
function PlayerInfinityTowerData:JudgeInfinityTowerCond(Cond, CondParam)
if Cond == GameEnum.InfinityTowerCond.LevelClearWithSpecificId then
local lvId = CondParam[1]
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
local diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", diff)
local towerId = diffData.TowerId
local towerLastLvId = self.itDifficultyData[towerId].LastLvId
if towerLastLvId == 0 then
return false
end
local lvDataLastLv = ConfigTable.GetData("InfinityTowerLevel", towerLastLvId)
if lvData.Floor <= lvDataLastLv.Floor then
return true
end
return false
elseif Cond == GameEnum.InfinityTowerCond.InfinityTowerWithSpecificLevelTotal then
local CondPassCount = CondParam[1]
local totalPassCount = 0
for i, v in pairs(self.itDifficultyData) do
if v.LastLvId ~= 0 then
local lastLv = v.LastLvId
local lvData = ConfigTable.GetData("InfinityTowerLevel", lastLv)
totalPassCount = totalPassCount + lvData.Floor
end
end
if CondPassCount <= totalPassCount then
return true
end
return false
elseif Cond == GameEnum.InfinityTowerCond.AnyTowerWithSpecificTotalLevel then
local CondCount = CondParam[1]
local CondFloor = CondParam[2]
local count = 0
for i, v in pairs(self.itDifficultyData) do
if v.LastLvId ~= 0 then
local lastLv = v.LastLvId
local lvData = ConfigTable.GetData("InfinityTowerLevel", lastLv)
if CondFloor <= lvData.Floor then
count = count + 1
end
end
end
if CondCount <= count then
return true
end
return false
elseif Cond == GameEnum.InfinityTowerCond.BountyLevelSpecific then
if self.BountyLevel >= CondParam[1] then
return true
end
return false
end
return true
end
function PlayerInfinityTowerData:JudgeInfinityTowerBuildCanUse(tbCharTid, levelId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", levelId)
local Cond = lvData.EntryCond
local CondParam = lvData.EntryCondParam
if Cond == GameEnum.InfinityTowerCond.MasterCharactersWithSpecificElementType then
local charId = tbCharTid[1]
local charData = ConfigTable.GetData_Character(charId)
if charData.EET == CondParam[1] then
return true
end
return false
elseif Cond == GameEnum.InfinityTowerCond.ElementTypeWithSpecificQuantityNoLessThanQuantity then
local count = 0
for i, v in pairs(tbCharTid) do
local charId = v
local charData = ConfigTable.GetData_Character(charId)
if charData.EET == CondParam[1] then
count = count + 1
end
end
return count >= CondParam[2]
elseif Cond == GameEnum.InfinityTowerCond.ElementTypeWithSpecificQuantityNoMoreThanQuantity then
local count = 0
for i, v in pairs(tbCharTid) do
local charId = v
local charData = ConfigTable.GetData_Character(charId)
if charData.EET == CondParam[1] then
count = count + 1
end
end
return count <= CondParam[2]
end
return true
end
function PlayerInfinityTowerData:GetTowerDiffCount(towerId)
return #self.itDifficultyData[towerId].Diff
end
function PlayerInfinityTowerData:GetTowerDiffData(towerId, sortId)
return self.itDifficultyData[towerId].Diff[sortId]
end
function PlayerInfinityTowerData:GetTowerPassFloor(towerId)
local _lastLvId = self.itDifficultyData[towerId].LastLvId
if _lastLvId == 0 then
return 0
end
local lvData = ConfigTable.GetData("InfinityTowerLevel", _lastLvId)
if lvData then
return lvData.Floor
end
return 0
end
function PlayerInfinityTowerData:GetTowerPassLv(towerId)
return self.itDifficultyData[towerId].LastLvId
end
function PlayerInfinityTowerData:GetTowerLayerData(towerId, floor)
return nil
end
function PlayerInfinityTowerData:GetCachedBuildId(lvId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
local diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", diff)
local towerId = diffData.TowerId
return self.selBuildId[towerId] or 0
end
function PlayerInfinityTowerData:GetSaveBuildId(lvId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
local diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", diff)
local towerId = diffData.TowerId
local tmpBuild = LocalData.GetPlayerLocalData("IntinityT_Select_Build_" .. towerId)
if tmpBuild ~= nil then
return tonumber(tmpBuild)
end
return 0
end
function PlayerInfinityTowerData:SetSelBuildId(nBuildId, lvId)
local lvData = ConfigTable.GetData("InfinityTowerLevel", lvId)
local diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", diff)
local towerId = diffData.TowerId
self.selBuildId[towerId] = nBuildId
end
function PlayerInfinityTowerData:GetInitInfoState()
return self.isGetITInfo
end
function PlayerInfinityTowerData:AnginOrNextLv(isAgain)
self.againOrNextLv = 0
if isAgain then
self.againOrNextLv = self.currentLevel
return true, self.againOrNextLv
elseif self.NextLevelId ~= 0 then
self.againOrNextLv = self.NextLevelId
return true, self.NextLevelId
else
return false, 0
end
end
function PlayerInfinityTowerData:GoAnginOrNextLv()
if self.againOrNextLv ~= 0 then
local lvData = ConfigTable.GetData("InfinityTowerLevel", self.againOrNextLv)
local _diff = lvData.DifficultyId
local diffData = ConfigTable.GetData("InfinityTowerDifficulty", _diff)
local _towerId = diffData.TowerId
local build = self.selBuildId[_towerId] or 0
self:SendEnterITApplyReq(self.againOrNextLv, build, true)
end
end
function PlayerInfinityTowerData:HandleMsgData()
self.bottomList_Daily = {}
self.bottomList_Breakout = {}
self.bottomList_News = {}
local foreach_Base = function(baseData)
if baseData.Type == GameEnum.InfinityTowerMsgType.Daily then
for i, v in pairs(baseData.DayOfWeek) do
if self.bottomList_Daily[v] == nil then
self.bottomList_Daily[v] = {}
end
table.insert(self.bottomList_Daily[v], baseData.Id)
end
elseif baseData.Type == GameEnum.InfinityTowerMsgType.Breakout then
if baseData.Condition == GameEnum.InfinityTowerMsgConditions.SpecialLv then
local tmpJ = decodeJson(baseData.Params)
for _, lvId in pairs(tmpJ) do
self.bottomList_Breakout[lvId] = baseData.Id
end
end
elseif baseData.Type == GameEnum.InfinityTowerMsgType.News then
table.insert(self.bottomList_News, baseData.Id)
end
end
ForEachTableLine(DataTable.InfinityTowerMsg, foreach_Base)
end
function PlayerInfinityTowerData:SetBreakoutMsgData(lvId)
if self.bottomList_Breakout[lvId] ~= nil then
LocalData.SetPlayerLocalData("IntinityT_Breakout_Id", tostring(lvId))
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
LocalData.SetPlayerLocalData("IntinityT_Breakout_Time", tostring(fixedTimeStamp))
end
end
function PlayerInfinityTowerData:RandomBottomMsg()
self.randomBotMsg = {}
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nWeek = tonumber(os.date("!%w", fixedTimeStamp))
local tmpDayList = self.bottomList_Daily[nWeek]
local nDayId = tmpDayList[math.random(1, #tmpDayList)]
if nDayId ~= 0 then
self.randomBotMsg[GameEnum.InfinityTowerMsgType.Daily] = nDayId
end
local tmpBreakoutId = LocalData.GetPlayerLocalData("IntinityT_Breakout_Id")
if tmpBreakoutId ~= nil then
local saveTime = LocalData.GetPlayerLocalData("IntinityT_Breakout_Time")
if saveTime ~= nil then
local nSaveWeek = tonumber(os.date("!%w", tonumber(saveTime)))
if nWeek == nSaveWeek then
self.randomBotMsg[GameEnum.InfinityTowerMsgType.Breakout] = self.bottomList_Breakout[tonumber(tmpBreakoutId)]
else
LocalData.DelPlayerLocalData("IntinityT_Breakout_Id")
LocalData.DelPlayerLocalData("IntinityT_Breakout_Time")
end
end
end
self.randomBotMsg[GameEnum.InfinityTowerMsgType.News] = {}
local tmpNews = {}
for i, v in pairs(self.bottomList_News) do
table.insert(tmpNews, v)
end
local tabLength = #tmpNews
for i = 1, tabLength do
local index = math.random(1, #tmpNews)
local nNewsId = tmpNews[index]
local _data = ConfigTable.GetData("InfinityTowerMsg", nNewsId)
if 0 < table.indexof(_data.DayOfWeek, nWeek) then
table.insert(self.randomBotMsg[GameEnum.InfinityTowerMsgType.News], nNewsId)
if #self.randomBotMsg[GameEnum.InfinityTowerMsgType.News] == 3 then
break
end
end
table.remove(tmpNews, index)
end
end
function PlayerInfinityTowerData:GetBottomMsgId(type, index)
if type == GameEnum.InfinityTowerMsgType.News then
return self.randomBotMsg[GameEnum.InfinityTowerMsgType.News][index]
else
return self.randomBotMsg[type]
end
end
function PlayerInfinityTowerData:HandPlotMsg()
local foreach_Base = function(baseData)
if self.tabPlotsIds[baseData.Id] then
self.tabUnLockPlotsIds[baseData.Id] = true
else
local isUnlock = self:JudgeInfinityTowerCond(baseData.UnlockCond, baseData.CondParam)
if isUnlock then
RedDotManager.SetValid(RedDotDefine.Map_InfinityTowerPlot, nil, true)
self.tabUnLockPlotsIds[baseData.Id] = true
end
end
end
ForEachTableLine(DataTable.InfinityTowerPlot, foreach_Base)
end
function PlayerInfinityTowerData:GetPlotUnLock(plotId)
if self.tabUnLockPlotsIds[plotId] then
return true
end
return false
end
function PlayerInfinityTowerData:GetPlotGetReward(plotId)
if self.tabPlotsIds[plotId] then
return true
end
return false
end
function PlayerInfinityTowerData:CheckLevelSetPlot()
local tmpPlotId = 0
local foreach_Base = function(baseData)
if not self.tabUnLockPlotsIds[baseData.Id] then
local isUnlock = self:JudgeInfinityTowerCond(baseData.UnlockCond, baseData.CondParam)
if isUnlock then
tmpPlotId = baseData.Id
RedDotManager.SetValid(RedDotDefine.Map_InfinityTowerPlot, nil, true)
self.tabUnLockPlotsIds[baseData.Id] = true
end
end
end
ForEachTableLine(DataTable.InfinityTowerPlot, foreach_Base)
return tmpPlotId
end
function PlayerInfinityTowerData:PlayPlot(plotId)
local plotData = ConfigTable.GetData("InfinityTowerPlot", plotId)
local sAvgId = plotData.avgId
local function avgEndCallback()
EventManager.Remove("StoryDialog_DialogEnd", self, avgEndCallback)
if self.tabPlotsIds[plotId] == nil then
self:ITPlotRewardReq(plotId)
end
end
EventManager.Add("StoryDialog_DialogEnd", self, avgEndCallback)
EventManager.Hit("StoryDialog_DialogStart", sAvgId)
end
function PlayerInfinityTowerData:SetPageState(index)
self.PageState = index
if index == 1 then
self.isLevelClear = false
end
end
function PlayerInfinityTowerData:GetPageState()
return self.PageState or 1
end
function PlayerInfinityTowerData:SetAutoNextLv(isAuto)
self.isAutoNextLv = isAuto
end
function PlayerInfinityTowerData:GetAutoNextLv()
return self.isAutoNextLv
end
function PlayerInfinityTowerData:SetSelectLvSortId(sortId)
self.selectDiffSort = sortId
end
function PlayerInfinityTowerData:GetSelectLvSortId()
return self.selectDiffSort or 1
end
function PlayerInfinityTowerData:OnEvent_PlayTwinEffect()
if not self.isContinue then
PlayerData.Voice:PlayCharVoice("twin_effect", self.TwinNpcId, nil, true)
end
end
function PlayerInfinityTowerData:GetNPCVoiceKey(NpcId)
local isFirst = true
if self.TabVoiceNpc[NpcId] then
isFirst = false
else
self.TabVoiceNpc[NpcId] = true
end
local timeNow = CS.ClientManager.Instance.serverTimeStamp
local nHour = tonumber(os.date("%H", timeNow))
if 6 <= nHour and nHour < 12 then
return isFirst, "greetmorn_npc"
elseif 12 <= nHour and nHour < 18 then
return isFirst, "greetnoon_npc"
else
return isFirst, "greetnight_npc"
end
end
return PlayerInfinityTowerData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,940 @@
local PlayerJointDrillData = class("PlayerJointDrillData")
local ConfigData = require("GameCore.Data.ConfigData")
local TimerManager = require("GameCore.Timer.TimerManager")
local LocalData = require("GameCore.Data.LocalData")
local ClientManager = CS.ClientManager.Instance
local ListInt = CS.System.Collections.Generic.List(CS.System.Int32)
function PlayerJointDrillData:Init()
self.nActId = 0
self.actTimer = nil
self.nActStatus = 0
self.tbPassedLevels = {}
self.bInBattle = false
self.curLevel = nil
self.nCurLevelId = 0
self.nCurLevel = 1
self.nStartTime = 0
self.nGameTime = 0
self._EntryTime = 0
self._EndTime = 0
self.mapBossInfo = {}
self.record = nil
self.bSimulate = false
self.tbTeams = {}
self.nSelectBuildId = 0
self.nChallengeCount = 0
self.tbRecordFloors = {}
self.tbQuests = {}
self.nTotalScore = 0
self.nLastRefreshRankTime = 0
self.nRankingRefreshTime = 600
self.mapSelfRankData = nil
self.mapRankList = nil
self.nTotalRank = 0
self:InitConfig()
end
function PlayerJointDrillData:UnInit()
end
function PlayerJointDrillData:InitConfig()
self.nMaxChallengeTime = ConfigTable.GetConfigNumber("JointDrill_Challenge_Time_Max")
self.nOverFlowChallengeTime = ConfigTable.GetConfigNumber("JointDrill_Challenge_Time_OverFlow")
local funcForeachMonsterValueTemplete = function(line)
CacheTable.SetField("_MonsterValueTemplete", line.TemplateId, line.Lv, line)
end
ForEachTableLine(ConfigTable.Get("MonsterValueTemplete"), funcForeachMonsterValueTemplete)
local funcForeachJointDrillLevel = function(line)
CacheTable.SetField("_JointDrillLevel", line.DrillLevelGroupId, line.Difficulty, line)
end
ForEachTableLine(ConfigTable.Get("JointDrillLevel"), funcForeachJointDrillLevel)
local funcForeachJointDrillLevel = function(line)
CacheTable.SetField("_JointDrillFloor", line.FloorId, line.BattleLvs, line)
end
ForEachTableLine(ConfigTable.Get("JointDrillFloor"), funcForeachJointDrillLevel)
local funcForeachJointDrillQuest = function(line)
if nil == CacheTable.GetData("_JointDrillQuest", line.GroupId) then
CacheTable.SetData("_JointDrillQuest", line.GroupId, {})
end
CacheTable.InsertData("_JointDrillQuest", line.GroupId, line)
end
ForEachTableLine(ConfigTable.Get("JointDrillQuest"), funcForeachJointDrillQuest)
self.nRankCount = 0
local funcForeachJointDrillRank = function(line)
self.nRankCount = self.nRankCount + 1
end
ForEachTableLine(ConfigTable.Get("JointDrillRank"), funcForeachJointDrillRank)
end
local EncodeTempDataJson = function(mapData)
local stTempData = CS.JointDrillTempData(1)
if mapData.mapCharacterTempData ~= nil and next(mapData.mapCharacterTempData) ~= nil then
local mapCharacterTempData = mapData.mapCharacterTempData
local stCharacter = {}
local tbHp = mapCharacterTempData.hpInfo
for nCharId, mapEffect in pairs(mapCharacterTempData.effectInfo) do
if stCharacter[nCharId] == nil then
stCharacter[nCharId] = CS.JointDrillCharacter(nCharId, tbHp[nCharId])
end
for nEtfId, mapEft in pairs(mapEffect.mapEffect) do
stCharacter[nCharId].tbEffect:Add(CS.StarTowerEffect(nEtfId, mapEft.nCount, mapEft.nCd))
end
end
for nCharId, mapBuff in pairs(mapCharacterTempData.buffInfo) do
if stCharacter[nCharId] == nil then
stCharacter[nCharId] = CS.JointDrillCharacter(nCharId, tbHp[nCharId])
end
for _, buffInfo in ipairs(mapBuff) do
stCharacter[nCharId].tbBuff:Add(CS.StarTowerBuffInfo(buffInfo.Id, buffInfo.CD, buffInfo.nNum))
end
end
for nCharId, mapStatus in pairs(mapCharacterTempData.stateInfo) do
if stCharacter[nCharId] == nil then
stCharacter[nCharId] = CS.JointDrillCharacter(nCharId, tbHp[nCharId])
end
stCharacter[nCharId].stateInfo = CS.StarTowerState(mapStatus.nState, mapStatus.nStateTime)
end
for nCharId, mapAmmoInfo in pairs(mapCharacterTempData.ammoInfo) do
if stCharacter[nCharId] == nil then
stCharacter[nCharId] = CS.JointDrillCharacter(nCharId, tbHp[nCharId])
end
stCharacter[nCharId].ammoInfo = CS.StarTowerAmmoInfo(mapAmmoInfo.nCurAmmo, mapAmmoInfo.nAmmo1, mapAmmoInfo.nAmmo2, mapAmmoInfo.nAmmo3, mapAmmoInfo.nAmmoMax1, mapAmmoInfo.nAmmoMax2, mapAmmoInfo.nAmmoMax3)
end
for _, skill in ipairs(mapCharacterTempData.skillInfo) do
stTempData.skillInfo:Add(CS.StarTowerSkill(skill.nCharId, skill.nSkillId, skill.nCd, skill.nSectionAmount, skill.nSectionResumeTime, skill.nUseTimeHint, skill.nEnergy))
end
stTempData.summonMonsterInfo = mapCharacterTempData.sommonInfo
for _, st in pairs(stCharacter) do
stTempData.characterInfo:Add(st)
end
end
local mapBossTempData = mapData.mapBossTempData
stTempData.bossInfo = mapBossTempData
local jsonData, length = NovaAPI.ParseJointDrillDataCompressed(stTempData)
return jsonData, length
end
local DecodeTempDataJson = function(sData)
local tempData = {}
tempData.mapCharacterTempData = {}
tempData.mapBossTempData = {}
tempData.mapCharacterTempData.skillInfo = {}
local stData = NovaAPI.DecodeJointDrillDataCompressed(sData)
local nCount = stData.skillInfo.Count
for index = 0, nCount - 1 do
local stSkill = stData.skillInfo[index]
table.insert(tempData.mapCharacterTempData.skillInfo, {
nCharId = stSkill.nCharId,
nSkillId = stSkill.nSkillId,
nCd = stSkill.nCd,
nSectionAmount = stSkill.nSectionAmount,
nSectionResumeTime = stSkill.nSectionResumeTime,
nUseTimeHint = stSkill.nUseTimeHint,
nEnergy = stSkill.nEnergy
})
end
local nCharCount = stData.characterInfo.Count
for index = 0, nCharCount - 1 do
local stChar = stData.characterInfo[index]
local nCharId = stChar.nCharId
local nHp = stChar.nHp
if tempData.mapCharacterTempData.hpInfo == nil then
tempData.mapCharacterTempData.hpInfo = {}
end
tempData.mapCharacterTempData.hpInfo[nCharId] = nHp
local nEffectCount = stChar.tbEffect.Count
if tempData.mapCharacterTempData.effectInfo == nil then
tempData.mapCharacterTempData.effectInfo = {}
end
if tempData.mapCharacterTempData.effectInfo[nCharId] == nil then
tempData.mapCharacterTempData.effectInfo[nCharId] = {
mapEffect = {}
}
end
for e = 0, nEffectCount - 1 do
local stEffect = stChar.tbEffect[e]
tempData.mapCharacterTempData.effectInfo[nCharId].mapEffect[stEffect.nId] = {
nCount = stEffect.nCount,
nCd = stEffect.nCd
}
end
local nBuffCount = stChar.tbBuff.Count
if tempData.mapCharacterTempData.buffInfo == nil then
tempData.mapCharacterTempData.buffInfo = {}
end
if tempData.mapCharacterTempData.buffInfo[nCharId] == nil then
tempData.mapCharacterTempData.buffInfo[nCharId] = {}
end
for b = 0, nBuffCount - 1 do
local stBuff = stChar.tbBuff[b]
table.insert(tempData.mapCharacterTempData.buffInfo[nCharId], {
Id = stBuff.Id,
CD = stBuff.CD,
nNum = stBuff.nNum
})
end
if stChar.stateInfo ~= nil then
if tempData.mapCharacterTempData.stateInfo == nil then
tempData.mapCharacterTempData.stateInfo = {}
end
tempData.mapCharacterTempData.stateInfo[nCharId] = {
jsonStr = "",
nState = stChar.stateInfo.nState,
nStateTime = stChar.stateInfo.nStateTime
}
end
if stChar.ammoInfo ~= nil then
if tempData.mapCharacterTempData.ammoInfo == nil then
tempData.mapCharacterTempData.ammoInfo = {}
end
tempData.mapCharacterTempData.ammoInfo[nCharId] = {
nCurAmmo = stChar.ammoInfo.nCurAmmo,
nAmmo1 = stChar.ammoInfo.nAmmo1,
nAmmo2 = stChar.ammoInfo.nAmmo2,
nAmmo3 = stChar.ammoInfo.nAmmo3,
nAmmoMax1 = stChar.ammoInfo.nAmmoMax1,
nAmmoMax2 = stChar.ammoInfo.nAmmoMax2,
nAmmoMax3 = stChar.ammoInfo.nAmmoMax3
}
end
end
if stData.summonMonsterInfo ~= nil and tempData.mapCharacterTempData.sommonInfo == nil then
tempData.mapCharacterTempData.sommonInfo = stData.summonMonsterInfo
end
tempData.mapBossTempData = stData.bossInfo
return tempData
end
function PlayerJointDrillData:EncodeTempDataJson(mapData)
return EncodeTempDataJson(mapData)
end
function PlayerJointDrillData:DecodeTempDataJson()
if self.record ~= nil then
return DecodeTempDataJson(self.record)
end
end
function PlayerJointDrillData:CacheJointDrillData(nActId, msgData)
self.nActId = nActId
self.tbPassedLevels = msgData.PassedLevels
if msgData.Meta ~= nil then
self.bInBattle = msgData.Meta.LevelId ~= 0
self.nCurLevelId = msgData.Meta.LevelId
self.nCurLevel = msgData.Meta.Floor
self.mapBossInfo.nHp = msgData.Meta.BossHP
self.mapBossInfo.nHpMax = msgData.Meta.BossHPMax
self.nStartTime = msgData.Meta.StartTime
self.record = msgData.Meta.Record
self.tbTeams = msgData.Meta.Teams
self.bSimulate = msgData.Meta.Simulate
self._EntryTime = msgData.Meta.StartTime
if self.bInBattle then
self:StartChallengeTime()
else
self:ChallengeEnd()
end
self.nTotalScore = msgData.Meta.TotalScore
end
if msgData.Quests ~= nil then
self.tbQuests = msgData.Quests
end
self:RefreshJointDrillQuestRedDot()
self:StartActTimer()
end
function PlayerJointDrillData:CheckPassedId(nLevelId)
if self.tbPassedLevels ~= nil then
for _, v in ipairs(self.tbPassedLevels) do
if v.LevelId == nLevelId then
return true
end
end
end
return false
end
function PlayerJointDrillData:IsJointDrillUnlock(nLevelId)
local mapLevelCfg = ConfigTable.GetData("JointDrillLevel", nLevelId)
if mapLevelCfg == nil then
return false
end
local nPreLevelId = mapLevelCfg.PreLevelId
if nPreLevelId == 0 then
return true
end
return self:CheckPassedId(nPreLevelId)
end
function PlayerJointDrillData:GetMonsterMaxHp(nMonsterId, nDifficulty)
local nMaxHp = 0
local mapMonsterCfg = ConfigTable.GetData("Monster", nMonsterId)
if mapMonsterCfg == nil then
return 0
end
local mapAdjustCfg = ConfigTable.GetData("MonsterValueTempleteAdjust", mapMonsterCfg.Templete)
if mapAdjustCfg == nil then
return 0
end
local mapCfgList = CacheTable.GetData("_MonsterValueTemplete", mapAdjustCfg.TemplateId)
if mapCfgList == nil then
return 0
end
local mapCfg = mapCfgList[nDifficulty]
if mapCfg == nil then
return 0
end
local nValue = mapCfg.Hp
local nRatio = mapAdjustCfg.HpRatio
local nFix = mapAdjustCfg.HpFix
nMaxHp = math.floor(nValue * (1 + nRatio * ConfigData.IntFloatPrecision) + nFix)
return nMaxHp
end
function PlayerJointDrillData:GetMonsterName(nMonsterId)
local mapMonsterCfg = ConfigTable.GetData("Monster", nMonsterId)
if mapMonsterCfg ~= nil then
local nSkinId = mapMonsterCfg.FAId
local mapSkinCfg = ConfigTable.GetData("MonsterSkin", nSkinId)
if mapSkinCfg ~= nil then
local nManualId = mapSkinCfg.MonsterManual
local mapManualCfg = ConfigTable.GetData("MonsterManual", nManualId)
if mapManualCfg ~= nil then
return mapManualCfg.Name
end
end
end
return ""
end
function PlayerJointDrillData:StartChallengeTime()
if self.challengeTimer ~= nil then
self.challengeTimer:Cancel()
self.challengeTimer = nil
end
local nOpenTime = self.nStartTime
local refreshTime = function()
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local nTime = self.nMaxChallengeTime - (nCurTime - nOpenTime)
if 0 <= nTime then
EventManager.Hit("RefreshChallengeTime", nTime)
end
return nTime
end
local nTime = refreshTime()
if 0 < nTime then
self.challengeTimer = TimerManager.Add(0, 1, nil, function()
local nTime = refreshTime()
if nTime <= 0 then
self.challengeTimer:Cancel()
self.challengeTimer = nil
if self.curLevel ~= nil then
self.curLevel:JointDrillTimeOut()
end
end
end, true, true, true)
end
end
function PlayerJointDrillData:StartActTimer()
if self.actTimer ~= nil then
self.actTimer:Cancel()
self.actTimer = nil
end
local actData = PlayerData.Activity:GetActivityDataById(self.nActId)
if actData ~= nil then
local nChallengeStartTime = actData:GetChallengeStartTime()
local nChallengeEndTime = actData:GetChallengeEndTime()
local nActEndTime = actData:GetActCloseTime()
self.nActStatus = 0
local refreshTime = function()
local nRemainTime = 0
local nCurTime = ClientManager.serverTimeStamp
if nCurTime < nChallengeStartTime then
self.nActStatus = AllEnum.JointDrillActStatus.WaitStart
nRemainTime = nChallengeStartTime - nCurTime
elseif nCurTime <= nChallengeEndTime then
self.nActStatus = AllEnum.JointDrillActStatus.Start
nRemainTime = nChallengeEndTime - nCurTime
elseif nCurTime > nChallengeEndTime and nCurTime < nActEndTime then
self.nActStatus = AllEnum.JointDrillActStatus.WaitClose
nRemainTime = nActEndTime - nCurTime
elseif nCurTime >= nActEndTime then
self.nActStatus = AllEnum.JointDrillActStatus.Closed
nRemainTime = 0
end
EventManager.Hit("RefreshJointDrillActTime", self.nActStatus, nRemainTime)
if nRemainTime <= 0 and self.actTimer ~= nil and self.nActStatus == AllEnum.JointDrillActStatus.Closed then
self.actTimer:Cancel()
self.actTimer = nil
return
end
end
refreshTime()
if self.actTimer == nil then
self.actTimer = TimerManager.Add(0, 1, nil, refreshTime, true, true, true)
end
end
end
function PlayerJointDrillData:RefreshJointDrillQuestRedDot()
local bHasReward = false
for _, v in ipairs(self.tbQuests) do
if v.Status == 1 then
bHasReward = true
break
end
end
RedDotManager.SetValid(RedDotDefine.JointDrillQuest, nil, bHasReward)
end
function PlayerJointDrillData:EnterJointDrill(nLevelId, nBuildId, bSimulate, bChangeLevel, nCurLevel)
local mapLevelCfg = ConfigTable.GetData("JointDrillLevel", nLevelId)
if mapLevelCfg == nil then
printError("找不到总力战关卡数据!!!levelId = " .. tostring(nLevelId))
return
end
local nHp, nHpMax = 0, 0
if self.record == nil or self.record == "" then
nHpMax = self:GetMonsterMaxHp(mapLevelCfg.BossId, mapLevelCfg.Difficulty)
nHp = nHpMax
else
local mapTemp = DecodeTempDataJson(self.record)
if mapTemp ~= nil and mapTemp.mapBossTempData ~= nil and mapTemp.mapBossTempData.nBossId ~= 0 then
nHpMax = mapTemp.mapBossTempData.nHpMax
nHp = mapTemp.mapBossTempData.nHp
end
end
if nHpMax == 0 then
printError(string.format("[总力战]获取boss血量失败!!! levelId = %s, bossId = %s", nLevelId, mapLevelCfg.BossId))
return
end
local enterLevel = function(mapNetData)
if self.curLevel == nil then
local luaClass = require("Game.Adventure.JointDrill.JointDrillLevelData")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
end
self.nCurLevelId = nLevelId
self.bInBattle = true
self.bSimulate = bSimulate
self.mapBossInfo = {}
self.mapBossInfo.nHp = nHp
self.mapBossInfo.nHpMax = nHpMax
if nCurLevel == nil then
nCurLevel = self.nCurLevel
end
if mapNetData ~= nil then
self.nStartTime = mapNetData.StarTime
self._EntryTime = mapNetData.StarTime
local sKey = LocalData.GetPlayerLocalData("JointDrillRecordKey") or ""
if sKey ~= nil and sKey ~= "" then
NovaAPI.DeleteRecFile(sKey)
end
sKey = tostring(mapNetData.StarTime)
LocalData.SetPlayerLocalData("JointDrillRecordKey", sKey)
LocalData.SetPlayerLocalData("JointDrillRecordFloorId", 0)
LocalData.SetPlayerLocalData("JointDrillRecordExcludeId", 0)
self:EventUpload(1)
end
self:StartChallengeTime()
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId, nCurLevel, bChangeLevel)
end
end
local netCallback = function(_, netMsg)
enterLevel(netMsg)
end
if self.bInBattle and not bChangeLevel then
self:ContinueJointDrill(nBuildId, enterLevel)
elseif not bChangeLevel then
local msg = {
LevelId = nLevelId,
BuildId = nBuildId,
BossHp = nHp,
BossHpMax = nHpMax,
Simulate = bSimulate
}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_apply_req, msg, nil, netCallback)
else
enterLevel()
end
end
function PlayerJointDrillData:ChangeLevel(nLevel)
self:EnterJointDrill(self.nCurLevelId, self.nSelectBuildId, self.bSimulate, true, nLevel)
end
function PlayerJointDrillData:RestartBattle()
self:EnterJointDrill(self.nCurLevelId, self.nSelectBuildId, self.bSimulate, true, self.nCurLevel)
end
function PlayerJointDrillData:ContinueJointDrill(nBuildId, callback)
local NetCallback = function(_, netMsg)
local sKey = LocalData.GetPlayerLocalData("JointDrillRecordKey") or ""
if sKey == "" or sKey ~= tostring(self.nStartTime) then
if sKey ~= "" then
NovaAPI.DeleteRecFile(sKey)
end
sKey = tostring(self.nStartTime)
LocalData.SetPlayerLocalData("JointDrillRecordKey", self.nStartTime)
end
if callback ~= nil then
callback()
end
end
local msg = {BuildId = nBuildId}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_continue_req, msg, nil, NetCallback)
end
function PlayerJointDrillData:JointDrillGameOver(callback, bSettle)
self:SetRecorderExcludeIds()
self:StopRecord()
self._EndTime = ClientManager.serverTimeStamp
local NetCallback = function(_, netMsg)
local nScoreOld = 0
if self.mapSelfRankData ~= nil then
nScoreOld = self.mapSelfRankData.Score
end
if netMsg.Old ~= netMsg.New then
self:SendJointDrillRankMsg()
end
self:UploadRecordFile(netMsg.Token)
if not self.bSimulate then
self.nTotalScore = self.nTotalScore + netMsg.FightScore + netMsg.HpScore + netMsg.DifficultyScore
end
EventManager.Hit(EventId.ClosePanel, PanelId.JointDrillBuildList)
EventManager.Hit("RefreshJointDrillLevel")
if callback ~= nil then
callback(netMsg)
end
if bSettle then
local nResultType = AllEnum.JointDrillResultType.ChallengeEnd
local mapScore = {}
local nTotalScore = PlayerData.JointDrill:GetTotalRankScore()
local mapChange, mapItems = {}, {}
local nOld, nNew = 0, 0
if netMsg ~= nil then
mapChange = netMsg.Change or {}
mapItems = netMsg.Items or {}
local nScore = netMsg.FightScore + netMsg.HpScore + netMsg.DifficultyScore
mapScore = {
FightScore = netMsg.FightScore,
HpScore = netMsg.HpScore,
DifficultyScore = netMsg.DifficultyScore,
nTotalScore = nTotalScore,
nScore = nScore,
nScoreOld = nScoreOld
}
nOld = netMsg.Old
nNew = netMsg.New
end
EventManager.Hit(EventId.OpenPanel, PanelId.JointDrillResult, nResultType, self.nCurLevel, 0, self.nCurLevelId, self.mapBossInfo, mapScore, mapItems, mapChange, nOld, nNew, self.bSimulate, #self.tbTeams)
end
self:EventUpload(4, 0)
self:ChallengeEnd()
end
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_game_over_req, {}, nil, NetCallback)
end
function PlayerJointDrillData:JointDrillGiveUp(nFloor, nTime, nDamage, nBossHp, sRecord, mapBuild, callback)
self:SetRecorderExcludeIds()
self:StopRecord()
local NetCallback = function(_, netMsg)
self.record = sRecord
self.nCurLevel = nFloor
self.mapBossInfo.nHp = nBossHp
if callback ~= nil then
callback(netMsg)
end
if netMsg.Old ~= netMsg.New then
self:SendJointDrillRankMsg()
end
end
local msg = {
Floor = nFloor,
Time = nTime,
Damage = nDamage,
BossHp = nBossHp,
Record = sRecord
}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_give_up_req, msg, nil, NetCallback)
end
function PlayerJointDrillData:JointDrillRetreat(mapBuild, callback)
self:SetRecorderExcludeIds(true)
self:StopRecord()
local NetCallback = function(_, netMsg)
self:RemoveJointDrillTeam(mapBuild)
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_retreat_req, {}, nil, NetCallback)
end
function PlayerJointDrillData:JointDrillSettle(mapBuild, nTime, nDamage, callback)
self:SetRecorderExcludeIds()
self:StopRecord()
self:AddJointDrillTeam(mapBuild, nTime, nDamage)
self._EndTime = ClientManager.serverTimeStamp
local NetCallback = function(_, netMsg)
self:UploadRecordFile(netMsg.Token)
if not self.bSimulate then
local nScore = netMsg.FightScore + netMsg.HpScore + netMsg.DifficultyScore
self.nTotalScore = self.nTotalScore + nScore
table.insert(self.tbPassedLevels, {
LevelId = self.nCurLevelId,
Score = nScore
})
end
EventManager.Hit(EventId.ClosePanel, PanelId.JointDrillBuildList)
if callback ~= nil then
callback(netMsg)
end
if netMsg.Old ~= netMsg.New then
self:SendJointDrillRankMsg()
end
self:EventUpload(4, 1)
end
local tbSamples = UTILS.GetBattleSamples()
local sKey = LocalData.GetPlayerLocalData("JointDrillRecordKey") or ""
local bSuccess, nCheckSum = NovaAPI.GetRecorderKey(sKey)
local tbSendSample = {Sample = tbSamples, Checksum = nCheckSum}
local msg = {
Time = nTime,
Damage = nDamage,
sample = tbSendSample,
Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.JointDrill, true)
}
}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_settle_req, msg, nil, NetCallback)
end
function PlayerJointDrillData:JointDrillSync(nFloor, nTime, nDamage, nBossHp, nBossHpMax, sRecord, callback)
local NetCallback = function(_, netMsg)
self.record = sRecord
self.mapBossInfo.nHp = nBossHp
self.mapBossInfo.nHpMax = nBossHpMax
if callback ~= nil then
callback()
end
end
local msg = {
Floor = nFloor,
Time = nTime,
Damage = nDamage,
BossHp = nBossHp,
BossHpMax = nBossHpMax,
Record = sRecord
}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_sync_req, msg, nil, NetCallback)
end
function PlayerJointDrillData:LevelEnd(nType)
if self.curLevel ~= nil and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
self.nGameTime = 0
if nType ~= AllEnum.JointDrillResultType.Retreat then
self.nSelectBuildId = 0
end
end
function PlayerJointDrillData:ChallengeEnd()
if self.curLevel ~= nil and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.bInBattle = false
self.curLevel = nil
self.nCurLevelId = 0
self.nCurLevel = 1
self.nStartTime = 0
self.nGameTime = 0
self.bSimulate = false
self.record = nil
self.tbTeams = {}
self.nSelectBuildId = 0
self.tbRecordFloors = {}
if self.challengeTimer ~= nil then
self.challengeTimer:Cancel()
self.challengeTimer = nil
end
self._EntryTime = 0
self._EndTime = 0
end
function PlayerJointDrillData:ResetRecord(sRecord)
self.record = sRecord
end
function PlayerJointDrillData:GetJointDrillLevelId()
return self.nCurLevelId
end
function PlayerJointDrillData:GetJointDrillCurLevel()
return self.nCurLevel
end
function PlayerJointDrillData:GetJointDrillStartTime()
return self.nStartTime
end
function PlayerJointDrillData:GetJointDrillBossInfo()
return self.mapBossInfo
end
function PlayerJointDrillData:GetJointDrillBuildList()
return self.tbTeams
end
function PlayerJointDrillData:GetJointDrillBattleCount()
return #self.tbTeams
end
function PlayerJointDrillData:CheckChallengeCount()
if self.nCurLevelId ~= 0 then
local mapLevelCfg = ConfigTable.GetData("JointDrillLevel", self.nCurLevelId)
if mapLevelCfg ~= nil then
if #self.tbTeams < mapLevelCfg.MaxBattleNum then
return true
else
EventManager.Hit(EventId.ClosePanel, PanelId.JointDrillBuildList)
self:JointDrillGameOver()
return false
end
end
return false
end
return true
end
function PlayerJointDrillData:CheckJointDrillInBattle()
return self.bInBattle
end
function PlayerJointDrillData:GetMaxChallengeCount(nLevelId)
local mapLevelCfg = ConfigTable.GetData("JointDrillLevel", nLevelId)
if mapLevelCfg ~= nil then
return mapLevelCfg.MaxBattleNum
end
return 0
end
function PlayerJointDrillData:SetSelBuildId(nBuildId)
self.nSelectBuildId = nBuildId
end
function PlayerJointDrillData:GetCachedBuild()
return self.nSelectBuildId
end
function PlayerJointDrillData:GetBossHpBarNum()
if self.nCurLevelId ~= nil then
local mapCfg = ConfigTable.GetData("JointDrillLevel", self.nCurLevelId)
if mapCfg ~= nil then
return mapCfg.HpBarNum
end
end
return 40
end
function PlayerJointDrillData:AddJointDrillTeam(mapBuildData, nTime, nDamage)
local bInsert = false
for _, v in ipairs(self.tbTeams) do
if v.BuildId == mapBuildData.nBuildId then
bInsert = true
v.Damage = nDamage
v.Time = nTime
break
end
end
if not bInsert then
local tbChar = {}
for _, mapChar in ipairs(mapBuildData.tbChar) do
local nCharId = mapChar.nTid
local nLv = PlayerData.Char:GetCharLv(nCharId)
table.insert(tbChar, {CharId = nCharId, CharLevel = nLv})
end
local teamData = {
Chars = tbChar,
BuildScore = mapBuildData.nScore,
Damage = nDamage,
Time = nTime,
BuildId = mapBuildData.nBuildId
}
table.insert(self.tbTeams, teamData)
end
end
function PlayerJointDrillData:RemoveJointDrillTeam(mapBuildData)
local nIndex = 0
for k, v in ipairs(self.tbTeams) do
if v.BuildId == mapBuildData.nBuildId then
nIndex = k
break
end
end
if nIndex ~= 0 then
table.remove(self.tbTeams, nIndex)
end
end
function PlayerJointDrillData:SetGameTime(nTime)
self.nGameTime = nTime
end
function PlayerJointDrillData:GetGameTime()
return self.nGameTime
end
function PlayerJointDrillData:GetBattleSimulate()
return self.bSimulate
end
function PlayerJointDrillData:AddRecordFloorList()
local nValue = LocalData.GetPlayerLocalData("JointDrillRecordFloorId") or 0
nValue = nValue + 1
table.insert(self.tbRecordFloors, nValue)
LocalData.SetPlayerLocalData("JointDrillRecordFloorId", nValue)
NovaAPI.SetRecorderFloorId(nValue)
end
function PlayerJointDrillData:AddRecordExcludeId(nId)
local nValue = LocalData.GetPlayerLocalData("JointDrillRecordExcludeId") or 0
nValue = 1 << nId - 1 | nValue
LocalData.SetPlayerLocalData("JointDrillRecordExcludeId", nValue)
end
function PlayerJointDrillData:SetRecorderExcludeIds(bRemove)
local tbFloorId = ListInt()
if bRemove then
for _, v in ipairs(self.tbRecordFloors) do
self:AddRecordExcludeId(v)
end
end
local nExcludeValue = LocalData.GetPlayerLocalData("JointDrillRecordExcludeId") or 0
if 0 < nExcludeValue then
local tbTemp = {}
while 0 < nExcludeValue do
table.insert(tbTemp, 1, nExcludeValue % 2)
nExcludeValue = math.floor(nExcludeValue / 2)
end
printTable(tbTemp)
for k, v in ipairs(tbTemp) do
if v == 1 then
tbFloorId:Add(#tbTemp - k + 1)
end
end
end
self.tbRecordFloors = {}
NovaAPI.SetRecorderExcludeIds(tbFloorId)
end
function PlayerJointDrillData:StopRecord()
NovaAPI.StopRecord()
end
function PlayerJointDrillData:UploadRecordFile(sToken)
local sKey = LocalData.GetPlayerLocalData("JointDrillRecordKey") or ""
if sKey ~= nil and sKey ~= "" then
if sToken ~= nil and sToken ~= "" then
NovaAPI.UploadStartowerFile(sToken, sKey)
else
NovaAPI.DeleteRecFile(sKey)
end
end
LocalData.SetPlayerLocalData("JointDrillRecordKey", "")
end
function PlayerJointDrillData:CheckActChallengeTime()
local actData = PlayerData.Activity:GetActivityDataById(self.nActId)
if actData ~= nil then
local nChallengeEndTime = actData:GetChallengeEndTime()
local nCurTime = ClientManager.serverTimeStamp
if nChallengeEndTime <= nCurTime then
return false
end
return true
end
return false
end
function PlayerJointDrillData:GetActStatus()
return self.nActStatus
end
function PlayerJointDrillData:SendJointDrillRankMsg()
local NetCallback = function(_, netMsg)
self.nLastRefreshRankTime = netMsg.LastRefreshTime
self.mapSelfRankData = netMsg.Self
self.mapRankList = netMsg.Rank
self.nTotalRank = netMsg.Total or 0
EventManager.Hit("GetJointDrillRankSuc")
end
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_rank_req, {}, nil, NetCallback)
end
function PlayerJointDrillData:GetSelfRankData()
return self.mapSelfRankData
end
function PlayerJointDrillData:GetRankList()
return self.mapRankList
end
function PlayerJointDrillData:GetRankRewardCount()
return self.nRankCount
end
function PlayerJointDrillData:GetTotalRankCount()
return self.nTotalRank
end
function PlayerJointDrillData:GetLastRankRefreshTime()
return self.nLastRefreshRankTime, self.nRankingRefreshTime
end
function PlayerJointDrillData:GetTotalRankScore()
return self.nTotalScore
end
function PlayerJointDrillData:SendJointDrillSweepMsg(nLevelId, nCount, callback)
local NetCallback = function(_, netMsg)
EventManager.Hit("JointDrillRaidSuccess", netMsg)
if callback ~= nil then
callback(netMsg)
end
self.nTotalScore = netMsg.Score
self:EventUpload(5)
end
local msg = {LevelId = nLevelId, Count = nCount}
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_sweep_req, msg, nil, NetCallback)
end
function PlayerJointDrillData:SendReceiveQuestReward(callback)
local NetCallback = function(_, netMsg)
UTILS.OpenReceiveByChangeInfo(netMsg, function()
if callback ~= nil then
callback()
end
end)
end
HttpNetHandler.SendMsg(NetMsgId.Id.joint_drill_quest_reward_receive_req, {}, nil, NetCallback)
end
function PlayerJointDrillData:RefreshQuestData(questData)
local bHasData = false
for k, v in ipairs(self.tbQuests) do
if v.Id == questData.Id then
self.tbQuests[k] = questData
bHasData = true
break
end
end
if not bHasData then
table.insert(self.tbQuests, questData)
end
self:RefreshJointDrillQuestRedDot()
end
function PlayerJointDrillData:GetRewardQuestList()
local tbQuests = {}
for _, v in ipairs(self.tbQuests) do
local nSortStatus = 0
if v.Status == 0 then
nSortStatus = 1
elseif v.Status == 1 then
nSortStatus = 0
elseif v.Status == 2 then
nSortStatus = 2
end
v.SortStatus = nSortStatus
table.insert(tbQuests, v)
end
return tbQuests
end
function PlayerJointDrillData:EventUpload(action, result)
result = result or ""
local nCostTime = 0
if action == 4 then
nCostTime = self._EndTime - self._EntryTime
end
local tabUpLevel = {}
table.insert(tabUpLevel, {
"action",
tostring(action)
})
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(nCostTime)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self.nCurLevelId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
table.insert(tabUpLevel, {
"team_num",
tostring(#self.tbTeams)
})
table.insert(tabUpLevel, {
"simulate",
tostring(self.bSimulate and 1 or 0)
})
NovaAPI.UserEventUpload("joint_drill_battle", tabUpLevel)
end
return PlayerJointDrillData
@@ -0,0 +1,308 @@
local PlayerMailData = class("PlayerMailData")
local TimerManager = require("GameCore.Timer.TimerManager")
function PlayerMailData:Init()
self.bisNew = false
EventManager.Add(EventId.UpdateWorldClass, self, self.UpdateWorldClass)
self._mapMail = {}
self.bNeedUpdate = true
self.funcCallBack = nil
self.isOpen = false
self.delayCallOpen = nil
self.bInitRedDot = false
self:StopDeadLineTimer()
end
function PlayerMailData:HandleDefaultMail(tab)
local id = tab.Id
local dMsg = ConfigTable.GetData("MailTemplate", tab.TemplateId)
if dMsg ~= nil then
if tab.Subject == nil or tab.Subject == "" then
tab.Subject = dMsg.Subject
end
if tab.Desc == nil or tab.Desc == "" then
tab.Desc = dMsg.Desc
end
if tab.Author == nil or tab.Author == "" then
tab.Author = dMsg.Author
end
if (tab.Attachments == nil or #tab.Attachments == 0) and tab.Read then
tab.Recv = true
end
tab.Icon = dMsg.Icon
tab.LetterPaper = dMsg.LetterPaper
end
return tab
end
function PlayerMailData:CacheMailData(mapData)
self.bNeedUpdate = false
self.bisNew = false
self._mapMail = {}
if mapData == nil then
self:RunCallBack()
self:StopDeadLineTimer()
else
if mapData.List == nil then
self:RunCallBack()
self:StopDeadLineTimer()
return
end
for _, mapMail in ipairs(mapData.List) do
if mapMail.TemplateId == 0 then
self._mapMail[mapMail.Id] = mapMail
else
local _data = self:HandleDefaultMail(mapMail)
self._mapMail[mapMail.Id] = _data
end
end
self:RunCallBack()
self:StartDeadLineTimer()
end
if not self.bInitRedDot then
self.bInitRedDot = true
end
self:UpdateMailUnReceiveRedDot()
end
function PlayerMailData:UpdateMailRed(isNew)
self.bisNew = isNew
if PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Mail) then
if isNew then
RedDotManager.SetValid(RedDotDefine.Mail_UnRead, nil, true)
end
self.bisNew = false
end
end
function PlayerMailData:UpdateWorldClass()
if PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Mail) then
RedDotManager.SetValid(RedDotDefine.Mail_UnRead, nil, self.bisNew)
self.bisNew = false
end
end
function PlayerMailData:UpdateMailList(mapMsgData)
self.bisNew = true
self.bNeedUpdate = true
if PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Mail) and mapMsgData.New then
RedDotManager.SetValid(RedDotDefine.Mail_New, nil, true)
end
EventManager.Hit("GetAllMailList")
end
function PlayerMailData:ReceiveMailItem(mapData)
local tabItem = {}
local tmpTab = {}
if type(mapData.Ids) == "table" then
for i = 1, #mapData.Ids do
if self._mapMail[mapData.Ids[i]] ~= nil then
self._mapMail[mapData.Ids[i]].Read = true
self._mapMail[mapData.Ids[i]].Recv = true
if self._mapMail[mapData.Ids[i]].Attachments and #self._mapMail[mapData.Ids[i]].Attachments > 0 then
for k, v in pairs(self._mapMail[mapData.Ids[i]].Attachments) do
local itemCfg = ConfigTable.GetData("Item", v.Tid)
if itemCfg ~= nil and itemCfg.Type ~= GameEnum.itemType.CharacterSkin then
if tmpTab[v.Tid] == nil then
tmpTab[v.Tid] = v.Qty
else
tmpTab[v.Tid] = tmpTab[v.Tid] + v.Qty
end
end
end
end
end
end
for i, v in pairs(tmpTab) do
table.insert(tabItem, {Tid = i, Qty = v})
end
UTILS.OpenReceiveByDisplayItem(tabItem, mapData.Items, function()
PlayerData.Base:TryOpenWorldClassUpgrade()
end)
end
self:RunCallBack()
self:UpdateMailUnReceiveRedDot()
end
function PlayerMailData:ReadMail(mapMsgData)
if self._mapMail[mapMsgData.Value] ~= nil then
self._mapMail[mapMsgData.Value].Read = true
if self._mapMail[mapMsgData.Value].Attachments == nil or #self._mapMail[mapMsgData.Value].Attachments == 0 then
self._mapMail[mapMsgData.Value].Recv = true
end
end
self:RunCallBack()
end
function PlayerMailData:RemoveMail(mapData)
if type(mapData.Ids) == "table" then
for i = 1, #mapData.Ids do
if self._mapMail[mapData.Ids[i]] ~= nil then
self._mapMail[mapData.Ids[i]] = nil
end
end
end
local wait = function()
coroutine.yield(CS.UnityEngine.WaitForEndOfFrame())
self:RunCallBack()
end
cs_coroutine.start(wait)
end
function PlayerMailData:GetAgainAllMain()
local fCb = function()
EventManager.Hit("OnEvent_RefrushMailGroup")
end
self.funcCallBack = fCb
self:SengMsgMailList()
end
function PlayerMailData:SengMsgMailList(callback)
HttpNetHandler.SendMsg(NetMsgId.Id.mail_list_req, {}, nil, callback)
end
function PlayerMailData:RefreshMailRedDot(mapMsgData)
if PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.Mail) and mapMsgData.New then
RedDotManager.SetValid(RedDotDefine.Mail_New, nil, true)
end
end
function PlayerMailData:GetAllMail(func_callBack, isOpen)
if func_callBack then
self.funcCallBack = func_callBack
end
self.isOpen = isOpen
if self.bNeedUpdate then
self:SengMsgMailList()
else
self:RunCallBack()
end
end
function PlayerMailData:RunCallBack()
if self.funcCallBack then
self.funcCallBack()
self.funcCallBack = nil
end
if self.isOpen then
local func = function()
EventManager.Hit(EventId.OpenPanel, PanelId.Mail)
end
EventManager.Hit(EventId.SetTransition, 5, func)
self.isOpen = false
local time = CS.ClientManager.Instance.serverTimeStamp
local hour = tonumber(os.date("%H", time))
local minute = tonumber(os.date("%M", time))
local second = tonumber(os.date("%S", time))
local delaySec = 100800 - hour * 3600 - minute * 60 - second
self.delayCallOpen = TimerManager.Add(1, delaySec, self, self.DelayTimeCallMsg, true, true, false)
end
end
function PlayerMailData:CheckMailDeadLine()
local bNeedRefresh = false
for id, v in pairs(self._mapMail) do
if v.Deadline ~= 0 and not self.tbDeadLineCheckList[id] then
local remainTime = v.Deadline - CS.ClientManager.Instance.serverTimeStamp
if remainTime <= 0 then
self.tbDeadLineCheckList[id] = true
bNeedRefresh = true
break
end
end
end
if bNeedRefresh then
self:UpdateMailUnReceiveRedDot()
EventManager.Hit("GetAllMailList")
end
end
function PlayerMailData:StartDeadLineTimer()
if nil == self.timerMailDeadLine then
self.timerMailDeadLine = TimerManager.Add(0, 10, self, self.CheckMailDeadLine, true, true, false)
end
end
function PlayerMailData:StopDeadLineTimer()
if nil ~= self.timerMailDeadLine then
TimerManager.Remove(self.timerMailDeadLine, false)
end
self.timerMailDeadLine = nil
self.tbDeadLineCheckList = {}
end
function PlayerMailData:DelayTimeCallMsg()
if self.bNeedUpdate then
local cb = function()
EventManager.Hit(EventId.RefrushMailView)
end
self:GetAllMail(cb, false)
end
self:CancelTimeDelay()
local time = CS.ClientManager.Instance.serverTimeStamp
local hour = tonumber(os.date("%H", time))
local minute = tonumber(os.date("%M", time))
local second = tonumber(os.date("%S", time))
local delaySec = 100800 - hour * 3600 - minute * 60 - second
self.delayCallOpen = TimerManager.Add(1, delaySec, self, self.DelayTimeCallMsg, true, true, false)
end
function PlayerMailData:SendMailRecvReq(id, flag, callback)
if callback then
self.funcCallBack = callback
end
local skinCachClearCb = function(_, mapMsgData)
PlayerData.CharSkin:TryOpenSkinShowPanel(function()
PlayerData.Mail:ReceiveMailItem(mapMsgData)
end)
if callback then
callback()
end
end
local sendMsgBody = {Id = id, Flag = flag}
HttpNetHandler.SendMsg(NetMsgId.Id.mail_recv_req, sendMsgBody, nil, skinCachClearCb)
end
function PlayerMailData:SendMailGetSurveryMsg(id, callback)
if callback then
self.funcCallBack = callback
end
local sendMsgBody = {SurveyId = id}
HttpNetHandler.SendMsg(NetMsgId.Id.player_survey_req, sendMsgBody, nil, callback)
end
function PlayerMailData:SendMailReadReq(id, flag, callback)
local sendMsgBody = {Id = id, Flag = flag}
HttpNetHandler.SendMsg(NetMsgId.Id.mail_read_req, sendMsgBody, nil, callback)
end
function PlayerMailData:SendMailRemoveReq(id, flag, callback)
if callback then
self.funcCallBack = callback
end
local sendMsgBody = {Id = id, Flag = flag}
HttpNetHandler.SendMsg(NetMsgId.Id.mail_remove_req, sendMsgBody, nil, callback)
end
function PlayerMailData:SendMailPin(id, flag, isPin, callback)
local sendMsgBody = {
Id = id,
Flag = flag,
Pin = isPin
}
local cb = function(_, mapMsgData)
self._mapMail[mapMsgData.Id].Flag = mapMsgData.Flag
self._mapMail[mapMsgData.Id].Pin = mapMsgData.Pin
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.mail_pin_req, sendMsgBody, nil, cb)
end
function PlayerMailData:CancelTimeDelay()
if self.delayCallOpen then
self.delayCallOpen:Cancel(nil)
self.delayCallOpen = nil
end
end
function PlayerMailData:ClearFunCallBack()
if self.funcCallBack then
self.funcCallBack = nil
end
end
function PlayerMailData:UpdateMailUnReadRedDot()
local bUnRead = false
for _, mail in pairs(self._mapMail) do
if not mail.Read then
bUnRead = true
break
end
end
RedDotManager.SetValid(RedDotDefine.Mail_UnRead, nil, bUnRead)
end
function PlayerMailData:UpdateMailUnReceiveRedDot()
local nUnReceive = false
for _, mail in pairs(self._mapMail) do
if (mail.Deadline == 0 or CS.ClientManager.Instance.serverTimeStamp < mail.Deadline) and mail.Attachments and 0 < #mail.Attachments and not mail.Recv then
nUnReceive = true
break
end
end
RedDotManager.SetValid(RedDotDefine.Mail_UnReceive, nil, nUnReceive)
end
return PlayerMailData
@@ -0,0 +1,599 @@
local RapidJson = require("rapidjson")
local ClientManager = CS.ClientManager
local PlayerMainlineDataEx = class("PlayerMainlineDataEx")
function PlayerMainlineDataEx:Init()
EventManager.Add(EventId.SendMsgEnterBattle, self, self.OnEvent_EnterMainline)
self._mapStar = {}
self._mapChapters = {}
self._nSelectId = 0
self._tbCharId = nil
self.nCurTeamIndex = 1
self._mainlineData = nil
self:ProcessMainlineData()
self._mainlineLevel = nil
self.bUseOldMainline = false
end
function PlayerMainlineDataEx:CacheMainline(mapData, Chapters)
for k, v in pairs(mapData) do
local mapMainline = ConfigTable.GetData_Mainline(v.Id)
if mapMainline ~= nil then
local nChapterId = mapMainline.ChapterId
if self._mapStar[nChapterId] == nil then
self._mapStar[nChapterId] = {}
end
local b1 = 1
local b2 = 2
local b3 = 4
local t1 = v.Star & b1 > 0
local t2 = v.Star & b2 > 0
local t3 = v.Star & b3 > 0
local nStar = self.CalStar(v.Star)
self._mapStar[nChapterId][v.Id] = {
nStar = nStar,
tbTarget = {
t1,
t2,
t3
}
}
end
end
if Chapters ~= nil then
for _, v in pairs(Chapters) do
self._mapChapters[v.Id] = v.Idx
end
end
self:UpdateRewardRedDot()
end
function PlayerMainlineDataEx:IsMainlineChapterUnlock(nChapterId)
local mapMainlineData = ConfigTable.GetData("Chapter", nChapterId)
if not self.bUseOldMainline then
mapMainlineData = ConfigTable.GetData("StoryChapter", nChapterId)
end
if mapMainlineData == nil then
return false
end
local nWorldClass = mapMainlineData.WorldClass
local nCurWorldClass = PlayerData.Base:GetWorldClass()
if nWorldClass > nCurWorldClass then
return false
end
local tbPrevId
if self.bUseOldMainline then
tbPrevId = mapMainlineData.PrevMainlines
else
tbPrevId = mapMainlineData.PrevStories
end
for _, nPrevId in ipairs(tbPrevId) do
local mapMainline = ConfigTable.GetData_Mainline(nPrevId)
local nPrevIdChapter = mapMainline.ChapterId
if self._mapStar[nPrevIdChapter] == nil or self._mapStar[nPrevIdChapter][nPrevId] == nil or self._mapStar[nPrevIdChapter][nPrevId].nStar == 0 then
return false
end
end
return true
end
function PlayerMainlineDataEx:IsMainlineLevelUnlock(nLevelId)
local mapMainlineData = ConfigTable.GetData_Mainline(nLevelId)
if mapMainlineData == nil then
return false
end
local tbPrevId = mapMainlineData.Prev
for __, nPrevId in ipairs(tbPrevId) do
local mapMainline = ConfigTable.GetData_Mainline(nPrevId)
if mapMainline == nil then
return false
end
if self._mapStar[mapMainline.ChapterId] == nil or self._mapStar[mapMainline.ChapterId][nPrevId] == nil or self._mapStar[mapMainline.ChapterId][nPrevId].nStar == 0 then
return false
end
end
local bCoinUnlock = self._mapStar[mapMainlineData.ChapterId] ~= nil and self._mapStar[mapMainlineData.ChapterId][nLevelId] ~= nil
return true, bCoinUnlock
end
function PlayerMainlineDataEx:GetChapterStars(nChapterId)
local ret = 0
local ret1 = 0
if self._mapStar[nChapterId] == nil then
return ret
end
for mainlinId, mapChapterStar in pairs(self._mapStar[nChapterId]) do
local mapData = ConfigTable.GetData_Mainline(mainlinId)
local nStar = mapChapterStar.nStar
if mapData.AvgId == "" then
ret = ret + nStar
end
ret1 = ret1 + nStar
end
return ret, ret1
end
function PlayerMainlineDataEx:GetChapterTotalStar(nChapterId)
local ret = 0
for _, _ in pairs(self._mainlineData[nChapterId]) do
ret = ret + 3
end
return ret
end
function PlayerMainlineDataEx:GetChapterAward(nChapterId)
if self._mapChapters[nChapterId] == nil then
return 0
end
return self._mapChapters[nChapterId]
end
function PlayerMainlineDataEx:GetMianlineLevelStar(nLevelId)
local mapMainlinData = ConfigTable.GetData_Mainline(nLevelId)
if nil == mapMainlinData then
return 0, {
false,
false,
false
}
end
local nChapterId = mapMainlinData.ChapterId
if self._mapStar[nChapterId] == nil then
return 0, {
false,
false,
false
}
end
if self._mapStar[nChapterId][nLevelId] == nil then
return 0, {
false,
false,
false
}
end
return self._mapStar[nChapterId][nLevelId].nStar, self._mapStar[nChapterId][nLevelId].tbTarget
end
function PlayerMainlineDataEx:ProcessMainlineData()
self._mainlineData = {}
local forEachTableMainline = function(mapData)
local nChapter = mapData.ChapterId
if self._mainlineData[nChapter] == nil then
self._mainlineData[nChapter] = {}
end
if self._mainlineData[nChapter][mapData.Id] == nil then
self._mainlineData[nChapter][mapData.Id] = {}
end
self._mainlineData[nChapter][mapData.Id].data = mapData
self._mainlineData[nChapter][mapData.Id].Prev = mapData.Prev
for _, prevId in pairs(mapData.Prev) do
local mapPrevData = ConfigTable.GetData_Mainline(prevId)
if mapPrevData ~= nil then
local nChapterPrev = mapPrevData.ChapterId
if self._mainlineData[nChapterPrev] == nil then
self._mainlineData[nChapterPrev] = {}
end
if self._mainlineData[nChapterPrev][prevId] == nil then
self._mainlineData[nChapterPrev][prevId] = {}
end
if self._mainlineData[nChapterPrev][prevId].After == nil then
self._mainlineData[nChapterPrev][prevId].After = {}
end
table.insert(self._mainlineData[nChapterPrev][prevId].After, mapData.Id)
table.sort(self._mainlineData[nChapterPrev][prevId].After)
end
end
end
ForEachTableLine(DataTable.Mainline, forEachTableMainline)
end
function PlayerMainlineDataEx:GetAllMainlineChapter(nChapterId)
local ret = {}
local idx = 1
local retIdx
local forEachTableChapter = function(mapData)
if nil ~= nChapterId and nChapterId == mapData.Id then
retIdx = idx
end
local isUnlock = self:IsMainlineChapterUnlock(mapData.Id)
local nStar, nAvgStar = self:GetChapterStars(mapData.Id)
local nAwardIdx = self:GetChapterAward(mapData.Id)
local TotalStar = self:GetChapterTotalStar(mapData.Id)
table.insert(ret, {
nId = mapData.Id,
nStar = nStar,
bUnlock = isUnlock,
nAwardIdx = nAwardIdx,
bComplete = TotalStar == nAvgStar
})
idx = idx + 1
end
ForEachTableLine(DataTable.Chapter, forEachTableChapter)
return ret, retIdx
end
function PlayerMainlineDataEx:GetAllLevelByChapter(nChapterId)
if self._mainlineData[nChapterId] == nil then
printError("没有章节数据:" .. nChapterId)
return {}
end
local tbId = {}
local mapId = {}
local ret = {}
for nId, _ in pairs(self._mainlineData[nChapterId]) do
table.insert(tbId, nId)
mapId[nId] = false
end
table.sort(tbId)
local function AddMainline(nId)
if nId == nil then
return
end
if mapId[nId] == nil or mapId[nId] == true then
return
end
local levelData = ConfigTable.GetData_Mainline(nId)
if levelData == nil then
printError("关卡数据不存在" .. nId)
return
end
local ChapterId = levelData.ChapterId
local nStar, tbTarget = self:GetMianlineLevelStar(nId)
table.insert(ret, {
nId = nId,
nStar = nStar,
tbTarget = tbTarget,
bUnlock = self:IsMainlineLevelUnlock(nId)
})
mapId[nId] = true
if self._mainlineData[ChapterId][nId] == nil then
return
end
local tbAfter = self._mainlineData[ChapterId][nId].After
if tbAfter == nil then
return
end
for _, nLevelId in ipairs(tbAfter) do
AddMainline(nLevelId)
end
end
local isStartLevel = function(nMainline)
local mapMainline = ConfigTable.GetData_Mainline(nMainline)
if mapMainline == nil then
return false
end
local mapChapter = ConfigTable.GetData("Chapter", mapMainline.ChapterId)
local tbPrevMainlines = mapChapter.PrevMainlines
if mapMainline.Prev == nil or #mapMainline.Prev == 0 or 0 < table.indexof(mapMainline.Prev, tbPrevMainlines[1]) then
return true
else
return false
end
end
for _, nId in ipairs(tbId) do
if isStartLevel(nId) then
AddMainline(nId)
end
end
return ret
end
function PlayerMainlineDataEx:GetBanedCharId()
if type(self._nSelectId) == "number" and self._nSelectId > 0 then
local data = ConfigTable.GetData_Mainline(self._nSelectId)
if data ~= nil then
if type(data.CharBanned) == "table" then
return data.CharBanned
else
return nil
end
else
return nil
end
else
return nil
end
end
function PlayerMainlineDataEx:GetBeforeBattleAvg()
local sAvgId = ConfigTable.GetData_Mainline(self._nSelectId).BeforeAvgId
if sAvgId == "" then
return false
end
return sAvgId
end
function PlayerMainlineDataEx.CalStar(nOrigin)
nOrigin = (nOrigin & 1431655765) + (nOrigin >> 1 & 1431655765)
nOrigin = (nOrigin & 858993459) + (nOrigin >> 2 & 858993459)
nOrigin = (nOrigin & 252645135) + (nOrigin >> 4 & 252645135)
nOrigin = nOrigin * 16843009 >> 24
return nOrigin
end
function PlayerMainlineDataEx:GetAfterBattleAvg()
if not self.bUseOldMainline then
return false
end
local sAvgId = ConfigTable.GetData_Mainline(self._nSelectId).AfterAvgId
if sAvgId == "" then
return false
end
return sAvgId
end
function PlayerMainlineDataEx:GetCurChapter()
if self._nSelectId == 0 then
local curChapter = 1
local forEachChapter = function(mapData)
if self:IsMainlineChapterUnlock(mapData.Id) and curChapter < mapData.Id then
curChapter = mapData.Id
end
end
ForEachTableLine(DataTable.Chapter, forEachChapter)
return curChapter
else
local mapMainline = ConfigTable.GetData_Mainline(self._nSelectId)
if mapMainline == nil then
return 1
end
return mapMainline.ChapterId
end
end
function PlayerMainlineDataEx:GetChapterCount()
local count = 0
if self.bUseOldMainline then
local forEachChapter = function(mapData)
count = count + 1
end
ForEachTableLine(DataTable.Chapter, forEachChapter)
else
local forEachChapter = function(mapData)
count = count + 1
end
ForEachTableLine(DataTable.StoryChapter, forEachChapter)
end
return count
end
function PlayerMainlineDataEx:GetSelectId()
return self._nSelectId
end
function PlayerMainlineDataEx:GetCurLevelChar()
if self._mainlineLevel ~= nil and self._mainlineLevel.tbChar ~= nil then
return self._mainlineLevel.tbChar
end
return {}
end
function PlayerMainlineDataEx:EnterTest(nMainlineId, nTeamId)
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空2")
return
end
if type(ConfigTable.GetData_Mainline(nMainlineId).AvgId) == "string" and ConfigTable.GetData_Mainline(nMainlineId).AvgId ~= "" then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("MainlineData_Avg")
})
return
end
local tbCharId = PlayerData.Team:GetTeamCharId(nTeamId)
self._nSelectId = nMainlineId
PlayerData.nCurGameType = AllEnum.WorldMapNodeType.Mainline
if #tbCharId == 0 then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("MainlineData_FormationError")
})
return
end
local luaClass = require("Game.Editor.MainlineLevel.MainlineEditor")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.Init) == "function" then
self._mainlineLevel:Init(self, nMainlineId, nTeamId, {}, {})
end
end
function PlayerMainlineDataEx:EnterMainlineEditor(nMainlineId, tbTeamCharId, tbTalentSkillAI, tbDisc, tbNote, tbSkinId)
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.MainlineLevel.MainlineEditor")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.InitBootConfig) == "function" then
self._mainlineLevel:InitBootConfig(self, nMainlineId, tbTeamCharId, {}, {}, tbTalentSkillAI, tbDisc, tbNote, tbSkinId)
end
end
function PlayerMainlineDataEx:EnterPreviewEditor(nLevelType, nLevelId, bView, nStarTowerFloorSetId, nPrefabID, nPrefabExtension, nPlayType, nSceneMir)
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.MainlineLevel.PreviewLevel")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.Init) == "function" then
self._mainlineLevel:Init(nLevelType, nLevelId, bView, nStarTowerFloorSetId, nPrefabID, nPrefabExtension, nPlayType, nSceneMir, self)
end
end
function PlayerMainlineDataEx:EnterTestBattleComboClipEditor(nMainlineId, tbTeamCharId, tbTalentSkillAI, tbDisc, tbNote, tbSkinId)
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.MainlineLevel.BattleTestComboClipEditor")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.InitBootConfig) == "function" then
self._mainlineLevel:InitBootConfig(self, nMainlineId, tbTeamCharId, {}, {}, tbTalentSkillAI, tbDisc, tbNote, tbSkinId)
end
end
function PlayerMainlineDataEx:LevelEnd()
PlayerData.Char:DeleteTrialChar()
if type(self._mainlineLevel.UnBindEvent) == "function" then
self._mainlineLevel:UnBindEvent()
end
self._mainlineLevel = nil
end
function PlayerMainlineDataEx:UpdateMainlineStar(nMainlineId, nStar)
local mapMainline = ConfigTable.GetData_Mainline(nMainlineId)
local nChapter = mapMainline.ChapterId
if self._mapStar[nChapter] == nil then
self._mapStar[nChapter] = {}
end
local sumStar = self.CalStar(nStar)
local b1 = 1
local b2 = 2
local b3 = 4
local t1 = 0 < nStar & b1
local t2 = 0 < nStar & b2
local t3 = 0 < nStar & b3
local tbTarget = {
t1,
t2,
t3
}
if 0 < sumStar and (self._mapStar[nChapter][nMainlineId] == nil or self._mapStar[nChapter][nMainlineId].nStar == 0) then
PlayerData.Base:CheckNewFuncUnlockMainlinePass(nMainlineId)
end
self._mapStar[nChapter][nMainlineId] = {nStar = sumStar, tbTarget = tbTarget}
self:UpdateRewardRedDot()
end
function PlayerMainlineDataEx:UpdateMainlineChapterReward(chapterId, nIdx)
self._mapChapters[chapterId] = nIdx
self:UpdateRewardRedDot()
end
function PlayerMainlineDataEx:OnEvent_EnterMainline(nTeamId)
local mapMainline = ConfigTable.GetData_Mainline(self._nSelectId)
if mapMainline == nil then
return
end
local nStar = 0
if self._mapStar[mapMainline.ChapterId] ~= nil and self._mapStar[mapMainline.ChapterId][self._nSelectId] ~= nil then
nStar = self._mapStar[mapMainline.ChapterId][self._nSelectId].nStar
end
if (nStar == nil or nStar == 0 or mapMainline.Energy < 1) and PlayerData.Base:CheckEnergyEnough(self._nSelectId) == false then
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("MainlineData_Energy")
})
return
end
self:NetMsg_EnterMainline(self._nSelectId, nTeamId, nil)
end
function PlayerMainlineDataEx:NetMsg_GetMainlineAward(nChapterId, callback, rewardIdx)
local msgCallback = function(_, mapMsgData)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
self._mapChapters[nChapterId] = rewardIdx
if callback ~= nil then
callback(mapMsgData.Items, mapMsgData.Change)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.chapter_reward_receive_req, {Value = nChapterId}, nil, msgCallback)
end
function PlayerMainlineDataEx:NetMsg_EnterMainline(nMainlineId, nTeamIdx, callback)
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空3")
return
end
local msgCallback = function(_, mapMsgData)
if callback ~= nil then
callback(mapMsgData)
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
local mapMainline = ConfigTable.GetData_Mainline(nMainlineId)
if mapMainline == nil then
printError("主线数据不存在:" .. nMainlineId)
return
end
if mapMainline.AvgId ~= nil and mapMainline.AvgId ~= "" then
local luaClass = require("Game.Adventure.MainlineLevel.MainlineAvgLevel")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.Init) == "function" then
self._mainlineLevel:Init(self, nMainlineId)
end
else
local luaClass = require("Game.Adventure.MainlineLevel.MainlineBattleLevel")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.Init) == "function" then
self._mainlineLevel:Init(self, nMainlineId, nTeamIdx, mapMsgData.OpenMinChests, mapMsgData.OpenMaxChests)
end
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.mainline_apply_req, {ID = nMainlineId, FormationId = nTeamIdx}, nil, msgCallback)
end
function PlayerMainlineDataEx:NetMsg_UnlockMainline(nMainlineId, callback)
local msg = {Value = nMainlineId}
local msgCallback = function()
local mapMainline = ConfigTable.GetData_Mainline(nMainlineId)
if mapMainline ~= nil then
if self._mapStar[mapMainline.ChapterId] == nil then
self._mapStar[mapMainline.ChapterId] = {}
end
self._mapStar[mapMainline.ChapterId][nMainlineId] = {}
self._mapStar[mapMainline.ChapterId][nMainlineId].nStar = 0
self._mapStar[mapMainline.ChapterId][nMainlineId].tbTarget = {
false,
false,
false
}
else
printError("Mainline Data Missing:" .. nMainlineId)
end
if type(callback) == "function" then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.mainline_unlock_req, msg, nil, msgCallback)
end
function PlayerMainlineDataEx:EnterPrologue()
if self._mainlineLevel ~= nil then
printError("当前关卡level不为空3")
return
end
PlayerData.nCurGameType = AllEnum.WorldMapNodeType.Prologue
local luaClass = require("Game.Adventure.MainlineLevel.MainlinePrologueLevel")
if luaClass == nil then
return
end
self._mainlineLevel = luaClass
if type(self._mainlineLevel.Init) == "function" then
self._mainlineLevel:Init(self)
end
end
function PlayerMainlineDataEx:UpdateRewardRedDot()
for chapterId, v in pairs(self._mapStar) do
local allStar = 0
local canReceive = false
for id, data in pairs(v) do
local mapData = ConfigTable.GetData_Mainline(id)
if mapData.AvgId == "" then
allStar = allStar + data.nStar
end
end
local chapterCfg = ConfigTable.GetData("Chapter", chapterId)
if nil ~= chapterCfg then
local tbReward = decodeJson(chapterCfg.CompleteRewards)
local tbSortReward = {}
for star, reward in pairs(tbReward) do
table.insert(tbSortReward, {
nStar = tonumber(star)
})
end
table.sort(tbSortReward, function(a, b)
return a.nStar < b.nStar
end)
local receivedRewardIdx = self._mapChapters[chapterId] or 0
for idx, v in ipairs(tbSortReward) do
if allStar >= v.nStar and idx > receivedRewardIdx then
canReceive = true
break
end
end
end
RedDotManager.SetValid(RedDotDefine.Map_MainLine_Reward, chapterId, canReceive)
end
end
return PlayerMainlineDataEx
@@ -0,0 +1,822 @@
local PlayerMallData = class("PlayerMallData")
local TimerManager = require("GameCore.Timer.TimerManager")
local MessageBoxManager = require("GameCore.Module.MessageBoxManager")
local ClientManager = CS.ClientManager.Instance
local WwiseAudioMgr = CS.WwiseAudioManager.Instance
local SDKManager = CS.SDKManager.Instance
local DisplayMode = {
Hide = 0,
End = 1,
Stay = 2
}
local OrderStatus = {
Unpaid = "Unpaid",
Done = "Done",
Retry = "Retry",
Error = "Error"
}
function PlayerMallData:Init()
self._tbNextMallPackage = nil
self._tbNextMallShop = nil
self._tbOrderCollect = {}
self._mapOrderId = {}
self._nOrderIdPaying = nil
self._tbWaitingOrderCollect = nil
self._mapOrderReward = nil
self._mapOrderCollecting = nil
self._bWaitTimeOut = false
self._bRetry = false
self._bProcessingOrder = false
self._timerOrderCollect = nil
self._timerOrderWait = nil
self._tbPackagePage = {}
self._tbExchangeShop = {}
EventManager.Add("OnSdkPaySuc", PlayerMallData, self.OnEvent_PayRespone)
EventManager.Add("OnSdkPayFail", PlayerMallData, self.OnEvent_PayRespone)
self:ProcessExchangeShop()
self:ProcessPackagePage()
end
function PlayerMallData:UnInit()
self._tbNextMallPackage = nil
self._tbNextMallShop = nil
self._tbOrderCollect = nil
self._mapOrderId = nil
self._nOrderIdPaying = nil
self._tbWaitingOrderCollect = nil
self._mapOrderReward = nil
self._mapOrderCollecting = nil
self._bWaitTimeOut = false
self._bRetry = false
self._bProcessingOrder = false
self._timerOrderCollect = nil
self._timerOrderWait = nil
self._tbPackagePage = nil
self._tbExchangeShop = nil
EventManager.Remove("OnSdkPaySuc", PlayerMallData, self.OnEvent_PayRespone)
EventManager.Remove("OnSdkPayFail", PlayerMallData, self.OnEvent_PayRespone)
end
function PlayerMallData:GetExchangeShop()
return self._tbExchangeShop
end
function PlayerMallData:GetPackagePage(nType)
return self._tbPackagePage[nType] or {}
end
function PlayerMallData:CheckOrderProcess()
return self._bProcessingOrder
end
function PlayerMallData:BuyGem(sId, sStatistical)
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("purchase_click", tab)
local callback = function(mapData)
self._mapOrderId[mapData.ExtraData] = {
nOrderId = mapData.Id,
StatisticalGroup = sStatistical,
nType = AllEnum.RMBOrderType.Mall
}
EventManager.Hit(EventId.BlockInput, true)
self._nOrderIdPaying = mapData.Id
SDKManager:Pay(sId, mapData.NotifyUrl, mapData.ExtraData)
end
self:SendMallGemOrderReq(sId, callback)
end
function PlayerMallData:BuyPackage(sId, sStatistical)
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("purchase_click", tab)
local callback = function(mapData)
self._mapOrderId[mapData.ExtraData] = {
nOrderId = mapData.Id,
StatisticalGroup = sStatistical,
nType = AllEnum.RMBOrderType.Mall
}
EventManager.Hit(EventId.BlockInput, true)
self._nOrderIdPaying = mapData.Id
SDKManager:Pay(sId, mapData.NotifyUrl, mapData.ExtraData)
end
self:SendMallPackageOrderReq(sId, callback)
end
function PlayerMallData:BuyMonthlyCard(sId, sStatistical)
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("purchase_click", tab)
local callback = function(mapData)
self._mapOrderId[mapData.ExtraData] = {
nOrderId = mapData.Id,
StatisticalGroup = sStatistical,
nType = AllEnum.RMBOrderType.Mall
}
EventManager.Hit(EventId.BlockInput, true)
self._nOrderIdPaying = mapData.Id
SDKManager:Pay(sId, mapData.NotifyUrl, mapData.ExtraData)
end
self:SendMallMonthlyCardOrderReq(sId, callback)
end
function PlayerMallData:BuyBattlePass(nMode, nVersion, sId, sStatistical)
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("purchase_click", tab)
local callback = function(mapData)
self._mapOrderId[mapData.ExtraData] = {
nOrderId = mapData.Id,
StatisticalGroup = sStatistical,
nType = AllEnum.RMBOrderType.BattlePass
}
EventManager.Hit(EventId.BlockInput, true)
self._nOrderIdPaying = mapData.Id
SDKManager:Pay(sId, mapData.NotifyUrl, mapData.ExtraData)
end
self:SendBattlePassOrderReq(nMode, nVersion, callback)
end
function PlayerMallData:TestBuyBattlePass(nMode, nVersion)
local callback = function(mapData)
self:CollectEnqueue(mapData.Id, AllEnum.RMBOrderType.BattlePass)
self:ProcessOrder()
end
self:SendBattlePassOrderReq(nMode, nVersion, callback)
end
function PlayerMallData:TestBuyGemSuc(sId)
local callback = function(mapData)
self:CollectEnqueue(mapData.Id, AllEnum.RMBOrderType.Mall)
self:ProcessOrder()
end
self:SendMallGemOrderReq(sId, callback)
end
function PlayerMallData:TestBuyPackageSuc(sId)
local callback = function(mapData)
self:CollectEnqueue(mapData.Id, AllEnum.RMBOrderType.Mall)
self:ProcessOrder()
end
self:SendMallPackageOrderReq(sId, callback)
end
function PlayerMallData:TestBuyMonthlyCardSuc(sId)
local callback = function(mapData)
self:CollectEnqueue(mapData.Id, AllEnum.RMBOrderType.Mall)
self:ProcessOrder()
end
self:SendMallMonthlyCardOrderReq(sId, callback)
end
function PlayerMallData:ProcessExchangeShop()
self._tbExchangeShop = {}
local func_ForEach_ExchangeShop = function(mapData)
table.insert(self._tbExchangeShop, mapData)
end
ForEachTableLine(DataTable.MallShopPage, func_ForEach_ExchangeShop)
table.sort(self._tbExchangeShop, function(a, b)
return a.Sort < b.Sort
end)
end
function PlayerMallData:ParseShopList(tbList)
local tbShop = {}
for _, v in pairs(tbList) do
local mapCfg = ConfigTable.GetData("MallShop", v.Id)
if mapCfg then
local mapPage = ConfigTable.GetData("MallShopPage", mapCfg.GroupId)
if mapPage and (v.Stock > 0 or mapCfg.DisplayMode ~= DisplayMode.Hide) then
local nDeListTime = PlayerData.Shop:ChangeToTimeStamp(mapCfg.DeListTime)
local nNextRefreshTime, bPrioritizeDeList = self:CalNextTime(v.RefreshTime, nDeListTime)
local mapPackage = {
sId = v.Id,
nCurStock = v.Stock,
nPageSort = mapPage.Sort,
nSort = mapCfg.Sort,
nDisplayMode = mapCfg.DisplayMode,
bPrioritizeDeList = bPrioritizeDeList,
nNextRefreshTime = nNextRefreshTime
}
table.insert(tbShop, mapPackage)
end
end
end
local comp = function(a, b)
if (a.nCurStock == 0 and a.nDisplayMode == DisplayMode.End) ~= (b.nCurStock == 0 and b.nDisplayMode == DisplayMode.End) then
return (a.nCurStock ~= 0 or a.nDisplayMode ~= DisplayMode.End) and b.nCurStock == 0 and b.nDisplayMode == DisplayMode.End
elseif a.nPageSort ~= b.nPageSort then
return a.nPageSort < b.nPageSort
else
return a.nSort < b.nSort
end
end
table.sort(tbShop, comp)
return tbShop
end
function PlayerMallData:CalShopAutoTime(tbList)
local tbTime = {}
for _, mapData in pairs(tbList) do
if mapData.nNextRefreshTime > 0 then
table.insert(tbTime, mapData.nNextRefreshTime)
end
end
for _, mapData in pairs(self._tbNextMallShop or {}) do
table.insert(tbTime, mapData.nListTime)
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function PlayerMallData:UpdateNextMallShop()
local nServerTimeStamp = ClientManager.serverTimeStamp
if self._tbNextMallShop == nil then
self._tbNextMallShop = {}
local func_ForEach_Shop = function(mapCfgData)
local nListTime = PlayerData.Shop:ChangeToTimeStamp(mapCfgData.ListTime)
if 0 < nListTime and nListTime > nServerTimeStamp then
table.insert(self._tbNextMallShop, {
nId = mapCfgData.Id,
nListTime = nListTime
})
end
end
ForEachTableLine(DataTable.MallShop, func_ForEach_Shop)
else
local nCount = #self._tbNextMallShop
if 0 < nCount then
for i = nCount, -1 do
if nServerTimeStamp >= self._tbNextMallShop[i].nListTime then
table.remove(self._tbNextMallShop, i)
end
end
end
end
end
function PlayerMallData:ProcessPackagePage()
self._tbPackagePage = {}
local func_ForEach_PackagePage = function(mapData)
local nType = mapData.Type
if self._tbPackagePage[nType] == nil then
self._tbPackagePage[nType] = {}
end
table.insert(self._tbPackagePage[nType], mapData)
end
ForEachTableLine(DataTable.MallPackagePage, func_ForEach_PackagePage)
for _, v in pairs(self._tbPackagePage) do
table.sort(v, function(a, b)
return a.Sort < b.Sort
end)
end
end
function PlayerMallData:ParsePackageList(tbList)
local tbPackage = {}
for _, v in pairs(tbList) do
local mapCfg = ConfigTable.GetData("MallPackage", v.Id)
if mapCfg then
local mapPage = ConfigTable.GetData("MallPackagePage", mapCfg.GroupId)
if mapPage and (v.Stock > 0 or mapCfg.DisplayMode ~= DisplayMode.Hide) then
local nDeListTime = PlayerData.Shop:ChangeToTimeStamp(mapCfg.DeListTime)
local nNextRefreshTime, bPrioritizeDeList = self:CalNextTime(v.RefreshTime, nDeListTime)
local mapPackage = {
sId = v.Id,
nCurStock = v.Stock,
nPageSort = mapPage.Sort,
nSort = mapCfg.Sort,
nDisplayMode = mapCfg.DisplayMode,
bPrioritizeDeList = bPrioritizeDeList,
nNextRefreshTime = nNextRefreshTime
}
table.insert(tbPackage, mapPackage)
end
end
end
local comp = function(a, b)
if (a.nCurStock == 0 and a.nDisplayMode == DisplayMode.End) ~= (b.nCurStock == 0 and b.nDisplayMode == DisplayMode.End) then
return (a.nCurStock ~= 0 or a.nDisplayMode ~= DisplayMode.End) and b.nCurStock == 0 and b.nDisplayMode == DisplayMode.End
elseif a.nPageSort ~= b.nPageSort then
return a.nPageSort < b.nPageSort
else
return a.nSort < b.nSort
end
end
table.sort(tbPackage, comp)
return tbPackage
end
function PlayerMallData:CalNextTime(nReTime, nDeTime)
if 0 < nDeTime then
if 0 < nReTime then
if nDeTime < nReTime then
return nDeTime, true
else
return nReTime, false
end
else
return nDeTime, true
end
else
return nReTime, false
end
end
function PlayerMallData:CalPackageAutoTime(tbPackageList)
local tbTime = {}
for _, mapData in pairs(tbPackageList) do
if mapData.nNextRefreshTime > 0 then
table.insert(tbTime, mapData.nNextRefreshTime)
end
end
for _, mapData in pairs(self._tbNextMallPackage) do
table.insert(tbTime, mapData.nListTime)
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function PlayerMallData:UpdateNextMallPackage()
local nServerTimeStamp = ClientManager.serverTimeStamp
if self._tbNextMallPackage == nil then
self._tbNextMallPackage = {}
local func_ForEach_Package = function(mapCfgData)
local nListTime = PlayerData.Shop:ChangeToTimeStamp(mapCfgData.ListTime)
if 0 < nListTime and nListTime > nServerTimeStamp then
table.insert(self._tbNextMallPackage, {
nId = mapCfgData.Id,
nListTime = nListTime
})
end
end
ForEachTableLine(DataTable.MallPackage, func_ForEach_Package)
else
local nCount = #self._tbNextMallPackage
if 0 < nCount then
for i = nCount, -1 do
if nServerTimeStamp >= self._tbNextMallPackage[i].nListTime then
table.remove(self._tbNextMallPackage, i)
end
end
end
end
end
function PlayerMallData:OnEvent_SdkPaySuc(nCode, sMsg, nOrderId, sExData)
local mapOrder = self._mapOrderId[sExData]
if mapOrder == nil then
printError("OrderId not found:" .. sExData)
return
end
local nCacheOrderId = self._mapOrderId[sExData].nOrderId
local nOrderType = self._mapOrderId[sExData].nType
local sStatistical = self._mapOrderId[sExData].StatisticalGroup
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
if sStatistical ~= nil then
if sStatistical == "pack.first" then
NovaAPI.UserEventUpload("purchase_starterpack", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_first_160")
elseif sStatistical == "pack.sr" then
NovaAPI.UserEventUpload("purchase_srtrekkerselect", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_sr_680")
elseif sStatistical == "pack.role" then
NovaAPI.UserEventUpload("purchase_newtrekkerpack", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_role_1480")
elseif sStatistical == "pack.disc" then
NovaAPI.UserEventUpload("purchase_newdiscpack", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_disc_1480")
elseif sStatistical == "pack.role_common" then
NovaAPI.UserEventUpload("purchase_newtrekkerstandard", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_role_common_1280")
elseif sStatistical == "monthlyCard.small" then
NovaAPI.UserEventUpload("purchase_monthlycard", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_monthlyCard_small_650")
elseif sStatistical == "pack_role_m" then
NovaAPI.UserEventUpload("purchase_monthtrekkervoucher", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_01_role_m_2600")
elseif sStatistical == "pack_disc_m" then
NovaAPI.UserEventUpload("purchase_monthdiscvoucher", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_01_disc_m_2600")
elseif sStatistical == "pack_role_w" then
NovaAPI.UserEventUpload("purchase_weektrekkerres", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_01_role_w_860")
elseif sStatistical == "pack_disc_w" then
NovaAPI.UserEventUpload("purchase_weekdiscres", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_pack_01_disc_w_860")
elseif sStatistical == "pack_role" then
NovaAPI.UserEventUpload("purchase_trekkercelebration", tab)
elseif sStatistical == "pack_gift" then
NovaAPI.UserEventUpload("purchase_trekkerdessert", tab)
elseif sStatistical == "pack_disc" then
NovaAPI.UserEventUpload("purchase_discmusic", tab)
elseif sStatistical == "pack_res" then
NovaAPI.UserEventUpload("purchase_trekkerupgrade", tab)
elseif sStatistical == "pack.op_role" then
NovaAPI.UserEventUpload("purchase_launchtrekker", tab)
elseif sStatistical == "pack.op_disc" then
NovaAPI.UserEventUpload("purchase_launchdisc", tab)
elseif string.find(sStatistical, "gem") ~= nil then
NovaAPI.UserEventUpload("purchase_diamond", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_" .. sStatistical)
elseif sStatistical == "BattlePassPremium" then
NovaAPI.UserEventUpload("purchase_standardbp", tab)
PlayerData.Base:UserEventUpload_PC("pc_purchase_battlepass_68_1280")
elseif sStatistical == "BattlePassOrigin_Luxury" or sStatistical == "BattlePassOrigin_Complement" then
NovaAPI.UserEventUpload("purchase_deluxebp", tab)
local tmpEvent = sStatistical == "BattlePassOrigin_Luxury" and "pc_purchase_battlepass_98_1980" or "pc_purchase_battlepass_38_980"
PlayerData.Base:UserEventUpload_PC(tmpEvent)
elseif sStatistical == "skin_3d" then
NovaAPI.UserEventUpload("purchase_skin", tab)
end
end
self._mapOrderId[sExData] = nil
self:CollectEnqueue(nCacheOrderId, nOrderType)
self:ProcessOrder()
end
function PlayerMallData:OnEvent_SdkPayFail(nCode, sMsg, nOrderId, sExData, nOrderIdPaying)
printError("SdkPayFail Msg:" .. sMsg)
printError("SdkPayFail nCode:" .. nCode)
local mapOrder = self._mapOrderId[sExData]
if mapOrder == nil then
printError("OrderId not found:" .. sExData)
if sExData == "" and nOrderIdPaying and nOrderIdPaying ~= "" and nOrderIdPaying ~= 0 then
for k, v in pairs(self._mapOrderId) do
if v.nOrderId == nOrderIdPaying then
self._mapOrderId[k] = nil
break
end
end
self:SendMallOrderCancelReq(nOrderIdPaying, nCode)
end
return
end
local nCacheOrderId = self._mapOrderId[sExData].nOrderId
self._mapOrderId[sExData] = nil
self:SendMallOrderCancelReq(nCacheOrderId, nCode)
end
function PlayerMallData:OnEvent_PayRespone(nCode, sMsg, nOrderId, sExData)
EventManager.Hit(EventId.BlockInput, false)
printLog("收到SDK PayRespone")
local nOrderIdPaying = self._nOrderIdPaying
self._nOrderIdPaying = nil
if nCode == 200180 or nCode == 0 or nCode == 201180 then
self:OnEvent_SdkPaySuc(nCode, sMsg, nOrderId, sExData)
else
self:OnEvent_SdkPayFail(nCode, sMsg, nOrderId, sExData, nOrderIdPaying)
end
end
function PlayerMallData:OpenOrderWait()
if MessageBoxManager.CheckOrderWaitOpen() then
return
end
EventManager.Hit("OpenOrderWait")
self._timerOrderWait = TimerManager.Add(1, 30, self, function()
self._bWaitTimeOut = true
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Mall_OrderRetry"),
bDisableSnap = true
})
self:CloseOrderWait()
end, true, true, false)
end
function PlayerMallData:CloseOrderWait()
if self._timerOrderWait ~= nil then
self._timerOrderWait:Cancel(false)
self._timerOrderWait = nil
end
if MessageBoxManager.CheckOrderWaitOpen() then
EventManager.Hit("CloseOrderWait")
end
end
function PlayerMallData:ProcessOrder(bRetry)
if self._bProcessingOrder then
return
end
self._bProcessingOrder = true
self._bRetry = bRetry == true
if not self._bRetry then
self:OpenOrderWait()
end
self._tbWaitingOrderCollect = {}
self._mapOrderReward = {
tbReward = {},
tbSpReward = {},
tbSrc = {},
tbDst = {}
}
self:CollectDequeue()
end
function PlayerMallData:SetReCollectTimer()
if self._timerOrderCollect ~= nil then
self._timerOrderCollect:Cancel(false)
self._timerOrderCollect = nil
end
if #self._tbOrderCollect > 0 then
self._timerOrderCollect = TimerManager.Add(1, 2, self, function()
self:ProcessOrder(true)
end, true, true, false)
end
end
function PlayerMallData:CollectDequeue()
local mapOrder = self._tbOrderCollect[1]
table.remove(self._tbOrderCollect, 1)
printLog("当前处理订单:" .. mapOrder.nOrderId)
if next(self._tbOrderCollect) ~= nil then
printLog("----预备订单----")
for _, v in ipairs(self._tbOrderCollect) do
printLog("订单:" .. v.nOrderId .. " 等待处理")
end
printLog("---------------")
else
printLog("后续无待处理订单")
end
self._mapOrderCollecting = mapOrder
if mapOrder.nType == AllEnum.RMBOrderType.Mall then
local callback = function(mapData)
self._mapOrderCollecting = nil
local tbSpReward = PlayerData.CharSkin:GetSkinForReward()
self:CollectOrder(mapOrder, mapData, tbSpReward)
end
self:SendMallOrderCollectReq(mapOrder.nOrderId, callback)
elseif mapOrder.nType == AllEnum.RMBOrderType.BattlePass then
local callback = function(mapData)
self._mapOrderCollecting = nil
local tbSpReward = PlayerData.CharSkin:GetSkinForReward()
if mapData.CollectResp then
PlayerData.BattlePass:OnPremiumBuySuccess(mapData)
self:CollectOrder(mapOrder, mapData.CollectResp, tbSpReward)
else
self:CollectOrder(mapOrder, mapData, tbSpReward)
end
end
self:SendBattlePassOrderCollectReq(mapOrder.nOrderId, callback)
end
end
function PlayerMallData:CollectOrder(mapOrder, mapData, tbSpReward)
printLog("订单:" .. mapOrder.nOrderId .. " 奖励状态:" .. mapData.Status)
if mapData.Items and next(mapData.Items) ~= nil then
local mapReward = PlayerData.Item:ProcessRewardChangeInfo(mapData.Items)
for _, v in pairs(mapReward.tbReward) do
table.insert(self._mapOrderReward.tbReward, v)
end
for _, v in pairs(mapReward.tbSpReward) do
table.insert(self._mapOrderReward.tbSpReward, v)
end
for _, v in pairs(mapReward.tbSrc) do
table.insert(self._mapOrderReward.tbSrc, v)
end
for _, v in pairs(mapReward.tbDst) do
table.insert(self._mapOrderReward.tbDst, v)
end
end
if tbSpReward and next(tbSpReward) ~= nil then
for _, v in pairs(tbSpReward) do
table.insert(self._mapOrderReward.tbSpReward, v)
end
end
if mapData.Status == OrderStatus.Unpaid or mapData.Status == OrderStatus.Retry then
local bHasWait = false
for _, v in pairs(self._tbWaitingOrderCollect) do
if v.nOrderId == mapOrder.nOrderId then
bHasWait = true
printError("订单:" .. mapOrder.nOrderId .. " 重复进入等待列表")
break
end
end
if not bHasWait then
table.insert(self._tbWaitingOrderCollect, mapOrder)
end
end
if mapData.Status == OrderStatus.Done then
local tab_1 = {}
table.insert(tab_1, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("confirm_order", tab_1)
local tab = {}
table.insert(tab, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
NovaAPI.UserEventUpload("purchase_complete", tab)
end
if not self._tbOrderCollect or #self._tbOrderCollect == 0 then
self:CollectEnd(mapData.Status ~= OrderStatus.Done)
else
self:CollectDequeue()
end
end
function PlayerMallData:CollectEnd(bError)
local funcClear = function()
self._bProcessingOrder = false
self._tbOrderCollect = {}
if self._bWaitTimeOut then
self._bWaitTimeOut = false
for _, mapOrder in pairs(self._tbWaitingOrderCollect) do
printError("订单:" .. mapOrder.nOrderId .. " 超时订单,需要联系客服,不再请求")
end
else
printLog("----需重新请求的订单----")
for _, mapOrder in pairs(self._tbWaitingOrderCollect) do
table.insert(self._tbOrderCollect, mapOrder)
printLog("订单:" .. mapOrder.nOrderId .. " 未成功,重新进入订单列表")
end
printLog("---------------")
end
self._tbWaitingOrderCollect = {}
if next(self._tbOrderCollect) == nil then
local bMoney = true
EventManager.Hit("MallOrderClear", bMoney)
end
self:SetReCollectTimer()
end
if not bError then
self:CloseOrderWait()
end
if PanelManager.CheckPanelOpen(PanelId.ReceiveAutoTrans) == true or PanelManager.CheckPanelOpen(PanelId.ReceivePropsTips) == true or PanelManager.CheckPanelOpen(PanelId.ReceiveSpecialReward) == true or PanelManager.CheckNextPanelOpening() then
funcClear()
else
local sTip
if self._bRetry and self._bWaitTimeOut then
sTip = ConfigTable.GetUIText("Mall_OrderDelayed")
end
UTILS.OpenReceiveByReward(self._mapOrderReward, funcClear, sTip)
end
end
function PlayerMallData:CollectEnqueue(nOrderId, nType)
if not self._tbOrderCollect then
self._tbOrderCollect = {}
end
table.insert(self._tbOrderCollect, {nOrderId = nOrderId, nType = nType})
end
function PlayerMallData:SendBattlePassOrderReq(nMode, nVersion, callback)
local mapMsg = {Mode = nMode, Version = nVersion}
local successCallback = function(_, mapData)
printLog("创建订单:" .. mapData.Id)
callback(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_order_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendMallGemListReq(callback)
local successCallback = function(_, mapData)
callback(mapData.List)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_gem_list_req, {}, nil, successCallback)
end
function PlayerMallData:SendMallGemOrderReq(sId, callback)
if type(sId) == "number" then
sId = tostring(sId)
end
local mapMsg = {Value = sId}
local successCallback = function(_, mapData)
printLog("创建订单:" .. mapData.Id)
callback(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_gem_order_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendMallOrderCancelReq(nId, nCode, callback)
local tbCancelCode = {
200154,
200230,
200340,
200500,
200600,
201236,
101606,
101731,
201230,
201221,
201223,
201224
}
if table.indexof(tbCancelCode, nCode) == 0 then
local bMoney = true
EventManager.Hit("MallOrderClear", bMoney)
return
end
printLog("订单取消")
EventManager.Hit(EventId.OpenMessageBox, {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Mall_OrderCancel")
})
local bMoney = true
EventManager.Hit("MallOrderClear", bMoney)
end
function PlayerMallData:SendMallOrderCollectReq(nId, callback)
if type(nId) == "number" then
nId = tostring(nId)
end
local mapMsg = {Value = nId}
local successCallback = function(_, mapData)
callback(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_order_collect_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendBattlePassOrderCollectReq(nId, callback)
if type(nId) == "number" then
nId = tostring(nId)
end
local mapMsg = {Value = nId}
local successCallback = function(_, mapData)
callback(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_order_collect_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendMallMonthlyCardListReq(callback)
local successCallback = function(_, mapData)
callback(mapData.List[1])
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_monthlyCard_list_req, {}, nil, successCallback)
end
function PlayerMallData:SendMallMonthlyCardOrderReq(sId, callback)
local mapMsg = {Value = sId}
local successCallback = function(_, mapData)
printLog("创建订单:" .. mapData.Id)
callback(mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_monthlyCard_order_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendMallPackageListReq(callback)
local successCallback = function(_, mapData)
self:UpdateNextMallPackage()
local tbPackageList = self:ParsePackageList(mapData.List)
local nAutoTime = self:CalPackageAutoTime(tbPackageList)
callback(tbPackageList, nAutoTime)
self:UpdateMallRedDot(tbPackageList)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_package_list_req, {}, nil, successCallback)
end
function PlayerMallData:SendMallPackageOrderReq(sId, callback)
local mapMsg = {Value = sId}
local successCallback = function(_, mapData)
if mapData.Order then
printLog("创建订单:" .. mapData.Order.Id)
callback(mapData.Order)
else
UTILS.OpenReceiveByChangeInfo(mapData.Change)
local bMoney = false
EventManager.Hit("MallOrderClear", bMoney)
WwiseAudioMgr:SetState("system", "shop_purchased")
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_package_order_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendMallShopListReq(callback)
local successCallback = function(_, mapData)
self:UpdateNextMallShop()
local tbList = self:ParseShopList(mapData.List)
local nAutoTime = self:CalShopAutoTime(tbList)
callback(tbList, nAutoTime)
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_shop_list_req, {}, nil, successCallback)
end
function PlayerMallData:SendMallShopOrderReq(sId, nCount)
local mapMsg = {Id = sId, Qty = nCount}
local successCallback = function(_, mapData)
UTILS.OpenReceiveByChangeInfo(mapData)
local bMoney = false
EventManager.Hit("MallOrderClear", bMoney)
WwiseAudioMgr:SetState("system", "shop_purchased")
end
HttpNetHandler.SendMsg(NetMsgId.Id.mall_shop_order_req, mapMsg, nil, successCallback)
end
function PlayerMallData:SendCharFragmentConvertReq(callBack)
local mapMsg = {}
HttpNetHandler.SendMsg(NetMsgId.Id.fragments_convert_req, mapMsg, nil, callBack)
end
function PlayerMallData:ProcessOrderPaidNotify(mapData)
if self._mapOrderCollecting and self._mapOrderCollecting.nOrderId == mapData.OrderId then
return
end
local nType = AllEnum.RMBOrderType.Mall
if mapData.Store == 3 then
nType = AllEnum.RMBOrderType.BattlePass
end
self:CollectEnqueue(mapData.OrderId, nType)
self:ProcessOrder()
end
function PlayerMallData:UpdateMallRedDot(tbPackageList)
local bCheck = false
for _, mallData in ipairs(tbPackageList) do
local mapCfg = ConfigTable.GetData("MallPackage", mallData.sId)
if nil ~= mapCfg and mapCfg.CurrencyType == GameEnum.currencyType.Free then
local tbCond = decodeJson(mapCfg.OrderCondParams)
local bPurchaseAble = PlayerData.Shop:CheckShopCond(mapCfg.OrderCondType, tbCond)
if mallData.nCurStock > 0 and bPurchaseAble then
bCheck = true
RedDotManager.SetValid(RedDotDefine.FreePackage, {
mallData.sId
}, true)
else
RedDotManager.SetValid(RedDotDefine.FreePackage, {
mallData.sId
}, false)
end
end
end
RedDotManager.SetValid(RedDotDefine.Mall_Free, nil, bCheck)
end
return PlayerMallData
@@ -0,0 +1,706 @@
local PlayerPhoneData = class("PlayerPhoneData")
local ModuleManager = require("GameCore.Module.ModuleManager")
local LocalData = require("GameCore.Data.LocalData")
function PlayerPhoneData:Init()
self.tbAddressBook = {}
self.tbChatMsgCache = {}
self.tbPhoneMsgChoiceTarget = {}
self.tbPhoneMsgGroupData = {}
self.tbHistoryMsg = {}
self.tbHistorySelection = {}
self.tbNewChatList = {}
self.bInitChatData = false
self:InitCfg()
EventManager.Add(EventId.AfterEnterMain, self, self.OnEvent_AfterEnterMain)
end
function PlayerPhoneData:InitCfg()
local foreachPlot = function(mapData)
if mapData.ConnectChatId ~= 0 then
local tbData = {}
tbData.sAvgId = mapData.AvgId
tbData.nCharId = mapData.Char
tbData.nPlotId = mapData.Id
CacheTable.SetData("_PlotChat", mapData.ConnectChatId, tbData)
end
end
ForEachTableLine(DataTable.Plot, foreachPlot)
end
function PlayerPhoneData:CachePhoneMsgCount(msgNetData)
if nil ~= msgNetData then
RedDotManager.SetValid(RedDotDefine.Phone_New, nil, msgNetData.NewMessage > 0)
local bNewValue = RedDotManager.GetValid(RedDotDefine.Phone)
RedDotManager.SetValid(RedDotDefine.Phone_UnComplete, nil, not bNewValue and 0 < msgNetData.ProgressMessage)
end
end
function PlayerPhoneData:GetChatState(chatData)
if chatData.nProcess == 0 then
return AllEnum.PhoneChatState.New
elseif chatData.nProcess < chatData.nAllProcess then
return AllEnum.PhoneChatState.UnComplete
elseif chatData.nProcess >= chatData.nAllProcess then
return AllEnum.PhoneChatState.Complete
end
end
function PlayerPhoneData:CreateNewChat(mapMsgData)
local chatData = {}
chatData.nChatId = mapMsgData.Id
chatData.nProcess = mapMsgData.Process
chatData.tbSelection = mapMsgData.Options
local chatAvgMsg = self:GetAVGPhoneMsg(chatData.nChatId)
if nil == chatAvgMsg then
return
end
chatData.avgMsg = chatAvgMsg
chatData.nAllProcess = #chatAvgMsg
chatData.nStatus = self:GetChatState(chatData)
if chatData.nProcess > 0 then
self:ParseAvgHistoryPhoneMsgData(chatData.nChatId, chatData.avgMsg, chatData.nProcess, chatData.tbSelection)
end
return chatData
end
function PlayerPhoneData:RefreshAddressStatus(nAddressId)
local addressData = self.tbAddressBook[nAddressId]
if nil ~= addressData then
local bNew = false
local bUnComplete = false
for _, chat in pairs(addressData.tbChatList) do
if chat.nStatus == AllEnum.PhoneChatState.UnComplete then
bUnComplete = true
break
elseif chat.nStatus == AllEnum.PhoneChatState.New then
bNew = true
end
end
if bUnComplete then
addressData.nStatus = AllEnum.PhoneChatState.UnComplete
elseif bNew then
addressData.nStatus = AllEnum.PhoneChatState.New
else
addressData.nStatus = AllEnum.PhoneChatState.Complete
end
end
end
function PlayerPhoneData:CacheAddressBookData(msgNetData)
self.bInitChatData = true
for _, v in ipairs(msgNetData) do
local mapChar = ConfigTable.GetData_Character(v.CharId)
if mapChar ~= nil and mapChar.Visible then
if nil == self.tbAddressBook[v.CharId] then
self.tbAddressBook[v.CharId] = {}
end
local tbChatList = {}
for _, chat in ipairs(v.Chats) do
local chatData = self:CreateNewChat(chat)
if nil ~= chatData then
tbChatList[chat.Id] = chatData
end
end
self.tbAddressBook[v.CharId].tbChatList = tbChatList
self.tbAddressBook[v.CharId].nTime = v.TriggerTime
self.tbAddressBook[v.CharId].bTop = v.Top
self.tbAddressBook[v.CharId].nOptTime = 0
if v.nOptTime ~= nil then
self.tbAddressBook[v.CharId].nOptTime = v.nOptTime
end
self:RefreshAddressStatus(v.CharId)
end
end
self:RefreshRedDot()
end
function PlayerPhoneData:RefreshChatProcess(nAddressId, nChatId, nProcess, tbSelection)
local addressData = self.tbAddressBook[nAddressId]
if nil ~= addressData then
local tbChatList = addressData.tbChatList
if nil ~= tbChatList[nChatId] then
local chatData = tbChatList[nChatId]
local lastProcess = chatData.nProcess
chatData.nProcess = nProcess
if nil ~= tbSelection then
chatData.tbSelection = tbSelection
local data = chatData.avgMsg[lastProcess]
if data ~= nil and data.cmd == "SetPhoneMsgChoiceBegin" then
local nGroupId = tonumber(data.param[1]) or 0
if nGroupId == #tbSelection then
if self.tbHistorySelection[nChatId] == nil then
self.tbHistorySelection[nChatId] = {}
else
for k, v in pairs(self.tbHistorySelection[nChatId]) do
if v.groupID == data.param[1] then
table.remove(self.tbHistorySelection[nChatId], k)
break
end
end
end
local dataSelection = {
groupID = data.param[1],
choiceIndex = tostring(tbSelection[#tbSelection])
}
table.insert(self.tbHistorySelection[nChatId], dataSelection)
end
end
end
chatData.nStatus = self:GetChatState(chatData)
self:UpdateHistoryPhoneMsgData(nChatId, chatData.avgMsg[nProcess], nProcess)
end
self:RefreshAddressStatus(nAddressId)
end
self:RefreshRedDot()
end
function PlayerPhoneData:NewChatTrigger(mapMsgData)
local nChatId = mapMsgData.Value
local tbData = {
Id = nChatId,
Options = {},
Process = 0
}
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if nil ~= chatCfg then
local nAddressId = chatCfg.AddressBookId
local mapChar = ConfigTable.GetData_Character(nAddressId)
if mapChar ~= nil and mapChar.Visible then
if nil == self.tbAddressBook[nAddressId] then
self.tbAddressBook[nAddressId] = {}
self.tbAddressBook[nAddressId].tbChatList = {}
end
local chatData = self:CreateNewChat(tbData)
if nil ~= chatData then
self.tbAddressBook[nAddressId].tbChatList[nChatId] = chatData
end
self.tbAddressBook[nAddressId].nTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
self:RefreshAddressStatus(nAddressId)
self:RefreshRedDot()
local sCurModule = ModuleManager.GetCurModuleName()
local bInGacha = PanelManager.CheckPanelOpen(PanelId.GachaSpin)
local bPhoneOpen = PanelManager.CheckPanelOpen(PanelId.Phone)
local bAffinityPanelOpen = PanelManager.CheckPanelOpen(PanelId.CharBgPanel)
if bAffinityPanelOpen or bPhoneOpen or sCurModule ~= "MainMenuModuleScene" or bInGacha then
local tbData = {
nAddressId = nAddressId,
nChatId = nChatId,
nSortId = chatCfg.Priority
}
table.insert(self.tbNewChatList, tbData)
elseif chatCfg.AutoPopUp then
EventManager.Hit(EventId.OpenPanel, PanelId.PhonePopUp, nChatId)
end
end
end
end
function PlayerPhoneData:PhoneContactReportSuc(mapMsgData)
if nil ~= mapMsgData and nil ~= mapMsgData then
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
end
EventManager.Hit("RecordChatProcessSuccess", mapMsgData)
end
function PlayerPhoneData:GetAddressBookList()
local tbSortList = {}
for addressId, v in pairs(self.tbAddressBook) do
local tbChatList = {}
for _, chat in pairs(v.tbChatList) do
table.insert(tbChatList, chat)
end
if 0 < #tbChatList then
table.sort(tbChatList, function(a, b)
local lastChat = LocalData.GetPlayerLocalData("LastPhoneChatId" .. addressId)
if a.nChatId == lastChat and a.nStatus == AllEnum.PhoneChatState.UnComplete then
return true
elseif b.nChatId == lastChat and b.nStatus == AllEnum.PhoneChatState.UnComplete then
return false
end
if a.nStatus == b.nStatus then
return a.nChatId > b.nChatId
end
return a.nStatus > b.nStatus
end)
local tbData = {
nAddressId = addressId,
tbChatList = tbChatList,
nTime = v.nTime,
nStatus = v.nStatus,
bTop = v.bTop,
nOptTime = v.nOptTime
}
table.insert(tbSortList, tbData)
end
end
table.sort(tbSortList, function(a, b)
if a.bTop and b.bTop then
return a.nOptTime > b.nOptTime
elseif not a.bTop and not b.bTop then
if a.nStatus == b.nStatus then
if a.nTime == b.nTime then
return a.nAddressId < b.nAddressId
end
return a.nTime > b.nTime
end
return a.nStatus > b.nStatus
end
return a.bTop
end)
return tbSortList
end
function PlayerPhoneData:GetAddressBookData(nAddressId)
if nil ~= self.tbAddressBook[nAddressId] then
local addressData = self.tbAddressBook[nAddressId]
return {
nAddressId = nAddressId,
tbChatList = addressData.tbChatList,
nTime = addressData.nTime,
nStatus = addressData.nStatus,
bTop = addressData.bTop
}
end
end
function PlayerPhoneData:GetChatHistoryList(nAddressId)
local tbSortChatList = {}
if nil ~= self.tbAddressBook[nAddressId] then
local tbChatList = self.tbAddressBook[nAddressId].tbChatList
for _, v in pairs(tbChatList) do
table.insert(tbSortChatList, v)
end
table.sort(tbSortChatList, function(a, b)
if a.nStatus == b.nStatus then
return a.nChatId > b.nChatId
end
return a.nStatus < b.nStatus
end)
else
printError(string.format("获取聊天信息失败!!!addressId = [%s]", nAddressId))
end
return tbSortChatList
end
function PlayerPhoneData:GetChatData(nAddressId, nChatId)
if nil ~= self.tbAddressBook[nAddressId] then
local tbChatList = self.tbAddressBook[nAddressId].tbChatList
if nil ~= tbChatList[nChatId] then
return tbChatList[nChatId]
end
end
traceback(string.format("获取聊天信息失败!!!addressId = [%s], chatId = [%s]", nAddressId, nChatId))
end
function PlayerPhoneData:RefreshRedDot()
RedDotManager.SetValid(RedDotDefine.Phone_New, nil, false)
RedDotManager.SetValid(RedDotDefine.Phone_UnComplete, nil, false)
local bUnComplete = false
for addressId, v in pairs(self.tbAddressBook) do
RedDotManager.SetValid(RedDotDefine.Phone_New_Item, addressId, v.nStatus == AllEnum.PhoneChatState.New)
bUnComplete = bUnComplete or v.nStatus == AllEnum.PhoneChatState.UnComplete
RedDotManager.SetValid(RedDotDefine.Phone_UnComplete_Item, addressId, v.nStatus == AllEnum.PhoneChatState.UnComplete)
end
local bNew = RedDotManager.GetValid(RedDotDefine.Phone)
RedDotManager.SetValid(RedDotDefine.Phone_UnComplete, nil, not bNew and bUnComplete)
end
function PlayerPhoneData:TrySendAddressListReq(callback)
if not self.bInitChatData then
self:SendAddressListReq(callback)
elseif nil ~= callback then
callback()
end
end
function PlayerPhoneData:OpenPhonePanel(openCall, nTog)
local callback = function()
local bChat = false
for _, v in pairs(self.tbAddressBook) do
for _, chat in pairs(v.tbChatList) do
bChat = true
break
end
end
if not bChat then
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("Phone_Chat_Empty"))
else
if nil ~= openCall then
openCall()
end
EventManager.Hit(EventId.OpenPanel, PanelId.Phone, nTog)
end
end
self:TrySendAddressListReq(callback)
end
function PlayerPhoneData:CheckHasNewChat()
return #self.tbNewChatList > 0
end
function PlayerPhoneData:CheckNewChat(nAddressId, callback)
local bNewChat = false
table.sort(self.tbNewChatList, function(a, b)
if a.nSortId == b.nSortId then
return a.nChatId < b.nChatId
end
return a.nSortId > b.nSortId
end)
if #self.tbNewChatList > 0 then
bNewChat = true
local tbData = self.tbNewChatList[#self.tbNewChatList]
local chatCfg = ConfigTable.GetData("Chat", tbData.nChatId)
local bPhoneOpen = PanelManager.CheckPanelOpen(PanelId.Phone)
if chatCfg ~= nil then
if chatCfg.AutoPopUp and not bPhoneOpen then
EventManager.Hit(EventId.OpenPanel, PanelId.PhonePopUp, tbData.nChatId, false, callback)
else
self:RefreshRedDot()
EventManager.Hit("NewChatTrigger", tbData.nAddressId, tbData.nChatId)
if nil ~= callback then
callback()
end
end
end
elseif nAddressId ~= nil then
local tbHistoryChat = self:GetChatHistoryList(nAddressId)
local tbNewChat = {}
for k, v in pairs(tbHistoryChat) do
if v.nStatus == AllEnum.PhoneChatState.New then
table.insert(tbNewChat, v)
end
end
if #tbNewChat < 1 then
for k, v in pairs(tbHistoryChat) do
if v.nStatus == AllEnum.PhoneChatState.UnComplete then
table.insert(tbNewChat, v)
end
end
end
if 0 < #tbNewChat then
self:RefreshRedDot()
EventManager.Hit("NewChatTrigger", nAddressId, tbNewChat[1].nChatId)
end
if nil ~= callback then
callback()
end
elseif nil ~= callback then
callback()
end
self.tbNewChatList = {}
return bNewChat
end
function PlayerPhoneData:GetNextProcess(nAddressId, nChatId, nProcess)
local chatData = self:GetChatData(nAddressId, nChatId)
local nNextProcess = nProcess
local tbMsg = chatData.avgMsg[nNextProcess]
if nil ~= tbMsg and tbMsg.cmd == "SetPhoneMsgChoiceJumpTo" then
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if chatCfg ~= nil then
local sGroupId = tbMsg.param[1]
local tbData = self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. chatCfg.AVGGroupId][sGroupId]
if nNextProcess > tbData.nBeginCmdId then
nNextProcess = self:SetPhoneMsgChoiceEnd(nChatId, sGroupId)
end
end
end
return nNextProcess > chatData.nAllProcess and chatData.nAllProcess or nNextProcess
end
function PlayerPhoneData:CheckChatComplete(nChatId)
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if nil ~= chatCfg then
local nAddressId = chatCfg.AddressBookId
local dataAddress = self.tbAddressBook[nAddressId]
if nil ~= dataAddress and nil ~= dataAddress.tbChatList then
local chatData = dataAddress.tbChatList[nChatId]
return chatData.nProcess >= chatData.nAllProcess
end
end
printError(string.format("聊天未解锁,请检查配置!!chatId = [%s])", nChatId))
return true
end
function PlayerPhoneData:ParseAvgContactsData()
local nCurLanguageIdx = GetLanguageIndex(Settings.sCurrentTxtLanguage)
self.sAvgContactsPath = GetAvgLuaRequireRoot(nCurLanguageIdx) .. "Preset/AvgContacts"
local tbContacts = require(self.sAvgContactsPath)
self.tbAvgContacts = {}
for i, v in ipairs(tbContacts) do
self.tbAvgContacts[v.id] = {
name = v.name,
signature = ProcAvgTextContent(v.signature),
landmark = ProcAvgTextContent(v.landmark),
icon = v.icon
}
end
end
function PlayerPhoneData:GetAvgContactsData(sContactsId)
if self.tbAvgContacts == nil then
self:ParseAvgContactsData()
end
local tbContacts = self.tbAvgContacts[sContactsId]
if tbContacts == nil then
return nil
else
return tbContacts
end
end
function PlayerPhoneData:GetAVGPhoneMsg(nChatId, sLanguage)
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if nil ~= chatCfg then
if sLanguage == nil then
sLanguage = Settings.sCurrentTxtLanguage
end
local nCurLanguageIdx = GetLanguageIndex(sLanguage)
local sAvgCfgPath = GetAvgLuaRequireRoot(nCurLanguageIdx) .. "Config/" .. chatCfg.AVGId
if nil == self.tbChatMsgCache[sAvgCfgPath] then
local ok, tbAllAvgCfg = pcall(require, sAvgCfgPath)
if not ok then
printError("AvgId对应的配置文件没有找到,path:" .. sAvgCfgPath .. ". error: " .. tbAllAvgCfg)
return
else
self.tbChatMsgCache[sAvgCfgPath] = {}
local sMsgGroup
for i, v in ipairs(tbAllAvgCfg) do
if v.cmd == "SetGroupId" then
sMsgGroup = v.param[1]
self.tbChatMsgCache[sAvgCfgPath][sMsgGroup] = {}
self.tbPhoneMsgGroupData[chatCfg.AVGId .. sMsgGroup] = {}
self.tbPhoneMsgGroupData[chatCfg.AVGId .. sMsgGroup].nStartCmdId = i
elseif v.cmd ~= "End" then
table.insert(self.tbChatMsgCache[sAvgCfgPath][sMsgGroup], v)
if v.cmd == "SetPhoneMsgChoiceBegin" then
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] = {}
end
local sChoiceGroup = v.param[1]
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] = {
nBeginCmdId = 0,
nEndCmdId = 0,
tbTargetCmdId = {}
}
end
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup].nBeginCmdId = i
elseif v.cmd == "SetPhoneMsgChoiceJumpTo" then
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] = {}
end
local sChoiceGroup = v.param[1]
local nIndex = v.param[2]
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] = {
nBeginCmdId = 0,
nEndCmdId = 0,
tbTargetCmdId = {}
}
end
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup].tbTargetCmdId[nIndex] = i
elseif v.cmd == "SetPhoneMsgChoiceEnd" then
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup] = {}
end
local sChoiceGroup = v.param[1]
if self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] == nil then
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup] = {
nBeginCmdId = 0,
nEndCmdId = 0,
tbTargetCmdId = {}
}
end
self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. sMsgGroup][sChoiceGroup].nEndCmdId = i
end
end
end
end
end
if nil ~= self.tbChatMsgCache[sAvgCfgPath] then
return self.tbChatMsgCache[sAvgCfgPath][chatCfg.AVGGroupId]
end
end
end
function PlayerPhoneData:ParseAvgHistoryPhoneMsgData(nChatId, tbMsgData, nProcess, tbSelection)
self:ClearHistoryPhoneMsgData(nChatId)
if nil ~= tbMsgData then
local choiceCount = 0
local sCurChoiceIndex = "0"
local sCurGroupId = "0"
local bFindChoice = false
local bStartChoice = false
for i, v in ipairs(tbMsgData) do
if i <= nProcess then
if v.cmd == "SetPhoneMsg" then
if bStartChoice then
if bFindChoice then
local data = {
cmd = v.cmd,
param = v.param,
process = i
}
table.insert(self.tbHistoryMsg[nChatId], data)
end
else
local data = {
cmd = v.cmd,
param = v.param,
process = i
}
table.insert(self.tbHistoryMsg[nChatId], data)
end
elseif v.cmd == "SetPhoneMsgChoiceBegin" then
if tbSelection ~= nil and choiceCount < #tbSelection then
choiceCount = choiceCount + 1
sCurChoiceIndex = tostring(tbSelection[choiceCount])
sCurGroupId = v.param[1] or "0"
bStartChoice = true
elseif i == nProcess then
local data = {
cmd = v.cmd,
param = v.param,
process = i
}
table.insert(self.tbHistoryMsg[nChatId], data)
end
elseif v.cmd == "SetPhoneMsgChoiceJumpTo" then
local sGroupId = v.param[1]
if sGroupId == sCurGroupId then
local sIndex = v.param[2]
if sIndex == sCurChoiceIndex then
bFindChoice = true
local dataSelection = {groupID = sCurGroupId, choiceIndex = sIndex}
table.insert(self.tbHistorySelection[nChatId], dataSelection)
else
bFindChoice = false
end
end
elseif v.cmd == "SetPhoneMsgChoiceEnd" then
bFindChoice = false
bStartChoice = false
end
else
break
end
end
end
end
function PlayerPhoneData:GetAvgStartCmdId(nChatId)
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if chatCfg ~= nil then
local tbData = self.tbPhoneMsgGroupData[chatCfg.AVGId .. chatCfg.AVGGroupId]
if tbData ~= nil then
return tbData.nStartCmdId
end
end
end
function PlayerPhoneData:ClearHistoryPhoneMsgData(nChatId)
self.tbHistoryMsg[nChatId] = {}
self.tbHistorySelection[nChatId] = {}
end
function PlayerPhoneData:UpdateHistoryPhoneMsgData(nChatId, tbMsgData, nProcess)
if self.tbHistoryMsg[nChatId] == nil then
self.tbHistoryMsg[nChatId] = {}
local data = {
cmd = tbMsgData.cmd,
param = tbMsgData.param,
process = nProcess
}
table.insert(self.tbHistoryMsg[nChatId], data)
return
end
if nProcess <= self.tbHistoryMsg[nChatId][#self.tbHistoryMsg[nChatId]].process then
return
end
if tbMsgData.cmd ~= "SetPhoneMsg" and tbMsgData.cmd ~= "SetPhoneMsgChoiceBegin" then
return
end
local lastData = self.tbHistoryMsg[nChatId][#self.tbHistoryMsg[nChatId]]
if lastData.cmd == "SetPhoneMsgChoiceBegin" then
table.remove(self.tbHistoryMsg[nChatId], #self.tbHistoryMsg[nChatId])
end
local data = {
cmd = tbMsgData.cmd,
param = tbMsgData.param,
process = nProcess
}
table.insert(self.tbHistoryMsg[nChatId], data)
end
function PlayerPhoneData:GetHistoryPhoneMsgData(nChatId)
if self.tbHistoryMsg[nChatId] == nil then
self.tbHistoryMsg[nChatId] = {}
end
return self.tbHistoryMsg[nChatId]
end
function PlayerPhoneData:GetHistoryPhoneSelectionData(nChatId)
if self.tbHistorySelection[nChatId] == nil then
self.tbHistorySelection[nChatId] = {}
end
return self.tbHistorySelection[nChatId]
end
function PlayerPhoneData:GetChatMsg(chatData, nIndex)
local avgGroupMsg = chatData.avgMsg
if nil ~= avgGroupMsg then
if nIndex == 1 then
return avgGroupMsg[nIndex]
else
local tbChatList = self.tbHistoryMsg[chatData.nChatId]
return tbChatList[#tbChatList]
end
end
end
function PlayerPhoneData:GetChatContent(chatData, nIndex)
local avgGroupMsg = chatData.avgMsg
if nil ~= avgGroupMsg then
local tbAvgMsg = avgGroupMsg[nIndex]
if nIndex == 1 then
return ProcAvgTextContent(tbAvgMsg.param[3], GetLanguageIndex(Settings.sCurrentTxtLanguage))
else
local tbChatList = self.tbHistoryMsg[chatData.nChatId]
local chatData = tbChatList[#tbChatList]
return ProcAvgTextContent(chatData.param[3], GetLanguageIndex(Settings.sCurrentTxtLanguage))
end
end
end
function PlayerPhoneData:SetPhoneMsgChoiceJumpTo(nChatId, nGroupId, nIndex)
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if chatCfg ~= nil then
local tbData = self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. chatCfg.AVGGroupId][tostring(nGroupId)]
if tbData ~= nil then
return tbData.tbTargetCmdId[tostring(nIndex)]
end
end
end
function PlayerPhoneData:SetPhoneMsgChoiceEnd(nChatId, nGroupId)
local chatCfg = ConfigTable.GetData("Chat", nChatId)
if chatCfg ~= nil then
nGroupId = tostring(nGroupId)
local tbData = self.tbPhoneMsgChoiceTarget[chatCfg.AVGId .. chatCfg.AVGGroupId][nGroupId]
if tbData ~= nil then
return tbData.nEndCmdId
end
end
end
function PlayerPhoneData:GetTopCount()
local nTopCount = 0
for k, v in pairs(self.tbAddressBook) do
if v.bTop then
nTopCount = nTopCount + 1
end
end
return nTopCount
end
function PlayerPhoneData:SetPhoneTopStatus(nAddressId, bTop)
local callback = function(...)
end
HttpNetHandler.SendMsg(NetMsgId.Id.phone_contacts_top_req, {Value = nAddressId}, nil, callback)
self.tbAddressBook[nAddressId].bTop = bTop
if bTop then
self.tbAddressBook[nAddressId].nOptTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
end
end
function PlayerPhoneData:SendAddressListReq(callback)
HttpNetHandler.SendMsg(NetMsgId.Id.phone_contacts_info_req, {}, nil, callback)
end
function PlayerPhoneData:SendChatProcess(nAddressId, nChatId, nProcess, tbSelection, bEnd, callback)
local httpCall = function(mapMsgData)
if nil == self.tbHistoryMsg[nChatId] or nil == next(self.tbHistoryMsg[nChatId]) then
local chatData = self:GetChatData(nAddressId, nChatId)
self:ParseAvgHistoryPhoneMsgData(nChatId, chatData.avgMsg, nProcess, tbSelection)
end
self:RefreshChatProcess(nAddressId, nChatId, nProcess, tbSelection)
if nil ~= callback then
callback()
end
end
local netMsg = {
ChatId = nChatId,
Options = tbSelection,
Process = nProcess,
End = bEnd
}
HttpNetHandler.SendMsg(NetMsgId.Id.phone_contacts_report_req, netMsg, nil, httpCall)
end
function PlayerPhoneData:OnEvent_AfterEnterMain()
end
return PlayerPhoneData
@@ -0,0 +1,960 @@
local statusOrder = {
[0] = 1,
[1] = 2,
[2] = 0
}
local PlayerQuestData = class("PlayerQuestData")
local QuestType = {
Unknown = 0,
TourGuide = 1,
Daily = 2,
TravelerDuel = 3,
TravelerDuelChallenge = 4,
Affinity = 5,
BattlePassDaily = 6,
BattlePassWeekly = 7,
VampireSurvivorNormal = 8,
VampireSurvivorSeason = 9,
Tower = 10,
Demon = 11,
TowerEvent = 12
}
local QuestRedDotType = {
TourGuide = RedDotDefine.Task_Guide,
Daily = RedDotDefine.Task_Daily,
TravelerDuel = RedDotDefine.Task_Duel,
TravelerDuelChallenge = RedDotDefine.Task_Season,
Affinity = RedDotDefine.Role_AffinityTask,
Tower = RedDotDefine.StarTowerQuest
}
function PlayerQuestData:Init()
self._mapQuest = {}
self.tbDailyActives = {}
self.nCurTourGroupOrderIndex = 0
self.nMaxTourGroupOrderIndex = 0
self.tbTourGuideGroup = {}
self.tbTourGuide = {}
self:InitConfig()
EventManager.Add(EventId.IsNewDay, self, self.HandleExpire)
EventManager.Add(EventId.UpdateWorldClass, self, self.UpdateDailyQuestRedDot)
end
function PlayerQuestData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.HandleExpire)
EventManager.Remove(EventId.UpdateWorldClass, self, self.UpdateDailyQuestRedDot)
end
function PlayerQuestData:InitConfig()
local foreachDailyActive = function(mapData)
self.tbDailyActives[mapData.Id] = {
bReward = false,
nActive = mapData.Active
}
end
ForEachTableLine(DataTable.DailyQuestActive, foreachDailyActive)
local foreachTourGroup = function(mapData)
table.insert(self.tbTourGuideGroup, mapData)
end
ForEachTableLine(DataTable.TourGuideQuestGroup, foreachTourGroup)
table.sort(self.tbTourGuideGroup, function(a, b)
return a.Order < b.Order
end)
self.nMaxTourGroupOrderIndex = #self.tbTourGuideGroup
local foreachTourQuest = function(mapData)
if nil == self.tbTourGuide[mapData.Order] then
self.tbTourGuide[mapData.Order] = {}
end
table.insert(self.tbTourGuide[mapData.Order], mapData)
end
ForEachTableLine(DataTable.TourGuideQuest, foreachTourQuest)
local foreachDemonQuest = function(line)
if nil == CacheTable.GetData("_DemonQuest", line.AdvanceGroup) then
CacheTable.SetData("_DemonQuest", line.AdvanceGroup, {})
end
CacheTable.InsertData("_DemonQuest", line.AdvanceGroup, line)
end
ForEachTableLine(ConfigTable.Get("DemonQuest"), foreachDemonQuest)
end
function PlayerQuestData:GetAllQuestData()
local retDaily = {}
local sortDaily = function(a, b)
if a.nStatus ~= b.nStatus then
return statusOrder[a.nStatus] > statusOrder[b.nStatus]
end
local mapQuestA = ConfigTable.GetData("DailyQuest", a.nTid)
local mapQuestB = ConfigTable.GetData("DailyQuest", b.nTid)
return mapQuestA.Order < mapQuestB.Order
end
if self._mapQuest[2] ~= nil then
for _, mapQuest in pairs(self._mapQuest[2]) do
table.insert(retDaily, mapQuest)
end
if 0 < #retDaily then
table.sort(retDaily, sortDaily)
end
end
if self._mapQuest[QuestType.TourGuide] == nil and self.nCurTourGroupOrderIndex >= self.nMaxTourGroupOrderIndex then
self._mapQuest[QuestType.TourGuide] = {}
local nGroupId = self.tbTourGuideGroup[self.nMaxTourGroupOrderIndex].Id
local tbQuest = self.tbTourGuide[nGroupId]
if nil ~= tbQuest then
for _, v in ipairs(tbQuest) do
self._mapQuest[QuestType.TourGuide][v.Id] = {
nTid = v.Id,
nGoal = 1,
nCurProgress = 1,
nStatus = 2,
nExpire = 0
}
end
end
end
return retDaily, self._mapQuest[QuestType.TourGuide]
end
function PlayerQuestData:CheckTourGroupReward(nIndex)
return nIndex <= self.nCurTourGroupOrderIndex
end
function PlayerQuestData:GetTourGuideQuestRewardId()
local tbQuest = self._mapQuest[QuestType.TourGuide]
if tbQuest ~= nil then
for nId, v in pairs(tbQuest) do
if v.nStatus == 1 then
return nId
end
end
end
return 0
end
function PlayerQuestData:GetMaxTourGroupOrderIndex()
return self.nMaxTourGroupOrderIndex
end
function PlayerQuestData:CheckDailyActiveReceive(nActiveId)
if self.tbDailyActives[nActiveId] ~= nil then
return self.tbDailyActives[nActiveId].bReward
end
return false
end
function PlayerQuestData:GetTravelerDuelQuestData()
if self._mapQuest[3] == nil then
self._mapQuest[3] = {}
end
return self._mapQuest[3], self._mapQuest[4]
end
function PlayerQuestData:GetBattlePassQuestData()
if self._mapQuest[6] == nil then
self._mapQuest[6] = {}
end
if self._mapQuest[7] == nil then
self._mapQuest[7] = {}
end
return self._mapQuest[6], self._mapQuest[7]
end
function PlayerQuestData:GetStarTowerBookQuestData()
if self._mapQuest[12] == nil then
self._mapQuest[12] = {}
end
return self._mapQuest[12]
end
function PlayerQuestData:GetCurTourGroup()
if self._mapQuest[QuestType.TourGuide] == nil then
return 0
end
local nCurIndex = math.min(self.nCurTourGroupOrderIndex + 1, self.nMaxTourGroupOrderIndex)
local mapCurGroup = self.tbTourGuideGroup[nCurIndex]
return mapCurGroup.Id
end
function PlayerQuestData:GetCurTourGroupOrder()
if self._mapQuest[QuestType.TourGuide] == nil then
return 0
end
local nCurIndex = math.min(self.nCurTourGroupOrderIndex + 1, self.nMaxTourGroupOrderIndex)
local mapCurGroup = self.tbTourGuideGroup[nCurIndex]
return mapCurGroup.Order
end
function PlayerQuestData:GetMaxTourGroup()
return self.tbTourGuideGroup[self.nMaxTourGroupOrderIndex].Id
end
function PlayerQuestData:GetAffinityQuestData(questId)
if self._mapQuest[QuestType.Affinity] ~= nil and self._mapQuest[QuestType.Affinity][questId] ~= nil then
return self._mapQuest[QuestType.Affinity][questId]
end
return nil
end
function PlayerQuestData:GetStarTowerQuestData()
local tbCore, tbNormal = {}, {}
if not self._mapQuest[QuestType.Tower] then
return tbCore, tbNormal
end
for nId, v in pairs(self._mapQuest[QuestType.Tower]) do
local mapCfg = ConfigTable.GetData("StarTowerQuest", nId)
if mapCfg and v.nStatus ~= 2 then
if mapCfg.TowerQuestType == GameEnum.TowerQuestType.Core then
table.insert(tbCore, v)
elseif mapCfg.TowerQuestType == GameEnum.TowerQuestType.Normal then
table.insert(tbNormal, v)
end
end
end
local sort = function(a, b)
if a.nStatus ~= b.nStatus then
return statusOrder[a.nStatus] > statusOrder[b.nStatus]
elseif a.nTid ~= b.nTid then
return a.nTid < b.nTid
end
end
if 0 < #tbNormal then
table.sort(tbNormal, sort)
end
return tbCore, tbNormal
end
function PlayerQuestData:ReceiveDemonQuest(nGroupId)
if self._mapQuest[QuestType.Demon] ~= nil then
for nId, v in pairs(self._mapQuest[QuestType.Demon]) do
local mapCfg = ConfigTable.GetData("DemonQuest", nId)
if mapCfg ~= nil and mapCfg.AdvanceGroup == nGroupId then
v.nStatus = 2
end
end
end
end
function PlayerQuestData:GetDemonQuestData(nGroupId, nStageId)
local tbQuest = {}
if self._mapQuest[QuestType.Demon] == nil then
self._mapQuest[QuestType.Demon] = {}
end
for nId, v in pairs(self._mapQuest[QuestType.Demon]) do
local mapCfg = ConfigTable.GetData("DemonQuest", nId)
if mapCfg ~= nil and mapCfg.AdvanceGroup == nGroupId then
table.insert(tbQuest, v)
end
end
if #tbQuest == 0 then
local nCurStageId = PlayerData.Base:GetCurWorldClassStageId()
local tbAllQuest = CacheTable.GetData("_DemonQuest", nGroupId)
if tbAllQuest ~= nil and 0 < #tbAllQuest then
for _, v in ipairs(tbAllQuest) do
table.insert(tbQuest, {
nTid = v.Id,
nGoal = 1,
nCurProgress = 0,
nStatus = nStageId < nCurStageId and 2 or 0,
nExpire = 0
})
end
end
end
table.sort(tbQuest, function(a, b)
if a.nStatus == b.nStatus then
return a.nTid < b.nTid
end
return a.nStatus < b.nStatus
end)
return tbQuest
end
function PlayerQuestData:OnQuestProgressChanged(mapData)
local nCur = mapData.Progress[1] == nil and 0 or mapData.Progress[1].Cur
print(string.format("任务进度变更 ID:%d 当前进度:%d 当前状态:%d", mapData.Id, nCur, mapData.Status))
if QuestType[mapData.Type] == nil then
return
end
if self._mapQuest[QuestType[mapData.Type]] == nil then
self._mapQuest[QuestType[mapData.Type]] = {}
end
if #mapData.Progress == 0 then
printError("没有任务进度:" .. mapData.Id)
return
end
self._mapQuest[QuestType[mapData.Type]][mapData.Id] = {
nTid = mapData.Id,
nGoal = mapData.Progress[1].Max,
nCurProgress = mapData.Status ~= 2 and mapData.Progress[1].Cur or mapData.Progress[1].Max,
nStatus = mapData.Status,
nExpire = mapData.Expire
}
EventManager.Hit(EventId.QuestDataRefresh, mapData.Type)
end
function PlayerQuestData:ReceiveTourReward(nTid, callback)
local msg = {Value = nTid}
local tbReceivedId = {}
if nTid == 0 then
for nId, mapQuestData in pairs(self._mapQuest[QuestType.TourGuide]) do
if mapQuestData.nStatus == 1 then
table.insert(tbReceivedId, nId)
end
end
end
local Callback = function(_, mapMsgData)
if nTid == 0 then
for _, nQuestId in ipairs(tbReceivedId) do
self._mapQuest[QuestType.TourGuide][nQuestId].nStatus = 2
self._mapQuest[QuestType.TourGuide][nQuestId].nCurProgress = 1
self._mapQuest[QuestType.TourGuide][nQuestId].nGoal = 1
end
else
self._mapQuest[QuestType.TourGuide][nTid].nStatus = 2
self._mapQuest[QuestType.TourGuide][nTid].nCurProgress = 1
self._mapQuest[QuestType.TourGuide][nTid].nGoal = 1
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback(mapMsgData)
end
EventManager.Hit(EventId.TourQuestReceived, mapMsgData.Rewards, mapMsgData.Change)
self:UpdateQuestRedDot("TourGuide")
end
PlayerData.State:SetMailOverflow(false)
HttpNetHandler.SendMsg(NetMsgId.Id.quest_tour_guide_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveTourGroupReward(callback)
local Callback = function(_, mapMsgData)
self.nCurTourGroupOrderIndex = self.nCurTourGroupOrderIndex + 1
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback(mapMsgData)
end
EventManager.Hit(EventId.TourGroupReceived, mapMsgData.Rewards, mapMsgData.Change)
self:UpdateQuestRedDot("TourGuide")
end
PlayerData.State:SetMailOverflow(false)
HttpNetHandler.SendMsg(NetMsgId.Id.quest_tour_guide_group_reward_receive_req, {}, nil, Callback)
end
function PlayerQuestData:ReceiveDailyReward(nTid, callback)
local msg = {Value = nTid}
local tbReceivedId = {}
for nId, mapQuestData in pairs(self._mapQuest[QuestType.Daily]) do
local questCfg = ConfigTable.GetData("DailyQuest", nId)
if nil ~= questCfg and nTid == 0 and mapQuestData.nStatus == 1 then
table.insert(tbReceivedId, nId)
end
end
local Callback = function(_, mapMsgData)
if nTid == 0 then
for _, nId in ipairs(tbReceivedId) do
if self._mapQuest[QuestType.Daily][nId].nStatus == 1 then
self._mapQuest[QuestType.Daily][nId].nStatus = 2
self._mapQuest[QuestType.Daily][nId].nCurProgress = 1
self._mapQuest[QuestType.Daily][nId].nGoal = 1
end
end
else
self._mapQuest[QuestType.Daily][nTid].nStatus = 2
self._mapQuest[QuestType.Daily][nTid].nCurProgress = 1
self._mapQuest[QuestType.Daily][nTid].nGoal = 1
table.insert(tbReceivedId, nTid)
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback()
end
EventManager.Hit(EventId.DailyQuestReceived, mapMsgData)
self:UpdateQuestRedDot("Daily")
end
PlayerData.State:SetMailOverflow(false)
HttpNetHandler.SendMsg(NetMsgId.Id.quest_daily_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveDailyActiveReward(callBack)
local callback = function(_, mapMsgData)
local tbReward = {}
for _, v in ipairs(mapMsgData.ActiveIds) do
self.tbDailyActives[v].bReward = true
local mapCfg = ConfigTable.GetData("DailyQuestActive", v)
if mapCfg ~= nil then
for i = 1, 2 do
if mapCfg["ItemTid" .. i] ~= 0 then
if tbReward[mapCfg["ItemTid" .. i]] == nil then
tbReward[mapCfg["ItemTid" .. i]] = 0
end
tbReward[mapCfg["ItemTid" .. i]] = tbReward[mapCfg["ItemTid" .. i]] + mapCfg["Number" .. i]
end
end
end
end
self:UpdateDailyQuestRedDot()
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callBack ~= nil then
callBack()
end
local tbShowReward = {}
for id, count in pairs(tbReward) do
table.insert(tbShowReward, {id = id, count = count})
end
EventManager.Hit(EventId.DailyQuestActiveReceived, tbShowReward)
end
HttpNetHandler.SendMsg(NetMsgId.Id.quest_daily_active_reward_receive_req, {}, nil, callback)
end
function PlayerQuestData:ReceiveTravelerDuelReward(nTid, callback)
local msg = {Id = nTid, Type = 3}
local tbReceivedId = {}
if nTid == 0 then
for nId, mapQuestData in pairs(self._mapQuest[QuestType.TravelerDuel]) do
if mapQuestData.nStatus == 1 then
table.insert(tbReceivedId, nId)
end
end
end
local Callback = function(_, mapMsgData)
if nTid == 0 then
for _, nId in ipairs(tbReceivedId) do
if self._mapQuest[QuestType.TravelerDuel][nId].nStatus == 1 then
self._mapQuest[QuestType.TravelerDuel][nId].nStatus = 2
self._mapQuest[QuestType.TravelerDuel][nId].nCurProgress = 1
self._mapQuest[QuestType.TravelerDuel][nId].nGoal = 1
end
end
else
self._mapQuest[QuestType.TravelerDuel][nTid].nStatus = 2
self._mapQuest[QuestType.TravelerDuel][nTid].nCurProgress = 1
self._mapQuest[QuestType.TravelerDuel][nTid].nGoal = 1
table.insert(tbReceivedId, nTid)
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback()
end
EventManager.Hit(EventId.TRNormalQusetReceived, mapMsgData.QuestRewards, tbReceivedId, mapMsgData.Change)
self:UpdateQuestRedDot("TravelerDuel")
end
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_quest_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveTravelerDuelChallengeReward(nTid, callback)
local msg = {Id = nTid, Type = 4}
local tbReceivedId = {}
if nTid == 0 then
for nId, mapQuestData in pairs(self._mapQuest[QuestType.TravelerDuelChallenge]) do
if mapQuestData.nStatus == 1 then
table.insert(tbReceivedId, nId)
end
end
end
local Callback = function(_, mapMsgData)
if nTid == 0 then
for _, nId in ipairs(tbReceivedId) do
if self._mapQuest[QuestType.TravelerDuelChallenge][nId].nStatus == 1 then
self._mapQuest[QuestType.TravelerDuelChallenge][nId].nStatus = 2
self._mapQuest[QuestType.TravelerDuelChallenge][nId].nCurProgress = 1
self._mapQuest[QuestType.TravelerDuelChallenge][nId].nGoal = 1
end
end
else
self._mapQuest[QuestType.TravelerDuelChallenge][nTid].nStatus = 2
self._mapQuest[QuestType.TravelerDuelChallenge][nTid].nCurProgress = 1
self._mapQuest[QuestType.TravelerDuelChallenge][nTid].nGoal = 1
table.insert(tbReceivedId, nTid)
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback()
end
EventManager.Hit(EventId.TRChallengeQusetReceived, mapMsgData.QuestRewards, tbReceivedId, mapMsgData.Change)
self:UpdateQuestRedDot("TravelerDuelChallenge")
end
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_quest_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveBattlePassQuestData(nTid, callback)
local msgCallback = function(_, msgData)
if nTid == 0 then
for _, mapQuest in pairs(self._mapQuest[6]) do
if mapQuest.nStatus == 1 then
mapQuest.nStatus = 2
end
end
for _, mapQuest in pairs(self._mapQuest[7]) do
if mapQuest.nStatus == 1 then
mapQuest.nStatus = 2
end
end
else
local mapQuestCfgData = ConfigTable.GetData("BattlePassQuest", nTid)
if mapQuestCfgData ~= nil then
if mapQuestCfgData.Type == GameEnum.battlePassQuestType.DAY then
if self._mapQuest[6][nTid] ~= nil then
self._mapQuest[6][nTid].nStatus = 2
end
elseif self._mapQuest[7][nTid] ~= nil then
self._mapQuest[7][nTid].nStatus = 2
end
end
end
EventManager.Hit("BattlePassQuestReceive", msgData)
if callback ~= nil and type(callback) == "function" then
callback()
end
self:UpdateBattlePassRedDot()
end
local msg = {Value = nTid}
HttpNetHandler.SendMsg(NetMsgId.Id.battle_pass_quest_reward_receive_req, msg, nil, msgCallback)
end
function PlayerQuestData:ReceiveAffinityReward(questIds, curCharId, callback)
local msg = {CharId = curCharId, QuestId = 0}
local Callback = function(_, mapMsgData)
if self._mapQuest[QuestType.Affinity] == nil then
self._mapQuest[QuestType.Affinity] = {}
end
for k, v in ipairs(questIds) do
if self._mapQuest[QuestType.Affinity][v] ~= nil then
self._mapQuest[QuestType.Affinity][v].nStatus = 2
else
local data = {
nTid = v,
nGoal = 1,
nCurProgress = 1,
nStatus = 2
}
self._mapQuest[QuestType.Affinity][v] = data
end
end
if callback ~= nil then
callback()
end
self:UpdateCharAffinityRedDot()
EventManager.Hit(EventId.AffinityQuestReceived)
end
HttpNetHandler.SendMsg(NetMsgId.Id.char_affinity_quest_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveStarTowerReward(nTid, callback)
local msg = {Value = nTid}
local tbReceivedId = {}
if nTid == 0 then
for nId, mapQuestData in pairs(self._mapQuest[QuestType.Tower]) do
if mapQuestData.nStatus == 1 then
table.insert(tbReceivedId, nId)
end
end
end
local Callback = function(_, mapMsgData)
if nTid == 0 then
for _, nId in ipairs(tbReceivedId) do
if self._mapQuest[QuestType.Tower][nId].nStatus == 1 then
self._mapQuest[QuestType.Tower][nId].nStatus = 2
self._mapQuest[QuestType.Tower][nId].nCurProgress = 1
self._mapQuest[QuestType.Tower][nId].nGoal = 1
end
end
else
self._mapQuest[QuestType.Tower][nTid].nStatus = 2
self._mapQuest[QuestType.Tower][nTid].nCurProgress = 1
self._mapQuest[QuestType.Tower][nTid].nGoal = 1
table.insert(tbReceivedId, nTid)
end
UTILS.OpenReceiveByChangeInfo(mapMsgData, function()
if callback ~= nil then
callback()
end
EventManager.Hit("StarTowerQuestReceived")
end)
self:UpdateQuestRedDot("Tower")
end
PlayerData.State:SetMailOverflow(false)
HttpNetHandler.SendMsg(NetMsgId.Id.quest_tower_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:ReceiveStarTowerEventReward(nTid, callback)
local sucCall = function(_, mapMsgData)
for _, v in ipairs(mapMsgData.ReceivedIds) do
if self._mapQuest[12] ~= nil and self._mapQuest[12][v] ~= nil then
self._mapQuest[12][v].nStatus = 2
self._mapQuest[12][v].nCurProgress = 0
self._mapQuest[12][v].nGoal = 0
end
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Event_Reward, v, false)
end
UTILS.OpenReceiveByChangeInfo(mapMsgData.Change, callback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_book_event_reward_receive_req, {Value = nTid}, nil, sucCall)
end
function PlayerQuestData:CacheAllQuest(tbQuests)
local tbQuestType = {}
for _, mapQuest in pairs(tbQuests) do
self:OnQuestProgressChanged(mapQuest)
if nil == tbQuestType[mapQuest.Type] then
tbQuestType[mapQuest.Type] = 1
end
end
for questType, v in pairs(tbQuestType) do
self:UpdateQuestRedDot(questType)
end
end
function PlayerQuestData:CacheDailyActiveIds(tbIds)
for _, v in ipairs(tbIds) do
self.tbDailyActives[v].bReward = true
end
self:UpdateDailyQuestRedDot()
end
function PlayerQuestData:CacheTourGroupOrder(nIndex)
self.nCurTourGroupOrderIndex = nIndex
end
function PlayerQuestData:CheckClientType(nEventType)
local tbQuestId = {}
for nQuestType, tbQuestList in pairs(self._mapQuest) do
for _, mapQuest in pairs(tbQuestList) do
local nClientType
if nQuestType == QuestType.Daily then
local mapQuestCfg = ConfigTable.GetData("DailyQuest", mapQuest.nTid)
if mapQuestCfg ~= nil then
nClientType = mapQuestCfg.CompleteCondClient
end
end
if nClientType == nEventType and mapQuest.nStatus == 0 then
table.insert(tbQuestId, mapQuest.nTid)
end
end
end
return tbQuestId
end
function PlayerQuestData:HandleExpire()
local curTime = CS.ClientManager.Instance.serverTimeStamp
local tbExpire = {}
if self._mapQuest[2] ~= nil then
for nTid, mapQuest in pairs(self._mapQuest[2]) do
if mapQuest.nExpire > 0 and curTime >= mapQuest.nExpire then
table.insert(tbExpire, nTid)
end
end
for _, nTid in ipairs(tbExpire) do
self._mapQuest[2][nTid] = nil
end
end
tbExpire = {}
if self._mapQuest[6] ~= nil then
for nTid, mapQuest in pairs(self._mapQuest[6]) do
if mapQuest.nExpire > 0 and curTime >= mapQuest.nExpire then
table.insert(tbExpire, nTid)
end
end
for _, nTid in ipairs(tbExpire) do
self._mapQuest[6][nTid] = nil
end
end
tbExpire = {}
if self._mapQuest[7] ~= nil then
for nTid, mapQuest in pairs(self._mapQuest[7]) do
if mapQuest.nExpire > 0 and curTime >= mapQuest.nExpire then
table.insert(tbExpire, nTid)
end
end
for _, nTid in ipairs(tbExpire) do
self._mapQuest[7][nTid] = nil
end
end
for _, v in pairs(self.tbDailyActives) do
v.bReward = false
end
self:UpdateDailyQuestRedDot()
self:UpdateBattlePassRedDot()
self:UpdateVampireQuestRedDot()
end
function PlayerQuestData:IsQuestHasReceived(nType, nQuestId)
if self._mapQuest[nType] == nil then
printError("没有记录的任务类型数据:" .. nQuestId)
return false
end
if self._mapQuest[nType][nQuestId] == nil then
printError("没有记录的任务组数据:" .. nQuestId)
return false
end
return self._mapQuest[nType][nQuestId].nStatus == 2
end
function PlayerQuestData:SendClientEvent(nEventType, nCount)
if nCount == nil then
nCount = 1
end
local tbQuestId = self:CheckClientType(nEventType)
if 0 < #tbQuestId then
local tbSendData = {}
for _, v in ipairs(tbQuestId) do
table.insert(tbSendData, {
Id = GameEnum.eventTypes.eClient,
Data = {nCount, v}
})
end
local msgData = {List = tbSendData}
HttpNetHandler.SendMsg(NetMsgId.Id.client_event_report_req, msgData, nil, nil)
end
end
function PlayerQuestData:UpdateServerQuestRedDot(mapMsgData)
if nil == mapMsgData then
return
end
local redDotType = QuestRedDotType[mapMsgData.Type]
if nil ~= redDotType then
RedDotManager.SetValid(redDotType, nil, mapMsgData.New)
end
end
function PlayerQuestData:UpdateQuestRedDot(questType)
if nil == questType then
return
end
if questType == "Daily" then
self:UpdateDailyQuestRedDot()
elseif questType == "TourGuide" then
self:UpdateTourGuideQuestRedDot()
elseif questType == "Affinity" then
self:UpdateCharAffinityRedDot()
elseif questType == "TravelerDuel" or questType == "TravelerDuelChallenge" then
self:UpdateDuelQuestRedDot(questType)
elseif questType == "BattlePassDaily" or questType == "BattlePassWeekly" then
self:UpdateBattlePassRedDot()
elseif questType == "Tower" then
self:UpdateStarTowerQuestRedDot()
elseif questType == "Demon" then
PlayerData.Base:RefreshWorldClassRedDot()
elseif questType == "VampireSurvivorSeason" or questType == "VampireSurvivorNormal" then
self:UpdateVampireQuestRedDot()
elseif questType == "TowerEvent" then
self:UpdateStarTowerBookQuestRedDot()
end
end
function PlayerQuestData:UpdateDailyQuestRedDot()
local bCanReceive = false
local bActiveReward = false
local nTotalActiveCount = 0
local questList = self._mapQuest[QuestType.Daily]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
bCanReceive = true
elseif v.nStatus == 2 then
local questCfg = ConfigTable.GetData("DailyQuest", v.nTid)
if questCfg ~= nil then
nTotalActiveCount = nTotalActiveCount + questCfg.Active
end
end
end
end
for _, v in pairs(self.tbDailyActives) do
bActiveReward = bActiveReward or nTotalActiveCount >= v.nActive and v.bReward == false
end
local bFuncUnlock = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.DailyQuest, false)
RedDotManager.SetValid(RedDotDefine.Task_Daily, nil, (bCanReceive or bActiveReward) and bFuncUnlock)
end
function PlayerQuestData:UpdateTourGuideQuestRedDot()
local bCanReceive = false
local bAllReceive = true
local nCurGroupId = self:GetCurTourGroup()
local questList = self._mapQuest[QuestType.TourGuide]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
local questCfg = ConfigTable.GetData("TourGuideQuest", v.nTid)
if nil ~= questCfg and nCurGroupId == questCfg.Order then
bCanReceive = true
break
end
end
if v.nStatus ~= 2 then
bAllReceive = false
end
end
end
local bGroupReceived = self:CheckTourGroupReward(self:GetCurTourGroupOrder())
local bChapterCanReceive = bAllReceive and not bGroupReceived
RedDotManager.SetValid(RedDotDefine.Task_Guide, nil, bCanReceive or bChapterCanReceive)
end
function PlayerQuestData:UpdateDuelQuestRedDot(questType)
local bCanReceive = false
local questList = self._mapQuest[QuestType[questType]]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
bCanReceive = true
break
end
end
end
RedDotManager.SetValid(QuestRedDotType[questType], nil, bCanReceive)
end
function PlayerQuestData:UpdateCharAffinityRedDot()
if self.tbCharQuest == nil then
self.tbCharQuest = {}
end
local questList = self._mapQuest[QuestType.Affinity]
if nil ~= questList then
for k, v in pairs(questList) do
local data = ConfigTable.GetData("AffinityQuest", v.nTid)
if data ~= nil then
if self.tbCharQuest[data.CharId] == nil then
self.tbCharQuest[data.CharId] = {}
end
table.insert(self.tbCharQuest[data.CharId], v)
end
end
local tbCharList = {}
for k, list in pairs(self.tbCharQuest) do
for i = 1, #list do
local state = list[i].nStatus
if state == 1 then
tbCharList[k] = true
break
else
tbCharList[k] = false
end
end
end
for k, v in pairs(tbCharList) do
RedDotManager.SetValid(RedDotDefine.Role_AffinityTask, k, v)
end
end
end
function PlayerQuestData:UpdateBattlePassRedDot()
local bCanDailyReceive = false
local bCanWeekReceive = false
local questList = self._mapQuest[6]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
bCanDailyReceive = true
break
end
end
end
questList = self._mapQuest[7]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
bCanWeekReceive = true
break
end
end
end
PlayerData.BattlePass:UpdateQuestRedDot(bCanDailyReceive, bCanWeekReceive)
end
function PlayerQuestData:UpdateStarTowerQuestRedDot()
local bCanReceive = false
local questList = self._mapQuest[QuestType.Tower]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
bCanReceive = true
break
end
end
end
RedDotManager.SetValid(QuestRedDotType.Tower, nil, bCanReceive)
end
function PlayerQuestData:UpdateStarTowerBookQuestRedDot()
local questList = self._mapQuest[QuestType.TowerEvent]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Event_Reward, v.nTid, true)
else
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Event_Reward, v.nTid, false)
end
end
end
end
function PlayerQuestData:GetVampireQuestData()
local tbScore, tbPass = {}, {}
if self._mapQuest[QuestType.VampireSurvivorSeason] ~= nil then
for nId, v in pairs(self._mapQuest[QuestType.VampireSurvivorSeason]) do
table.insert(tbScore, v)
end
end
if self._mapQuest[QuestType.VampireSurvivorNormal] ~= nil then
for nId, v in pairs(self._mapQuest[QuestType.VampireSurvivorNormal]) do
table.insert(tbPass, v)
end
end
return tbScore, tbPass
end
function PlayerQuestData:GetVampireQuestStatusById(nId)
if nId == nil then
return 0
end
if self._mapQuest[QuestType.VampireSurvivorSeason] ~= nil and self._mapQuest[QuestType.VampireSurvivorSeason][nId] ~= nil then
return self._mapQuest[QuestType.VampireSurvivorSeason][nId].nStatus
end
if self._mapQuest[QuestType.VampireSurvivorNormal] ~= nil and self._mapQuest[QuestType.VampireSurvivorNormal][nId] ~= nil then
return self._mapQuest[QuestType.VampireSurvivorNormal][nId].nStatus
end
return 0
end
function PlayerQuestData:ReceiveVampireQuest(nType, tbList, callback)
local msg = {
QuestType = nType - 7,
QuestIds = tbList
}
local Callback = function(_, mapMsgData)
for _, nTid in ipairs(tbList) do
if self._mapQuest[8][nTid] ~= nil then
self._mapQuest[8][nTid].nStatus = 2
end
if self._mapQuest[9] ~= nil and self._mapQuest[9][nTid] ~= nil then
self._mapQuest[9][nTid].nStatus = 2
end
end
self:UpdateVampireQuestRedDot()
EventManager.Hit("VampireQuestRefresh")
if callback ~= nil then
callback(mapMsgData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_survivor_quest_reward_receive_req, msg, nil, Callback)
end
function PlayerQuestData:UpdateVampireQuestRedDot()
local bCanNormalReceive = false
local bCanHardReceive = false
local bCanSeasonReceive = false
local questList = self._mapQuest[8]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
local mapQusetData = ConfigTable.GetData("VampireSurvivorQuest", v.nTid)
if mapQusetData ~= nil then
if mapQusetData.Type == GameEnum.vampireSurvivorType.Normal then
bCanNormalReceive = true
elseif mapQusetData.Type == GameEnum.vampireSurvivorType.Hard then
bCanHardReceive = true
elseif mapQusetData.Type == GameEnum.vampireSurvivorType.Turn then
bCanSeasonReceive = true
end
end
end
end
end
questList = self._mapQuest[9]
if nil ~= questList then
for _, v in pairs(questList) do
if v.nStatus == 1 then
local mapQusetData = ConfigTable.GetData("VampireSurvivorQuest", v.nTid)
if mapQusetData ~= nil then
if mapQusetData.Type == GameEnum.vampireSurvivorType.Normal then
bCanNormalReceive = true
elseif mapQusetData.Type == GameEnum.vampireSurvivorType.Hard then
bCanHardReceive = true
elseif mapQusetData.Type == GameEnum.vampireSurvivorType.Turn then
bCanSeasonReceive = true
end
end
end
end
end
RedDotManager.SetValid(RedDotDefine.VampireQuest_Normal, nil, bCanNormalReceive)
RedDotManager.SetValid(RedDotDefine.VampireQuest_Hard, nil, bCanHardReceive)
RedDotManager.SetValid(RedDotDefine.VampireQuest_Season, nil, bCanSeasonReceive)
end
function PlayerQuestData:ClearVampireSeasonQuest(nCurSeason)
local mapSeasonData = ConfigTable.GetData("VampireRankSeason", nCurSeason)
local tbRemove = {}
if mapSeasonData ~= nil then
local nSeasonGroupId = mapSeasonData.QuestGroup
if self._mapQuest[9] == nil then
self._mapQuest[9] = {}
end
for nTid, mapQuest in pairs(self._mapQuest[9]) do
local mapQuestCfgData = ConfigTable.GetData("VampireRankSeason", nTid)
if mapQuestCfgData ~= nil and mapQuestCfgData.GroupId ~= nSeasonGroupId then
table.insert(tbRemove, nTid)
end
end
for _, nQuestId in ipairs(tbRemove) do
if self._mapQuest[9][nQuestId] ~= nil then
self._mapQuest[9][nQuestId] = nil
end
end
end
end
return PlayerQuestData
@@ -0,0 +1,678 @@
local ClientManager = CS.ClientManager
local newDayTime = UTILS.GetDayRefreshTimeOffset()
local PlayerRogueBossData = class("PlayerRogueBossData")
local Actor2DManager = require("Game.Actor2D.Actor2DManager")
function PlayerRogueBossData:Init()
EventManager.Add(EventId.DelBuildItemId, self, self.OnEvent_DelBuildItemId)
EventManager.Add("region_boss_ticket_notify", self, self.OnEvent_RefreshRes)
self.passStar = 1
self.nBeforeStar = 0
self.selRegionBossId = 0
self.selBuildId = 0
self.selLvId = 0
self.isWeeklyCopies = false
self.weekBossThroughTime = nil
self.curLevel = nil
self._regionBossLevel = {}
self._regionBossAffix = {}
self:HandleDifficultyMsg()
self:HandleAffixMsg()
self.CacheBossLevelMsg = {}
self.CacheWeeklyCopiesMsg = {}
self.CacheWeeklyReceivedIds = {}
self.isUnLock = false
self.tbLastMaxHard = {}
self.isPauseCount = 0
self.nRegionBossChallengeTicket = 0
self.isSelectHardCore = false
self.upDataBuildId = 0
end
function PlayerRogueBossData:GetUnlockRogueBoss(nId, nIndex)
local data = ConfigTable.GetData("RegionBoss", nId)
local _prev = decodeJson(data.UnlockCondition)
for __, nMainlineId in ipairs(_prev) do
local nStar = PlayerData.Mainline:GetMainlineStar(nMainlineId)
if type(nStar) ~= "number" then
return false
end
end
local worldClass = PlayerData.Base:GetWorldClass()
local tempData = self._regionBossLevel[nId][nIndex]
if worldClass < tempData.NeedWorldClass then
return false, tempData.NeedWorldClass
end
if tempData.PreLevelId ~= 0 then
local cachePreData = self:GetCacheBossLevelMsg(tempData.PreLevelId)
if cachePreData == nil or cachePreData.Star == nil or cachePreData.Star < tempData.PreLevelStar then
return false
end
end
return true
end
function PlayerRogueBossData:GetRogueBossUnLockMsg(nId, nIndex)
local worldClass = PlayerData.Base:GetWorldClass()
local tempData = self._regionBossLevel[nId][nIndex]
local isWorldClass = true
if worldClass < tempData.NeedWorldClass then
isWorldClass = false
end
local isPreLevelStar = true
if tempData.PreLevelId ~= 0 then
local cachePreData = self:GetCacheBossLevelMsg(tempData.PreLevelId)
if cachePreData == nil or cachePreData.Star == nil or cachePreData.Star < tempData.PreLevelStar then
isPreLevelStar = false
end
end
if isWorldClass == false or isPreLevelStar == false then
return false, isWorldClass, isPreLevelStar
end
return true
end
function PlayerRogueBossData:GetBossMaxLv(bossId)
local maxLv = 1
local worldClass = PlayerData.Base:GetWorldClass()
local lvGroupCount = self._regionBossLevel[bossId].groupCount
for i = 1, lvGroupCount do
local tempData = self._regionBossLevel[bossId][i]
if worldClass >= tempData.NeedWorldClass then
if tempData.PreLevelId ~= 0 then
local cachePreData = PlayerData.RogueBoss:GetCacheBossLevelMsg(tempData.Id)
if cachePreData and 0 < cachePreData.Star then
maxLv = i
end
else
maxLv = i
end
end
end
return maxLv
end
function PlayerRogueBossData:GetBossMaxGroupCount(bossId)
if nil ~= self._regionBossLevel[bossId] then
return self._regionBossLevel[bossId].groupCount
end
return 0
end
function PlayerRogueBossData:SetLastMaxHard(nGroupId, nHard)
self.tbLastMaxHard[nGroupId] = nHard
end
function PlayerRogueBossData:GetLastMaxHard(nGroupId)
return self.tbLastMaxHard[nGroupId] or 0
end
function PlayerRogueBossData:GetMaxHard(nGroupId)
local nHard = PlayerData.RogueBoss:GetBossMaxLv(nGroupId)
local maxCount = PlayerData.RogueBoss:GetBossMaxGroupCount(nGroupId)
if maxCount < nHard + 1 then
nHard = maxCount
else
local bUnlock = PlayerData.RogueBoss:GetUnlockRogueBoss(nGroupId, nHard + 1)
if bUnlock then
nHard = nHard + 1
end
end
return nHard
end
function PlayerRogueBossData:GetLevelOpenState(nGroupId)
local mapData = ConfigTable.GetData("RegionBoss", nGroupId)
if nil ~= mapData then
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local fixedTimeStamp = curTimeStamp - newDayTime * 3600
local nWeek = tonumber(os.date("!%w", fixedTimeStamp))
local bOpenTime = table.indexof(mapData.OpenDay, nWeek) > 0
local nLockMainline = 0
local bMainLine = true
local _prev = decodeJson(mapData.UnlockCondition)
if 0 < #_prev then
for _, nMainlineId in ipairs(_prev) do
local nStar = PlayerData.Mainline:GetMainlineStar(nMainlineId)
if type(nStar) ~= "number" then
nLockMainline = nMainlineId
end
end
bMainLine = 0 < nLockMainline
end
local bRogueLike = true
local bUnlock = bMainLine and bRogueLike
if not bOpenTime then
return AllEnum.RogueBossLevelState.Not_OpenDay, bUnlock
end
if not bMainLine then
return AllEnum.RogueBossLevelState.Not_MainLine, bUnlock
end
if not bRogueLike then
return AllEnum.RogueBossLevelState.Not_RogueLike, bUnlock
end
return AllEnum.RogueBossLevelState.Open, bUnlock
end
return AllEnum.RogueBossLevelState.None
end
function PlayerRogueBossData:GetUnOpenTipText(nLevelState, nGroupId)
local sTipStr = ""
if nLevelState == AllEnum.RogueBossLevelState.Not_OpenDay then
sTipStr = ConfigTable.GetUIText("Not_Open_Time")
elseif nLevelState == AllEnum.RogueBossLevelState.Not_MainLine then
local mapData = ConfigTable.GetData("RegionBoss", nGroupId)
local nLockMainline = 0
local _prev = decodeJson(mapData.UnlockCondition)
for _, nMainlineId in ipairs(_prev) do
local nStar = PlayerData.Mainline:GetMainlineStar(nMainlineId)
if type(nStar) ~= "number" then
nLockMainline = nMainlineId
end
end
local mapLevelData = ConfigTable.GetData_Mainline(nLockMainline)
if mapLevelData ~= nil then
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock"), mapLevelData.Num, mapLevelData.Name)
else
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock"), tostring(nLockMainline), "")
end
elseif nLevelState == AllEnum.RogueBossLevelState.Not_HardUnlock then
sTipStr = ConfigTable.GetUIText("Level_Lock")
end
return sTipStr
end
function PlayerRogueBossData:GetUnOpenUITipText(nLevelState, nGroupId)
local sTipStr = ""
if nLevelState == AllEnum.RogueBossLevelState.Not_OpenDay then
sTipStr = ConfigTable.GetUIText("Not_Open_Time")
elseif nLevelState == AllEnum.RogueBossLevelState.Not_MainLine then
local mapData = ConfigTable.GetData("RegionBoss", nGroupId)
local nLockMainline = 0
local _prev = decodeJson(mapData.UnlockCondition)
for _, nMainlineId in ipairs(_prev) do
local nStar = PlayerData.Mainline:GetMainlineStar(nMainlineId)
if type(nStar) ~= "number" then
nLockMainline = nMainlineId
end
end
local mapLevelData = ConfigTable.GetData_Mainline(nLockMainline)
if mapLevelData ~= nil then
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock"), mapLevelData.Num, mapLevelData.Name)
else
sTipStr = orderedFormat(ConfigTable.GetUIText("MainLine_Lock"), tostring(nLockMainline), "")
end
elseif nLevelState == AllEnum.RogueBossLevelState.Not_HardUnlock then
sTipStr = ConfigTable.GetUIText("Level_Lock")
end
return sTipStr
end
function PlayerRogueBossData:CheckLevelOpen(nGroupId, nHard, bShowTips)
if nGroupId == 0 then
return AllEnum.RogueBossLevelState.Open
end
local nLevelState, bUnlock = self:GetLevelOpenState(nGroupId)
if nil ~= nHard and nLevelState == AllEnum.RogueBossLevelState.Open then
local nMaxLevel = self:GetMaxHard(nGroupId)
if nHard > nMaxLevel then
nLevelState = AllEnum.RogueBossLevelState.Not_HardUnlock
end
end
if true == bShowTips then
local sTipStr = self:GetUnOpenTipText(nLevelState, nGroupId)
if nil ~= sTipStr and "" ~= sTipStr then
EventManager.Hit(EventId.OpenMessageBox, sTipStr)
end
end
return nLevelState == AllEnum.RogueBossLevelState.Open, bUnlock
end
function PlayerRogueBossData:HandleDifficultyMsg()
local foreach_Diff = function(diffData)
if self._regionBossLevel[diffData.RegionBossId] == nil then
self._regionBossLevel[diffData.RegionBossId] = {}
self._regionBossLevel[diffData.RegionBossId].groupCount = 0
end
self._regionBossLevel[diffData.RegionBossId][diffData.Difficulty] = diffData
self._regionBossLevel[diffData.RegionBossId].groupCount = self._regionBossLevel[diffData.RegionBossId].groupCount + 1
end
if self._regionBossLevel == nil then
self._regionBossLevel = {}
end
ForEachTableLine(DataTable.RegionBossLevel, foreach_Diff)
end
function PlayerRogueBossData:GetDiffAffixUnlockLv(regionBossId, entryGroupLevel)
local gCount = self._regionBossLevel[regionBossId].groupCount
for i = 1, gCount do
if self._regionBossLevel[regionBossId][i][entryGroupLevel] ~= 0 then
return self._regionBossLevel[regionBossId][i].Difficulty
end
end
return 1
end
function PlayerRogueBossData:HandleAffixMsg()
local foreach_Affix = function(affixData)
if self._regionBossAffix[affixData.GroupId] == nil then
self._regionBossAffix[affixData.GroupId] = {}
self._regionBossAffix[affixData.GroupId].groupCount = 0
end
self._regionBossAffix[affixData.GroupId][affixData.Level] = affixData
self._regionBossAffix[affixData.GroupId].groupCount = self._regionBossAffix[affixData.GroupId].groupCount + 1
end
ForEachTableLine(DataTable.RegionBossAffix, foreach_Affix)
end
function PlayerRogueBossData:SetRegionBossId(_regionBossId)
self.selRegionBossId = _regionBossId
end
function PlayerRogueBossData:GetRegionBossId()
return self.selRegionBossId
end
function PlayerRogueBossData:GetRewardItem(id, isFirstPass, isThreeStar)
local cfgData = ConfigTable.GetData("RegionBossLevel", id)
local tbItem = {}
local _base = decodeJson(cfgData.BaseAwardPreview)
if not isFirstPass then
local _first = decodeJson(cfgData.FirstAwardPreview)
for k, v in ipairs(_first) do
table.insert(tbItem, {
Tid = v,
rewardType = AllEnum.RewardType.First
})
end
end
if not isThreeStar then
local _three = decodeJson(cfgData.ThreeStarAwardPreview)
for k, v in ipairs(_three) do
table.insert(tbItem, {
Tid = v,
rewardType = AllEnum.RewardType.Three
})
end
end
for k, v in ipairs(_base) do
table.insert(tbItem, {Tid = v})
end
return tbItem
end
function PlayerRogueBossData:SetSelLvId(id)
self.selLvId = id
end
function PlayerRogueBossData:GetSelLvId()
return self.selLvId
end
function PlayerRogueBossData:SetIsWeeklyCopies(isWeeklyCopies)
self.isWeeklyCopies = isWeeklyCopies
end
function PlayerRogueBossData:GetIsWeeklyCopies()
return self.isWeeklyCopies
end
function PlayerRogueBossData:CacheRogueBossData(tbData)
if self.CacheBossLevelMsg == nil then
self.CacheBossLevelMsg = {}
end
if tbData then
for i, v in ipairs(tbData) do
local tab = {}
tab.Star = v.Star
tab.First = v.First
tab.ThreeStar = v.ThreeStar
tab.BuildId = v.BuildId
tab.maxStar = v.ThreeStar and 3 or v.Star
self.CacheBossLevelMsg[v.Id] = tab
end
end
self:OnEvent_RefreshRes(AllEnum.CoinItemId.RogueHardCoreTick)
end
function PlayerRogueBossData:CacheWeeklyCopiesData(tbData)
if self.CacheWeeklyCopiesMsg == nil then
self.CacheWeeklyCopiesMsg = {}
end
if tbData then
for i, v in pairs(tbData) do
if self.CacheWeeklyCopiesMsg[v.Id] ~= nil then
local tab = self.CacheWeeklyCopiesMsg[v.Id]
if tab.Time > v.Time then
tab.Time = v.Time
tab.BuildId = v.BuildId
tab.First = v.First
self.CacheWeeklyCopiesMsg[v.Id] = tab
end
else
local tab = {}
tab.Id = v.Id
tab.Time = v.Time
tab.BuildId = v.BuildId
tab.First = v.First
self.CacheWeeklyCopiesMsg[v.Id] = tab
end
end
end
end
function PlayerRogueBossData:GetCacheWeeklyBossMsg(id)
return self.CacheWeeklyCopiesMsg[id] or nil
end
function PlayerRogueBossData:CacheWeeklyThroughTime(time)
self.weekBossThroughTime = time
end
function PlayerRogueBossData:ClearCacheWeeklyRecIds()
self.CacheWeeklyReceivedIds = {}
if PanelManager.CheckPanelOpen(PanelId.WeeklyCopiesPanel) then
EventManager.Hit(EventId.OpenPanel, PanelId.WeeklyCopiesPanel)
end
end
function PlayerRogueBossData:GetCacheBossLevelMsg(Id)
return self.CacheBossLevelMsg[Id] or nil
end
function PlayerRogueBossData:GetBeforeStar()
return self.nBeforeStar
end
function PlayerRogueBossData:OnEvent_RefreshRes(nId)
if nId == AllEnum.CoinItemId.RogueHardCoreTick then
self.nRegionBossChallengeTicket = PlayerData.Item:GetItemCountByID(AllEnum.CoinItemId.RogueHardCoreTick)
local worldClass = PlayerData.Base:GetWorldClass()
local openClass = ConfigTable.GetData("OpenFunc", GameEnum.OpenFuncType.RegionBossChallenge).NeedWorldClass
if worldClass >= openClass and self.nRegionBossChallengeTicket > 0 then
RedDotManager.SetValid(RedDotDefine.Map_RogueBoss, nil, true)
else
RedDotManager.SetValid(RedDotDefine.Map_RogueBoss, nil, false)
end
end
end
function PlayerRogueBossData:GetRegionBossChallengeTicket()
return self.nRegionBossChallengeTicket
end
function PlayerRogueBossData:SetSelectRegionType(isHard)
self.isSelectHardCore = isHard
end
function PlayerRogueBossData:GetSelectRegionType()
return self.isSelectHardCore
end
function PlayerRogueBossData:EnterRegionBoss(mapData)
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
if self.curLevel ~= nil then
if self.curLevel.UnBindEvent ~= nil then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
local luaClass = require("Game.Adventure.RegionBossLevel.RegionBossBattleLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.upDataBuildId = self.selBuildId
self.curLevel:Init(self, self.selLvId, self.selBuildId, 1)
end
end
function PlayerRogueBossData:EnterWeekBoss(mapData)
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
if self.curLevel ~= nil then
if self.curLevel.UnBindEvent ~= nil then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
local luaClass = require("Game.Adventure.RegionBossLevel.RegionBossBattleLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.upDataBuildId = self.selBuildId
self.curLevel:Init(self, self.selLvId, self.selBuildId, 2)
end
end
function PlayerRogueBossData:EnterRoguelikeEditor(floorId, tbTeamCharId, tbDisc, tbNote)
self.selLvId = 0
self.nFloorId = floorId
self.tbCharId = tbTeamCharId
self.selBuildId = 0
local foreach_level = function(_Data)
if _Data.FloorId == floorId then
self.selLvId = _Data.Id
end
end
ForEachTableLine(DataTable.RegionBossLevel, foreach_level)
if self.curLevel ~= nil then
if self.curLevel.UnBindEvent ~= nil then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
local luaClass = require("Game.Editor.RegionBossLevel.RegionBossBattleLevelEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, self.selLvId, tbTeamCharId, tbDisc, tbNote)
end
end
function PlayerRogueBossData:LevelEnd()
self.curLevel = nil
end
function PlayerRogueBossData:RegionBossLevelSettleReq(isWin, useTime, callback)
if isWin and not PlayerData.Guide:CheckGuideFinishById(16) then
PlayerData.Guide:SetPlayerLearnReq(16, -1)
end
local func_cbRegionBossLevelSettleAck = function(_, msgData)
if callback ~= nil then
callback(msgData, self.passStar)
end
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
local result = isWin and "1" or "2"
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(useTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self.upDataBuildId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self.selLvId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
NovaAPI.UserEventUpload("region_boss_battle", tabUpLevel)
end
self.passStar = 0
if isWin then
self.passStar = 1
local lvMsg = ConfigTable.GetData("RegionBossLevel", self.selLvId)
if lvMsg.RegionType == GameEnum.RegionType.NormalRegion then
local star2 = decodeJson(lvMsg.TwoStarCondition)
local star3 = decodeJson(lvMsg.ThreeStarCondition)
if star2[1] == 2 and useTime < star2[2] then
self.passStar = 2
end
if star3[1] == 2 and useTime < star3[2] then
self.passStar = 3
end
end
end
local Events = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.RegionBoss, isWin)
local mapSendMsg = {}
mapSendMsg.Star = self.passStar
if 0 < #Events then
mapSendMsg.Events = {
List = {}
}
mapSendMsg.Events.List = Events
end
HttpNetHandler.SendMsg(NetMsgId.Id.region_boss_level_settle_req, mapSendMsg, nil, func_cbRegionBossLevelSettleAck)
end
function PlayerRogueBossData:WeeklyCopiesLevelSettleReq(isWin, useTime, callback)
local func_cbRegionBossLevelSettleAck = function(_, msgData)
if callback ~= nil then
callback(msgData, self.passStar)
end
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
local result = isWin and "1" or "2"
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(useTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self.upDataBuildId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self.selLvId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
NovaAPI.UserEventUpload("week_boss", tabUpLevel)
end
local Events = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.WeeklyCopies, isWin)
local mapSendMsg = {}
mapSendMsg.Result = isWin
mapSendMsg.Time = useTime
if isWin then
PlayerData.RogueBoss:CacheWeeklyThroughTime(useTime)
else
PlayerData.RogueBoss:CacheWeeklyThroughTime(nil)
end
if 0 < #Events then
mapSendMsg.Events = {
List = {}
}
mapSendMsg.Events.List = Events
end
HttpNetHandler.SendMsg(NetMsgId.Id.week_boss_settle_req, mapSendMsg, nil, func_cbRegionBossLevelSettleAck)
end
function PlayerRogueBossData:WeeklyCopiesLevelSettleReqSuccess(msgData)
local isFirst = msgData.First
if self.weekBossThroughTime == nil or self.weekBossThroughTime == 0 then
return
end
local levels = {}
local level = {}
level.Id = self.selLvId
level.Time = self.weekBossThroughTime
level.First = isFirst
level.BuildId = self.selBuildId
table.insert(levels, level)
self:CacheWeeklyCopiesData(levels)
self.weekBossThroughTime = nil
end
function PlayerRogueBossData:RegionBossLevelSettleSuccess(mapMsgData)
self.nBeforeStar = 0
if self.CacheBossLevelMsg[self:GetSelLvId()] then
self.nBeforeStar = self.CacheBossLevelMsg[self:GetSelLvId()].Star
end
if 0 < self.passStar then
local tempCache = self.CacheBossLevelMsg[self:GetSelLvId()]
local data = {}
data.Id = self:GetSelLvId()
if tempCache and tempCache.Star > self.passStar then
data.Star = tempCache.Star
else
data.Star = self.passStar
end
if tempCache and tempCache.First then
data.First = tempCache.First
else
data.First = mapMsgData.First
end
if tempCache and tempCache.ThreeStar then
data.ThreeStar = tempCache.ThreeStar
else
data.ThreeStar = mapMsgData.ThreeStar
end
data.BuildId = self.selBuildId
if tempCache and tempCache.ThreeStar then
data.maxStar = 3
else
data.maxStar = mapMsgData.ThreeStar and 3 or self.passStar
end
self.CacheBossLevelMsg[data.Id] = data
local tempLvData = ConfigTable.GetData("RegionBossLevel", self:GetSelLvId())
if tempLvData.Difficulty < self._regionBossLevel[tempLvData.RegionBossId].groupCount then
local tempDiff = tempLvData.Difficulty + 1
local _tempLvId = self._regionBossLevel[tempLvData.RegionBossId][tempDiff].Id
if self.CacheBossLevelMsg[_tempLvId] == nil then
self:SetIsUnlock(true)
end
end
else
local tempCache = self.CacheBossLevelMsg[self:GetSelLvId()]
local data = {}
data.Id = self:GetSelLvId()
if tempCache and tempCache.Star > self.passStar then
data.Star = tempCache.Star
else
data.Star = self.passStar
end
data.First = tempCache and tempCache.First or mapMsgData.First
data.ThreeStar = tempCache and tempCache.ThreeStar or mapMsgData.ThreeStar
data.BuildId = self.selBuildId
if tempCache and tempCache.maxStar > self.passStar then
data.maxStar = tempCache.maxStar
else
data.maxStar = self.passStar
end
self.CacheBossLevelMsg[data.Id] = data
end
self:SetSelBuildId(0)
self:OnEvent_RefreshRes(AllEnum.CoinItemId.RogueHardCoreTick)
end
function PlayerRogueBossData:RegionBossLevelSettleFail()
end
function PlayerRogueBossData:SetSelBuildId(bId)
self.selBuildId = bId
end
function PlayerRogueBossData:GetSelBuildId()
return self.selBuildId
end
function PlayerRogueBossData:OnEvent_DelBuildItemId(tab)
for i, v in pairs(tab) do
for i1, v1 in pairs(self.CacheBossLevelMsg) do
if v1.BuildId == v then
v1.BuildId = 0
end
end
end
end
function PlayerRogueBossData:GetIsUnlock()
return self.isUnLock
end
function PlayerRogueBossData:SetIsUnlock(isPass)
self.isUnLock = isPass
end
function PlayerRogueBossData:Sweep(nLevelId, nTimes, callback)
local msg = {
Id = nLevelId,
Times = nTimes,
Events = {
List = {}
}
}
local successCallback = function(_, mapMainData)
callback(mapMainData.Rewards, mapMainData.Change)
end
HttpNetHandler.SendMsg(NetMsgId.Id.region_boss_level_sweep_req, msg, nil, successCallback)
end
return PlayerRogueBossData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,627 @@
local PlayerScoreBossData = class("PlayerScoreBossData")
local LocalData = require("GameCore.Data.LocalData")
function PlayerScoreBossData:Init()
self.BattleLv = 0
self:InitBaseData()
self.isGetScInfo = false
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
self:InitTableData()
self:InitRankData()
end
function PlayerScoreBossData:InitTableData()
self.tabScoreNeed = {}
local foreach_Base = function(baseData)
self.tabScoreNeed[baseData.Star] = baseData.ScoreNeed
end
ForEachTableLine(DataTable.ScoreBossStar, foreach_Base)
self.maxStarNeed = 0
self.tabScoreBossReward = {}
local foreach_Base = function(baseData)
self.tabScoreBossReward[baseData.Id] = baseData
if self.maxStarNeed < baseData.StarNeed then
self.maxStarNeed = baseData.StarNeed
end
end
ForEachTableLine(DataTable.ScoreBossReward, foreach_Base)
end
function PlayerScoreBossData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerScoreBossData:InitBaseData()
self.ControlId = 0
self.Score = 0
self.Star = 0
self.tabStarRewards = {}
self.tabScoreBossLevel = {}
self.OpenLevelGroup = {}
self.StartTime = 0
self.EndTime = 0
self.tabCachedBuildId = {}
end
function PlayerScoreBossData:GetInitInfoState()
if self.ControlId ~= 0 then
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local tmpControl = ConfigTable.GetData("ScoreBossControl", self.ControlId + 1)
if tmpControl then
local startTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(tmpControl.StartTime)
if nCurTime >= startTime then
self.isGetScInfo = false
end
end
end
return self.isGetScInfo
end
function PlayerScoreBossData:GetScoreBossInstanceData(openPanelCallBack)
local msgCallback = function(_, mapMsgData)
self:CacheScoreBossInstanceData(mapMsgData, openPanelCallBack)
end
HttpNetHandler.SendMsg(NetMsgId.Id.score_boss_info_req, {}, nil, msgCallback)
end
function PlayerScoreBossData:CacheScoreBossInstanceData(mapMsgData, openPanelCallBack)
self:InitBaseData()
if mapMsgData == nil or mapMsgData.ControlId == 0 then
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("ScoreBoss_Season_Error"))
return
end
self.ControlId = mapMsgData.ControlId
self.Score = mapMsgData.Score
self.Star = mapMsgData.Star
for i, v in pairs(mapMsgData.StarRewards) do
table.insert(self.tabStarRewards, v)
end
self.maxRankCount = 0
local foreach_Base = function(baseData)
if baseData.SeasonId == self.ControlId then
self.maxRankCount = self.maxRankCount + 1
end
end
ForEachTableLine(DataTable.ScoreBossRank, foreach_Base)
local scoreBossControl = ConfigTable.GetData("ScoreBossControl", self.ControlId)
if scoreBossControl ~= nil then
local levelGroup = scoreBossControl.LevelGroup
if 0 < #levelGroup then
for i = 1, #levelGroup do
table.insert(self.OpenLevelGroup, levelGroup[i])
local tab = {}
tab.LevelId = levelGroup[i]
tab.BuildId = 0
tab.CharId = {
0,
0,
0
}
tab.Score = 0
tab.Star = 0
tab.SkillScore = 0
self.tabScoreBossLevel[levelGroup[i]] = tab
end
end
self.StartTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(scoreBossControl.StartTime)
self.EndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(scoreBossControl.EndTime) - ConfigTable.GetConfigNumber("SeasonEndThreshold")
end
for i, v in pairs(mapMsgData.Levels) do
if self.tabScoreBossLevel[v.LevelId] then
self.tabScoreBossLevel[v.LevelId].BuildId = v.BuildId
for i1 = 1, #v.CharIds do
self.tabScoreBossLevel[v.LevelId].CharId[i1] = v.CharIds[i1]
end
self.tabScoreBossLevel[v.LevelId].Score = v.Score
self.tabScoreBossLevel[v.LevelId].Star = v.Star
self.tabScoreBossLevel[v.LevelId].SkillScore = v.SkillScore
else
printError("ScoreBossControl 下发数据和配置数据对不上")
end
end
if not self.isGetScInfo then
EventManager.Hit("Get_ScoreBoss_InfoReq")
end
self.isGetScInfo = true
self:RefreshRedMsg()
if openPanelCallBack then
openPanelCallBack()
end
end
function PlayerScoreBossData:RefreshRedMsg()
self.isHave = false
for i, v in ipairs(self.tabScoreBossReward) do
if self.Star >= v.StarNeed and table.indexof(self.tabStarRewards, v.StarNeed) == 0 then
self.isHave = true
break
end
end
RedDotManager.SetValid(RedDotDefine.Map_ScoreBossStar, nil, self.isHave)
end
function PlayerScoreBossData:UpdateRedDot(mapMsgData)
if nil == mapMsgData then
return
end
RedDotManager.SetValid(RedDotDefine.Map_ScoreBossStar, nil, mapMsgData.New)
end
function PlayerScoreBossData:ChangeTabScoreBossLevel(nLevelId, nBuildId, nScore, nStar, nBehaviorScore, isReplace, tabOtherLevelId)
if isReplace then
self.tabScoreBossLevel[nLevelId].BuildId = nBuildId
self.tabScoreBossLevel[nLevelId].CharId = self.entryLevelChar
self.tabScoreBossLevel[nLevelId].Score = nScore
self.tabScoreBossLevel[nLevelId].Star = nStar
self.tabScoreBossLevel[nLevelId].SkillScore = nBehaviorScore
elseif nScore >= self.tabScoreBossLevel[nLevelId].Score then
self.tabScoreBossLevel[nLevelId].BuildId = nBuildId
self.tabScoreBossLevel[nLevelId].CharId = self.entryLevelChar
self.tabScoreBossLevel[nLevelId].Score = nScore
self.tabScoreBossLevel[nLevelId].Star = nStar
self.tabScoreBossLevel[nLevelId].SkillScore = nBehaviorScore
end
if 0 < #tabOtherLevelId then
for i, v in pairs(tabOtherLevelId) do
local tmpLevelId = v
self.tabScoreBossLevel[tmpLevelId].BuildId = 0
self.tabScoreBossLevel[tmpLevelId].CharId = {
0,
0,
0
}
self.tabScoreBossLevel[tmpLevelId].Score = 0
self.tabScoreBossLevel[tmpLevelId].Star = 0
self.tabScoreBossLevel[tmpLevelId].SkillScore = 0
end
end
local _totalStar = 0
local _totalScore = 0
for i, v in pairs(self.tabScoreBossLevel) do
_totalStar = _totalStar + v.Star
_totalScore = _totalScore + v.Score
end
self.Score = _totalScore
self.Star = _totalStar
self:RefreshRedMsg()
end
function PlayerScoreBossData:OnEvent_NewDay()
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
if self.EndTime ~= 0 and nCurTime > self.EndTime then
self:GetScoreBossInstanceData(nil)
self:SendScoreBossApplyReq(function()
end)
end
end
function PlayerScoreBossData:SendEnterScoreBossApplyReq(nLevelId, nBuildId)
local msg = {}
msg.LevelId = nLevelId
msg.BuildId = nBuildId
local msgCallback = function()
self.CurHPLvScore = 0
self.HPLvScore = 0
self.CurHPDamage = 0
self.BehaviorScore = 0
self.BehaviorScoreCount = 0
local curTimeStamp = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local sKey = LocalData.GetPlayerLocalData("ScoreBossRecordKey")
if sKey ~= nil and sKey ~= "" then
NovaAPI.DeleteRecFile(sKey)
end
sKey = tostring(curTimeStamp)
LocalData.SetPlayerLocalData("ScoreBossRecordKey", sKey)
self:EnterScoreBossInstance(nLevelId, nBuildId)
end
HttpNetHandler.SendMsg(NetMsgId.Id.score_boss_apply_req, msg, nil, msgCallback)
end
function PlayerScoreBossData:EnterScoreBossInstance(nLevelId, nBuildId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
self.entryLevelId = nLevelId
self.entryBuild = nBuildId
local luaClass = require("Game.Adventure.ScoreBoss.ScoreBossLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId)
end
end
function PlayerScoreBossData:EnterScoreBossInstanceEditor(nLevelId, tbChar, tbDisc, tbNote)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
self.entryLevelId = nLevelId
self.CurHPLvScore = 0
self.HPLvScore = 0
self.CurHPDamage = 0
self.BehaviorScore = 0
self.BehaviorScoreCount = 0
local luaClass = require("Game.Editor.ScoreBoss.ScoreBossEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, tbChar, tbDisc, tbNote)
end
end
function PlayerScoreBossData:LevelEnd()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerScoreBossData:CacheBuildCharTid(tab)
self.entryLevelChar = tab
end
function PlayerScoreBossData:GetEntryBuildCharTid()
return self.entryLevelChar
end
function PlayerScoreBossData:SetSelBuildId(nBuildId, levelId)
self.tabCachedBuildId[levelId] = nBuildId
end
function PlayerScoreBossData:GetCachedBuild(levelId)
return self.tabCachedBuildId[levelId] or 0
end
function PlayerScoreBossData:GetLevelBuild(levelId)
if self.tabScoreBossLevel[levelId] and self.tabScoreBossLevel[levelId].BuildId ~= 0 then
return self.tabScoreBossLevel[levelId].BuildId
end
return 0
end
function PlayerScoreBossData:GetLevelData(levelId)
if self.tabScoreBossLevel[levelId] then
return self.tabScoreBossLevel[levelId]
end
return nil
end
function PlayerScoreBossData:GetBuildChar(buildId, callBack)
local GetDataCallback = function(tbBuildData, mapAllBuild)
local mapBuild = mapAllBuild[buildId]
local tbCharId = {}
if mapBuild ~= nil then
for _, mapChar in ipairs(mapBuild.tbChar) do
table.insert(tbCharId, mapChar.nTid)
end
end
callBack(tbCharId)
end
PlayerData.Build:GetAllBuildBriefData(GetDataCallback)
end
function PlayerScoreBossData:JudgeOtherLevelHaveSameChar(entryLevelId, entryBuildId, callBack)
local otherLevelId = {}
local GetDataCallback = function(tbBuildData, mapAllBuild)
local entryBuild = mapAllBuild[entryBuildId]
local entryChar = {}
for _, mapChar in ipairs(entryBuild.tbChar) do
table.insert(entryChar, mapChar.nTid)
end
for i, v in pairs(self.OpenLevelGroup) do
if v ~= entryLevelId and self.tabScoreBossLevel[v] and self.tabScoreBossLevel[v].CharId[1] ~= 0 then
for i1, v1 in pairs(self.tabScoreBossLevel[v].CharId) do
local idx = table.indexof(entryChar, v1)
if idx ~= 0 then
table.insert(otherLevelId, self.tabScoreBossLevel[v].LevelId)
break
end
end
end
end
callBack(otherLevelId)
end
PlayerData.Build:GetAllBuildBriefData(GetDataCallback)
end
function PlayerScoreBossData:JudgeLevelCacheOtherChar(entryLevelId, entryBuildId, callBack)
local tmpBuild = self:GetLevelBuild(entryLevelId)
if tmpBuild == 0 or tmpBuild == entryBuildId then
callBack(false)
return
end
if self.tabScoreBossLevel[entryLevelId].CharId[1] ~= 0 then
for i, v in pairs(self.tabScoreBossLevel[entryLevelId].CharId) do
local idx = table.indexof(self.entryLevelChar, v)
if idx == 0 then
callBack(true)
return
end
end
callBack(false)
else
callBack(false)
end
end
function PlayerScoreBossData:DamageToScore(damageValue, SwitchRate, battleLv)
self.CurHPDamage = damageValue
self.CurHPLvScore = math.floor(damageValue / SwitchRate)
self.BattleLv = battleLv
EventManager.Hit("ScoreBoss_Score_Change")
end
function PlayerScoreBossData:HPLevelChanged()
self.HPLvScore = self.HPLvScore + self.CurHPLvScore
self.CurHPLvScore = 0
self.CurHPDamage = 0
EventManager.Hit("ScoreBoss_Score_Change")
end
function PlayerScoreBossData:BehaviorToScore(nScore)
self.BehaviorScore = nScore
self.BehaviorScoreCount = self.BehaviorScoreCount + 1
EventManager.Hit("ScoreBoss_Score_Change")
EventManager.Hit("ScoreBoss_Score_SkillChange")
end
function PlayerScoreBossData:GetTotalScore()
local totalScore = self.HPLvScore + self.CurHPLvScore + self.BehaviorScore
return totalScore
end
function PlayerScoreBossData:GetBehaviorScore()
return self.BehaviorScore, self.BehaviorScoreCount
end
function PlayerScoreBossData:GetDamageScore()
return self.HPLvScore + self.CurHPLvScore
end
function PlayerScoreBossData:ScoreToStar()
local tmpStar = 0
local totalScore = self.HPLvScore + self.CurHPLvScore + self.BehaviorScore
for i, v in pairs(self.tabScoreNeed) do
if v <= totalScore and i > tmpStar then
tmpStar = i
end
end
return tmpStar
end
function PlayerScoreBossData:QuiteLevel()
self:LevelEnd()
local wait = function()
coroutine.yield(CS.UnityEngine.WaitForEndOfFrame())
coroutine.yield(CS.UnityEngine.WaitForEndOfFrame())
CS.WwiseAudioManager.Instance:PostEvent("ui_loading_combatSFX_mute", nil, false)
end
cs_coroutine.start(wait)
CS.AdventureModuleHelper.ResumeLogic()
local function levelEndCallback()
EventManager.Remove("ADVENTURE_LEVEL_UNLOAD_COMPLETE", self, levelEndCallback)
NovaAPI.EnterModule("MainMenuModuleScene", true)
end
EventManager.Add("ADVENTURE_LEVEL_UNLOAD_COMPLETE", self, levelEndCallback)
CS.AdventureModuleHelper.LevelStateChanged(true, 0, true)
end
function PlayerScoreBossData:SureScoreBossSettleReq(totalStar, totalScore, isReplace, tabOtherLevelId)
NovaAPI.StopRecord()
local tbSamples = UTILS.GetBattleSamples()
local sKey = LocalData.GetPlayerLocalData("ScoreBossRecordKey")
local bSuccess, nCheckSum = NovaAPI.GetRecorderKey(sKey)
local tbSendSample = {Sample = tbSamples, Checksum = nCheckSum}
local msg = {}
msg.Star = totalStar
msg.Score = totalScore
msg.sample = tbSendSample
msg.DamageScore = math.floor(self.HPLvScore + self.CurHPLvScore)
msg.SkillScore = self.BehaviorScore
msg.BossResultLevel = self.BattleLv
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.ScoreBoss, true)
}
local msgCallback = function(_, mapMsgData)
local oldRank = mapMsgData.oldRank
local newRank = mapMsgData.newRank
self:UploadRecordFile(mapMsgData.token)
self:ChangeTabScoreBossLevel(self.entryLevelId, self.entryBuild, totalScore, totalStar, self.BehaviorScore, isReplace, tabOtherLevelId)
CS.AdventureModuleHelper.ResumeLogic()
EventManager.Hit("ScoreBossSettleSuccess", self.entryLevelId, totalScore, totalStar)
self:LevelEnd()
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local leveData = ConfigTable.GetData("ScoreBossLevel", self.entryLevelId)
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self.TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self.entryBuild)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(leveData.MonsterId)
})
table.insert(tabUpLevel, {
"total_score",
tostring(totalScore)
})
table.insert(tabUpLevel, {
"boss_result_level",
tostring(self.BattleLv)
})
NovaAPI.UserEventUpload("boss_rush", tabUpLevel)
self.isLevelClear = true
end
HttpNetHandler.SendMsg(NetMsgId.Id.score_boss_settle_req, msg, nil, msgCallback)
end
function PlayerScoreBossData:UploadRecordFile(sToken)
local sKey = LocalData.GetPlayerLocalData("ScoreBossRecordKey") or ""
if sKey ~= nil and sKey ~= "" then
if sToken ~= nil and sToken ~= "" then
NovaAPI.UploadStartowerFile(sToken, sKey)
else
NovaAPI.DeleteRecFile(sKey)
end
end
LocalData.SetPlayerLocalData("ScoreBossRecordKey", "")
end
function PlayerScoreBossData:SendScoreBossSettleReq(totalTime)
self.TotalTime = totalTime
CS.AdventureModuleHelper.PauseLogic()
local JudgeOther = function(otherLevelId)
local totalScore = self.HPLvScore + self.CurHPLvScore + self.BehaviorScore
local totalStar = self:ScoreToStar()
if #otherLevelId == 0 then
local judgeCache = function(isReplace)
if isReplace then
local ConfirmCb = function()
self:SureScoreBossSettleReq(totalStar, totalScore, true, {})
end
local CancelCb = function()
self:QuiteLevel()
end
EventManager.Hit(EventId.OpenPanel, PanelId.ScoreBossReplaceBD, self.entryLevelId, ConfirmCb, CancelCb)
else
self:SureScoreBossSettleReq(totalStar, totalScore, false, {})
end
end
self:JudgeLevelCacheOtherChar(self.entryLevelId, self.entryBuild, judgeCache)
else
local judgeCache = function(isReplace)
if isReplace then
local ConfirmCb = function()
local ConfirmClearCb = function()
self:SureScoreBossSettleReq(totalStar, totalScore, true, otherLevelId)
end
local CancelClearCb = function()
self:QuiteLevel()
end
EventManager.Hit(EventId.OpenPanel, PanelId.ScoreBossClearBD, otherLevelId, ConfirmClearCb, CancelClearCb)
end
local CancelCb = function()
self:QuiteLevel()
end
EventManager.Hit(EventId.OpenPanel, PanelId.ScoreBossReplaceBD, self.entryLevelId, ConfirmCb, CancelCb)
else
local ConfirmClearCb = function()
self:SureScoreBossSettleReq(totalStar, totalScore, true, otherLevelId)
end
local CancelClearCb = function()
self:QuiteLevel()
end
EventManager.Hit(EventId.OpenPanel, PanelId.ScoreBossClearBD, otherLevelId, ConfirmClearCb, CancelClearCb)
end
end
self:JudgeLevelCacheOtherChar(self.entryLevelId, self.entryBuild, judgeCache)
end
end
self:JudgeOtherLevelHaveSameChar(self.entryLevelId, self.entryBuild, JudgeOther)
end
function PlayerScoreBossData:SendScoreBossStarRewardReceiveReq(cb, star)
local msg = {}
msg.Star = star
local msgCallback = function(_, mapMsgData)
if star ~= 0 then
table.insert(self.tabStarRewards, star)
else
self.tabStarRewards = {}
for i, v in pairs(self.tabScoreBossReward) do
if v.StarNeed <= self.Star then
table.insert(self.tabStarRewards, v.StarNeed)
end
end
end
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData)
UTILS.OpenReceiveByDisplayItem(mapDecodedChangeInfo["proto.Res"], mapMsgData)
cb()
self:RefreshRedMsg()
end
HttpNetHandler.SendMsg(NetMsgId.Id.score_boss_star_reward_receive_req, msg, nil, msgCallback)
end
function PlayerScoreBossData:SendScoreBossApplyReq(cb)
self:InitRankData()
local msgCallback = function(_, mapMsgData)
self:SetRankMsg(mapMsgData, cb)
end
HttpNetHandler.SendMsg(NetMsgId.Id.score_boss_rank_req, {}, nil, msgCallback)
end
function PlayerScoreBossData:InitRankData()
self.RankLastRefreshTime = 0
self.RankSelfMsg = nil
self.RankPlayerMsg = {}
self.RankBorder = {}
self.nRankTotalCount = 0
end
function PlayerScoreBossData:SetRankMsg(mapMsgData, cb)
self.RankLastRefreshTime = mapMsgData.LastRefreshTime
if mapMsgData.Self then
self.RankSelfMsg = mapMsgData.Self
end
if mapMsgData.Rank then
for i, v in pairs(mapMsgData.Rank) do
table.insert(self.RankPlayerMsg, v)
end
end
if mapMsgData.Border then
for i, v in pairs(mapMsgData.Border) do
table.insert(self.RankBorder, v)
end
end
if mapMsgData.Total then
self.nRankTotalCount = mapMsgData.Total
end
cb()
end
function PlayerScoreBossData:CheckRankDataLastest()
if self.RankSelfMsg == nil or self.RankSelfMsg.Rank == 0 then
return true
end
local mapSelfDataInList
if self.RankSelfMsg.Rank <= #self.RankPlayerMsg then
mapSelfDataInList = self.RankPlayerMsg[self.RankSelfMsg.Rank]
else
return false
end
if mapSelfDataInList == nil or mapSelfDataInList.NickName ~= self.RankSelfMsg.NickName or mapSelfDataInList.Score ~= self.RankSelfMsg.Score then
return false
end
return true
end
function PlayerScoreBossData:GetRankSelfMsg()
return self.RankSelfMsg
end
function PlayerScoreBossData:GetSelfRankIndex()
if self.RankSelfMsg then
return self.RankSelfMsg.Rank
end
return 0
end
function PlayerScoreBossData:GetRankBorderCount(index)
return self.RankBorder[index] or 0
end
function PlayerScoreBossData:GetSelfBorderIndex()
for i, v in pairs(self.RankBorder) do
if v <= self.RankSelfMsg.Score then
return i
end
end
return 1
end
function PlayerScoreBossData:GetRankPlayerCount()
return self.nRankTotalCount or 0
end
function PlayerScoreBossData:GetRankTableCount()
return #self.RankPlayerMsg or 0
end
function PlayerScoreBossData:GetPlayerRankMsg(index)
return self.RankPlayerMsg[index] or nil
end
function PlayerScoreBossData:GetVoiceKey()
local isFirst = false
if not self.isFirstVoice then
isFirst = true
self.isFirstVoice = true
end
local timeNow = CS.ClientManager.Instance.serverTimeStamp
local nHour = tonumber(os.date("%H", timeNow))
if 6 <= nHour and nHour < 12 then
return isFirst, "greetmorn_npc"
elseif 12 <= nHour and nHour < 18 then
return isFirst, "greetnoon_npc"
else
return isFirst, "greetnight_npc"
end
end
return PlayerScoreBossData
@@ -0,0 +1,419 @@
local PlayerShopData = class("PlayerShopData")
local ClientManager = CS.ClientManager.Instance
local DisplayMode = {
Hide = 0,
End = 1,
Stay = 2
}
function PlayerShopData:Init()
self._tbShops = {}
self._tbGoods = {}
self._tbServerData = {}
self._bFirstInShop = true
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Add(EventId.NewFuncUnlockWorldClass, self, self.OnEvent_NewFuncUnlockWorldClass)
end
function PlayerShopData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
EventManager.Remove(EventId.NewFuncUnlockWorldClass, self, self.OnEvent_NewFuncUnlockWorldClass)
end
function PlayerShopData:OnEvent_NewDay()
self:CacheDailyShopReward(true)
end
function PlayerShopData:OnEvent_NewFuncUnlockWorldClass(nId)
if nId == GameEnum.OpenFuncType.DailyReward then
self:CacheDailyShopReward(true)
end
end
function PlayerShopData:CheckShopData(callback)
if next(self._tbShops) == nil then
local func_create = function()
self:CreateData()
if callback then
callback()
end
end
self:SendResidentShopGetReq({}, func_create)
else
local tbShopIds = self:GetNeedToRefreshShops()
if 0 < #tbShopIds then
local func_update = function()
self:UpdateData(tbShopIds)
if callback then
callback()
end
end
self:SendResidentShopGetReq(tbShopIds, func_update)
elseif callback then
callback()
end
end
end
function PlayerShopData:CheckGoodsData(nShopId)
local tbGoods = self:GetNeedToRefreshGoods(nShopId)
if #tbGoods == 0 then
return
end
local nServerTimeStamp = ClientManager.serverTimeStamp
for _, mapGoods in pairs(tbGoods) do
if mapGoods.nDownShelfTime ~= 0 and nServerTimeStamp >= mapGoods.nDownShelfTime then
self._tbGoods[nShopId][mapGoods.nId] = nil
else
self:UpdateGoodsData(nShopId, mapGoods.nId)
end
end
end
function PlayerShopData:GetShopList()
local tbList = {}
for _, mapShop in pairs(self._tbShops) do
if mapShop.bUnlock and mapShop.bOpenAble then
table.insert(tbList, mapShop)
end
end
table.sort(tbList, function(a, b)
return a.nSequence < b.nSequence
end)
return tbList
end
function PlayerShopData:GetGoodsList(nShopId)
local tbList = {}
for _, mapGoods in pairs(self._tbGoods[nShopId]) do
if mapGoods.bUnlock and mapGoods.bOpenAble and (not mapGoods.bSoldOut or mapGoods.nDisplayMode ~= DisplayMode.Hide) then
table.insert(tbList, mapGoods)
end
end
local comp = function(a, b)
if (a.bSoldOut and a.nDisplayMode == DisplayMode.End) ~= (b.bSoldOut and b.nDisplayMode == DisplayMode.End) then
return (not a.bSoldOut or a.nDisplayMode ~= DisplayMode.End) and b.bSoldOut and b.nDisplayMode == DisplayMode.End
else
return a.nSaleNumber < b.nSaleNumber
end
end
table.sort(tbList, comp)
return tbList
end
function PlayerShopData:GetShopAutoUpdateTime()
local tbTime = {}
for _, mapShop in pairs(self._tbShops) do
if mapShop.nNextRefreshTime > 0 then
table.insert(tbTime, mapShop.nNextRefreshTime)
end
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function PlayerShopData:GetGoodsAutoUpdateTime(nShopId)
local tbTime = {}
for _, mapGoods in pairs(self._tbGoods[nShopId]) do
if mapGoods.nNextRefreshTime > 0 then
table.insert(tbTime, mapGoods.nNextRefreshTime)
end
end
if #tbTime == 0 then
return 0
end
table.sort(tbTime)
return tbTime[1] - ClientManager.serverTimeStamp
end
function PlayerShopData:GetShopFirstIn()
local bFirst = self._bFirstInShop
if self._bFirstInShop == true then
self._bFirstInShop = false
end
return bFirst
end
function PlayerShopData:CreateData()
local nServerTimeStamp = ClientManager.serverTimeStamp
local func_ForEach_Shop = function(mapCfgData)
self:CreateShopData(mapCfgData, nServerTimeStamp)
end
ForEachTableLine(DataTable.ResidentShop, func_ForEach_Shop)
local func_ForEach_Goods = function(mapCfgData)
if self._tbShops[mapCfgData.ShopId] then
self:CreateGoodsData(mapCfgData, nServerTimeStamp)
end
end
ForEachTableLine(DataTable.ResidentGoods, func_ForEach_Goods)
end
function PlayerShopData:CreateShopData(mapCfgData, nServerTimeStamp)
local nCloseTime = self:ChangeToTimeStamp(mapCfgData.CloseTime)
local bExpired = nCloseTime ~= 0 and nServerTimeStamp >= nCloseTime
if bExpired then
return
end
local mapShop = {
nId = mapCfgData.Id,
tbShopCoin = mapCfgData.ShopCoin,
sName = mapCfgData.Name,
nSequence = mapCfgData.Sequence,
nRefreshTimeType = mapCfgData.RefreshTimeType,
nRefreshInterval = mapCfgData.RefreshInterval,
nUnlockCondType = mapCfgData.UnlockCondType,
tbUnlockCondParams = decodeJson(mapCfgData.UnlockCondParams),
nOpenTime = self:ChangeToTimeStamp(mapCfgData.OpenTime),
nCloseTime = nCloseTime,
bUnlock = false,
bOpenAble = false,
nServerRefreshTime = 0,
nNextRefreshTime = 0
}
self._tbShops[mapCfgData.Id] = mapShop
self:UpdateShopData(mapCfgData.Id)
end
function PlayerShopData:CreateGoodsData(mapCfgData, nServerTimeStamp)
local nDownShelfTime = self:ChangeToTimeStamp(mapCfgData.DownShelfTime)
local bExpired = nDownShelfTime ~= 0 and nServerTimeStamp >= nDownShelfTime
if bExpired then
return
end
local mapGoods = {
nId = mapCfgData.Id,
sName = mapCfgData.Name,
sDesc = mapCfgData.Desc,
nSaleNumber = mapCfgData.SaleNumber,
nItemId = mapCfgData.ItemId,
nItemQuantity = mapCfgData.ItemQuantity,
nMaximumLimit = mapCfgData.MaximumLimit,
nCurrencyItemId = mapCfgData.CurrencyItemId,
nPrice = mapCfgData.Price,
nOriginalPrice = mapCfgData.OriginalPrice,
nDiscount = mapCfgData.Discount,
nAppearCondType = mapCfgData.AppearCondType,
tbAppearCondParams = decodeJson(mapCfgData.AppearCondParams),
nPurchaseCondType = mapCfgData.PurchaseCondType,
tbPurchaseCondParams = decodeJson(mapCfgData.PurchaseCondParams),
nUpShelfTime = self:ChangeToTimeStamp(mapCfgData.UpShelfTime),
nDownShelfTime = nDownShelfTime,
nUnlockPurchaseTime = self:ChangeToTimeStamp(mapCfgData.UnlockPurchaseTime),
nDisplayMode = mapCfgData.DisplayMode,
bUnlock = false,
bPurchasable = false,
bPurchasTime = false,
bOpenAble = false,
bSoldOut = false,
nBoughtCount = 0,
nNextRefreshTime = 0
}
if not self._tbGoods[mapCfgData.ShopId] then
self._tbGoods[mapCfgData.ShopId] = {}
end
self._tbGoods[mapCfgData.ShopId][mapCfgData.Id] = mapGoods
self:UpdateGoodsData(mapCfgData.ShopId, mapCfgData.Id)
end
function PlayerShopData:ChangeToTimeStamp(sTime)
return sTime == "" and 0 or ClientManager:ISO8601StrToTimeStamp(sTime)
end
function PlayerShopData:UpdateData(tbShopIds)
local nServerTimeStamp = ClientManager.serverTimeStamp
for _, nShopId in pairs(tbShopIds) do
if self._tbShops[nShopId].nCloseTime ~= 0 and nServerTimeStamp >= self._tbShops[nShopId].nCloseTime then
self._tbShops[nShopId] = nil
self._tbGoods[nShopId] = nil
else
self:UpdateShopData(nShopId)
for nGoodsId, mapGoods in pairs(self._tbGoods[nShopId]) do
if mapGoods.nDownShelfTime ~= 0 and nServerTimeStamp >= mapGoods.nDownShelfTime then
self._tbGoods[nShopId][nGoodsId] = nil
else
self:UpdateGoodsData(nShopId, nGoodsId)
end
end
end
end
end
function PlayerShopData:UpdateShopData(nId)
self._tbShops[nId].bUnlock = self:CheckShopCond(self._tbShops[nId].nUnlockCondType, self._tbShops[nId].tbUnlockCondParams)
self._tbShops[nId].bOpenAble = ClientManager.serverTimeStamp >= self._tbShops[nId].nOpenTime
self._tbShops[nId].nServerRefreshTime = self._tbServerData[nId] and self._tbServerData[nId].RefreshTime or 0
self._tbShops[nId].nNextRefreshTime = self:UpdateNextShopRefreshTime(nId, self._tbShops[nId].nServerRefreshTime)
end
function PlayerShopData:UpdateGoodsData(nShopId, nGoodsId)
local mapGoods = self._tbGoods[nShopId][nGoodsId]
local nBoughtCount = self:GetBoughtCount(nGoodsId)
self._tbGoods[nShopId][nGoodsId].bUnlock = self:CheckShopCond(mapGoods.nAppearCondType, mapGoods.tbAppearCondParams, AllEnum.ShopCondSource.ResidentGoods)
self._tbGoods[nShopId][nGoodsId].bPurchasable = self:CheckShopCond(mapGoods.nPurchaseCondType, mapGoods.tbPurchaseCondParams, AllEnum.ShopCondSource.ResidentGoods)
self._tbGoods[nShopId][nGoodsId].bPurchasTime = ClientManager.serverTimeStamp >= mapGoods.nUnlockPurchaseTime
self._tbGoods[nShopId][nGoodsId].bOpenAble = ClientManager.serverTimeStamp >= mapGoods.nUpShelfTime
self._tbGoods[nShopId][nGoodsId].bSoldOut = nBoughtCount ~= 0 and nBoughtCount == mapGoods.nMaximumLimit
self._tbGoods[nShopId][nGoodsId].nBoughtCount = nBoughtCount
self._tbGoods[nShopId][nGoodsId].nNextRefreshTime = self:UpdateNextGoodsRefreshTime(nShopId, nGoodsId)
end
function PlayerShopData:UpdateNextShopRefreshTime(nId, nServerRefreshTime)
local mapShop = self._tbShops[nId]
if mapShop.nOpenTime > 0 then
local nTime = mapShop.nOpenTime
if 0 < nTime - ClientManager.serverTimeStamp then
return nTime
end
end
local nNextRefreshTime = 0
if 0 < mapShop.nCloseTime then
local nTime = mapShop.nCloseTime
nNextRefreshTime = nTime
end
if 0 < mapShop.nRefreshTimeType then
local nTime = nServerRefreshTime
nNextRefreshTime = (nNextRefreshTime == 0 or nNextRefreshTime > nTime) and nTime or nNextRefreshTime
end
return nNextRefreshTime
end
function PlayerShopData:UpdateNextGoodsRefreshTime(nShopId, nGoodsId)
local mapGoods = self._tbGoods[nShopId][nGoodsId]
if mapGoods.nUpShelfTime > 0 then
local nTime = mapGoods.nUpShelfTime
if 0 < nTime - ClientManager.serverTimeStamp then
return nTime
end
end
local nNextRefreshTime = 0
if 0 < mapGoods.nDownShelfTime then
local nTime = mapGoods.nDownShelfTime
nNextRefreshTime = nTime
end
if 0 < mapGoods.nUnlockPurchaseTime then
local nTime = mapGoods.nUnlockPurchaseTime
nNextRefreshTime = (nNextRefreshTime == 0 or nNextRefreshTime > nTime) and nTime or nNextRefreshTime
end
return nNextRefreshTime
end
function PlayerShopData:ProcessServerData(mapServerData)
for _, mapShop in ipairs(mapServerData) do
self._tbServerData[mapShop.Id] = {}
self._tbServerData[mapShop.Id].RefreshTime = mapShop.RefreshTime or 0
for _, mapBoughtGoods in ipairs(mapShop.Infos) do
self._tbServerData[mapShop.Id][mapBoughtGoods.Id] = mapBoughtGoods.Number
end
end
end
function PlayerShopData:GetBoughtCount(nGoodsId)
local mapGoods = ConfigTable.GetData("ResidentGoods", nGoodsId)
if mapGoods == nil then
printError("商品配置不存在" .. nGoodsId)
return 0
end
local nShopId = mapGoods.ShopId
if self._tbServerData[nShopId] and self._tbServerData[nShopId][nGoodsId] then
return self._tbServerData[nShopId][nGoodsId]
else
return 0
end
end
function PlayerShopData:CacheDailyShopReward(bDailyReward)
local bUnlock = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.DailyReward)
self.bDailyReward = bUnlock and bDailyReward
RedDotManager.SetValid(RedDotDefine.Shop_Daily, nil, self.bDailyReward)
end
function PlayerShopData:GetDailyShopReward()
return self.bDailyReward
end
function PlayerShopData:GetNeedToRefreshShops()
local tbShopIds = {}
local nServerTimeStamp = ClientManager.serverTimeStamp
for _, mapShop in pairs(self._tbShops) do
if not mapShop.bUnlock then
local bUnlock = self:CheckShopCond(mapShop.nUnlockCondType, mapShop.tbUnlockCondParams)
if bUnlock then
table.insert(tbShopIds, mapShop.nId)
end
elseif mapShop.nNextRefreshTime > 0 and nServerTimeStamp >= mapShop.nNextRefreshTime then
table.insert(tbShopIds, mapShop.nId)
end
end
return tbShopIds
end
function PlayerShopData:GetNeedToRefreshGoods(nShopId)
local tbGoods = {}
local nServerTimeStamp = ClientManager.serverTimeStamp
if self._tbGoods[nShopId] then
for _, mapGoods in pairs(self._tbGoods[nShopId]) do
if not mapGoods.bUnlock then
local bUnlock = self:CheckShopCond(mapGoods.nAppearCondType, mapGoods.tbAppearCondParams, AllEnum.ShopCondSource.ResidentGoods)
if bUnlock then
table.insert(tbGoods, mapGoods)
end
elseif not mapGoods.bPurchasable then
local bPurchasable = self:CheckShopCond(mapGoods.nPurchaseCondType, mapGoods.tbPurchaseCondParams, AllEnum.ShopCondSource.ResidentGoods)
if bPurchasable then
table.insert(tbGoods, mapGoods)
end
elseif mapGoods.nNextRefreshTime > 0 and nServerTimeStamp >= mapGoods.nNextRefreshTime then
table.insert(tbGoods, mapGoods)
end
end
end
return tbGoods
end
function PlayerShopData:CheckShopCond(eCond, tbParam, nType)
if eCond == 0 then
return true
elseif eCond == GameEnum.shopCond.WorldClassSpecific and #tbParam == 1 then
local worldClass = PlayerData.Base:GetWorldClass()
return worldClass >= tbParam[1]
elseif eCond == GameEnum.shopCond.ShopPreGoodsSellOut and #tbParam == 2 and nType == AllEnum.ShopCondSource.ResidentGoods then
local nBeforeId = tbParam[2]
local nBoughtCount = self:GetBoughtCount(nBeforeId)
local mapCfg = ConfigTable.GetData("ResidentGoods", nBeforeId)
if not mapCfg then
return false
end
local bSoldOut = nBoughtCount ~= 0 and nBoughtCount == mapCfg.MaximumLimit
return bSoldOut
else
printError("条件配置错误:")
return false
end
end
function PlayerShopData:SendResidentShopGetReq(tbShopIds, callback)
local mapMsg = {ShopIds = tbShopIds}
local successCallback = function(_, mapData)
if mapData.Shops then
self:ProcessServerData(mapData.Shops)
callback()
else
printError("商店数据为空")
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.resident_shop_get_req, mapMsg, nil, successCallback)
end
function PlayerShopData:SendResidentShopPurchaseReq(nShopId, nGoodsId, nCount, callback)
local mapMsg = {
GoodsId = nGoodsId,
Number = nCount,
RefreshTime = self._tbShops[nShopId].nServerRefreshTime,
ShopId = nShopId
}
local successCallback = function(_, mapData)
if mapData.IsRefresh then
self:ProcessServerData({
mapData.Shop
})
EventManager.Hit("ShopTimeRefresh")
else
if not self._tbServerData[nShopId] then
self._tbServerData[nShopId] = {}
end
self._tbServerData[nShopId][nGoodsId] = mapData.PurchasedNumber
end
self:UpdateData({nShopId})
UTILS.OpenReceiveByChangeInfo(mapData.Change)
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.resident_shop_purchase_req, mapMsg, nil, successCallback)
end
function PlayerShopData:SendDailyShopRewardReceiveReq(callback)
local successCallback = function(_, mapData)
self.bDailyReward = false
RedDotManager.SetValid(RedDotDefine.Shop_Daily, nil, false)
UTILS.OpenReceiveByChangeInfo(mapData)
if callback then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.daily_shop_reward_receive_req, {}, nil, successCallback)
end
return PlayerShopData
@@ -0,0 +1,99 @@
local PlayerSideBannerData = class("PlayerSideBannerData")
local ModuleManager = require("GameCore.Module.ModuleManager")
function PlayerSideBannerData:Init()
self.tbDictionaryEntry = {}
self.tbAchievement = {}
self.tbFavour = {}
EventManager.Add("DispatchMsgDone", self, self.OnEvent_TryOpenSideBanner)
end
function PlayerSideBannerData:UnInit()
EventManager.Remove("DispatchMsgDone", self, self.OnEvent_TryOpenSideBanner)
end
function PlayerSideBannerData:OnEvent_TryOpenSideBanner()
self:TryOpenSideBanner(true)
end
function PlayerSideBannerData:TryOpenSideBanner(bLimit)
if bLimit and (ModuleManager.GetIsAdventure() or PanelManager.GetCurPanelId() == PanelId.Login or PanelManager.GetCurPanelId() == PanelId.GachaSpin or PanelManager.CheckPanelOpen(PanelId.DatingLandmark) or PanelManager.CheckPanelOpen(PanelId.Dating)) then
return
end
local mapData = {}
if next(self.tbAchievement) ~= nil then
local nAchievementCount = #self.tbAchievement
if nAchievementCount == 1 then
table.insert(mapData, {
nType = AllEnum.SideBaner.Achievement,
nId = self.tbAchievement[1]
})
else
local comp = function(a, b)
local aRarity = ConfigTable.GetData("Achievement", a).Rarity
local bRarity = ConfigTable.GetData("Achievement", b).Rarity
if aRarity ~= bRarity then
return aRarity < bRarity
elseif a ~= b then
return a < b
end
end
table.sort(self.tbAchievement, comp)
table.insert(mapData, {
nType = AllEnum.SideBaner.Achievement,
nId = self.tbAchievement[1],
nOtherCount = nAchievementCount - 1
})
end
end
if next(self.tbDictionaryEntry) ~= nil then
local nEntryCount = #self.tbDictionaryEntry
if nEntryCount == 1 then
table.insert(mapData, {
nType = AllEnum.SideBaner.DictionaryEntry,
nId = self.tbDictionaryEntry[1]
})
else
table.insert(mapData, {
nType = AllEnum.SideBaner.DictionaryEntry,
nId = self.tbDictionaryEntry[1],
nOtherCount = nEntryCount - 1
})
end
end
if next(self.tbFavour) ~= nil then
local tbChar = {}
local nFavourCount = 0
for _, v in ipairs(self.tbFavour) do
if tbChar[v] == nil then
tbChar[v] = 1
nFavourCount = nFavourCount + 1
end
end
if nFavourCount == 1 then
table.insert(mapData, {
nType = AllEnum.SideBaner.Favour,
nId = self.tbFavour[1]
})
else
table.insert(mapData, {
nType = AllEnum.SideBaner.Favour,
nId = self.tbFavour[1],
nOtherCount = nFavourCount - 1
})
end
end
if next(mapData) == nil then
return
end
self.tbDictionaryEntry = {}
self.tbAchievement = {}
self.tbFavour = {}
EventManager.Hit("OpenSideBanner", mapData)
end
function PlayerSideBannerData:AddDictionaryEntry(nId)
table.insert(self.tbDictionaryEntry, nId)
end
function PlayerSideBannerData:AddAchievement(nId)
table.insert(self.tbAchievement, nId)
end
function PlayerSideBannerData:AddFavour(nId)
table.insert(self.tbFavour, nId)
end
return PlayerSideBannerData
@@ -0,0 +1,391 @@
local PlayerSkillInstanceData = class("PlayerSkillInstanceData")
local newDayTime = UTILS.GetDayRefreshTimeOffset()
function PlayerSkillInstanceData:Init()
self.curLevel = nil
self.mapAllLevel = {}
self.bInSettlement = false
self.tbLastMaxHard = {}
self.mapLevelCfg = {}
self:InitConfigData()
EventManager.Add("Skill_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function PlayerSkillInstanceData:OnEvent_Time(nTime)
self._TotalTime = nTime
end
function PlayerSkillInstanceData:UnInit()
EventManager.Remove("Skill_Instance_Gameplay_Time", self, self.OnEvent_Time)
end
function PlayerSkillInstanceData:InitConfigData()
local funcForeachLine = function(line)
if nil == self.mapLevelCfg[line.Type] then
self.mapLevelCfg[line.Type] = {}
end
self.mapLevelCfg[line.Type][line.Id] = line
end
ForEachTableLine(ConfigTable.Get("SkillInstance"), funcForeachLine)
end
function PlayerSkillInstanceData:EnterSkillInstanceEditor(nFloor, tbChar, tbDisc, tbNote)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.SkillInstance.SkillInstanceEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nFloor, tbChar, tbDisc, tbNote)
end
end
function PlayerSkillInstanceData:EnterSkillInstance(nLevelId, nBuildId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.SkillInstance.SkillInstanceLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId)
end
end
function PlayerSkillInstanceData:SetSelBuildId(nBuildId)
self.selBuildId = nBuildId
end
function PlayerSkillInstanceData:GetCachedBuildId(nLevelId)
if self.selBuildId ~= 0 and self.selBuildId ~= nil then
local ret = self.selBuildId
return ret
end
if nLevelId == 0 then
return 0
end
if self.mapAllLevel[nLevelId] == nil then
local mapLevelCfgData = ConfigTable.GetData("SkillInstance", nLevelId)
if mapLevelCfgData == nil then
return 0
end
if mapLevelCfgData.PreLevelId ~= 0 then
if self.mapAllLevel[mapLevelCfgData.PreLevelId] ~= nil then
return self.mapAllLevel[mapLevelCfgData.PreLevelId].nBuildId
else
return 0
end
else
return 0
end
end
return self.mapAllLevel[nLevelId].nBuildId
end
function PlayerSkillInstanceData:CacheSkillInstanceLevel(tbData)
if tbData == nil then
return
end
for _, mapData in ipairs(tbData) do
local t1 = mapData.Star >= 1
local t2 = mapData.Star >= 2
local t3 = mapData.Star >= 3
local nStar = mapData.Star
self.mapAllLevel[mapData.Id] = {
nStar = nStar,
nBuildId = mapData.BuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
end
function PlayerSkillInstanceData:GetSkillInstanceLevelUnlock(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("SkillInstance", nLevelId)
if mapLevelCfgData == nil then
return false
end
if mapLevelCfgData.PreLevelId == 0 then
return true
end
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
return false, mapLevelCfgData.NeedWorldClass
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil then
return false
end
if self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar >= mapLevelCfgData.PreLevelStar then
return true
end
return false
end
function PlayerSkillInstanceData:GetSkillInstanceUnlockMsg(nLevelId)
local mapLevelCfgData = ConfigTable.GetData("SkillInstance", nLevelId)
if mapLevelCfgData.PreLevelId == 0 then
return true
end
local isWorldClass = true
if PlayerData.Base:GetWorldClass() < mapLevelCfgData.NeedWorldClass then
isWorldClass = false
end
local isPreLevelStar = true
if self.mapAllLevel[mapLevelCfgData.PreLevelId] == nil or self.mapAllLevel[mapLevelCfgData.PreLevelId].nStar < mapLevelCfgData.PreLevelStar then
isPreLevelStar = false
end
if isWorldClass == false or isPreLevelStar == false then
return false, isWorldClass, isPreLevelStar
end
return true
end
function PlayerSkillInstanceData:GetSkillInstanceStar(nLevelId)
if nLevelId == nil then
return 0, {
false,
false,
false
}
end
if self.mapAllLevel[nLevelId] == nil then
return 0, {
false,
false,
false
}
end
return self.mapAllLevel[nLevelId].nStar, self.mapAllLevel[nLevelId].tbTarget == nil and {
false,
false,
false
} or self.mapAllLevel[nLevelId].tbTarget
end
function PlayerSkillInstanceData:MsgEnterSkillInstance(nLevelId, nBuildId, callback)
self._EntryTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
self._Build_id = nBuildId
self._Level_id = nLevelId
local msg = {}
msg.Id = nLevelId
msg.BuildId = nBuildId
local msgCallback = function(_, mapChangeInfo)
self:EnterSkillInstance(nLevelId, nBuildId)
if self.mapAllLevel[nLevelId] == nil then
self.mapAllLevel[nLevelId] = {nStar = 0, nBuildId = 0}
end
self.mapAllLevel[nLevelId].nBuildId = nBuildId
if callback ~= nil then
callback(mapChangeInfo)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.skill_instance_apply_req, msg, nil, msgCallback)
end
function PlayerSkillInstanceData:MsgSettleSkillInstance(nLevelId, nBuildId, nStar, callback)
local msg = {}
msg.Star = nStar
msg.Events = {
List = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.SkillInstance, 0 < nStar)
}
local msgCallback = function(_, mapMsgData)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(mapMsgData.Change)
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
local t1 = 1 <= nStar
local t2 = 2 <= nStar
local t3 = 3 <= nStar
if self.mapAllLevel[nLevelId] ~= nil then
if self.mapAllLevel[nLevelId].nStar < nStar then
self.mapAllLevel[nLevelId].nStar = nStar
end
if self.mapAllLevel[nLevelId].tbTarget == nil then
self.mapAllLevel[nLevelId].tbTarget = {
false,
false,
false
}
end
self.mapAllLevel[nLevelId].tbTarget[1] = t1 or self.mapAllLevel[nLevelId].tbTarget[1]
self.mapAllLevel[nLevelId].tbTarget[2] = t2 or self.mapAllLevel[nLevelId].tbTarget[2]
self.mapAllLevel[nLevelId].tbTarget[3] = t3 or self.mapAllLevel[nLevelId].tbTarget[3]
else
self.mapAllLevel[nLevelId] = {
nStar = nStar,
nBuildId = nBuildId,
tbTarget = {
t1,
t2,
t3
}
}
end
if callback ~= nil then
callback(mapMsgData.AwardItems, mapMsgData.FirstItems, mapMsgData.ThreeStarItems, mapMsgData.SurpriseItems, mapMsgData.Exp, mapMsgData.Change)
end
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self._TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(self._Build_id)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(self._Level_id)
})
if 0 < nStar then
table.insert(tabUpLevel, {
"battle_result",
tostring(1)
})
else
table.insert(tabUpLevel, {
"battle_result",
tostring(2)
})
end
NovaAPI.UserEventUpload("skill_instance_battle", tabUpLevel)
end
HttpNetHandler.SendMsg(NetMsgId.Id.skill_instance_settle_req, msg, nil, msgCallback)
end
function PlayerSkillInstanceData:EventUpload(result, nLevelId, nBuildId)
self._EndTime = CS.ClientManager.Instance.serverTimeStampWithTimeZone
local tabUpLevel = {}
table.insert(tabUpLevel, {
"role_id",
tostring(PlayerData.Base._nPlayerId)
})
table.insert(tabUpLevel, {
"game_cost_time",
tostring(self._TotalTime)
})
table.insert(tabUpLevel, {
"real_cost_time",
tostring(self._EndTime - self._EntryTime)
})
table.insert(tabUpLevel, {
"build_id",
tostring(nBuildId)
})
table.insert(tabUpLevel, {
"battle_id",
tostring(nLevelId)
})
table.insert(tabUpLevel, {
"battle_result",
tostring(result)
})
NovaAPI.UserEventUpload("skill_instance_battle", tabUpLevel)
end
function PlayerSkillInstanceData:LevelEnd()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerSkillInstanceData.CalStar(nOrigin)
nOrigin = (nOrigin & 1431655765) + (nOrigin >> 1 & 1431655765)
nOrigin = (nOrigin & 858993459) + (nOrigin >> 2 & 858993459)
nOrigin = (nOrigin & 252645135) + (nOrigin >> 4 & 252645135)
nOrigin = nOrigin * 16843009 >> 24
return nOrigin
end
function PlayerSkillInstanceData:GetCurLevel()
if self.curLevel == nil then
return 0
end
return self.curLevel.nLevelId
end
function PlayerSkillInstanceData:SetLastMaxHard(nGroupId, nMaxHard)
self.tbLastMaxHard[nGroupId] = nMaxHard
end
function PlayerSkillInstanceData:GetLastMaxHard(nGroupId)
return self.tbLastMaxHard[nGroupId] or 0
end
function PlayerSkillInstanceData:GetMaxSkillInstanceHard(nType)
local retHard = 1
local tbLevelList = self.mapLevelCfg[nType]
if nil ~= tbLevelList then
for nLevelId, mapLevel in pairs(tbLevelList) do
if self:GetSkillInstanceLevelUnlock(nLevelId) then
retHard = math.max(mapLevel.Difficulty, retHard)
end
end
end
return retHard
end
function PlayerSkillInstanceData:GetLevelOpenState(nType)
local mapData = ConfigTable.GetData("SkillInstanceType", nType)
if nil ~= mapData then
local worldClass = PlayerData.Base:GetWorldClass()
local bWorldClass = worldClass >= mapData.WorldClassLevel
local bUnlock = bWorldClass
if not bWorldClass then
return AllEnum.SkillInstanceState.Not_WorldClass, bUnlock
end
return AllEnum.SkillInstanceState.Open, bUnlock
end
return AllEnum.SkillInstanceState.None
end
function PlayerSkillInstanceData:GetUnOpenTipText(nLevelState, nType)
local sTipStr = ""
if nLevelState == AllEnum.SkillInstanceState.Not_WorldClass then
local mapData = ConfigTable.GetData("SkillInstanceType", nType)
sTipStr = orderedFormat(ConfigTable.GetUIText("WorldClass_Lock") or "", mapData.WorldClassLevel)
elseif nLevelState == AllEnum.SkillInstanceState.Not_HardUnlock then
sTipStr = ConfigTable.GetUIText("Level_Lock")
end
return sTipStr
end
function PlayerSkillInstanceData:CheckLevelOpen(nType, nHard, bShowTips)
if nType == 0 then
return AllEnum.SkillInstanceState.Open
end
local nLevelState, bUnlock = self:GetLevelOpenState(nType)
if nil ~= nHard and nLevelState == AllEnum.SkillInstanceState.Open then
local nMaxUnlockHard = self:GetMaxSkillInstanceHard(nType)
if nHard > nMaxUnlockHard then
nLevelState = AllEnum.SkillInstanceState.Not_HardUnlock
end
end
if true == bShowTips then
local sTipStr = self:GetUnOpenTipText(nLevelState, nType)
if nil ~= sTipStr and "" ~= sTipStr then
EventManager.Hit(EventId.OpenMessageBox, sTipStr)
end
end
return nLevelState == AllEnum.SkillInstanceState.Open, bUnlock
end
function PlayerSkillInstanceData:SetSettlementState(bInSettlement)
self.bInSettlement = bInSettlement
end
function PlayerSkillInstanceData:GetSettlementState()
return self.bInSettlement
end
function PlayerSkillInstanceData:SendSkillInstanceRaidReq(nId, nCount, callback)
local Events = {}
local msgData = {Id = nId, Times = nCount}
if 0 < #Events then
msgData.Events = {
List = {}
}
msgData.Events.List = Events
end
local successCallback = function(_, mapMainData)
callback(mapMainData.Rewards, mapMainData.Change)
end
HttpNetHandler.SendMsg(NetMsgId.Id.skill_instance_sweep_req, msgData, nil, successCallback)
end
return PlayerSkillInstanceData
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,338 @@
local PlayerStateData = class("PlayerStateData")
function PlayerStateData:Init()
self.tbWorldClassRewardState = {}
self.tbCharAdvanceRewards = {}
self.tbCharAffinityReward = {}
self.bNewAchievement = false
self.bFriendState = false
self.bMailOverflow = false
self.bInStarTowerSweep = false
self.nVampireId = 0
end
function PlayerStateData:CacheStateData(mapMsgData)
if mapMsgData ~= nil then
self:CacheStarTowerStateData(mapMsgData.StarTower)
self:CacheCharAdvanceRewardsState(mapMsgData.CharAdvanceRewards)
self:CacheWorldClassRewardState(mapMsgData.WorldClassReward)
self:CacheAchievementState(mapMsgData.Achievement.New)
self:CacheFriendState(mapMsgData)
RedDotManager.SetValid(RedDotDefine.BattlePass_Quest_Server, nil, mapMsgData.BattlePass.State == 1 or mapMsgData.BattlePass.State == 3)
RedDotManager.SetValid(RedDotDefine.BattlePass_Reward, nil, mapMsgData.BattlePass.State >= 2)
PlayerData.Mail:UpdateMailRed(mapMsgData.Mail.New)
RedDotManager.SetValid(RedDotDefine.Mall_Free, nil, mapMsgData.MallPackage.New)
RedDotManager.SetValid(RedDotDefine.Friend_Apply, nil, mapMsgData.Friend)
RedDotManager.SetValid(RedDotDefine.Friend_Energy, nil, mapMsgData.FriendEnergy.State)
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Affinity, nil, mapMsgData.NpcAffinityReward)
PlayerData.Quest:UpdateServerQuestRedDot(mapMsgData.TravelerDuelQuest)
PlayerData.Quest:UpdateServerQuestRedDot(mapMsgData.TravelerDuelChallengeQuest)
PlayerData.InfinityTower:UpdateBountyRewardState(mapMsgData.InfinityTower)
PlayerData.StarTowerBook:UpdateServerRedDot(mapMsgData.StarTowerBook)
PlayerData.ScoreBoss:UpdateRedDot(mapMsgData.ScoreBoss)
PlayerData.Activity:UpdateActivityState(mapMsgData.Activities)
PlayerData.StorySet:UpdateStorySetState(mapMsgData.StorySet)
self.nVampireId = mapMsgData.VampireSurvivorId
else
self.bMailState = false
end
end
function PlayerStateData:CacheWorldClassRewardState(WorldClassReward)
self.tbWorldClassRewardState = {
string.byte(WorldClassReward.Flag, 1, -1)
}
PlayerData.Base:RefreshWorldClassRedDot()
end
function PlayerStateData:CacheWorldClassRewardStateInBoard(WorldClassReward)
if WorldClassReward == nil then
return
end
self.tbWorldClassRewardState = {
string.byte(WorldClassReward, 1, -1)
}
end
function PlayerStateData:CacheAchievementState(bNew)
self.bNewAchievement = bNew
end
function PlayerStateData:CacheFriendState(mapMsgData)
self.bFriendState = mapMsgData.Friend or mapMsgData.FriendEnergy.State
end
function PlayerStateData:CacheStarTowerStateData(mapData)
if mapData ~= nil then
self.mapStarTowerState = mapData
if self.mapStarTowerState.BuildId ~= 0 then
self.mapStarTowerState.Id = 0
end
if self.mapStarTowerState.Floor == 0 then
self.mapStarTowerState.Floor = 1
end
else
self.mapStarTowerState = {
BuildId = 0,
Id = 0,
Floor = 1,
Sweep = false
}
end
end
function PlayerStateData:CacheCharAdvanceRewardsState(CharAdRewards)
if CharAdRewards == nil then
return
end
if CharAdRewards == {} then
return
end
for _, v in ipairs(CharAdRewards) do
self.tbCharAdvanceRewards[v.CharId] = string.byte(v.Flag, 1, -1)
end
self:RefreshCharAdvanceRewardRedDot()
end
function PlayerStateData:CacheCharactersAdRewards_Notify(mapMsgData)
if mapMsgData == nil then
return
end
self.tbCharAdvanceRewards[mapMsgData.CharId] = string.byte(mapMsgData.Flag, 1, -1)
self:RefreshCharAdvanceRewardRedDot()
end
function PlayerStateData:GetCharAdvanceRewards(nCharId, nAdvance)
if self.tbCharAdvanceRewards[nCharId] then
return self.tbCharAdvanceRewards[nCharId] >> nAdvance - 1 & 1 == 1
else
return false
end
end
function PlayerStateData:GetCanPickedAdvanceRewards(nCharId, nMaxAdvance)
if self.tbCharAdvanceRewards[nCharId] then
for nIndex = 1, nMaxAdvance do
if self.tbCharAdvanceRewards[nCharId] >> nIndex - 1 & 1 == 1 then
return nIndex
end
end
else
return 0
end
end
function PlayerStateData:CheckState()
if self.mapStarTowerState.BuildId ~= 0 then
print("正在保存的BuildId" .. self.mapStarTowerState.BuildId)
local buildDetailcallback = function(mapBuild)
EventManager.Hit(EventId.OpenPanel, PanelId.StarTowerBuildSave, false, mapBuild)
self.mapStarTowerState.BuildId = 0
end
PlayerData.Build:GetBuildDetailData(buildDetailcallback, self.mapStarTowerState.BuildId)
return true
end
return false
end
function PlayerStateData:CheckVampireState(callback)
if self.nVampireId > 0 then
local mapVampireCfgData = ConfigTable.GetData("VampireSurvivor", self.nVampireId)
if mapVampireCfgData == nil then
if callback ~= nil and type(callback) == "function" then
callback(false)
end
self.nVampireId = 0
return
end
if mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn then
local curSeason, nLevel = PlayerData.VampireSurvivor:GetCurSeason()
if nLevel ~= self.nVampireId then
if callback ~= nil and type(callback) == "function" then
callback(false)
end
self.nVampireId = 0
return
end
end
local GetDataCallback = function()
local ConfirmCallback = function()
self.nVampireId = 0
PlayerData.VampireSurvivor:ReEnterVampireSurvivor(self.nVampireId)
end
local CancelCallback = function()
local netMsgCallback = function(_, msgData)
if mapVampireCfgData ~= nil and mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn then
PlayerData.VampireSurvivor:AddPointAndLevel(msgData.Defeat.FinalScore, 0, msgData.Defeat.SeasonId)
end
PlayerData.VampireSurvivor:CacheScoreByLevel(self.nVampireId, msgData.Defeat.FinalScore)
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("VampireReconnnect_Abandon"))
self.nVampireId = 0
end
local msg = {
KillCount = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
},
Time = 0,
Defeat = true,
Events = {
List = {}
}
}
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_survivor_settle_req, msg, nil, netMsgCallback)
end
local data = {
nType = AllEnum.MessageBox.Confirm,
sContent = orderedFormat(ConfigTable.GetUIText("VampireReconnnect_Hint") or "", mapVampireCfgData.Name),
sConfirm = ConfigTable.GetUIText("RoguelikeReenter_Yes"),
sCancel = ConfigTable.GetUIText("RoguelikeReenter_No"),
sContentSub = "",
callbackConfirm = ConfirmCallback,
callbackCancel = CancelCallback,
bCloseNoHandler = true,
bRedCancel = true
}
EventManager.Hit(EventId.OpenMessageBox, data)
end
local function success(bSuccess)
EventManager.Remove("GetTalentDataVampire", self, success)
if bSuccess then
if callback ~= nil and type(callback) == "function" then
callback(true)
end
GetDataCallback()
else
self.nVampireId = 0
printError("GetTalentDataVampire Failed")
if callback ~= nil and type(callback) == "function" then
callback(false)
end
end
end
EventManager.Add("GetTalentDataVampire", self, success)
local ret, _, _ = PlayerData.VampireSurvivor:GetTalentData()
if ret ~= nil then
success(true)
end
elseif callback ~= nil and type(callback) == "function" then
callback(false)
end
end
function PlayerStateData:GetStarTowerState()
return self.mapStarTowerState
end
function PlayerStateData:CheckStarTowerState()
if self.mapStarTowerState == nil then
return false
end
local bState = self.mapStarTowerState.Id ~= 0
if bState then
print(string.format("正在进行的遗迹:%s", self.mapStarTowerState.Id))
local nMaxCount = ConfigTable.GetConfigNumber("StarTowerReconnMaxCnt")
local confirmCallback = function()
self.mapStarTowerState.ReConnection = self.mapStarTowerState.ReConnection + 1
if self.mapStarTowerState.Sweep then
PlayerData.StarTower:ReenterTowerFastBattle()
else
PlayerData.StarTower:ReenterTower(self.mapStarTowerState.Id)
end
end
local cancelCallback = function()
local giveUpCallback = function()
PlayerData.StarTower:GiveUpReconnect(self.mapStarTowerState.Id, self.mapStarTowerState.CharIds, self.mapStarTowerState.ReConnection < nMaxCount)
end
giveUpCallback()
end
if 0 > self.mapStarTowerState.ReConnection then
local msg = {
nType = AllEnum.MessageBox.Confirm,
sContent = ConfigTable.GetUIText("Roguelike_Reenter_Hint_Clear"),
sConfirm = ConfigTable.GetUIText("RoguelikeReenter_Yes"),
sCancel = ConfigTable.GetUIText("RoguelikeReenter_No"),
callbackConfirm = confirmCallback,
callbackCancel = cancelCallback,
bCloseNoHandler = true,
bRedCancel = true
}
EventManager.Hit(EventId.OpenMessageBox, msg)
elseif nMaxCount > self.mapStarTowerState.ReConnection then
local sHint = orderedFormat(ConfigTable.GetUIText("Roguelike_Reenter_Hint") or "", nMaxCount - self.mapStarTowerState.ReConnection, nMaxCount)
local msg = {
nType = AllEnum.MessageBox.Confirm,
sContent = sHint,
sConfirm = ConfigTable.GetUIText("RoguelikeReenter_Yes"),
sCancel = ConfigTable.GetUIText("RoguelikeReenter_No"),
callbackConfirm = confirmCallback,
callbackCancel = cancelCallback,
bCloseNoHandler = true,
bRedCancel = true
}
EventManager.Hit(EventId.OpenMessageBox, msg)
else
local msg = {
nType = AllEnum.MessageBox.Alert,
sContent = ConfigTable.GetUIText("Roguelike_Reenter_Hint_Limit"),
sTitle = "",
sConfirm = ConfigTable.GetUIText("RoguelikeReenter_Yes"),
callbackConfirm = cancelCallback
}
EventManager.Hit(EventId.OpenMessageBox, msg)
end
EventManager.Hit("HaveRoguelikeState")
end
return bState
end
function PlayerStateData:GetStarTowerRecon()
return self.mapStarTowerState.ReConnection
end
function PlayerStateData:GetWorldClassRewardState()
return self.tbWorldClassRewardState
end
function PlayerStateData:ResetWorldClassRewardState(nLv)
local nIndex = math.ceil(nLv / 8)
local bActive = 1 << nLv - (nIndex - 1) * 8 - 1 & self.tbWorldClassRewardState[nIndex] > 0
if bActive then
self.tbWorldClassRewardState[nIndex] = self.tbWorldClassRewardState[nIndex] & ~(1 << nLv - (nIndex - 1) * 8 - 1)
end
PlayerData.Base:RefreshWorldClassRedDot()
end
function PlayerStateData:ResetIntervalWorldClassRewardState(nMinLevel, nMaxLevel)
for nLv = nMinLevel, nMaxLevel do
local nIndex = math.ceil(nLv / 8)
local bActive = 1 << nLv - (nIndex - 1) * 8 - 1 & self.tbWorldClassRewardState[nIndex] > 0
if bActive then
self.tbWorldClassRewardState[nIndex] = self.tbWorldClassRewardState[nIndex] & ~(1 << nLv - (nIndex - 1) * 8 - 1)
end
end
PlayerData.Base:RefreshWorldClassRedDot()
end
function PlayerStateData:ResetAllWorldClassRewardState()
for k, _ in pairs(self.tbWorldClassRewardState) do
self.tbWorldClassRewardState[k] = 0
end
PlayerData.Base:RefreshWorldClassRedDot()
end
function PlayerStateData:SetMailOverflow(bOverflow)
self.bMailOverflow = bOverflow
end
function PlayerStateData:GetMailOverflow()
return self.bMailOverflow
end
function PlayerStateData:SetStarTowerSweepState(bInSweep)
self.bInStarTowerSweep = bInSweep
end
function PlayerStateData:GetStarTowerSweepState()
return self.bInStarTowerSweep
end
function PlayerStateData:RefreshCharAdvanceRewardRedDot()
local tbAdvanceLevel = PlayerData.Char:GetAdvanceLevelTable()
for charId, v in pairs(self.tbCharAdvanceRewards) do
local charCfg = ConfigTable.GetData_Character(charId)
if nil ~= charCfg then
local nGrade = charCfg.Grade
local tbLevelAttr = tbAdvanceLevel[nGrade]
local maxAdvance = #tbLevelAttr - 1
for i = 1, maxAdvance do
local bReceive = v >> i - 1 & 1 == 1
RedDotManager.SetValid(RedDotDefine.Role_AdvanceReward, {charId, i}, bReceive)
end
end
end
end
return PlayerStateData
@@ -0,0 +1,149 @@
local PlayerStorySetData = class("PlayerStorySetData")
function PlayerStorySetData:Init()
self.tbChapter = {}
self.bGetData = false
self:InitConfig()
end
function PlayerStorySetData:InitConfig()
local funcForeachSection = function(mapData)
if nil == self.tbChapter[mapData.ChapterId] then
self.tbChapter[mapData.ChapterId] = {}
self.tbChapter[mapData.ChapterId].tbSectionList = {}
self.tbChapter[mapData.ChapterId].bUnlock = false
end
table.insert(self.tbChapter[mapData.ChapterId].tbSectionList, {
nId = mapData.Id,
nSortId = mapData.SortId,
nStatus = AllEnum.StorySetStatus.Lock
})
end
ForEachTableLine(ConfigTable.Get("StorySetSection"), funcForeachSection)
for _, v in pairs(self.tbChapter) do
if v.tbSectionList ~= nil then
table.sort(v.tbSectionList, function(a, b)
return a.nId < b.nId
end)
end
end
end
function PlayerStorySetData:UnInit()
end
function PlayerStorySetData:UpdateStorySetState(bState)
RedDotManager.SetValid(RedDotDefine.Story_Set_Server, nil, bState)
end
function PlayerStorySetData:CacheStorySetData(netMsg)
if netMsg.Chapters ~= nil then
for _, data in ipairs(netMsg.Chapters) do
if self.tbChapter[data.ChapterId] ~= nil then
self.tbChapter[data.ChapterId].bUnlock = true
local nCurIndex = data.SectionIndex or 0
nCurIndex = nCurIndex + 1
local bShow = false
local mapChapterCfg = ConfigTable.GetData("StorySetChapter", data.ChapterId)
if mapChapterCfg ~= nil then
bShow = mapChapterCfg.IsShow
end
for nIndex, v in ipairs(self.tbChapter[data.ChapterId].tbSectionList) do
if nIndex <= nCurIndex then
v.nStatus = AllEnum.StorySetStatus.UnLock
end
if 0 < table.indexof(data.RewardedIds, v.nId) then
v.nStatus = AllEnum.StorySetStatus.Received
end
RedDotManager.SetValid(RedDotDefine.Story_Set_Section, {
data.ChapterId,
v.nId
}, v.nStatus == AllEnum.StorySetStatus.UnLock and bShow)
end
end
end
end
end
function PlayerStorySetData:UnlockNewChapter(nId)
if self.tbChapter[nId] ~= nil then
self.tbChapter[nId].bUnlock = true
local bShow = false
local mapCfg = ConfigTable.GetData("StorySetChapter", nId)
if mapCfg ~= nil then
bShow = mapCfg.IsShow
end
for k, v in ipairs(self.tbChapter[nId].tbSectionList) do
if k == 1 then
v.nStatus = AllEnum.StorySetStatus.UnLock
RedDotManager.SetValid(RedDotDefine.Story_Set_Section, {
nId,
v.nId
}, bShow)
break
end
end
end
end
function PlayerStorySetData:GetAllChapterList()
local tbChapter = {}
for nId, v in pairs(self.tbChapter) do
local mapCfg = ConfigTable.GetData("StorySetChapter", nId)
if mapCfg ~= nil and mapCfg.IsShow then
table.insert(tbChapter, {
nId = nId,
tbSectionList = v.tbSectionList,
bUnlock = v.bUnlock
})
end
end
table.sort(tbChapter, function(a, b)
return a.nId < b.nId
end)
return tbChapter
end
function PlayerStorySetData:TryOpenStorySetPanel(callback)
if not self.bGetData then
self:SendGetStorySetData(callback)
elseif callback ~= nil then
callback()
end
end
function PlayerStorySetData:SendGetStorySetData(callback)
local func_cb = function(_, netMsg)
RedDotManager.SetValid(RedDotDefine.Story_Set_Server, nil, false)
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.story_set_info_req, {}, nil, func_cb)
end
function PlayerStorySetData:ReceiveStorySetReward(nChapterId, nSectionId, callback)
local func_cb = function(_, netMsg)
if self.tbChapter[nChapterId] ~= nil then
local nIndex = 0
for k, v in ipairs(self.tbChapter[nChapterId].tbSectionList) do
if v.nId == nSectionId then
nIndex = k
break
end
end
if nIndex ~= 0 then
self.tbChapter[nChapterId].tbSectionList[nIndex].nStatus = AllEnum.StorySetStatus.Received
RedDotManager.SetValid(RedDotDefine.Story_Set_Section, {nChapterId, nSectionId}, false)
nIndex = nIndex + 1
end
if nIndex <= #self.tbChapter[nChapterId].tbSectionList then
self.tbChapter[nChapterId].tbSectionList[nIndex].nStatus = AllEnum.StorySetStatus.UnLock
local bShow = false
local mapCfg = ConfigTable.GetData("StorySetChapter", nChapterId)
if mapCfg ~= nil then
bShow = mapCfg.IsShow
end
local nId = self.tbChapter[nChapterId].tbSectionList[nIndex].nId
RedDotManager.SetValid(RedDotDefine.Story_Set_Section, {nChapterId, nId}, bShow)
end
end
if callback ~= nil then
callback(netMsg)
end
EventManager.Hit("ReceiveStorySetRewardSuc")
end
local msg = {ChapterId = nChapterId, SectionId = nSectionId}
HttpNetHandler.SendMsg(NetMsgId.Id.story_set_reward_receive_req, msg, nil, func_cb)
end
return PlayerStorySetData
@@ -0,0 +1,598 @@
local PlayerTalentData = class("PlayerTalentData")
local TimerManager = require("GameCore.Timer.TimerManager")
function PlayerTalentData:Init()
self._tbCharTalentGroup = {}
self._tbCharTalentNode = {}
self._tbCharEnhancedSkill = {}
self._tbCharEnhancedPotential = {}
self._tbCharFateTalent = {}
self._tbTalentBgIndex = {}
self:ProcessTableData()
end
function PlayerTalentData:ProcessTableData()
local func_ForEach_Group = function(mapData)
CacheTable.SetField("_TalentGroup", mapData.CharId, mapData.Id, mapData)
end
ForEachTableLine(DataTable.TalentGroup, func_ForEach_Group)
local func_ForEach_Line = function(mapData)
CacheTable.SetField("_Talent", mapData.GroupId, mapData.Id, mapData)
local nCharId = ConfigTable.GetData("TalentGroup", mapData.GroupId).CharId
CacheTable.SetField("_TalentByIndex", nCharId, mapData.Index, mapData)
end
ForEachTableLine(DataTable.Talent, func_ForEach_Line)
self.FragmentsToChar = {}
local func_ForEach_Char = function(mapData)
self.FragmentsToChar[mapData.FragmentsId] = mapData.Id
end
ForEachTableLine(DataTable.Character, func_ForEach_Char)
end
function PlayerTalentData:CreateNewTalentData(nCharId, tbActive)
local tbActiveTalent = {}
local nMaxNormalCount = 0
local groupData = {}
local nFirstGroup = 0
local tbGroupCfg = CacheTable.GetData("_TalentGroup", nCharId)
if not tbGroupCfg then
printError("TalentGroup表找不到该角色" .. nCharId)
tbGroupCfg = {}
end
for nGroupId, mapGroup in pairs(tbGroupCfg) do
local mapCurGroup = groupData[nGroupId] or self:CreateTalentGroup(nGroupId)
groupData[nGroupId] = mapCurGroup
if mapGroup.PreGroup ~= 0 then
local mapPreGroup = groupData[mapGroup.PreGroup]
if not mapPreGroup then
mapPreGroup = self:CreateTalentGroup(mapGroup.PreGroup)
groupData[mapGroup.PreGroup] = mapPreGroup
end
mapPreGroup.nNext = nGroupId
else
nFirstGroup = nGroupId
end
nMaxNormalCount = nMaxNormalCount + mapGroup.NodeLimit
local tbTalent = CacheTable.GetData("_Talent", nGroupId) or {}
for _, v in pairs(tbTalent) do
if v.Type == GameEnum.talentType.KeyNode then
groupData[nGroupId].nKeyTalent = v.Id
break
end
end
end
if type(tbActive) == "table" then
for _, nTalentId in pairs(tbActive) do
tbActiveTalent[nTalentId] = true
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
local nType = mapCfg.Type
if nType == GameEnum.talentType.OrdinaryNode then
groupData[mapCfg.GroupId].nNormalCount = groupData[mapCfg.GroupId].nNormalCount + 1
end
end
end
local nAllCount = 0
for _, v in pairs(groupData) do
nAllCount = nAllCount + v.nNormalCount
end
local talentData = {
nMaxNormalCount = nMaxNormalCount,
nFirstGroup = nFirstGroup,
tbActiveTalent = tbActiveTalent,
nAllNormalCount = nAllCount
}
return talentData, groupData
end
function PlayerTalentData:CreateTalentGroup(nId)
return {
nId = nId,
nNext = 0,
nKeyTalent = 0,
bLock = true,
nNormalCount = 0
}
end
function PlayerTalentData:UpdateTalentGroupLock(nCharId)
local bPreGroupLock = false
local bPreKeyLock = false
local nGroupId = self._tbCharTalentNode[nCharId].nFirstGroup
local mapCurGroup = self._tbCharTalentGroup[nCharId][nGroupId]
while mapCurGroup do
local nKeyTalent = mapCurGroup.nKeyTalent
local bLock = bPreGroupLock or bPreKeyLock
self._tbCharTalentGroup[nCharId][mapCurGroup.nId].bLock = bLock
mapCurGroup = self._tbCharTalentGroup[nCharId][mapCurGroup.nNext]
bPreKeyLock = not self._tbCharTalentNode[nCharId].tbActiveTalent[nKeyTalent]
bPreGroupLock = bLock
end
end
function PlayerTalentData:CreateEnhancedSkill(nCharId, tbTalentId)
local charCfgData = ConfigTable.GetData_Character(nCharId)
if not charCfgData then
printError("Character表找不到该角色" .. nCharId)
return {}
end
local mapSkill = {
[charCfgData.NormalAtkId] = 0,
[charCfgData.SkillId] = 0,
[charCfgData.AssistSkillId] = 0,
[charCfgData.UltimateId] = 0
}
for _, v in pairs(tbTalentId) do
local mapCfg = ConfigTable.GetData("Talent", v)
local nSkillId = mapCfg.EnhanceSkillId
if 0 < nSkillId and mapSkill[nSkillId] then
mapSkill[nSkillId] = mapSkill[nSkillId] + mapCfg.EnhanceSkillLevel
end
end
return mapSkill
end
function PlayerTalentData:CreateEnhancedPotential(tbTalentId)
local mapPotential = {}
for _, v in pairs(tbTalentId) do
local mapCfg = ConfigTable.GetData("Talent", v)
local nPotentialId = mapCfg.EnhancePotentialId
if 0 < nPotentialId then
if not mapPotential[nPotentialId] then
mapPotential[nPotentialId] = 0
end
mapPotential[nPotentialId] = mapPotential[nPotentialId] + mapCfg.EnhancePotentialLevel
end
end
return mapPotential
end
function PlayerTalentData:CreateFateTalent(tbAllTalent)
local nFateCount = 0
local tbFateTypeTalent = {}
for nIndex, v in pairs(tbAllTalent) do
if v.Type == GameEnum.talentType.KeyNode and 0 < v.SubType then
nFateCount = nFateCount + 1
tbFateTypeTalent[v.SubType] = v.Id
end
end
local tbFateTalent = {}
for i = 1, nFateCount do
local nId = tbFateTypeTalent[GameEnum.talentSubType["Fate" .. i]]
tbFateTalent[i] = nId
end
return tbFateTalent
end
function PlayerTalentData:CacheTalentData(mapMsgData, nTalentResetTime)
if self._tbCharTalentNode == nil then
self._tbCharTalentNode = {}
end
if self._tbCharTalentGroup == nil then
self._tbCharTalentGroup = {}
end
for _, mapCharInfo in ipairs(mapMsgData) do
local nCharId = mapCharInfo.Tid
local tbTalent = CacheTable.GetData("_TalentByIndex", nCharId)
if tbTalent == nil then
printError("Talent表找不到该角色" .. nCharId)
tbTalent = {}
end
local tbActive = {}
local tbNodes = UTILS.ParseByteString(mapCharInfo.TalentNodes)
for nIndex, v in pairs(tbTalent) do
local bActive = UTILS.IsBitSet(tbNodes, nIndex)
if bActive then
table.insert(tbActive, v.Id)
end
end
local talentData, groupData = self:CreateNewTalentData(nCharId, tbActive)
self._tbCharTalentNode[nCharId] = talentData
self._tbCharTalentGroup[nCharId] = groupData
self._tbCharEnhancedSkill[nCharId] = self:CreateEnhancedSkill(nCharId, tbActive)
self._tbCharEnhancedPotential[nCharId] = self:CreateEnhancedPotential(tbActive)
self._tbCharFateTalent[nCharId] = self:CreateFateTalent(tbTalent)
self._tbTalentBgIndex[nCharId] = mapCharInfo.TalentBackground
self:UpdateTalentGroupLock(nCharId)
end
end
function PlayerTalentData:ResetTalentEnhanceLevel(nCharId, mapCfg)
local nSkillId = mapCfg.EnhanceSkillId
if 0 < nSkillId and self._tbCharEnhancedSkill[nCharId][nSkillId] then
self._tbCharEnhancedSkill[nCharId][nSkillId] = self._tbCharEnhancedSkill[nCharId][nSkillId] - mapCfg.EnhanceSkillLevel
end
local nPotentialId = mapCfg.EnhancePotentialId
if 0 < nPotentialId and self._tbCharEnhancedPotential[nCharId][nPotentialId] then
self._tbCharEnhancedPotential[nCharId][nPotentialId] = self._tbCharEnhancedPotential[nCharId][nPotentialId] - mapCfg.EnhancePotentialLevel
end
end
function PlayerTalentData:ResetTalentNode(nCharId, nTalentId, bResetKey)
self._tbCharTalentNode[nCharId].nAllNormalCount = self._tbCharTalentNode[nCharId].nAllNormalCount - 1
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
local nGroupId = mapCfg.GroupId
self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount = self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount - 1
if self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] then
self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] = false
self:ResetTalentEnhanceLevel(nCharId, mapCfg)
end
if bResetKey then
local tbTalent = CacheTable.GetData("_Talent", nGroupId)
for k, v in pairs(tbTalent) do
if v.Type == GameEnum.talentType.KeyNode and self._tbCharTalentNode[nCharId].tbActiveTalent[k] then
self._tbCharTalentNode[nCharId].tbActiveTalent[k] = false
self:ResetTalentEnhanceLevel(nCharId, v)
end
end
end
self:UpdateTalentGroupLock(nCharId)
end
function PlayerTalentData:ResetTalent(nCharId, nGroupId)
local tbTalent = CacheTable.GetData("_Talent", nGroupId)
self._tbCharTalentNode[nCharId].nAllNormalCount = self._tbCharTalentNode[nCharId].nAllNormalCount - self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount
self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount = 0
for nTalentId, v in pairs(tbTalent) do
if self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] then
self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] = false
self:ResetTalentEnhanceLevel(nCharId, v)
end
end
self:UpdateTalentGroupLock(nCharId)
end
function PlayerTalentData:ResetAllTalent(nCharId)
local tbGroup = CacheTable.GetData("_TalentGroup", nCharId)
self._tbCharTalentNode[nCharId].nAllNormalCount = 0
self._tbCharTalentNode[nCharId].tbActiveTalent = {}
for nId, _ in pairs(tbGroup) do
self._tbCharTalentGroup[nCharId][nId].nNormalCount = 0
end
self:UpdateTalentGroupLock(nCharId)
for k, _ in pairs(self._tbCharEnhancedSkill[nCharId]) do
self._tbCharEnhancedSkill[nCharId][k] = 0
end
for k, _ in pairs(self._tbCharEnhancedPotential[nCharId]) do
self._tbCharEnhancedPotential[nCharId][k] = 0
end
end
function PlayerTalentData:UnlockTalent(nCharId, nTalentId)
self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] = true
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
local nGroupId = mapCfg.GroupId
if mapCfg.Type == GameEnum.talentType.KeyNode then
self:UpdateTalentGroupLock(nCharId)
else
self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount = self._tbCharTalentGroup[nCharId][nGroupId].nNormalCount + 1
self._tbCharTalentNode[nCharId].nAllNormalCount = self._tbCharTalentNode[nCharId].nAllNormalCount + 1
end
local nSkillId = mapCfg.EnhanceSkillId
if 0 < nSkillId then
if not self._tbCharEnhancedSkill[nCharId][nSkillId] then
self._tbCharEnhancedSkill[nCharId][nSkillId] = 0
end
self._tbCharEnhancedSkill[nCharId][nSkillId] = self._tbCharEnhancedSkill[nCharId][nSkillId] + mapCfg.EnhanceSkillLevel
end
local nPotentialId = mapCfg.EnhancePotentialId
if 0 < nPotentialId then
if not self._tbCharEnhancedPotential[nCharId][nPotentialId] then
self._tbCharEnhancedPotential[nCharId][nPotentialId] = 0
end
self._tbCharEnhancedPotential[nCharId][nPotentialId] = self._tbCharEnhancedPotential[nCharId][nPotentialId] + mapCfg.EnhancePotentialLevel
end
end
function PlayerTalentData:SetTimer(nTime)
if nTime <= 0 then
return
end
local stopcd = function()
if self.timercd ~= nil then
self.timercd:Cancel(false)
self.timercd = nil
end
self.nCd = 0
end
self.bTalentResetCD = true
if self.timer ~= nil then
self.timer:Cancel(false)
self.timer = nil
stopcd()
end
self.nCd = nTime
self.timer = TimerManager.Add(1, nTime, self, function()
self.bTalentResetCD = false
stopcd()
end, true, true, false)
self.timercd = TimerManager.Add(0, 1, self, function()
self.nCd = self.nCd - 1
end, true, true, false)
end
function PlayerTalentData:GetTalentNode(nCharId)
return self._tbCharTalentNode[nCharId]
end
function PlayerTalentData:GetTalentGroup(nCharId)
return self._tbCharTalentGroup[nCharId]
end
function PlayerTalentData:GetTalentBg(nCharId)
return self._tbTalentBgIndex[nCharId]
end
function PlayerTalentData:GetSortedTalentGroup(nCharId)
local tbSorted = {}
local nFirstGroup = self._tbCharTalentNode[nCharId].nFirstGroup
local mapCurGroup = self._tbCharTalentGroup[nCharId][nFirstGroup]
while mapCurGroup do
table.insert(tbSorted, mapCurGroup)
mapCurGroup = self._tbCharTalentGroup[nCharId][mapCurGroup.nNext]
end
return tbSorted
end
function PlayerTalentData:GetEnhancedSkill(nCharId)
return self._tbCharEnhancedSkill[nCharId]
end
function PlayerTalentData:GetEnhancedPotential(nCharId)
return self._tbCharEnhancedPotential[nCharId]
end
function PlayerTalentData:GetFateTalent(nCharId)
local tbFate = {}
if not self._tbCharFateTalent[nCharId] then
return tbFate
end
for i, v in ipairs(self._tbCharFateTalent[nCharId]) do
tbFate[i] = self:CheckTalentActive(nCharId, v)
end
return tbFate
end
function PlayerTalentData:GetFateTalentByTalentNodes(nCharId, tbActive)
local tbFate = {}
if not self._tbCharFateTalent[nCharId] then
return tbFate
end
for i, v in ipairs(self._tbCharFateTalent[nCharId]) do
tbFate[i] = table.indexof(tbActive, v) > 0
end
return tbFate
end
function PlayerTalentData:GetFragmentsToChar(nFragmentsId)
return self.FragmentsToChar[nFragmentsId]
end
function PlayerTalentData:GetOverFragments(nCharId)
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
local mapGradeCfg = ConfigTable.GetData("CharGrade", mapCharCfg.Grade)
local mapChar = PlayerData.Char:GetCharDataByTid(nCharId)
local nCompositeFragments = 0
if mapChar == nil then
nCompositeFragments = mapCharCfg.RecruitmentQty
end
local nNodeFragments = mapGradeCfg.FragmentsQty
local mapTalent = self._tbCharTalentNode[nCharId]
local nNodeCount = 0
if mapTalent then
nNodeCount = mapTalent.nMaxNormalCount - mapTalent.nAllNormalCount
end
local nHas = PlayerData.Item:GetItemCountByID(mapCharCfg.FragmentsId)
local nOverflow = nHas - nNodeCount * nNodeFragments - nCompositeFragments
return 0 < nOverflow and nOverflow or 0
end
function PlayerTalentData:GetRemainFragments(nCharId, nHas)
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
local mapGradeCfg = ConfigTable.GetData("CharGrade", mapCharCfg.Grade)
local nNodeFragments = mapGradeCfg.FragmentsQty
local nMaxNormalCount = 0
local tbGroupCfg = CacheTable.GetData("_TalentGroup", nCharId)
if not tbGroupCfg then
printError("TalentGroup表找不到该角色" .. nCharId)
tbGroupCfg = {}
end
for _, mapGroup in pairs(tbGroupCfg) do
nMaxNormalCount = nMaxNormalCount + mapGroup.NodeLimit
end
nHas = nHas or PlayerData.Item:GetItemCountByID(mapCharCfg.FragmentsId)
local mapTalent = self:GetTalentNode(nCharId)
local nCompositeFragments = mapCharCfg.RecruitmentQty
local nRemain = mapTalent and (nMaxNormalCount - mapTalent.nAllNormalCount) * nNodeFragments - nHas or nMaxNormalCount * nNodeFragments + nCompositeFragments - nHas
return nRemain, mapTalent == nil
end
function PlayerTalentData:CheckTalentActive(nCharId, nTalentId)
if self._tbCharTalentNode[nCharId] and self._tbCharTalentNode[nCharId].tbActiveTalent[nTalentId] then
return true
end
return false
end
function PlayerTalentData:GetTalentEffect(nCharId)
local mapTalent = self._tbCharTalentNode[nCharId]
local tbEffect = {}
if mapTalent then
for nTalentId, bActive in pairs(mapTalent.tbActiveTalent) do
if bActive then
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
for _, nEffectId in pairs(mapCfg.EffectId) do
table.insert(tbEffect, nEffectId)
end
end
end
end
return tbEffect
end
function PlayerTalentData:GetTalentAttributeDesc(nTalentId)
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
local tbDesc = {}
for _, nEffectId in pairs(mapCfg.EffectId) do
local configEffect = ConfigTable.GetData_Effect(nEffectId)
local config = ConfigTable.GetData("EffectValue", nEffectId)
local bAttrFix = config.EffectType == GameEnum.effectType.ATTR_FIX or config.EffectType == GameEnum.effectType.PLAYER_ATTR_FIX
if bAttrFix and configEffect.Trigger == GameEnum.trigger.NOTHING then
local nEffectDescId = GameEnum.effectType.ATTR_FIX * 10000 + config.EffectTypeFirstSubtype * 10 + config.EffectTypeSecondSubtype
local configDesc = ConfigTable.GetData("EffectDesc", nEffectDescId)
local nValue = tonumber(config.EffectTypeParam1) or 0
table.insert(tbDesc, {nEftDescId = nEffectDescId, nValueNum = nValue})
end
end
return tbDesc
end
function PlayerTalentData:UpdateAllCharTalentRedDot()
for charId, v in pairs(self._tbCharTalentNode) do
self:UpdateCharTalentRedDot(charId)
end
end
function PlayerTalentData:UpdateCharTalentRedDotByItem(mapChange)
for _, v in ipairs(mapChange) do
local charId = self.FragmentsToChar[v.Tid]
if charId and v.Qty > 0 then
self:UpdateCharTalentRedDot(charId)
end
end
end
function PlayerTalentData:UpdateCharTalentRedDot(nCharId)
local mapTalent = self._tbCharTalentNode[nCharId]
if not mapTalent then
return
end
local bValid = false
if mapTalent.nMaxNormalCount > mapTalent.nAllNormalCount then
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
local mapGradeCfg = ConfigTable.GetData("CharGrade", mapCharCfg.Grade)
local nFragmentCount = PlayerData.Item:GetItemCountByID(mapCharCfg.FragmentsId)
if nFragmentCount >= mapGradeCfg.FragmentsQty then
bValid = true
end
end
RedDotManager.SetValid(RedDotDefine.Role_Talent, nCharId, bValid)
end
function PlayerTalentData:SendTalentUnlockReq(nCharId, nTalentId, callback)
local msgData = {Value = nTalentId}
local successCallback = function(_, mapMainData)
local bKey = false
if mapMainData.TalentId and mapMainData.TalentId > 0 then
self:UnlockTalent(nCharId, mapMainData.TalentId)
bKey = true
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
if mapCfg then
local mapGroup = ConfigTable.GetData("TalentGroup", mapCfg.GroupId)
if mapGroup then
self._tbTalentBgIndex[nCharId] = mapGroup.Background
end
end
end
self:UnlockTalent(nCharId, nTalentId)
self:UpdateCharTalentRedDot(nCharId)
callback(bKey)
end
HttpNetHandler.SendMsg(NetMsgId.Id.talent_unlock_req, msgData, nil, successCallback)
end
function PlayerTalentData:SendTalentResetReq(nCharId, nGroupId, callback)
if self.bTalentResetCD then
EventManager.Hit(EventId.OpenMessageBox, orderedFormat(ConfigTable.GetUIText("CharTalent_CD"), self.nCd))
return
end
local msgData = {CharId = nCharId, GroupId = nGroupId}
local successCallback = function(_, mapMainData)
self:SetTimer(ConfigTable.GetConfigNumber("TalentResetTimeInterval") * 60)
if nGroupId == 0 then
self:ResetAllTalent(nCharId)
else
self:ResetTalent(nCharId, nGroupId)
end
self:UpdateCharTalentRedDot(nCharId)
UTILS.OpenReceiveByChangeInfo(mapMainData, nil, ConfigTable.GetUIText("CharTalent_ResetReceiveTip"))
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.talent_reset_req, msgData, nil, successCallback)
end
function PlayerTalentData:SendTalentNodeResetReq(nCharId, nId, callback)
local msgData = {Value = nId}
local successCallback = function(_, mapMainData)
self:ResetTalentNode(nCharId, nId, mapMainData.ResetKeyNode)
self:UpdateCharTalentRedDot(nCharId)
UTILS.OpenReceiveByChangeInfo(mapMainData.Change, callback, ConfigTable.GetUIText("CharTalent_ResetReceiveTip"))
end
HttpNetHandler.SendMsg(NetMsgId.Id.talent_node_reset_req, msgData, nil, successCallback)
end
function PlayerTalentData:SendTalentBackgroundSetReq(nCharId, nGroupId, callback)
local msgData = {GroupId = nGroupId, CharId = nCharId}
if nGroupId ~= 0 then
msgData.CharId = 0
end
local successCallback = function(_, mapMainData)
if nGroupId == 0 then
self._tbTalentBgIndex[nCharId] = 0
else
local mapGroup = ConfigTable.GetData("TalentGroup", nGroupId)
if mapGroup then
self._tbTalentBgIndex[nCharId] = mapGroup.Background
end
end
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.talent_background_set_req, msgData, nil, successCallback)
end
function PlayerTalentData:SendTalentGroupUnlockSetReq(nCharId, nGroupId, callback)
local msgData = {Value = nGroupId}
local successCallback = function(_, mapMainData)
local mapGroup = ConfigTable.GetData("TalentGroup", nGroupId)
if mapGroup then
self._tbTalentBgIndex[nCharId] = mapGroup.Background
end
for _, v in pairs(mapMainData.Nodes) do
self:UnlockTalent(nCharId, v)
end
self:UpdateCharTalentRedDot(nCharId)
callback()
end
HttpNetHandler.SendMsg(NetMsgId.Id.talent_group_unlock_req, msgData, nil, successCallback)
end
function PlayerTalentData:CreateTrialData(tbTrialId)
self._tbTrialTalentNode = {}
self._tbTrialEnhancedSkill = {}
self._tbTrialEnhancedPotential = {}
self._tbTrialFateTalent = {}
for _, nTrialId in ipairs(tbTrialId) do
local mapCfg = ConfigTable.GetData("TrialCharacter", nTrialId)
if mapCfg == nil then
printError("体验角色数据没有找到:" .. nTrialId)
return
end
local nCharId = mapCfg.CharId
local tbActive = mapCfg.Talent
self._tbTrialTalentNode[nTrialId] = {}
for _, v in ipairs(tbActive) do
self._tbTrialTalentNode[nTrialId][v] = true
end
self._tbTrialEnhancedSkill[nTrialId] = self:CreateEnhancedSkill(nCharId, tbActive)
self._tbTrialEnhancedPotential[nTrialId] = self:CreateEnhancedPotential(tbActive)
local tbTalent = CacheTable.GetData("_TalentByIndex", nCharId)
if tbTalent == nil then
printError("Talent表找不到该角色" .. nCharId)
tbTalent = {}
end
self._tbTrialFateTalent[nTrialId] = self:CreateFateTalent(tbTalent)
end
end
function PlayerTalentData:DeleteTrialData()
self._tbTrialTalentNode = {}
self._tbTrialEnhancedSkill = {}
self._tbTrialEnhancedPotential = {}
self._tbTrialFateTalent = {}
end
function PlayerTalentData:GetTrialEnhancedSkill(nTrialId)
return self._tbTrialEnhancedSkill[nTrialId]
end
function PlayerTalentData:GetTrialEnhancedPotential(nTrialId)
return self._tbTrialEnhancedPotential[nTrialId]
end
function PlayerTalentData:GetTrialFateTalent(nTrialId)
local tbFate = {}
if not self._tbTrialFateTalent[nTrialId] then
return tbFate
end
for i, v in ipairs(self._tbTrialFateTalent[nTrialId]) do
if self._tbTrialTalentNode[nTrialId] and self._tbTrialTalentNode[nTrialId][v] then
tbFate[i] = true
else
tbFate[i] = false
end
end
return tbFate
end
function PlayerTalentData:GetTrialTalentEffect(nTrialId)
local mapTalent = self._tbTrialTalentNode[nTrialId]
local tbEffect = {}
if mapTalent then
for nTalentId, bActive in pairs(mapTalent) do
if bActive then
local mapCfg = ConfigTable.GetData("Talent", nTalentId)
for _, nEffectId in pairs(mapCfg.EffectId) do
table.insert(tbEffect, nEffectId)
end
end
end
end
return tbEffect
end
return PlayerTalentData
@@ -0,0 +1,156 @@
local PlayerTeamData = class("PlayerTeamData")
function PlayerTeamData:Init()
self._tbTeam = nil
end
function PlayerTeamData:CacheFormationInfo(mapData)
if mapData == nil then
return
end
if self._tbTeam == nil then
self._tbTeam = {}
for i = 1, AllEnum.Const.MAX_TEAM_COUNT do
self._tbTeam[i] = {
nCaptainIndex = 0,
tbTeamMemberId = {
0,
0,
0
},
tbTeamDiscId = {
0,
0,
0
}
}
end
end
if mapData.Info ~= nil then
for k, v in pairs(mapData.Info) do
local nTeamId = v.Number
local mapTeamData = self._tbTeam[nTeamId]
if mapTeamData ~= nil then
mapTeamData.nCaptainIndex = 1
else
mapTeamData = {
nCaptainIndex = 1,
tbTeamMemberId = {
0,
0,
0
},
tbTeamDiscId = {
0,
0,
0
}
}
end
for nIndex, nCharId in ipairs(v.CharIds) do
mapTeamData.tbTeamMemberId[nIndex] = nCharId
end
for nIndex, nDiscId in ipairs(v.DiscIds) do
mapTeamData.tbTeamDiscId[nIndex] = nDiscId
end
end
end
end
function PlayerTeamData:UpdateFormationInfo(nTeamId, tbCharIds, tbDiscIds, callback)
local PlayerFormationReq = {}
PlayerFormationReq.Formation = {}
PlayerFormationReq.Formation.Number = nTeamId
PlayerFormationReq.Formation.Captain = 1
PlayerFormationReq.Formation.CharIds = tbCharIds
PlayerFormationReq.Formation.DiscIds = tbDiscIds
local Callback = function()
if self._tbTeam == nil then
self._tbTeam = {}
end
local mapTeamData = self._tbTeam[nTeamId]
mapTeamData.nCaptainIndex = 1
for nIndex, nCharId in ipairs(tbCharIds) do
mapTeamData.tbTeamMemberId[nIndex] = nCharId
end
if tbDiscIds then
for nIndex, nDiscId in ipairs(tbDiscIds) do
mapTeamData.tbTeamDiscId[nIndex] = nDiscId
end
end
if callback ~= nil and type(callback) == "function" then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.player_formation_req, PlayerFormationReq, nil, Callback)
end
function PlayerTeamData:GetTeamData(nTeamId)
if self._tbTeam == nil then
return nil, nil
end
local mapTeamData = self._tbTeam[nTeamId]
if mapTeamData ~= nil then
return mapTeamData.nCaptainIndex, mapTeamData.tbTeamMemberId
else
return nil, nil
end
end
function PlayerTeamData:GetTeamDiscData(nTeamId)
if self._tbTeam == nil then
return {
0,
0,
0,
0,
0,
0
}
end
local mapTeamData = self._tbTeam[nTeamId]
if mapTeamData ~= nil then
return mapTeamData.tbTeamDiscId
else
return {
0,
0,
0,
0,
0,
0
}
end
end
function PlayerTeamData:GetTeamCharId(nTeamId)
local mapTeamData = self._tbTeam[nTeamId]
local tbCharId = {}
if mapTeamData ~= nil then
local nCaptainId = mapTeamData.tbTeamMemberId[mapTeamData.nCaptainIndex]
table.insert(tbCharId, nCaptainId)
for _nIdx, _nCharId in ipairs(mapTeamData.tbTeamMemberId) do
if _nCharId ~= 0 and _nCharId ~= nCaptainId then
table.insert(tbCharId, _nCharId)
end
end
end
return tbCharId
end
function PlayerTeamData:CheckTeamValid(nTeamId)
if self._tbTeam == nil then
return false
end
local mapTeam = self._tbTeam[nTeamId]
if mapTeam == nil then
return false
elseif type(mapTeam.tbTeamMemberId) == "table" then
for i, nCharId in ipairs(mapTeam.tbTeamMemberId) do
if nCharId < 1 then
return false
end
end
return true
else
return false
end
end
function PlayerTeamData:TempCreateRoguelikeTeam(tbTeamCharId)
self._tbTeam = {}
self._tbTeam[5] = {nCaptainIndex = 1, tbTeamMemberId = tbTeamCharId}
end
return PlayerTeamData
@@ -0,0 +1,405 @@
local PlayerTravelerDuelData = class("PlayerTravelerDuelData")
function PlayerTravelerDuelData:Init()
self.rankingRefreshTime = 610
self.bClassChange = false
self.oldLevel = 0
self.oldExp = 0
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
self.bHasData = false
self.curLevel = nil
self.nDuelLevel = 0
self.selBuildId = 0
self.nDuelExp = 0
self.mapBossLevel = {}
self.RankingData = {}
self.SelfRankingData = {}
self.LastRankingRefreshTime = 0
self.UploadRemainTimes = 0
self.mapCurChallenge = {
bLock = false,
nIdx = 0,
nOpenTime = 0,
nCloseTime = 0
}
end
function PlayerTravelerDuelData:UnInit()
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerTravelerDuelData:CacheTravelerDuelData(mapDuelData)
self.nDuelLevel = mapDuelData.DuelLevel
self.nDuelExp = mapDuelData.DuelExp
self.WeeklyAwardTimes = mapDuelData.WeeklyAwardTimes
self:CacheTravelerDuelLevelData(mapDuelData)
self.mapCurChallenge.bUnlock = mapDuelData.Challenge.Unlock
if mapDuelData.Challenge.Id == 0 then
printError("season idx == 0")
else
self.mapCurChallenge.nIdx = mapDuelData.Challenge.Id
end
self.mapCurChallenge.nOpenTime = mapDuelData.Challenge.OpenTime
self.mapCurChallenge.nCloseTime = mapDuelData.Challenge.CloseTime
PlayerData.Quest:CacheAllQuest(mapDuelData.Quests.List)
end
function PlayerTravelerDuelData:CacheTravelerDuelLevelData(mapDuelData)
for _, mapBossLevel in ipairs(mapDuelData.Levels) do
self.mapBossLevel[mapBossLevel.Id] = {
nStar = mapBossLevel.Star,
nLastBuildId = mapBossLevel.BuildId,
nMaxDifficulty = mapBossLevel.Difficulty
}
end
end
function PlayerTravelerDuelData:CacheTravelerDuelRankingData(mapDuelData)
self.SelfRankingData = mapDuelData.Self
self.RankingData = mapDuelData.Rank
self.LastRankingRefreshTime = mapDuelData.LastRefreshTime
self.UploadRemainTimes = mapDuelData.UploadRemainTimes
if self.SelfRankingData ~= nil then
self.SelfRankingData.nRewardIdx = self:GetRewardIdx(self.SelfRankingData.Rank)
end
local nSelfuid = PlayerData.Base:GetPlayerId()
for _, mapRankingData in ipairs(self.RankingData) do
mapRankingData.nRewardIdx = self:GetRewardIdx(mapRankingData.Rank)
mapRankingData.bSelf = nSelfuid == mapRankingData.Id
mapRankingData.nBuildRank = self:GetBuildRank(mapRankingData.BuildScore)
if mapRankingData.TitlePrefix == 0 then
mapRankingData.TitlePrefix = 1
end
if mapRankingData.TitleSuffix == 0 then
mapRankingData.TitleSuffix = 2
end
end
end
function PlayerTravelerDuelData:GetTDRankingData()
return self.SelfRankingData, self.RankingData, self.LastRankingRefreshTime, self.UploadRemainTimes
end
function PlayerTravelerDuelData:GetTravelerDuelLevel()
return self.nDuelLevel, self.nDuelExp
end
function PlayerTravelerDuelData:GetTravelerDuelChallenge()
return self.mapCurChallenge
end
function PlayerTravelerDuelData:GetCachedBuildId(nLevelId)
if self.selBuildId ~= 0 and self.selBuildId ~= nil then
local ret = self.selBuildId
return ret
end
if self.mapBossLevel[nLevelId] ~= nil then
return self.mapBossLevel[nLevelId].nLastBuildId
end
return 0
end
function PlayerTravelerDuelData:SetCacheAffixids(tbAffixes, nBossId)
if tbAffixes ~= nil then
self.CachedAffixes = tbAffixes
self.curCachedAffixesBoss = nBossId
end
self.CachedBossId = nBossId
end
function PlayerTravelerDuelData:GetCacheAffixids()
return self.CachedAffixes, self.CachedBossId
end
function PlayerTravelerDuelData:SetSelBuildId(nBuildId)
self.selBuildId = nBuildId
end
function PlayerTravelerDuelData:EnterTravelerDuel(nLevel, nBuildId, tbAffixes)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.TravelerDuelLevel.TravelerDuelLevelData")
if luaClass == nil then
return
end
self.entryLevelId = nLevel
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevel, tbAffixes, nBuildId)
end
end
function PlayerTravelerDuelData:EnterTravelerDuelEditor(nLevel, tbChar, tbAffixes, tbDisc, tbNote)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.TravelerDuelLevel.TravelerDuelLevelEditorData")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevel, tbAffixes, tbChar, tbDisc, tbNote)
end
end
function PlayerTravelerDuelData:LevelEnd()
if type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerTravelerDuelData:SendMsg_EnterTravelerDuel(nLevelId, nBuildId, tbAffixes)
local msgData = {
Id = nLevelId,
BuildId = nBuildId,
AffixIds = tbAffixes
}
local Callback = function()
if self.mapBossLevel[nLevelId] == nil then
self.mapBossLevel[nLevelId] = {
nStar = 0,
nLastBuildId = 0,
nMaxDifficulty = 0
}
end
self.mapBossLevel[nLevelId].nLastBuildId = nBuildId
self:EnterTravelerDuel(nLevelId, nBuildId, tbAffixes)
end
self.LevelId = nLevelId
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_level_apply_req, msgData, nil, Callback)
end
function PlayerTravelerDuelData:SendMsg_UplodeTravelerDuelRanking(tbChar, Score, callback)
local oldScore = 0
local oldRank = 0
if self.SelfRankingData ~= nil then
oldScore = self.SelfRankingData.Score
end
local LocalData = require("GameCore.Data.LocalData")
local sKey = LocalData.GetPlayerLocalData("TravelerDuelRecordKey")
local bSuccess, nCheckSum = NovaAPI.GetRecorderKey(sKey)
local msgCallback = function(_, mapValue)
if self.SelfRankingData == nil then
self.SelfRankingData = {}
end
self.SelfRankingData.Chars = tbChar
self.SelfRankingData.Score = Score
self.SelfRankingData.Rank = mapValue.New
oldRank = mapValue.Old
self.UploadRemainTimes = self.UploadRemainTimes - 1
local curIdx = -1
local minLower = -1
local forEachReward = function(mapData)
if self.SelfRankingData.Rank <= mapData.RankUpper and (minLower > mapData.RankUpper or minLower < 0) then
curIdx = mapData.Id
minLower = mapData.RankUpper
end
end
ForEachTableLine(DataTable.TravelerDuelChallengeRankReward, forEachReward)
if curIdx < 0 then
curIdx = 4
end
self.SelfRankingData.nRewardIdx = curIdx
EventManager.Hit(EventId.OpenPanel, PanelId.TravelerDuelRankUploadSuccess, oldScore, Score, oldRank, self.SelfRankingData.Rank, curIdx)
if callback ~= nil and type(callback) == "function" then
callback()
end
if bSuccess and mapValue.Token ~= nil and mapValue.Token ~= "" and sKey ~= nil and sKey ~= "" then
NovaAPI.UploadStartowerFile(mapValue.Token, sKey)
LocalData.SetPlayerLocalData("TravelerDuelRecordKey", "")
else
NovaAPI.DeleteRecFile(sKey)
end
end
local tbSamples = UTILS.GetBattleSamples()
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_rank_upload_req, {Sample = tbSamples, Checksum = nCheckSum}, nil, msgCallback)
end
function PlayerTravelerDuelData:SendMsg_TravelerDuelSettle(nStar, nLevelId, nTime, callback)
local Events = PlayerData.Achievement:GetBattleAchievement(GameEnum.levelType.TravelerDuel, 0 < nStar)
local msgData = {
Star = nStar,
Time = nTime,
Events = {List = Events}
}
local Callback = function(_, netMsgData)
local mapDecodedChangeInfo = UTILS.DecodeChangeInfo(netMsgData.Change)
local nBossId = ConfigTable.GetData("TravelerDuelBossLevel", nLevelId).BossId
if 0 < nStar then
if self.nDuelLevel ~= netMsgData.DuelLevel then
self.bClassChange = true
self.oldLevel = self.nDuelLevel
self.oldExp = self.nDuelExp
end
self.nDuelLevel = netMsgData.DuelLevel
self.nDuelExp = netMsgData.DuelExp
if self.mapBossLevel[nLevelId] == nil then
self.mapBossLevel[nLevelId] = {
nStar = nStar,
nLastBuildId = 0,
nMaxDifficulty = 0
}
else
if 0 < self.mapBossLevel[nLevelId].nStar then
self.WeeklyAwardTimes = self.WeeklyAwardTimes + 1
end
if nStar > self.mapBossLevel[nLevelId].nStar then
self.mapBossLevel[nLevelId].nStar = nStar
end
end
end
if netMsgData.Affinities ~= nil then
for k, v in pairs(netMsgData.Affinities) do
PlayerData.Char:ChangeCharAffinityValue(v)
end
end
HttpNetHandler.ProcChangeInfo(mapDecodedChangeInfo)
if callback ~= nil then
callback(netMsgData)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_level_settle_req, msgData, nil, Callback)
end
function PlayerTravelerDuelData:SendMsg_GetTravelerDuelRanking(callback)
local msgCallback = function()
if callback ~= nil and type(callback) == "function" then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_rank_req, {}, nil, msgCallback)
end
function PlayerTravelerDuelData:OnEvent_NewDay()
self.bHasData = false
end
function PlayerTravelerDuelData:GetTravelerDuelData(callback)
if self.bHasData and callback ~= nil then
callback()
return
end
local Callback = function(_, netMsgData)
self:CacheTravelerDuelData(netMsgData)
local nCurChallengeBossId = 0
local mapSeasonCfg = ConfigTable.GetData("TravelerDuelChallengeSeason", self.mapCurChallenge.nIdx)
if mapSeasonCfg ~= nil then
nCurChallengeBossId = mapSeasonCfg.BossId
end
if nCurChallengeBossId ~= self.curCachedAffixesBoss then
self.CachedBossId = nil
self.CachedAffixes = nil
self.curCachedAffixesBoss = nil
end
self.bHasData = true
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.traveler_duel_info_req, {}, nil, Callback)
end
function PlayerTravelerDuelData:GetTravelerDuelLevelUnlock(nLevelId)
if nLevelId == 0 then
return false, 0
end
local mapBossLevel = ConfigTable.GetData("TravelerDuelBossLevel", nLevelId)
if mapBossLevel == nil then
return false, ConfigTable.GetUIText("RegusBoss_Unlock_Rank")
end
if mapBossLevel.PreLevelId ~= 0 then
local bPreLevelId = self.mapBossLevel[mapBossLevel.PreLevelId] ~= nil and 0 < self.mapBossLevel[mapBossLevel.PreLevelId].nStar
if not bPreLevelId then
return false, ConfigTable.GetUIText("RegusBoss_Unlock_Rank")
end
end
if mapBossLevel.UnlockWorldClass ~= 0 then
local nCurWorldClass = PlayerData.Base:GetWorldClass()
local bUnlockWorldClass = nCurWorldClass >= mapBossLevel.UnlockWorldClass
if not bUnlockWorldClass then
return false, orderedFormat(ConfigTable.GetUIText("TravelerDuel_Unlock_WorldClass"), mapBossLevel.UnlockWorldClass)
end
end
if mapBossLevel.UnlockDuelLevel ~= 0 then
local nDuelLevel = self.nDuelLevel
local bDuelLevel = nDuelLevel >= mapBossLevel.UnlockDuelLevel
if not bDuelLevel then
return false, orderedFormat(ConfigTable.GetUIText("TravelerDuel_Unlock_DuelRank"), mapBossLevel.UnlockDuelLevel)
end
end
return true, 0
end
function PlayerTravelerDuelData:GetTravelerDuelLevelRewardCount(nBossId)
if self.WeeklyAwardTimes == nil then
return 0
end
return self.WeeklyAwardTimes
end
function PlayerTravelerDuelData:GetTravelerDuelLevelStar(nLevelId)
if self.mapBossLevel[nLevelId] == nil then
return 0
else
return self.mapBossLevel[nLevelId].nStar
end
end
function PlayerTravelerDuelData:GetTravelerDuelAffixUnlock(nAffixId)
local mapAffixCfgData = ConfigTable.GetData("TravelerDuelChallengeAffix", nAffixId)
if mapAffixCfgData.UnlockWorldClass > 0 or 0 < mapAffixCfgData.UnlockDuelLevel or 0 < mapAffixCfgData.UnlockDifficulty then
local nWorldClass = PlayerData.Base:GetWorldClass()
if nWorldClass < mapAffixCfgData.UnlockWorldClass then
return false, 1, mapAffixCfgData.UnlockWorldClass
elseif mapAffixCfgData.UnlockDuelLevel > self.nDuelLevel then
return false, 2, mapAffixCfgData.UnlockDuelLevel
else
return false, 3, mapAffixCfgData.UnlockDifficulty
end
else
return true, 0, 0
end
end
function PlayerTravelerDuelData:GetTravelerChallengeUnlock()
local nNeedWorldLevel = 0
local nNeedDuelLevel = 0
local mapOpenFunc = ConfigTable.GetData("OpenFunc", GameEnum.OpenFuncType.TravelerDuelChallenge)
if mapOpenFunc ~= nil then
nNeedWorldLevel = mapOpenFunc.NeedWorldClass
nNeedDuelLevel = 0
end
local nDuelLevel = self.nDuelLevel
local nWorldClass = PlayerData.Base:GetWorldClass()
local sDesc = ""
if nNeedWorldLevel > nWorldClass then
sDesc = orderedFormat(ConfigTable.GetUIText("TD_Lock_WorldClass"), nNeedWorldLevel)
elseif nNeedDuelLevel > nDuelLevel then
sDesc = orderedFormat(ConfigTable.GetUIText("TD_Lock_DuelLevel"), nNeedDuelLevel)
end
return nNeedWorldLevel <= nWorldClass and nNeedDuelLevel <= nDuelLevel, sDesc
end
function PlayerTravelerDuelData:GetCurLevel()
if self.curLevel == nil then
return 0
end
return self.curLevel.nlevelId
end
function PlayerTravelerDuelData:TryOpenTDUpgradePanel(callback)
if self.bClassChange then
EventManager.Hit(EventId.OpenPanel, PanelId.TDLevelUpgrade, callback)
self.bClassChange = false
end
end
function PlayerTravelerDuelData:GetOldTDLevelData()
return self.oldLevel, self.oldExp
end
function PlayerTravelerDuelData:GetBuildRank(nScore)
local curIdx = -1
local minLower = -1
if curIdx < 0 then
curIdx = 1
end
return curIdx
end
function PlayerTravelerDuelData:GetRewardIdx(nScore)
local curIdx = -1
local minLower = -1
local forEachReward = function(mapData)
if nScore < mapData.RankUpper and (minLower > mapData.RankUpper or minLower < 0) then
curIdx = mapData.Id - 1
minLower = mapData.RankUpper
end
end
ForEachTableLine(DataTable.TravelerDuelChallengeRankReward, forEachReward)
if curIdx < 0 then
curIdx = 4
end
return curIdx
end
return PlayerTravelerDuelData
@@ -0,0 +1,113 @@
local PlayerTrialData = class("PlayerTrialData")
local AdventureModuleHelper = CS.AdventureModuleHelper
function PlayerTrialData:Init()
self.curLevel = nil
self.bInSettlement = false
self.nActId = nil
self.nSelectTrialGroupId = nil
self.sLevelTitle = nil
end
function PlayerTrialData:SetTrialAct(nActId)
self.nActId = nActId
end
function PlayerTrialData:GetTrialAct()
return self.nActId
end
function PlayerTrialData:SetSelectTrialGroup(nGroupId)
self.nSelectTrialGroupId = nGroupId
end
function PlayerTrialData:GetSelectTrialGroup()
return self.nSelectTrialGroupId
end
function PlayerTrialData:CheckGroupReceived()
if not self.nActId or not self.nSelectTrialGroupId then
return false
end
local actData = PlayerData.Activity:GetActivityDataById(self.nActId)
if not actData then
return false
end
return actData:CheckGroupReceived(self.nSelectTrialGroupId)
end
function PlayerTrialData:GetNextUnreceiveGroup()
if not self.nActId then
return
end
local actData = PlayerData.Activity:GetActivityDataById(self.nActId)
if not actData then
return
end
return actData:GetNextUnreceiveGroup()
end
function PlayerTrialData:SendReceiveTrialRewardReq(callback)
if not self.nActId or not self.nSelectTrialGroupId then
callback()
return false
end
local actData = PlayerData.Activity:GetActivityDataById(self.nActId)
if not actData then
callback()
return false
end
actData:SendActivityTrialRewardReceiveReq(self.nSelectTrialGroupId, callback)
end
function PlayerTrialData:EnterTrialEditor(nFloor)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Editor.Trial.TrialEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nFloor)
end
end
function PlayerTrialData:EnterTrial(nLevelId)
if self.curLevel ~= nil then
printError("当前关卡level不为空1")
return
end
local luaClass = require("Game.Adventure.Trial.TrialLevel")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId)
end
end
function PlayerTrialData:LevelEnd()
PlayerData.Build:DeleteTrialBuild()
if nil ~= self.curLevel and type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
function PlayerTrialData:GetCurLevel()
if self.curLevel == nil then
return 0
end
return self.curLevel.nLevelId
end
function PlayerTrialData:SetLevelTitle(sTitle)
self.sLevelTitle = sTitle
end
function PlayerTrialData:GetLevelTitle()
return self.sLevelTitle or ""
end
function PlayerTrialData:SetSettlementState(bInSettlement)
self.bInSettlement = bInSettlement
end
function PlayerTrialData:GetSettlementState()
return self.bInSettlement
end
return PlayerTrialData
@@ -0,0 +1,689 @@
local PlayerVampireSurvivorData = class("PlayerVampireSurvivorData")
local mapDropId = {
[GameEnum.dropEntityType.HP] = 106,
[GameEnum.dropEntityType.MP] = 107,
[GameEnum.dropEntityType.ATK] = 108,
[GameEnum.dropEntityType.VampireClear] = 109,
[GameEnum.dropEntityType.VampireGet] = 110
}
function PlayerVampireSurvivorData:Init()
self.tbPassedId = {}
self.mapRecord = {}
self.mapScore = {}
self.mapRecordSeason = {}
self.bInitTalent = false
self.mapActiveTalent = {}
self.nFateCardCount = 0
self.nTalentPoints = 0
self.nTalentResetTime = 0
self.nSeasonScore = 0
self.nCurSeasonId = 0
self.nTalentPointMax = 0
self.ObtainCount = 0
self.bSuccessBattle = false
local mapQuestGroup = {}
local forEachTableLine = function(mapData)
if mapQuestGroup[mapData.GroupId] == nil then
mapQuestGroup[mapData.GroupId] = {}
end
table.insert(mapQuestGroup[mapData.GroupId], mapData.Id)
end
ForEachTableLine(DataTable.VampireSurvivorQuest, forEachTableLine)
local forEachTalent = function(mapData)
self.nTalentPointMax = self.nTalentPointMax + mapData.Point
end
ForEachTableLine(DataTable.VampireTalent, forEachTalent)
for _, tbId in pairs(mapQuestGroup) do
table.sort(tbId)
end
CacheTable.Set("_VampireQuestGroup", mapQuestGroup)
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerVampireSurvivorData:UnInit()
self.tbPassedId = {}
self.mapRecord = {}
self.mapRecordSeason = {}
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerVampireSurvivorData:EnterVampireSurvivor(nLevelId, nBuildId1, nBuildId2)
local NetCallback = function(_, netMsg)
local luaClass = require("Game.Adventure.VampireSurvivor.VampireSurvivorLevelData")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, nLevelId, nBuildId1, nBuildId2, netMsg.Events, netMsg.Reward, netMsg.Select)
end
end
local BuildIds = {nBuildId1}
if 0 < nBuildId2 then
table.insert(BuildIds, nBuildId2)
end
local msg = {Id = nLevelId, BuildIds = BuildIds}
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_survivor_apply_req, msg, nil, NetCallback)
end
function PlayerVampireSurvivorData:ReEnterVampireSurvivor(nVampireId)
local NetCallback = function(_, netMsg)
local luaClass = require("Game.Adventure.VampireSurvivor.VampireSurvivorLevelData")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
local nBuildId1 = 0
local nBuildId2 = 0
local mapSceneFirst
for _, mapScene in ipairs(netMsg.Scenes) do
if mapScene.SceneType == 2 then
nBuildId2 = mapScene.BuildId
end
if mapScene.SceneType == 1 then
nBuildId1 = mapScene.BuildId
mapSceneFirst = mapScene
end
end
if mapSceneFirst == nil then
return
end
local GetAllBuildCallback = function(tbBuildData, mapAllBuild)
if mapAllBuild[nBuildId2] == nil then
local netMsgCallback = function(_, msgData)
local mapVampireCfgData = ConfigTable.GetData("VampireSurvivor", nVampireId)
if mapVampireCfgData ~= nil and mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn then
PlayerData.VampireSurvivor:AddPointAndLevel(msgData.Defeat.FinalScore, 0, msgData.Defeat.SeasonId)
end
PlayerData.VampireSurvivor:CacheScoreByLevel(nVampireId, msgData.Defeat.FinalScore)
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("VampireReconnnect_Abandon"))
end
local msg = {
KillCount = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
},
Time = 0,
Defeat = true,
Events = {
List = {}
}
}
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_survivor_settle_req, msg, nil, netMsgCallback)
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("VampireReConnect_BuildDeleted"))
elseif type(self.curLevel.Init) == "function" then
self.curLevel:InitReEnter(self, netMsg.Id, nBuildId1, nBuildId2, netMsg.Events, netMsg.Reward, netMsg.FateCardIds, netMsg.ClientData, mapSceneFirst)
end
end
PlayerData.Build:GetAllBuildBriefData(GetAllBuildCallback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_survivor_info_req, {}, nil, NetCallback)
end
function PlayerVampireSurvivorData:EnterVampireEditor(floorId, tbChar, isFirstHalf, tbDisc, tbNote)
local floorData = ConfigTable.GetData("VampireFloor", floorId)
if floorData == nil then
printError("吸血鬼floorData 为空,floor id === " .. floorId)
return
end
local luaClass = require("Game.Editor.VampireSurvivor.VampireSurvivorEditor")
if luaClass == nil then
return
end
self.curLevel = luaClass
if type(self.curLevel.BindEvent) == "function" then
self.curLevel:BindEvent()
end
if type(self.curLevel.Init) == "function" then
self.curLevel:Init(self, floorId, tbChar, isFirstHalf, tbDisc, tbNote)
end
end
function PlayerVampireSurvivorData:GetFloorBuff(floorId, isFirstHalf)
local floorData = ConfigTable.GetData("VampireFloor", floorId)
if isFirstHalf then
return floorData.FHAffixId
else
return floorData.SHAffixId
end
end
function PlayerVampireSurvivorData:LevelEnd()
if self.curLevel == nil then
return
else
if type(self.curLevel.UnBindEvent) == "function" then
self.curLevel:UnBindEvent()
end
self.curLevel = nil
end
end
function PlayerVampireSurvivorData:CacheLevelData(mapData)
if mapData == nil then
return
end
self.tbPassedId = {}
for _, mapRecord in ipairs(mapData.Records) do
self.mapRecord[mapRecord.Id] = mapRecord.BuildIds
self.mapScore[mapRecord.Id] = mapRecord.Score
if mapRecord.Passed then
table.insert(self.tbPassedId, mapRecord.Id)
end
end
self.mapRecordSeason = mapData.Season
self.nSeasonScore = mapData.SeasonScore
end
function PlayerVampireSurvivorData:GetCachedBuildId(nLevelId)
local mapVampireCfgData = ConfigTable.GetData("VampireSurvivor", nLevelId)
local bSeason = false
if mapVampireCfgData ~= nil then
bSeason = mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn
end
if bSeason then
return self.mapRecordSeason.BuildIds
end
if self.mapRecord[nLevelId] == nil then
return nil
else
return self.mapRecord[nLevelId]
end
end
function PlayerVampireSurvivorData:CacheSelectedBuildId(nLevelId, nIdx, nBuildId)
if nIdx == 0 then
printError("索引为0")
return
end
local mapVampireCfgData = ConfigTable.GetData("VampireSurvivor", nLevelId)
local bSeason = false
if mapVampireCfgData ~= nil then
bSeason = mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn
end
if bSeason then
if self.mapRecordSeason == nil then
self.mapRecordSeason = {}
end
if self.mapRecordSeason.BuildIds == nil then
self.mapRecordSeason.BuildIds = {}
self.mapRecordSeason.BuildIds[nIdx] = nBuildId
self.mapRecordSeason.BuildIds[2 / nIdx] = 0
else
self.mapRecordSeason.BuildIds[nIdx] = nBuildId
end
EventManager.Hit("VampireSurvivorChangeBuild")
return
end
if self.mapRecord[nLevelId] == nil then
self.mapRecord[nLevelId] = {}
self.mapRecord[nLevelId][nIdx] = nBuildId
self.mapRecord[nLevelId][2 / nIdx] = 0
else
self.mapRecord[nLevelId][nIdx] = nBuildId
end
EventManager.Hit("VampireSurvivorChangeBuild")
end
function PlayerVampireSurvivorData:ExchangeBuild(nLevelId)
local mapVampireCfgData = ConfigTable.GetData("VampireSurvivor", nLevelId)
local bSeason = false
if mapVampireCfgData ~= nil then
bSeason = mapVampireCfgData.Type == GameEnum.vampireSurvivorType.Turn
end
if bSeason then
if self.mapRecordSeason == nil then
self.mapRecordSeason = {}
end
if self.mapRecordSeason.BuildIds == nil then
self.mapRecordSeason.BuildIds = {0, 0}
else
local temp = self.mapRecordSeason.BuildIds[1]
self.mapRecordSeason.BuildIds[1] = self.mapRecordSeason.BuildIds[2] == nil and 0 or self.mapRecordSeason.BuildIds[2]
self.mapRecordSeason.BuildIds[2] = temp
end
elseif self.mapRecord[nLevelId] == nil then
self.mapRecord[nLevelId] = {0, 0}
else
local temp = self.mapRecord[nLevelId][1]
self.mapRecord[nLevelId][1] = self.mapRecord[nLevelId][2] == nil and 0 or self.mapRecord[nLevelId][2]
self.mapRecord[nLevelId][2] = temp
end
EventManager.Hit("VampireSurvivorChangeBuild")
end
function PlayerVampireSurvivorData:CheckLevelUnlock(nLevelId)
local mapLevelData = ConfigTable.GetData("VampireSurvivor", nLevelId)
if mapLevelData == nil then
return true
end
local nNeedWorldClass = mapLevelData.NeedWorldClass
local nCurWorldClass = PlayerData.Base:GetWorldClass()
if nNeedWorldClass > nCurWorldClass then
return false, 1, nNeedWorldClass
end
local prev = mapLevelData.PreLevelId
if 0 < prev and 1 > table.indexof(self.tbPassedId, prev) then
local mapLevelDataPrev = ConfigTable.GetData("VampireSurvivor", prev)
local sName = ""
if mapLevelDataPrev ~= nil then
sName = mapLevelDataPrev.Name
end
return false, 2, sName
end
return true
end
function PlayerVampireSurvivorData:GetTalentData()
local GetTalentCallback = function(_, mapData)
self:CacheTalentData(mapData)
self.bInitTalent = true
EventManager.Hit("GetTalentDataVampire", true)
end
if self.bInitTalent then
return self.mapActiveTalent, self.nTalentPoints, self.nTalentResetTime
end
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_talent_detail_req, {}, nil, GetTalentCallback)
return nil
end
function PlayerVampireSurvivorData:GetActivedTalent()
local ret = {}
if not self.bInitTalent then
printError("TalentData not init!")
return ret
end
for nTalentId, bActive in pairs(self.mapActiveTalent) do
if bActive then
table.insert(ret, nTalentId)
end
end
return ret
end
function PlayerVampireSurvivorData:ResetTalent(callback)
local msgCallback = function(_, msgData)
local curTime = CS.ClientManager.Instance.serverTimeStamp
self.nTalentResetTime = curTime + tonumber(ConfigTable.GetConfigValue("VampireTalentResetTimeInterval"))
self.mapActiveTalent = {}
if callback ~= nil and type(callback) == "function" then
callback()
end
end
local curTime = CS.ClientManager.Instance.serverTimeStamp
local tbActivedTalent = self:GetActivedTalent()
if #tbActivedTalent == 0 then
EventManager.Hit(EventId.OpenMessageBox, ConfigTable.GetUIText("VampireTalent_NoTalent"))
return
end
if curTime > self.nTalentResetTime then
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_talent_reset_req, {}, nil, msgCallback)
else
EventManager.Hit(EventId.OpenMessageBox, orderedFormat(ConfigTable.GetUIText("VampireTalent_ResetTime"), self.nTalentResetTime - curTime))
end
end
function PlayerVampireSurvivorData:ActiveTalent(nTalentId, callback)
local msgCallback = function(_, msgData)
self.mapActiveTalent[nTalentId] = true
self.nTalentPoints = self:CalTalentPoint(self.mapActiveTalent, self.nFateCardCount)
RedDotManager.SetValid(RedDotDefine.VampireTalent, nil, self:CheckCanAciveTalent())
if callback ~= nil and type(callback) == "function" then
callback(nTalentId)
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_talent_unlock_req, {Value = nTalentId}, nil, msgCallback)
end
function PlayerVampireSurvivorData:GetActivedTalentEft()
local tbActivedTalent = self:GetActivedTalent()
local ret = {}
for _, nTalentId in ipairs(tbActivedTalent) do
local talentData = ConfigTable.GetData("VampireTalent", nTalentId)
if talentData ~= nil and talentData.EffectId ~= 0 then
table.insert(ret, talentData.EffectId)
end
end
return ret
end
function PlayerVampireSurvivorData:GetActivedDropItem()
local tbActivedTalent = self:GetActivedTalent()
local tbActived = {}
local mapPropData = {}
local ret = {}
for _, nTalentId in ipairs(tbActivedTalent) do
local talentData = ConfigTable.GetData("VampireTalent", nTalentId)
if talentData ~= nil then
if talentData.Effect == GameEnum.vampireTalentEffect.ActiveDrop then
local tbParam = decodeJson(talentData.Params)
if tbParam ~= nil then
if table.indexof(tbActived, tbParam[1]) < 1 then
table.insert(tbActived, tbParam[1])
end
local nType = tonumber(tbParam[1])
if nType ~= nil then
if mapPropData[nType] == nil then
mapPropData[nType] = {
nProb = 0,
nGrowth = 0,
nMaxCount = 0
}
end
local nParam1 = tonumber(tbParam[2])
mapPropData[nType].nProb = math.max(mapPropData[nType].nProb, nParam1 == nil and 0 or nParam1)
local nParam2 = tonumber(tbParam[3])
mapPropData[nType].nGrowth = math.max(mapPropData[nType].nGrowth, nParam2 == nil and 0 or nParam2)
local nParam3 = tonumber(tbParam[4])
mapPropData[nType].nMaxCount = math.max(mapPropData[nType].nMaxCount, nParam3 == nil and 0 or nParam3)
end
end
elseif talentData.Effect == GameEnum.vampireTalentEffect.DropItemPropUp then
local tbParam = decodeJson(talentData.Params)
if tbParam ~= nil then
local nType = tonumber(tbParam[1])
if nType ~= nil then
if mapPropData[nType] == nil then
mapPropData[nType] = {
nProb = 0,
nGrowth = 0,
nMaxCount = 0
}
end
local nParam1 = tonumber(tbParam[2])
mapPropData[nType].nProb = math.max(mapPropData[nType].nProb, nParam1 == nil and 0 or nParam1)
local nParam2 = tonumber(tbParam[3])
mapPropData[nType].nGrowth = math.max(mapPropData[nType].nGrowth, nParam2 == nil and 0 or nParam2)
local nParam3 = tonumber(tbParam[4])
mapPropData[nType].nMaxCount = math.max(mapPropData[nType].nMaxCount, nParam3 == nil and 0 or nParam3)
end
end
end
end
end
for _, nType in ipairs(tbActived) do
if mapDropId[nType] ~= nil then
local stActorInfo = CS.VampireDropData(mapDropId[nType], 0, 0, 0)
if mapPropData[nType] ~= nil then
stActorInfo.DropProb = mapPropData[nType].nProb
stActorInfo.GrowthProb = mapPropData[nType].nGrowth
stActorInfo.DropMaxCount = mapPropData[nType].nMaxCount
end
table.insert(ret, stActorInfo)
end
end
return ret
end
function PlayerVampireSurvivorData:GetCurTalentPoint()
if not self.bInitTalent then
printError("TalentData not init!")
return 0
end
return self.nTalentPoints
end
function PlayerVampireSurvivorData:GetActiveExFateCard()
local tbActivedTalent = self:GetActivedTalent()
for _, nTalentId in ipairs(tbActivedTalent) do
local talentData = ConfigTable.GetData("VampireTalent", nTalentId)
if talentData ~= nil and talentData.Effect == GameEnum.vampireTalentEffect.UnlockspecialFateCard then
return true
end
end
return false
end
function PlayerVampireSurvivorData:GetCurScore()
return self.nSeasonScore
end
function PlayerVampireSurvivorData:GetScoreByLevel(nLevelId)
return self.mapScore[nLevelId] == nil and 0 or self.mapScore[nLevelId]
end
function PlayerVampireSurvivorData:CacheScoreByLevel(nLevelId, nScore)
if self.mapScore[nLevelId] ~= nil and nScore <= self.mapScore[nLevelId] then
return
end
self.mapScore[nLevelId] = nScore
end
function PlayerVampireSurvivorData:CacheTalentData(mapData)
local tbNodes = UTILS.ParseByteString(mapData.Nodes)
local forEachTalent = function(mapData)
local bActive = UTILS.IsBitSet(tbNodes, mapData.Id)
self.mapActiveTalent[mapData.Id] = bActive
end
ForEachTableLine(DataTable.VampireTalent, forEachTalent)
self.nTalentResetTime = mapData.ResetTime
self.nFateCardCount = mapData.ActiveCount
self.nTalentPoints = self:CalTalentPoint(self.mapActiveTalent, self.nFateCardCount)
self.ObtainCount = mapData.ObtainCount
self.nActiveExp = self.nTalentPoints - self:CalTalentPoint(self.mapActiveTalent, self.nFateCardCount - self.ObtainCount)
RedDotManager.SetValid(RedDotDefine.VampireTalent, nil, self:CheckCanAciveTalent())
end
function PlayerVampireSurvivorData:GetIsTalentPointMax()
local nFateCardPoint = ConfigTable.GetConfigNumber("FateCardBookToVampireTalentPoint")
if nFateCardPoint == nil then
nFateCardPoint = 1
end
local nCurCount = self.nFateCardCount * nFateCardPoint
return nCurCount >= self.nTalentPointMax
end
function PlayerVampireSurvivorData:CheckOpenHint()
if self.nActiveExp > 0 then
HttpNetHandler.SendMsg(NetMsgId.Id.vampire_talent_show_req, {}, nil, nil)
local ret1 = self.ObtainCount
local ret2 = self.nActiveExp
self.ObtainCount = 0
self.nActiveExp = 0
return true, ret1, ret2
end
return false, 0, 0
end
function PlayerVampireSurvivorData:ResetTalentPoint()
local nFateCardPoint = ConfigTable.GetConfigNumber("FateCardBookToVampireTalentPoint")
if nFateCardPoint == nil then
nFateCardPoint = 1
end
self.nTalentPoints = math.min(self.nTalentPointMax, nFateCardPoint * self.nFateCardCount)
RedDotManager.SetValid(RedDotDefine.VampireTalent, nil, self:CheckCanAciveTalent())
end
function PlayerVampireSurvivorData:AddTalentPoint(tbFateCard)
if tbFateCard ~= nil then
self.nFateCardCount = self.nFateCardCount + #tbFateCard
end
self.ObtainCount = self.ObtainCount + #tbFateCard
self.nActiveExp = math.max(0, self:CalTalentPoint(self.mapActiveTalent, self.nFateCardCount) - self.nTalentPoints)
self.nTalentPoints = self:CalTalentPoint(self.mapActiveTalent, self.nFateCardCount)
RedDotManager.SetValid(RedDotDefine.VampireTalent, nil, self:CheckCanAciveTalent())
end
function PlayerVampireSurvivorData:GetRefreshTiem()
local nSeasonId = self:GetCurSeason()
if nSeasonId == 0 then
return ""
end
local mapSeasonCfgData = ConfigTable.GetData("VampireRankSeason", nSeasonId)
if mapSeasonCfgData == nil then
return ""
end
local nEndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapSeasonCfgData.EndTime)
local curTime = CS.ClientManager.Instance.serverTimeStamp
local remainTime = nEndTime - curTime
if remainTime < 0 then
return ""
end
local sTimeStr = ""
local remainTime = nEndTime - curTime
if 86400 <= remainTime then
local day = math.floor(remainTime / 86400)
local hour = math.floor((remainTime - day * 86400) / 3600)
if hour == 0 then
day = day - 1
hour = 24
end
sTimeStr = orderedFormat(ConfigTable.GetUIText("Energy_LeftTime_Day"), day, hour)
elseif 3600 <= remainTime then
local hour = math.floor(remainTime / 3600)
local min = math.floor((remainTime - hour * 3600) / 60)
if min == 0 then
hour = hour - 1
min = 60
end
sTimeStr = orderedFormat(ConfigTable.GetUIText("Energy_LeftTime_Hour"), hour, min)
else
sTimeStr = ConfigTable.GetUIText("Energy_LeftTime_LessThenHour")
end
return sTimeStr
end
function PlayerVampireSurvivorData:GetCurSeason()
local ret = 0
local nLevel = 0
local nCurTime = CS.ClientManager.Instance.serverTimeStamp
local foreachVampireSeason = function(mapData)
local starttime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapData.OpenTime)
local endtime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapData.EndTime)
if starttime < nCurTime and endtime > nCurTime then
ret = mapData.Id
nLevel = mapData.MissionId
end
end
ForEachTableLine(DataTable.VampireRankSeason, foreachVampireSeason)
return ret, nLevel
end
function PlayerVampireSurvivorData:AddPointAndLevel(nPoint, nLevelId, nSeasonId)
if nLevelId ~= 0 and table.indexof(self.tbPassedId) < 1 then
table.insert(self.tbPassedId, nLevelId)
end
if nSeasonId ~= nil and nSeasonId ~= self:GetCurSeason() then
return
end
self.nSeasonScore = self.nSeasonScore + nPoint
end
function PlayerVampireSurvivorData:CheckCanAciveTalent()
local checkPrecAcitve = function(tbPrev)
if tbPrev == nil or #tbPrev == 0 then
return true
end
for _, nId in ipairs(tbPrev) do
if self.mapActiveTalent[nId] ~= true then
return false
end
end
return true
end
local ret = false
local foreachTalent = function(mapData)
if self.mapActiveTalent[mapData.Id] == true then
return
end
local tbPrev = mapData.Prev
if checkPrecAcitve(tbPrev) and mapData.Point <= self.nTalentPoints then
ret = true
end
end
ForEachTableLine(DataTable.VampireTalent, foreachTalent)
return ret
end
function PlayerVampireSurvivorData:CalTalentPoint(mapActiveTalent, nCards)
local nActivedPoint = 0
local nFateCardPoint = ConfigTable.GetConfigNumber("FateCardBookToVampireTalentPoint")
if nFateCardPoint == nil then
nFateCardPoint = 1
end
for nTalentId, bActive in pairs(mapActiveTalent) do
if bActive then
local mapTalentCfg = ConfigTable.GetData("VampireTalent", nTalentId)
if mapTalentCfg ~= nil then
nActivedPoint = nActivedPoint + mapTalentCfg.Point
end
end
end
local totalPoint = math.min(self.nTalentPointMax, nFateCardPoint * nCards)
return totalPoint - nActivedPoint
end
function PlayerVampireSurvivorData:OnNotifyRefresh(nSeasonId)
self.mapRecordSeason = {
Id = nSeasonId,
Score = 0,
BuildIds = {},
Passed = false
}
self.nSeasonScore = 0
PlayerData.Quest:ClearVampireSeasonQuest(nSeasonId)
EventManager.Hit("VampireSeasonRefresh")
end
function PlayerVampireSurvivorData:SetBattleSuccess()
self.bSuccessBattle = true
end
function PlayerVampireSurvivorData:CheckBattleSuccess()
if self.bSuccessBattle == true then
self.bSuccessBattle = false
return true
end
return false
end
function PlayerVampireSurvivorData:IsActiveTalent(nId)
local mapTalentData = ConfigTable.GetData("VampireTalent", nId)
if mapTalentData == nil then
return 3
end
if self.mapActiveTalent[nId] then
return 1
else
local tbPrev = mapTalentData.Prev
if tbPrev == nil or #tbPrev == 0 then
return 2
end
for _, nPrevId in ipairs(tbPrev) do
if self.mapActiveTalent[nPrevId] then
return 2
end
end
return 3
end
end
function PlayerVampireSurvivorData:GetHardUnlock()
local ret = {
false,
false,
false
}
local forEachVampire = function(mapData)
if self:CheckLevelUnlock(mapData.Id) then
if mapData.Type == GameEnum.vampireSurvivorType.Normal then
ret[1] = true
elseif mapData.Type == GameEnum.vampireSurvivorType.Hard then
ret[2] = true
end
end
end
ForEachTableLine(DataTable.VampireSurvivor, forEachVampire)
local nCurSeasonId, nLevelId = self:GetCurSeason()
if nCurSeasonId ~= 0 then
ret[3] = self:CheckLevelUnlock(nLevelId)
end
return ret
end
function PlayerVampireSurvivorData:GetSeasonQuestCount(nHard)
local tbScore, tbPass = PlayerData.Quest:GetVampireQuestData()
local cur, total = 0, 0
for _, mapPassData in ipairs(tbPass) do
local mapCfg = ConfigTable.GetData("VampireSurvivorQuest", mapPassData.nTid)
if mapCfg ~= nil and mapCfg.Type == nHard then
total = total + 1
if mapPassData.nStatus == 2 then
cur = cur + 1
end
end
end
for _, mapPassData in ipairs(tbScore) do
local mapCfg = ConfigTable.GetData("VampireSurvivorQuest", mapPassData.nTid)
if mapCfg ~= nil and mapCfg.Type == nHard then
total = total + 1
if mapPassData.nStatus == 2 then
cur = cur + 1
end
end
end
return cur, total
end
function PlayerVampireSurvivorData:CacheScore(nScore)
self.nSeasonScore = nScore
end
function PlayerVampireSurvivorData:CachePassedId(tbIds)
self.tbPassedId = tbIds
end
return PlayerVampireSurvivorData
@@ -0,0 +1,423 @@
local PlayerVoiceData = class("PlayerVoiceData")
local WwiseAudioMgr = CS.WwiseAudioManager.Instance
local TimerManager = require("GameCore.Timer.TimerManager")
local Actor2DManager = require("Game.Actor2D.Actor2DManager")
local ClientManager = CS.ClientManager.Instance
local LocalData = require("GameCore.Data.LocalData")
local TN = AllEnum.Actor2DType.Normal
local TF = AllEnum.Actor2DType.FullScreen
local board_click_time = ConfigTable.GetConfigNumber("HFCtimer")
local board_click_max_count = ConfigTable.GetConfigNumber("HFCcounter")
local board_click_free_time = ConfigTable.GetConfigNumber("Hangtimer")
local npc_board_click_time = ConfigTable.GetConfigNumber("NpcHFCtimer")
local npc_board_click_max_count = ConfigTable.GetConfigNumber("NpcHFCcounter")
local npc_board_click_free_time = ConfigTable.GetConfigNumber("NpcHangtimer")
local board_free_trigger_none = 0
local board_free_trigger_hang = 1
local board_free_trigger_ex_hang = 2
local charFavorLevelClickVoice = {
[1] = {nLevel = 10, sClickVoiceKey = "affchat1"},
[2] = {nLevel = 15, sClickVoiceKey = "affchat2"},
[3] = {nLevel = 20, sClickVoiceKey = "affchat3"},
[4] = {nLevel = 25, sClickVoiceKey = "affchat4"},
[5] = {nLevel = 30, sClickVoiceKey = "affchat5"}
}
local charFavorLevelUnlockVoice = {
{nLevel = 10, sUnlockVoiceKey = "afflv1"},
{nLevel = 15, sUnlockVoiceKey = "afflv2"},
{nLevel = 25, sUnlockVoiceKey = "afflv3"},
{nLevel = 30, sUnlockVoiceKey = "afflv4"}
}
local voiceRandomSkinLimit = {"posterchat"}
function PlayerVoiceData:Init()
self.bFirstEnterGame = true
self.bNpc = false
self.nNpcId = 0
self.bStartBoardClickTimer = false
self.nContinuousClickCount = 0
self.nBoardClickTime = 0
self.nBoardFreeTime = 0
self.nVoiceDuration = 0
self.nCurVoiceId = nil
self.nTriggerFreeVoiceState = board_free_trigger_none
self.boardClickTimer = nil
self.boardFreeTimer = nil
self.boardPlayTimer = nil
self.tbHolidayVoice = {}
self.tbHolidayVoiceKey = {}
EventManager.Add(EventId.UIOperate, self, self.OnEvent_UIOperate)
EventManager.Add(EventId.AvgVoiceDuration, self, self.OnEvent_AvgVoiceDuration)
EventManager.Add(EventId.IsNewDay, self, self.OnEvent_NewDay)
self:InitConfig()
end
function PlayerVoiceData:UnInit()
EventManager.Remove(EventId.UIOperate, self, self.OnEvent_UIOperate)
EventManager.Remove(EventId.AvgVoiceDuration, self, self.OnEvent_AvgVoiceDuration)
EventManager.Remove(EventId.IsNewDay, self, self.OnEvent_NewDay)
end
function PlayerVoiceData:InitConfig()
local foreachVoiceControl = function(line)
if line.dateTrigger and line.date ~= "" then
local tbParam = string.split(line.date, ".")
local year, month, day = 0
if #tbParam == 3 then
year = tonumber(tbParam[1])
month = tonumber(tbParam[2])
day = tonumber(tbParam[3])
else
month = tonumber(tbParam[1])
day = tonumber(tbParam[2])
end
table.insert(self.tbHolidayVoice, {
voiceKey = line.Id,
date = {
year = year,
month = month,
day = day
}
})
end
end
ForEachTableLine(ConfigTable.Get("CharacterVoiceControl"), foreachVoiceControl)
end
function PlayerVoiceData:PlayCharVoice(voiceKey, nCharId, nSkinId, bNpc)
if nil ~= voiceKey then
local tbVoiceKey = {}
if type(voiceKey) ~= "table" then
table.insert(tbVoiceKey, voiceKey)
else
tbVoiceKey = voiceKey
end
nSkinId = nSkinId or 0
if nCharId ~= 0 then
if nSkinId == 0 then
if bNpc then
local mapNpcCfg = ConfigTable.GetData("BoardNPC", nCharId)
if mapNpcCfg ~= nil then
nSkinId = mapNpcCfg.DefaultSkinId
end
else
nSkinId = PlayerData.Char:GetCharSkinId(nCharId)
end
end
else
nSkinId = 0
end
local nVoiceId = WwiseAudioMgr:WwiseVoice_Play(nCharId, tbVoiceKey, nil, nSkinId)
if nil ~= nVoiceId and nVoiceId ~= 0 then
self.nCurVoiceId = nVoiceId
end
return nVoiceId
end
end
function PlayerVoiceData:StopCharVoice()
if nil ~= self.nCurVoiceId and self.nCurVoiceId ~= 0 then
local mapVoDirectoryData = ConfigTable.GetData("VoDirectory", self.nCurVoiceId)
if mapVoDirectoryData ~= nil then
local tbCfg = ConfigTable.GetData("CharacterVoiceControl", mapVoDirectoryData.votype)
if nil ~= tbCfg then
WwiseAudioMgr:WwiseVoice_Stop(tbCfg.voPlayer - 1)
end
end
self.nCurVoiceId = 0
end
end
function PlayerVoiceData:CheckHoliday()
self.tbHolidayVoiceKey = {}
local nServerTimeStamp = ClientManager.serverTimeStamp
local nYear = tonumber(os.date("%Y", nServerTimeStamp))
local nMonth = tonumber(os.date("%m", nServerTimeStamp))
local nDay = tonumber(os.date("%d", nServerTimeStamp))
for _, v in ipairs(self.tbHolidayVoice) do
if v.date.year ~= 0 then
if v.date.year == nYear and v.date.month == nMonth and v.date.day == nDay then
table.insert(self.tbHolidayVoiceKey, v.voiceKey)
end
elseif v.date.month == nMonth and v.date.day == nDay then
table.insert(self.tbHolidayVoiceKey, v.voiceKey)
end
end
end
function PlayerVoiceData:CheckBirthday()
local nServerTimeStamp = ClientManager.serverTimeStamp
local nYear = tonumber(os.date("%Y", nServerTimeStamp))
local nMonth = tonumber(os.date("%m", nServerTimeStamp))
local nDay = tonumber(os.date("%d", nServerTimeStamp))
local curBoardCharId = PlayerData.Board:GetCurBoardCharID()
local mapCharDesc = ConfigTable.GetData("CharacterDes", curBoardCharId)
if nil ~= mapCharDesc and mapCharDesc.Birthday ~= "" then
local tbParam = string.split(mapCharDesc.Birthday, ".")
if #tbParam == 3 then
if nYear == tonumber(tbParam[1]) and nMonth == tonumber(tbParam[2]) and nDay == tonumber(tbParam[3]) then
return true
end
elseif nMonth == tonumber(tbParam[1]) and nDay == tonumber(tbParam[2]) then
return true
end
end
return false
end
local getBoardClickTime = function(bNpc)
return bNpc and npc_board_click_time or board_click_time
end
local getBoardClickMaxCount = function(bNpc)
return bNpc and npc_board_click_max_count or board_click_max_count
end
local getBoardClickFreeTime = function(bNpc)
return bNpc and npc_board_click_free_time or board_click_free_time
end
function PlayerVoiceData:StartBoardFreeTimer(nNpcId)
if nNpcId ~= nil or self.bNpc then
self.bNpc = true
if nNpcId ~= nil then
self.nNpcId = nNpcId or 0
end
else
self.bNpc = false
self.nNpcId = 0
end
self.bStartBoardClickTimer = true
if nil == self.boardFreeTimer and self.nTriggerFreeVoiceState ~= board_free_trigger_ex_hang then
self.boardFreeTimer = TimerManager.Add(0, 0.1, self, self.CheckBoardFree, true, true, false)
end
end
function PlayerVoiceData:CheckBoardFree()
self.nBoardFreeTime = self.nBoardFreeTime + 0.1
if self.nBoardFreeTime >= getBoardClickFreeTime(self.bNpc) then
self:ResetBoardFreeTimer()
if self.nTriggerFreeVoiceState == board_free_trigger_none then
self.nTriggerFreeVoiceState = board_free_trigger_hang
self:PlayBoardFreeVoice()
elseif self.nTriggerFreeVoiceState == board_free_trigger_hang then
self.nTriggerFreeVoiceState = board_free_trigger_ex_hang
self:PlayBoardFreeLongTimeVoice()
end
end
end
function PlayerVoiceData:ResetBoardFreeTimer()
if nil ~= self.boardFreeTimer then
TimerManager.Remove(self.boardFreeTimer, false)
end
self.boardFreeTimer = nil
self.nBoardFreeTime = 0
end
function PlayerVoiceData:StartBoardPlayTimer()
if nil == self.boardPlayTimer then
self.boardPlayTimer = TimerManager.Add(1, self.nVoiceDuration, nil, function()
self:StartBoardFreeTimer()
end, true, true, false)
end
end
function PlayerVoiceData:ResetBoardPlayTimer()
if nil ~= self.boardPlayTimer then
TimerManager.Remove(self.boardPlayTimer, false)
end
self.boardPlayTimer = nil
self.nVoiceDuration = 0
end
function PlayerVoiceData:PlayBoardSelectVoice(nCharId)
local sVoiceKey = "greet"
self:PlayCharVoice(sVoiceKey, nCharId)
end
function PlayerVoiceData:PlayMainViewOpenVoice()
local curBoardCharId = PlayerData.Board:GetCurBoardCharID()
self:CheckHoliday()
local bPlayFirst = false
local tbVoiceKey = {}
if nil ~= curBoardCharId then
local nServerTimeStamp = ClientManager.serverTimeStamp
local nHour = tonumber(os.date("%H", nServerTimeStamp))
local getIndex = function(nHour)
if 6 <= nHour and nHour < 12 then
return 1, "greetmorn"
elseif 12 <= nHour and nHour < 18 then
return 2, "greetnoon"
else
return 3, "greetnight"
end
end
local nIndex, sKey = getIndex(nHour)
if true == self.bFirstEnterGame then
tbVoiceKey = {sKey}
self.bFirstEnterGame = false
else
tbVoiceKey = {sKey, "greet"}
end
if #self.tbHolidayVoiceKey > 0 then
for _, v in ipairs(self.tbHolidayVoiceKey) do
table.insert(tbVoiceKey, v)
end
end
if self:CheckBirthday() then
table.insert(tbVoiceKey, "birth")
end
self:PlayCharVoice(tbVoiceKey, curBoardCharId)
end
end
function PlayerVoiceData:CheckContinuousClick()
self.nBoardClickTime = self.nBoardClickTime + 0.1
local nTime = getBoardClickTime(self.bNpc)
if nTime < self.nBoardClickTime then
self:ResetBoardClickTimer()
end
end
function PlayerVoiceData:ResetBoardClickTimer()
if nil ~= self.boardClickTimer then
TimerManager.Remove(self.boardClickTimer, false)
end
self.boardClickTimer = nil
self.nBoardClickTime = 0
self.nContinuousClickCount = 0
end
function PlayerVoiceData:PlayBoardClickVoice()
self.bNpc = false
self.nNpcId = 0
if 0 == self.nBoardClickTime and nil == self.boardClickTimer then
self.boardClickTimer = TimerManager.Add(0, 0.1, self, self.CheckContinuousClick, true, true, false)
end
self.nContinuousClickCount = self.nContinuousClickCount + 1
local curBoardCharId = PlayerData.Board:GetCurBoardCharID()
if nil ~= curBoardCharId then
local tbVoiceKey = {}
if self.nContinuousClickCount > getBoardClickMaxCount(self.bNpc) then
table.insert(tbVoiceKey, "hfc")
self:ResetBoardClickTimer()
else
table.insert(tbVoiceKey, "posterchat")
local curActor2DType = Actor2DManager.GetCurrentActor2DType()
if curActor2DType == TN then
table.insert(tbVoiceKey, "standee")
elseif curActor2DType == TF then
table.insert(tbVoiceKey, "fullscreen")
end
local mapData = PlayerData.Char:GetCharAffinityData(curBoardCharId)
if nil ~= mapData then
local nLevel = mapData.Level
for _, v in ipairs(charFavorLevelClickVoice) do
if nLevel >= v.nLevel then
table.insert(tbVoiceKey, v.sClickVoiceKey)
end
end
end
end
if 0 < #self.tbHolidayVoiceKey then
for _, v in ipairs(self.tbHolidayVoiceKey) do
table.insert(tbVoiceKey, v)
end
end
if self:CheckBirthday() then
table.insert(tbVoiceKey, "birth")
end
local nVoiceId = self:PlayCharVoice(tbVoiceKey, curBoardCharId)
if nil ~= nVoiceId and 0 ~= nVoiceId then
PlayerData.Quest:SendClientEvent(GameEnum.questCompleteCondClient.InteractL2D)
end
end
end
function PlayerVoiceData:PlayBoardNPCClickVoice(nNpcId)
self.bNpc = true
self.nNpcId = nNpcId
if 0 == self.nBoardClickTime and nil == self.boardClickTimer then
self.boardClickTimer = TimerManager.Add(0, 0.1, self, self.CheckContinuousClick, true, true, false)
end
self.nContinuousClickCount = self.nContinuousClickCount + 1
local curBoardCharId = nNpcId
if nil ~= curBoardCharId then
local tbVoiceKey = {}
if self.nContinuousClickCount > getBoardClickMaxCount(self.bNpc) then
table.insert(tbVoiceKey, "hfc_npc")
self:ResetBoardClickTimer()
else
table.insert(tbVoiceKey, "posterchat_npc")
end
self:PlayCharVoice(tbVoiceKey, curBoardCharId, nil, true)
end
end
function PlayerVoiceData:PlayBoardFreeVoice()
local curBoardCharId, sVoiceKey
if not self.bNpc then
curBoardCharId = PlayerData.Board:GetCurBoardCharID()
sVoiceKey = "hang"
else
curBoardCharId = self.nNpcId
sVoiceKey = "hang_npc"
end
if nil ~= curBoardCharId then
self:PlayCharVoice(sVoiceKey, curBoardCharId)
end
end
function PlayerVoiceData:PlayBoardFreeLongTimeVoice()
local curBoardCharId, sVoiceKey
if not self.bNpc then
curBoardCharId = PlayerData.Board:GetCurBoardCharID()
sVoiceKey = "exhang"
else
curBoardCharId = self.nNpcId
sVoiceKey = "exhang_npc"
end
if nil ~= curBoardCharId then
self:PlayCharVoice(sVoiceKey, curBoardCharId)
end
end
function PlayerVoiceData:PlayBattleResultVoice(tbChar, bWin)
local nIndex = math.random(1, #tbChar)
local nCharId = tbChar[nIndex]
local sVoiceKey = bWin and "win" or "lose"
self:PlayCharVoice(sVoiceKey, nCharId)
end
function PlayerVoiceData:CheckPlayGiftVoice(nLevel, nLastLevel)
local bPlay = true
if nLastLevel ~= nLevel then
for i = 1, #charFavorLevelUnlockVoice do
if charFavorLevelUnlockVoice[i] ~= nil and nLastLevel < charFavorLevelUnlockVoice[i].nLevel and nLevel >= charFavorLevelUnlockVoice[i].nLevel then
bPlay = false
break
end
end
end
return bPlay
end
function PlayerVoiceData:PlayCharFavourUpVoice(nCharId, nLastFavourLevel)
local nVoiceId
local mapData = PlayerData.Char:GetCharAffinityData(nCharId)
if nil ~= mapData then
local nLevel = mapData.Level
local sVoiceKey = ""
for i = 1, #charFavorLevelUnlockVoice do
if charFavorLevelUnlockVoice[i] ~= nil and nLastFavourLevel < charFavorLevelUnlockVoice[i].nLevel and nLevel >= charFavorLevelUnlockVoice[i].nLevel then
sVoiceKey = charFavorLevelUnlockVoice[i].sUnlockVoiceKey
end
end
if sVoiceKey ~= "" then
nVoiceId = self:PlayCharVoice(sVoiceKey, nCharId)
end
end
return nVoiceId
end
function PlayerVoiceData:ClearTimer()
self:ResetBoardPlayTimer()
self:ResetBoardFreeTimer()
self:ResetBoardClickTimer()
self.bStartBoardClickTimer = false
self.bNpc = false
self.nNpcId = 0
end
function PlayerVoiceData:OnEvent_UIOperate()
self.nBoardFreeTime = 0
self.nTriggerFreeVoiceState = board_free_trigger_none
if self.bStartBoardClickTimer and self.nVoiceDuration == 0 then
self:StartBoardFreeTimer()
end
end
function PlayerVoiceData:OnEvent_AvgVoiceDuration(nDuration)
self:ResetBoardPlayTimer()
self.nVoiceDuration = nDuration
if self.bStartBoardClickTimer and self.nTriggerFreeVoiceState ~= board_free_trigger_ex_hang then
self:ResetBoardFreeTimer()
self:StartBoardPlayTimer()
end
end
function PlayerVoiceData:OnEvent_NewDay()
self:CheckHoliday()
end
return PlayerVoiceData
+156
View File
@@ -0,0 +1,156 @@
local PopUpData = class("PopUpData")
local LocalData = require("GameCore.Data.LocalData")
function PopUpData:Init()
self.tbPopUpConfig = {}
self.tbPopUpData = {}
self.tbCachedPopUpData = {}
self:ParseConfig()
end
function PopUpData:ParseConfig()
local foreachPopup = function(mapData)
self:CachedPopUpConfig(mapData)
end
ForEachTableLine(ConfigTable.Get("PopUp"), foreachPopup)
end
function PopUpData:CachedPopUpConfig(mapData)
if mapData.PopUpType == GameEnum.PopUpType.Activity or mapData.PopUpType == GameEnum.PopUpType.ActivityGroup then
self.tbPopUpConfig[mapData.ActivityId] = mapData.Id
elseif mapData.PopUpType == GameEnum.PopUpType.OwnPopUP then
self.tbPopUpConfig[mapData.Id] = mapData.Id
end
end
function PopUpData:RefreshPopUp()
for k, v in pairs(self.tbPopUpConfig) do
local cfg = ConfigTable.GetData("PopUp", v)
if cfg.PopUpType == GameEnum.PopUpType.OwnPopUP and self:CheckPopUpOpen(cfg) and self:IsNeedOwnPopUp(cfg.Id) and table.indexof(self.tbPopUpData, cfg.Id) <= 0 and 0 >= table.indexof(self.tbCachedPopUpData, v) then
table.insert(self.tbPopUpData, cfg.Id)
table.insert(self.tbCachedPopUpData, cfg.Id)
end
end
if #self.tbPopUpData > 0 then
table.sort(self.tbPopUpData, function(a, b)
if self.tbPopUpConfig[a] ~= nil and self.tbPopUpConfig[b] ~= nil then
local cfgA = ConfigTable.GetData("PopUp", self.tbPopUpConfig[a])
local cfgB = ConfigTable.GetData("PopUp", self.tbPopUpConfig[b])
return cfgA.SortId < cfgB.SortId
end
return false
end)
PopUpManager.PopUpEnQueue(GameEnum.PopUpSeqType.ActivityFaceAnnounce, self.tbPopUpData)
self.tbPopUpData = {}
end
end
function PopUpData:CheckPopUpOpen(mapData)
local bUnlock = false
if mapData.StartCondType == GameEnum.activityAcceptCond.WorldClassSpecific then
local nWorldCalss = PlayerData.Base:GetWorldClass()
if nWorldCalss >= mapData.StartCondParams[1] then
bUnlock = true
end
else
bUnlock = true
end
if bUnlock then
local bOpen = false
local nStartTime = 0
local nEndTime = 0
local curTime = CS.ClientManager.Instance.serverTimeStamp
if mapData.StartType == GameEnum.PopUpOpenType.Date then
nStartTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapData.StartTime)
else
bOpen = true
end
if mapData.EndType == GameEnum.PopUpEndType.Date then
nEndTime = CS.ClientManager.Instance:ISO8601StrToTimeStamp(mapData.EndTime)
elseif mapData.EndType == GameEnum.activityEndType.TimeLimit then
nEndTime = nStartTime + mapData.EndDuration * 86400
else
bOpen = true
end
if 0 < nStartTime and 0 < nEndTime and curTime >= nStartTime and curTime <= nEndTime then
bOpen = true
end
return bOpen
end
return false
end
function PopUpData:InsertPopUpQueue(tbPopUpList)
for k, v in pairs(tbPopUpList) do
if table.indexof(self.tbPopUpData, v) <= 0 and 0 >= table.indexof(self.tbCachedPopUpData, v) then
table.insert(self.tbPopUpData, v)
table.insert(self.tbCachedPopUpData, v)
end
end
self:RefreshPopUp()
end
local GetCurrentYearInfo = function(time_s)
local day = os.date("%d", time_s)
local weekIndex = os.date("%W", time_s)
local month = os.date("%m", time_s)
local yearNum = os.date("%Y", time_s)
return {
year = yearNum,
month = month,
weekIdx = weekIndex,
day = day
}
end
function PopUpData:IsNeedActPopUp(actId)
if self.tbPopUpConfig[actId] ~= nil then
local popupId = self.tbPopUpConfig[actId]
local localData = LocalData.GetPlayerLocalData("Act_PopUp" .. actId)
return self:IsNeedPopUp(popupId, localData)
end
return false
end
function PopUpData:IsNeedOwnPopUp(popUpId)
if self.tbPopUpConfig[popUpId] ~= nil then
local localData = LocalData.GetPlayerLocalData("Act_PopUp" .. popUpId)
return self:IsNeedPopUp(popUpId, localData)
end
return false
end
function PopUpData:IsNeedPopUp(popupId, localData)
local cfg = ConfigTable.GetData("PopUp", popupId)
if cfg.PopRefreshType == GameEnum.PopRefreshType.WholeFirst then
if nil == localData then
return cfg.PopUpRes ~= nil
else
return false
end
elseif cfg.PopRefreshType == GameEnum.PopRefreshType.DailyFirst then
if nil == localData then
return cfg.PopUpRes ~= nil
else
local dateA = GetCurrentYearInfo(tonumber(localData))
local dateB = GetCurrentYearInfo()
local isSameDay = dateA.day == dateB.day and dateA.month == dateB.month and dateA.year == dateB.year
return not isSameDay and cfg.PopUpRes ~= nil
end
elseif cfg.PopRefreshType == GameEnum.PopRefreshType.WeeklyFirst then
if nil == localData then
return cfg.PopUpRes ~= nil
else
local nextTime = tonumber(localData)
local curTime = CS.ClientManager.Instance.serverTimeStamp
return nextTime <= curTime
end
end
return cfg.PopUpRes ~= nil
end
function PopUpData:GetPopUpConfigData(actId)
if self.tbPopUpConfig[actId] ~= nil then
local cfg = ConfigTable.GetData("PopUp", self.tbPopUpConfig[actId])
return cfg
end
return nil
end
function PopUpData:ReleaseCachedPopUpData(popupId)
for i, v in ipairs(self.tbCachedPopUpData) do
if v == popupId then
table.remove(self.tbCachedPopUpData, i)
break
end
end
end
return PopUpData
+57
View File
@@ -0,0 +1,57 @@
local SkinData = class("SkinData")
function SkinData:ctor(skinId, handbookId, unlock)
self.nId = skinId
self.nHandbookId = handbookId
self.tbCfgData = ConfigTable.GetData_CharacterSkin(skinId)
if nil == self.tbCfgData then
printError("Get skinData fail!!! skinId = " .. skinId)
return
end
self.nCharId = self.tbCfgData.CharId
self.nUnlock = unlock
self.tbSkinExtraTag = self.tbCfgData.SkinExtraTag
end
function SkinData:UpdateUnlockState(nUnlock)
self.nUnlock = nUnlock
end
function SkinData:GetId()
return self.nId
end
function SkinData:GetCharId()
return self.nCharId
end
function SkinData:GetHandbookId()
return self.nHandbookId
end
function SkinData:GetSkinExtraTags()
return self.tbSkinExtraTag
end
function SkinData:GetCfgData()
return self.tbCfgData
end
function SkinData:CheckSkinShow()
return self.tbCfgData.IsShow
end
function SkinData:CheckUnlock()
return self.nUnlock == 1
end
function SkinData:CheckFavorCG()
local nCGId = self.tbCfgData.CharacterCG
local cfgCG = ConfigTable.GetData("CharacterCG", nCGId)
if cfgCG == nil then
printError(string.format("读取CharacterCG配置失败!!!id = [%s]", nCGId))
elseif cfgCG.UnlockPlot > 0 then
return PlayerData.Char:IsCharPlotFinish(self.nCharId, cfgCG.UnlockPlot)
end
return true
end
function SkinData:GetUnlockPlot()
local nCGId = self.tbCfgData.CharacterCG
local cfgCG = ConfigTable.GetData("CharacterCG", nCGId)
if cfgCG == nil then
printError(string.format("读取CharacterCG配置失败!!!id = [%s]", nCGId))
return 0
end
return cfgCG.UnlockPlot
end
return SkinData
@@ -0,0 +1,665 @@
local StarTowerBookData = class("StarTowerBookData")
local MAPSTATUS = {
[0] = AllEnum.BookQuestStatus.UnComplete,
[1] = AllEnum.BookQuestStatus.Complete,
[2] = AllEnum.BookQuestStatus.Received
}
function StarTowerBookData:Init()
self.mapPotentialBookBrief = {}
self.mapPotentialBook = {}
self.mapFateCardBook = {}
self.mapPotentialQuest = {}
self.mapFateCardQuest = {}
self.mapEntranceCfg = {}
self.bFateCardInit = false
self.bEventInit = false
EventManager.Add(EventId.UpdateWorldClass, StarTowerBookData, self.OnEvent_UpdateWorldClass)
EventManager.Add(EventId.StarTowerPass, StarTowerBookData, self.OnEvent_StarTowerPass)
self:InitConfig()
end
function StarTowerBookData:InitConfig()
local foreachEntranceTableLine = function(line)
table.insert(self.mapEntranceCfg, line)
end
ForEachTableLine(ConfigTable.Get("StarTowerBookEntrance"), foreachEntranceTableLine)
local foreachPotentialTableLine = function(line)
local nCharId = line.Id
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
if mapCharCfg ~= nil and mapCharCfg.Available then
local nAllCount = 0
self.mapPotentialBook[nCharId] = {}
self.mapPotentialBook[nCharId].Init = false
self.mapPotentialBook[nCharId].PotentialList = {}
self.mapPotentialBookBrief[nCharId] = {}
local addPotentialList = function(tbList)
for _, v in pairs(tbList) do
nAllCount = nAllCount + 1
end
end
addPotentialList(line.MasterSpecificPotentialIds)
addPotentialList(line.MasterNormalPotentialIds)
addPotentialList(line.AssistSpecificPotentialIds)
addPotentialList(line.AssistNormalPotentialIds)
addPotentialList(line.CommonPotentialIds)
self.mapPotentialBookBrief[nCharId].AllCount = nAllCount
self.mapPotentialBookBrief[nCharId].Count = 0
self.mapPotentialBookBrief[nCharId].Rarity = mapCharCfg.Grade
end
end
ForEachTableLine(ConfigTable.Get("CharPotential"), foreachPotentialTableLine)
local foreachPotentialRewardTableLine = function(line)
if self.mapPotentialQuest[line.CharId] == nil then
self.mapPotentialQuest[line.CharId] = {}
end
self.mapPotentialQuest[line.CharId][line.Id] = {}
self.mapPotentialQuest[line.CharId][line.Id].Status = AllEnum.BookQuestStatus.UnComplete
local nAllProgress = 0
local nParam = 0
if line.Cond == GameEnum.towerBookPotentialCond.TowerBookCharPotentialQuantity then
local params = decodeJson(line.Params)
nParam = tonumber(params[1])
nAllProgress = tonumber(params[2])
end
self.mapPotentialQuest[line.CharId][line.Id].Cond = line.Cond
self.mapPotentialQuest[line.CharId][line.Id].Param = nParam
self.mapPotentialQuest[line.CharId][line.Id].AllProgress = nAllProgress
self.mapPotentialQuest[line.CharId][line.Id].CurProgress = 0
local tbReward = {
RewardId = line.ItemId,
RewardCount = line.ItemQty
}
self.mapPotentialQuest[line.CharId][line.Id].Reward = tbReward
self.mapPotentialQuest[line.CharId][line.Id].Desc = UTILS.ParseParamDesc(line.Desc, line)
end
ForEachTableLine(ConfigTable.Get("StarTowerBookPotentialReward"), foreachPotentialRewardTableLine)
local foreachFateCardTableLine = function(line)
if not line.IsBanned then
self.mapFateCardBook[line.Id] = {
Sort = line.SortId,
Status = AllEnum.FateCardBookStatus.Lock
}
end
end
ForEachTableLine(ConfigTable.Get("StarTowerBookFateCard"), foreachFateCardTableLine)
local foreachFateCardQuestTableLine = function(line)
if self.mapFateCardQuest[line.BundleId] == nil then
self.mapFateCardQuest[line.BundleId] = {}
end
self.mapFateCardQuest[line.BundleId][line.Id] = {
Id = line.Id,
Desc = UTILS.ParseParamDesc(line.Desc, line),
Status = AllEnum.BookQuestStatus.UnComplete,
CurProgress = 0,
AllProgress = 0
}
local tbReward = {}
for i = 1, 3 do
if 0 < line["Tid" .. i] then
table.insert(tbReward, {
RewardId = line["Tid" .. i],
RewardCount = line["Qty" .. i]
})
end
end
self.mapFateCardQuest[line.BundleId][line.Id].Reward = tbReward
if line.FinishType == GameEnum.towerBookFateCardFinishType.FateCardCount then
local param = decodeJson(line.FinishParams)
self.mapFateCardQuest[line.BundleId][line.Id].AllProgress = tonumber(param[1])
elseif line.FinishType == GameEnum.towerBookFateCardFinishType.FateCardCollect then
local param = decodeJson(line.FinishParams)
for _, id in ipairs(param) do
self.mapFateCardQuest[line.BundleId][line.Id].AllProgress = self.mapFateCardQuest[line.BundleId][line.Id].AllProgress + 1
end
end
end
ForEachTableLine(ConfigTable.Get("StarTowerBookFateCardQuest"), foreachFateCardQuestTableLine)
end
function StarTowerBookData:CharPotentialBookChange(mapMsgData)
for _, v in ipairs(mapMsgData.CharPotentials) do
local nCharId = v.CharId
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
local tbPotentials = v.Potentials
if self.mapPotentialBook[nCharId] ~= nil then
local mapPotentialList = self.mapPotentialBook[nCharId].PotentialList
for _, v in ipairs(tbPotentials) do
local nLastLevel = mapPotentialList[v.Id] or 0
if nLastLevel == 0 and mapCharCfg ~= nil and mapCharCfg.Available then
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_New, v.Id, true)
end
mapPotentialList[v.Id] = v.Level
end
end
end
self:RefreshPotentialQuest()
for _, v in ipairs(mapMsgData.CharIds) do
local mapCfg = ConfigTable.GetData_Character(v)
if mapCfg ~= nil and mapCfg.Available then
local nElement = mapCfg.EET
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {nElement, v}, true)
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {0, v}, true)
end
end
EventManager.Hit("PotentialBookDataChange")
end
function StarTowerBookData:RefreshPotentialQuest()
for nCharId, list in pairs(self.mapPotentialQuest) do
if self.mapPotentialBook[nCharId] ~= nil and self.mapPotentialBook[nCharId].Init then
local bCanReceive = false
local nCharPotentialCount = 0
for _, v in pairs(self.mapPotentialBook[nCharId].PotentialList) do
nCharPotentialCount = nCharPotentialCount + 1
end
for nId, data in pairs(list) do
if data.Status ~= AllEnum.BookQuestStatus.Received then
if data.Cond == GameEnum.towerBookPotentialCond.TowerBookCharPotentialQuantity then
if self.mapPotentialBookBrief[data.Param] ~= nil then
self.mapPotentialQuest[nCharId][nId].CurProgress = nCharPotentialCount
local nStatus = self.mapPotentialQuest[nCharId][nId].CurProgress >= self.mapPotentialQuest[nCharId][nId].AllProgress and AllEnum.BookQuestStatus.Complete or AllEnum.BookQuestStatus.UnComplete
self.mapPotentialQuest[nCharId][nId].Status = nStatus
else
self.mapPotentialQuest[nCharId][nId].Status = AllEnum.BookQuestStatus.UnComplete
end
end
if self.mapPotentialQuest[nCharId][nId].Status == AllEnum.BookQuestStatus.Complete then
bCanReceive = true
end
end
end
local mapCfg = ConfigTable.GetData_Character(nCharId)
if mapCfg ~= nil and mapCfg.Available then
local nElement = mapCfg.EET
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {nElement, nCharId}, bCanReceive)
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {0, nCharId}, bCanReceive)
end
end
end
end
function StarTowerBookData:GetCharPotentialBriefBook()
local mapBrief = {}
for nCharId, v in pairs(self.mapPotentialBookBrief) do
local nUnlock = PlayerData.Char:CheckCharUnlock(nCharId) and 1 or 0
local mapData = {
nCharId = nCharId,
nCount = v.Count or 0,
nAllCount = v.AllCount,
nUnlock = nUnlock,
nRarity = v.Rarity
}
table.insert(mapBrief, mapData)
end
table.sort(mapBrief, function(a, b)
if a.nUnlock == b.nUnlock then
if a.nRarity == b.nRarity then
return a.nCharId < b.nCharId
end
return a.nRarity < b.nRarity
end
return a.nUnlock > b.nUnlock
end)
return mapBrief
end
function StarTowerBookData:TryGetCharPotentialBook(nCharId, callback)
if self.mapPotentialBook[nCharId] == nil or not self.mapPotentialBook[nCharId].Init then
self:SendPotentialBookMsg(nCharId, callback)
elseif callback ~= nil then
callback()
end
end
function StarTowerBookData:GetCharPotentialBook(nCharId)
if self.mapPotentialBook[nCharId] ~= nil then
return self.mapPotentialBook[nCharId].PotentialList
end
end
function StarTowerBookData:GetAllCharPotential(nCharId)
local mapAllPotential = {}
local mapPotentialData = self:GetCharPotentialBook(nCharId)
local mapCfg = ConfigTable.GetData("CharPotential", nCharId)
if mapCfg ~= nil then
local funcSort = function(tbSort)
table.sort(tbSort, function(a, b)
local mapCfgA = ConfigTable.GetData_Item(a.nId)
local mapCfgB = ConfigTable.GetData_Item(b.nId)
if mapCfgA ~= nil and mapCfgB ~= nil then
if mapCfgA.Rarity == mapCfgB.Rarity then
return a.nId < b.nId
end
return mapCfgA.Rarity < mapCfgB.Rarity
end
return a.nId < b.nId
end)
end
mapAllPotential.MasterSpecificIds = {}
for _, v in pairs(mapCfg.MasterSpecificPotentialIds) do
table.insert(mapAllPotential.MasterSpecificIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 1
})
end
funcSort(mapAllPotential.MasterSpecificIds)
mapAllPotential.MasterNormalIds = {}
for _, v in pairs(mapCfg.MasterNormalPotentialIds) do
table.insert(mapAllPotential.MasterNormalIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 0
})
end
mapAllPotential.AssistSpecificIds = {}
for _, v in pairs(mapCfg.AssistSpecificPotentialIds) do
table.insert(mapAllPotential.AssistSpecificIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 1
})
end
funcSort(mapAllPotential.AssistSpecificIds)
mapAllPotential.AssistNormalIds = {}
for _, v in pairs(mapCfg.AssistNormalPotentialIds) do
table.insert(mapAllPotential.AssistNormalIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 0
})
end
for _, v in pairs(mapCfg.CommonPotentialIds) do
table.insert(mapAllPotential.MasterNormalIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 0
})
table.insert(mapAllPotential.AssistNormalIds, {
nId = v,
nLevel = mapPotentialData[v] or 0,
nSpecial = 0
})
end
funcSort(mapAllPotential.MasterNormalIds)
funcSort(mapAllPotential.AssistNormalIds)
end
return mapAllPotential
end
function StarTowerBookData:GetCharPotentialQuest(nCharId)
if self.mapPotentialQuest[nCharId] ~= nil then
return self.mapPotentialQuest[nCharId]
end
end
function StarTowerBookData:GetCharPotentialCount(nCharId)
if self.mapPotentialBookBrief[nCharId] == nil then
return 0, 0
end
if self.mapPotentialBook[nCharId] == nil or not self.mapPotentialBook[nCharId].Init then
return self.mapPotentialBookBrief[nCharId].Count, self.mapPotentialBookBrief[nCharId].AllCount
end
local nCount = 0
for _, v in pairs(self.mapPotentialBook[nCharId].PotentialList) do
nCount = nCount + 1
end
return nCount, self.mapPotentialBookBrief[nCharId].AllCount
end
function StarTowerBookData:TryGetFateCardBook(callback)
if not self.bFateCardInit then
self:SendGetFateCardBookMsg(callback)
elseif callback ~= nil then
callback()
end
end
function StarTowerBookData:CheckFateCardBundleUnlock(nBundleId)
local nWorldClass = PlayerData.Base:GetWorldClass()
local mapCfg = ConfigTable.GetData("StarTowerBookFateCardBundle", nBundleId)
if mapCfg ~= nil then
local bWorldClass = mapCfg.WorldClass == 0 and true or nWorldClass >= mapCfg.WorldClass
local bStarTower = mapCfg.StarTowerId == 0 and true or PlayerData.StarTower:CheckPassedId(mapCfg.StarTowerId)
local bCollect = true
for _, v in pairs(mapCfg.CollectCards) do
bCollect = bCollect and self.mapFateCardBook[v].Status == AllEnum.FateCardBookStatus.Collect
if not bCollect then
break
end
end
local bUnlock = true
for _, v in pairs(mapCfg.UnlockCards) do
bUnlock = bUnlock and self.mapFateCardBook[v].Status ~= AllEnum.FateCardBookStatus.Lock
if not bUnlock then
break
end
end
if bWorldClass and bStarTower and bCollect and bUnlock then
return true
end
end
return false
end
function StarTowerBookData:CheckFateCardUnLock(nId)
local nWorldClass = PlayerData.Base:GetWorldClass()
local mapCfg = ConfigTable.GetData("StarTowerBookFateCard", nId)
if mapCfg ~= nil then
local bBundleUnlock = self:CheckFateCardBundleUnlock(mapCfg.BundleId)
if not bBundleUnlock then
return false
end
local bWorldClass = mapCfg.WorldClass == 0 and true or nWorldClass >= mapCfg.WorldClass
local bStarTower = mapCfg.StarTowerId == 0 and true or PlayerData.StarTower:CheckPassedId(mapCfg.StarTowerId)
local bCollect = true
for _, v in pairs(mapCfg.CollectCards) do
bCollect = bCollect and self.mapFateCardBook[v].Status == AllEnum.FateCardBookStatus.Collect
if not bCollect then
break
end
end
local bUnlock = true
for _, v in pairs(mapCfg.UnlockCards) do
bUnlock = bUnlock and self.mapFateCardBook[v].Status ~= AllEnum.FateCardBookStatus.Lock
if not bUnlock then
break
end
end
if bWorldClass and bStarTower and bCollect and bUnlock then
return true
end
end
return false
end
function StarTowerBookData:UpdateFateCardStatus()
local mapFateCardLock = {}
for nId, v in pairs(self.mapFateCardBook) do
if v.Status == AllEnum.FateCardBookStatus.Lock then
table.insert(mapFateCardLock, nId)
end
end
local function check(tbLock)
local tempUnlock = {}
local tempLock = {}
for _, nId in ipairs(tbLock) do
if self:CheckFateCardUnLock(nId) then
self.mapFateCardBook[nId].Status = AllEnum.FateCardBookStatus.UnLock
table.insert(tempUnlock, nId)
else
table.insert(tempLock, nId)
end
end
if #tempUnlock == 0 then
return
else
check(tempLock)
end
end
check(mapFateCardLock)
self:UpdateFateCardQuest()
end
function StarTowerBookData:UpdateFateCardQuest()
local nCollectCount = 0
local tbBundleCollect = {}
for nId, v in pairs(self.mapFateCardBook) do
if v.Status == AllEnum.FateCardBookStatus.Collect then
nCollectCount = nCollectCount + 1
local mapCfg = ConfigTable.GetData("StarTowerBookFateCard", nId)
if mapCfg ~= nil then
local nBundleId = mapCfg.BundleId
if tbBundleCollect[nBundleId] == nil then
tbBundleCollect[nBundleId] = 0
end
tbBundleCollect[nBundleId] = tbBundleCollect[nBundleId] + 1
end
end
end
for nBundleId, list in pairs(self.mapFateCardQuest) do
for nId, data in pairs(list) do
if data.Status == AllEnum.BookQuestStatus.UnComplete then
local mapCfg = ConfigTable.GetData("StarTowerBookFateCardQuest", nId)
if mapCfg ~= nil then
if mapCfg.FinishType == GameEnum.towerBookFateCardFinishType.FateCardCount then
local param = decodeJson(mapCfg.FinishParams)
local nBundleParam = 0
if 1 < #param and param[2] ~= 0 then
nBundleParam = param[2]
end
if nBundleParam == 0 then
self.mapFateCardQuest[nBundleId][nId].CurProgress = nCollectCount
else
self.mapFateCardQuest[nBundleId][nId].CurProgress = tbBundleCollect[nBundleParam] or 0
end
if self.mapFateCardQuest[nBundleId][nId].CurProgress >= self.mapFateCardQuest[nBundleId][nId].AllProgress then
self.mapFateCardQuest[nBundleId][nId].Status = AllEnum.BookQuestStatus.Complete
end
elseif mapCfg.FinishType == GameEnum.towerBookFateCardFinishType.FateCardCollect then
local param = decodeJson(mapCfg.FinishParams)
local bCollect = true
local nProgress = 0
for _, id in ipairs(param) do
if self.mapFateCardBook[id].Status ~= AllEnum.FateCardBookStatus.Collect then
bCollect = false
else
nProgress = nProgress + 1
end
end
self.mapFateCardQuest[nBundleId][nId].CurProgress = nProgress
if bCollect then
self.mapFateCardQuest[nBundleId][nId].Status = AllEnum.BookQuestStatus.Complete
end
end
end
end
end
end
end
function StarTowerBookData:RefreshFateCardRedDot()
for nBundleId, list in pairs(self.mapFateCardQuest) do
local bCanReceive = false
for _, data in pairs(list) do
if data.Status == AllEnum.BookQuestStatus.Complete then
bCanReceive = true
break
end
end
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, nBundleId, bCanReceive)
end
end
function StarTowerBookData:FateCardBookChange(mapMsgData)
for _, v in ipairs(mapMsgData.Cards) do
if nil ~= self.mapFateCardBook[v] then
self.mapFateCardBook[v].Status = AllEnum.FateCardBookStatus.Collect
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_New, v, true)
end
end
self:UpdateFateCardStatus()
self:RefreshFateCardRedDot()
end
function StarTowerBookData:FateCardBookRewardChange(mapMsgData)
if mapMsgData.Option then
for _, v in ipairs(mapMsgData.List) do
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, v, true)
end
else
for _, v in ipairs(mapMsgData.List) do
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, v, false)
end
end
end
function StarTowerBookData:GetFateCardBundleQuest(nBundleId)
local mapQuest = {}
if self.mapFateCardQuest[nBundleId] ~= nil then
for nId, data in pairs(self.mapFateCardQuest[nBundleId]) do
data.Id = nId
table.insert(mapQuest, data)
end
end
return mapQuest
end
function StarTowerBookData:GetAllFateCardBundle()
local mapBundle = {}
local foreachTableLine = function(line)
mapBundle[line.Id] = {
nSort = line.SortId,
tbCardList = {}
}
end
ForEachTableLine(DataTable.StarTowerBookFateCardBundle, foreachTableLine)
for nId, v in pairs(self.mapFateCardBook) do
local mapCfg = ConfigTable.GetData("StarTowerBookFateCard", nId)
if mapCfg ~= nil then
local nBundleId = mapCfg.BundleId
if mapBundle[nBundleId] ~= nil then
table.insert(mapBundle[nBundleId].tbCardList, {
nId = nId,
nStatus = v.Status,
nSort = v.Sort
})
end
end
end
return mapBundle
end
function StarTowerBookData:GetAllEventBookData()
local mapEventBook = {}
local mapQuestData = PlayerData.Quest:GetStarTowerBookQuestData()
local foreachEventRewardTableLine = function(line)
if not line.IsBanned then
local tbData = {}
tbData.Id = line.Id
tbData.Status = mapQuestData[line.Id] ~= nil and MAPSTATUS[mapQuestData[line.Id].nStatus] or AllEnum.BookQuestStatus.Received
tbData.CfgData = line
tbData.nGoal = mapQuestData[line.Id] ~= nil and mapQuestData[line.Id].nGoal or 0
tbData.nCurProgress = mapQuestData[line.Id] ~= nil and mapQuestData[line.Id].nCurProgress or 0
table.insert(mapEventBook, tbData)
end
end
ForEachTableLine(ConfigTable.Get("StarTowerBookEventReward"), foreachEventRewardTableLine)
table.sort(mapEventBook, function(a, b)
if a.CfgData.Sort == b.CfgData.Sort then
return a.CfgData.Id < b.CfgData.Id
end
return a.CfgData.Sort < b.CfgData.Sort
end)
return mapEventBook
end
function StarTowerBookData:GetRandomEntranceCfg()
local nIndex = math.random(1, #self.mapEntranceCfg)
return self.mapEntranceCfg[nIndex]
end
function StarTowerBookData:UpdateServerRedDot(msgData)
for _, v in ipairs(msgData.CharIds) do
local mapCfg = ConfigTable.GetData_Character(v)
if mapCfg ~= nil and mapCfg.Available then
local nElement = mapCfg.EET
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {nElement, v}, true)
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {0, v}, true)
end
end
for _, v in ipairs(msgData.Bundles) do
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, v, true)
end
end
function StarTowerBookData:SendPotentialBriefListMsg(callback)
local sucCall = function(_, mapMsgData)
if mapMsgData.Infos ~= nil then
for _, v in ipairs(mapMsgData.Infos) do
local nCharId = v.CharId
if nil ~= self.mapPotentialBookBrief[nCharId] then
self.mapPotentialBookBrief[nCharId].Count = v.Count
end
end
end
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_book_potential_brief_list_get_req, {}, nil, sucCall)
end
function StarTowerBookData:SendPotentialBookMsg(nCharId, callback)
local sucCall = function(_, mapMsgData)
if mapMsgData.Potentials ~= nil then
if nil == self.mapPotentialBook[nCharId] then
self.mapPotentialBook[nCharId] = {}
end
self.mapPotentialBook[nCharId].Init = true
for _, v in ipairs(mapMsgData.Potentials) do
self.mapPotentialBook[nCharId].PotentialList[v.Id] = v.Level
end
end
if mapMsgData.ReceivedIds ~= nil then
for _, v in ipairs(mapMsgData.ReceivedIds) do
local mapCfg = ConfigTable.GetData("StarTowerBookPotentialReward", v)
if mapCfg ~= nil and self.mapPotentialQuest[mapCfg.CharId] ~= nil then
self.mapPotentialQuest[mapCfg.CharId][v].Status = AllEnum.BookQuestStatus.Received
end
end
end
self:RefreshPotentialQuest()
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_book_char_potential_get_req, {Value = nCharId}, nil, sucCall)
end
function StarTowerBookData:SendReceivePotentialRewardMsg(nCharId, callback)
local sucCall = function(_, mapMsgData)
for _, v in ipairs(mapMsgData.ReceivedIds) do
local mapCfg = ConfigTable.GetData("StarTowerBookPotentialReward", v)
if mapCfg ~= nil and self.mapPotentialQuest[mapCfg.CharId] ~= nil then
self.mapPotentialQuest[mapCfg.CharId][v].Status = AllEnum.BookQuestStatus.Received
end
end
local mapCharCfg = ConfigTable.GetData_Character(nCharId)
if mapCharCfg ~= nil and mapCharCfg.Available then
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {
mapCharCfg.EET,
nCharId
}, false)
RedDotManager.SetValid(RedDotDefine.StarTowerBook_Potential_Reward, {0, nCharId}, false)
end
EventManager.Hit("ReceivePotentialBookReward")
UTILS.OpenReceiveByChangeInfo(mapMsgData.Change, callback)
end
HttpNetHandler.SendMsg(NetMsgId.Id.star_tower_book_potential_reward_receive_req, {Value = nCharId}, nil, sucCall)
end
function StarTowerBookData:SendGetFateCardBookMsg(callback)
local sucCall = function(_, mapMsgData)
self.bFateCardInit = true
for _, v in ipairs(mapMsgData.Cards) do
if nil ~= self.mapFateCardBook[v] then
self.mapFateCardBook[v].Status = AllEnum.FateCardBookStatus.Collect
end
end
self:UpdateFateCardStatus()
for _, v in ipairs(mapMsgData.Quests) do
local mapCfg = ConfigTable.GetData("StarTowerBookFateCardQuest", v)
if mapCfg ~= nil then
local nBundleId = mapCfg.BundleId
if self.mapFateCardQuest[nBundleId] ~= nil then
self.mapFateCardQuest[nBundleId][v].Status = AllEnum.BookQuestStatus.Received
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, nBundleId, false)
end
end
end
self:RefreshFateCardRedDot()
if callback ~= nil then
callback()
end
end
HttpNetHandler.SendMsg(NetMsgId.Id.tower_book_fate_card_detail_req, {}, nil, sucCall)
end
function StarTowerBookData:SendReceiveFateCardRewardMsg(nBundleId, nQuestId, callback)
local sucCall = function(_, mapMsgData)
if self.mapFateCardQuest[nBundleId] ~= nil then
for nId, v in pairs(self.mapFateCardQuest[nBundleId]) do
if v.Status == AllEnum.BookQuestStatus.Complete then
self.mapFateCardQuest[nBundleId][nId].Status = AllEnum.BookQuestStatus.Received
end
end
end
RedDotManager.SetValid(RedDotDefine.StarTowerBook_FateCard_Reward, nBundleId, false)
EventManager.Hit("ReceiveFateCardBookReward")
UTILS.OpenReceiveByChangeInfo(mapMsgData, callback)
end
local msgData = {
CardBundleId = nBundleId,
QuestId = nQuestId or 0
}
HttpNetHandler.SendMsg(NetMsgId.Id.tower_book_fate_card_reward_receive_req, msgData, nil, sucCall)
end
function StarTowerBookData:OnEvent_UpdateWorldClass()
end
function StarTowerBookData:OnEvent_StarTowerPass()
end
return StarTowerBookData
@@ -0,0 +1,201 @@
local PlayerTutorialData = class("PlayerTutorialData")
local LevelData = require("GameCore.Data.DataClass.Tutorial.TutorialLevelData")
local LocalData = require("GameCore.Data.LocalData")
function PlayerTutorialData:Init()
self.curLevelId = 0
self.tbLevelData = {}
self.LevelIdList = {}
end
function PlayerTutorialData:CacheTutorialData(levelsData)
local forEachTableFunc = function(config)
self:UpdateLevel({
nlevelId = config.Id,
LevelStatus = AllEnum.ActQuestStatus.UnComplete
})
table.insert(self.LevelIdList, config.Id)
end
ForEachTableLine(DataTable.TutorialLevel, forEachTableFunc)
for _, level in pairs(levelsData) do
self:UpdateLevel({
nlevelId = level.LevelId,
LevelStatus = self:QuestStateServer2Client(level.Passed, level.RewardReceived)
})
end
local sortFunc = function(a, b)
return a < b
end
table.sort(self.LevelIdList, sortFunc)
self.LevelData = LevelData.new()
local bIsNew = LocalData.GetPlayerLocalData("Tutorial_IsNew")
if bIsNew == nil then
bIsNew = true
end
local bAllComplate = true
if self.tbLevelData ~= nil then
for _, levelData in pairs(self.tbLevelData) do
if levelData.LevelStatus ~= AllEnum.ActQuestStatus.Received then
bAllComplate = false
break
end
end
end
if bAllComplate then
bIsNew = false
end
self:RefreshRedDot(bIsNew)
end
function PlayerTutorialData:GetLevelLockType(levelId)
local levelData = self:GetLevelData(levelId)
if levelData.LevelStatus == AllEnum.ActQuestStatus.Complete or levelData.LevelStatus == AllEnum.ActQuestStatus.Received then
return AllEnum.TutorialLevelLockType.None
end
local levelConfig = ConfigTable.GetData("TutorialLevel", levelId)
if levelConfig == nil then
return AllEnum.TutorialLevelLockType.None
end
if levelConfig.WorldClass > PlayerData.Base:GetWorldClass() then
return AllEnum.TutorialLevelLockType.WorldClass
end
local preLevelData = self:GetLevelData(levelConfig.PreLevelId)
if preLevelData == nil then
return AllEnum.TutorialLevelLockType.None
end
if preLevelData.LevelStatus == AllEnum.ActQuestStatus.UnComplete then
return AllEnum.TutorialLevelLockType.PreLevel
end
return AllEnum.TutorialLevelLockType.None
end
function PlayerTutorialData:GetLevelList()
return self.LevelIdList
end
function PlayerTutorialData:UpdateLevel(levelData)
self.tbLevelData[levelData.nlevelId] = levelData
end
function PlayerTutorialData:GetLevelData(levelId)
return self.tbLevelData[levelId]
end
function PlayerTutorialData:GetProgress()
local nReceivedCount = 0
for _, data in pairs(self.tbLevelData) do
if data.LevelStatus == AllEnum.ActQuestStatus.Received then
nReceivedCount = nReceivedCount + 1
end
end
return #self.LevelIdList, nReceivedCount
end
function PlayerTutorialData:GetNextLevelId(levelId)
local nNextlevelId = 0
local nIndex = table.indexof(self.LevelIdList, levelId)
if 0 < nIndex and nIndex + 1 <= #self.LevelIdList then
for i = nIndex + 1, #self.LevelIdList do
if self:GetLevelLockType(self.LevelIdList[i]) == AllEnum.TutorialLevelLockType.None then
nNextlevelId = self.LevelIdList[i]
break
end
end
end
return nNextlevelId
end
function PlayerTutorialData:GetLevelReward(levelId)
local mapSendMsg = {Value = levelId}
local succ_cb = function(_, mapData)
self:UpdateLevel({
nlevelId = levelId,
LevelStatus = AllEnum.ActQuestStatus.Received
})
local bIsNew = LocalData.GetPlayerLocalData("Tutorial_IsNew")
self:RefreshRedDot(bIsNew)
EventManager.Hit(EventId.TutorialQuestReceived, mapData)
end
HttpNetHandler.SendMsg(NetMsgId.Id.tutorial_level_reward_receive_req, mapSendMsg, nil, succ_cb)
end
function PlayerTutorialData:EnterLevel(levelId, callback)
self.curLevelId = levelId
local levelConfig = ConfigTable.GetData("TutorialLevel", self.curLevelId)
if levelConfig == nil then
return
end
local buildData = ConfigTable.GetData("TrialBuild", levelConfig.TutorialBuild)
if buildData == nil then
return
end
local charIdList = {}
local discIdList = {}
for _, id in pairs(buildData.Char) do
local charData = ConfigTable.GetData("TrialCharacter", id)
if charData ~= nil then
table.insert(charIdList, charData.CharId)
end
end
for _, id in pairs(buildData.Disc) do
local discData = ConfigTable.GetData("TrialDisc", id)
if discData ~= nil then
table.insert(discIdList, discData.DiscId)
end
end
self.LevelData:InitLevelData(self.curLevelId, charIdList, discIdList)
if callback ~= nil then
callback()
end
end
function PlayerTutorialData:FinishLevel(bResult)
if not bResult then
self.LevelData:FinishLevel(false)
self.curLevelId = 0
else
local levelData = self:GetLevelData(self.curLevelId)
if levelData ~= nil then
if levelData.LevelStatus == AllEnum.ActQuestStatus.UnComplete then
self.LevelData:FinishLevel(true)
local mapSendMsg = {
Value = self.curLevelId
}
local func_cb = function()
self:UpdateLevel({
nlevelId = self.curLevelId,
LevelStatus = AllEnum.ActQuestStatus.Complete
})
self.curLevelId = 0
end
HttpNetHandler.SendMsg(NetMsgId.Id.tutorial_level_settle_req, mapSendMsg, nil, func_cb)
else
self.LevelData:FinishLevel(true)
self.curLevelId = 0
end
end
end
end
function PlayerTutorialData:GetCurDicId()
return self.LevelData:GetCurDicId()
end
function PlayerTutorialData:RefreshRedDot(bIsNew)
local bFuncUnlock = PlayerData.Base:CheckFunctionUnlock(GameEnum.OpenFuncType.TutorialLevel)
if not bFuncUnlock then
return
end
LocalData.SetPlayerLocalData("Tutorial_IsNew", bIsNew)
if bIsNew then
RedDotManager.SetValid(RedDotDefine.Task_Tutorial, nil, true)
return
end
local bRedDot = false
if self.tbLevelData ~= nil then
for _, levelData in pairs(self.tbLevelData) do
if levelData.LevelStatus == AllEnum.ActQuestStatus.Complete then
bRedDot = true
break
end
end
end
RedDotManager.SetValid(RedDotDefine.Task_Tutorial, nil, bRedDot)
end
function PlayerTutorialData:QuestStateServer2Client(Passed, RewardReceived)
if not Passed then
return AllEnum.ActQuestStatus.UnComplete
elseif Passed and not RewardReceived then
return AllEnum.ActQuestStatus.Complete
else
return AllEnum.ActQuestStatus.Received
end
end
return PlayerTutorialData
@@ -0,0 +1,283 @@
local TutorialLevelData = class("TutorialLevelData")
local AdventureModuleHelper = CS.AdventureModuleHelper
local mapEventConfig = {
UpdateOperationTips = "OnEvent_UpdateTips",
OpenTutorialCard = "OnEvent_OpenTutorialCard",
TaskLevel_TaskFinish = "OnEvent_UpdateFinishTaskCount",
AdventureModuleEnter = "OnEvent_AdventureModuleEnter",
TutorialLevelSuccess = "OnEvent_LevelSuccess",
TutorialPotentialSelect = "OnEvent_PotentialSelect",
TutorialRefreshNoteCount = "OnEvent_RefreshNoteCount",
Trigger_Guide_Index = "OnEvent_GuideStart",
GuideEnd = "OnEvent_GuideEnd",
ShowTutorialButtonHint = "OnEvent_ShowButtonHint"
}
function TutorialLevelData:ctor()
end
function TutorialLevelData:InitData()
self.nlevelId = 0
self.tbCharId = {}
self.tbDiscId = {}
self.CardId = 0
self.TipsKey = ""
self.CurQuestCount = 0
self.MaxQuestCount = 0
self.levelConfig = nil
self.floorConfig = nil
end
function TutorialLevelData:InitLevelData(levelId, tbCharId, tbDiscId)
self:InitData()
self:BindEvent()
self.nlevelId = levelId
self.levelConfig = ConfigTable.GetData("TutorialLevel", self.nlevelId)
self.floorConfig = ConfigTable.GetData("TutorialLevelFloor", self.levelConfig.FloorId)
self.mapBuildData = PlayerData.Build:GetTrialBuild(self.levelConfig.TutorialBuild)
self.tbCharacterPotential = {}
self.tbCharId, self.tbCharTrialId, self.mapCharData, self.mapTalentAddLevel = {}, {}, {}, {}
for _, mapChar in ipairs(self.mapBuildData.tbChar) do
table.insert(self.tbCharId, mapChar.nTid)
self.tbCharTrialId[mapChar.nTid] = mapChar.nTrialId
self.mapCharData[mapChar.nTid] = PlayerData.Char:GetTrialCharById(mapChar.nTrialId)
self.mapTalentAddLevel[mapChar.nTid] = PlayerData.Talent:GetTrialEnhancedPotential(mapChar.nTrialId)
end
self.tbDiscId, self.mapDiscData = {}, {}
for _, nDiscId in ipairs(self.mapBuildData.tbDisc) do
if 0 < nDiscId then
table.insert(self.tbDiscId, nDiscId)
local mapCfg = ConfigTable.GetData("TrialDisc", nDiscId)
if mapCfg then
self.mapDiscData[mapCfg.DiscId] = PlayerData.Disc:GetTrialDiscById(nDiscId)
end
end
end
self.MaxQuestCount = #self.floorConfig.QuestFlow
end
function TutorialLevelData:FinishLevel(result)
self:UnBindEvent()
local nCurQuestCount = self:GetCurQuestCount() or 0
local nMaxQuestCount = self:GetMaxQuestCount() or 0
local tbCharId = self:GetCharList() or {}
if not result then
EventManager.Hit(EventId.OpenPanel, PanelId.TutorialResult, 2, self.nlevelId, {}, nCurQuestCount, nMaxQuestCount, tbCharId, {}, false)
else
local tbSkin = {}
for _, nCharId in ipairs(self.tbCharId) do
local nSkinId = PlayerData.Char:GetCharSkinId(nCharId)
table.insert(tbSkin, nSkinId)
end
local func_SettlementFinish = function()
end
local function levelEndCallback()
EventManager.Remove("ADVENTURE_LEVEL_UNLOAD_COMPLETE", self, levelEndCallback)
local levelConfig = ConfigTable.GetData("TutorialLevel", self.nlevelId)
if levelConfig == nil then
return
end
local floorConfig = ConfigTable.GetData("TutorialLevelFloor", levelConfig.FloorId)
if floorConfig == nil then
return
end
local nType = floorConfig.Theme
local sName = ConfigTable.GetData("EndSceneType", nType).EndSceneName
print("sceneName:" .. sName)
AdventureModuleHelper.PlaySettlementPerform(sName, "", tbSkin, func_SettlementFinish)
end
EventManager.Add("ADVENTURE_LEVEL_UNLOAD_COMPLETE", self, levelEndCallback)
local function openBattleResultPanel()
EventManager.Remove("SettlementPerformLoadFinish", self, openBattleResultPanel)
EventManager.Hit(EventId.OpenPanel, PanelId.TutorialResult, 1, self.nlevelId, {}, nCurQuestCount, nMaxQuestCount, tbCharId, {}, false)
PlayerData.Build:DeleteTrialBuild()
end
EventManager.Add("SettlementPerformLoadFinish", self, openBattleResultPanel)
AdventureModuleHelper.LevelStateChanged(true)
EventManager.Hit(EventId.OpenPanel, PanelId.BattleResultMask)
end
end
function TutorialLevelData:GetCurDicId()
return self.CardId
end
function TutorialLevelData:GetCurQuestCount()
return self.CurQuestCount
end
function TutorialLevelData:GetMaxQuestCount()
return self.MaxQuestCount
end
function TutorialLevelData:GetCharList()
return self.tbCharId
end
function TutorialLevelData:SetDiscInfo()
local tbDiscInfo = {}
for k, nDiscId in ipairs(self.mapBuildData.tbDisc) do
if k <= 3 then
local discInfo = PlayerData.Disc:CalcTrialInfoInBuild(nDiscId, self.mapBuildData.tbSecondarySkill)
table.insert(tbDiscInfo, discInfo)
end
end
safe_call_cs_func(CS.AdventureModuleHelper.SetDiscInfo, tbDiscInfo)
end
function TutorialLevelData:CalCharFixedEffect(nTrialId, bMainChar, tbDiscId)
local stActorInfo = CS.Lua2CSharpInfo_CharAttribute()
PlayerData.Char:CalCharacterTrialAttrBattle(nTrialId, stActorInfo, bMainChar, tbDiscId, self.levelConfig.TutorialBuild)
return stActorInfo
end
function TutorialLevelData:GetCharIdByBtnName(btnName)
if self.tbCharId == nil then
return
end
if btnName == "Fire1" or btnName == "Fire2" or btnName == "Fire3" or btnName == "Fire4" then
return self.tbCharId[1]
elseif btnName == "ActorSwitch1" or btnName == "SwitchWithUltra1" then
return self.tbCharId[2]
elseif btnName == "ActorSwitch2" or btnName == "SwitchWithUltra2" then
return self.tbCharId[3]
end
end
function TutorialLevelData:GetByBtnType(btnName)
if btnName == "Fire1" or btnName == "Fire3" then
return 1
elseif btnName == "ActorSwitch1" or btnName == "ActorSwitch2" or btnName == "Fire2" then
return 2
else
if btnName == "SwitchWithUltra1" or btnName ~= "SwitchWithUltra2" then
end
return 4
end
end
function TutorialLevelData:OnEvent_UpdateTips(tipsKey)
if tipsKey == self.TipsKey then
return
end
self.TipsKey = tipsKey
EventManager.Hit("Tutorial_UpdateTips", self.TipsKey)
end
function TutorialLevelData:OnEvent_OpenTutorialCard(cardId, bIsLevelStart)
self.CardId = cardId
EventManager.Hit("Tutorial_OpenCard", self.CardId, bIsLevelStart)
end
function TutorialLevelData:OnEvent_UpdateFinishTaskCount(isLast)
self.CurQuestCount = self.CurQuestCount + 1
end
function TutorialLevelData:OnEvent_AdventureModuleEnter()
self:SetDiscInfo()
for idx, nCharId in ipairs(self.tbCharId) do
local stActorInfo = self:CalCharFixedEffect(self.tbCharTrialId[nCharId], idx == 1, self.tbDiscId)
safe_call_cs_func(CS.AdventureModuleHelper.SetActorAttribute, nCharId, stActorInfo)
end
local tbDisc = {}
for _, v in ipairs(self.tbDiscId) do
local mapCfg = ConfigTable.GetData("TrialDisc", v)
if mapCfg then
table.insert(tbDisc, mapCfg.DiscId)
end
end
EventManager.Hit(EventId.OpenPanel, PanelId.TutorialPanel, self.tbCharId, tbDisc, self.mapCharData, self.mapDiscData)
end
function TutorialLevelData:OnEvent_LevelSuccess()
EventManager.Hit("TutorialLevel_Success")
end
function TutorialLevelData:OnEvent_PotentialSelect(potentialData)
local potentialList = {}
for _, pot in pairs(potentialData) do
table.insert(potentialList, pot)
end
local callback = function(index)
local nPotentialId = potentialList[index]
local potConfig = ConfigTable.GetData("Potential", nPotentialId)
if potConfig == nil then
return
end
if self.tbCharacterPotential[potConfig.CharId] == nil then
self.tbCharacterPotential[potConfig.CharId] = {}
end
local stPerkInfo = CS.Lua2CSharpInfo_TPPerkInfo()
stPerkInfo.perkId = nPotentialId
stPerkInfo.nCount = 1
local bChange = false
if #self.tbCharacterPotential[potConfig.CharId] >= 1 then
bChange = true
end
safe_call_cs_func(CS.AdventureModuleHelper.ChangePersonalPerkIds, {stPerkInfo}, potConfig.CharId, bChange)
table.insert(self.tbCharacterPotential[potConfig.CharId], nPotentialId)
end
EventManager.Hit("Tutorial_PotentialSelect", potentialList, callback)
end
function TutorialLevelData:OnEvent_GuideStart(index)
self.GuideIndex = index
end
function TutorialLevelData:OnEvent_GuideEnd()
NovaAPI.DispatchEventWithData("Tutorial_GuideEnd", nil, {
self.GuideIndex
})
end
function TutorialLevelData:OnEvent_RefreshNoteCount(note, dropNote, activeSkills)
local noteList = {}
local dropNoteList = {}
local mapChangeSecondarySkill = {}
for id, count in pairs(note) do
noteList[id] = count
end
for id, count in pairs(dropNote) do
local bIsNew = count - noteList[id] == 0
dropNoteList[id] = {
Tid = id,
LuckyLevel = 0,
New = bIsNew,
Qty = count
}
end
for id, v in pairs(activeSkills) do
local skillData = {Active = true, SecondaryId = v}
table.insert(mapChangeSecondarySkill, skillData)
end
self:ResetNoteInfo(noteList)
self:ResetDiscInfo(noteList)
EventManager.Hit("RefreshNoteCount", noteList, dropNoteList, mapChangeSecondarySkill, false)
end
function TutorialLevelData:OnEvent_ShowButtonHint(btnName, isShow)
local charId = self:GetCharIdByBtnName(btnName)
local btnId = self:GetByBtnType(btnName)
EventManager.Hit("Open_Ultra_Special_FX", charId * 10 + btnId, isShow)
end
function TutorialLevelData:ResetNoteInfo(noteList)
local tbNoteInfo = {}
for i, v in pairs(noteList) do
local noteInfo = CS.Lua2CSharpInfo_NoteInfo()
noteInfo.noteId = i
noteInfo.noteCount = v
table.insert(tbNoteInfo, noteInfo)
end
safe_call_cs_func(CS.AdventureModuleHelper.SetNoteInfo, tbNoteInfo)
end
function TutorialLevelData:ResetDiscInfo(noteList)
local tbDiscInfo = {}
for nDiscId, mapDiscData in pairs(self.mapDiscData) do
if table.indexof(self.tbDiscId, nDiscId) <= 3 and mapDiscData ~= nil then
local discInfo = mapDiscData:GetDiscInfo(noteList)
table.insert(tbDiscInfo, discInfo)
end
end
safe_call_cs_func(CS.AdventureModuleHelper.SetDiscInfo, tbDiscInfo)
end
function TutorialLevelData:BindEvent()
if type(mapEventConfig) ~= "table" then
return
end
for nEventId, sCallbackName in pairs(mapEventConfig) do
local callback = self[sCallbackName]
if type(callback) == "function" then
EventManager.Add(nEventId, self, callback)
end
end
end
function TutorialLevelData:UnBindEvent()
if type(mapEventConfig) ~= "table" then
return
end
for nEventId, sCallbackName in pairs(mapEventConfig) do
local callback = self[sCallbackName]
if type(callback) == "function" then
EventManager.Remove(nEventId, self, callback)
end
end
end
return TutorialLevelData
+44
View File
@@ -0,0 +1,44 @@
local ConfigData = require("GameCore.Data.ConfigData")
local PB = require("pb")
local GameTableDefine = require("Game.CodeGen.GAME_TABLE_DEFINE")
require("GameCore.Data.LuaDataTable")
local rawget = rawget
local pairs = pairs
local tableInsert = table.insert
local assert = assert
local GameBinTable = {}
local ForEachTableLine = function(tb, f)
if f == nil or tb == nil then
return
end
local raw = rawget(tb, "raw")
for k, _ in pairs(raw) do
f(tb[k])
end
end
local GetTableKeys = function(tb)
if tb == nil then
return
end
local raw = rawget(tb, "raw")
if raw == nil then
traceback("raw = nil !")
return
end
local keys = {}
for k, _ in pairs(raw) do
tableInsert(keys, k)
end
return keys
end
function LoadGameBinTable(sLanguage)
local pbSchema = NovaAPI.LoadLuaBytes("Game/CodeGen/table.pb")
assert(PB.load(pbSchema))
for k, v in pairs(GameTableDefine.CommonTable) do
local tab = ConfigData.LoadCommonBinTable(k, v, sLanguage)
GameBinTable[k] = tab
end
_G.DataTable = GameBinTable
_G.ForEachTableLine = ForEachTableLine
_G.GetTableKeys = GetTableKeys
end
+32
View File
@@ -0,0 +1,32 @@
local ConfigData = require("GameCore.Data.ConfigData")
local GameTableDefine = require("Game.CodeGen.GAME_TABLE_DEFINE")
local pairs = pairs
local tableInsert = table.insert
local GameJsonTable = {}
local ForEachTableLine = function(tb, f)
if f == nil or tb == nil then
return
end
for k, _ in pairs(tb) do
f(tb[k])
end
end
local GetTableKeys = function(tb)
if tb == nil then
return
end
local keys = {}
for k, _ in pairs(tb) do
tableInsert(keys, k)
end
return keys
end
function LoadGameJsonTable(sLanguage)
for k, v in pairs(GameTableDefine.CommonTable) do
local tab = ConfigData.LoadCommonJsonTable(k, v, sLanguage)
GameJsonTable[k] = tab
end
_G.DataTable = GameJsonTable
_G.ForEachTableLine = ForEachTableLine
_G.GetTableKeys = GetTableKeys
end
+16
View File
@@ -0,0 +1,16 @@
local ConfigData = require("GameCore.Data.ConfigData")
require("Diagnose")
local tab = {}
function tab.Init(lang)
tab.SetType(lang)
end
function tab.SetType(lang)
tab.LanguageType = lang
end
function tab.GetType()
if tab.LanguageType == nil then
tab.LanguageType = "zh_CN"
end
return tab.LanguageType
end
_G.LanguageTable = tab
+56
View File
@@ -0,0 +1,56 @@
local RapidJson = require("rapidjson")
local String = CS.System.String
local PlayerPrefs = CS.UnityEngine.PlayerPrefs
local LocalData = {}
function LocalData.SetLocalData(sMainKey, sSubKey, sValue)
local sJson = PlayerPrefs.GetString(sMainKey)
local mapData
if String.IsNullOrEmpty(sJson) == true then
mapData = {}
mapData[sSubKey] = sValue
else
mapData = RapidJson.decode(sJson)
mapData[sSubKey] = sValue
end
sJson = RapidJson.encode(mapData)
PlayerPrefs.SetString(sMainKey, sJson)
PlayerPrefs.Save()
end
function LocalData.GetLocalData(sMainKey, sSubKey)
local sJson = PlayerPrefs.GetString(sMainKey)
if String.IsNullOrEmpty(sJson) == true then
return nil
else
local mapData = RapidJson.decode(sJson)
return mapData[sSubKey]
end
end
function LocalData.DelLocalData(sMainKey, sSubKey)
local sJson = PlayerPrefs.GetString(sMainKey)
if String.IsNullOrEmpty(sJson) == false then
local mapData = RapidJson.decode(sJson)
mapData[sSubKey] = nil
sJson = RapidJson.encode(mapData)
PlayerPrefs.SetString(sMainKey, sJson)
PlayerPrefs.Save()
end
end
function LocalData.SetPlayerLocalData(sKey, sValue)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
LocalData.SetLocalData(tostring(nPlayerId), sKey, sValue)
end
end
function LocalData.GetPlayerLocalData(sKey)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
return LocalData.GetLocalData(tostring(nPlayerId), sKey)
end
end
function LocalData.DelPlayerLocalData(sKey)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
LocalData.DelLocalData(tostring(nPlayerId), sKey)
end
end
return LocalData
+70
View File
@@ -0,0 +1,70 @@
local LocalSettingData = {}
local LocalData = require("GameCore.Data.LocalData")
local WwiseManger = CS.WwiseAudioManager
local UIGameSystemSetup = CS.UIGameSystemSetup
local DefaultSoundValue = 100
local LoadLocalData = function(key, defaultValue)
local value = LocalData.GetLocalData("GameSystemSettingsData", key)
if value ~= nil then
return value
else
return defaultValue
end
end
local InitCurSignInData = function()
LocalData.DelLocalData("UpgradeMat", "Presents")
LocalData.DelLocalData("UpgradeMat", "Outfit")
end
local LoadSoundData = function()
LocalSettingData.mapData.NumMusic = LoadLocalData("NumMusic", DefaultSoundValue)
LocalSettingData.mapData.OpenMusic = LoadLocalData("OpenMusic", true)
LocalSettingData.mapData.NumSfx = LoadLocalData("NumSfx", DefaultSoundValue)
LocalSettingData.mapData.OpenSfx = LoadLocalData("OpenSfx", true)
LocalSettingData.mapData.NumChar = LoadLocalData("NumChar", DefaultSoundValue)
LocalSettingData.mapData.OpenChar = LoadLocalData("OpenChar", true)
LocalSettingData.mapData.WwiseMuteInBackground = LoadLocalData("WwiseMuteInBackground", true)
end
local LoadBattleData = function()
LocalSettingData.mapData.Animation = LoadLocalData("Animation", AllEnum.BattleAnimSetting.DayOnce)
if LocalSettingData.mapData.Animation == 1 then
UIGameSystemSetup.Instance.PlayType = UIGameSystemSetup.TimeLinePlayType.dayOnce
elseif LocalSettingData.mapData.Animation == 2 then
UIGameSystemSetup.Instance.PlayType = UIGameSystemSetup.TimeLinePlayType.everyTime
elseif LocalSettingData.mapData.Animation == 3 then
UIGameSystemSetup.Instance.PlayType = UIGameSystemSetup.TimeLinePlayType.none
end
LocalSettingData.mapData.AnimationSub = LoadLocalData("AnimationSub", AllEnum.BattleAnimSetting.DayOnce)
if not NovaAPI.IsMobilePlatform() then
LocalSettingData.mapData.Mouse = LoadLocalData("Mouse", false)
UIGameSystemSetup.Instance.EnableMouseInputDir = LocalSettingData.mapData.Mouse
end
LocalSettingData.mapData.JoyStick = LoadLocalData("JoyStick", true)
UIGameSystemSetup.Instance.EnableFloatingJoyStick = LocalSettingData.mapData.JoyStick
LocalSettingData.mapData.Gizmos = LoadLocalData("Gizmos", true)
UIGameSystemSetup.Instance.EnableAttackGizmos = LocalSettingData.mapData.Gizmos
LocalSettingData.mapData.AutoUlt = LoadLocalData("AutoUlt", true)
UIGameSystemSetup.Instance.EnableAutoUlt = LocalSettingData.mapData.AutoUlt
if not NovaAPI.IsMobilePlatform() then
LocalSettingData.mapData.BattleHUD = LoadLocalData("BattleHUD", AllEnum.BattleHudType.Horizontal)
else
LocalSettingData.mapData.BattleHUD = LoadLocalData("BattleHUD", AllEnum.BattleHudType.Sector)
end
end
function LocalSettingData.Init()
LocalSettingData.mapData = {}
LocalSettingData.mapData.UseLive2D = LoadLocalData("UseLive2D", true)
LoadSoundData()
LoadBattleData()
InitCurSignInData()
end
function LocalSettingData.GetLocalSettingData(subKey)
return LocalSettingData.mapData[subKey]
end
function LocalSettingData.SetLocalSettingData(subKey, value)
if type(subKey) ~= "string" or value == nil then
return
end
LocalData.SetLocalData("GameSystemSettingsData", subKey, value)
LocalSettingData.mapData[subKey] = value
end
return LocalSettingData
+41
View File
@@ -0,0 +1,41 @@
local PB = require("pb")
local ipairs = ipairs
local rawget = rawget
local setmetatable = setmetatable
local ConfigData = require("GameCore.Data.ConfigData")
local ReadTable = {}
function ReadTable:__index(k)
local raw = rawget(self, "raw")
local meta = rawget(self, "meta")
local lang = meta.lang
local loaded = meta.loaded
local pbName = meta.pbName
local langs = meta.langs
local line = raw[k]
if langs ~= nil and lang == nil and not loaded then
lang = ConfigData.LoadLanguageTable(LanguageTable.GetType(), pbName)
meta.lang = lang
meta.loaded = true
end
if nil ~= line then
local lineInstance = assert(PB.decode("nova.client." .. pbName, line))
if langs ~= nil then
for _, v in ipairs(langs) do
local field = lineInstance[v]
if field ~= nil and lang ~= nil then
lineInstance[v] = lang[field] or ""
end
end
end
return lineInstance
end
end
function LoadDataTable(meta, raw, lang)
local newTable = {
raw = raw,
meta = meta,
lang = lang
}
setmetatable(newTable, ReadTable)
return newTable
end
+229
View File
@@ -0,0 +1,229 @@
local PlayerData = {back2Login = false, back2Home = false}
function PlayerData.Init()
local PlayerBaseData = require("GameCore.Data.DataClass.PlayerBaseData")
PlayerData.Base = PlayerBaseData.new()
PlayerData.Base:Init()
local PlayerCoinData = require("GameCore.Data.DataClass.PlayerCoinData")
PlayerData.Coin = PlayerCoinData.new()
PlayerData.Coin:Init()
local PlayerCharData = require("GameCore.Data.DataClass.PlayerCharData")
PlayerData.Char = PlayerCharData.new()
PlayerData.Char:Init()
local PlayerTeamData = require("GameCore.Data.DataClass.PlayerTeamData")
PlayerData.Team = PlayerTeamData.new()
PlayerData.Team:Init()
local PlayerMainlineData = require("GameCore.Data.DataClass.PlayerMainlineDataEx")
PlayerData.Mainline = PlayerMainlineData.new()
PlayerData.Mainline:Init()
local PlayerRoguelikeData = require("GameCore.Data.DataClass.PlayerRoguelikeData")
PlayerData.Roguelike = PlayerRoguelikeData.new()
PlayerData.Roguelike:Init()
local PlayerItemData = require("GameCore.Data.DataClass.PlayerItemData")
PlayerData.Item = PlayerItemData.new()
PlayerData.Item:Init()
local PlayerGachaData = require("GameCore.Data.DataClass.PlayerGachaData")
PlayerData.Gacha = PlayerGachaData.new()
PlayerData.Gacha:Init()
local PlayerMailData = require("GameCore.Data.DataClass.PlayerMailData")
PlayerData.Mail = PlayerMailData.new()
PlayerData.Mail:Init()
local PlayerStateData = require("GameCore.Data.DataClass.PlayerStateData")
PlayerData.State = PlayerStateData.new()
PlayerData.State:Init()
local PlayerBuildData = require("GameCore.Data.DataClass.PlayerBuildData")
PlayerData.Build = PlayerBuildData.new()
PlayerData.Build:Init()
PlayerData.nCurGameType = AllEnum.WorldMapNodeType.Mainline
local PlayerRogueBossData = require("GameCore.Data.DataClass.PlayerRogueBossData")
PlayerData.RogueBoss = PlayerRogueBossData.new()
PlayerData.RogueBoss:Init()
local PlayerFriendData = require("GameCore.Data.DataClass.PlayerFriendData")
PlayerData.Friend = PlayerFriendData.new()
PlayerData.Friend:Init()
local PlayerQuestData = require("GameCore.Data.DataClass.PlayerQuestData")
PlayerData.Quest = PlayerQuestData.new()
PlayerData.Quest:Init()
local PlayerShopData = require("GameCore.Data.DataClass.PlayerShopData")
PlayerData.Shop = PlayerShopData.new()
PlayerData.Shop:Init()
local PlayerGuideData = require("GameCore.Data.DataClass.PlayerGuideData")
PlayerData.Guide = PlayerGuideData.new()
PlayerData.Guide:Init()
local PlayerAchievementData = require("GameCore.Data.DataClass.PlayerAchievementData")
PlayerData.Achievement = PlayerAchievementData.new()
PlayerData.Achievement:Init()
PlayerData.Daily = require("GameCore.Data.DataClass.PlayerDailyData")
PlayerData.Daily.Init()
PlayerData.Mall = require("GameCore.Data.DataClass.PlayerMallData")
PlayerData.Mall:Init()
local PlayerHandbookData = require("GameCore.Data.DataClass/PlayerHandbookData")
PlayerData.Handbook = PlayerHandbookData.new()
PlayerData.Handbook:Init()
local PlayerCharSkinData = require("GameCore.Data.DataClass/PlayerCharSkinData")
PlayerData.CharSkin = PlayerCharSkinData.new()
PlayerData.CharSkin:Init()
local PlayerTravelerDuelData = require("GameCore.Data.DataClass.PlayerTravelerDuelData")
PlayerData.TravelerDuel = PlayerTravelerDuelData.new()
PlayerData.TravelerDuel:Init()
local PlayerBoardData = require("GameCore.Data.DataClass.PlayerBoardData")
PlayerData.Board = PlayerBoardData.new()
PlayerData.Board:Init()
local PlayerVoiceData = require("GameCore.Data.DataClass.PlayerVoiceData")
PlayerData.Voice = PlayerVoiceData.new()
PlayerData.Voice:Init()
local PlayerDailyInstanceData = require("GameCore.Data.DataClass.PlayerDailyInstanceData")
PlayerData.DailyInstance = PlayerDailyInstanceData.new()
PlayerData.DailyInstance:Init()
local PlayerEquipmentInstanceData = require("GameCore.Data.DataClass.PlayerEquipmentInstanceData")
PlayerData.EquipmentInstance = PlayerEquipmentInstanceData.new()
PlayerData.EquipmentInstance:Init()
local PlayerSkillInstanceData = require("GameCore.Data.DataClass.PlayerSkillInstanceData")
PlayerData.SkillInstance = PlayerSkillInstanceData.new()
PlayerData.SkillInstance:Init()
local PlayerCraftingData = require("GameCore.Data.DataClass.PlayerCraftingData")
PlayerData.Crafting = PlayerCraftingData.new()
PlayerData.Crafting:Init()
local PlayerDictionaryData = require("GameCore.Data.DataClass.PlayerDictionaryData")
PlayerData.Dictionary = PlayerDictionaryData.new()
PlayerData.Dictionary:Init()
local PlayerActivityData = require("GameCore.Data.DataClass.Activity.PlayerActivityData")
PlayerData.Activity = PlayerActivityData.new()
PlayerData.Activity:Init()
local PlayerPhoneData = require("GameCore.Data.DataClass.PlayerPhoneData")
PlayerData.Phone = PlayerPhoneData.new()
PlayerData.Phone:Init()
local PlayerInfinityTowerData = require("GameCore.Data.DataClass.PlayerInfinityTowerData")
PlayerData.InfinityTower = PlayerInfinityTowerData.new()
PlayerData.InfinityTower:Init()
local PlayerBattlePassData = require("GameCore.Data.DataClass.PlayerBattlePassData")
PlayerData.BattlePass = PlayerBattlePassData.new()
PlayerData.BattlePass:Init()
local PlayerTalentData = require("GameCore.Data.DataClass.PlayerTalentData")
PlayerData.Talent = PlayerTalentData.new()
PlayerData.Talent:Init()
local PlayerDiscData = require("GameCore.Data.DataClass.PlayerDiscData")
PlayerData.Disc = PlayerDiscData.new()
PlayerData.Disc:Init()
local PlayerEquipmentData = require("GameCore.Data.DataClass.PlayerEquipmentDataEx")
PlayerData.Equipment = PlayerEquipmentData.new()
PlayerData.Equipment:Init()
local PlayerStarTowerData = require("GameCore.Data.DataClass.PlayerStarTowerData")
PlayerData.StarTower = PlayerStarTowerData.new()
PlayerData.StarTower:Init()
local AvgData = require("GameCore.Data.DataClass.AvgData")
PlayerData.Avg = AvgData.new()
PlayerData.Avg:Init()
local FilterData = require("GameCore.Data.DataClass.FilterData")
PlayerData.Filter = FilterData.new()
PlayerData.Filter:Init()
printLog("Player data inited.")
PlayerData.Dispatch = require("GameCore.Data.DataClass.DispatchData")
PlayerData.Dispatch.Init()
local StarTowerBookData = require("GameCore.Data.DataClass.StarTowerBookData")
PlayerData.StarTowerBook = StarTowerBookData.new()
PlayerData.StarTowerBook:Init()
local DatingData = require("GameCore.Data.DataClass.PlayerDatingData")
PlayerData.Dating = DatingData.new()
PlayerData.Dating:Init()
local PlayerVampireSurvivorData = require("GameCore.Data.DataClass.PlayerVampireSurvivorData")
PlayerData.VampireSurvivor = PlayerVampireSurvivorData.new()
PlayerData.VampireSurvivor:Init()
local PlayerSideBannerData = require("GameCore.Data.DataClass.PlayerSideBannerData")
PlayerData.SideBanner = PlayerSideBannerData.new()
PlayerData.SideBanner:Init()
local PlayerScoreBossData = require("GameCore.Data.DataClass.PlayerScoreBossData")
PlayerData.ScoreBoss = PlayerScoreBossData.new()
PlayerData.ScoreBoss:Init()
local GameAnnouncementData = require("GameCore.Data.DataClass.GameAnnouncementData")
PlayerData.AnnouncementData = GameAnnouncementData.new()
PlayerData.AnnouncementData:Init()
local JointDrillData = require("GameCore.Data.DataClass.PlayerJointDrillData")
PlayerData.JointDrill = JointDrillData.new()
PlayerData.JointDrill:Init()
local TrialData = require("GameCore.Data.DataClass.PlayerTrialData")
PlayerData.Trial = TrialData.new()
PlayerData.Trial:Init()
local TutorialData = require("GameCore.Data.DataClass.Tutorial.PlayerTutorialData")
PlayerData.TutorialData = TutorialData.new()
PlayerData.TutorialData:Init()
local ActivityAvgData = require("GameCore.Data.DataClass.Activity.ActivityAvgData")
PlayerData.ActivityAvg = ActivityAvgData.new()
PlayerData.ActivityAvg:Init()
local HeadData = require("GameCore.Data.DataClass.PlayerHeadData")
PlayerData.HeadData = HeadData.new()
PlayerData.HeadData:Init()
local PopUpData = require("GameCore.Data.DataClass.PopUpData")
PlayerData.PopUp = PopUpData.new()
PlayerData.PopUp:Init()
local StorySet = require("GameCore.Data.DataClass.PlayerStorySetData")
PlayerData.StorySet = StorySet.new()
PlayerData.StorySet:Init()
local foreachEnumDesc = function(mapData)
CacheTable.SetField("_EnumDesc", mapData.EnumName, mapData.Value, mapData.Key)
end
ForEachTableLine(DataTable.EnumDesc, foreachEnumDesc)
end
function PlayerData.UnInit()
PlayerData.Base:UnInit()
PlayerData.Daily.UnInit()
PlayerData.Base = nil
PlayerData.Coin = nil
PlayerData.Char = nil
PlayerData.Team = nil
PlayerData.Mainline = nil
PlayerData.Roguelike = nil
PlayerData.Item = nil
PlayerData.Gacha = nil
PlayerData.Mail = nil
PlayerData.State = nil
PlayerData.Friend = nil
PlayerData.Quest:UnInit()
PlayerData.Quest = nil
PlayerData.Guide:UnInit()
PlayerData.Guide = nil
PlayerData.PlayerFixedRoguelikeData = nil
PlayerData.Shop:UnInit()
PlayerData.Shop = nil
PlayerData.Achievement = nil
PlayerData.Mall:UnInit()
PlayerData.Handbook = nil
PlayerData.CharSkin = nil
PlayerData.TravelerDuel:UnInit()
PlayerData.TravelerDuel = nil
PlayerData.DailyInstance = nil
PlayerData.EquipmentInstance:UnInit()
PlayerData.EquipmentInstance = nil
PlayerData.SkillInstance:UnInit()
PlayerData.SkillInstance = nil
PlayerData.Board = nil
PlayerData.Voice:UnInit()
PlayerData.Voice = nil
PlayerData.Dictionary = nil
PlayerData.Activity:UnInit()
PlayerData.Activity = nil
PlayerData.Phone = nil
PlayerData.InfinityTower:UnInit()
PlayerData.InfinityTower = nil
PlayerData.Talent = nil
PlayerData.Disc = nil
PlayerData.Equipment = nil
PlayerData.Filter = nil
PlayerData.StarTowerBook = nil
PlayerData.StarTower:UnInit()
PlayerData.StarTower = nil
PlayerData.Dating:UnInit()
PlayerData.Dating = nil
PlayerData.Avg:UnInit()
PlayerData.VampireSurvivor:UnInit()
PlayerData.VampireSurvivor = nil
PlayerData.SideBanner:UnInit()
PlayerData.SideBanner = nil
PlayerData.ScoreBoss:UnInit()
PlayerData.ScoreBoss = nil
PlayerData.AnnouncementData = nil
PlayerData.JointDrill:UnInit()
PlayerData.JointDrill = nil
PlayerData.Trial = nil
PlayerData.StorySet = nil
end
return PlayerData
+190
View File
@@ -0,0 +1,190 @@
local PopUpManager = {}
local ClientManager = CS.ClientManager.Instance
local LocalData = require("GameCore.Data.LocalData")
local RapidJson = require("rapidjson")
local ModuleManager = require("GameCore.Module.ModuleManager")
local popUpPanelConfig = {}
local _tbPopUpQueue = {}
local _tbPopUpCache = {}
local _popUpCallback
local _bInPopUpQueue = false
local _bInterruptPopUp = false
local _tbSpecifyPopUp = {}
local _tempPopUpMapData = {}
local _interruptPopUpIndex = 0
function PopUpManager.Init()
local foreachPopupSeq = function(mapData)
local data = {
nPanelId = mapData.PanelId,
nSortId = mapData.SortId,
bLocalSave = mapData.bLocalSave
}
popUpPanelConfig[mapData.Type] = data
end
ForEachTableLine(ConfigTable.Get("PopUpSequence"), foreachPopupSeq)
end
function PopUpManager.InitLoginQueue()
local sTime = LocalData.GetPlayerLocalData("LoginPanelTime")
local nTime = tonumber(sTime) or 0
local nNextTime = ClientManager:GetNextRefreshTime(ClientManager.serverTimeStamp)
if nTime < nNextTime then
_tbPopUpQueue = {}
PopUpManager.SaveLocalData()
else
local sJson = LocalData.GetPlayerLocalData("LoginPanelQueue")
local tb = decodeJson(sJson)
if type(tb) == "table" then
_tbPopUpQueue = tb
end
end
end
function PopUpManager.SaveLocalData()
local nNextTime = ClientManager:GetNextRefreshTime(ClientManager.serverTimeStamp)
local tbLocalSave = {}
for _, v in ipairs(_tbPopUpQueue) do
local mapConfig = popUpPanelConfig[v.nType]
if mapConfig and mapConfig.bLocalSave then
table.insert(tbLocalSave, v)
end
end
LocalData.SetPlayerLocalData("LoginPanelQueue", RapidJson.encode(tbLocalSave))
LocalData.SetPlayerLocalData("LoginPanelTime", tostring(nNextTime))
end
function PopUpManager.StartShowPopUp(callback)
_popUpCallback = callback
_bInPopUpQueue = true
PopUpManager.PopUpDeQueue()
end
function PopUpManager.PopUpEnQueue(nType, mapData)
local bAdded = false
for nIndex, mapPopUp in ipairs(_tbPopUpQueue) do
if mapPopUp.nType == nType then
_tbPopUpQueue[nIndex].mapData = mapData
bAdded = true
break
end
end
if not bAdded then
table.insert(_tbPopUpQueue, {nType = nType, mapData = mapData})
end
table.sort(_tbPopUpQueue, function(a, b)
local nSortA = popUpPanelConfig[a.nType].nSortId or 999
local nSortB = popUpPanelConfig[b.nType].nSortId or 999
return nSortA < nSortB
end)
if nType == GameEnum.PopUpSeqType.MonthlyCard and PlayerData.Mall:CheckOrderProcess() then
return
end
EventManager.Hit("MainViewCheckOpenPanel")
end
function PopUpManager.PopUpDeQueue()
local exitPopUpQueue = function()
if _popUpCallback ~= nil then
_popUpCallback()
end
_tbPopUpCache = {}
_bInPopUpQueue = false
_bInterruptPopUp = false
_interruptPopUpIndex = 0
EventManager.Hit("Event_MainViewPopUpEnd")
end
if #_tbPopUpQueue == 0 and not _bInterruptPopUp and _interruptPopUpIndex == 0 then
exitPopUpQueue()
return
end
if not _bInterruptPopUp and _interruptPopUpIndex == 0 then
_tempPopUpMapData = table.remove(_tbPopUpQueue, 1)
else
local mapData = _tempPopUpMapData.mapData
for i = 1, _interruptPopUpIndex do
table.remove(mapData, 1)
end
if #mapData == 0 then
exitPopUpQueue()
return
else
_tempPopUpMapData.mapData = mapData
end
end
_bInterruptPopUp = false
_interruptPopUpIndex = 0
local mapNext = _tempPopUpMapData
_tbPopUpCache[mapNext.nType] = true
local callback = function(funcCall)
PopUpManager.PopUpDeQueue()
if nil ~= funcCall then
funcCall()
end
end
local mapConfig = popUpPanelConfig[mapNext.nType]
if mapConfig ~= nil then
if mapNext.nType == GameEnum.PopUpSeqType.MessageBox then
local msg = {
nType = AllEnum.MessageBox.Alert,
sContent = mapNext.mapData,
callbackConfirm = callback
}
EventManager.Hit(EventId.OpenMessageBox, msg)
else
local mapData = {}
if mapNext.nType == GameEnum.PopUpSeqType.ActivityFaceAnnounce then
for k, v in pairs(mapNext.mapData) do
table.insert(mapData, v)
end
else
mapData = mapNext.mapData
end
EventManager.Hit(EventId.OpenPanel, mapConfig.nPanelId, mapData, callback)
end
if mapConfig.bLocalSave then
PopUpManager.SaveLocalData()
end
end
end
function PopUpManager.InterruptPopUp(index)
_bInterruptPopUp = true
_interruptPopUpIndex = index
end
function PopUpManager.OpenPopUpPanelByType(nType, callback)
local nRemoveIdx = 0
for nIdx, data in ipairs(_tbPopUpQueue) do
if data.nType == nType then
nRemoveIdx = nIdx
break
end
end
if nRemoveIdx ~= 0 then
local mapNext = table.remove(_tbPopUpQueue, nRemoveIdx)
local mapConfig = popUpPanelConfig[mapNext.nType]
if mapConfig ~= nil then
EventManager.Hit(EventId.OpenPanel, mapConfig.nPanelId, mapNext.mapData, callback)
if mapConfig.bLocalSave then
PopUpManager.SaveLocalData()
end
end
elseif callback ~= nil then
callback()
end
end
function PopUpManager.OpenPopUpPanel(tbType, callback)
local bInPopUp = PopUpManager.CheckInPopUpQueue()
if bInPopUp then
return
end
_tbSpecifyPopUp = tbType
local function popUp()
if #_tbSpecifyPopUp == 0 then
if callback ~= nil then
callback()
end
return
end
local nType = table.remove(_tbSpecifyPopUp, 1)
PopUpManager.OpenPopUpPanelByType(nType, popUp)
end
popUp()
end
function PopUpManager.CheckInPopUpQueue()
return _bInPopUpQueue and not _bInterruptPopUp
end
return PopUpManager