equip.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. local schema = require "model.schema"
  2. local logger = require "logger"
  3. local common_fun = require "model.common_fun"
  4. local module_fun = require "model.module_fun"
  5. local asset = require "model.asset"
  6. local payment = require "model.payment"
  7. local reward = require "model.reward"
  8. local stringify = require "stringify"
  9. local keygen = require "model.keygen"
  10. local embattle
  11. local logger_trace = logger.trace
  12. local table_insert = table.insert
  13. local math_min = math.min
  14. local MAX_NUM = 2000 -- 装备背包最大数量
  15. local MAX_UPGRADE = 1000 -- 最大升级数量
  16. local module_name = "equip"
  17. local _M = schema.new(module_name, {
  18. first = nil,
  19. key = 100,
  20. num = 0,
  21. list = {
  22. --[[
  23. [sid] = {
  24. sid = 唯一id,
  25. id = 模板id,
  26. lv = 1,
  27. hero = 穿戴的英雄id
  28. }
  29. ]]
  30. },
  31. })
  32. local REQUEST = {}
  33. local CMD = {}
  34. local MODULE = {}
  35. local THIS = {}
  36. local tm_list = {}
  37. tm_list.equip_onekey_upgrade_star = 0
  38. local function func_ret(fname, character, args)
  39. local f = THIS[fname]
  40. if not f then
  41. logger.error("func_ret not fname:%s !!!", fname)
  42. return {errno = STD_ERR.COMMON_SYS_ERR}
  43. end
  44. if tm_list[fname] then
  45. local now = os.time()
  46. if now - tm_list[fname] == 0 then
  47. return {errno = STD_ERR.COMMON_CLICK_TOO_FAST} -- 点击太快了
  48. else
  49. tm_list[fname] = now
  50. end
  51. end
  52. local errno, ret = f(character, args)
  53. if errno ~= 0 then
  54. return {errno = errno}
  55. end
  56. ret = ret or {}
  57. ret.errno = 0
  58. return ret
  59. end
  60. function MODULE.list_request_interests() return REQUEST end
  61. function MODULE.list_command_interests() return CMD end
  62. -- TODO: 解析/升级模块数据 在这里把数据初始化好
  63. function MODULE.parse(character)
  64. local d = _M.load(character)
  65. d.num = d.num or 0
  66. d.list = d.list or {}
  67. end
  68. -- TODO: 侦听事件
  69. function MODULE.monitor(character)
  70. end
  71. -- TODO: 类似泰利的 prepare 接口
  72. function MODULE.launch(character)
  73. local d = _M.assert_get(character)
  74. local u = _M.assert_runtime(character)
  75. embattle = embattle or require "model.embattle"
  76. end
  77. -- TODO: 与客户端同步数据
  78. function MODULE.ready(character)
  79. local d = _M.assert_get(character)
  80. -- logger.test("%s:ready, %s", module_name, stringify(d or {}))
  81. end
  82. -- TODO: 玩家下线时的处理
  83. function MODULE.saybye(character)
  84. end
  85. function MODULE.equip_surplus(character)
  86. local d = _M.assert_get(character)
  87. return math.max((MAX_NUM - d.num), 0)
  88. end
  89. local function new_equip(character, id)
  90. return {
  91. sid = THIS.key(character),
  92. id = id,
  93. lv = 1
  94. }
  95. end
  96. function MODULE.add_equip(character, id, num, collect, dispose, addition)
  97. local d = _M.assert_get(character) or {}
  98. local equip_conf_list = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")
  99. local conf = equip_conf_list[id]
  100. if not conf and dispose then
  101. dispose(nil, id, num)
  102. return
  103. end
  104. local surplus = MODULE.equip_surplus(character)
  105. if num >= 1 and num <= MAX_NUM then
  106. local add_num = math.min(surplus, num)
  107. if add_num > 0 then
  108. for i = 1, add_num do
  109. local equip = new_equip(character, id)
  110. d.list[equip.sid] = equip
  111. collect(GOODS_EQUIP, equip)
  112. end
  113. d.num = d.num + add_num
  114. _M.persist(character)
  115. character.dispatch("equip_add_num", id, num)
  116. end
  117. addition(GOODS_EQUIP, id, add_num)
  118. if add_num < num then
  119. dispose(GOODS_EQUIP, id, num - add_num)
  120. end
  121. return true, add_num
  122. else
  123. if dispose then
  124. dispose(nil, id, num)
  125. end
  126. end
  127. end
  128. function MODULE.equip_check(character, sid)
  129. local d = _M.assert_get(character)
  130. return d.list[sid] and true or false
  131. end
  132. function MODULE.equip_get(character, sid)
  133. local d = _M.assert_get(character)
  134. return d.list[sid]
  135. end
  136. function MODULE.equip_wear(character, hero, old_list, new_list)
  137. local d = _M.assert_get(character)
  138. local equip_conf_list = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")
  139. local old_wear = 0
  140. local new_wear = 0
  141. local surplus = MODULE.equip_surplus(character)
  142. local sid = hero.sid
  143. local heroid = hero.id
  144. local hero_conf = asset.RoleConfig_proto[heroid]
  145. if not hero_conf then
  146. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  147. end
  148. local hero_profession = hero_conf.profession
  149. for pos, esid in ipairs(new_list or {}) do
  150. if esid and esid ~= "" then
  151. local data = d.list[esid]
  152. if not data then
  153. return STD_ERR.COMMON_PARM_ERR -- 未找到装备
  154. end
  155. local id = data.id
  156. local conf = equip_conf_list[id]
  157. if not conf then
  158. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  159. end
  160. if conf.type ~= pos then
  161. return STD_ERR.EQUIP_POS_ERR -- 装备位置异常
  162. end
  163. local can_wear = false
  164. for _, profession in ipairs(conf.profession) do
  165. if hero_profession == profession then
  166. can_wear = true
  167. break
  168. end
  169. end
  170. if not can_wear then
  171. return STD_ERR.EQUIP_PROFESSION_ERR -- 装备位置异常
  172. end
  173. if data.hero and data.hero ~= sid then
  174. return STD_ERR.EQUIP_BE_USED -- 装备被穿戴
  175. end
  176. new_wear = new_wear + 1
  177. end
  178. end
  179. for _, esid in ipairs(old_list or {}) do
  180. if esid and esid ~= "" and d.list[esid] and d.list[esid].hero then
  181. old_wear = old_wear + 1
  182. end
  183. end
  184. if surplus < old_wear - new_wear then
  185. return STD_ERR.EQUIP_FULL -- 背包已满
  186. end
  187. for _, esid in ipairs(old_list or {}) do
  188. if esid and esid ~= "" and d.list[esid] and d.list[esid].hero then
  189. d.list[esid].hero = nil
  190. end
  191. end
  192. for _, esid in ipairs(new_list or {}) do
  193. if esid and esid ~= "" and d.list[esid] then
  194. d.list[esid].hero = sid
  195. end
  196. end
  197. d.num = d.num + new_wear - old_wear
  198. _M.persist(character)
  199. return 0
  200. end
  201. function MODULE.equip_remove_check(character, list)
  202. local num = MODULE.equip_surplus(character)
  203. return num > #list
  204. end
  205. function MODULE.equip_remove(character, list)
  206. local d = _M.assert_get(character)
  207. local add_num = 0
  208. for _, esid in ipairs(list or {}) do
  209. if esid and esid ~= "" and d.list[esid] and d.list[esid].hero then
  210. d.list[esid].hero = nil
  211. add_num = add_num + 1
  212. end
  213. end
  214. d.num = d.num + add_num
  215. _M.persist(character)
  216. return 0
  217. end
  218. function MODULE.equip_save(character)
  219. _M.persist(character)
  220. end
  221. function THIS.equip_get_data(character, args)
  222. local d = _M.assert_get(character)
  223. return 0, {list = common_fun.tqueue(d.list)}
  224. end
  225. local function get_max_upgrade(character, equip_pos, cur_lv, max_lv)
  226. local num = 0
  227. local max_lv = max_lv or cur_lv + MAX_UPGRADE
  228. local level_conf_list = assert(asset.EquipmentLevelConfig_proto, "EquipmentLevelConfig_proto")
  229. local scrol_id = asset.DataConfig_proto[6].data6[equip_pos]
  230. local errno = common_fun.goods_check(scrol_id)
  231. if errno ~= 0 then
  232. return num
  233. end
  234. local goods_list = {}
  235. for lv = cur_lv+1, max_lv do
  236. local level_conf = level_conf_list[lv]
  237. if not level_conf then
  238. break
  239. end
  240. if level_conf.scrollNum > 0 then
  241. local item_id = scrol_id
  242. local item_num = level_conf.scrollNum
  243. if not goods_list[item_id] then
  244. goods_list[item_id] = module_fun.get_goods_num(character, item_id)
  245. end
  246. if goods_list[item_id] < item_num then
  247. break
  248. end
  249. goods_list[item_id] = goods_list[item_id] - item_num
  250. end
  251. if level_conf.goodNum > 0 then
  252. local item_id = CURRENCY_ID_COINS
  253. local item_num = level_conf.goodNum
  254. if not goods_list[item_id] then
  255. goods_list[item_id] = module_fun.get_goods_num(character, item_id)
  256. end
  257. if goods_list[item_id] < item_num then
  258. break
  259. end
  260. goods_list[item_id] = goods_list[item_id] - item_num
  261. end
  262. num = lv - cur_lv
  263. end
  264. return num
  265. end
  266. local function upgrade_award(equip_pos, cur, tar, list)
  267. local item_id = asset.DataConfig_proto[6].data6[equip_pos]
  268. local errno = common_fun.goods_check(item_id)
  269. if errno ~= 0 then
  270. return errno
  271. end
  272. local level_conf_list = assert(asset.EquipmentLevelConfig_proto, "EquipmentLevelConfig_proto")
  273. for lv = cur+1, tar do
  274. local level_conf = level_conf_list[lv]
  275. if not level_conf then
  276. return STD_ERR.COMMON_SYS_ERR -- 系统异常
  277. end
  278. if level_conf.scrollNum > 0 then
  279. table_insert(list, {id = item_id, num = level_conf.scrollNum})
  280. end
  281. if level_conf.goodNum > 0 then
  282. table_insert(list, {id = CURRENCY_ID_COINS, num = level_conf.goodNum})
  283. end
  284. end
  285. return 0
  286. end
  287. local function reset_level(equip_pos, lv, list)
  288. return upgrade_award(equip_pos, 1, lv, list)
  289. end
  290. function THIS.key(character)
  291. local d = _M.assert_get(character)
  292. d.key = d.key + 1
  293. return tostring(d.key)
  294. end
  295. function THIS.equip_upgrade(character, args)
  296. local d = _M.assert_get(character)
  297. local sid = args.sid
  298. local num = args.num or 0
  299. if not sid then
  300. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  301. end
  302. if num < 0 or num > MAX_UPGRADE then
  303. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  304. end
  305. local data = d.list[sid]
  306. local level = data.lv
  307. if not data then
  308. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  309. end
  310. local equip_conf_list = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")
  311. local equip_conf = equip_conf_list[data.id]
  312. if not equip_conf then
  313. logger_trace("ArmorConfig_proto:%d", data.id)
  314. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  315. end
  316. local quality_conf_list = assert(asset.EquipmentQualityConfig_proto, "EquipmentQualityConfig_proto")
  317. local cur_quality = common_fun.get_equip_quality(data.id)
  318. local quality_conf = quality_conf_list[cur_quality]
  319. if not quality_conf then
  320. logger_trace("EquipmentQualityConfig_proto:%d", cur_quality)
  321. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  322. end
  323. if num == 0 then
  324. num = get_max_upgrade(character, equip_conf.type, level, math_min(quality_conf.maxLv, character.level))
  325. end
  326. if level+num > quality_conf.maxLv or level+num > character.level then
  327. return STD_ERR.EQUIP_MAX_LEVEL -- 超过最大等级
  328. end
  329. local pay_list = {}
  330. local errno = upgrade_award(equip_conf.type, level, level+num, pay_list)
  331. if errno ~= 0 then
  332. return errno
  333. end
  334. local receipt = {
  335. module="equip",
  336. brief="装备升级",
  337. context=string.format("装备id%d, 从%d升级到%d", data.id, level, level+num),
  338. notify={
  339. flags="equip_upgrade"
  340. },
  341. detail=pay_list
  342. }
  343. local errno = payment(character, receipt)
  344. if errno ~=0 then
  345. return errno
  346. end
  347. local pre_lv = data.lv
  348. local cur_lv = data.lv + num
  349. data.lv = data.lv+num
  350. _M.persist(character)
  351. character.dispatch("equip_upgrade", data.id, pre_lv, cur_lv)
  352. return 0, {data = data}
  353. end
  354. function THIS.equip_upgrade_star(character, args)
  355. local d = _M.assert_get(character)
  356. local sid = args.sid
  357. local same_list = args.same or {}
  358. local other_list = args.other or {}
  359. local item_list = args.currency or {}
  360. local buse_item = next(item_list) and item_list.num and item_list.num > 0 and true or false
  361. if buse_item then
  362. if not item_list.id then
  363. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  364. end
  365. end
  366. if not sid then
  367. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  368. end
  369. local data = d.list[sid]
  370. if not data then
  371. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  372. end
  373. -- 先检查是否重复
  374. local temp_list = {[sid] = 1}
  375. for _, v in ipairs(same_list) do
  376. if temp_list[v] then
  377. return STD_ERR.EQUIP_SAME_SID -- 重复的装备id
  378. end
  379. if not d.list[v] or d.list[v].hero then
  380. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  381. end
  382. temp_list[v] = 1
  383. end
  384. for _, v in ipairs(other_list) do
  385. if temp_list[v] then
  386. return STD_ERR.EQUIP_SAME_SID -- 重复的装备id
  387. end
  388. if not d.list[v] or d.list[v].hero then
  389. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  390. end
  391. temp_list[v] = 1
  392. end
  393. local equip_conf_list = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")
  394. local equip_conf = equip_conf_list[data.id]
  395. local equip_type = equip_conf.type
  396. if not equip_type then
  397. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  398. end
  399. if not equip_conf then
  400. logger_trace("ArmorConfig_proto:%d", data.id)
  401. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  402. end
  403. local cur_quality = common_fun.get_equip_quality(data.id)
  404. local max_quality = asset.DataConfig_proto[5].data3
  405. if cur_quality >= max_quality then
  406. return STD_ERR.EQUIP_START_MAX -- 达到最大突破等级
  407. end
  408. local min_id = math.floor(data.id/100)*100+1
  409. local max_id = min_id + 98
  410. local conf_id = data.id + 1
  411. if not equip_conf_list[conf_id] then
  412. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  413. end
  414. local quality_conf_list = assert(asset.EquipmentQualityConfig_proto, "EquipmentQualityConfig_proto")
  415. local quality_conf = quality_conf_list[cur_quality+1]
  416. if not quality_conf then
  417. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  418. end
  419. -- 检查消耗数量
  420. if quality_conf.sameQualityNum ~= #same_list or quality_conf.anyQualityNum ~= #other_list + (buse_item and item_list.num or 0) then
  421. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  422. end
  423. --检查同名装备消耗
  424. for i = 1, #same_list do
  425. local id = d.list[same_list[i]].id
  426. if id < min_id or id > max_id then
  427. return STD_ERR.EQUIP_SAME_PAY_ERR -- 不符合消耗条件
  428. end
  429. -- local conf = equip_conf_list[id]
  430. local quality = common_fun.get_equip_quality(id)
  431. if quality ~= quality_conf.sameQuality then
  432. return STD_ERR.EQUIP_SAME_PAY_ERR -- 不符合消耗条件
  433. end
  434. end
  435. --检查任意装备消耗
  436. for i = 1, #other_list do
  437. local id = d.list[other_list[i]].id
  438. local conf = equip_conf_list[id]
  439. local quality = common_fun.get_equip_quality(id)
  440. if quality ~= quality_conf.anyQuality or conf.type ~= equip_type then
  441. return STD_ERR.EQUIP_OTHER_PAY_ERR -- 不符合消耗条件
  442. end
  443. end
  444. local del_list = {}
  445. local award_list = {}
  446. -- 把突破的装备排除和已装备的装备排除
  447. temp_list[sid] = nil
  448. for k in pairs(temp_list) do
  449. if d.list[k].lv > 1 or d.list[k].hero then
  450. local errno = reset_level(equip_type, d.list[k].lv, award_list)
  451. if errno ~= 0 then
  452. return errno
  453. end
  454. end
  455. table_insert(del_list, k)
  456. end
  457. -- 检查替代品消耗
  458. if buse_item then
  459. if quality_conf.resetGoods[equip_type] ~= item_list.id then
  460. return STD_ERR.EQUIP_OTHER_PAY_ERR -- 不符合消耗条件
  461. end
  462. local receipt = {
  463. module="equip",
  464. brief="装备升星",
  465. context=string.format("装备id%d, 升星为%d", data.id, conf_id),
  466. notify={
  467. flags="equip_upgrade_star"
  468. },
  469. detail={item_list}
  470. }
  471. local errno = payment(character, receipt)
  472. if errno ~= 0 then
  473. return errno
  474. end
  475. end
  476. if next(award_list) then
  477. local desc = {
  478. module="equip",
  479. brief="装备突破",
  480. context= "装备突破返还",
  481. mailgen={subject=2, body=""},
  482. notify={
  483. flags="equip_upgrade_star"
  484. },
  485. detail=award_list
  486. }
  487. reward(character, desc)
  488. end
  489. for _, v in ipairs(del_list)do
  490. if d.list[v] then
  491. d.list[v] = nil
  492. end
  493. end
  494. d.list[sid].id = conf_id
  495. d.num = d.num - #temp_list
  496. _M.persist(character)
  497. character.dispatch("equip_del", del_list)
  498. character.dispatch("equip_upstart", conf_id, cur_quality, cur_quality+1)
  499. return 0, {data = d.list[sid], same = args.same, other = args.other, currency = args.currency}
  500. end
  501. function THIS.equip_onekey_upgrade_star(character, args)
  502. local d = _M.assert_get(character)
  503. local temp_list = {}
  504. for sid, data in pairs(d.list) do
  505. -- 紫色 未上阵 未升级的装备一键突破
  506. local quality = common_fun.get_equip_quality(data.id)
  507. if data.lv == 1 and quality < STAR_COLOR_PURPLE and not data.hero or data.hero == "" then
  508. temp_list[quality] = temp_list[quality] or {}
  509. temp_list[quality][data.id] = temp_list[quality][data.id] or {}
  510. table_insert(temp_list[quality][data.id], sid)
  511. end
  512. end
  513. local del_list = {}
  514. local change_list = {}
  515. local max_quality = 1
  516. for quality = 1, STAR_COLOR_PURPLE do
  517. local quality_conf_list = assert(asset.EquipmentQualityConfig_proto, "EquipmentQualityConfig_proto")
  518. if not quality_conf_list[quality] or quality_conf_list[quality].anyQualityNum > 0 then
  519. break
  520. end
  521. local temp = temp_list[quality]
  522. if temp then
  523. for id, list in pairs(temp) do
  524. local quality_conf = quality_conf_list[quality+1]
  525. local equip_conf = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")[id+1]
  526. local num = #list
  527. local step = quality_conf.sameQualityNum+1
  528. assert(step > 0)
  529. if equip_conf and step <= num and quality_conf.sameQuality == quality then
  530. for i = 1, num, step do
  531. if list[i+step-1] then
  532. d.list[list[i]].id = id+1
  533. table.insert(change_list, d.list[list[i]])
  534. for j = i+1, i+step-1 do
  535. d.list[list[j]] = nil
  536. table.insert(del_list, list[j])
  537. end
  538. max_quality = quality
  539. if #change_list >= 100 then
  540. goto equip_onekey_upgrade_star_break
  541. end
  542. end
  543. end
  544. end
  545. end
  546. end
  547. end
  548. ::equip_onekey_upgrade_star_break::
  549. if not next(change_list) then
  550. return STD_ERR.EQUIP_NOBODY_CAN_UP_STAR -- 没有
  551. end
  552. d.num = d.num - #del_list
  553. _M.persist(character)
  554. character.dispatch("equip_del", del_list)
  555. character.dispatch("equip_upstart_times", #change_list, max_quality+1)
  556. return 0, {del_list = del_list, change_list = change_list}
  557. end
  558. -- 重置装备
  559. function THIS.equip_reset(character, args)
  560. local sid = args.sid
  561. if not sid then
  562. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  563. end
  564. local d = _M.assert_get(character)
  565. local data = d.list[sid]
  566. if not data then
  567. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  568. end
  569. local temp_data = common_fun.scopy(data)
  570. local award_list = {}
  571. local desc = {
  572. module="equip",
  573. brief="重置装备",
  574. mailgen={subject=2, body=""},
  575. notify={
  576. flags="equip_reset"
  577. },
  578. }
  579. local equip_conf_list = assert(asset.ArmorConfig_proto, "ArmorConfig_proto")
  580. local equip_conf = equip_conf_list[data.id]
  581. if not equip_conf then
  582. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  583. end
  584. if args.level then
  585. if data.lv <= 1 then
  586. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  587. end
  588. desc.context= string.format("重置装备等级, sid:%s, lv:%d", sid, data.lv)
  589. else
  590. local quality = common_fun.get_equip_quality(data.id)
  591. local min_quality = -1
  592. if quality > STAR_COLOR_RED then
  593. min_quality = STAR_COLOR_RED
  594. elseif quality > STAR_COLOR_ORANGE then
  595. min_quality = STAR_COLOR_ORANGE
  596. elseif quality > STAR_COLOR_PURPLE then
  597. min_quality = STAR_COLOR_PURPLE
  598. else
  599. return STD_ERR.COMMON_PARM_ERR -- 参数异常
  600. end
  601. local quality_conf_list = assert(asset.EquipmentQualityConfig_proto, "EquipmentQualityConfig_proto")
  602. for i = min_quality+1, quality do
  603. local quality_conf = quality_conf_list[i]
  604. if not quality_conf or quality_conf.sameQualityNum > 0 then
  605. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  606. end
  607. local item_id = quality_conf.resetGoods[equip_conf.type]
  608. if not item_id or item_id <= 0 then
  609. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  610. end
  611. table_insert(award_list, {id = item_id, num = quality_conf.anyQualityNum})
  612. end
  613. local new_id = math.floor(data.id/100)*100+min_quality
  614. equip_conf = equip_conf_list[new_id]
  615. if not equip_conf then
  616. return STD_ERR.COMMON_CONF_ERR -- 配置异常
  617. end
  618. desc.context = string.format("重置装备突破等级, sid:%s, id:%d==>%d", sid, data.id, new_id)
  619. temp_data.id = new_id
  620. end
  621. if data.lv > 1 then
  622. local errno = reset_level(equip_conf.type, data.lv, award_list)
  623. if errno ~= 0 then
  624. return
  625. end
  626. temp_data.lv = 1
  627. end
  628. desc.detail = award_list
  629. reward(character, desc)
  630. d.list[sid] = temp_data
  631. _M.persist(character)
  632. return 0, {data = temp_data}
  633. end
  634. -- 装备背包数据
  635. function REQUEST.equip_get_data(character, args)
  636. return func_ret("equip_get_data", character, args)
  637. end
  638. -- 装备升级
  639. function REQUEST.equip_upgrade(character, args)
  640. return func_ret("equip_upgrade", character, args)
  641. end
  642. -- 装备升星
  643. function REQUEST.equip_upgrade_star(character, args)
  644. return func_ret("equip_upgrade_star", character, args)
  645. end
  646. -- 一键升星
  647. function REQUEST.equip_onekey_upgrade_star(character, args)
  648. return func_ret("equip_onekey_upgrade_star", character, args)
  649. end
  650. -- 重置
  651. function REQUEST.equip_reset(character, args)
  652. return func_ret("equip_reset", character, args)
  653. end
  654. function MODULE.get_equip_data(character, sid)
  655. local d = _M.assert_get(character)
  656. return d.list[sid]
  657. end
  658. return MODULE