123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by zhangkai.
- --- DateTime: 2024/9/2 上午10:54
- ---
- BossBounty = {}
- local this = {}
- local BountyInfo = "T$bossbountydata"
- ---未领取
- local NOT_RECEIVE = 1;
- ---已领取奖励
- local RECEIVED = 2;
- function bossbountytest(actor,msgID,msgData)
- handlerequest(actor, 0,tonumber(msgID), msgData)
- end
- function this.GetNewBountyData()
- ---悬赏数据,
- local BossBountyData = {
- ---层级领奖数据
- group = {},
- ---怪物领奖数据
- monster = {}
- }
- return BossBountyData
- end
- function this.SaveBountyData(actor,bountyData)
- setplaydef(actor,BountyInfo,bountyData)
- end
- function this.GetBountyData(actor)
- local bountyData = getplaydef(actor,BountyInfo)
- if bountyData == nil then
- bountyData = this.GetNewBountyData()
- end
- return bountyData
- end
- ---获取悬赏分组
- function this.GetBountyGroup(monsterCfgId)
- return ConfigDataManager.getTableValue("cfg_newarea_offerreward", "group","monsterid", monsterCfgId)
- end
- function BossBounty.KillMonster(actor,monsterCfgId)
- local success, errorInfo = xpcall(this.KillMonster, debug.traceback, actor,monsterCfgId)
- gameDebug.assertPrint(success, "怪物死亡Boss悬赏更新异常:", actor,monsterCfgId, errorInfo)
- end
- ---击杀怪物
- function this.KillMonster(actor,monsterCfgId)
- if actor == nil then
- return
- end
- local group = this.GetBountyGroup(monsterCfgId)
- if group == nil or string.isNullOrEmpty(group) then
- return
- end
- local bountyData = this.GetBountyData(actor)
- local monsterInfo = bountyData.monster
- local bountyStatus = monsterInfo[monsterCfgId]
- if bountyStatus ~= nil then
- return
- end
- monsterInfo[monsterCfgId] = NOT_RECEIVE
- bountyData.monster = monsterInfo
- this.SaveBountyData(actor,bountyData)
- this.SendChangeMsg(actor,monsterCfgId,NOT_RECEIVE)
- end
- function BossBounty.GetBountyInfo(actor)
- local bountyData = this.GetBountyData(actor)
- --jprint("悬赏数据",actor,bountyData)
- sendluamsg(actor, LuaMessageIdToClient.RES_BOSS_BOUNTY_DATA, bountyData)
- end
- ---请求领取怪物奖励
- function BossBounty.ReqReceiveMonsterAward(actor, msgData)
- jprint("请求领取怪物奖励",msgData)
- local monsterCfgId = this.GetMsgData(msgData)
- local bountyData = this.GetBountyData(actor)
- local monsterInfo = bountyData.monster
- local bountyStatus = monsterInfo[monsterCfgId]
- if bountyStatus == nil then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT337)
- return
- end
- if bountyStatus == RECEIVED then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT338)
- return
- end
- local rewardCfg = ConfigDataManager.getTableValue("cfg_newarea_offerreward", "reward","monsterid", monsterCfgId)
- this.SendReward(actor,rewardCfg)
- --更新状态
- monsterInfo[monsterCfgId] = RECEIVED
- bountyData.monster = monsterInfo
- this.SaveBountyData(actor,bountyData)
- this.SendChangeMsg(actor,monsterCfgId,RECEIVED)
- end
- ---请求领取分组奖励
- function BossBounty.ReqReceiveGroupAward(actor, msgData)
- jprint("请求领取分组奖励",msgData)
- local group = this.GetMsgData(msgData)
- local bountyData = this.GetBountyData(actor)
- local groupInfo = bountyData.group
- local monsterInfo = bountyData.monster
- if array.contains(groupInfo,group) then
- tipinfo(actor,"已领取")
- return
- end
- local groupMonster = ConfigDataManager.getTable("cfg_newarea_offerreward","group", group)
- if table.isNullOrEmpty(groupMonster) then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT339)
- return
- end
- --jprint("杀怪列表:",monsterInfo)
- for _, bountyCfg in pairs(groupMonster) do
- local monsterCfgId = tonumber(bountyCfg["monsterid"])
- local bountyStatus = monsterInfo[monsterCfgId]
- if bountyStatus == nil or bountyStatus ~= RECEIVED then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT340)
- return
- end
- end
- local rewardList = ConfigDataManager.getTableValue("cfg_newarea_offerreward", "groupreward","group", group)
- if string.isNullOrEmpty(rewardList) then
- return
- end
- this.SendReward(actor,rewardList)
- table.insert(groupInfo,group)
- bountyData.group = groupInfo
- this.SaveBountyData(actor,bountyData)
- sendluamsg(actor, LuaMessageIdToClient.RES_BOSS_BOUNTY_DATA, bountyData)
- TaskHandler.TriggerTaskGoal(actor, TaskTargetType.BOSS_BOUNTY, group)
- end
- --发放奖励
- function this.SendReward(actor,rewardCfg)
- if string.isNullOrEmpty(rewardCfg) then
- --error("奖励未配置")
- return
- end
- local awardMap = {}
- local itemArray = string.split(rewardCfg, "|")
- for _, param in pairs(itemArray) do
- local cfgArray = string.split(param, "#")
- local itemId = tonumber(cfgArray[1])
- local itemNum = tonumber(cfgArray[2])
- awardMap[itemId] = itemNum
- local itemBind = ConfigDataManager.getTableValue("cfg_bind","bind","id",15)
- --奖励入包
- additemtobag(actor, itemId, itemNum,itemBind,9999,'boss悬赏')
- end
- --奖励弹框
- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, awardMap)
- end
- function this.SendChangeMsg(actor,monsterCfg,status)
- local dataChange = {
- monsterId = monsterCfg,
- status = status
- }
- sendluamsg(actor, LuaMessageIdToClient.BOSS_BOUNTY_CHANGE, dataChange)
- end
- function this.GetMsgData(msgData)
- if table.isNullOrEmpty(msgData) then
- return 0
- end
- local id = msgData["id"]
- return tonumber(id)
- end
|