FenjieLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. -------------------------------------------------------
  2. -- 英雄分解
  3. -------------------------------------------------------
  4. local HeroExcel = require("excel.hero")
  5. local UpNeedExcel = require("excel.upNeed")
  6. local EquipExcel = require("excel.equip")
  7. local Lang = require("common.Lang")
  8. local Util = require("common.Util")
  9. local Msg = require("core.Msg")
  10. local HeroLogic = require("hero.HeroLogic")
  11. local BagLogic = require("bag.BagLogic")
  12. local ItemDefine = require("bag.ItemDefine")
  13. local Grid = require("bag.Grid")
  14. local HeroGrid = require("hero.HeroGrid")
  15. local HeroBook = require("hero.HeroBook")
  16. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  17. local Broadcast = require("broadcast.Broadcast")
  18. local HechengLogic = require("hecheng.HechengLogic")
  19. local FuwenLogic = require("fuwen.FuwenLogic")
  20. local SuipianLogic = require("bag.SuipianLogic")
  21. local CombatPosLogic = require("combat.CombatPosLogic")
  22. local HeroDefine = require("hero.HeroDefine")
  23. local EquipLogic = require("equip.EquipLogic")
  24. local BingshuLogic = require("fuwen.BingshuLogic")
  25. local FuwenExcel = require("excel.fuwen")
  26. local WinnerRelicLogic = require("winnerRelic.WinnerRelicLogic")
  27. FENJIE_QUERY = 1 --分解查询
  28. FENJIE_DO = 2 --祭坛分解
  29. FENJIE_DO_HECHENG = 3 --合成导致的分解
  30. FENJIE_DO_JUEXING = 4 --觉醒导致的分解
  31. FENJIE_DO_SHELTER = 5 --庇护所导致的分解
  32. FENJIE_DO_TENSTAR = 7 --十星置换导致分解
  33. FENJIE_DO_MERGE = 7 --融合导致分解
  34. -------------------------------------------------------------------------------------
  35. local FENJIE_OUTITEMS = {}
  36. local FENJIE_FUWEN_LIST = {}
  37. local FENJIE_EQUIP_LIST = {}
  38. local SUIJI_CNT = 0
  39. -- 重置产出信息
  40. local function cleanOutItems()
  41. for k in pairs(FENJIE_OUTITEMS) do
  42. FENJIE_OUTITEMS[k] = nil
  43. end
  44. for k in pairs(FENJIE_FUWEN_LIST) do
  45. FENJIE_FUWEN_LIST[k] = nil
  46. end
  47. for k in pairs(FENJIE_EQUIP_LIST) do
  48. FENJIE_EQUIP_LIST[k] = nil
  49. end
  50. SUIJI_CNT = 0
  51. end
  52. -- 添加产出道具
  53. local function addOutItem(itemID, itemCnt)
  54. if itemCnt < 1 then return end
  55. FENJIE_OUTITEMS[itemID] = FENJIE_OUTITEMS[itemID] or 0
  56. FENJIE_OUTITEMS[itemID] = FENJIE_OUTITEMS[itemID] + itemCnt
  57. end
  58. local function cleanOutItem(itemID)
  59. FENJIE_OUTITEMS[itemID] = nil
  60. end
  61. -- 添加产出符文
  62. local function addOutFuwen(fuwenGrid)
  63. FENJIE_FUWEN_LIST[#FENJIE_FUWEN_LIST + 1] = fuwenGrid
  64. end
  65. -- 添加产出符文
  66. local function addOutEquip(equipGrid)
  67. equipGrid.putUuid = nil -- 重置装备穿戴属性
  68. FENJIE_EQUIP_LIST[#FENJIE_EQUIP_LIST + 1] = equipGrid
  69. end
  70. -- 材料打折
  71. local function solveOutItem(itemID, rate, value, isFloor)
  72. FENJIE_OUTITEMS[itemID] = FENJIE_OUTITEMS[itemID] or 0
  73. FENJIE_OUTITEMS[itemID] = FENJIE_OUTITEMS[itemID] * rate + value
  74. if isFloor then
  75. FENJIE_OUTITEMS[itemID] = math.floor(FENJIE_OUTITEMS[itemID])
  76. else
  77. FENJIE_OUTITEMS[itemID] = math.ceil(FENJIE_OUTITEMS[itemID])
  78. end
  79. if FENJIE_OUTITEMS[itemID] <= 0 then
  80. FENJIE_OUTITEMS[itemID] = nil
  81. end
  82. end
  83. --返还宝石
  84. local function returnGem(gemData)
  85. if not gemData then
  86. return
  87. end
  88. local calCnt = function(level)
  89. local cnt = 0
  90. for i=level, 1, -1 do
  91. cnt = cnt + math.ceil(i/3)
  92. end
  93. return cnt
  94. end
  95. local num = 0
  96. for _, v in pairs(gemData) do
  97. num = num + calCnt(v.lv)
  98. end
  99. return num
  100. end
  101. ----------------------------------------------------------------------------------------
  102. -- 判断能否分解
  103. local function checkCanFenjie(human, heroIDList, heroIndexList)
  104. if heroIDList[0] < 0 then return end
  105. if heroIDList[0] ~= heroIndexList[0] then return end
  106. local indexTable = {}
  107. for i = 1, heroIDList[0] do
  108. local heroID = heroIDList[i]
  109. local heroIndex = heroIndexList[i]
  110. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  111. if not heroGrid then
  112. return -- 信息不一致
  113. end
  114. -- 服务器不判断是否上锁,因为分解还有其它地方用到
  115. if indexTable[heroIndex] then
  116. return -- 重复index
  117. end
  118. indexTable[heroIndex] = true
  119. if CombatPosLogic.isLastInCombat(human, heroGrid.uuid) then
  120. return
  121. end
  122. -- 检查英雄装备
  123. end
  124. return true
  125. end
  126. -- 判断碎片能否费解
  127. local function checkCanFenjieChip(human, itemIdList, itemIdCntList)
  128. if itemIdList[0] < 0 then return end
  129. if itemIdList[0] ~= itemIdCntList[0] then return end
  130. local indexTable = {}
  131. for i = 1, itemIdList[0] do
  132. local itemID = itemIdList[i]
  133. local itemIDCnt = itemIdCntList[i]
  134. -- 判定道具类型
  135. local itemConfig = ItemDefine.getConfig(itemID)
  136. if not itemConfig then return end
  137. -- 是否是英雄碎片
  138. if itemConfig.get[2] ~= SuipianLogic.SUMMON_SUBTYPE_HERO then
  139. return
  140. end
  141. local cnt = BagLogic.getItemCnt(human, itemID)
  142. if cnt < itemIDCnt then
  143. return
  144. end
  145. -- 服务器不判断是否上锁,因为分解还有其它地方用到
  146. if indexTable[itemID] then
  147. return -- 重复index
  148. end
  149. indexTable[itemID] = true
  150. end
  151. return true
  152. end
  153. -- 给予玩家道具返还
  154. local function giveItems(human, outItems, fuwenList, equipList, logType)
  155. local itemList = {}
  156. for itemID, itemCnt in pairs(outItems) do
  157. BagLogic.addItem(human, itemID, itemCnt, logType)
  158. itemList[itemID] = itemList[itemID] or 0
  159. itemList[itemID] = itemList[itemID] + itemCnt
  160. end
  161. for _, fuwenGrid in ipairs(fuwenList) do
  162. FuwenLogic.addByGrid(human, fuwenGrid, logType)
  163. end
  164. for _, equipGrid in ipairs(equipList) do
  165. EquipLogic.addByEquipGrid(human, equipGrid, logType)
  166. end
  167. end
  168. -- 统计单个英雄产出
  169. local function calcHeroOut(heroGrid, mainType)
  170. local heroConfig = HeroExcel.hero[heroGrid.id]
  171. if not heroConfig then return end
  172. -- 等级返还
  173. local upLvTempConfig = UpNeedExcel.upLv
  174. local lv = heroGrid.lv
  175. if heroGrid.oldLV then
  176. lv = heroGrid.oldLV
  177. end
  178. for i = 1, lv do
  179. local upcf = UpNeedExcel.upLv[i]
  180. if not upcf then break end
  181. addOutItem(ItemDefine.ITEM_GREEN_EXP_ID, upcf.soul)
  182. addOutItem(ItemDefine.ITEM_JINBI_ID, upcf.money)
  183. end
  184. local quality = heroGrid.quality
  185. if heroGrid.oldQuality then
  186. quality = heroGrid.oldQuality
  187. end
  188. for i = 1, quality do
  189. local qcf = UpNeedExcel.upQuality[i]
  190. if not qcf then break end
  191. addOutItem(ItemDefine.ITEM_HERO_UPGRADE_ID, qcf.jinjieshi)
  192. addOutItem(ItemDefine.ITEM_JINBI_ID, qcf.money)
  193. end
  194. -- 魔法之尘消耗
  195. if heroGrid.equip and heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN] then
  196. local equipTempID = heroGrid.equip[ItemDefine.EQUIP_SUBTYPE_SHUIJIN]
  197. local shuijinMoney = 0
  198. for j = 1, 10000 do
  199. if equipTempID == 0 then
  200. break
  201. end
  202. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipTempID]
  203. addOutItem(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, shuijingUpNeedConfig.jinghua)
  204. addOutItem(ItemDefine.ITEM_JINBI_ID, shuijingUpNeedConfig.money)
  205. equipTempID = shuijingUpNeedConfig.prevID
  206. end
  207. SUIJI_CNT = SUIJI_CNT + 1
  208. end
  209. -- 返还装备
  210. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  211. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN and
  212. heroGrid.equip and heroGrid.equip[i] then
  213. local equipGrid = heroGrid.equip[i]
  214. if equipGrid then
  215. addOutEquip(equipGrid)
  216. end
  217. end
  218. end
  219. -- 返还符文
  220. for i = 1, 2 do
  221. local fuwenGrid = heroGrid.fuwen and heroGrid.fuwen[i]
  222. if fuwenGrid and fuwenGrid.id then
  223. addOutFuwen(fuwenGrid)
  224. end
  225. end
  226. -- 返还战意 策划说 当战意遗忘处理
  227. for index = 1, 3 do
  228. local grid = BingshuLogic.getBingshuGrid(heroGrid, index)
  229. if grid then
  230. local config = FuwenExcel.skill[grid.skillID]
  231. if config then
  232. for i = 1, #config.bingshuForgetReturn do
  233. local itemID = config.bingshuForgetReturn[i][1]
  234. local itemCnt = config.bingshuForgetReturn[i][2]
  235. addOutItem(itemID, itemCnt)
  236. end
  237. end
  238. end
  239. end
  240. --返还宝石
  241. local gemCnt = returnGem(heroGrid.gem)
  242. if gemCnt and gemCnt > 0 then
  243. local gemId = HeroDefine.HEROJOBTOGEM[heroConfig.job]
  244. addOutItem(gemId, gemCnt)
  245. end
  246. end
  247. -- 计算打折
  248. local function calcSolveOuts(mainType)
  249. solveOutItem(ItemDefine.ITEM_GREEN_EXP_ID, 1, 0, true)
  250. solveOutItem(ItemDefine.ITEM_HERO_UPGRADE_ID, 1, 0)
  251. --solveOutItem(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, 0.6, 3*SUIJI_CNT)
  252. solveOutItem(ItemDefine.ITEM_JINBI_ID, 1, 120*SUIJI_CNT)
  253. end
  254. -- 计算英雄自身产出
  255. local function calcHeroSelfOut(heroGrid)
  256. local baseValueConfig = HeroExcel.baseValue[heroGrid.star]
  257. for _, item in ipairs(baseValueConfig.items) do
  258. addOutItem(item[1], item[2])
  259. end
  260. addOutItem(ItemDefine.ITEM_GREEN_EXP_ID, baseValueConfig.soul)
  261. addOutItem(ItemDefine.ITEM_HERO_UPGRADE_ID, baseValueConfig.jinjieshi)
  262. addOutItem(ItemDefine.ITEM_SOUL_SUIPIAN_ID, baseValueConfig.suipian)
  263. --英雄身上的宝石返还
  264. end
  265. local function calcHeroOuts(human, mainType, heroIDList, heroIndexList)
  266. cleanOutItems() -- 重置产出信息
  267. for i = 1, heroIDList[0] do
  268. local heroID = heroIDList[i]
  269. local heroIndex = heroIndexList[i]
  270. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  271. calcHeroOut(heroGrid, mainType)
  272. -- 处理遗物
  273. if heroGrid and heroGrid.relic then
  274. WinnerRelicLogic.WinnerRelic_CancelWinner(human, heroGrid, heroIndex)
  275. heroGrid.relic = {}
  276. end
  277. end
  278. -- 材料打折
  279. calcSolveOuts(mainType)
  280. -- 英雄本身价值基数 与 碎片:不打折
  281. if mainType ~= FENJIE_DO_JUEXING then
  282. for i = 1, heroIDList[0] do
  283. local heroID = heroIDList[i]
  284. local heroIndex = heroIndexList[i]
  285. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  286. calcHeroSelfOut(heroGrid)
  287. end
  288. end
  289. if mainType ~= FENJIE_DO and mainType ~= FENJIE_QUERY then
  290. cleanOutItem(ItemDefine.ITEM_SOUL_SUIPIAN_ID)
  291. end
  292. end
  293. -- 发送分解列表
  294. function sendFenjieQuery(human, mainType)
  295. local msgRet = Msg.gc.GC_FENJIE
  296. msgRet.type = mainType
  297. msgRet.itemList[0] = 0
  298. for itemID, itemCnt in Util.pairsByKeys(FENJIE_OUTITEMS) do
  299. msgRet.itemList[0] = msgRet.itemList[0] + 1
  300. Grid.makeItem(msgRet.itemList[msgRet.itemList[0]], itemID, itemCnt)
  301. end
  302. for _, fuwenGrid in ipairs(FENJIE_FUWEN_LIST) do
  303. msgRet.itemList[0] = msgRet.itemList[0] + 1
  304. Grid.makeItem(msgRet.itemList[msgRet.itemList[0]], fuwenGrid.id, 1, nil, fuwenGrid)
  305. end
  306. for _, equipGrid in ipairs(FENJIE_EQUIP_LIST) do
  307. msgRet.itemList[0] = msgRet.itemList[0] + 1
  308. Grid.makeItem(msgRet.itemList[msgRet.itemList[0]], equipGrid.id, 1, nil, equipGrid)
  309. end
  310. --Msg.trace(msgRet)
  311. Msg.send(msgRet, human.fd)
  312. end
  313. -- 分解
  314. function fenjie(human, mainType, heroIDList, heroIndexList, sendNotify, logType)
  315. if not checkCanFenjie(human, heroIDList, heroIndexList) then
  316. return
  317. end
  318. calcHeroOuts(human, mainType, heroIDList, heroIndexList)
  319. -- 给东西
  320. local cnt = 0
  321. if mainType ~= FENJIE_QUERY then
  322. logType = logType or "hero_fenjie"
  323. -- 删除英雄
  324. for i = 1, heroIndexList[0] do
  325. local heroIndex = heroIndexList[i]
  326. HeroLogic.delHeroByIndex(human, heroIndex, logType)
  327. cnt = cnt + 1
  328. end
  329. -- 给东西
  330. giveItems(human, FENJIE_OUTITEMS, FENJIE_FUWEN_LIST, FENJIE_EQUIP_LIST, logType)
  331. end
  332. -- 通知客户端
  333. if sendNotify then
  334. sendFenjieQuery(human, mainType)
  335. end
  336. return FENJIE_OUTITEMS
  337. end
  338. -- 分解碎片
  339. function fenjieChip(human, mainType, itemIdList, itemIdCntList, sendNotify, logType)
  340. if not checkCanFenjieChip(human, itemIdList, itemIdCntList) then
  341. return
  342. end
  343. -- 重置
  344. cleanOutItems()
  345. -- 结算返还材料
  346. for i = 1, itemIdList[0] do
  347. local itemID = itemIdList[i]
  348. local itemCnt = itemIdCntList[i]
  349. local itemConfig = ItemDefine.getConfig(itemID)
  350. if itemConfig then
  351. for k, v in ipairs(itemConfig.material) do
  352. addOutItem(v[1], v[2] * itemCnt)
  353. end
  354. end
  355. end
  356. -- 给东西
  357. if mainType ~= FENJIE_QUERY then
  358. logType = logType or "ship_fenjie"
  359. -- 删除英雄
  360. for i = 1, itemIdList[0] do
  361. local itemID = itemIdList[i]
  362. local itemCnt = itemIdCntList[i]
  363. BagLogic.delItem(human, itemID, itemCnt, logType)
  364. end
  365. -- 给东西
  366. giveItems(human, FENJIE_OUTITEMS, FENJIE_FUWEN_LIST, FENJIE_EQUIP_LIST, logType)
  367. end
  368. -- 通知客户端
  369. if sendNotify then
  370. sendFenjieQuery(human, mainType)
  371. end
  372. return FENJIE_OUTITEMS
  373. end
  374. -- 自动分解三星以下英雄
  375. function autoFenjie(human, heroID, heroCnt, logType)
  376. local heroConfig = HeroExcel.hero[heroID]
  377. if not heroConfig then return end
  378. if heroConfig.star > 3 then return end -- 只有三星以下自动分解
  379. local heroGrid = HeroGrid.getCacheHeroGrid(heroID)
  380. if not heroGrid then return end
  381. cleanOutItems() -- 重置产出信息
  382. calcHeroOut(heroGrid, FENJIE_DO)
  383. calcSolveOuts(FENJIE_DO)
  384. calcHeroSelfOut(heroGrid)
  385. for itemID, itemCnt in pairs(FENJIE_OUTITEMS) do
  386. FENJIE_OUTITEMS[itemID] = FENJIE_OUTITEMS[itemID] * heroCnt
  387. end
  388. -- 给东西
  389. giveItems(human, FENJIE_OUTITEMS, FENJIE_FUWEN_LIST, FENJIE_EQUIP_LIST, logType)
  390. HeroBook.onAddHero(human, heroID, heroGrid.star)
  391. return true, FENJIE_OUTITEMS
  392. end