BossBounty.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by zhangkai.
  4. --- DateTime: 2024/9/2 上午10:54
  5. ---
  6. BossBounty = {}
  7. local this = {}
  8. local BountyInfo = "T$bossbountydata"
  9. ---未领取
  10. local NOT_RECEIVE = 1;
  11. ---已领取奖励
  12. local RECEIVED = 2;
  13. function bossbountytest(actor,msgID,msgData)
  14. handlerequest(actor, 0,tonumber(msgID), msgData)
  15. end
  16. function this.GetNewBountyData()
  17. ---悬赏数据,
  18. local BossBountyData = {
  19. ---层级领奖数据
  20. group = {},
  21. ---怪物领奖数据
  22. monster = {}
  23. }
  24. return BossBountyData
  25. end
  26. function this.SaveBountyData(actor,bountyData)
  27. setplaydef(actor,BountyInfo,bountyData)
  28. end
  29. function this.GetBountyData(actor)
  30. local bountyData = getplaydef(actor,BountyInfo)
  31. if bountyData == nil then
  32. bountyData = this.GetNewBountyData()
  33. end
  34. return bountyData
  35. end
  36. ---获取悬赏分组
  37. function this.GetBountyGroup(monsterCfgId)
  38. return ConfigDataManager.getTableValue("cfg_newarea_offerreward", "group","monsterid", monsterCfgId)
  39. end
  40. function BossBounty.KillMonster(actor,monsterCfgId)
  41. local success, errorInfo = xpcall(this.KillMonster, debug.traceback, actor,monsterCfgId)
  42. gameDebug.assertPrint(success, "怪物死亡Boss悬赏更新异常:", actor,monsterCfgId, errorInfo)
  43. end
  44. ---击杀怪物
  45. function this.KillMonster(actor,monsterCfgId)
  46. if actor == nil then
  47. return
  48. end
  49. local group = this.GetBountyGroup(monsterCfgId)
  50. if group == nil or string.isNullOrEmpty(group) then
  51. return
  52. end
  53. local bountyData = this.GetBountyData(actor)
  54. local monsterInfo = bountyData.monster
  55. local bountyStatus = monsterInfo[monsterCfgId]
  56. if bountyStatus ~= nil then
  57. return
  58. end
  59. monsterInfo[monsterCfgId] = NOT_RECEIVE
  60. bountyData.monster = monsterInfo
  61. this.SaveBountyData(actor,bountyData)
  62. this.SendChangeMsg(actor,monsterCfgId,NOT_RECEIVE)
  63. end
  64. function BossBounty.GetBountyInfo(actor)
  65. local bountyData = this.GetBountyData(actor)
  66. --jprint("悬赏数据",actor,bountyData)
  67. sendluamsg(actor, LuaMessageIdToClient.RES_BOSS_BOUNTY_DATA, bountyData)
  68. end
  69. ---请求领取怪物奖励
  70. function BossBounty.ReqReceiveMonsterAward(actor, msgData)
  71. jprint("请求领取怪物奖励",msgData)
  72. local monsterCfgId = this.GetMsgData(msgData)
  73. local bountyData = this.GetBountyData(actor)
  74. local monsterInfo = bountyData.monster
  75. local bountyStatus = monsterInfo[monsterCfgId]
  76. if bountyStatus == nil then
  77. noticeTip.noticeinfo(actor, StringIdConst.TEXT337)
  78. return
  79. end
  80. if bountyStatus == RECEIVED then
  81. noticeTip.noticeinfo(actor, StringIdConst.TEXT338)
  82. return
  83. end
  84. local rewardCfg = ConfigDataManager.getTableValue("cfg_newarea_offerreward", "reward","monsterid", monsterCfgId)
  85. this.SendReward(actor,rewardCfg)
  86. --更新状态
  87. monsterInfo[monsterCfgId] = RECEIVED
  88. bountyData.monster = monsterInfo
  89. this.SaveBountyData(actor,bountyData)
  90. this.SendChangeMsg(actor,monsterCfgId,RECEIVED)
  91. end
  92. ---请求领取分组奖励
  93. function BossBounty.ReqReceiveGroupAward(actor, msgData)
  94. jprint("请求领取分组奖励",msgData)
  95. local group = this.GetMsgData(msgData)
  96. local bountyData = this.GetBountyData(actor)
  97. local groupInfo = bountyData.group
  98. local monsterInfo = bountyData.monster
  99. if array.contains(groupInfo,group) then
  100. tipinfo(actor,"已领取")
  101. return
  102. end
  103. local groupMonster = ConfigDataManager.getTable("cfg_newarea_offerreward","group", group)
  104. if table.isNullOrEmpty(groupMonster) then
  105. noticeTip.noticeinfo(actor, StringIdConst.TEXT339)
  106. return
  107. end
  108. --jprint("杀怪列表:",monsterInfo)
  109. for _, bountyCfg in pairs(groupMonster) do
  110. local monsterCfgId = tonumber(bountyCfg["monsterid"])
  111. local bountyStatus = monsterInfo[monsterCfgId]
  112. if bountyStatus == nil or bountyStatus ~= RECEIVED then
  113. noticeTip.noticeinfo(actor, StringIdConst.TEXT340)
  114. return
  115. end
  116. end
  117. local rewardList = ConfigDataManager.getTableValue("cfg_newarea_offerreward", "groupreward","group", group)
  118. if string.isNullOrEmpty(rewardList) then
  119. return
  120. end
  121. this.SendReward(actor,rewardList)
  122. table.insert(groupInfo,group)
  123. bountyData.group = groupInfo
  124. this.SaveBountyData(actor,bountyData)
  125. sendluamsg(actor, LuaMessageIdToClient.RES_BOSS_BOUNTY_DATA, bountyData)
  126. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.BOSS_BOUNTY, group)
  127. end
  128. --发放奖励
  129. function this.SendReward(actor,rewardCfg)
  130. if string.isNullOrEmpty(rewardCfg) then
  131. --error("奖励未配置")
  132. return
  133. end
  134. local awardMap = {}
  135. local itemArray = string.split(rewardCfg, "|")
  136. for _, param in pairs(itemArray) do
  137. local cfgArray = string.split(param, "#")
  138. local itemId = tonumber(cfgArray[1])
  139. local itemNum = tonumber(cfgArray[2])
  140. awardMap[itemId] = itemNum
  141. local itemBind = ConfigDataManager.getTableValue("cfg_bind","bind","id",15)
  142. --奖励入包
  143. additemtobag(actor, itemId, itemNum,itemBind,9999,'boss悬赏')
  144. end
  145. --奖励弹框
  146. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, awardMap)
  147. end
  148. function this.SendChangeMsg(actor,monsterCfg,status)
  149. local dataChange = {
  150. monsterId = monsterCfg,
  151. status = status
  152. }
  153. sendluamsg(actor, LuaMessageIdToClient.BOSS_BOUNTY_CHANGE, dataChange)
  154. end
  155. function this.GetMsgData(msgData)
  156. if table.isNullOrEmpty(msgData) then
  157. return 0
  158. end
  159. local id = msgData["id"]
  160. return tonumber(id)
  161. end