FenjieLogic.lua 12 KB

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