GoldFirstKill_1.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. GoldFirstKill = {}
  2. local this = {}
  3. GoldFirstKill.Var = {
  4. GOLD_FIRST_KILL_TASK = "T$goldfirstkilltask", -- 个人首杀任务
  5. GOLD_FIRST_KILL_ENVELOPE = "T$firstkillenvelope", -- 全服首杀红包
  6. SERVER_FIRST_KILL_GOLD_BOSS = "R$serverfirstkillgoldboss" -- 全服首杀
  7. }
  8. ---任务状态
  9. GoldFirstKill.TASK_STATUS = {
  10. ---已接取
  11. ACCEPT = 1,
  12. ---已完成
  13. FINISH = 2,
  14. ---已提交
  15. SUBMIT = 3
  16. }
  17. -- 请求领取首杀红包
  18. function GoldFirstKill.receiveFirstKillAward(actor, msgData)
  19. -- if not GoldFirstKill.tableOpen(actor) then
  20. -- tipinfo(actor, "活动未开启")
  21. -- return
  22. -- end
  23. -- local monsterId = msgData.monsterId
  24. -- local envelope = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_ENVELOPE) or {}
  25. -- local isReceive = envelope[tostring(monsterId)]
  26. -- if isReceive then
  27. -- sendluamsg(actor, LuaMessageIdToClient.TIPS, "请勿重复领取!")
  28. -- return
  29. -- end
  30. -- if not isReceive then
  31. -- envelope[tostring(monsterId)] = true
  32. -- setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_ENVELOPE, envelope)
  33. -- -- 发奖励
  34. -- local config = ConfigDataManager.getTable("cfg_goldFirstKill", "id", monsterId)
  35. -- if not config then
  36. -- return
  37. -- end
  38. -- local weight = string.split(config[1].redenvelopeweight, "#")
  39. -- local map = {}
  40. -- for k, v in pairs(weight) do
  41. -- map[k] = tonumber(v)
  42. -- end
  43. -- local index = math.weightedRandom(map)
  44. -- local redEnvelope = string.split(config[1].redenvelope, "|")[tonumber(index)]
  45. -- local reward = splitbyshuxianandjinghao2(redEnvelope)
  46. -- for itemCfgId, count in pairs(reward) do
  47. -- additemtobag(actor, itemCfgId, count, 0, 9999, '黄金首杀')
  48. -- end
  49. -- -- 奖励弹框
  50. -- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, reward)
  51. -- -- 通知客户端
  52. -- sendluamsg(actor, LuaMessageIdToClient.RES_RECEIVE_FIRST_KILL_ENVELOPE, table.valueConvertToString(envelope))
  53. -- end
  54. end
  55. -- 根据权重进行随机
  56. function math.weightedRandom(weights)
  57. local total = 0
  58. for _, weight in pairs(weights) do
  59. total = total + weight
  60. end
  61. local rand = math.random() * total
  62. local cumulative = 0
  63. for item, weight in pairs(weights) do
  64. cumulative = cumulative + weight
  65. if cumulative >= rand then
  66. return item
  67. end
  68. end
  69. end
  70. -- 请求获取全服首杀数据和红包数据
  71. function GoldFirstKill.getFirstKillInfo(actor)
  72. if not GoldFirstKill.tableOpen(actor) then
  73. return
  74. end
  75. local allServerData = getsysvar(GoldFirstKill.Var.SERVER_FIRST_KILL_GOLD_BOSS) or {}
  76. local envelope = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_ENVELOPE) or {}
  77. local taskInfo = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK) or {}
  78. local taskStatus = {}
  79. for mId, v in pairs(taskInfo) do
  80. taskStatus[mId] = v.status
  81. end
  82. local result = {}
  83. result.allServerData = allServerData
  84. result.envelope = envelope
  85. result.taskInfo = taskStatus
  86. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_SERVER_FIRST_KILL_INFO, table.valueConvertToString(result))
  87. end
  88. -- 活动是否开启
  89. function GoldFirstKill.isActivityOpen(actor)
  90. local config = ConfigDataManager.getTable("sub_mainActivity", "id", 1)
  91. if config == nil then
  92. return false
  93. end
  94. return ConditionManager.Check(actor, config[1].actualcondition)
  95. end
  96. -- 页签是否开启
  97. function GoldFirstKill.tableOpen(actor)
  98. local config = ConfigDataManager.getTable("sub_mainActivity", "id", 1)
  99. if config == nil then
  100. return false
  101. end
  102. return ConditionManager.Check(actor, config[1].showcondition)
  103. end
  104. -- 登录时尝试接取任务
  105. function GoldFirstKill.login(actor)
  106. GoldFirstKill.AcceptTask(actor)
  107. end
  108. ---接取任务
  109. function GoldFirstKill.AcceptTask(actor)
  110. -- 活动是否开启
  111. if not GoldFirstKill.isActivityOpen(actor) then
  112. return
  113. end
  114. local taskInfo = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK)
  115. if taskInfo ~= nil then
  116. -- 通知客户端
  117. local result = {}
  118. for mId, v in pairs(taskInfo) do
  119. result[mId] = v.status
  120. end
  121. sendluamsg(actor, LuaMessageIdToClient.RES_GOAL_FIRST_KILL_CHANGE, table.valueConvertToString(result))
  122. return
  123. end
  124. taskInfo = {}
  125. local config = ConfigDataManager.getTable("cfg_goldFirstKill")
  126. if not config then
  127. return
  128. end
  129. -- 接取任务
  130. for i = 1, #config, 1 do
  131. local cfg = config[i]
  132. local monsterId = cfg.id
  133. local taskId = cfg.taskid
  134. -- local targetId = ConfigDataManager.getTableValue("cfg_task","taskTargetId","id",taskId)
  135. local targetCfg = ConfigDataManager.getTable("cfg_task_target", "id", taskId)
  136. if targetCfg ~= nil then
  137. local task = {}
  138. task.taskGoalId = targetCfg[1].taskgoalparam
  139. task.goalCount = targetCfg[1].goalcount
  140. task.nowCount = 0
  141. task.status = GoldFirstKill.TASK_STATUS.ACCEPT
  142. taskInfo[monsterId] = task
  143. end
  144. end
  145. setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK, taskInfo)
  146. local result = {}
  147. for mId, v in pairs(taskInfo) do
  148. result[mId] = v.status
  149. end
  150. result = table.valueConvertToString(result)
  151. -- 通知客户端
  152. sendluamsg(actor, LuaMessageIdToClient.RES_GOAL_FIRST_KILL_CHANGE, result)
  153. end
  154. function GoldFirstKill.UpdateTaskProgress(actor, monsterId)
  155. local success, errorInfo = xpcall(this.UpdateTaskProgress, debug.traceback, actor, monsterId)
  156. gameDebug.assertPrint(success, "怪物死亡黄金任务更新进度异常:", actor, monsterId, errorInfo)
  157. end
  158. ---更新任务进度
  159. function this.UpdateTaskProgress(actor, monsterId)
  160. if actor == nil then
  161. return
  162. end
  163. -- 活动是否开启
  164. if not GoldFirstKill.isActivityOpen(actor) then
  165. return
  166. end
  167. local taskInfo = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK)
  168. if not taskInfo then
  169. return
  170. end
  171. local task = taskInfo[tostring(monsterId)]
  172. if not task then
  173. return
  174. end
  175. if task.status ~= GoldFirstKill.TASK_STATUS.ACCEPT then
  176. return
  177. end
  178. if tonumber(task.taskGoalId) ~= tonumber(monsterId) then
  179. return
  180. end
  181. task.nowCount = task.nowCount + 1
  182. if task.nowCount >= tonumber(task.goalCount) then
  183. task.status = GoldFirstKill.TASK_STATUS.FINISH
  184. end
  185. taskInfo[tostring(monsterId)] = task
  186. setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK, taskInfo)
  187. -- 更新全服黄金首杀数据
  188. callonserial(actor, "update_gold_first_kill_data", monsterId)
  189. -- 通知客户端
  190. local result = {}
  191. for mId, v in pairs(taskInfo) do
  192. result[mId] = v.status
  193. end
  194. sendluamsg(actor, LuaMessageIdToClient.RES_GOAL_FIRST_KILL_CHANGE, table.valueConvertToString(result))
  195. end
  196. function update_gold_first_kill_data(actor, monsterId)
  197. -- 更新全服黄金首杀数据
  198. -- local allServerData = getsysvar(GoldFirstKill.Var.SERVER_FIRST_KILL_GOLD_BOSS)
  199. -- if allServerData == nil or allServerData == "" then
  200. -- allServerData = {}
  201. -- end
  202. -- local killInfo = allServerData[tostring(monsterId)]
  203. -- if not killInfo then
  204. -- killInfo = {}
  205. -- killInfo.killer = getbaseinfo(actor, "rid")
  206. -- killInfo.killerName = getbaseinfo(actor, "rolename")
  207. -- killInfo.killTime = getbaseinfo("now")
  208. -- allServerData[tostring(monsterId)] = killInfo
  209. -- setsysvar(GoldFirstKill.Var.SERVER_FIRST_KILL_GOLD_BOSS, allServerData)
  210. -- local config = ConfigDataManager.getTable("cfg_goldFirstKill", "id", monsterId)
  211. -- if config ~= nil then
  212. -- local itemMap = string.toIntIntMap(config[1].serreward)
  213. -- local monsterCfg = ConfigDataManager.getTable("cfg_monster", "id", monsterId)
  214. -- local name = monsterCfg[1].name
  215. -- sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), MailConfig.SERVER_FIRST_KILL_GOLD_BOSS, itemMap, name)
  216. -- noticeTip.noticeinfo(actor, StringIdConst.ALL_SERVER_FIRST_KILL, getbaseinfo(actor, "rolename"), name)
  217. -- end
  218. -- end
  219. end
  220. ---提交任务
  221. function GoldFirstKill.SubmitTask(actor, msgData)
  222. -- if not GoldFirstKill.tableOpen(actor) then
  223. -- tipinfo(actor, "活动未开启")
  224. -- return
  225. -- end
  226. -- local monsterId = msgData.monsterId
  227. -- local taskInfo = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK)
  228. -- if not taskInfo then
  229. -- tipinfo(actor, "任务未接取")
  230. -- return
  231. -- end
  232. -- local task = taskInfo[tostring(monsterId)]
  233. -- if not task then
  234. -- tipinfo(actor, "任务不存在")
  235. -- return
  236. -- end
  237. -- if tonumber(task.status) ~= GoldFirstKill.TASK_STATUS.FINISH then
  238. -- tipinfo(actor, "任务未完成")
  239. -- return
  240. -- end
  241. -- -- 修改任务状态
  242. -- task.status = GoldFirstKill.TASK_STATUS.SUBMIT
  243. -- taskInfo[tostring(monsterId)] = task
  244. -- setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK, taskInfo)
  245. -- -- 发奖励
  246. -- local reward = GoldFirstKill.GetTaskReward(monsterId)
  247. -- for itemCfgId, count in pairs(reward) do
  248. -- additemtobag(actor, itemCfgId, count, 0, 9999, '黄金首杀')
  249. -- end
  250. -- -- 奖励弹框
  251. -- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, reward)
  252. -- -- 通知客户端
  253. -- local ti = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK)
  254. -- local result = {}
  255. -- for mId, v in pairs(ti) do
  256. -- result[mId] = v.status
  257. -- end
  258. -- sendluamsg(actor, LuaMessageIdToClient.RES_RECEIVE_PERSONAL_FIRST_KILL_AWARD, table.valueConvertToString(result))
  259. end
  260. -- 获取任务奖励
  261. function GoldFirstKill.GetTaskReward(monsterId)
  262. local reward = {}
  263. local config = ConfigDataManager.getTable("cfg_goldFirstKill", "id", monsterId)
  264. if not config then
  265. return reward
  266. end
  267. return string.toIntIntMap(config[1].perreward)
  268. end
  269. -- 全服奖励
  270. function GoldFirstKill.endTimeReward()
  271. -- local allData = getsysvar(GoldFirstKill.Var.SERVER_FIRST_KILL_GOLD_BOSS)
  272. -- if allData == nil or allData == "" then
  273. -- return
  274. -- end
  275. -- local allRoleInfos = getallrolesummaryinfos()
  276. -- if allRoleInfos == nil or next(allRoleInfos) == nil then
  277. -- return
  278. -- end
  279. -- for _, roleInfo in pairs(allRoleInfos) do
  280. -- local reward = {}
  281. -- local actor = roleInfo["actor"]
  282. -- if GoldFirstKill.tableOpen(actor) then
  283. -- return
  284. -- end
  285. -- -- 全服首杀红包奖励
  286. -- local envelope = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_ENVELOPE) or {}
  287. -- for monsterId, v in pairs(envelope) do
  288. -- if not v then
  289. -- local config = ConfigDataManager.getTable("cfg_goldFirstKill", "id", monsterId)
  290. -- if not config then
  291. -- return
  292. -- end
  293. -- local weight = string.split(config[1].redenvelopeweight, "#")
  294. -- local map = {}
  295. -- for k, value in pairs(weight) do
  296. -- map[k] = tonumber(value)
  297. -- end
  298. -- local index = math.weightedRandom(map)
  299. -- local redEnvelope = string.split(config[1].redenvelope, "|")[tonumber(index)]
  300. -- string.putIntIntMap(reward, redEnvelope)
  301. -- end
  302. -- end
  303. -- -- 怪物个人首杀奖励
  304. -- local taskInfo = getplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK)
  305. -- if taskInfo == nil or taskInfo == "" then
  306. -- taskInfo = {}
  307. -- end
  308. -- for monsterId, v in pairs(taskInfo) do
  309. -- if v.status == GoldFirstKill.TASK_STATUS.FINISH then
  310. -- table.mergeAdd(reward, GoldFirstKill.GetTaskReward(monsterId))
  311. -- end
  312. -- end
  313. -- -- 发邮件
  314. -- if table.count(reward) > 0 then
  315. -- sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), MailConfig.END_TIME_GOLD_BOSS_REWARD, reward, "")
  316. -- end
  317. -- setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_ENVELOPE, nil)
  318. -- setplaydef(actor, GoldFirstKill.Var.GOLD_FIRST_KILL_TASK, nil)
  319. -- end
  320. -- setsysvar(GoldFirstKill.Var.SERVER_FIRST_KILL_GOLD_BOSS, nil)
  321. end