SuipianLogic.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. -- 碎片逻辑
  2. local ItemExcel = require("excel.item")
  3. local DropExcel = require("excel.drop")
  4. local HeroExcel = require("excel.hero")
  5. local Lang = require("common.Lang")
  6. local Msg = require("core.Msg")
  7. local HeroGrid = require("hero.HeroGrid")
  8. local HeroDefine = require("hero.HeroDefine")
  9. local HeroLogic = require("hero.HeroLogic")
  10. local BagLogic = require("bag.BagLogic")
  11. local ItemDefine = require("bag.ItemDefine")
  12. local DropSpecial = require("bag.DropSpecial")
  13. local Grid = require("bag.Grid")
  14. local Broadcast = require("broadcast.Broadcast")
  15. SUMMON_TYPE_TARGET = 1 -- 指定目标兑换
  16. SUMMON_TYPE_DROP = 2 -- 随机掉落表兑换
  17. SUMMON_TYPE_HERO_SP = 3 -- 英雄条件兑换
  18. SUMMON_TYPE_SHENQI_SP = 4 -- 神器条件兑换
  19. SUMMON_SUBTYPE_MIN = 1
  20. SUMMON_SUBTYPE_HERO = 1 -- 英雄
  21. SUMMON_SUBTYPE_EQUIP = 2 -- 装备
  22. SUMMON_SUBTYPE_SKIN = 3 -- 皮肤
  23. SUMMON_SUBTYPE_TALISAM = 4 --秘宝
  24. SUMMON_SUBTYPE_RELIC = 5 --遗物
  25. SUMMON_SUBTYPE_ELF = 6 -- 精灵
  26. SUMMON_SUBTYPE_MAX = 6
  27. SUMMON_HECHENG_TYPE_GOOD = 11 --可合成物品
  28. function SuipianLogic_CanHeCheng(nID)
  29. if nID == SUMMON_SUBTYPE_HERO or nID == SUMMON_SUBTYPE_SKIN or SUMMON_SUBTYPE_TALISAM == nID
  30. or SUMMON_SUBTYPE_RELIC == nID or SUMMON_SUBTYPE_ELF == nID then
  31. return true
  32. end
  33. return false
  34. end
  35. function SuipianLogic_CanDuiHuang(nID)
  36. return SUMMON_HECHENG_TYPE_GOOD == nID
  37. end
  38. -- 查询
  39. function query(human, itemID)
  40. local itemConfig = ItemExcel.item[itemID]
  41. if itemConfig == nil then return end
  42. if itemConfig.get[1] ~= SUMMON_TYPE_TARGET then
  43. return
  44. end
  45. if itemConfig.get[2] ~= SUMMON_SUBTYPE_HERO then
  46. return
  47. end
  48. local heroID = itemConfig.get[3]
  49. local heroGrid = HeroGrid.getCacheHeroGridTujian(heroID)
  50. if not heroGrid then return end
  51. local msgRet = Msg.gc.GC_SUIPIAN_HERO_QUERY
  52. msgRet.id = itemID
  53. HeroGrid.makeHeroSimple(msgRet.heroSimple, heroGrid, nil, human, nil, true)
  54. --Msg.trace(msgRet)
  55. Msg.send(msgRet, human.fd)
  56. end
  57. -- 合成
  58. function summon(human, itemID, itemUseCnt)
  59. if human.db.bag[itemID] == nil or human.db.bag[itemID] < itemUseCnt then
  60. return
  61. end
  62. local itemConfig = ItemExcel.item[itemID]
  63. if itemConfig == nil then
  64. return
  65. end
  66. if itemConfig.get[1] ~= SUMMON_TYPE_TARGET
  67. and itemConfig.get[1] ~= SUMMON_TYPE_DROP
  68. and itemConfig.get[1] ~= SUMMON_TYPE_HERO_SP
  69. and itemConfig.get[1] ~= SUMMON_TYPE_SHENQI_SP then
  70. return
  71. end
  72. if itemConfig.get[2] < SUMMON_SUBTYPE_MIN or SUMMON_SUBTYPE_MAX < itemConfig.get[2] then
  73. return
  74. end
  75. local leftHeroBox = HeroLogic.getEmptyCnt(human)
  76. -- if itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  77. -- if leftHeroBox <= 0 then
  78. -- return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  79. -- end
  80. -- end
  81. --只有英雄碎片合成才判断英雄背包格子是否足够
  82. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  83. if leftHeroBox <= 0 then
  84. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  85. end
  86. end
  87. local realItemCnt = math.floor(itemUseCnt/itemConfig.fullCnt)
  88. if realItemCnt < 1 then
  89. return
  90. end
  91. if realItemCnt * itemConfig.fullCnt ~= itemUseCnt then
  92. return
  93. end
  94. local isHero = 0
  95. local outItemIDList = nil
  96. local targetID = nil
  97. if itemConfig.get[1] == SUMMON_TYPE_TARGET then
  98. --如果是合成英雄才这么处理
  99. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  100. local leftHeroBox = HeroLogic.getEmptyCnt(human)
  101. if realItemCnt > leftHeroBox then
  102. realItemCnt = leftHeroBox
  103. end
  104. end
  105. -- 指定目标
  106. targetID = itemConfig.get[3]
  107. elseif itemConfig.get[1] == SUMMON_TYPE_DROP then
  108. --如果是合成英雄才这么处理
  109. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  110. local leftHeroBox = HeroLogic.getEmptyCnt(human)
  111. if realItemCnt > leftHeroBox then
  112. realItemCnt = leftHeroBox
  113. end
  114. end
  115. -- 掉落表随机掉落
  116. for i = 1, realItemCnt do
  117. local dropID = itemConfig.get[3]
  118. targetID = getDropTargetID(dropID)
  119. outItemIDList = outItemIDList or {}
  120. outItemIDList[targetID] = outItemIDList[targetID] or 0
  121. outItemIDList[targetID] = outItemIDList[targetID] + 1
  122. end
  123. elseif itemConfig.get[1] == SUMMON_TYPE_HERO_SP then
  124. --如果是合成英雄才这么处理
  125. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  126. local leftHeroBox = HeroLogic.getEmptyCnt(human)
  127. if realItemCnt > leftHeroBox then
  128. realItemCnt = leftHeroBox
  129. end
  130. end
  131. -- 英雄条件兑换
  132. local dropTable = DropSpecial.getDropHeroTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3])
  133. for i = 1, realItemCnt do
  134. local randTemp = math.random(1, #dropTable)
  135. targetID = dropTable[randTemp]
  136. outItemIDList = outItemIDList or {}
  137. outItemIDList[targetID] = outItemIDList[targetID] or 0
  138. outItemIDList[targetID] = outItemIDList[targetID] + 1
  139. end
  140. elseif itemConfig.get[1] == SUMMON_TYPE_SHENQI_SP then
  141. -- 神器条件兑换
  142. local dropTable = DropSpecial.getDropEquipTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3], itemConfig.get[3][4])
  143. for i = 1, realItemCnt do
  144. local randTemp = math.random(1, #dropTable)
  145. targetID = dropTable[randTemp]
  146. outItemIDList = outItemIDList or {}
  147. outItemIDList[targetID] = outItemIDList[targetID] or 0
  148. outItemIDList[targetID] = outItemIDList[targetID] + 1
  149. end
  150. end
  151. if targetID == nil and outItemIDList == nil then
  152. assert(nil)
  153. end
  154. local realSuiPianCnt = realItemCnt * itemConfig.fullCnt
  155. BagLogic.delItem(human, itemID, realSuiPianCnt, "item_summon")
  156. local fenJieList = nil
  157. local itemList = {}
  158. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  159. isHero = 1
  160. if outItemIDList then
  161. -- 多个id
  162. for k, v in pairs(outItemIDList) do
  163. local _, fjlist = HeroLogic.addHero(human, k,nil, v, "item_summon")
  164. local heroID = k
  165. local hero = HeroExcel.hero[heroID]
  166. if fjlist and type(fjlist) == "table" then
  167. for fjItemID, fjItemCnt in pairs(fjlist) do
  168. fenJieList = fenJieList or {}
  169. fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  170. end
  171. end
  172. end
  173. else
  174. -- 单个id
  175. local _, fjlist = HeroLogic.addHero(human, targetID,nil, realItemCnt, "item_summon")
  176. local heroID = targetID
  177. local hero = HeroExcel.hero[heroID]
  178. if fjlist and type(fjlist) == "table" then
  179. for fjItemID, fjItemCnt in pairs(fjlist) do
  180. fenJieList = fenJieList or {}
  181. fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  182. end
  183. end
  184. end
  185. else
  186. if outItemIDList then
  187. -- 多个id
  188. for k, v in pairs(outItemIDList) do
  189. BagLogic.addItem(human, k, v, "item_summon")
  190. itemList[k] = itemList[k] or 0
  191. itemList[k] = itemList[k] + v
  192. end
  193. else
  194. -- 单个id
  195. BagLogic.addItem(human, targetID, realItemCnt, "item_summon")
  196. itemList[targetID] = itemList[targetID] or 0
  197. itemList[targetID] = itemList[targetID] + realItemCnt
  198. end
  199. end
  200. BagLogic.sendItemGetList(human, itemList, "item_summon")
  201. local msgRet = Msg.gc.GC_SUIPIAN_SUMMON
  202. msgRet.isHero = isHero
  203. msgRet.list[0] = 0
  204. msgRet.heroList[0] = 0
  205. msgRet.fenJieList[0] = 0
  206. local netList = (isHero == 1) and msgRet.heroList or msgRet.list
  207. if outItemIDList then
  208. -- 多个id
  209. for k, v in pairs(outItemIDList) do
  210. netList[0] = netList[0] + 1
  211. makeResultItemData(netList[netList[0]], k, v, isHero)
  212. end
  213. else
  214. netList[0] = netList[0] + 1
  215. makeResultItemData(netList[netList[0]], targetID, realItemCnt, isHero)
  216. end
  217. if fenJieList then
  218. for fjItemID, fjItemCnt in pairs(fenJieList) do
  219. msgRet.fenJieList[0] = msgRet.fenJieList[0] + 1
  220. Grid.makeItem(msgRet.fenJieList[msgRet.fenJieList[0]], fjItemID, fjItemCnt)
  221. end
  222. end
  223. --Msg.trace(msgRet)
  224. Msg.send(msgRet, human.fd)
  225. end
  226. function makeResultItemData(net, id, cnt, isHero)
  227. if isHero == 1 then
  228. HeroGrid.makeHeroSimpleByID(net, id)
  229. net.cnt = cnt
  230. else
  231. --Grid.makeItem(net, id, cnt)
  232. Grid.makeItem(net, id, cnt, nil,nil,nil, Grid.getOpflagAtBag(id))
  233. end
  234. end
  235. -- 根据掉落id 获取id
  236. function getDropTargetID(dropID)
  237. local dropConfig = DropExcel.dropSuipian[dropID]
  238. if dropConfig == nil then
  239. return
  240. end
  241. -- 计算总权重
  242. local totalWeight = 0
  243. for k, v in ipairs(dropConfig.dropRule) do
  244. local weight = v[2]
  245. totalWeight = totalWeight + weight
  246. end
  247. local heroWeight = nil
  248. local r = math.random(1, totalWeight)
  249. for k, v in ipairs(dropConfig.dropRule) do
  250. local weight = v[2]
  251. if r <= weight then
  252. heroWeight = v[1]
  253. break
  254. else
  255. r = r - weight
  256. end
  257. end
  258. if heroWeight == nil then
  259. assert()
  260. end
  261. local len = #dropConfig.camp
  262. local index = math.random(1, len)
  263. local heroID = HeroDefine.getRandHeroByWeightLvAndCamp(heroWeight, dropConfig.camp[index])
  264. return heroID
  265. end
  266. local function queryBoxList(human, itemConfig)
  267. local itemList = itemConfig.cmd[2]
  268. if not itemList then return end
  269. local msgRet = Msg.gc.GC_SUIPIAN_ITEM_SUMMON_QUERY
  270. msgRet.items[0] = #itemList
  271. for i = 1, msgRet.items[0] do
  272. local itemID = itemList[i][1]
  273. local itemCnt = itemList[i][2]
  274. local quality = itemList[i][3]
  275. Grid.makeItem(msgRet.items[i], itemID, itemCnt, nil, nil, nil, nil, quality)
  276. end
  277. Msg.send(msgRet, human.fd)
  278. end
  279. --碎片英雄召唤预览
  280. function CG_SUIPIAN_HERO_SUMMON_QUERY(human, itemID)
  281. local itemConfig = ItemExcel.item[itemID]
  282. if not itemConfig then return end
  283. local cmdStr = itemConfig.cmd[1]
  284. if cmdStr == "box" or cmdStr == "boxAll" then
  285. return queryBoxList(human, itemConfig)
  286. end
  287. if itemConfig.get[1] ~= SUMMON_TYPE_TARGET
  288. and itemConfig.get[1] ~= SUMMON_TYPE_DROP
  289. and itemConfig.get[1] ~= SUMMON_TYPE_HERO_SP
  290. and itemConfig.get[1] ~= SUMMON_TYPE_SHENQI_SP then
  291. return
  292. end
  293. if itemConfig.get[2] ~= SUMMON_SUBTYPE_HERO and itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  294. return
  295. end
  296. local realItemCnt = 1
  297. if human.db.bag[itemID] ~= nil then
  298. realItemCnt = math.floor(human.db.bag[itemID])
  299. end
  300. if realItemCnt < 1 then
  301. return
  302. end
  303. local outItemIDList = nil
  304. local targetID = nil
  305. if itemConfig.get[1] == SUMMON_TYPE_TARGET then
  306. -- 指定目标
  307. targetID = itemConfig.get[3]
  308. elseif itemConfig.get[1] == SUMMON_TYPE_DROP then
  309. local dropID = itemConfig.get[3]
  310. local dropConfig = DropExcel.dropSuipian[dropID]
  311. if dropConfig == nil then
  312. return
  313. end
  314. local totalCnt = #dropConfig.dropRule
  315. local heroWeight
  316. local weightLvAndCampHeros = nil
  317. for i=1,totalCnt do
  318. targetID = dropConfig.dropRule[i]
  319. heroWeight = targetID[1]
  320. for _, camp in ipairs(dropConfig.camp) do
  321. weightLvAndCampHeros = HeroDefine.getHeroByWeightLvAndCamp(heroWeight, camp)
  322. for k, v in pairs(weightLvAndCampHeros) do
  323. outItemIDList = outItemIDList or {}
  324. outItemIDList[v] = outItemIDList[v] or 0
  325. outItemIDList[v] = outItemIDList[v] + 1
  326. end
  327. end
  328. end
  329. elseif itemConfig.get[1] == SUMMON_TYPE_HERO_SP then
  330. -- 英雄条件兑换
  331. local dropTable = DropSpecial.getDropHeroTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3])
  332. for i = 1, realItemCnt do
  333. local randTemp = math.random(1, #dropTable)
  334. targetID = dropTable[randTemp]
  335. outItemIDList = outItemIDList or {}
  336. outItemIDList[targetID] = outItemIDList[targetID] or 0
  337. outItemIDList[targetID] = outItemIDList[targetID] + 1
  338. end
  339. elseif itemConfig.get[1] == SUMMON_TYPE_SHENQI_SP then
  340. -- 神器条件兑换
  341. local dropTable = DropSpecial.getDropEquipTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3], itemConfig.get[3][4])
  342. for i = 1, realItemCnt do
  343. local randTemp = math.random(1, #dropTable)
  344. targetID = dropTable[randTemp]
  345. outItemIDList = outItemIDList or {}
  346. outItemIDList[targetID] = outItemIDList[targetID] or 0
  347. outItemIDList[targetID] = outItemIDList[targetID] + 1
  348. end
  349. end
  350. if targetID == nil and outItemIDList == nil then
  351. assert(nil)
  352. end
  353. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  354. local msgRet = Msg.gc.GC_SUIPIAN_HERO_SUMMON_QUERY
  355. if outItemIDList then
  356. local len = 0
  357. for heroID, _ in pairs(outItemIDList) do
  358. if heroID and HeroExcel.hero[heroID] == nil then
  359. assert(nil, "why heroID no config " .. heroID .. " " .. itemID)
  360. end
  361. if len >= 50 then
  362. break
  363. end
  364. len = len + 1
  365. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[len], heroID)
  366. end
  367. msgRet.heroSimple[0] = len
  368. else
  369. local heroID = targetID
  370. msgRet.heroSimple[0] = 1
  371. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[1], heroID)
  372. end
  373. Msg.send(msgRet, human.fd)
  374. else
  375. local msgRet = Msg.gc.GC_SUIPIAN_ITEM_SUMMON_QUERY
  376. local cnt = 0
  377. if outItemIDList then
  378. for k, v in pairs(outItemIDList) do
  379. cnt = cnt + 1
  380. Grid.makeItem(msgRet.items[cnt], k, v)
  381. end
  382. if cnt > 0 then
  383. msgRet.items[0] = cnt
  384. Msg.send(msgRet, human.fd)
  385. end
  386. else
  387. msgRet.items[0] = 1
  388. Grid.makeItem(msgRet.items[1], targetID, 1)
  389. Msg.send(msgRet, human.fd)
  390. end
  391. end
  392. end
  393. local HEROID_2_SUIPIANID = nil
  394. function getSuipianIDbyHeroID(heroID)
  395. if not HEROID_2_SUIPIANID then
  396. HEROID_2_SUIPIANID = {}
  397. for itemID, itemConfig in pairs(ItemExcel.item) do
  398. if itemConfig.get[1] == SUMMON_TYPE_TARGET and
  399. itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  400. local targetID = itemConfig.get[3]
  401. HEROID_2_SUIPIANID[targetID] = itemID
  402. end
  403. end
  404. end
  405. return HEROID_2_SUIPIANID[heroID]
  406. end
  407. -- 碎片合成
  408. -- itemID 合成消耗物品ID
  409. -- itemUseCnt 合成消耗物品当前数量
  410. -- function SUIPIAN_SYNTHESIS(human, itemID, itemUseCnt)
  411. -- if human.db.bag[itemID] == nil or human.db.bag[itemID] < itemUseCnt then
  412. -- return
  413. -- end
  414. -- local itemConfig = ItemExcel.item[itemID]
  415. -- if itemConfig == nil then
  416. -- return
  417. -- end
  418. -- local leftHeroBox = HeroLogic.getEmptyCnt(human)
  419. -- if itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  420. -- if leftHeroBox <= 0 then
  421. -- return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  422. -- end
  423. -- end
  424. -- local realItemCnt = math.floor(itemUseCnt/itemConfig.fullCnt)
  425. -- if realItemCnt < 1 then
  426. -- return
  427. -- end
  428. -- local isHero = 0
  429. -- local outItemIDList = nil
  430. -- local targetID = nil
  431. -- if itemConfig.get[1] == SUMMON_TYPE_TARGET then
  432. -- --local leftHeroBox = HeroLogic.getEmptyCnt(human)
  433. -- if realItemCnt > leftHeroBox then
  434. -- realItemCnt = leftHeroBox
  435. -- end
  436. -- -- 指定目标
  437. -- targetID = itemConfig.get[3]
  438. -- elseif itemConfig.get[1] == SUMMON_TYPE_DROP then
  439. -- if itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  440. -- --local leftHeroBox = HeroLogic.getEmptyCnt(human)
  441. -- if realItemCnt > leftHeroBox then
  442. -- realItemCnt = leftHeroBox
  443. -- end
  444. -- end
  445. -- -- 掉落表随机掉落
  446. -- for i = 1, realItemCnt do
  447. -- local dropID = itemConfig.get[3]
  448. -- targetID = getDropTargetID(dropID)
  449. -- if nil == targetID then
  450. -- print("[SUIPIAN_SYNTHESIS] 获取目标ID失败 dropID = "..dropID)
  451. -- return
  452. -- end
  453. -- outItemIDList = outItemIDList or {}
  454. -- outItemIDList[targetID] = outItemIDList[targetID] or 0
  455. -- outItemIDList[targetID] = outItemIDList[targetID] + 1
  456. -- end
  457. -- elseif itemConfig.get[1] == SUMMON_TYPE_HERO_SP then
  458. -- --local leftHeroBox = HeroLogic.getEmptyCnt(human)
  459. -- if realItemCnt > leftHeroBox then
  460. -- realItemCnt = leftHeroBox
  461. -- end
  462. -- local dropTable = DropSpecial.getDropHeroTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3])
  463. -- for i = 1, realItemCnt do
  464. -- local randTemp = math.random(1, #dropTable)
  465. -- targetID = dropTable[randTemp]
  466. -- outItemIDList = outItemIDList or {}
  467. -- outItemIDList[targetID] = outItemIDList[targetID] or 0
  468. -- outItemIDList[targetID] = outItemIDList[targetID] + 1
  469. -- end
  470. -- elseif itemConfig.get[1] == SUMMON_TYPE_SHENQI_SP then
  471. -- local dropTable = DropSpecial.getDropEquipTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3], itemConfig.get[3][4])
  472. -- for i = 1, realItemCnt do
  473. -- local randTemp = math.random(1, #dropTable)
  474. -- targetID = dropTable[randTemp]
  475. -- outItemIDList = outItemIDList or {}
  476. -- outItemIDList[targetID] = outItemIDList[targetID] or 0
  477. -- outItemIDList[targetID] = outItemIDList[targetID] + 1
  478. -- end
  479. -- end
  480. -- if targetID == nil and outItemIDList == nil then
  481. -- assert(nil)
  482. -- end
  483. -- local realSuiPianCnt = realItemCnt * itemConfig.fullCnt
  484. -- BagLogic.delItem(human, itemID, realSuiPianCnt, "item_summon")
  485. -- print("[SUIPIAN_SYNTHESIS] 实际上删除的碎片数量 realItemCnt = "
  486. -- ..realItemCnt.. " realSuiPianCnt = "..realSuiPianCnt.. " itemUseCnt = "..itemUseCnt)
  487. -- local fenJieList = nil
  488. -- local itemList = {}
  489. -- if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  490. -- isHero = 1
  491. -- if outItemIDList then
  492. -- -- 多个id
  493. -- for k, v in pairs(outItemIDList) do
  494. -- local _, fjlist = HeroLogic.addHero(human, k,nil, v, "item_summon")
  495. -- local heroID = k
  496. -- local hero = HeroExcel.hero[heroID]
  497. -- if fjlist and type(fjlist) == "table" then
  498. -- for fjItemID, fjItemCnt in pairs(fjlist) do
  499. -- fenJieList = fenJieList or {}
  500. -- fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  501. -- end
  502. -- end
  503. -- end
  504. -- else
  505. -- -- 单个id
  506. -- local _, fjlist = HeroLogic.addHero(human, targetID,nil, realItemCnt, "item_summon")
  507. -- local heroID = targetID
  508. -- local hero = HeroExcel.hero[heroID]
  509. -- if fjlist and type(fjlist) == "table" then
  510. -- for fjItemID, fjItemCnt in pairs(fjlist) do
  511. -- fenJieList = fenJieList or {}
  512. -- fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  513. -- end
  514. -- end
  515. -- end
  516. -- else
  517. -- if outItemIDList then
  518. -- -- 多个id
  519. -- for k, v in pairs(outItemIDList) do
  520. -- BagLogic.addItem(human, k, v, "item_summon")
  521. -- itemList[k] = itemList[k] or 0
  522. -- itemList[k] = itemList[k] + v
  523. -- end
  524. -- else
  525. -- -- 单个id
  526. -- BagLogic.addItem(human, targetID, realItemCnt, "item_summon")
  527. -- itemList[targetID] = itemList[targetID] or 0
  528. -- itemList[targetID] = itemList[targetID] + realItemCnt
  529. -- end
  530. -- end
  531. -- BagLogic.sendItemGetList(human, itemList, "item_summon")
  532. -- local msgRet = Msg.gc.GC_SUIPIAN_SUMMON
  533. -- msgRet.isHero = isHero
  534. -- msgRet.list[0] = 0
  535. -- msgRet.heroList[0] = 0
  536. -- msgRet.fenJieList[0] = 0
  537. -- local netList = (isHero == 1) and msgRet.heroList or msgRet.list
  538. -- if outItemIDList then
  539. -- -- 多个id
  540. -- for k, v in pairs(outItemIDList) do
  541. -- netList[0] = netList[0] + 1
  542. -- makeResultItemData(netList[netList[0]], k, v, isHero)
  543. -- print("[SUIPIAN_SYNTHESIS] 合成的数量 英雄ID k = "
  544. -- ..k .. " v ="..v.." cnt = "..netList[netList[0]].cnt)
  545. -- end
  546. -- else
  547. -- netList[0] = netList[0] + 1
  548. -- makeResultItemData(netList[netList[0]], targetID, realItemCnt, isHero)
  549. -- print("[SUIPIAN_SYNTHESIS] 合成的数量 英雄ID targetID = "
  550. -- ..targetID .." realItemCnt = "..realItemCnt.. " cnt = "..netList[netList[0]].cnt)
  551. -- end
  552. -- if fenJieList then
  553. -- for fjItemID, fjItemCnt in pairs(fenJieList) do
  554. -- msgRet.fenJieList[0] = msgRet.fenJieList[0] + 1
  555. -- Grid.makeItem(msgRet.fenJieList[msgRet.fenJieList[0]], fjItemID, fjItemCnt)
  556. -- end
  557. -- end
  558. -- --Msg.trace(msgRet)
  559. -- Msg.send(msgRet, human.fd)
  560. -- end
  561. -- 通用合成碎片具体逻辑
  562. function Suipan_BeginSyntheticFragments(human, nItemID, nItemNum, tMsgData)
  563. if human.db.bag[nItemID] == nil or human.db.bag[nItemID] < nItemNum then
  564. return false
  565. end
  566. local itemConfig = ItemExcel.item[nItemID]
  567. if itemConfig == nil then
  568. return false
  569. end
  570. local leftHeroBox = HeroLogic.getEmptyCnt(human)
  571. if itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  572. if leftHeroBox <= 0 and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN then
  573. return false
  574. end
  575. end
  576. local realItemCnt = math.floor(nItemNum/itemConfig.fullCnt)
  577. if realItemCnt < 1 then
  578. return false
  579. end
  580. local isHero = 0
  581. local outItemIDList = nil
  582. local targetID = nil
  583. if itemConfig.get[1] == SUMMON_TYPE_TARGET then
  584. if realItemCnt > leftHeroBox and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN then
  585. realItemCnt = leftHeroBox
  586. end
  587. -- 指定目标
  588. targetID = itemConfig.get[3]
  589. elseif itemConfig.get[1] == SUMMON_TYPE_DROP then
  590. if itemConfig.get[2] ~= SUMMON_SUBTYPE_EQUIP then
  591. if realItemCnt > leftHeroBox and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN then
  592. realItemCnt = leftHeroBox
  593. end
  594. end
  595. -- 掉落表随机掉落
  596. for i = 1, realItemCnt do
  597. local dropID = itemConfig.get[3]
  598. targetID = getDropTargetID(dropID)
  599. if nil == targetID then
  600. print("[Suipan_BeginSyntheticFragments] 获取目标ID失败 dropID = "..dropID)
  601. return false
  602. end
  603. outItemIDList = outItemIDList or {}
  604. outItemIDList[targetID] = outItemIDList[targetID] or 0
  605. outItemIDList[targetID] = outItemIDList[targetID] + 1
  606. end
  607. elseif itemConfig.get[1] == SUMMON_TYPE_HERO_SP then
  608. if realItemCnt > leftHeroBox and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN then
  609. realItemCnt = leftHeroBox
  610. end
  611. local dropTable = DropSpecial.getDropHeroTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3])
  612. for i = 1, realItemCnt do
  613. local randTemp = math.random(1, #dropTable)
  614. targetID = dropTable[randTemp]
  615. outItemIDList = outItemIDList or {}
  616. outItemIDList[targetID] = outItemIDList[targetID] or 0
  617. outItemIDList[targetID] = outItemIDList[targetID] + 1
  618. end
  619. elseif itemConfig.get[1] == SUMMON_TYPE_SHENQI_SP then
  620. local dropTable = DropSpecial.getDropEquipTable(itemConfig.get[3][1], itemConfig.get[3][2], itemConfig.get[3][3], itemConfig.get[3][4])
  621. for i = 1, realItemCnt do
  622. local randTemp = math.random(1, #dropTable)
  623. targetID = dropTable[randTemp]
  624. outItemIDList = outItemIDList or {}
  625. outItemIDList[targetID] = outItemIDList[targetID] or 0
  626. outItemIDList[targetID] = outItemIDList[targetID] + 1
  627. end
  628. end
  629. if targetID == nil and outItemIDList == nil then
  630. -- assert(nil)
  631. return false
  632. end
  633. local realSuiPianCnt = realItemCnt * itemConfig.fullCnt
  634. BagLogic.delItem(human, nItemID, realSuiPianCnt, "item_summon")
  635. print("[Suipan_BeginSyntheticFragments] 实际上删除的碎片数量 realItemCnt = "
  636. ..realItemCnt.. " itemID" .. nItemID.. " realSuiPianCnt = "..realSuiPianCnt.. " nItemNum = "..nItemNum)
  637. local fenJieList = nil
  638. local itemList = {}
  639. if itemConfig.get[2] == SUMMON_SUBTYPE_HERO then
  640. isHero = 1
  641. if outItemIDList then
  642. -- 多个id
  643. for k, v in pairs(outItemIDList) do
  644. local _, fjlist = HeroLogic.addHero(human, k,nil, v, "item_summon")
  645. local heroID = k
  646. local hero = HeroExcel.hero[heroID]
  647. if fjlist and type(fjlist) == "table" then
  648. for fjItemID, fjItemCnt in pairs(fjlist) do
  649. fenJieList = fenJieList or {}
  650. fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  651. end
  652. end
  653. end
  654. else
  655. -- 单个id
  656. local _, fjlist = HeroLogic.addHero(human, targetID,nil, realItemCnt, "item_summon")
  657. local heroID = targetID
  658. local hero = HeroExcel.hero[heroID]
  659. if fjlist and type(fjlist) == "table" then
  660. for fjItemID, fjItemCnt in pairs(fjlist) do
  661. fenJieList = fenJieList or {}
  662. fenJieList[fjItemID] = (fenJieList[fjItemID] or 0) + fjItemCnt
  663. end
  664. end
  665. end
  666. else
  667. if outItemIDList then
  668. -- 多个id
  669. for k, v in pairs(outItemIDList) do
  670. BagLogic.addItem(human, k, v, "item_summon")
  671. itemList[k] = itemList[k] or 0
  672. itemList[k] = itemList[k] + v
  673. end
  674. else
  675. -- 单个id
  676. BagLogic.addItem(human, targetID, realItemCnt, "item_summon")
  677. itemList[targetID] = itemList[targetID] or 0
  678. itemList[targetID] = itemList[targetID] + realItemCnt
  679. end
  680. end
  681. BagLogic.sendItemGetList(human, itemList, "item_summon")
  682. local netList = (isHero == 1) and tMsgData.heroList or tMsgData.list
  683. if outItemIDList then
  684. -- 多个id
  685. for k, v in pairs(outItemIDList) do
  686. netList[0] = netList[0] + 1
  687. makeResultItemData(netList[netList[0]], k, v, isHero)
  688. print("[Suipan_BeginSyntheticFragments] 合成的数量 道具ID k = "
  689. ..k .. " v ="..v.." cnt = "..netList[netList[0]].cnt)
  690. end
  691. else
  692. netList[0] = netList[0] + 1
  693. makeResultItemData(netList[netList[0]], targetID, realItemCnt, isHero)
  694. print("[Suipan_BeginSyntheticFragments] 合成的数量 道具ID targetID = "
  695. ..targetID .." realItemCnt = "..realItemCnt.. " cnt = "..netList[netList[0]].cnt)
  696. end
  697. if fenJieList then
  698. for fjItemID, fjItemCnt in pairs(fenJieList) do
  699. tMsgData.fenJieList[0] = tMsgData.fenJieList[0] + 1
  700. Grid.makeItem(tMsgData.fenJieList[tMsgData.fenJieList[0]], fjItemID, fjItemCnt)
  701. end
  702. end
  703. return true
  704. --Msg.trace(msgRet)
  705. --Msg.send(msgRet, human.fd)
  706. end
  707. -- 碎片合成
  708. function SUIPIAN_SYNTHESIS(human, tCompositeTable, isHaveHero)
  709. if not human or nil == tCompositeTable or nil == _G.next(tCompositeTable) then
  710. return false
  711. end
  712. -- 英雄背包空余格子数
  713. local nLefeHeroNum = HeroLogic.getEmptyCnt(human)
  714. if 0 >= nLefeHeroNum and isHaveHero then
  715. Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  716. print("[SUIPIAN_SYNTHESIS] 背包格子不够直接返回 nLefeHeroNum = "..nLefeHeroNum)
  717. return false
  718. end
  719. -- 检查一次数量信息
  720. local nAllnum = 0
  721. for nID, nNum in pairs(tCompositeTable) do
  722. if human.db.bag[nID] == nil or human.db.bag[nID] < nNum then
  723. print("[SUIPIAN_SYNTHESIS] 背包中数量不正确,无法合成直接返回 nID = "..nID.." nNum = "..nNum)
  724. return false
  725. end
  726. local itemConfig = ItemExcel.item[nID]
  727. if itemConfig == nil then
  728. print("[SUIPIAN_SYNTHESIS] 不存在对应物品的配置 nID = "..nID.." nNum = "..nNum)
  729. return false
  730. end
  731. local nRealNum = math.floor(nNum / itemConfig.fullCnt)
  732. if 0 >= nRealNum then
  733. print("[SUIPIAN_SYNTHESIS] 真实生成的数量不正确 nID = "
  734. ..nID.." nNum = "..nNum.." fullCnt = "..itemConfig.fullCnt)
  735. return false
  736. end
  737. print("[SUIPIAN_SYNTHESIS] 进行合成的碎片信息 nID = "..nID.." nNum = "..nNum)
  738. nAllnum = nAllnum + 1
  739. end
  740. if nAllnum >= 100 then
  741. print("[SUIPIAN_SYNTHESIS] 真实生成的数量大于了协议生成最大长度 nAllnum = "..nAllnum)
  742. return false
  743. end
  744. local msgRet = Msg.gc.GC_SUIPIAN_SUMMON
  745. msgRet.isHero = isHaveHero and 1 or 0
  746. msgRet.list[0] = 0
  747. msgRet.heroList[0] = 0
  748. msgRet.fenJieList[0] = 0
  749. -- 正式开始正式生成
  750. for nID, nNum in pairs(tCompositeTable) do
  751. -- 不存在剩余空位
  752. if 0 >= nLefeHeroNum and isHaveHero then
  753. break
  754. end
  755. local itemConfig = ItemExcel.item[nID]
  756. if itemConfig then
  757. if isHaveHero then
  758. local nCanCreateNum = math.floor(nNum / itemConfig.fullCnt)
  759. if nCanCreateNum > nLefeHeroNum then
  760. nCanCreateNum = nLefeHeroNum
  761. end
  762. nLefeHeroNum = nLefeHeroNum - nCanCreateNum
  763. end
  764. local bRet = Suipan_BeginSyntheticFragments(human, nID, nNum, msgRet)
  765. if false == bRet then
  766. print("[SUIPIAN_SYNTHESIS] 合成碎片失败 nID = "..nID.." nNum = "..nNum)
  767. break
  768. end
  769. else
  770. print("[SUIPIAN_SYNTHESIS] 检测过居然还不存在对应物品的配置 nID = "..nID.." nNum = "..nNum)
  771. end
  772. end
  773. Msg.send(msgRet, human.fd)
  774. end
  775. function CG_SUIPIAN_SYNTHESIS(human, synthesisType)
  776. if not synthesisType or synthesisType < SUMMON_SUBTYPE_HERO or synthesisType > SUMMON_SUBTYPE_ELF then
  777. print("[CG_SUIPIAN_SYNTHESIS] 合成类型错误 synthesisType = "..synthesisType)
  778. return
  779. end
  780. --目前只有三种碎片能合成
  781. if synthesisType ~= SUMMON_SUBTYPE_HERO and
  782. synthesisType ~= SUMMON_SUBTYPE_TALISAM and
  783. synthesisType ~= SUMMON_SUBTYPE_RELIC and
  784. synthesisType ~= SUMMON_SUBTYPE_ELF then
  785. print("[CG_SUIPIAN_SYNTHESIS] 合成类型错误 synthesisType = "..synthesisType)
  786. return
  787. end
  788. local msgRet = Msg.gc.GC_SUIPIAN_SYNTHESIS
  789. local status = 1
  790. local isHaveHero = false
  791. local tCompositeTable = {}
  792. -- for itemID,itemCnt in pairs(human.db.bag) do
  793. -- local itemConfig = ItemExcel.item[itemID]
  794. -- if itemConfig ~= nil and
  795. -- itemConfig.mainType == ItemDefine.MAINTYPE_ITEM and
  796. -- (itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  797. -- itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_TALISMAM) then
  798. -- if itemCnt >= itemConfig.fullCnt then
  799. -- tCompositeTable[itemID] = tCompositeTable[itemID] or 0
  800. -- tCompositeTable[itemID] = tCompositeTable[itemID] + itemCnt
  801. -- if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN then
  802. -- isHaveHero = true
  803. -- end
  804. -- end
  805. -- end
  806. -- end
  807. --后续可以优化下,把值对应起来
  808. local targetSubType = 0
  809. if synthesisType == SUMMON_SUBTYPE_HERO then
  810. targetSubType = ItemDefine.ITEM_SUBTYPE_SUIPIAN
  811. elseif synthesisType == SUMMON_SUBTYPE_TALISAM then
  812. targetSubType = ItemDefine.ITEM_SUBTYPE_SUIPIAN_TALISMAM
  813. elseif synthesisType == SUMMON_SUBTYPE_RELIC then
  814. targetSubType = ItemDefine.ITEM_SUBTYPE_SUIPIAN_RELIC
  815. elseif synthesisType == SUMMON_SUBTYPE_ELF then
  816. targetSubType = ItemDefine.ITEM_SUBTYPE_SUIPIAN_ELF
  817. end
  818. for itemID,itemCnt in pairs(human.db.bag) do
  819. local itemConfig = ItemExcel.item[itemID]
  820. if itemConfig and itemConfig.mainType == ItemDefine.MAINTYPE_ITEM and itemCnt >= itemConfig.fullCnt then
  821. if itemConfig.subType == targetSubType then
  822. tCompositeTable[itemID] = tCompositeTable[itemID] or 0
  823. tCompositeTable[itemID] = tCompositeTable[itemID] + itemCnt
  824. if synthesisType == SUMMON_SUBTYPE_HERO then
  825. isHaveHero = true
  826. end
  827. end
  828. end
  829. end
  830. if nil ~= _G.next(tCompositeTable) then
  831. status = 0
  832. SUIPIAN_SYNTHESIS(human, tCompositeTable, isHaveHero)
  833. end
  834. msgRet.status = status
  835. Msg.send(msgRet, human.fd)
  836. end
  837. function SuiPianLogic_DuiHuangQuery(human, nID)
  838. local itemConfig = ItemDefine.getConfig(nID)
  839. if not itemConfig then
  840. return
  841. end
  842. local tGetInfo = itemConfig.get
  843. if nil == _G.next(tGetInfo) then
  844. return
  845. end
  846. if tGetInfo[1] ~= SUMMON_TYPE_TARGET or tGetInfo[2] ~= SUMMON_HECHENG_TYPE_GOOD then
  847. return
  848. end
  849. local tTargetID = tGetInfo[3]
  850. local nUseNum = itemConfig.nUseNum
  851. if 0 >= nUseNum then
  852. return
  853. end
  854. local tMsgData = Msg.gc.GC_DUIHUANG_QUERY
  855. tMsgData.nUseNum = nUseNum
  856. Grid.makeItem(tMsgData.ItemData, tTargetID, itemConfig.nGetNum)
  857. Msg.send(tMsgData, human.fd)
  858. end
  859. function SuiPianLogic_DuiHuangDo(human, nID, nTargetNum)
  860. local itemConfig = ItemDefine.getConfig(nID)
  861. if not itemConfig then
  862. return
  863. end
  864. local tGetInfo = itemConfig.get
  865. if nil == _G.next(tGetInfo) then
  866. return
  867. end
  868. if tGetInfo[1] ~= SUMMON_TYPE_TARGET or tGetInfo[2] ~= SUMMON_HECHENG_TYPE_GOOD then
  869. return
  870. end
  871. local nUseNum = nTargetNum * itemConfig.nUseNum
  872. if 0 >= nUseNum or nUseNum > BagLogic.getItemCnt(human, nID) then
  873. return
  874. end
  875. local nAddNum = nTargetNum * itemConfig.nGetNum
  876. -- print("[SuiPianLogic_DuiHuangDo]")
  877. BagLogic.delItem(human, nID, nUseNum, "item_hecheng")
  878. BagLogic.addItemList(human, {{tGetInfo[3], nAddNum}}, "item_hecheng")
  879. end