123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- --===========================================================================================
- --勇者试炼
- --===========================================================================================
- BraveTest = {}
- local this = {}
- ---红点id
- this.ReadId = 100
- local MONSTER_ID_KEY = "CURRENT_MONSTERS"
- local REP_ID_KEY = "REP_ID"
- local CURR_LEVEL = "T$_BRAVE_TEST_CURR_LEVEL"
- local COMPLETE_INFO = "T$_BRAVE_TEST_COMPLETE_INFO"
- local STAGE_REWARD_KEY = "T$_STAGE_REWARD"
- local FIGHT_TIME_KEY = "T$_BRAVE_TEST_TIME"
- --region 战斗时间数据访问相关
- function BraveTest.getFightTime(actor)
- local data = getplaydef(actor, FIGHT_TIME_KEY)
- if table.isNullOrEmpty(data) then
- return {}
- end
- return data
- end
- function BraveTest.setFightTime(actor, data)
- setplaydef(actor, FIGHT_TIME_KEY, data)
- end
- function BraveTest.getFightTimeByLevel(actor, level)
- local data = BraveTest.getFightTime(actor)
- local result = table.getValue(data, tostring(level))
- if result == nil then
- return nil
- end
- return tonumber(result)
- end
- function BraveTest.setFightTimeByLevel(actor, level, timestampMills)
- local data = BraveTest.getFightTime(actor)
- data[tostring(level)] = timestampMills
- BraveTest.setFightTime(actor, data)
- end
- --endregion
- function BraveTest.CheckEnter(actor)
- local currLevel = getplaydef(actor, CURR_LEVEL)
- if string.isNullOrEmpty(currLevel) then
- currLevel = 1
- else
- currLevel = tonumber(currLevel) + 1
- end
- if currLevel > this.GetMaxLevel() then
- return false
- end
- local id = BraveTest.level2ConfigId(currLevel)
- id = tonumber(id)
- if id == nil or id <= 0 then
- gameDebug.assertPrintTrace(false, actor:toString() .. "勇者试炼检测进入失败,副本配置未找到!currLevel:" .. currLevel)
- return false
- end
- return DuplicateCommon.CheckEnterConditonCommon(actor, id) == EnterLimitResultConst.ALLOW
- end
- function this.GetMaxLevel()
- local minAndMaxId = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", RepGlobalConfig.BRAVE_TEST_LEVEL)
- local maxId = string.split(minAndMaxId, "#")[2]
- local maxLevel = tonumber(ConfigDataManager.getTableValue("cfg_rep", "replevel", "id", maxId))
- return tonumber(maxLevel)
- end
- function BraveTest.ReqEnterBraveTest(actor, configId)
- --个人进入
- if DuplicateCommon.CheckEnterConditonCommon(actor, configId) ~= EnterLimitResultConst.ALLOW then
- return
- end
- local maxHP = getattrinfo(actor, "maxHP")
- local maxMP = getattrinfo(actor, "maxMP")
- sethp(actor, maxHP)
- setmp(actor, maxMP)
- --寻找是否有可进入的副本,如果没有创建副本
- local mapId = DuplicateCommon.CreateDupMapCommon(actor, configId, true)
- local x, y = DuplicateCommon.GetEnterPointXYCommon(configId)
- --回蓝回血
- DuplicateCommon.RecoverHPMP(actor)
- --进入副本
- --print("【勇者试炼】进入副本",actor:toString() ,mapId, x, y)
- enterduplicate(actor, mapId, x, y)
- --BraveTest.resCurrencyStateInfo(DuplicateState.PREPARE,mapId,actor)
- --上一关奖励未领取则执行领取操作
- local prevCfgId = BraveTest.getPrevCfgId(configId)
- if prevCfgId ~= nil and BraveTest.rewardable(actor, prevCfgId) then
- local level = BraveTest.config2Level(prevCfgId)
- BraveTest.rewardByLevel(actor, level)
- end
- end
- function BraveTest.BraveTestStateUpdate(system, id, state, nextStateStartTime, configId)
- local currLevel = BraveTest.config2Level(configId)
- local now = getbaseinfo("now")
- local dupInfo = getduplicate(id)
- local players = table.getValue(dupInfo, "players")
- if state == DuplicateState.PREPARE then
- --jprint("【勇者试炼】副本开始",configId,id,state)
- elseif state == DuplicateState.FIGHT then
- --战斗阶段,刷怪
- local monsterId = ConfigDataManager.getTableValue("cfg_rep", "monster", "id", configId)
- --jprint("【勇者试炼】战斗阶段开始刷怪",configId,id,state)
- local monsterActors = DuplicateCommon.DupGenMonsterCommon(id, monsterId)
- local monsterActorIDs = {}
- for _, id in pairs(monsterActors) do
- table.insert(monsterActorIDs, id:toString())
- end
- --jprint("monsterActorIDs", monsterActorIDs)
- --把刷出来的怪保存起来
- setenvirvar(id, MONSTER_ID_KEY, monsterActorIDs)
- --把副本的配置ID保存起来
- setenvirvar(id, REP_ID_KEY, configId)
- BraveTest.resCurrencyStateInfo(state, id)
- --记录开始时间
- if players ~= nil then
- for _, actor in pairs(players) do
- BraveTest.setFightTimeByLevel(actor, currLevel, now)
- end
- end
- elseif state == DuplicateState.FINISH then
- --jprint("【勇者试炼】副本结束",configId,id,state)
- BraveTest.resCurrencyStateInfo(state, id)
- --计算战斗时间
- if players ~= nil then
- for _, actor in pairs(players) do
- local startTime = BraveTest.getFightTimeByLevel(actor, currLevel);
- if startTime ~= nil then
- local diffMills = now - startTime
- jprint("勇者试炼完成时间", actor, currLevel, startTime, now, diffMills)
- RankScript.updateBraveTestInfos(actor, currLevel, diffMills)
- AngelBenefit.UpdateTaskProgress(actor, AngelBenefit.TASK_TYPE.BRAVE, currLevel)
- end
- end
- end
- end
- end
- function BraveTest.refreshRedDot(actor)
- RedPoint.sendOneRedPoint(actor, this.ReadId, BraveTest.CheckEnter(actor) or false)
- end
- ---登录触发红点刷新
- function BraveTest.loginRed(red_data, actor)
- if BraveTest.CheckEnter(actor) then
- ---登陆的时候判定 false 可以不发送的
- red_data[this.ReadId] = true
- end
- end
- -- @description 响应给客户端当前阶段
- -- @param 玩家对象;地图id
- -- @return
- function BraveTest.resCurrencyStateInfo(state, mapId, actor)
- local dupInfo = getduplicate(mapId)
- local players = table.getValue(dupInfo, "players")
- -- local state = table.getValue(dupInfo,"state")
- local configId = table.getValue(dupInfo, "dupcfgid")
- local nextStateStartTime = table.getValue(dupInfo, "nextstatetime")
- local ok = false
- local monsterActorIDs = getenvirvar(mapId, MONSTER_ID_KEY)
- if table.isNullOrEmpty(monsterActorIDs) and state == DuplicateState.FINISH then
- ok = true
- end
- local res = { state, tostring(nextStateStartTime), configId, ok }
- if actor ~= nil then
- sendluamsg(actor, LuaMessageIdToClient.BRAVE_TEST_STATE, res)
- else
- for _, _actor in ipairs(players) do
- sendluamsg(_actor, LuaMessageIdToClient.BRAVE_TEST_STATE, res)
- end
- end
- end
- function BraveTest.BraveTestEnter(actor, mapId, state, nextStateStartTime, configId)
- BraveTest.resCurrencyStateInfo(state, mapId, actor)
- end
- function BraveTest.BraveTestMonsterDie(mapId, killer, monCfgId, monActor)
- local monsterActorIDs = getenvirvar(mapId, MONSTER_ID_KEY)
- --jprint("monsterActorIDs", monsterActorIDs)
- if table.isNullOrEmpty(monsterActorIDs) then
- return
- end
- local strId = monActor:toString()
- if array.contains(monsterActorIDs, strId) then
- table.removeByValue(monsterActorIDs, strId)
- end
- --jprint("monsterActorIDs2", monsterActorIDs)
- setenvirvar(mapId, MONSTER_ID_KEY, monsterActorIDs)
- if table.isNullOrEmpty(monsterActorIDs) then
- --领取奖励
- local cfgId = getenvirvar(mapId, REP_ID_KEY)
- --记录下当前的关卡层级
- local level = BraveTest.config2Level(cfgId)
- setplaydef(killer, CURR_LEVEL, level)
- OpenServerCompetition.updateRankData(killer, CompetitionType.BRAVE_CHALLENGE, level)
- --BraveTest.resCurrencyStateInfo(DuplicateState.FINISH, mapId)
- setduplicatestate(mapId, SetDuplicateStateConst.TO_FINISH)
- end
- end
- function BraveTest.ReqBraveTestPanelInfo(actor)
- local currLevel = getplaydef(actor, CURR_LEVEL)
- if string.isNullOrEmpty(currLevel) then
- currLevel = 1
- else
- currLevel = tonumber(currLevel) + 1
- end
- local rewardInfo = BraveTest.getStageRewardInfo(actor)
- local stageReward = not table.isNullOrEmpty(rewardInfo)
- local id = BraveTest.level2ConfigId(currLevel)
- local res = {
- id = id,
- level = currLevel,
- stageReward = stageReward
- }
- sendluamsg(actor, LuaMessageIdToClient.BRAVE_TEST_PANEL_INFO, res)
- end
- function BraveTest.level2ConfigId(level)
- local cfgId = ConfigDataManager.getTableValue("cfg_rep", "id", "type", DuplicateType.BRAVE_TEST, "replevel", level)
- return cfgId
- end
- function BraveTest.config2Level(cfgId)
- local level = ConfigDataManager.getTableValue("cfg_rep", "replevel", "id", cfgId)
- if level == nil then
- return nil
- end
- return tonumber(level)
- end
- function BraveTest.getPrevCfgId(cfgId)
- local currLevel = BraveTest.config2Level(cfgId)
- if currLevel ~= nil and currLevel > 1 then
- local prevLevel = currLevel - 1
- return BraveTest.level2ConfigId(prevLevel)
- else
- return nil
- end
- end
- function BraveTest.onQuitDup(actor, cfgId)
- if BraveTest.rewardable(actor, cfgId) then
- local level = BraveTest.config2Level(cfgId)
- BraveTest.rewardByLevel(actor, level)
- end
- end
- function BraveTest.getStageRewardInfo(actor)
- local data = getplaydef(actor, STAGE_REWARD_KEY)
- if data == nil then
- return {}
- end
- return data
- end
- function BraveTest.setStageRewardInfo(actor, data)
- setplaydef(actor, STAGE_REWARD_KEY, data)
- end
- --领取阶阶段奖励
- function BraveTest.ReqBraveTestStageReward(actor)
- local rewardConfigStr = ConfigDataManager.getTableValue("cfg_repGlobal", "value", "id", 12001002)
- if string.isNullOrEmpty(rewardConfigStr) then
- return
- end
- local items = string.split(rewardConfigStr, "#")
- if array.length(items) ~= 3 then
- return
- end
- local level = items[1]
- local itemId = items[2]
- local itemCount = items[3]
- local numLevel = tonumber(level)
- local currLevel = getplaydef(actor, CURR_LEVEL)
- if tonumber(currLevel) >= numLevel then
- --可以领奖
- local rewardInfo = BraveTest.getStageRewardInfo(actor)
- if table.contains(rewardInfo, numLevel) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT385)
- return
- end
- additemtobag(actor, itemId, itemCount, 0, 9999, '勇气试炼')
- table.insert(rewardInfo, numLevel)
- BraveTest.setStageRewardInfo(actor, rewardInfo)
- local res = {}
- res[itemId] = itemCount
- sendluamsg(actor, LuaMessageIdToClient.BRAVE_TEST_STAGE_REWARD, res)
- else
- noticeTip.noticeinfo(actor, StringIdConst.TEXT386)
- end
- BraveTest.refreshRedDot(actor)
- end
- -- 领取奖励
- function BraveTest.ReqBraveTestReward(actor)
- local currLevel = getplaydef(actor, CURR_LEVEL)
- if currLevel == nil and currLevel <= 0 then
- return
- end
- local cfgId = BraveTest.level2ConfigId(currLevel)
- if BraveTest.rewardable(actor, cfgId) then
- BraveTest.rewardByLevel(actor, currLevel)
- jprint("领取勇者试炼奖励", actor, currLevel, cfgId)
- end
- end
- --执行领奖
- function BraveTest.rewardByLevel(actor, currLevel)
- local cfgId = BraveTest.level2ConfigId(currLevel)
- local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", cfgId)
- reduceactivitytimes(actor, activityId, 1)
- local completeInfo = getplaydef(actor, COMPLETE_INFO)
- if completeInfo == nil then
- completeInfo = {}
- end
- local levelKey = tostring(currLevel)
- local completeInfoItem = table.getValue(completeInfo, levelKey)
- if completeInfoItem == nil then
- completeInfoItem = {}
- completeInfo[levelKey] = completeInfoItem
- end
- local isreward = table.getValue(completeInfoItem, "isreward");
- if isreward == 1 then
- return
- end
- --local cfgId = BraveTest.level2ConfigId(currLevel)
- if string.isNullOrEmpty(cfgId) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT387)
- return
- end
- local reward = ConfigDataManager.getTableValue("cfg_rep", "reward", "id", cfgId)
- if string.isNullOrEmpty(reward) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT388)
- return
- end
- local rewardMap = string.toIntIntMap(reward, "#", "|")
- if table.isNullOrEmpty(rewardMap) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT389)
- return
- end
- --jprint("领取奖励",rewardMap)
- local itemBing = ConfigDataManager.getTableValue("cfg_bind", "bind", "id", 11)
- additemmaptobag(actor, rewardMap, itemBing, 9999, '勇气试炼')
- sendluamsg(actor, LuaMessageIdToClient.BRAVE_TEST_REWARD, rewardMap)
- completeInfoItem["isreward"] = 1
- setplaydef(actor, COMPLETE_INFO, completeInfo)
- DuplicateCommon.FinishDupActivity(actor, cfgId)
- BraveTest.refreshRedDot(actor)
- --勇气试炼任务
- TaskHandler.TriggerTaskGoal(actor, TaskTargetType.FLUSH_BRAVE_TEST_LV)
- end
- --是否领取了奖励
- function BraveTest.rewardable(actor, cfgId)
- local currlevel = getplaydef(actor, CURR_LEVEL)
- if currlevel ~= BraveTest.config2Level(cfgId) then
- return false
- end
- local completeInfo = getplaydef(actor, COMPLETE_INFO)
- if completeInfo == nil then
- return true
- end
- local currLevel = BraveTest.config2Level(cfgId)
- local levelKey = tostring(currLevel)
- local completeInfoItem = table.getValue(completeInfo, levelKey)
- if completeInfoItem == nil then
- return true
- end
- local isreward = table.getValue(completeInfoItem, "isreward");
- return isreward == 0
- end
- function BraveTest.playerDie(actor)
- local mapId = getbaseinfo(actor, "unimapid")
- --print("mapid", mapId)
- local dupInfo = getduplicate(mapId)
- if dupInfo == nil then
- return
- end
- local type = dupInfo["type"]
- if type ~= DuplicateType.BRAVE_TEST then
- return
- end
- --print("dupinfo", dupInfo)
- local players = table.getValue(dupInfo, "players")
- for _, v in pairs(players) do
- if tostring(v) == actor:toString() then
- intervalcalldelay(actor, 4000, 1000, 1, "bravetestquitdump", actor)
- break
- end
- end
- end
- function BraveTest.getBraveTestLv(actor)
- return getplaydef(actor, CURR_LEVEL) or 0
- end
- function bravetestquitdump(actor)
- --print("bravetestquitdump", actor:toString())
- quitduplicate(actor)
- end
- function addbravetestcount(actor, count)
- jprint(actor, "增加勇者试炼次数", count)
- addleftcountofactivity(actor, DuplicateType.BRAVE_TEST, count)
- end
- RedPointEventListerTable:eventLister("0", "勇者试炼红点", BraveTest.loginRed)
|