OpenServerNewActivity.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. OpenServerNewAct = {}
  2. local this = {}
  3. ---全服首杀数据
  4. local GLOBAL_OPENSERVERNEW_INFO = "R$global_openservernew_info"
  5. ---开服活动常量
  6. local Const = {
  7. AwardType = {
  8. ---无
  9. NONE = 0,
  10. ---集字
  11. COLLECT_WORD = 1,
  12. ---冲级
  13. LEVEL_UP = 2,
  14. ---一代翅膀
  15. WING_ONE = 3,
  16. ---二代翅膀
  17. WING_TWO = 4,
  18. ---三代翅膀
  19. WING_THREE = 5,
  20. ---大天使武器
  21. ANGLE_WEAPON = 6,
  22. },
  23. }
  24. function OpenServerNewAct.IsDataKey(varName)
  25. if string.equalsIgnoreCase(varName,GLOBAL_OPENSERVERNEW_INFO) then
  26. return true
  27. else
  28. return false
  29. end
  30. end
  31. ---合服事件触发
  32. function OpenServerNewAct.Combine(varName)
  33. --清空全服数据
  34. this.SaveGlobalFirstKill(nil)
  35. this.SaveGlobalRankInfo(nil)
  36. end
  37. --活动是否结束
  38. function this.IsEnd(type)
  39. local openDay = tonumber(getserveropendays())
  40. if type == Const.AwardType.COLLECT_WORD then
  41. return openDay > 30
  42. end
  43. return false
  44. end
  45. ---活动页面是否关闭
  46. function this.IsClose(type)
  47. local openDay = tonumber(getserveropendays())
  48. if type == Const.AwardType.COLLECT_WORD then
  49. return openDay > 30
  50. end
  51. return false
  52. end
  53. ---[[
  54. --- 开服数据结构
  55. --- {type : Const.AwardType,
  56. --- record : table {
  57. --- rank : 1,
  58. --- rid : 1,
  59. --- }
  60. --- }
  61. ---]]
  62. ---获取开服活动数据
  63. function this.GetGlobalOpenServerData(type)
  64. local globalOpenServerInfo = getsysvar(GLOBAL_OPENSERVERNEW_INFO)
  65. if globalOpenServerInfo == nil then
  66. globalOpenServerInfo = {}
  67. end
  68. -- 如果type为NONE则返回所有数据
  69. if type == Const.AwardType.NONE then
  70. return globalOpenServerInfo
  71. end
  72. -- 如果type不为NONE则返回对应数据
  73. if globalOpenServerInfo[type] == nil then
  74. globalOpenServerInfo[type] = {}
  75. end
  76. return globalOpenServerInfo[type]
  77. end
  78. ---保存开服活动数据
  79. function this.SaveGlobalOpenServerData(type, globalOpenServerInfo)
  80. local golbalOpenServerAllInfo = this.GetGlobalOpenServerData(Const.AwardType.NONE)
  81. golbalOpenServerAllInfo[type] = globalOpenServerInfo
  82. setsysvar(GLOBAL_OPENSERVERNEW_INFO, golbalOpenServerAllInfo)
  83. end
  84. ---构建活动数据回包
  85. function OpenServerNewAct.SendActivityInfo(actor, msgData)
  86. this.SendActivityInfo(actor)
  87. end
  88. ---构建活动数据回包
  89. function this.SendActivityInfo(actor)
  90. -- setsysvar(GLOBAL_OPENSERVERNEW_INFO, {})
  91. local globalOpenServerInfo = this.GetGlobalOpenServerData(Const.AwardType.NONE)
  92. sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_INFO, globalOpenServerInfo)
  93. end
  94. ---构建子活动记录
  95. function OpenServerNewAct.SendActivitySubRecord(actor, msgData)
  96. this.SendActivitySubRecord(actor, msgData)
  97. end
  98. ---构建子活动记录
  99. function this.SendActivitySubRecord(actor, msgData)
  100. local activityType = tonumber(msgData["activityType"])
  101. local globalOpenServerInfo = this.GetGlobalOpenServerData(activityType)
  102. if globalOpenServerInfo.record == nil then
  103. globalOpenServerInfo.record = {}
  104. end
  105. local listRecord = {}
  106. if activityType == Const.AwardType.COLLECT_WORD then
  107. for i = 1, 10 do
  108. local recordData = globalOpenServerInfo.record[i] or {}
  109. for _, data in ipairs(recordData) do
  110. local rid = tonumber(data.rid)
  111. local actor = getactor(rid)
  112. local rank = tonumber(data.rank)
  113. local name = getbaseinfo(actor, "rolename")
  114. local careerbase = getbaseinfo(actor, "getbasecareer")
  115. local careerrank = getbaseinfo(actor, "getcareerrank")
  116. local rewardType = i
  117. table.insert(listRecord, {rid = rid, rank = rank, name = name, careerbase = careerbase, careerrank = careerrank, rewardType = rewardType})
  118. end
  119. end
  120. else
  121. for _, data in ipairs(globalOpenServerInfo.record) do
  122. local rid = tonumber(data.rid)
  123. local actor = getactor(rid)
  124. local rank = tonumber(data.rank)
  125. local name = getbaseinfo(actor, "rolename")
  126. local careerbase = getbaseinfo(actor, "getbasecareer")
  127. local careerrank = getbaseinfo(actor, "getcareerrank")
  128. table.insert(listRecord, {rid = rid, rank = rank, name = name, careerbase = careerbase, careerrank = careerrank})
  129. end
  130. end
  131. sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_RECORD, listRecord)
  132. end
  133. -- 获取对应活动可领取奖励总数
  134. function this.GetActivityRewardTotalNum(activityType, listConfig)
  135. local totalNum = 0
  136. for _, v in pairs(listConfig) do
  137. local numParam = v.numparam
  138. if activityType == Const.AwardType.COLLECT_WORD or
  139. activityType == Const.AwardType.ANGLE_WEAPON then
  140. totalNum = totalNum + tonumber(numParam)
  141. else
  142. local numArr = string.split(numParam, "#")
  143. local numLower = tonumber(numArr[1])
  144. local numUpper = tonumber(numArr[2])
  145. totalNum = totalNum + numUpper - numLower + 1
  146. end
  147. end
  148. return totalNum
  149. end
  150. ---领取奖励
  151. function OpenServerNewAct.ReceiveReward(actor, msgData)
  152. this.ReceiveAward(actor, msgData)
  153. end
  154. ---领取奖励
  155. function this.ReceiveAward(actor, msgData)
  156. -- jprint("玩家请求领取开服冲榜奖励",actor,msgData)
  157. local activityType = tonumber(msgData["activityType"])
  158. local activitySubType = tonumber(msgData["activitySubType"])
  159. local activityData = this.GetGlobalOpenServerData(activityType)
  160. if this.IsEnd(activityType) then
  161. tipinfo(actor, "活动已结束")
  162. return
  163. end
  164. ---@type cfg_OpenServer_column[]
  165. local listConfig = {}
  166. local configTable = ConfigDataManager.getList("cfg_OpenServer")
  167. for i = 1, #configTable do
  168. ---@type cfg_OpenServer_column
  169. local config = configTable[i]
  170. if tonumber(config.maingroup) == activityType then
  171. if activityType ~= Const.AwardType.COLLECT_WORD or tonumber(config.subtype) == activitySubType then
  172. table.insert(listConfig, config)
  173. end
  174. end
  175. end
  176. local totalCount = this.GetActivityRewardTotalNum(activityType, listConfig)
  177. if totalCount <= 0 then
  178. tipinfo(actor,"配置可领取数量不足")
  179. return
  180. elseif activityType == Const.AwardType.COLLECT_WORD then
  181. local configCollectWord = listConfig[1]
  182. if configCollectWord == nil then
  183. print("OpenServerNewActivity.ReceiveAward configCollectWord is nil, listConfig:", listConfig)
  184. return
  185. end
  186. if activityData.record == nil then
  187. activityData.record = {}
  188. end
  189. if activityData.record[activitySubType] == nil then
  190. activityData.record[activitySubType] = {}
  191. end
  192. -- 可领取数量不足
  193. local hasRewardNum = #activityData.record[activitySubType]
  194. if tonumber(configCollectWord.numparam) <= hasRewardNum then
  195. tipinfo(actor,"可领取数量不足")
  196. -- 发送活动数据刷新显示
  197. this.SendActivityInfo(actor)
  198. return
  199. end
  200. -- 解析配置表,获取所需的物品
  201. local itemsNeedArr = string.split(configCollectWord.needitem, "|")
  202. local itemsNeed = {}
  203. for _, itemData in pairs(itemsNeedArr) do
  204. local itemAttr = string.split(itemData, "#")
  205. local itemNeed = {itemId = tonumber(itemAttr[1]), num = tonumber(itemAttr[2])}
  206. table.insert(itemsNeed, itemNeed)
  207. end
  208. -- print("OpenServerNewActivity.ReceiveAward itemsNeed:", itemsNeed)
  209. -- 判断所需道具是否足够
  210. local listItem = getbagdata(actor)
  211. for _, item in pairs(listItem.items) do
  212. for i, itemNeed in ipairs(itemsNeed) do
  213. if tonumber(item.cfgid) == itemNeed.itemId and itemNeed.num > 0 then
  214. if tonumber(item.count) >= itemNeed.num then
  215. itemsNeed[i].num = 0
  216. else
  217. itemsNeed[i].num = itemsNeed[i].num - tonumber(item.count)
  218. end
  219. end
  220. end
  221. end
  222. local hasItem = false
  223. for k, itemNeed in pairs(itemsNeed) do
  224. if itemNeed.num > 0 then
  225. hasItem = true
  226. break
  227. end
  228. end
  229. if hasItem then
  230. -- 所需道具不足
  231. tipinfo(actor,"所需道具不足")
  232. return
  233. end
  234. -- 发送对应活动奖励
  235. if this.SendReward(actor, activityType, activitySubType, activityData, listConfig) then
  236. local recordNum = 0
  237. for i,v in pairs(activityData.record) do
  238. recordNum = recordNum + table.count(v)
  239. end
  240. local recordData = {rank = recordNum + 1, rid = getbaseinfo(actor, "rid")}
  241. table.insert(activityData.record[activitySubType], recordData)
  242. this.SaveGlobalOpenServerData(activityType, activityData)
  243. this.SendActivityInfo(actor)
  244. end
  245. else
  246. if activityData.record == nil then
  247. activityData.record = {}
  248. end
  249. -- 可领取数量不足
  250. if #activityData.record >= totalCount then
  251. tipinfo(actor,"可领取数量不足")
  252. -- 发送活动数据刷新显示
  253. this.SendActivityInfo(actor)
  254. return
  255. end
  256. -- 判断是否已领取过
  257. local rid = getbaseinfo(actor, "rid")
  258. for k, recordData in pairs(activityData.record) do
  259. if tonumber(rid) == tonumber(recordData.rid) then
  260. tipinfo(actor,"您已领取过该活动奖励")
  261. -- 发送活动数据刷新显示
  262. this.SendActivityInfo(actor)
  263. return
  264. end
  265. end
  266. local wingItemId = 0
  267. -- 判断是否符合条件
  268. if activityType == Const.AwardType.LEVEL_UP then
  269. local levelNeed = tonumber(listConfig[1].needitem)
  270. if levelNeed > getbaseinfo(actor, "level") then
  271. -- 目标等级不足
  272. tipinfo(actor,"等级不足"..levelNeed.."级")
  273. return
  274. end
  275. elseif activityType == Const.AwardType.WING_ONE or
  276. activityType == Const.AwardType.WING_TWO or
  277. activityType == Const.AwardType.WING_THREE then
  278. -- 解析配置表,获取所需的翅膀id
  279. local wingIdsNeedArr = string.split(listConfig[1].needitem, "|")
  280. local wingIdsNeed = {}
  281. for _, wingItem in pairs(wingIdsNeedArr) do
  282. local wingItemAttr = string.split(wingItem, "#")
  283. table.insert(wingIdsNeed, tonumber(wingItemAttr[1]))
  284. end
  285. -- 获取当前角色的翅膀id
  286. local hasWing = false
  287. local hasSameWing = false
  288. local listEquip = getallequipinfo(actor)
  289. for _, equipItem in pairs(listEquip) do
  290. local cfgId = tonumber(equipItem.cfgid)
  291. local configEquip = ConfigDataManager.getById("cfg_item", cfgId)
  292. local originid = API.GetItemData(actor, equipItem.id, "originid")
  293. if configEquip ~= nil and tonumber(configEquip.type) == 2 and tonumber(configEquip.subtype) == 13 then
  294. for _, wingId in pairs(wingIdsNeed) do
  295. if tonumber(wingId) == tonumber(configEquip.id) then
  296. local tmpHasSameWing = false
  297. for _,recordData in ipairs(activityData.record) do
  298. print("check wing id, recordData: ", recordData, originid, equipItem.id)
  299. if originid ~= nil and tonumber(recordData.itemId) == tonumber(originid) then
  300. tmpHasSameWing = true
  301. elseif tonumber(recordData.itemId) == tonumber(equipItem.id) then
  302. tmpHasSameWing = true
  303. end
  304. end
  305. if tmpHasSameWing then
  306. hasSameWing = true
  307. else
  308. if originid ~= nil and tonumber(originid) > 0 then
  309. wingItemId = originid
  310. else
  311. wingItemId = equipItem.id
  312. end
  313. hasWing = true
  314. break
  315. end
  316. end
  317. end
  318. if hasWing then
  319. break
  320. end
  321. end
  322. end
  323. if not hasWing then
  324. -- 目标没有所需翅膀
  325. if hasSameWing then
  326. tipinfo(actor,"您拥有的翅膀已领取过奖励")
  327. else
  328. tipinfo(actor,"没有所需翅膀")
  329. end
  330. return
  331. end
  332. elseif activityType == Const.AwardType.ANGLE_WEAPON then
  333. -- 解析配置表,获取所需的大天使武器id
  334. local weaponIdsNeedArr = string.split(listConfig[1].needitem, "|")
  335. local weaponIdsNeed = {}
  336. for _, weaponItem in ipairs(weaponIdsNeedArr) do
  337. local weaponItemAttr = string.split(weaponItem, "#")
  338. table.insert(weaponIdsNeed, tonumber(weaponItemAttr[1]))
  339. end
  340. -- 获取当前角色的大天使武器id
  341. local hasWeapon = false
  342. local listEquip = getallequipinfo(actor)
  343. for _, equipItem in pairs(listEquip) do
  344. local cfgId = tonumber(equipItem.cfgid)
  345. local configEquip = ConfigDataManager.getById("cfg_item", cfgId)
  346. if configEquip ~= nil and tonumber(configEquip.type) == 2 then
  347. for _, weaponId in pairs(weaponIdsNeed) do
  348. if tonumber(weaponId) == tonumber(equipItem.cfgid) then
  349. hasWeapon = true
  350. break
  351. end
  352. end
  353. if hasWeapon then
  354. break
  355. end
  356. end
  357. end
  358. if not hasWeapon then
  359. -- 目标没有所需大天使武器
  360. tipinfo(actor,"没有所需大天使武器")
  361. return
  362. end
  363. end
  364. print("OpenServerNewAct.ReceiveReward SendReward Start")
  365. -- 发送对应活动奖励
  366. if this.SendReward(actor, activityType, activitySubType, activityData, listConfig) then
  367. local recordData = {rank = #activityData.record + 1, rid = getbaseinfo(actor, "rid")}
  368. if wingItemId > 0 then
  369. recordData.itemId = wingItemId
  370. end
  371. table.insert(activityData.record, recordData)
  372. this.SaveGlobalOpenServerData(activityType, activityData)
  373. this.SendActivityInfo(actor)
  374. end
  375. end
  376. end
  377. -- 获取对应活动配置
  378. function this.GetRewardConfig(activityType, activitySubType, activityData, listConfig)
  379. if activityType == Const.AwardType.COLLECT_WORD then
  380. return listConfig[1]
  381. elseif activityType == Const.AwardType.LEVEL_UP or
  382. activityType == Const.AwardType.WING_ONE or
  383. activityType == Const.AwardType.WING_TWO or
  384. activityType == Const.AwardType.WING_THREE then
  385. local rewardNum = #activityData.record + 1
  386. for _, config in ipairs(listConfig) do
  387. local numParam = config.numparam
  388. local numArr = string.split(numParam, "#")
  389. local numUpper = tonumber(numArr[2])
  390. local numLower = tonumber(numArr[1])
  391. rewardNum = rewardNum - numUpper + numLower - 1
  392. if rewardNum <= 0 then
  393. return config
  394. end
  395. end
  396. return nil
  397. elseif activityType == Const.AwardType.ANGLE_WEAPON then
  398. return listConfig[1]
  399. end
  400. return nil
  401. end
  402. -- 发送奖励
  403. function this.SendReward(actor, activityType, activitySubType, activityData, listConfig)
  404. local configReward = this.GetRewardConfig(activityType, activitySubType, activityData, listConfig)
  405. if configReward == nil then
  406. print("[OpenServerNewActivity.SendReward] configReward is nil")
  407. return false
  408. end
  409. local title = "开服活动"
  410. if activityType == Const.AwardType.COLLECT_WORD then
  411. local emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_1
  412. if activitySubType == 1 then
  413. emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_1
  414. elseif activitySubType == 2 then
  415. emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_2
  416. elseif activitySubType == 3 then
  417. emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_3
  418. else
  419. print("[OpenServerNewActivity.SendReward] activitySubType error")
  420. return false
  421. end
  422. -- 解析配置表,移除道具
  423. local itemsNeedArr = string.split(configReward.needitem, "|")
  424. local itemsNeed = {}
  425. for _, itemData in pairs(itemsNeedArr) do
  426. local itemAttr = string.split(itemData, "#")
  427. local itemNeed = {itemId = tonumber(itemAttr[1]), num = tonumber(itemAttr[2])}
  428. table.insert(itemsNeed, itemNeed)
  429. removeitemfrombag(actor, tonumber(itemAttr[1]), tonumber(itemAttr[2]), 0, 9999, "开服集字活动")
  430. end
  431. sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), emailId, {}, "")
  432. else
  433. local rewardArr = string.split(configReward.reward, "|")
  434. local rewardMap = {}
  435. for i = 1, #rewardArr do
  436. local rewardArr2 = string.split(rewardArr[i], "#")
  437. rewardMap[tonumber(rewardArr2[1])] = tonumber(rewardArr2[2])
  438. end
  439. local emailId = MailConfig.ACTIVITY_OPENSERVER_LEVEL_UP
  440. if activityType == Const.AwardType.LEVEL_UP then
  441. emailId = MailConfig.ACTIVITY_OPENSERVER_LEVEL_UP
  442. elseif activityType == Const.AwardType.WING_ONE then
  443. emailId = MailConfig.ACTIVITY_OPENSERVER_WING_ONE
  444. elseif activityType == Const.AwardType.WING_TWO then
  445. emailId = MailConfig.ACTIVITY_OPENSERVER_WING_TWO
  446. elseif activityType == Const.AwardType.WING_THREE then
  447. emailId = MailConfig.ACTIVITY_OPENSERVER_WING_THREE
  448. elseif activityType == Const.AwardType.ANGLE_WEAPON then
  449. emailId = MailConfig.ACTIVITY_OPENSERVER_ANGLE_WEAPON
  450. else
  451. print("[OpenServerNewActivity.SendReward] activityType error")
  452. return false
  453. end
  454. local rewardNum = #activityData.record + 1
  455. sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), emailId, rewardMap, configReward.showtogname.."#"..rewardNum)
  456. end
  457. print("OpenServerNewActivity.SendReward send reward success")
  458. sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_REWARD_RESULT, {activityType = activityType, activitySubType = activitySubType})
  459. return true
  460. end