整理一下代码,接入联网
This commit is contained in:
parent
fc39a3487d
commit
8801943ae3
@ -86,14 +86,18 @@ end
|
|||||||
function DataManager:initWithServerData(data)
|
function DataManager:initWithServerData(data)
|
||||||
self:init()
|
self:init()
|
||||||
Time:setServerTimeZone(0)
|
Time:setServerTimeZone(0)
|
||||||
|
Time:updateServerTime(data.now_ts)
|
||||||
|
Time:updateServerTimeToday(data.today_ts)
|
||||||
|
|
||||||
self.initWithServer = true
|
self.initWithServer = true
|
||||||
|
|
||||||
if EDITOR_MODE then
|
if EDITOR_MODE then
|
||||||
Logger.logHighlight("initWithServerData")
|
Logger.logHighlight("initWithServerData")
|
||||||
Logger.printTable(data)
|
Logger.printTable(data)
|
||||||
end
|
end
|
||||||
|
self.todayFirstLogin = data.today_first_login
|
||||||
self.PlayerData:init(data.PlayerData)
|
self.PlayerData:init(data.PlayerData)
|
||||||
self.ChapterData:init(data.ChapterData)
|
self.ChapterData:init(data.chapter)
|
||||||
self.HeroData:init(data.HeroData)
|
self.HeroData:init(data.HeroData)
|
||||||
self.BagData:init(data.BagData)
|
self.BagData:init(data.BagData)
|
||||||
self.FormationData:init(data.FormationData)
|
self.FormationData:init(data.FormationData)
|
||||||
|
|||||||
@ -84,7 +84,6 @@ function Game:initOther()
|
|||||||
BF.exports.BaseModule = require "app/module/base_module"
|
BF.exports.BaseModule = require "app/module/base_module"
|
||||||
BF.exports.ModuleManager = require "app/common/module_manager"
|
BF.exports.ModuleManager = require "app/common/module_manager"
|
||||||
BF.exports.ServerBaseData = require "app/server/data/server_base_data"
|
BF.exports.ServerBaseData = require "app/server/data/server_base_data"
|
||||||
BF.exports.ServerDataManager = require "app/server/server_data_manager"
|
|
||||||
BF.exports.DataManager = require "app/common/data_manager"
|
BF.exports.DataManager = require "app/common/data_manager"
|
||||||
BF.exports.DOTweenManager = require "app/common/dotween_manager"
|
BF.exports.DOTweenManager = require "app/common/dotween_manager"
|
||||||
BF.exports.FSMManager = require "app/common/state_machine_manager"
|
BF.exports.FSMManager = require "app/common/state_machine_manager"
|
||||||
@ -96,7 +95,6 @@ function Game:initOther()
|
|||||||
CameraManager:init()
|
CameraManager:init()
|
||||||
WebRequestManager:init()
|
WebRequestManager:init()
|
||||||
I18N:init()
|
I18N:init()
|
||||||
ServerDataManager:init()
|
|
||||||
DataManager:init()
|
DataManager:init()
|
||||||
DOTweenManager:init()
|
DOTweenManager:init()
|
||||||
ModuleManager:init()
|
ModuleManager:init()
|
||||||
@ -154,7 +152,6 @@ function Game:specialForIdea()
|
|||||||
BaseModule = BaseModule or require "app/module/base_module"
|
BaseModule = BaseModule or require "app/module/base_module"
|
||||||
ModuleManager = ModuleManager or require "app/common/module_manager"
|
ModuleManager = ModuleManager or require "app/common/module_manager"
|
||||||
ServerBaseData = ServerBaseData or require "app/server/data/server_base_data"
|
ServerBaseData = ServerBaseData or require "app/server/data/server_base_data"
|
||||||
ServerDataManager = ServerDataManager or require "app/server/server_data_manager"
|
|
||||||
DataManager = DataManager or require "app/common/data_manager"
|
DataManager = DataManager or require "app/common/data_manager"
|
||||||
DOTweenManager = DOTweenManager or require "app/common/dotween_manager"
|
DOTweenManager = DOTweenManager or require "app/common/dotween_manager"
|
||||||
FSMManager = FSMManager or require "app/common/state_machine_manager"
|
FSMManager = FSMManager or require "app/common/state_machine_manager"
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
local GConst = {}
|
local GConst = {}
|
||||||
|
|
||||||
local CONST_PATHS = {
|
local CONST_PATHS = {
|
||||||
ServerDataConst = "app/server/server_data_const",
|
|
||||||
StageConst = "app/module/stage/stage_const",
|
StageConst = "app/module/stage/stage_const",
|
||||||
ItemConst = "app/module/item/item_const",
|
ItemConst = "app/module/item/item_const",
|
||||||
TaskConst = "app/module/task/task_const",
|
TaskConst = "app/module/task/task_const",
|
||||||
|
|||||||
@ -934,13 +934,6 @@ function GFunc.getTickCount()
|
|||||||
return math.floor(UnityTime.realtimeSinceStartup)
|
return math.floor(UnityTime.realtimeSinceStartup)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GFunc.IsGotServerTime()
|
|
||||||
if not CS.BF.BFMain.IsGotServerTime then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
---得到展示奖励的图集名称,图片资源id
|
---得到展示奖励的图集名称,图片资源id
|
||||||
function GFunc.getFrameRes(type, id)
|
function GFunc.getFrameRes(type, id)
|
||||||
if type == GConst.REWARD_TYPE.REWARD_NONE then
|
if type == GConst.REWARD_TYPE.REWARD_NONE then
|
||||||
|
|||||||
@ -8,11 +8,7 @@ function BattleControllerStage:getChapterId()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function BattleControllerStage:getMaxWave()
|
function BattleControllerStage:getMaxWave()
|
||||||
local chapterInfo = ConfigManager:getConfig("chapter")[self.chapterId]
|
return DataManager.ChapterData:getChapterCfgMaxWave(self.chapterId)
|
||||||
if not chapterInfo then
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
return #chapterInfo.monster
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleControllerStage:getBlockIcon()
|
function BattleControllerStage:getBlockIcon()
|
||||||
|
|||||||
@ -6,19 +6,19 @@ function ChapterManager:openBox(chapterId, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local parmas = {
|
local parmas = {
|
||||||
id = chapterId,
|
chapter_id = chapterId,
|
||||||
index = index,
|
wave = index,
|
||||||
}
|
}
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX, parmas, function(result)
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterBoxRewardReq, parmas, {}, self.openBoxFinish, BIReport.ITEM_GET_TYPE.CHAPTER_BOX)
|
||||||
if result.status == 0 then
|
end
|
||||||
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.CHAPTER_BOX)
|
|
||||||
GFunc.showRewardBox(result.rewards)
|
|
||||||
DataManager.ChapterData:init(result.chapterData, true)
|
|
||||||
DataManager.ChapterData:setDirty()
|
|
||||||
|
|
||||||
BIReport:postChapterOpenBox(chapterId, DataManager.ChapterData:getChapterBoxNum(chapterId, index), result.rewards)
|
function ChapterManager:openBoxFinish(result)
|
||||||
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
|
GFunc.showRewardBox(result.rewards)
|
||||||
|
DataManager.ChapterData:openBox(result.reqData.chapter_id, result.reqData.wave)
|
||||||
|
|
||||||
|
BIReport:postChapterOpenBox(result.reqData.chapter_id, DataManager.ChapterData:getChapterBoxNum(chapterId, index), result.rewards)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterManager:startFight()
|
function ChapterManager:startFight()
|
||||||
@ -38,50 +38,41 @@ function ChapterManager:startFight()
|
|||||||
local parmas = {
|
local parmas = {
|
||||||
id = DataManager.ChapterData:getChapterId()
|
id = DataManager.ChapterData:getChapterId()
|
||||||
}
|
}
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.START_FIGHT, parmas, function(result)
|
-- self:sendMessage(ProtoMsgType.FromMsgEnum., parmas, {}, self.startFightFinish, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_START)
|
||||||
if result.status == 0 then
|
self:startFightFinish({err_code = "SUCCESS"})
|
||||||
if result.cost then
|
end
|
||||||
GFunc.addCosts(result.cost, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_START)
|
|
||||||
end
|
function ChapterManager:startFightFinish(result)
|
||||||
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
|
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterManager:endFight(id, combatReport)
|
function ChapterManager:endFight(id, combatReport)
|
||||||
local cfg = ConfigManager:getConfig("chapter")[id]
|
|
||||||
local rewards = {}
|
|
||||||
for i = 1, combatReport.wave do
|
|
||||||
for _, reward in ipairs(cfg.wave_reward) do
|
|
||||||
table.insert(rewards, reward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if combatReport.victory then
|
|
||||||
for _, reward in ipairs(cfg.finish_reward) do
|
|
||||||
table.insert(rewards, reward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local parmas = {
|
local parmas = {
|
||||||
id = id,
|
chapter_id = id,
|
||||||
|
win = combatReport.victory,
|
||||||
|
pass_wave = combatReport.wave,
|
||||||
combatReport = combatReport,
|
combatReport = combatReport,
|
||||||
rewards = GFunc.mergeRewards(rewards)
|
|
||||||
}
|
}
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT, parmas, function(result)
|
|
||||||
if result.status == 0 then
|
self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterSettlementReq, parmas, {}, self.startFightFinish, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_END)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChapterManager:endFightFinish(result)
|
||||||
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
|
local reqData = result.reqData
|
||||||
local maxChapter = DataManager.ChapterData:getNewChapterId()
|
local maxChapter = DataManager.ChapterData:getNewChapterId()
|
||||||
if combatReport.victory and DataManager.ChapterData:getChapterId() == DataManager.ChapterData:getMaxChapterId() + 1 then
|
if reqData.combatReport.victory and DataManager.ChapterData:getChapterId() == DataManager.ChapterData:getMaxChapterId() + 1 then
|
||||||
DataManager.ChapterData:goNextChapter()
|
DataManager.ChapterData:goNextChapter()
|
||||||
end
|
end
|
||||||
GFunc.addRewards(result.rewards, BIReport.ITEM_GET_TYPE.CHAPTER_FIGHT_END)
|
|
||||||
local newRewards = {}
|
local newRewards = {}
|
||||||
if result.rewards then
|
if result.rewards then
|
||||||
GFunc.mergeRewards2(result.rewards, newRewards)
|
GFunc.mergeRewards2(result.rewards, newRewards)
|
||||||
end
|
end
|
||||||
ModuleManager.BattleManager:showBattleResultUI(newRewards, combatReport)
|
ModuleManager.BattleManager:showBattleResultUI(newRewards, reqData.combatReport)
|
||||||
DataManager.ChapterData:init(result.chapterData, true)
|
-- DataManager.ChapterData:init(result.chapterData, true)
|
||||||
DataManager.ChapterData:setDirty()
|
-- DataManager.ChapterData:setDirty()
|
||||||
-- 处理金猪
|
-- 处理金猪
|
||||||
DataManager.GodPigData:addGoldPigCount()
|
DataManager.GodPigData:addGoldPigCount()
|
||||||
|
|
||||||
@ -92,7 +83,6 @@ function ChapterManager:endFight(id, combatReport)
|
|||||||
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
|
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return ChapterManager
|
return ChapterManager
|
||||||
@ -10,12 +10,14 @@ function FormationManager:upHeroToStageFormation(heroId, matchType)
|
|||||||
matchType = matchType,
|
matchType = matchType,
|
||||||
heroId = heroId
|
heroId = heroId
|
||||||
}
|
}
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION, args, function(msgData)
|
-- self:sendMessage(ProtoMsgType.FromMsgEnum., args, {}, self.upHeroToStageFormationFinish)
|
||||||
if msgData.status == 0 then
|
end
|
||||||
|
|
||||||
|
function FormationManager:upHeroToStageFormationFinish(result)
|
||||||
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
DataManager.FormationData:upHeroToFormation(GConst.BattleConst.BATTLE_TYPE.STAGE, matchType, heroId)
|
DataManager.FormationData:upHeroToFormation(GConst.BattleConst.BATTLE_TYPE.STAGE, matchType, heroId)
|
||||||
DataManager.HeroData:setDirty()
|
DataManager.HeroData:setDirty()
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function FormationManager:formationIsFull()
|
function FormationManager:formationIsFull()
|
||||||
|
|||||||
@ -14,13 +14,14 @@ function HeroManager:upgradeHero(heroId, heroEntity)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO, {heroId = heroId}, function(result)
|
-- self:sendMessage(ProtoMsgType.FromMsgEnum., args, {}, self.upgradeHeroFinish, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
|
||||||
if result.status == 0 then
|
end
|
||||||
GFunc.addCosts(result.costs, BIReport.ITEM_GET_TYPE.UPGRADE_HERO)
|
|
||||||
|
function HeroManager:upgradeHeroFinish(result)
|
||||||
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
DataManager.HeroData:setHeroLv(result.heroId, result.lv)
|
DataManager.HeroData:setHeroLv(result.heroId, result.lv)
|
||||||
DataManager.HeroData:setDirty()
|
DataManager.HeroData:setDirty()
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,24 +20,7 @@ end
|
|||||||
function LoginManager:loginGame()
|
function LoginManager:loginGame()
|
||||||
-- adjust 打开应用事件识别码
|
-- adjust 打开应用事件识别码
|
||||||
BIReport:postAdjustSimpleTrackEvent("xbszrl", {})
|
BIReport:postAdjustSimpleTrackEvent("xbszrl", {})
|
||||||
|
|
||||||
local serverTime = Time:getServerTime() * 1000
|
|
||||||
local todayBeginTime = serverTime - serverTime%86400
|
|
||||||
Time:updateByServer(serverTime, todayBeginTime)
|
|
||||||
|
|
||||||
CS.BF.BFMain.IsGotServerTime = true
|
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA, GConst.EMPTY_TABLE, function(msgData)
|
|
||||||
DataManager:initWithServerData(msgData)
|
|
||||||
ConfigManager:preLoadConfig()
|
|
||||||
ModuleManager.MaincityManager:firstEnterMainCity()
|
ModuleManager.MaincityManager:firstEnterMainCity()
|
||||||
local data = {}
|
|
||||||
data.max_chapter = DataManager.ChapterData:getNewChapterId()
|
|
||||||
-- data.ads_num = DataManager.PlayerData:getAdCount()
|
|
||||||
-- data.pay_money = DataManager.PlayerData:getPaymentCount()
|
|
||||||
data.play_days = DataManager.PlayerData:getLoginDay()
|
|
||||||
data.now_version = Platform:getClientVersion()
|
|
||||||
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function LoginManager:goToLoginScene()
|
function LoginManager:goToLoginScene()
|
||||||
@ -157,6 +140,14 @@ function LoginManager:loginFinish(data)
|
|||||||
ServerPushManager:initWhenLogin()
|
ServerPushManager:initWhenLogin()
|
||||||
DataManager:initWithServerData(data)
|
DataManager:initWithServerData(data)
|
||||||
|
|
||||||
|
local data = {}
|
||||||
|
data.max_chapter = DataManager.ChapterData:getNewChapterId()
|
||||||
|
-- data.ads_num = DataManager.PlayerData:getAdCount()
|
||||||
|
-- data.pay_money = DataManager.PlayerData:getPaymentCount()
|
||||||
|
data.play_days = DataManager.PlayerData:getLoginDay()
|
||||||
|
data.now_version = Platform:getClientVersion()
|
||||||
|
CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserSet(data)
|
||||||
|
|
||||||
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.LOGIN_REQ_SUCCESS)
|
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.LOGIN_REQ_SUCCESS)
|
||||||
-- ModuleManager.MailManager:getMailList(true)
|
-- ModuleManager.MailManager:getMailList(true)
|
||||||
DataManager:setLoginSuccess(true)
|
DataManager:setLoginSuccess(true)
|
||||||
|
|||||||
@ -23,14 +23,12 @@ function TutorialManager:sendTutorialId(id, callback)
|
|||||||
|
|
||||||
self.sendTutorialIdCallback = callback
|
self.sendTutorialIdCallback = callback
|
||||||
|
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.MARK_GUIDE, args, function(result)
|
-- self:sendMessage(ProtoMsgType.FromMsgEnum., args, {}, self.sendTutorialIdFinish)
|
||||||
self:sendTutorialIdFinish(result)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function TutorialManager:sendTutorialIdFinish(result)
|
function TutorialManager:sendTutorialIdFinish(result)
|
||||||
Logger.printTable(result)
|
Logger.printTable(result)
|
||||||
if result.status == 0 then
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
||||||
if result.id then
|
if result.id then
|
||||||
-- BIReport:postTutorialStep(result.id)
|
-- BIReport:postTutorialStep(result.id)
|
||||||
-- DataManager.TutorialData:markFuncTutorialFinish(result.id)
|
-- DataManager.TutorialData:markFuncTutorialFinish(result.id)
|
||||||
|
|||||||
@ -958,40 +958,40 @@ function NetManager:getNotCheckResponse(msgName)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if msgName == ProtoMsgType.FromMsgEnum.LoginReq or
|
-- if msgName == ProtoMsgType.FromMsgEnum.LoginReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.SyncReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.SyncReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.ArenaInfoReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.ArenaInfoReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.SummonReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.SummonReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MineResearchADReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MineResearchADReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MineResearchResultReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MineResearchResultReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.IdleRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.IdleRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.IdleExtraRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.IdleExtraRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.GMReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.GMReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MallPayReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MallPayReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.ChapterPassReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.ChapterPassReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MallPaidResultReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MallPaidResultReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MineDoReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MineDoReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.TaskTutorRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.TaskTutorRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.BlessingReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.BlessingReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MarkGuideReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MarkGuideReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.EnterDungeonReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.EnterDungeonReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.FinishedArenaReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.FinishedArenaReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.SettleArenaReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.SettleArenaReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.SevenDayRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.SevenDayRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MonCardRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MonCardRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.ChapterStageRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.ChapterStageRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.BattlePassRewardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.BattlePassRewardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.ChapterRebornReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.ChapterRebornReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MineReceiveAwardReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MineReceiveAwardReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MailExtractReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MailExtractReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MailListReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MailListReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.MailDeleteReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.MailDeleteReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.ExistReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.ExistReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.BindReq or
|
-- msgName == ProtoMsgType.FromMsgEnum.BindReq or
|
||||||
msgName == ProtoMsgType.FromMsgEnum.DeleteReq
|
-- msgName == ProtoMsgType.FromMsgEnum.DeleteReq
|
||||||
then
|
-- then
|
||||||
return true
|
-- return true
|
||||||
end
|
-- end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f37c247985544954bbcd2f09de7728d8
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
local ServerBagData = class("ServerBagData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerBagData:ctor()
|
|
||||||
self.ItemData = require("app/server/data/server_item_data"):create()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBagData:init()
|
|
||||||
self.ItemData:init()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBagData:loadLocalData()
|
|
||||||
self.ItemData:loadLocalData()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBagData:getCloneData()
|
|
||||||
local data = {
|
|
||||||
ItemData = self.ItemData:getCloneData()
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBagData:saveLocalData()
|
|
||||||
self.ItemData:saveLocalData()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBagData:clear()
|
|
||||||
self.ItemData:clear()
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerBagData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: d136d1a130b633146aadeca89f6c41a6
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
local ServerBaseData = class("ServerBaseData")
|
|
||||||
|
|
||||||
function ServerBaseData:ctor(...)
|
|
||||||
self.data = {}
|
|
||||||
-- self.data.__parent = self
|
|
||||||
|
|
||||||
-- local innerData = nil
|
|
||||||
-- innerData = {
|
|
||||||
-- __index = function (t, key)
|
|
||||||
-- return innerData[key]
|
|
||||||
-- end,
|
|
||||||
-- __newindex = function (t, key, value)
|
|
||||||
-- innerData[key] = value
|
|
||||||
-- end
|
|
||||||
-- }
|
|
||||||
-- setmetatable(self.data, innerData)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:init()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:clear()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:loadLocalData()
|
|
||||||
local data = LocalData:getString(self:_getLocalSaveKey(), "")
|
|
||||||
local dataObj = nil
|
|
||||||
if data and data ~= "" then
|
|
||||||
dataObj = json.decode(data)
|
|
||||||
end
|
|
||||||
self:init(dataObj)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:saveLocalData()
|
|
||||||
local str = json.encode(self.data) or ""
|
|
||||||
LocalData:setString(self:_getLocalSaveKey(), str)
|
|
||||||
if EDITOR_MODE then
|
|
||||||
Logger.logHighlight("save data:%s=%s", self:_getLocalSaveKey(), str)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:_getLocalSaveKey()
|
|
||||||
if self._localSaveKey == nil then
|
|
||||||
self._localSaveKey = "ServerData_" .. self.__cname
|
|
||||||
end
|
|
||||||
return self._localSaveKey
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:getCloneData()
|
|
||||||
local cloneData = {}
|
|
||||||
local function _copy(object)
|
|
||||||
if type(object) ~= "table" then
|
|
||||||
return object
|
|
||||||
elseif cloneData[object] then
|
|
||||||
return cloneData[object]
|
|
||||||
end
|
|
||||||
local newObject = {}
|
|
||||||
cloneData[object] = newObject
|
|
||||||
for key, value in pairs(object) do
|
|
||||||
newObject[_copy(key)] = _copy(value)
|
|
||||||
end
|
|
||||||
return newObject
|
|
||||||
end
|
|
||||||
return _copy(self.data)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerBaseData:_clear()
|
|
||||||
self._localSaveKey = nil
|
|
||||||
self:clear()
|
|
||||||
end
|
|
||||||
|
|
||||||
if NOT_PUBLISH then
|
|
||||||
ServerBaseData._editorGetLocalSaveKey = ServerBaseData._getLocalSaveKey
|
|
||||||
function ServerBaseData:_getLocalSaveKey()
|
|
||||||
if self._localSaveKey == nil then
|
|
||||||
self._localSaveKey = LocalData:getDistinctId() .. "ServerData_" .. self.__cname
|
|
||||||
end
|
|
||||||
return self._localSaveKey
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerBaseData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8b88996eb5328d742b2a198434cabef1
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
local ServerChapterData = class("ServerChapterData", ServerBaseData)
|
|
||||||
|
|
||||||
local MIN_CHAPTER_ID = 1
|
|
||||||
|
|
||||||
function ServerChapterData:init(data)
|
|
||||||
self.data.maxChapterId = data and data.maxChapterId or (MIN_CHAPTER_ID - 1)
|
|
||||||
self.data.chapterBoxInfo = data and data.chapterBoxInfo or {}
|
|
||||||
self.data.chapterFightInfo = data and data.chapterFightInfo or {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:enterFight(id)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if not self.data.chapterFightInfo[idStr] then
|
|
||||||
self.data.chapterFightInfo[idStr] = {
|
|
||||||
victory = false,
|
|
||||||
maxWave = 0,
|
|
||||||
fightCount = 0
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
self.data.chapterFightInfo[idStr].fightCount = (self.data.chapterFightInfo[idStr].fightCount or 0) + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:fightChapter(id, victory, wave)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if not self.data.chapterFightInfo[idStr] then
|
|
||||||
self.data.chapterFightInfo[idStr] = {
|
|
||||||
victory = false,
|
|
||||||
maxWave = 0,
|
|
||||||
fightCount = 0
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local passBefore = self.data.chapterFightInfo[idStr].victory
|
|
||||||
if victory then
|
|
||||||
self.data.chapterFightInfo[idStr].victory = victory
|
|
||||||
end
|
|
||||||
|
|
||||||
if wave > self.data.chapterFightInfo[idStr].maxWave then
|
|
||||||
self.data.chapterFightInfo[idStr].maxWave = wave
|
|
||||||
end
|
|
||||||
|
|
||||||
if not passBefore and victory then
|
|
||||||
if id > self.data.maxChapterId then
|
|
||||||
self.data.maxChapterId = id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:getChapterBoxRewardGot(chapterId, index)
|
|
||||||
local idStr = tostring(chapterId)
|
|
||||||
local list = self.data.chapterBoxInfo[idStr]
|
|
||||||
if not list then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, idx in ipairs(list) do
|
|
||||||
if idx == index then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:getChapterBoxRewards(chapterId, index)
|
|
||||||
local cfg = ConfigManager:getConfig("chapter")[chapterId]
|
|
||||||
if not cfg then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
return cfg["box_reward_" .. index]
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:openChapterBox(chapterId, index)
|
|
||||||
local idStr = tostring(chapterId)
|
|
||||||
local list = self.data.chapterBoxInfo[idStr]
|
|
||||||
if not list then
|
|
||||||
self.data.chapterBoxInfo[idStr] = {}
|
|
||||||
else
|
|
||||||
for _, idx in ipairs(list) do
|
|
||||||
if idx == index then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(self.data.chapterBoxInfo[idStr], index)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterData:getMaxChapterId()
|
|
||||||
return self.data.maxChapterId
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerChapterData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 58e11526da53ab84da05ed5fd3a6cf31
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
local ServerFormationData = class("ServerFormationData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerFormationData:init(data)
|
|
||||||
if data then
|
|
||||||
self.data.formations = data.formations or {}
|
|
||||||
else
|
|
||||||
self.data.formations = {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerFormationData:getFormation(formationType)
|
|
||||||
local formation = self.data.formations[formationType]
|
|
||||||
if formation == nil then
|
|
||||||
formation = {}
|
|
||||||
self.data.formations[formationType] = formation
|
|
||||||
end
|
|
||||||
return formation
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerFormationData:upHeroToFormation(formationType, matchType, heroId)
|
|
||||||
local formation = self:getFormation(formationType)
|
|
||||||
if formation[matchType] == heroId then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
formation[matchType] = heroId
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerFormationData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 89bb0382eca3c184e814ee1bc10355c8
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
local ServerHeroData = class("ServerHeroData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerHeroData:init(data)
|
|
||||||
self.data.heroes = data and data.heroes or {}
|
|
||||||
self.data.unlockHeroes = data and data.unlockHeroes or {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:getHeroByCfgId(id)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
return self.data.heroes[idStr]
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:getIsUnlockHero(id)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if self.data.heroes[idStr] then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return self.data.unlockHeroes[idStr]
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:addHero(id, lv)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if self.data.heroes[idStr] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.data.heroes[idStr] = {
|
|
||||||
cfg_id = id,
|
|
||||||
lv = lv,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:unlockHero(id)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if self.data.unlockHeroes[idStr] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.data.unlockHeroes[idStr] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:tryUnlockHeroByChapterId(maxChapterId)
|
|
||||||
if self.maxChapterId and self.maxChapterId >= maxChapterId then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.maxChapterId = maxChapterId
|
|
||||||
if self.unlockHeroList == nil then
|
|
||||||
self.unlockHeroList = {}
|
|
||||||
local config = ConfigManager:getConfig("hero")
|
|
||||||
for k, v in pairs(config) do
|
|
||||||
if not self:getIsUnlockHero(k) then
|
|
||||||
if v.unlock_chapter then
|
|
||||||
table.insert(self.unlockHeroList, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.sort(self.unlockHeroList, function(a, b)
|
|
||||||
return config[a].unlock_chapter > config[b].unlock_chapter
|
|
||||||
end)
|
|
||||||
self.unlockChapterList = {}
|
|
||||||
for k, v in ipairs(self.unlockHeroList) do
|
|
||||||
self.unlockChapterList[k] = config[v].unlock_chapter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i = #self.unlockChapterList, 1, -1 do
|
|
||||||
if self.unlockChapterList[i] <= maxChapterId then
|
|
||||||
self:unlockHero(self.unlockHeroList[i])
|
|
||||||
table.remove(self.unlockChapterList, i)
|
|
||||||
table.remove(self.unlockHeroList, i)
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerHeroData:upgradeHero(heroId, lv)
|
|
||||||
local idStr = tostring(heroId)
|
|
||||||
if not self.data.heroes[idStr] then
|
|
||||||
self:addHero(heroId, 0)
|
|
||||||
end
|
|
||||||
self.data.heroes[idStr].lv = lv
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerHeroData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 56a4a8f5d6118d74b9bb6971db3d030a
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,213 +0,0 @@
|
|||||||
local ServerItemData = class("ServerItemData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerItemData:init(data)
|
|
||||||
self.data.items = {}
|
|
||||||
if data then
|
|
||||||
for idStr, item in pairs(data.items) do
|
|
||||||
local id = tonumber(idStr)
|
|
||||||
if id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
ServerGameData.PlayerData:setVit(item.count)
|
|
||||||
end
|
|
||||||
self.data.items[idStr] = {cfg_id = id, count = item.count}
|
|
||||||
end
|
|
||||||
self.data.recoveries = data.recoveries or {}
|
|
||||||
else
|
|
||||||
self.data.recoveries = {}
|
|
||||||
end
|
|
||||||
self:checkRecoveries()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:tryAddItem(id, num)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if not self.data.items[idStr] then
|
|
||||||
if num < 0 then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if self.data.items[idStr].count + num < 0 then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:getAllItems()
|
|
||||||
return self.data.items
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:getItemNumById(id)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
if not self.data.items[idStr] then
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
local num = self.data.items[idStr].count or 0
|
|
||||||
return num
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:checkRecoveries()
|
|
||||||
local recoveryCfg = self:getRecoveryCfg()
|
|
||||||
for k, v in pairs(recoveryCfg) do
|
|
||||||
local inList = false
|
|
||||||
for ii, vv in ipairs(self.data.recoveries) do
|
|
||||||
if vv.cfg_id == k then
|
|
||||||
inList = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not inList then
|
|
||||||
table.insert(self.data.recoveries, {cfg_id = k, ts = Time:getServerTime()})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:recoveryItems(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:recoveryItems(isInit)
|
|
||||||
if not self.data.recoveries then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for i,v in ipairs(self.data.recoveries) do
|
|
||||||
if v.cfg_id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
local maxCount = self:getMaxVit()
|
|
||||||
self:recoveryItem(v, maxCount, isInit)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function ServerItemData:recoveryItem(data, maxCount, isInit)
|
|
||||||
if not CS.BF.BFMain.IsGotServerTime then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if data.cfg_id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
local currentCount = ServerGameData.PlayerData:getVit()
|
|
||||||
if currentCount >= maxCount then -- 已经达到上限
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local cfg = self:getRecoveryCfg()[data.cfg_id]
|
|
||||||
local nowTime = Time:getServerTime()
|
|
||||||
local diffTime = nowTime - data.ts
|
|
||||||
if diffTime <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local addCount = math.floor(diffTime / cfg.time)
|
|
||||||
if addCount <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local currentCount = self:getItemNumById(data.cfg_id)
|
|
||||||
if currentCount >= maxCount then -- 已经达到上限
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local cfg = self:getRecoveryCfg()[data.cfg_id]
|
|
||||||
local nowTime = Time:getServerTime()
|
|
||||||
local diffTime = nowTime - data.ts
|
|
||||||
if diffTime <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local addCount = math.floor(diffTime / cfg.time)
|
|
||||||
if addCount <= 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
data.ts = data.ts + cfg.time*addCount
|
|
||||||
if currentCount + addCount > maxCount then
|
|
||||||
addCount = maxCount - currentCount
|
|
||||||
end
|
|
||||||
self:_addItem(data.cfg_id, addCount)
|
|
||||||
|
|
||||||
if data.cfg_id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
BIReport:postVitGet(addCount, BIReport.ITEM_GET_TYPE.RECOVERY_TIME, self:getItemNumById(data.cfg_id))
|
|
||||||
end
|
|
||||||
ServerDataManager:saveData()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:resetVitRecoverTime()
|
|
||||||
local maxCount = self:getMaxVit()
|
|
||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
local currentCount = ServerGameData.PlayerData:getVit()
|
|
||||||
if currentCount >= maxCount then -- 已经达到上限
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local currentCount = self:getItemNumById(GConst.ItemConst.ITEM_ID_VIT)
|
|
||||||
if currentCount >= maxCount then -- 已经达到上限
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for i,v in ipairs(self.data.recoveries) do
|
|
||||||
if v.cfg_id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
self.data.recoveries[i].ts = Time:getServerTime()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:getRecoveryCfg()
|
|
||||||
if self.recoveryCfg == nil then
|
|
||||||
self.recoveryCfg = ConfigManager:getConfig("recovery")
|
|
||||||
end
|
|
||||||
return self.recoveryCfg
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:getMaxVit()
|
|
||||||
if self.maxVit == nil then
|
|
||||||
local cfg = self:getRecoveryCfg()[GConst.ItemConst.ITEM_ID_VIT]
|
|
||||||
self.maxVit = cfg.limit
|
|
||||||
end
|
|
||||||
return self.maxVit
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:addItemReward(item, getType)
|
|
||||||
local id = GFunc.getRewardId(item)
|
|
||||||
local num = GFunc.getRewardNum(item)
|
|
||||||
self:addItem(id, num, getType)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:addItemCost(cost)
|
|
||||||
local id = GFunc.getRewardId(cost)
|
|
||||||
local num = GFunc.getRewardNum(cost)
|
|
||||||
self:addItem(id, -num)
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:addItem(id, num, getType)
|
|
||||||
if id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
local maxCount = self:getMaxVit()
|
|
||||||
local currentCount = self:getItemNumById(GConst.ItemConst.ITEM_ID_VIT)
|
|
||||||
local isMax = currentCount >= maxCount
|
|
||||||
self:_addItem(id, num, getType)
|
|
||||||
local currentCount = currentCount + num
|
|
||||||
local isMax1 = currentCount >= maxCount
|
|
||||||
if not isMax1 then
|
|
||||||
if isMax then
|
|
||||||
self:resetVitRecoverTime()
|
|
||||||
else
|
|
||||||
self:recoveryItems()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self:_addItem(id, num, getType)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerItemData:_addItem(id, num, getType)
|
|
||||||
local idStr = tostring(id)
|
|
||||||
local hadNum = 0
|
|
||||||
if self.data.items[idStr] then
|
|
||||||
hadNum = self.data.items[idStr].count
|
|
||||||
else
|
|
||||||
self.data.items[idStr] = {}
|
|
||||||
self.data.items[idStr].cfg_id = id
|
|
||||||
self.data.items[idStr].count = 0
|
|
||||||
end
|
|
||||||
local finalNum = (hadNum or 0) + num
|
|
||||||
if finalNum < 0 then
|
|
||||||
finalNum = 0
|
|
||||||
end
|
|
||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
if id == GConst.ItemConst.ITEM_ID_VIT then
|
|
||||||
ServerGameData.PlayerData:setVit(finalNum)
|
|
||||||
end
|
|
||||||
self.data.items[idStr].count = finalNum
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerItemData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 21a3f0972e236154197f14df6f246f40
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
local ServerPlayerData = class("ServerPlayerData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerPlayerData:init(data)
|
|
||||||
self.data.loginDay = data and data.loginDay or 0
|
|
||||||
self.data.lastLoginTime = data and data.lastLoginTime or 0
|
|
||||||
if self.data.lastLoginTime < Time:getBeginningOfServerToday() then
|
|
||||||
self.data.lastLoginTime = Time:getBeginningOfServerToday()
|
|
||||||
self.data.loginDay = self.data.loginDay + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerPlayerData:setVit(vit)
|
|
||||||
self.vit = tonumber(vit) or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerPlayerData:getVit()
|
|
||||||
return self.vit or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerPlayerData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: e1a04f57465c5be4882f1efdec828dc2
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
local ServerTutorialData = class("ServerTutorialData", ServerBaseData)
|
|
||||||
|
|
||||||
function ServerTutorialData:init(data)
|
|
||||||
if data then
|
|
||||||
self.data.markedGuide = data.markedGuide or {}
|
|
||||||
else
|
|
||||||
self.data.markedGuide = {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerTutorialData:markGuide(id)
|
|
||||||
id = tostring(id)
|
|
||||||
if not id then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.data.markedGuide[id] = true
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerTutorialData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8482be101c0b05347b61cef1d8925dac
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 09d17db485e3192459d5fcd0a0cefb49
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -1,98 +0,0 @@
|
|||||||
local ServerChapterManager = {}
|
|
||||||
|
|
||||||
function ServerChapterManager:openBox(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
if params == nil or not params.id or not params.index then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ServerGameData = ServerDataManager:getServerGameData()
|
|
||||||
|
|
||||||
if not ServerGameData.ChapterData:openChapterBox(params.id, params.index) then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local rewards = ServerGameData.ChapterData:getChapterBoxRewards(params.id, params.index)
|
|
||||||
result.rewards = ServerGameData:addRewards(rewards)
|
|
||||||
result.chapterData = ServerGameData.ChapterData:getCloneData()
|
|
||||||
result.status = 0
|
|
||||||
|
|
||||||
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterManager:startFight(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
local cost = GFunc.getConstReward("chapter_cost")
|
|
||||||
if cost == nil then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local vitCostNum = GFunc.getRewardNum(cost)
|
|
||||||
local ServerGameData = ServerDataManager:getServerGameData()
|
|
||||||
if vitCostNum > ServerGameData.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_VIT) then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
ServerGameData.ChapterData:enterFight(params.id)
|
|
||||||
result.cost = ServerGameData:addCosts({cost})
|
|
||||||
result.status = 0
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerChapterManager:endFight(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
if params == nil or not params.id or not params.combatReport then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local cfg = ConfigManager:getConfig("chapter")[params.id]
|
|
||||||
local rewards = {}
|
|
||||||
for i = 1, params.combatReport.wave do
|
|
||||||
for _, reward in ipairs(cfg.wave_reward) do
|
|
||||||
table.insert(rewards, reward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if params.combatReport.victory then
|
|
||||||
for _, reward in ipairs(cfg.finish_reward) do
|
|
||||||
table.insert(rewards, reward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rewards = GFunc.mergeRewards(rewards)
|
|
||||||
local ServerGameData = ServerDataManager:getServerGameData()
|
|
||||||
ServerGameData.ChapterData:fightChapter(params.id, params.combatReport.victory, params.combatReport.wave)
|
|
||||||
ServerGameData.HeroData:tryUnlockHeroByChapterId(ServerGameData.ChapterData:getMaxChapterId())
|
|
||||||
result.rewards = ServerGameData:addRewards(rewards)
|
|
||||||
result.chapterData = ServerGameData.ChapterData:getCloneData()
|
|
||||||
result.status = 0
|
|
||||||
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerChapterManager
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 5a93eee72dda74b4695a1e0de728ac96
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
local ServerFormationManager = {}
|
|
||||||
|
|
||||||
function ServerFormationManager:updateFormation(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
if params == nil then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local formationType = params.formationType
|
|
||||||
local matchType = tostring(params.matchType)
|
|
||||||
local heroId = params.heroId
|
|
||||||
if formationType and matchType and heroId then
|
|
||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
if ServerGameData.FormationData:upHeroToFormation(formationType, matchType, heroId) then
|
|
||||||
result.status = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerFormationManager
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3f6f74ff6268bec4593ef0e060480d93
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
local ServerHeroManager = {}
|
|
||||||
|
|
||||||
function ServerHeroManager:onUpgradeHero(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
if params == nil then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local heroId = params.heroId
|
|
||||||
local heroCfg = ConfigManager:getConfig("hero")[heroId]
|
|
||||||
if heroId and heroCfg then
|
|
||||||
local ServerGameData = ServerDataManager:getServerGameData()
|
|
||||||
local ItemData = ServerGameData.BagData.ItemData
|
|
||||||
local heroInfo = ServerGameData.HeroData:getHeroByCfgId(heroId) or {cfg_id = heroId, lv = 0}
|
|
||||||
local lv = heroInfo.lv + 1
|
|
||||||
if lv < heroCfg.begin_lv then
|
|
||||||
lv = heroCfg.begin_lv
|
|
||||||
end
|
|
||||||
local nextLvInfo = ConfigManager:getConfig("hero_level")[lv]
|
|
||||||
if not nextLvInfo then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local fieldName = "cost_" .. heroCfg.qlt
|
|
||||||
nextLvInfo = nextLvInfo[fieldName]
|
|
||||||
|
|
||||||
local fragmentCost = nextLvInfo[1] or 0
|
|
||||||
if not ItemData:tryAddItem(heroCfg.item_id, -fragmentCost) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local goldCost = nextLvInfo[2] or 0
|
|
||||||
if not ItemData:tryAddItem(GConst.ItemConst.ITEM_ID_GOLD, -goldCost) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local costs = {
|
|
||||||
{
|
|
||||||
type = GConst.REWARD_TYPE.ITEM,
|
|
||||||
id = heroCfg.item_id,
|
|
||||||
num = fragmentCost
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = GConst.REWARD_TYPE.ITEM,
|
|
||||||
id = GConst.ItemConst.ITEM_ID_GOLD,
|
|
||||||
num = goldCost
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerGameData.HeroData:upgradeHero(heroId, lv)
|
|
||||||
result.heroId = heroId
|
|
||||||
result.lv = lv
|
|
||||||
result.costs = ServerGameData:addCosts(costs)
|
|
||||||
|
|
||||||
result.status = 0
|
|
||||||
end
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerHeroManager
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b697148ece07e2f4c873aa1bd9589e59
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
local ServerChapterManager = {}
|
|
||||||
|
|
||||||
function ServerChapterManager:markGuide(params, callback)
|
|
||||||
local result = {
|
|
||||||
status = 1
|
|
||||||
}
|
|
||||||
if params == nil or not params.id then
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ServerGameData = ServerDataManager:getServerGameData()
|
|
||||||
ServerGameData.TutorialData:markGuide(params.id)
|
|
||||||
result.id = params.id
|
|
||||||
result.status = 0
|
|
||||||
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerChapterManager
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 635bfc3932a24014192fd87a7c164c14
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
local ServerDataConst = {}
|
|
||||||
|
|
||||||
ServerDataConst.REWARD_TYPE = {
|
|
||||||
REWARD_NONE = 0,
|
|
||||||
ITEM = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerDataConst.DATA_OP_BEHAVIOR = {
|
|
||||||
SYNC_DATA = "SYNC_DATA",
|
|
||||||
CROSS_DAY = "CROSS_DAY",
|
|
||||||
UPDATE_FORMATION = "UPDATE_FORMATION",
|
|
||||||
UPGRADE_HERO = "UPGRADE_HERO",
|
|
||||||
START_FIGHT = "START_FIGHT",
|
|
||||||
END_FIGHT = "END_FIGHT",
|
|
||||||
OPEN_CHAPTER_BOX = "OPEN_CHAPTER_BOX",
|
|
||||||
MARK_GUIDE = "MARK_GUIDE",
|
|
||||||
}
|
|
||||||
|
|
||||||
return ServerDataConst
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 8af3001c06ad5ab44ba95cb6a2486229
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,181 +0,0 @@
|
|||||||
local ServerGameData = require "app/server/server_game_data"
|
|
||||||
|
|
||||||
local ServerDataManager = {}
|
|
||||||
|
|
||||||
function ServerDataManager:init()
|
|
||||||
self.ServerFormationManager = require("app/server/manager/server_formation_manager")
|
|
||||||
self.ServerHeroManager = require("app/server/manager/server_hero_manager")
|
|
||||||
self.ServerChapterManager = require("app/server/manager/server_chapter_manager")
|
|
||||||
self.ServerTutorialManager = require("app/server/manager/server_tutorial_manager")
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerDataManager:saveData()
|
|
||||||
ServerGameData:saveData()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerDataManager:randomReward(rewardsArr, count, callback)
|
|
||||||
local maxWeight = 0
|
|
||||||
local reward
|
|
||||||
for i = 1, count do
|
|
||||||
reward = rewardsArr[i]
|
|
||||||
maxWeight = maxWeight + reward.weight
|
|
||||||
end
|
|
||||||
local randomWeight
|
|
||||||
if callback then
|
|
||||||
randomWeight = callback(1, maxWeight)
|
|
||||||
else
|
|
||||||
randomWeight = math.random(1, maxWeight)
|
|
||||||
end
|
|
||||||
local idx
|
|
||||||
for i = 1, count do
|
|
||||||
if randomWeight <= rewardsArr[i].weight then
|
|
||||||
idx = i
|
|
||||||
break
|
|
||||||
else
|
|
||||||
randomWeight = randomWeight - rewardsArr[i].weight
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return idx
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerDataManager:dataOperate(behavior, params, callback)
|
|
||||||
local opFunc = ServerDataManager.OP_FUNC[behavior]
|
|
||||||
if opFunc then
|
|
||||||
opFunc(params, function(result)
|
|
||||||
if callback then
|
|
||||||
callback(result)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
-- TODO临时处理
|
|
||||||
ServerGameData:saveData()
|
|
||||||
else
|
|
||||||
Logger.logError("Undefined data operation function, please check :%s", behavior)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerDataManager:onSyncData(params, callback)
|
|
||||||
-- 初始化本地数据
|
|
||||||
ServerGameData:initData()
|
|
||||||
local data = ServerGameData:getData()
|
|
||||||
if callback then
|
|
||||||
callback(data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ServerDataManager.OP_FUNC = {
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPGRADE_HERO] = function (...) ServerDataManager.ServerHeroManager:onUpgradeHero(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.START_FIGHT] = function(...) ServerDataManager.ServerChapterManager:startFight(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.END_FIGHT] = function(...) ServerDataManager.ServerChapterManager:endFight(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.OPEN_CHAPTER_BOX] = function(...) ServerDataManager.ServerChapterManager:openBox(...) end,
|
|
||||||
[GConst.ServerDataConst.DATA_OP_BEHAVIOR.MARK_GUIDE] = function(...) ServerDataManager.ServerTutorialManager:markGuide(...) end,
|
|
||||||
}
|
|
||||||
|
|
||||||
function ServerDataManager:dealGM(params, callback)
|
|
||||||
if IS_PUBLISH then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if not params or not params.args then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local args = params.args
|
|
||||||
if args[1] == "add_item" then
|
|
||||||
local id = tonumber(args[2])
|
|
||||||
local count = tonumber(args[3])
|
|
||||||
if not id or not count then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
ServerGameData.BagData.ItemData:addItem(id, count)
|
|
||||||
ServerGameData.BagData.ItemData:saveLocalData()
|
|
||||||
if id == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
ServerGameData.PlayerData:addExp(count)
|
|
||||||
end
|
|
||||||
elseif args[1] == "add_items" then
|
|
||||||
local cfg = ConfigManager:getConfig("item")
|
|
||||||
local count = tonumber(args[2])
|
|
||||||
if not count then
|
|
||||||
for k, v in pairs(cfg) do
|
|
||||||
if k == GConst.ItemConst.ITEM_ID_GOLD then
|
|
||||||
ServerGameData.BagData.ItemData:addItem(k, 99999999)
|
|
||||||
else
|
|
||||||
ServerGameData.BagData.ItemData:addItem(k, 2000)
|
|
||||||
end
|
|
||||||
if k == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
ServerGameData.PlayerData:addExp(1000)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for k, v in pairs(cfg) do
|
|
||||||
ServerGameData.BagData:addItem(k, count)
|
|
||||||
if k == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
ServerGameData.PlayerData:addExp(count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif args[1] == "del_item" then
|
|
||||||
local id = tonumber(args[2])
|
|
||||||
local count = tonumber(args[3])
|
|
||||||
if not id or not count then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
ServerGameData.BagData.ItemData:addItem(id, -count)
|
|
||||||
if id == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
ServerGameData.PlayerData:addExp(-count)
|
|
||||||
end
|
|
||||||
elseif args[1] == "clear_item" then
|
|
||||||
local items = ServerGameData.BagData.ItemData:getAllItems()
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
v.count = 0
|
|
||||||
end
|
|
||||||
elseif args[1] == "add_hero" then
|
|
||||||
local id = tonumber(args[2])
|
|
||||||
if not id then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local hero = ServerGameData.HeroData:getHeroByCfgId(id)
|
|
||||||
if hero == nil or hero.lv <= 0 then
|
|
||||||
local heroCfg = ConfigManager:getConfig("hero")
|
|
||||||
local heroLvCfg = ConfigManager:getConfig("hero_level")
|
|
||||||
local heroInfo = heroCfg[id]
|
|
||||||
if heroInfo then
|
|
||||||
local costKey = "cost_" .. heroInfo.qlt
|
|
||||||
for k, v in ipairs(heroLvCfg) do
|
|
||||||
if v[costKey] then -- 第一个有值的就是解锁所需的数量
|
|
||||||
ServerGameData.HeroData:addHero(id, k)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif args[1] == "pass_chapter" then
|
|
||||||
local maxId = tonumber(args[2])
|
|
||||||
if not maxId then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local cfg = ConfigManager:getConfig("chapter")
|
|
||||||
for id, info in ipairs(cfg) do
|
|
||||||
if id > maxId then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
local maxWave = info.box_num[#info.box_num]
|
|
||||||
if maxWave then
|
|
||||||
ServerGameData.ChapterData:fightChapter(id, true, maxWave)
|
|
||||||
end
|
|
||||||
ServerGameData.HeroData:tryUnlockHeroByChapterId(id)
|
|
||||||
end
|
|
||||||
ServerGameData.ChapterData.data.maxChapterId = maxId
|
|
||||||
end
|
|
||||||
|
|
||||||
ServerGameData:saveData()
|
|
||||||
if callback then
|
|
||||||
callback()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerDataManager:getServerGameData()
|
|
||||||
return ServerGameData
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerDataManager
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 46cc0de161cb26d4f901f3475f83927a
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -1,272 +0,0 @@
|
|||||||
local ServerGameData = {
|
|
||||||
seed = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
local TempRewards = {}
|
|
||||||
local WeightArr = {}
|
|
||||||
|
|
||||||
function ServerGameData:init()
|
|
||||||
if self.isInit then
|
|
||||||
for k, v in pairs(self.dataMap) do
|
|
||||||
v:_clear()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.isInit = true
|
|
||||||
self:initServerData("PlayerData", "app/server/data/server_player_data")
|
|
||||||
self:initServerData("BagData", "app/server/data/server_bag_data")
|
|
||||||
self:initServerData("HeroData", "app/server/data/server_hero_data")
|
|
||||||
self:initServerData("ChapterData", "app/server/data/server_chapter_data")
|
|
||||||
self:initServerData("FormationData", "app/server/data/server_formation_data")
|
|
||||||
self:initServerData("TutorialData", "app/server/data/server_tutorial_data")
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:initData()
|
|
||||||
self.disableSave = true
|
|
||||||
self:init()
|
|
||||||
if self.distinctId == nil or self.distinctId == "" then
|
|
||||||
self.distinctId = LocalData:getDistinctId()
|
|
||||||
end
|
|
||||||
local isNewPlayer = self:getIsNewPlayer()
|
|
||||||
if isNewPlayer then
|
|
||||||
if EDITOR_MODE then
|
|
||||||
Logger.logHighlight("create new player")
|
|
||||||
end
|
|
||||||
for k, v in pairs(self.dataMap) do
|
|
||||||
v:init()
|
|
||||||
end
|
|
||||||
local playerInitialCfg = ConfigManager:getConfig("player_initial")
|
|
||||||
if playerInitialCfg then
|
|
||||||
for k, v in pairs(playerInitialCfg) do
|
|
||||||
if v.reward then
|
|
||||||
self.BagData.ItemData:addItemReward(v.reward, BIReport.ITEM_GET_TYPE.NEW_PLAYER_INITIAL)
|
|
||||||
local rewardId = GFunc.getRewardId(v.reward)
|
|
||||||
local rewardNum = GFunc.getRewardNum(v.reward)
|
|
||||||
if rewardId == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
self.PlayerData:addExp(rewardNum)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local itemCfg = ConfigManager:getConfig("item")
|
|
||||||
local heroCfg = ConfigManager:getConfig("hero")
|
|
||||||
local heroLvCfg = ConfigManager:getConfig("hero_level")
|
|
||||||
-- 如果初始化里面有碎片就直接合成
|
|
||||||
local initHeroMap = {}
|
|
||||||
local items = self.BagData.ItemData:getAllItems()
|
|
||||||
for idStr, item in pairs(items) do
|
|
||||||
local itemInfo = itemCfg[item.cfg_id]
|
|
||||||
if itemInfo and itemInfo.type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then -- 英雄碎片就直接合成
|
|
||||||
local heroCfgId = itemInfo.parameter or 0
|
|
||||||
local hero = self.HeroData:getHeroByCfgId(heroCfgId)
|
|
||||||
if hero == nil or hero.lv <= 0 then -- 没有此英雄的时候才自动转化,不消耗金币,且只激活1级
|
|
||||||
local heroInfo = heroCfg[heroCfgId]
|
|
||||||
if heroInfo then
|
|
||||||
local costKey = "cost_" .. heroInfo.qlt
|
|
||||||
for k, v in ipairs(heroLvCfg) do
|
|
||||||
if v[costKey] then -- 第一个有值的就是解锁所需的数量
|
|
||||||
local needCout = v[costKey][1]
|
|
||||||
if item.count >= needCout then
|
|
||||||
item.count = item.count - needCout
|
|
||||||
self.HeroData:addHero(heroCfgId, k)
|
|
||||||
initHeroMap[heroInfo.position] = heroCfgId
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for matchType, heroId in pairs(initHeroMap) do
|
|
||||||
matchType = tostring(matchType)
|
|
||||||
self.FormationData:upHeroToFormation(GConst.BattleConst.BATTLE_TYPE.STAGE, matchType, heroId)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self:setNotNewPlayer()
|
|
||||||
else
|
|
||||||
for k, v in pairs(self.dataMap) do
|
|
||||||
v:loadLocalData()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
self.disableSave = false
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:initServerData(name, path)
|
|
||||||
self[name] = require(path):create()
|
|
||||||
if self.dataMap == nil then
|
|
||||||
self.dataMap = {}
|
|
||||||
end
|
|
||||||
self.dataMap[name] = self[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:getData()
|
|
||||||
local data = {}
|
|
||||||
for k, v in pairs(self.dataMap) do
|
|
||||||
data[k] = v:getCloneData()
|
|
||||||
end
|
|
||||||
return data
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:saveData()
|
|
||||||
if self.disableSave then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for k, v in pairs(self.dataMap) do
|
|
||||||
v:saveLocalData()
|
|
||||||
end
|
|
||||||
LocalData:save()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 根据配置表添加奖励
|
|
||||||
function ServerGameData:addRewards(cfgRewards, getType)
|
|
||||||
local rewards = {}
|
|
||||||
if cfgRewards then
|
|
||||||
local count = #TempRewards
|
|
||||||
for i = 1, count do
|
|
||||||
table.remove(TempRewards)
|
|
||||||
end
|
|
||||||
for _, reward in ipairs(cfgRewards) do
|
|
||||||
local rewardType = GFunc.getRewardType(reward)
|
|
||||||
if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then
|
|
||||||
local rewardId = GFunc.getRewardId(reward)
|
|
||||||
local rewardNum = GFunc.getRewardNum(reward)
|
|
||||||
local cfg = ConfigManager:getItemConfig()[rewardId]
|
|
||||||
if cfg.hero_drop then
|
|
||||||
self:openRewardBox(TempRewards, cfg.hero_drop, rewardNum, rewardId)
|
|
||||||
else
|
|
||||||
table.insert(TempRewards, reward)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
table.insert(TempRewards, reward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
count = #TempRewards
|
|
||||||
for i = 1, count do
|
|
||||||
local reward = table.remove(TempRewards)
|
|
||||||
local newReward = self:getNewReward()
|
|
||||||
local rewardType = GFunc.getRewardType(reward)
|
|
||||||
newReward.type = rewardType
|
|
||||||
if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then
|
|
||||||
self.BagData.ItemData:addItemReward(reward, getType)
|
|
||||||
local rewardId = GFunc.getRewardId(reward)
|
|
||||||
local rewardNum = GFunc.getRewardNum(reward)
|
|
||||||
if rewardId == GConst.ItemConst.ITEM_ID_EXP then
|
|
||||||
self.PlayerData:addExp(rewardNum)
|
|
||||||
end
|
|
||||||
local item = self:getNewItem()
|
|
||||||
item.cfg_id = rewardId
|
|
||||||
item.count = rewardNum
|
|
||||||
newReward.item = item
|
|
||||||
end
|
|
||||||
table.insert(rewards, newReward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return rewards
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- 根据配置表添加奖励
|
|
||||||
function ServerGameData:addCosts(cfgRewards, getType)
|
|
||||||
local rewards = {}
|
|
||||||
if cfgRewards then
|
|
||||||
local count = #TempRewards
|
|
||||||
for i = 1, count do
|
|
||||||
table.remove(TempRewards)
|
|
||||||
end
|
|
||||||
for _, reward in ipairs(cfgRewards) do
|
|
||||||
table.insert(TempRewards, reward)
|
|
||||||
end
|
|
||||||
count = #TempRewards
|
|
||||||
for i = 1, count do
|
|
||||||
local reward = table.remove(TempRewards)
|
|
||||||
local newReward = self:getNewReward()
|
|
||||||
local rewardType = GFunc.getRewardType(reward)
|
|
||||||
newReward.type = rewardType
|
|
||||||
if rewardType == GConst.ServerDataConst.REWARD_TYPE.ITEM then
|
|
||||||
self.BagData.ItemData:addItemCost(reward, getType)
|
|
||||||
local rewardId = GFunc.getRewardId(reward)
|
|
||||||
local rewardNum = GFunc.getRewardNum(reward)
|
|
||||||
newReward.item = {
|
|
||||||
id = rewardId,
|
|
||||||
num = rewardNum
|
|
||||||
}
|
|
||||||
end
|
|
||||||
table.insert(rewards, newReward)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return rewards
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:getNewReward()
|
|
||||||
local rewards = {
|
|
||||||
type = 0,
|
|
||||||
item = {},
|
|
||||||
}
|
|
||||||
return rewards
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:getNewItem()
|
|
||||||
local item = {
|
|
||||||
cfg_id = 0,
|
|
||||||
count = 0
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:openRewardBox(finalReward, drop, num, id)
|
|
||||||
local count = 0
|
|
||||||
for _, v in ipairs(drop) do
|
|
||||||
if self.HeroData:getIsUnlockHero(v.id) then
|
|
||||||
count = count + 1
|
|
||||||
WeightArr[count] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i = 1, num do
|
|
||||||
local rewardIdx = ServerDataManager:randomReward(WeightArr, count, function (min, max)
|
|
||||||
return ServerGameData:randomItemBox(id, min, max)
|
|
||||||
end)
|
|
||||||
table.insert(finalReward, WeightArr[rewardIdx])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:randomItemBox(id, min, max)
|
|
||||||
id = tostring(id)
|
|
||||||
local seed = self.seed[id]
|
|
||||||
if not seed then
|
|
||||||
local str = self.distinctId .. "_ItemBox_" .. id
|
|
||||||
seed = GFunc.hash(str)
|
|
||||||
self.seed[id] = seed
|
|
||||||
end
|
|
||||||
self.seed[id] = (seed*9301 + 49297)%233280
|
|
||||||
return min + self.seed[id]*(max - min + 1)//233280
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:getDistinctId()
|
|
||||||
return self.distinctId
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:setDistinctId(distinctId)
|
|
||||||
self.distinctId = distinctId
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:getIsNewPlayer()
|
|
||||||
return LocalData:getIsNewPlayer()
|
|
||||||
end
|
|
||||||
|
|
||||||
function ServerGameData:setNotNewPlayer()
|
|
||||||
LocalData:setNotNewPlayer()
|
|
||||||
end
|
|
||||||
|
|
||||||
if NOT_PUBLISH then
|
|
||||||
ServerGameData.editorGetIsNewPlayer = ServerGameData.getIsNewPlayer
|
|
||||||
function ServerGameData:getIsNewPlayer()
|
|
||||||
return LocalData:getInt(LocalData:getDistinctId() .. LocalData.KEYS.IS_NEW_PLAYER, 0) == 0
|
|
||||||
end
|
|
||||||
|
|
||||||
ServerGameData.editorSetNotNewPlayer = ServerGameData.setNotNewPlayer
|
|
||||||
function ServerGameData:setNotNewPlayer()
|
|
||||||
LocalData:setInt(LocalData:getDistinctId() .. LocalData.KEYS.IS_NEW_PLAYER, 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ServerGameData
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 341e1d539fc4d7a45a47ebb7a3376088
|
|
||||||
ScriptedImporter:
|
|
||||||
internalIDToNameTable: []
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
|
||||||
@ -89,12 +89,12 @@ function GMToolUI:sendMsg(gmCommand)
|
|||||||
else
|
else
|
||||||
local args = {}
|
local args = {}
|
||||||
args.args = string.split(gmCommand, " ")
|
args.args = string.split(gmCommand, " ")
|
||||||
ServerDataManager:dealGM(args, function()
|
-- :dealGM(args, function()
|
||||||
ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA, GConst.EMPTY_TABLE, function(msgData)
|
-- :dataOperate(GConst..DATA_OP_BEHAVIOR.SYNC_DATA, GConst.EMPTY_TABLE, function(msgData)
|
||||||
DataManager:initWithServerData(msgData)
|
-- DataManager:initWithServerData(msgData)
|
||||||
ModuleManager.MaincityManager:firstEnterMainCity()
|
-- ModuleManager.MaincityManager:firstEnterMainCity()
|
||||||
end)
|
-- end)
|
||||||
end)
|
-- end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -7,24 +7,30 @@ function ChapterData:ctor()
|
|||||||
self.data.chapterId = MIN_CHAPTER_ID
|
self.data.chapterId = MIN_CHAPTER_ID
|
||||||
self.data.maxChapterId = 0
|
self.data.maxChapterId = 0
|
||||||
self.data.isDirty = false
|
self.data.isDirty = false
|
||||||
self.data.chapterBoxInfo = {}
|
|
||||||
self.data.chapterFightInfo = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:clear()
|
function ChapterData:clear()
|
||||||
self.data.chapterId = MIN_CHAPTER_ID
|
self.data.chapterId = MIN_CHAPTER_ID
|
||||||
self.data.maxChapterId = 0
|
self.data.maxChapterId = 0
|
||||||
self.data.chapterBoxInfo = {}
|
|
||||||
self.data.chapterFightInfo = {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:init(data, notChangeChapterId)
|
function ChapterData:init(data, notChangeChapterId)
|
||||||
self.data.maxChapterId = data and data.maxChapterId or MIN_CHAPTER_ID - 1
|
if not data then
|
||||||
if not notChangeChapterId then
|
return
|
||||||
self.data.chapterId = self:getNextChapter(self.data.maxChapterId)
|
|
||||||
end
|
end
|
||||||
self.data.chapterBoxInfo = data and data.chapterBoxInfo or {}
|
|
||||||
self.data.chapterFightInfo = data and data.chapterFightInfo or {}
|
self.maxWave = data.max_wave or 0
|
||||||
|
if self.maxWave >= self:getChapterCfgMaxWave(data.max_chapter_id) then
|
||||||
|
self.data.maxChapterId = data.max_chapter_id
|
||||||
|
else
|
||||||
|
self.data.maxChapterId = data.max_chapter_id - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if not notChangeChapterId then
|
||||||
|
self.data.chapterId = data.max_chapter_id
|
||||||
|
end
|
||||||
|
|
||||||
|
self.data.chapterInfo = data.chapter_info or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:getIsFirstChapter(chapterId)
|
function ChapterData:getIsFirstChapter(chapterId)
|
||||||
@ -129,13 +135,13 @@ function ChapterData:getChapterBoxNum(chapterId, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:getChapterBoxRewardGot(chapterId, index)
|
function ChapterData:getChapterBoxRewardGot(chapterId, index)
|
||||||
chapterId = tostring(chapterId or self:getChapterId())
|
chapterId = chapterId or self:getChapterId()
|
||||||
local list = self.data.chapterBoxInfo[chapterId]
|
local info = self.data.chapterInfo[chapterId]
|
||||||
if not list then
|
if not info or not info.index then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, idx in ipairs(list) do
|
for _, idx in ipairs(info.index) do
|
||||||
if idx == index then
|
if idx == index then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -166,18 +172,34 @@ function ChapterData:getChapterBoxRewards(chapterId, index)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:getChapterMaxWave(chapterId)
|
function ChapterData:getChapterMaxWave(chapterId)
|
||||||
chapterId = tostring(chapterId or self:getChapterId())
|
chapterId = chapterId or self:getChapterId()
|
||||||
if self.data.chapterFightInfo[chapterId] then
|
if chapterId <= self.maxChapterId then
|
||||||
return self.data.chapterFightInfo[chapterId].maxWave
|
return self:getChapterCfgMaxWave(chapterId)
|
||||||
|
else
|
||||||
|
return self.maxWave
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChapterData:getChapterCfgMaxWave(chapterId)
|
||||||
|
if not self.chapterCfgMaxWaveMap then
|
||||||
|
self.chapterCfgMaxWaveMap = {}
|
||||||
|
end
|
||||||
|
if not self.chapterCfgMaxWaveMap[chapterId] then
|
||||||
|
local chapterInfo = self:getChapterCfg()[chapterId]
|
||||||
|
if not chapterInfo then
|
||||||
|
self.chapterCfgMaxWaveMap[chapterId] = 1
|
||||||
|
else
|
||||||
|
self.chapterCfgMaxWaveMap[chapterId] = #chapterInfo.monster
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return 0
|
return self.chapterCfgMaxWaveMap[chapterId]
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:getChapterFightCount(chapterId)
|
function ChapterData:getChapterFightCount(chapterId)
|
||||||
chapterId = tostring(chapterId or self:getChapterId())
|
chapterId = chapterId or self:getChapterId()
|
||||||
if self.data.chapterFightInfo[chapterId] then
|
if self.data.chapterInfo[chapterId] then
|
||||||
return self.data.chapterFightInfo[chapterId].fightCount or 0
|
return self.data.chapterInfo[chapterId].total_count or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -227,18 +249,21 @@ function ChapterData:getIsHaveRewards(chapterId)
|
|||||||
if chapterId > self.data.maxChapterId + 1 then
|
if chapterId > self.data.maxChapterId + 1 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local chapterStr = tostring(chapterId)
|
local info = self.data.chapterInfo[chapterId]
|
||||||
local list = self.data.chapterBoxInfo[chapterStr]
|
if not info or not info.index then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local count = self:getChapterBoxCount(chapterId)
|
local count = self:getChapterBoxCount(chapterId)
|
||||||
if list and #list == count then -- 数量一致说明都领完了
|
if info.index and #info.index == count then -- 数量一致说明都领完了
|
||||||
return false
|
return false
|
||||||
elseif chapterId < self.data.maxChapterId then
|
elseif chapterId < self.data.maxChapterId then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local curMaxWave = self:getChapterMaxWave(chapterStr)
|
local curMaxWave = self:getChapterMaxWave(chapterId)
|
||||||
for i = 1, count do
|
for i = 1, count do
|
||||||
local needWave = self:getChapterBoxNum(chapterId, i)
|
local needWave = self:getChapterBoxNum(chapterId, i)
|
||||||
local rewardGot = self:getChapterBoxRewardGot(chapterStr, i)
|
local rewardGot = self:getChapterBoxRewardGot(chapterId, i)
|
||||||
if needWave <= curMaxWave and not rewardGot then -- 有可以领但是没有领的奖励
|
if needWave <= curMaxWave and not rewardGot then -- 有可以领但是没有领的奖励
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -247,12 +272,27 @@ function ChapterData:getIsHaveRewards(chapterId)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ChapterData:getChapterPassed(chapterId)
|
function ChapterData:getChapterPassed(chapterId)
|
||||||
chapterId = tostring(chapterId or self:getChapterId())
|
chapterId = chapterId or self:getChapterId()
|
||||||
if self.data.chapterFightInfo[chapterId] then
|
if chapterId <= self.maxChapterId then
|
||||||
return self.data.chapterFightInfo[chapterId].victory or false
|
return true
|
||||||
|
else
|
||||||
|
return self.maxWave >= self:getChapterCfgMaxWave(chapterId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChapterData:openBox(chapterId, index)
|
||||||
|
if not self.data.chapterInfo[chapterId] or not self.data.chapterInfo[chapterId].index then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, idx in ipairs(self.data.chapterInfo[chapterId].index) do
|
||||||
|
if idx == index then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
table.insert(self.data.chapterInfo[chapterId].index, index)
|
||||||
|
|
||||||
|
self:setDirty()
|
||||||
end
|
end
|
||||||
|
|
||||||
return ChapterData
|
return ChapterData
|
||||||
Loading…
x
Reference in New Issue
Block a user