EquipHechengLogic.lua 5.1 KB

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