EquipHechengLogic.lua 5.2 KB

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