EquipHechengLogic.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. local Lang = require("common.Lang")
  2. local Msg = require("core.Msg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local EquipExcel = require("excel.equip")
  5. local BagLogic = require("bag.BagLogic")
  6. local Grid = require("bag.Grid")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  9. local ItemDefine = require("bag.ItemDefine")
  10. local Util = require("common.Util")
  11. local EquipLogic = require("equip.EquipLogic")
  12. local CommonDefine = require("common.CommonDefine")
  13. EQUIP_HECHENG_LOG_MAX = 30
  14. local EQUIP_HECHENG_QUALITY = 5
  15. --装备合成帮助查询
  16. function equipDetailQuery(human)
  17. local descConfig = EquipExcel.detail[1]
  18. if not descConfig then return end
  19. local msgRet = Msg.gc.GC_EQUIP_HECHENG_DETAIL_QUERY
  20. msgRet.desc = descConfig.desc
  21. Msg.send(msgRet, human.fd)
  22. end
  23. local function sendQuery(human, pos)
  24. local msgRet = Msg.gc.GC_EQUIP_HECHENG_QUERY
  25. msgRet.pos = pos
  26. local cnt = 0
  27. local count = 0
  28. msgRet.dot = {0,0,0,0}
  29. for key, value in ipairs(EquipExcel.hecheng)do
  30. if pos == value.pos then
  31. cnt = cnt + 1
  32. msgRet.list[cnt].id = key
  33. msgRet.list[cnt].itemData[0] = 2
  34. Grid.makeItem(msgRet.list[cnt].itemData[1], value.hechengID, 1, nil, nil, nil, nil, 5)
  35. Grid.makeItem(msgRet.list[cnt].itemData[2], value.needID, 1, nil, nil, nil, nil, 5)
  36. msgRet.list[cnt].cnt = value.cnt
  37. Grid.makeItem(msgRet.list[cnt].need[1], value.money[1][1], value.money[1][2])
  38. msgRet.list[cnt].need[0] = 1
  39. end
  40. local nowEquipCnt = BagLogic.getItemCnt(human, value.needID)
  41. if nowEquipCnt >= value.cnt then
  42. msgRet.dot[value.pos] = 1
  43. end
  44. end
  45. msgRet.list[0] = cnt
  46. msgRet.dot[0] = 4
  47. Msg.send(msgRet, human.fd)
  48. end
  49. -- 装备合成信息查询
  50. function equipHechengQuery(human, pos)
  51. if pos == ItemDefine.EQUIP_SUBTYPE_RING or pos == EQUIP_SUBTYPE_AMULET then
  52. return
  53. end
  54. if pos == 0 then
  55. for i = ItemDefine.EQUIP_SUBTYPE_WEAPON, ItemDefine.EQUIP_SUBTYPE_SHIPIN do
  56. sendQuery(human, i)
  57. end
  58. else
  59. sendQuery(human, pos)
  60. end
  61. end
  62. -- 合成装备
  63. function equipHechengDo(human, id, indexList)
  64. print(" equipHechengDo ", id )
  65. Util.printTable(indexList)
  66. local config = EquipExcel.hecheng[id]
  67. if not config then
  68. Broadcast.sendErr(human, Util.format(Lang.SKIN_CONF_ERR))
  69. return
  70. end
  71. if config.cnt ~= #indexList then
  72. Broadcast.sendErr(human, Util.format(Lang.EQUIP_HECHENG_ERR_NOITEM,ItemDefine.getValue(config.needID,"name")))
  73. return
  74. end
  75. -- 检查 装备下标是否正确
  76. local isExist = {}
  77. local nLen = indexList[0]
  78. for i = 1, nLen, 1 do
  79. local idx = indexList[i]
  80. if isExist[idx] then
  81. Broadcast.sendErr(human, Util.format(Lang.DRILL_CHOOSE_MY_ERR_INDEX))
  82. return
  83. end
  84. isExist[idx] = true
  85. end
  86. for _, index in ipairs(indexList) do
  87. local grid = human.db.equipBag[index]
  88. if not grid or grid.id ~= config.needID then
  89. return Broadcast.sendErr(human, Util.format(Lang.EQUIP_HECHENG_ERR_NOITEM,ItemDefine.getValue(config.needID,"name")))
  90. end
  91. if grid.quality ~= EQUIP_HECHENG_QUALITY then
  92. return Broadcast.sendErr(human, Util.format(Lang.EQUIP_HECHENG_QUALITY_ERROR, EQUIP_HECHENG_QUALITY))
  93. end
  94. local equipCfg = EquipExcel.equip[grid.id]
  95. if equipCfg.subType == ItemDefine.EQUIP_SUBTYPE_RING or equipCfg.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then
  96. return
  97. end
  98. end
  99. -- 判断消耗
  100. for _, v in ipairs(config.money) do
  101. if BagLogic.getItemCnt(human, v[1]) < v[2] then
  102. return
  103. end
  104. end
  105. for _, v in ipairs(config.money) do
  106. BagLogic.delItem(human, v[1], v[2], "equip_hecheng")
  107. end
  108. local equipGrid = Util.copyTable(human.db.equipBag[indexList[1]])
  109. -- 删除道具
  110. for k, index in ipairs(indexList) do
  111. EquipLogic.delEquip(human, index, "equip_hecheng")
  112. end
  113. equipGrid.id = config.hechengID
  114. -- EquipLogic.getNewAttrByItemID(config.hechengID, equipGrid.attr)
  115. EquipLogic.getNewAttrByItemID(config.hechengID, equipGrid)
  116. EquipLogic.addByEquipGrid(human, equipGrid, "equip_hecheng")
  117. -- 通知客户端
  118. local msgRet = Msg.gc.GC_EQUIP_HECHENG_DO
  119. BagLogic.BagLogic_GetAllSendInfo(human, msgRet.item, nil, CommonDefine.COMMON_SEND_PRIZE_TYPE_ONLYEQUIP)
  120. --Grid.makeItem(msgRet.item, equipGrid.id, 1, nil, equipGrid, index, Grid.getOpflagAtBag(equipGrid.id))
  121. Msg.send(msgRet, human.fd)
  122. local equipTb = {}
  123. equipTb[config.hechengID] = 1
  124. equipHechengLog(human,equipTb, config.money)
  125. end
  126. function equipHechengLog(human,equip,cost)
  127. local now = os.time()
  128. local logTb = {}
  129. logTb.equip = equip
  130. logTb.cost = cost
  131. logTb.time = now
  132. human.db.equipLogs = human.db.equipLogs or {}
  133. table.insert(human.db.equipLogs,1,logTb)
  134. human.db.equipLogs[EQUIP_HECHENG_LOG_MAX + 1] = nil
  135. end
  136. function equipLogsQuery(human)
  137. local msgRet = Msg.gc.GC_EUQIP_HECHENG_LOG_QUERY
  138. if human.db.equipLogs == nil or #human.db.equipLogs == 0 then
  139. msgRet.equipLogs[0] = 0
  140. Msg.send(msgRet,human.fd)
  141. return
  142. end
  143. local len = #human.db.equipLogs
  144. for i = 1,len do
  145. local v = human.db.equipLogs[i]
  146. local count = 0
  147. for equipID,equipCnt in pairs(v.equip) do
  148. Grid.makeItem(msgRet.equipLogs[i].equip,equipID,equipCnt, nil, nil, nil, nil, 5)
  149. end
  150. Grid.makeItem(msgRet.equipLogs[i].cost[1], v.cost[1],v.cost[2])
  151. msgRet.equipLogs[i].cost[0] = 1
  152. msgRet.equipLogs[i].time = v.time
  153. if i >= 30 then
  154. break
  155. end
  156. end
  157. msgRet.equipLogs[0] = len
  158. Msg.send(msgRet,human.fd)
  159. end