FenjieLogic.lua 13 KB

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