FenjieLogic.lua 12 KB

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