--- --- 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