adventure.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. local schema = require "model.schema"
  2. local logger = require "logger"
  3. local reward = require "model.reward"
  4. local payment = require "model.payment"
  5. local asset = require "model.asset"
  6. local common_fun = require "model.common_fun"
  7. local module_fun = require "model.module_fun"
  8. local skynet = require "skynet"
  9. local stringify = require "stringify"
  10. local rankinglist
  11. local supreme_card
  12. local talent
  13. local hero
  14. local module_name = "adventure"
  15. local LAYER_SYS_NUM = 100 -- 波次系数(关卡*100+1为本关第一波)
  16. local NIL_RET = -1 -- 为nil时返回值
  17. local NULL_ADV = -1
  18. local SIMPLE_ADV = 0
  19. local ELITE_ADV = 1
  20. local MIN_ELITE_ID = 101
  21. local math_floor = math.floor
  22. local table_insert = table.insert
  23. local math_min = math.min
  24. local _M = schema.new(module_name, {
  25. pass = {
  26. -- [1] = {
  27. -- id = 关卡;
  28. -- tm = 时间
  29. -- award = {123,456}
  30. -- award_list = {}
  31. -- }
  32. },
  33. cost = nil,
  34. type = nil,
  35. layer = nil,
  36. trialid = 0, -- 试玩英雄配置id
  37. trialnum = 0, -- 试玩英雄次数
  38. btrial = false, -- 是否开始试玩
  39. })
  40. local REQUEST = {}
  41. local CMD = {}
  42. local MODULE = {}
  43. local THIS= {}
  44. local function func_ret(fname, character, args)
  45. local f = THIS[fname]
  46. if not f then
  47. logger.error("func_ret not fname:%s !!!", fname)
  48. return {errno = STD_ERR.COMMON_SYS_ERR}
  49. end
  50. local errno, ret = f(character, args)
  51. if errno ~= 0 then
  52. return {errno = errno}
  53. end
  54. ret = ret or {}
  55. ret.errno = 0
  56. return ret
  57. end
  58. function MODULE.list_request_interests() return REQUEST end
  59. function MODULE.list_command_interests() return CMD end
  60. -- TODO: 解析/升级模块数据
  61. function MODULE.parse(character)
  62. local d = _M.load(character)
  63. d.pass = d.pass or {}
  64. if not d.pass[SIMPLE_ADV] then d.pass[SIMPLE_ADV] = {id = 0, tm = 0, award = {}} end
  65. if not d.pass[ELITE_ADV] then d.pass[ELITE_ADV] = {id = 0, tm = 0, award = {}} end
  66. d.trialid = d.trialid or 0
  67. d.trialnum = d.trialnum or 0
  68. end
  69. local function sysnc_adventure(character)
  70. -- if character.ban_rank ~= 0 then
  71. -- return
  72. -- end
  73. -- local d = _M.assert_get(character)
  74. -- if d.pass[SIMPLE_ADV].id <=0 then
  75. -- return
  76. -- end
  77. -- local data = {
  78. -- num = d.pass[SIMPLE_ADV].id,
  79. -- num2 = d.pass[SIMPLE_ADV].tm,
  80. -- role = module_fun.simple_role(character),
  81. -- }
  82. -- skynet.call(rankinglist, "lua", "update", RANKING_ADV, data)
  83. end
  84. -- TODO: 侦听事件
  85. function MODULE.monitor(character)
  86. local d = _M.assert_get(character)
  87. character.monitor("simple_battle_pass", function(_, id)
  88. sysnc_adventure(character)
  89. end)
  90. end
  91. -- TODO: 类似泰利的 prepare 接口
  92. function MODULE.launch(character)
  93. local d = _M.assert_get(character)
  94. local u = _M.assert_runtime(character)
  95. rankinglist = skynet.localname(".rankinglist")
  96. end
  97. -- TODO: 与客户端同步数据
  98. function MODULE.ready(character)
  99. local d = _M.assert_get(character)
  100. sysnc_adventure(character)
  101. logger.test("%s: ready, d:%s", module_name, stringify(d))
  102. end
  103. -- TODO: 玩家下线时的处理
  104. function MODULE.saybye(character)
  105. sysnc_adventure(character)
  106. end
  107. function MODULE.gm_set_simple_adventure(character, id)
  108. local d = _M.assert_get(character) or {}
  109. if d.pass[SIMPLE_ADV].id < id then
  110. character.dispatch("simple_battle_pass", id)
  111. end
  112. d.pass[SIMPLE_ADV].id = id
  113. d.pass[SIMPLE_ADV].tm = os.time()
  114. _M.persist(character)
  115. end
  116. function MODULE.gm_set_elite_adventure(character, id)
  117. local d = _M.assert_get(character) or {}
  118. if asset.EliteInfoConfig_proto[id] then
  119. if d.pass[ELITE_ADV].id < id then
  120. character.dispatch("elite_battle_pass", id)
  121. end
  122. d.pass[ELITE_ADV].id = id
  123. d.pass[ELITE_ADV].tm = os.time()
  124. _M.persist(character)
  125. return true
  126. end
  127. return false
  128. end
  129. function MODULE.get_simple_pass(character)
  130. local d = _M.assert_get(character) or {}
  131. return d.pass[SIMPLE_ADV].id or 0
  132. end
  133. function MODULE.get_simple_pass_data(character)
  134. local d = _M.assert_get(character) or {}
  135. return d.pass[SIMPLE_ADV]
  136. end
  137. function MODULE.get_elite_pass(character)
  138. local d = _M.assert_get(character) or {}
  139. return d.pass[ELITE_ADV].id or 0
  140. end
  141. function MODULE.get_elite_pass_data(character)
  142. local d = _M.assert_get(character) or {}
  143. return d.pass[ELITE_ADV]
  144. end
  145. local function touch_trail(character, ttype, id)
  146. -- local d = _M.assert_get(character)
  147. -- if d.trialid and d.trialid > 0 then
  148. -- local conf = asset.TrialConfig_proto[d.trialid]
  149. -- if conf and id >= conf.parameter or id < conf.endcondition then
  150. -- return
  151. -- end
  152. -- end
  153. -- for _, conf in pairs(asset.TrialConfig_proto) do
  154. -- if id >= conf.parameter and id < conf.endcondition then
  155. -- if conf.integral == ttype then
  156. -- d.trialid = conf.ID
  157. -- d.trialnum = 0
  158. -- -- d.btrial = ttype == 1 and true or false
  159. -- _M.persist(character)
  160. -- return
  161. -- else
  162. -- return
  163. -- end
  164. -- end
  165. -- end
  166. end
  167. function THIS.get_conf_list(adv_type)
  168. if adv_type == SIMPLE_ADV then return assert(asset.StageInfoConfig_proto, "StageInfoConfig_proto")
  169. elseif adv_type == ELITE_ADV then return assert(asset.EliteInfoConfig_proto, "EliteInfoConfig_proto")
  170. end
  171. end
  172. function THIS.get_layer_conf_list(adv_type)
  173. if adv_type == SIMPLE_ADV then return assert(asset.StageConfig_proto, "StageConfig_proto")
  174. elseif adv_type == ELITE_ADV then return assert(asset.EliteStageConfig_proto, "EliteStageConfig_proto")
  175. end
  176. end
  177. function THIS.adventure_layer(character, args)
  178. local d = _M.assert_get(character)
  179. if not d.layer or not d.type then
  180. return STD_ERR.ADVENTURE_NOT_BATTLE
  181. end
  182. local id = math_floor(d.layer/LAYER_SYS_NUM)
  183. if id ~= math_floor(args.layer/LAYER_SYS_NUM) then
  184. return STD_ERR.COMMON_PARM_ERR
  185. end
  186. local conf_list = THIS.get_layer_conf_list(d.type)
  187. if not conf_list or not conf_list[args.layer] then
  188. return STD_ERR.COMMON_SYS_ERR
  189. end
  190. local conf = conf_list[args.layer]
  191. local max_list = {}
  192. local all_num = 0
  193. if conf then
  194. all_num = all_num + #conf.roles
  195. for _, monster_id in ipairs(conf.roles) do
  196. local monster_conf = asset.MonsterConfig_proto[monster_id]
  197. if monster_conf then
  198. max_list[monster_conf.type] = (max_list[monster_conf.type] or 0) + 1
  199. end
  200. end
  201. end
  202. local kill_boss = math.min(max_list[MONESTER_TYPE_BOSS] or 0, args.monster_num or 0)
  203. local all_num = math.min(all_num, (args.monster_num or 0) + (args.elite_num or 0) + (args.boss_num or 0))
  204. if args.layer > d.layer then
  205. d.layer = args.layer
  206. _M.persist(character)
  207. if all_num > 0 then
  208. character.dispatch("kill_monster", all_num)
  209. end
  210. if kill_boss > 0 then
  211. character.dispatch("kill_boss", kill_boss)
  212. end
  213. end
  214. if d.type == SIMPLE_ADV then
  215. local data = d.pass[SIMPLE_ADV]
  216. if id > data.id then
  217. data.progress = math.max(d.layer%LAYER_SYS_NUM, data.progress or 0)
  218. _M.persist(character)
  219. end
  220. end
  221. return 0
  222. end
  223. function THIS.adventure_start(character, args)
  224. local d = _M.assert_get(character)
  225. local id = args.id
  226. local key = args.type or 0
  227. -- 在冒险中
  228. -- if d.layer and d.type then
  229. -- return STD_ERR.ADVENTURE_IN_BATTLE -- 有冒险在进行
  230. -- end
  231. if not id or not key then
  232. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  233. end
  234. local conf_list = THIS.get_conf_list(key)
  235. if not conf_list or not conf_list[id] then
  236. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  237. end
  238. if not d.pass and not d.pass[key] then
  239. return STD_ERR.COMMON_SYS_ERR -- 系统异常
  240. end
  241. local data = d.pass[key]
  242. if conf_list[id].front > data.id then
  243. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  244. end
  245. if key == ELITE_ADV then
  246. if conf_list[id].condition > d.pass[SIMPLE_ADV].id then
  247. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  248. end
  249. end
  250. local conf_list = assert(asset.DataConfig_proto, "DataConfig_proto")
  251. local conf = conf_list[1]
  252. if not conf then
  253. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  254. end
  255. local costnum = conf.data5[1]
  256. if not costnum or costnum < 0 then
  257. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  258. end
  259. if key == SIMPLE_ADV then
  260. local detail = {{
  261. id = CURRENCY_ID_STM,
  262. num = costnum
  263. }}
  264. local receipt = {
  265. module="adventure",
  266. brief="闯关开始",
  267. context="闯关开始:"..id,
  268. notify={
  269. flags="adventure_start"
  270. },
  271. detail=detail
  272. }
  273. local errno = payment(character, receipt)
  274. if errno ~=0 then
  275. return errno
  276. end
  277. end
  278. d.layer = id * LAYER_SYS_NUM + 1;
  279. d.type = key
  280. d.cost = 0;
  281. _M.persist(character)
  282. if key == SIMPLE_ADV then
  283. touch_trail(character, 1, id)
  284. character.dispatch("simple_battle", id)
  285. elseif key == ELITE_ADV then
  286. character.dispatch("elite_battle", id)
  287. end
  288. -- if key == SIMPLE_ADV and d.trialid > 0 then
  289. -- local conf = asset.TrialConfig_proto[d.trialid]
  290. -- if conf and id >= conf.parameter and id <= conf.endcondition and d.trialnum < conf.rank then
  291. -- return 0, {
  292. -- trial_id = d.trialid,
  293. -- trial_num = d.trialnum,
  294. -- btrial = d.btrial
  295. -- }
  296. -- end
  297. -- end
  298. return 0
  299. end
  300. function THIS.adventure_end(character, args)
  301. local d = _M.assert_get(character) or {}
  302. if not d.layer or not d.type or d.layer <= 0 then
  303. return STD_ERR.ADVENTURE_NOT_BATTLE -- 没有进行中的冒险
  304. end
  305. local bwin = args.win
  306. local id = math_floor(d.layer/LAYER_SYS_NUM)
  307. if id <= 0 then
  308. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  309. end
  310. local key = d.type or 0
  311. if key ~= ELITE_ADV and key ~= SIMPLE_ADV then
  312. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  313. end
  314. local award_list
  315. local start_id = id*LAYER_SYS_NUM + 1
  316. -- 保护下每关最多99波
  317. local end_id = math_min(d.layer-1, (id+1)*LAYER_SYS_NUM-1)
  318. if not d.layer then
  319. return STD_ERR.ADVENTURE_NOT_BATTLE -- 没有进行中的冒险
  320. end
  321. local conf_list = THIS.get_layer_conf_list(d.type)
  322. if not conf_list then
  323. return STD_ERR.COMMON_SYS_ERR
  324. end
  325. local data = d.pass[key]
  326. if bwin then
  327. end_id = (id+1)*LAYER_SYS_NUM-1
  328. else
  329. if key == SIMPLE_ADV then
  330. touch_trail(character, 2, id)
  331. end
  332. end
  333. -- 简单关卡才有奖励
  334. if key == SIMPLE_ADV then
  335. local errno
  336. errno, award_list = THIS.simple_award(character, start_id, end_id)
  337. if errno ~= 0 then
  338. return errno
  339. end
  340. if award_list and next(award_list) then
  341. local desc = {
  342. module="adventure",
  343. brief="闯关奖励",
  344. context= string.format("闯关奖励%d", id),
  345. mailgen={subject=2, body=""},
  346. notify={
  347. flags="adventure_end"
  348. },
  349. detail=award_list
  350. }
  351. reward(character, desc)
  352. end
  353. end
  354. local max_list = {}
  355. local all_num = 0
  356. for confid = start_id, end_id do
  357. local conf = conf_list[confid]
  358. if conf then
  359. all_num = all_num + #conf.roles
  360. for _, monster_id in ipairs(conf.roles) do
  361. local monster_conf = asset.MonsterConfig_proto[monster_id]
  362. if monster_conf then
  363. max_list[monster_conf.type] = (max_list[monster_conf.type] or 0) + 1
  364. end
  365. end
  366. end
  367. end
  368. if id > data.id then
  369. if bwin then
  370. d.pass[key].id = id
  371. d.pass[key].tm = os.time()
  372. d.pass[key].progress = 0
  373. if key == SIMPLE_ADV then
  374. character.dispatch("simple_battle_pass", id)
  375. local ctx = _M.assert_runtime(character)
  376. ctx.ad_award = award_list
  377. ctx.id = id
  378. if d.btrial then
  379. d.trialnum = d.trialnum + 1
  380. end
  381. elseif key == ELITE_ADV then
  382. character.dispatch("elite_battle_pass", id)
  383. end
  384. else
  385. d.pass[key].progress = math.max(d.layer%LAYER_SYS_NUM, d.pass[key].progress or 0)
  386. end
  387. end
  388. local kill_boss = math.min(max_list[MONESTER_TYPE_BOSS] or 0, args.boss_num or 0)
  389. local all_num = math.min(all_num, (args.monster_num or 0) + (args.elite_num or 0) + (args.boss_num or 0))
  390. if all_num > 0 then
  391. character.dispatch("kill_monster", all_num)
  392. end
  393. if kill_boss > 0 then
  394. character.dispatch("kill_boss", kill_boss)
  395. end
  396. d.layer = nil;
  397. d.type = nil
  398. d.cost = nil
  399. _M.persist(character)
  400. return 0
  401. end
  402. local function adv_coins_add_addition(character, equip_list)
  403. -- supreme_card = supreme_card or require "model.activity.supreme_card"
  404. -- local unlock_supreme_card = supreme_card.card_unlock(character)
  405. local add_num = 0
  406. -- if unlock_supreme_card then
  407. -- add_num = add_num + asset.DataConfig_proto[48].data3*100
  408. -- end
  409. talent = talent or require "model.talent"
  410. local talent_list = talent.get_special_attr(character)
  411. if talent_list then
  412. add_num = add_num + (talent_list[ATTR_ADV_COIN] or 0)
  413. end
  414. if equip_list then
  415. add_num = add_num + (equip_list[ATTR_ADV_COIN] or 0)
  416. end
  417. return add_num
  418. end
  419. local function adv_exp_add_addition(character)
  420. -- supreme_card = supreme_card or require "model.activity.supreme_card"
  421. -- local unlock_supreme_card = supreme_card.card_unlock(character)
  422. local add_num = 0
  423. -- if unlock_supreme_card then
  424. -- add_num = add_num + asset.DataConfig_proto[48].data2*100
  425. -- end
  426. return add_num
  427. end
  428. local function adv_exp_stone_add_addition(character, equip_list)
  429. local add_num = 0
  430. talent = talent or require "model.talent"
  431. local talent_list = talent.get_special_attr(character)
  432. if talent_list then
  433. add_num = add_num + (talent_list[ATTR_ADV_EXP_STONE] or 0)
  434. end
  435. if equip_list then
  436. add_num = add_num + (equip_list[ATTR_ADV_EXP_STONE] or 0)
  437. end
  438. return add_num
  439. end
  440. function THIS.simple_award(character, min, max)
  441. local list = {}
  442. local conf_list = assert(asset.StageConfig_proto, "StageConfig_proto")
  443. for i = min, max do
  444. local conf = conf_list[i]
  445. if not conf then
  446. break
  447. end
  448. for _, id in ipairs(conf.rewardId or {}) do
  449. if id <= 0 then
  450. break
  451. end
  452. local errno, temp = common_fun.get_award(id)
  453. if errno ~= 0 then
  454. return errno
  455. end
  456. if temp and next(temp) then
  457. if not next(list) then
  458. list = temp
  459. else
  460. list = common_fun.merge2list(list, temp)
  461. end
  462. end
  463. end
  464. end
  465. hero = hero or require "model.hero"
  466. local equip_list = hero.get_special_attr(character)
  467. local coin_addition = adv_coins_add_addition(character, equip_list)
  468. local exp_addition = adv_exp_add_addition(character)
  469. local exp_stone = adv_exp_stone_add_addition(character, equip_list)
  470. if coin_addition > 0 or exp_addition > 0 or exp_stone > 0 then
  471. list = list or common_fun.merge_award(list)
  472. for _, v in ipairs(list) do
  473. if v.id == CURRENCY_ID_COINS and coin_addition > 0 then
  474. v.num = v.num + math.floor(v.num * coin_addition/10000)
  475. end
  476. if v.id == CURRENCY_ID_ROLE_EXP and exp_addition > 0 then
  477. v.num = v.num + math.floor(v.num * exp_addition/10000)
  478. end
  479. if v.id == CURRENCY_ID_EXP_STONE and exp_stone > 0 then
  480. v.num = v.num + math.floor(v.num * exp_stone/10000)
  481. end
  482. end
  483. end
  484. return 0, list
  485. end
  486. function THIS.adventure_sweep(character, args)
  487. local d = _M.assert_get(character) or {}
  488. local id = args.id
  489. if not id then
  490. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  491. end
  492. local info_conf_list = assert(asset.StageInfoConfig_proto, "StageInfoConfig_proto")
  493. if not info_conf_list[id] then
  494. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  495. end
  496. if d.pass[SIMPLE_ADV].id < id then
  497. return STD_ERR.ADVENTURE_NOT_PASS -- 未通关
  498. end
  499. local conf_list = assert(asset.DataConfig_proto, "DataConfig_proto")
  500. local conf = conf_list[1]
  501. if not conf then
  502. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  503. end
  504. local costnum = conf.data5[1]
  505. if not costnum then
  506. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  507. end
  508. local pay_list = {{
  509. id = CURRENCY_ID_STM,
  510. num = costnum
  511. }}
  512. local receipt = {
  513. module="adventure",
  514. brief="扫荡",
  515. context="扫荡:"..id,
  516. notify={
  517. flags="adventure_sweep"
  518. },
  519. detail=pay_list
  520. }
  521. -- 检查消耗
  522. local errno = module_fun.paymeny_check(character, pay_list)
  523. if errno ~= 0 then
  524. return errno
  525. end
  526. local min_id = id*LAYER_SYS_NUM+1
  527. local max_id = (id+1)*LAYER_SYS_NUM-1
  528. local award_list
  529. errno, award_list = THIS.simple_award(character, min_id, max_id)
  530. if errno ~= 0 then
  531. return errno
  532. end
  533. if not award_list or not next(award_list) then
  534. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  535. end
  536. -- 发奖励
  537. local desc = {
  538. module="adventure",
  539. brief="扫荡",
  540. context= "扫荡:"..id,
  541. mailgen={subject=2, body=""},
  542. notify={
  543. flags="adventure_sweep"
  544. },
  545. detail=award_list
  546. }
  547. payment(character, receipt, true)
  548. reward(character, desc)
  549. character.dispatch("sweep_simple_battle", id)
  550. return 0
  551. end
  552. function THIS.adventure_pass_award(character, args)
  553. local id = args.id
  554. local key = args.type or 0
  555. if not id then
  556. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  557. end
  558. if key ~= SIMPLE_ADV and key ~= ELITE_ADV then
  559. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  560. end
  561. local d = _M.assert_get(character)
  562. local data = d.pass[key]
  563. if not d.pass[key] then
  564. return STD_ERR.COMMON_SYS_ERR -- 系统异常
  565. end
  566. if data.id < id then
  567. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  568. end
  569. local temp_id = id - 1
  570. local index = math_floor(temp_id/32)+1
  571. local pos = math_floor(temp_id%32)
  572. data.award = data.award or {}
  573. if key == ELITE_ADV then
  574. index = math_floor((temp_id - 100)/10)+1
  575. pos = math_floor(temp_id%10)
  576. end
  577. if index < 1 or pos < 0 then
  578. return STD_ERR.COMMON_SYS_ERR -- 参数异常
  579. end
  580. for i = 1, index do
  581. data.award[i] = data.award[i] or 0
  582. end
  583. if data.award[index] & (1<<pos) > 0 then
  584. return STD_ERR.COMMON_AWARD_RECEIVED -- 已领取过奖励
  585. end
  586. local conf_list
  587. if key == SIMPLE_ADV then
  588. conf_list = assert(asset.StageInfoConfig_proto, "StageInfoConfig_proto")
  589. elseif key == ELITE_ADV then
  590. conf_list = assert(asset.EliteInfoConfig_proto, "EliteInfoConfig_proto")
  591. else
  592. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  593. end
  594. local conf = conf_list[id]
  595. if not conf then
  596. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  597. end
  598. local award_list = {}
  599. for i = 1, #conf.reward, 2 do
  600. local item = conf.reward[i]
  601. local num = conf.reward[i+1]
  602. if item and num and item > 0 and num > 0 then
  603. table_insert(award_list, {id = item, num = num})
  604. else
  605. break
  606. end
  607. end
  608. -- 发奖励
  609. local desc = {
  610. module="adventure",
  611. brief="通关奖励",
  612. context= "通关奖励:"..id,
  613. mailgen={subject=2, body=""},
  614. notify={
  615. flags="adventure_pass_award"
  616. },
  617. detail=award_list
  618. }
  619. reward(character, desc)
  620. data.award[index] = data.award[index] | (1<<pos)
  621. _M.persist(character)
  622. return 0, {id = args.id}
  623. end
  624. function THIS.adventure_ad_award(character, args)
  625. local ctx = _M.assert_runtime(character)
  626. if ctx.ad_award and next(ctx.ad_award) then
  627. local desc = {
  628. module="adventure",
  629. brief="闯关奖励",
  630. context= string.format("闯关广告奖励%d", ctx.id),
  631. mailgen={subject=2, body=""},
  632. notify={
  633. flags="adventure_ad_award"
  634. },
  635. detail=ctx.ad_award
  636. }
  637. reward(character, desc)
  638. ctx.ad_award = nil
  639. character.dispatch("watch_ad")
  640. else
  641. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  642. end
  643. return 0
  644. end
  645. function THIS.adventure_trial(character, args)
  646. local d = _M.assert_get(character) or {}
  647. if d.trialid > 0 and not d.btrial then
  648. d.btrial = d.btrial or true
  649. _M.persist(character)
  650. end
  651. return 0
  652. end
  653. function THIS.adventure_box_award(character, args)
  654. local id = args.id
  655. local pos = args.pos
  656. if not id or not pos or pos < 1 or pos > 10 then
  657. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  658. end
  659. local d = _M.assert_get(character) or {}
  660. local data = d.pass[SIMPLE_ADV]
  661. if not data then
  662. return STD_ERR.COMMON_SYS_ERR
  663. end
  664. if id > data.id + 1 then
  665. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  666. end
  667. local conf_list = THIS.get_conf_list(SIMPLE_ADV)
  668. if not conf_list then
  669. return STD_ERR.COMMON_SYS_ERR
  670. end
  671. local conf = conf_list[id]
  672. if not conf.boxcondition[pos] or not conf.box[pos] then
  673. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  674. end
  675. if id == data.id + 1 then
  676. if not data.progress or data.progress <= conf.boxcondition[pos] then
  677. return STD_ERR.COMMON_AWARD_NOT_UNLOCK
  678. end
  679. end
  680. data.award_list = data.award_list or {}
  681. data.award_list[id] = data.award_list[id] or 0
  682. local flag = 1 << pos-1
  683. if data.award_list[id] & flag > 0 then
  684. return STD_ERR.COMMON_AWARD_RECEIVED
  685. end
  686. local errno, award_list = common_fun.get_award(conf.box[pos])
  687. if errno ~= 0 then
  688. return errno
  689. end
  690. local desc = {
  691. module="adventure",
  692. brief="关卡宝箱奖励",
  693. context= string.format("关卡宝箱奖励%d", id),
  694. mailgen={subject=2, body=""},
  695. notify={
  696. flags="adventure_box_award"
  697. },
  698. detail=award_list
  699. }
  700. reward(character, desc)
  701. data.award_list[id] = data.award_list[id] + flag
  702. _M.persist(character)
  703. return 0, {id = args.id, pos = args.pos, data = data.award_list[id]}
  704. end
  705. function REQUEST.adventure_start(character, args)
  706. return func_ret("adventure_start", character, args)
  707. end
  708. function REQUEST.adventure_end(character, args)
  709. return func_ret("adventure_end", character, args)
  710. end
  711. function REQUEST.adventure_data(character, args)
  712. local d = _M.assert_get(character) or {}
  713. -- local elite_id = d.pass[ELITE_ADV].id+1
  714. -- if elite_id <= 100 then
  715. -- elite_id = MIN_ELITE_ID
  716. -- end
  717. -- if not asset.EliteInfoConfig_proto[elite_id] then
  718. -- for id = elite_id, elite_id + 20 do
  719. -- if asset.EliteInfoConfig_proto[id] then
  720. -- elite_id = id
  721. -- break
  722. -- end
  723. -- end
  724. -- end
  725. local list = {}
  726. d.pass[SIMPLE_ADV].award_list = d.pass[SIMPLE_ADV].award_list or {}
  727. for i = 1, d.pass[SIMPLE_ADV].id +1 do
  728. if d.pass[SIMPLE_ADV].award_list[i] then
  729. table.insert(list, d.pass[SIMPLE_ADV].award_list[i])
  730. else
  731. table.insert(list, 0)
  732. end
  733. end
  734. return {
  735. errno = 0,
  736. id1 = d.pass[SIMPLE_ADV].id +1,
  737. award1 = d.pass[SIMPLE_ADV].award,
  738. -- id2 = elite_id,
  739. box_award = list,
  740. award2 = d.pass[ELITE_ADV].award,
  741. layer = d.pass[SIMPLE_ADV].progress and d.pass[SIMPLE_ADV].progress or 0,
  742. type = d.type and d.type or NIL_RET,
  743. cost = d.cost and d.cost or NIL_RET
  744. }
  745. end
  746. function REQUEST.adventure_layer(character, args)
  747. return func_ret("adventure_layer", character, args)
  748. end
  749. function REQUEST.adventure_sweep(character, args)
  750. return func_ret("adventure_sweep", character, args)
  751. end
  752. function REQUEST.adventure_pass_award(character, args)
  753. return func_ret("adventure_pass_award", character, args)
  754. end
  755. function REQUEST.adventure_ad_award(character, args)
  756. return func_ret("adventure_ad_award", character, args)
  757. end
  758. function REQUEST.adventure_trial(character, args)
  759. return func_ret("adventure_trial", character, args)
  760. end
  761. function REQUEST.adventure_box_award(character, args)
  762. return func_ret("adventure_box_award", character, args)
  763. end
  764. return MODULE