SuipianLogic.lua 31 KB

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