FenjieLogic.lua 13 KB

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