123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by zhangkai.
- --- DateTime: 2024/8/20 上午10:02
- ---
- GoldTask = {}
- local this = {}
- GoldTask.Var = {
- GOLD_TASK_INFO = "T$goldtaskinfo",
- }
- GoldTask.Const = {
- ---任务状态
- TASK_STATUS = {
- ---已接取
- ACCEPT = 1,
- ---已完成
- FINISH = 2,
- ---已提交
- SUBMIT = 3,
- },
- ---任务星级
- TASK_STAR = {
- ---一星
- ONE = 1,
- ---二星
- TWO = 2,
- ---三星
- THREE = 3,
- }
- }
- ---任务池大小
- local TASK_POOL_SIZE = 4;
- --function goldtasktest(actor,msgID, msgData)
- -- jprint("黄金任务测试")
- -- handlerequest(actor, 0,tonumber(msgID), msgData)
- --end
- function this.GetNewTaskRecord()
- ---玩家任务记录
- local taskrecord = {
- taskid = 0,
- star = 1,
- progress = 0,
- status = GoldTask.Const.TASK_STATUS.ACCEPT,
- }
- return taskrecord
- end
- function this.GetNewGoldTask()
- ---玩家黄金任务信息任务
- local goldtaskinfo = {
- ---当前任务池
- nowtaskpool = {},
- ---当日刷新次数
- flushcount = 0;
- ---当前正在进行的任务
- nowtask = nil,
- ---是否首次开启任务页面
- firstopen = true,
- ---当日已完成的任务记录
- dailyrecord = {},
- --重置时间
- lastresettime = "",
- }
- return goldtaskinfo
- end
- function GoldTask.GetPayerTaskInfo(actor)
- local taskInfo = getplaydef(actor, GoldTask.Var.GOLD_TASK_INFO)
- if not taskInfo then
- taskInfo = this.GetNewGoldTask()
- end
- return taskInfo
- end
- function GoldTask.Login(actor)
- GoldTask.SendTaskInfo(actor)
- end
- ---刷新玩家任务池
- function GoldTask.FlushGoldTaskPool(actor)
- local playerLevel = tonumber(getbaseinfo(actor, "level"))
- local levelLimit = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.GOLD_TASK_LEVEL_LIMIT))
- if playerLevel < levelLimit then
- noticeTip.noticeinfo(actor, StringIdConst.LEVEL_INSUFFICIENT)
- return
- end
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- if taskInfo.nowtask ~= nil then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT349)
- return
- end
- local flushCount = taskInfo.flushcount
- local pay = false;
- local freeLimit = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.GOLD_TASK_FREE_LIMIT))
- local itemCfg = 0
- local needCount = 0
- if flushCount >= freeLimit then
- --尝试付费刷新
- itemCfg, needCount = GoldTask.CheckConst(actor)
- if itemCfg == nil or needCount == nil then
- return
- end
- end
- local taskCfgList = ConfigDataManager.getList("cfg_task_gold")
- local taskList = GoldTask.RandomTask(actor, playerLevel, taskCfgList)
- if not taskList or #taskList == 0 then
- print("刷新数据异常, playerLevel: ", tostring(playerLevel), "配置空")
- return
- end
- --扣消耗
- if itemCfg ~= nil and needCount > 0 then
- local ret = removeitemfrombag(actor, itemCfg, needCount, 0, 9999, '黄金任务')
- if not ret then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT350)
- return
- end
- pay = true
- end
- taskInfo.nowtaskpool = GoldTask.BuildNewTaskPool(actor, taskList, pay, false)
- --jprint(taskInfo.nowtaskpool)
- taskInfo.flushcount = flushCount + 1
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- --jprint("刷新黄金任务池",taskInfo)
- end
- ---付费刷新
- function GoldTask.CheckConst(actor)
- local flushCost = string.split(ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.GOLD_TASK_FLUSH_COST), "#")
- local itemCfg = tonumber(flushCost[1])
- local needCount = tonumber(flushCost[2])
- local ownCount = tonumber(getbagitemcountbyid(actor, itemCfg))
- if ownCount == nil or needCount > ownCount then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT351)
- return nil
- end
- return itemCfg, needCount
- end
- function GoldTask.BuildNewTaskPool(actor, taskList, pay, first)
- local taskPool = {}
- for _, taskId in pairs(taskList) do
- local star = this.RandomStar(taskId, pay)
- taskPool[taskId] = star
- end
- return taskPool
- end
- function this.RandomStar(taskId, pay)
- local taskCfgList = ConfigDataManager.getTable("cfg_task_gold", "id", taskId)
- local star = GoldTask.Const.TASK_STAR.ONE
- if table.isNullOrEmpty(taskCfgList) then
- return 0
- end
- local taskCfg = taskCfgList[1]
- local weightCfg = string.split(taskCfg["probability"], "#")
- if pay then
- weightCfg = string.split(taskCfg["specialprobability"], "#")
- end
- retList = randombyweight(weightCfg, 1)
- if not table.isNullOrEmpty(retList) then
- star = retList[1]
- end
- return star
- end
- function GoldTask.RandomTask(actor, level, taskCfgList)
- local weightMap = {}
- for _, taskCfg in pairs(taskCfgList) do
- local taskId = tonumber(taskCfg["id"])
- local pass = GoldTask.CheckLv(level, taskCfg["level"])
- if pass then
- weightMap[taskId] = tonumber(taskCfg["weight"])
- end
- end
- return randombyweight(actor, weightMap, TASK_POOL_SIZE)
- end
- function GoldTask.CheckLv(level, taskLvCfgLimit)
- if string.isNullOrEmpty(taskLvCfgLimit) then
- return true
- end
- local lvLimit = string.split(taskLvCfgLimit, "#")
- if #lvLimit < 0 then
- return true
- end
- if #lvLimit >= 1 and level < tonumber(lvLimit[1]) then
- return false
- end
- if #lvLimit >= 2 and level > tonumber(lvLimit[2]) then
- return false
- end
- return true
- end
- ---接取任务
- function GoldTask.AcceptTask(actor, msgData)
- jprint("请求接取黄金任务", msgData)
- local taskId = GoldTask.GetTaskId(msgData)
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local myTaskPool = taskInfo.nowtaskpool
- if not myTaskPool then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT352)
- return
- end
- local myTask = taskInfo.nowtask
- if myTask or myTask ~= nil then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT349)
- return
- end
- local finishCount = 0
- local taskRecord = taskInfo.dailyrecord
- if taskRecord then
- finishCount = table.count(taskRecord)
- end
- local countLimit = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.GOLD_TASK_COUNT))
- if finishCount >= countLimit then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT354)
- return
- end
- local taskStar = myTaskPool[taskId]
- if taskStar == nil then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT355)
- return
- end
- local record = GoldTask.BuildTaskRecord(taskId, taskStar)
- taskInfo.nowtask = record
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- --jprint("接取黄金任务",taskInfo)
- end
- function GoldTask.BuildTaskRecord(taskId, taskStar)
- local record = this.GetNewTaskRecord()
- record.taskid = taskId
- record.star = taskStar
- return record
- end
- function GoldTask.UpdateTaskProgress(actor, monsterId)
- local success, errorInfo = xpcall(this.UpdateTaskProgress, debug.traceback, actor, monsterId)
- gameDebug.assertPrint(success, "怪物死亡更新黄金任务进度异常:", actor, monsterId, errorInfo)
- end
- ---更新任务进度
- function this.UpdateTaskProgress(actor, monsterId)
- if actor == nil then
- return
- end
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local myTask = taskInfo.nowtask
- if table.isNullOrEmpty(myTask) then
- return
- end
- local taskCfgList = ConfigDataManager.getTable("cfg_task_gold", "id", myTask.taskid)
- if table.isNullOrEmpty(taskCfgList) then
- return
- end
- local taskCfg = taskCfgList[1]
- local monsterCfg = tonumber(taskCfg["monsterid"])
- if monsterId ~= monsterCfg then
- return
- end
- if myTask.status > GoldTask.Const.TASK_STATUS.ACCEPT then
- return
- end
- local myProgress = myTask.progress
- local taskGoalNum = string.split(taskCfg["taskgoalnum"], "#")
- local needNum = tonumber(taskGoalNum[myTask.star])
- if myProgress + 1 >= needNum then
- myTask.status = GoldTask.Const.TASK_STATUS.FINISH
- end
- myTask.progress = myProgress + 1
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- end
- ---放弃任务
- function GoldTask.GiveUpTask(actor, msgData)
- jprint("请求放弃黄金任务", msgData)
- local taskId = GoldTask.GetTaskId(msgData)
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local myTask = taskInfo.nowtask
- if table.isNullOrEmpty(myTask) or myTask.taskid ~= tonumber(taskId) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT355)
- return
- end
- if myTask.status > GoldTask.Const.TASK_STATUS.ACCEPT then
- tipinfo(actor, "任务已完成")
- return
- end
- taskInfo.nowtask = nil
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- --jprint("放弃黄金任务",taskId,taskInfo)
- end
- ---提交任务
- function GoldTask.SubmitTask(actor, msgData)
- jprint("请求提交黄金任务", msgData)
- local taskId = GoldTask.GetTaskId(msgData)
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local myTask = taskInfo.nowtask
- if table.isNullOrEmpty(myTask) or myTask.taskid ~= taskId then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT355)
- return
- end
- if myTask.status ~= GoldTask.Const.TASK_STATUS.FINISH then
- tipinfo(actor, "任务未完成")
- return
- end
- local taskStar = myTask.star
- local taskCfgList = ConfigDataManager.getTable("cfg_task_gold", "id", taskId)
- if not taskCfgList then
- return
- end
- local ret = GoldTask.GetTaskReward(taskStar, taskCfgList[1])
- local exp = ret.exp
- local itemBind = ConfigDataManager.getTableValue("cfg_bind", "bind", "id", 16)
- --发奖励
- if exp > 0 then
- additemtobag(actor, ItemConfigId.EXP, exp, itemBind, 9999, "黄金任务")
- end
- local itemAward = ret.item
- for itemCfgId, count in pairs(itemAward) do
- additemtobag(actor, itemCfgId, count, 0, 9999, '黄金任务')
- end
- --奖励面板
- if exp > 0 then
- itemAward[ItemConfigId.EXP] = exp
- end
- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, itemAward)
- --提交任务
- taskInfo.nowtask = nil
- myTask.status = GoldTask.Const.TASK_STATUS.SUBMIT
- table.insert(taskInfo.dailyrecord, myTask)
- this.SubmitFlushTaskPool(actor, taskInfo.nowtaskpool, taskId)
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- jprint("提交黄金任务", taskId, taskInfo)
- --更新任务进度
- TaskHandler.TriggerTaskGoal(actor, TaskTargetType.FINISH_GOLD_TASK, taskId)
- end
- function this.SubmitFlushTaskPool(actor, nowTaskPool, submitTask)
- local playerLevel = tonumber(getbaseinfo(actor, "level"))
- local taskCfgList = ConfigDataManager.getList("cfg_task_gold")
- local weightMap = {}
- for _, taskCfg in pairs(taskCfgList) do
- local taskId = tonumber(taskCfg["id"])
- local pass = GoldTask.CheckLv(playerLevel, taskCfg["level"])
- local taskStar = nowTaskPool[taskId]
- if pass and taskStar == nil then
- weightMap[taskId] = tonumber(taskCfg["weight"])
- end
- end
- local randomTask = submitTask
- if not table.isNullOrEmpty(weightMap) then
- --随机一个新任务
- local randomTaskList = randombyweight(actor, weightMap, 1)
- if not table.isNullOrEmpty(randomTaskList) then
- randomTask = randomTaskList[1]
- end
- end
- --随机一个星级
- local star = this.RandomStar(randomTask, false)
- if star == 0 then
- return
- end
- nowTaskPool[submitTask] = nil
- nowTaskPool[randomTask] = star
- --jprint("黄金任务池",nowTaskPool)
- end
- function GoldTask.GetTaskReward(taskStar, taskCfg)
- local rewardCfg = ""
- local exp = 0
- local reward = {
- exp = exp,
- item = {}
- }
- if taskStar == GoldTask.Const.TASK_STAR.ONE then
- rewardCfg = taskCfg["rewarditem1"]
- exp = tonumber(taskCfg["rewardexpnum1"])
- end
- if taskStar == GoldTask.Const.TASK_STAR.TWO then
- rewardCfg = taskCfg["rewarditem2"]
- exp = tonumber(taskCfg["rewardexpnum2"])
- end
- if taskStar == GoldTask.Const.TASK_STAR.THREE then
- rewardCfg = taskCfg["rewarditem3"]
- exp = tonumber(taskCfg["rewardexpnum3"])
- end
- if exp ~= nil then
- reward.exp = exp
- end
- if string.isNullOrEmpty(rewardCfg) then
- return reward
- end
- for _, itemCfg in pairs(string.split(rewardCfg, "|")) do
- local itemCfgArray = string.split(itemCfg, "#")
- local itemId = tonumber(itemCfgArray[1])
- local itemNum = tonumber(itemCfgArray[2])
- reward.item[itemId] = itemNum
- end
- return reward
- end
- ---发送玩家黄金任务信息
- function GoldTask.SendTaskInfo(actor)
- --jprint("发送玩家黄金任务信息")
- local playerLevel = tonumber(getbaseinfo(actor, "level"))
- local levelLimit = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.GOLD_TASK_LEVEL_LIMIT))
- if playerLevel < levelLimit then
- return
- end
- ---检测重置
- GoldTask.TryResetTaskRecord(actor)
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- if taskInfo.firstopen or table.isNullOrEmpty(taskInfo.nowtaskpool) then
- GoldTask.FirstFlushTaskPool(actor, playerLevel, taskInfo)
- end
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- --jprint(taskInfo)
- end
- ---首次打开任务池
- function GoldTask.FirstFlushTaskPool(actor, playerLevel, taskInfo)
- local taskCfgList = ConfigDataManager.getList("cfg_task_gold")
- local taskList = GoldTask.RandomTask(actor, playerLevel, taskCfgList)
- if not taskList or #taskList == 0 then
- print("刷新数据异常, playerLevel: ", tostring(playerLevel), "配置空")
- return
- end
- taskInfo.nowtaskpool = GoldTask.BuildNewTaskPool(actor, taskList, false, taskInfo.firstopen)
- taskInfo.flushcount = 1
- taskInfo.firstopen = false
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- end
- ---重置任务信息
- function GoldTask.TryResetTaskRecord(actor)
- local nowTime = tonumber((getbaseinfo("nowsec")))
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local lastResetTime = 0
- if taskInfo.lastresettime ~= nil and #taskInfo.lastresettime > 0 then
- lastResetTime = tonumber(taskInfo.lastresettime)
- end
- local sameDay = TimeUtil.isSameDay(lastResetTime, nowTime)
- if sameDay then
- return
- end
- local firstOpen = taskInfo.firstopen
- taskInfo = this.GetNewGoldTask()
- if not firstOpen then
- taskInfo.firstopen = false
- end
- taskInfo.lastresettime = tostring(nowTime)
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- end
- function GoldTask.GetTaskId(msgData)
- if type(msgData) == "number" then
- return msgData
- end
- if msgData == nil or #msgData <= 2 then
- return 0
- end
- --移除首尾
- local taskId = string.sub(msgData, 2, -2)
- return tonumber(taskId)
- end
- ---完成任务GM
- function finishgoldtasktest(actor)
- local taskInfo = GoldTask.GetPayerTaskInfo(actor)
- local myTask = taskInfo.nowtask
- if not myTask or myTask == nil then
- return
- end
- local taskCfgList = ConfigDataManager.getTable("cfg_task_gold", "id", myTask.taskid)
- if table.isNullOrEmpty(taskCfgList) then
- return
- end
- local taskCfg = taskCfgList[1]
- if myTask.status > GoldTask.Const.TASK_STATUS.ACCEPT then
- return
- end
- local taskGoalNum = string.split(taskCfg["taskgoalnum"], "#")
- local needNum = tonumber(taskGoalNum[myTask.star])
- myTask.progress = needNum
- myTask.status = GoldTask.Const.TASK_STATUS.FINISH
- setplaydef(actor, GoldTask.Var.GOLD_TASK_INFO, taskInfo)
- --通知客户端
- sendluamsg(actor, LuaMessageIdToClient.RES_GOLD_TASK_INFO, taskInfo)
- end
|