HeroEquip.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. -- 英雄装备相关逻辑
  2. local Lang = require("common.Lang")
  3. local HeroExcel = require("excel.hero")
  4. local EquipExcel = require("excel.equip")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local HeroDefine = require("hero.HeroDefine")
  8. local HeroLogic = require("hero.HeroLogic")
  9. local ItemDefine = require("bag.ItemDefine")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local RoleAttr = require("role.RoleAttr")
  14. local Util = require("common.Util")
  15. local ItemExcel = require("excel.item").item
  16. local FuwenLogic = require("fuwen.FuwenLogic")
  17. local EquipLogic = require("equip.EquipLogic")
  18. function query(human, heroID, heroIndex)
  19. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  20. if heroGrid == nil then
  21. return
  22. end
  23. local msgRet = Msg.gc.GC_HERO_EQUIP_QUERY
  24. msgRet.id = heroID
  25. msgRet.index = heroIndex
  26. local cnt = 0
  27. for i = 1, ItemDefine.EQUIP_MAX_CNT do
  28. local equipGrid = heroGrid.equip and heroGrid.equip[i]
  29. if equipGrid then
  30. cnt = cnt + 1
  31. if i == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then -- 水晶比较特殊
  32. Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, heroGrid.shuijingAttrID)
  33. else
  34. Grid.makeItem(msgRet.equips[cnt], equipGrid.id, 1, nil, equipGrid, -1, Grid.getOpflagAtBag(heroGrid.equip[i].id))
  35. end
  36. end
  37. local dot = isEquipDotByPos(human, heroGrid, i)
  38. msgRet.equipDot[i] = dot or 0
  39. end
  40. msgRet.equipDot[0] = ItemDefine.EQUIP_MAX_CNT
  41. msgRet.equips[0] = cnt
  42. cnt = 0
  43. for i = 1, 2 do
  44. -- 尝试解锁符文
  45. FuwenLogic.fuwenGridUnlock(human, heroID, heroIndex, i)
  46. if heroGrid.fuwen and
  47. heroGrid.fuwen[i] and
  48. heroGrid.fuwen[i].id ~= nil then
  49. cnt = cnt + 1
  50. msgRet.fuwens[cnt].pos = i
  51. Grid.makeItem(msgRet.fuwens[cnt].fuwen, heroGrid.fuwen[i].id, 1,nil,heroGrid.fuwen[i],-1, Grid.getOpflagAtBag(heroGrid.fuwen[i].id))
  52. end
  53. msgRet.fuwenGrid[i] = 1
  54. if heroGrid.fuwen == nil or
  55. heroGrid.fuwen[i] == nil then
  56. msgRet.fuwenGrid[i] = 0
  57. end
  58. local dot = FuwenLogic.isFuwenDotByPos(human, heroGrid, i) == true and 1 or 0
  59. msgRet.fuwenDot[i] = dot
  60. end
  61. msgRet.fuwenGrid[0] = 2
  62. msgRet.fuwenDot[0] = 2
  63. msgRet.fuwens[0] = cnt
  64. Msg.send(msgRet, human.fd)
  65. end
  66. function putOn(human, heroID, heroIndex, bagIndex, noCalc)
  67. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  68. if heroGrid == nil then return end
  69. if bagIndex == 0 then return end
  70. local equipGrid = human.db.equipBag[bagIndex]
  71. if not equipGrid or type(equipGrid) ~= "table" then return end
  72. local equipID = equipGrid.id
  73. local equipConfig = EquipExcel.equip[equipID]
  74. if equipConfig == nil then return end
  75. if heroGrid.star < equipConfig.star then
  76. local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
  77. return Broadcast.sendErr(human, errDesc)
  78. end
  79. local pos = equipConfig.subType
  80. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  81. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  82. msgRet.heroID = heroID
  83. msgRet.heroIndex = heroIndex
  84. Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, bagIndex, Grid.getOpflagAtBag(equipID))
  85. if heroGrid.equip == nil or
  86. heroGrid.equip[pos] == nil then
  87. heroGrid.equip = heroGrid.equip or { }
  88. heroGrid.equip[pos] = equipGrid
  89. -- 穿戴者
  90. equipGrid.putUuid = heroGrid.uuid
  91. -- 新穿装备
  92. EquipLogic.delEquip(human, bagIndex, "equip_puton")
  93. else
  94. -- 同一件装备
  95. if heroGrid.equip[pos].uuid == equipGrid.uuid then
  96. return Msg.send(msgRet, human.fd)
  97. end
  98. -- 替换装备
  99. EquipLogic.delEquip(human, bagIndex, "equip_puton")
  100. local unEquipGrid = heroGrid.equip[pos]
  101. unEquipGrid.putUuid = nil
  102. EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
  103. heroGrid.equip[pos] = equipGrid
  104. equipGrid.putUuid = heroGrid.uuid
  105. end
  106. if noCalc ~= true then
  107. -- 计算属性
  108. ObjHuman.doCalcHero(human, heroIndex)
  109. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  110. HeroLogic.refreshDot(human, heroGrid.uuid)
  111. end
  112. -- 通知客户端
  113. Msg.send(msgRet, human.fd)
  114. end
  115. --
  116. function putOnHero(human, heroID, heroIndex, putHeroID, putHeroIndex, putHeroPos)
  117. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  118. if heroGrid == nil then return end
  119. local putHeroGrid = HeroLogic.getHeroGrid(human, putHeroID, putHeroIndex)
  120. if putHeroGrid == nil then return end
  121. -- 同一个英雄
  122. if heroGrid.uuid == putHeroGrid.uuid then return end
  123. -- 部位有没有装备
  124. if putHeroGrid.equip == nil then return end
  125. local putEquipGrid = putHeroGrid.equip[putHeroPos]
  126. if not putEquipGrid then return end
  127. local equipID = putEquipGrid.id
  128. local equipConfig = EquipExcel.equip[equipID]
  129. if equipConfig == nil then return end
  130. if heroGrid.star < equipConfig.star then
  131. local errDesc = Util.format(Lang.EQUIP_PUT_ON_STAR_ERR, equipConfig.star)
  132. return Broadcast.sendErr(human, errDesc)
  133. end
  134. local pos = equipConfig.subType
  135. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  136. if heroGrid.equip == nil or
  137. heroGrid.equip[pos] == nil then
  138. heroGrid.equip = heroGrid.equip or { }
  139. -- 穿戴者
  140. heroGrid.equip[pos] = putEquipGrid
  141. putEquipGrid.putUuid = heroGrid.uuid
  142. else
  143. -- 同一件装备
  144. if heroGrid.equip[pos].uuid == putHeroGrid.uuid then
  145. return Msg.send(msgRet, human.fd)
  146. end
  147. --放入到背包
  148. local unEquipGrid = heroGrid.equip[pos]
  149. unEquipGrid.putUuid = nil
  150. EquipLogic.addByEquipGrid(human, unEquipGrid, "equip_puton", true)
  151. -- 设置新装备
  152. heroGrid.equip[pos] = putEquipGrid
  153. putEquipGrid.putUuid = heroGrid.uuid
  154. end
  155. -- 老英雄脱去此装备
  156. putHeroGrid.equip[putHeroPos] = nil
  157. -- 计算属性
  158. ObjHuman.doCalcHero(human, heroIndex)
  159. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  160. HeroLogic.refreshDot(human, heroGrid.uuid)
  161. ObjHuman.doCalcHero(human, putHeroIndex)
  162. HeroLogic.sendHeroBagDynamic(human, putHeroID, putHeroIndex)
  163. HeroLogic.refreshDot(human, putHeroGrid.uuid)
  164. -- 通知客户端
  165. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  166. msgRet.heroID = heroID
  167. msgRet.heroIndex = heroIndex
  168. Grid.makeItem(msgRet.equip, equipID, 1, nil, equipGrid, 0, Grid.getOpflagAtBag(equipID))
  169. Msg.send(msgRet, human.fd)
  170. end
  171. function putOff(human, heroID, heroIndex, pos, noCalc)
  172. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  173. if heroGrid == nil then
  174. return
  175. end
  176. if pos == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then return end
  177. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  178. return
  179. end
  180. -- 判断背包空间
  181. if not EquipLogic.checkEmptyCnt(human, 1) then
  182. return
  183. end
  184. -- 改db
  185. local equipGrid = heroGrid.equip[pos]
  186. heroGrid.equip[pos] = nil
  187. equipGrid.putUuid = nil
  188. EquipLogic.addByEquipGrid(human, equipGrid, "equip_putoff", true)
  189. if noCalc ~= true then
  190. -- 计算属性
  191. ObjHuman.doCalcHero(human,heroIndex)
  192. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  193. HeroLogic.refreshDot(human, heroGrid.uuid)
  194. end
  195. -- 通知客户端
  196. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTOFF
  197. msgRet.heroID = heroID
  198. msgRet.heroIndex = heroIndex
  199. msgRet.pos = pos
  200. Msg.send(msgRet, human.fd)
  201. end
  202. -- 一键穿装
  203. function putOnQuick(human, heroID, heroIndex, equipID1, equipID2, equipID3, equipID4, equipID6)
  204. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  205. if heroGrid == nil then
  206. return
  207. end
  208. putOn(human, heroID, heroIndex, equipID1, true)
  209. putOn(human, heroID, heroIndex, equipID2, true)
  210. putOn(human, heroID, heroIndex, equipID3, true)
  211. putOn(human, heroID, heroIndex, equipID4, true)
  212. putOn(human, heroID, heroIndex, equipID6, true)
  213. ObjHuman.doCalcHero(human,heroIndex)
  214. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  215. HeroLogic.refreshDot(human, heroGrid.uuid)
  216. end
  217. -- 一键脱装
  218. function putOffQuick(human, heroID, heroIndex, noSendDy)
  219. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  220. if heroGrid == nil then
  221. return
  222. end
  223. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, true)
  224. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, true)
  225. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, true)
  226. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, true)
  227. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, true)
  228. if not noSendDy then
  229. ObjHuman.doCalcHero(human,heroIndex)
  230. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  231. end
  232. end
  233. function doCalcHero(obj,attrs)
  234. local equip = obj.equip
  235. if not equip then return end
  236. local mathFloor = math.floor
  237. local equipSuitCntTable = nil
  238. for i = 1,ItemDefine.EQUIP_MAX_CNT do
  239. local equipGrid = equip[i]
  240. if equipGrid then
  241. local equipID = equipGrid.id
  242. local equipConfig = EquipExcel.equip[equipID]
  243. local baseRate = EquipLogic.getEquipBaseRate(equipGrid.quality)
  244. -- 水晶
  245. if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  246. for _,v in ipairs(EquipExcel.shuijingAttr[obj.shuijingAttrID].attr) do
  247. RoleAttr.updateValue(v[1],v[2],attrs)
  248. end
  249. else
  250. for _,v in ipairs(equipConfig.base) do
  251. RoleAttr.updateValue(v[1],mathFloor(v[2] * baseRate),attrs)
  252. end
  253. -- 随机属性
  254. for key, value in pairs(equipGrid.attr) do
  255. RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
  256. end
  257. local heroID = obj.id
  258. local heroConfig = HeroExcel.hero[heroID]
  259. if equipConfig.camp == heroConfig.camp then
  260. -- 阵营专属属性
  261. for _,v in ipairs(equipConfig.campAttr) do
  262. RoleAttr.updateValue(v[1],v[2],attrs)
  263. end
  264. end
  265. if equipConfig.job == heroConfig.job then
  266. -- 职业专属属性
  267. for _,v in ipairs(equipConfig.jobAttr) do
  268. RoleAttr.updateValue(v[1],v[2],attrs)
  269. end
  270. end
  271. if equipConfig.suit ~= 0 then
  272. equipSuitCntTable = equipSuitCntTable or {}
  273. equipSuitCntTable[equipConfig.suit] = equipSuitCntTable[equipConfig.suit] or {cnt = 0}
  274. equipSuitCntTable[equipConfig.suit].equipID = equipID
  275. equipSuitCntTable[equipConfig.suit].cnt = equipSuitCntTable[equipConfig.suit].cnt + 1
  276. end
  277. end
  278. end
  279. end
  280. -- 套装属性
  281. if equipSuitCntTable then
  282. for k, v in pairs(equipSuitCntTable) do
  283. if v.cnt > 1 then
  284. local equipIDTemp = v.equipID
  285. local equipConfigTemp = EquipExcel.equip[equipIDTemp]
  286. for i = 1, #equipConfigTemp.suitIm do
  287. local keyTemp = equipConfigTemp.suitIm[i][1]
  288. local valTemp = equipConfigTemp.suitIm[i][2]
  289. if v.cnt > i then
  290. RoleAttr.updateValue(keyTemp,valTemp,attrs)
  291. end
  292. end
  293. end
  294. end
  295. end
  296. end
  297. -- 激活水晶
  298. function jihuoShuijing(human, heroID, heroIndex)
  299. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  300. if heroGrid == nil then
  301. return
  302. end
  303. if heroGrid.lv < HeroDefine.JIHUO_SHUIJING_NEEDLV then
  304. return
  305. end
  306. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  307. if heroGrid.equip ~= nil and heroGrid.equip[pos] then
  308. return
  309. end
  310. --存db
  311. local equipID = HeroDefine.DEFAULT_SHUIJING_GET -- todo 20011
  312. local equipConfig = EquipExcel.equip[equipID]
  313. if not equipConfig then return end
  314. heroGrid.equip = heroGrid.equip or {}
  315. heroGrid.equip[pos] = equipID
  316. local randIdCnt = #equipConfig.shuijingAttrID
  317. local indexTemp = math.random(1,randIdCnt)
  318. local attrID = equipConfig.shuijingAttrID[indexTemp]
  319. heroGrid.shuijingAttrID = attrID
  320. -- 计算属性
  321. ObjHuman.doCalcHero(human,heroIndex)
  322. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  323. -- 通知客户端
  324. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  325. msgRet.heroID = heroID
  326. msgRet.heroIndex = heroIndex
  327. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  328. Msg.send(msgRet, human.fd)
  329. end
  330. -- 水晶转换的信息查询
  331. function shuijingTransQuery(human, heroID, heroIndex)
  332. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  333. if heroGrid == nil then
  334. return
  335. end
  336. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  337. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  338. return
  339. end
  340. local equipID = heroGrid.equip[pos]
  341. local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
  342. if not shuijingTransConfig then return end
  343. local msgRet = Msg.gc.GC_SHUIJING_TRANS_QUERY
  344. msgRet.heroID = heroID
  345. msgRet.heroIndex = heroIndex
  346. msgRet.needJinbi = shuijingTransConfig.money
  347. msgRet.needItemCnt = shuijingTransConfig.jinghua
  348. Msg.send(msgRet, human.fd)
  349. end
  350. -- 水晶转换
  351. function shuijingTransDo(human, heroID, heroIndex)
  352. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  353. if heroGrid == nil then
  354. return
  355. end
  356. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  357. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  358. return
  359. end
  360. local equipID = heroGrid.equip[pos]
  361. local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
  362. if not shuijingTransConfig then return end
  363. -- 材料判断
  364. local needJinbi = shuijingTransConfig.money
  365. if human.db.jinbi < needJinbi then
  366. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  367. end
  368. local needItemCnt = shuijingTransConfig.jinghua
  369. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  370. if nowItemCnt< needItemCnt then
  371. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  372. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  373. return Broadcast.sendErr(human, strRet)
  374. end
  375. -- 扣道具
  376. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  377. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  378. local msgRet = Msg.gc.GC_SHUIJING_TRANS_DO
  379. msgRet.heroID = heroID
  380. msgRet.heroIndex = heroIndex
  381. -- 存db之前,先随机获得下一个水晶的属性
  382. local equipConfig = EquipExcel.equip[equipID]
  383. if not equipConfig then return end
  384. local randIdCnt = #equipConfig.shuijingAttrID
  385. local indexTemp = math.random(1,randIdCnt)
  386. -- todo 单单这样子会有漏洞。。。玩家可以把水晶A洗练出的属性保存到水晶B那里,需要注意!!太忙了,之后修改
  387. human.tempAttrID = equipConfig.shuijingAttrID[indexTemp]
  388. -- 通知客户端
  389. Grid.makeItem(msgRet.equip, equipID, 1, human.tempAttrID)
  390. Msg.send(msgRet, human.fd)
  391. end
  392. -- 水晶转换保存
  393. function shuijingTransSave(human, heroID, heroIndex)
  394. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  395. if heroGrid == nil then
  396. return
  397. end
  398. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  399. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  400. return
  401. end
  402. if human.tempAttrID == nil then
  403. return
  404. end
  405. local equipID = heroGrid.equip[pos]
  406. -- 改db
  407. heroGrid.shuijingAttrID = human.tempAttrID
  408. human.tempAttrID = nil
  409. -- 计算属性并发送
  410. ObjHuman.doCalcHero(human,heroIndex)
  411. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  412. -- 通知客户端
  413. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  414. msgRet.heroID = heroID
  415. msgRet.heroIndex = heroIndex
  416. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  417. Msg.send(msgRet, human.fd)
  418. local msgRet = Msg.gc.GC_SHUIJING_TRANS_SAVE
  419. Msg.send(msgRet, human.fd)
  420. end
  421. -- 水晶升级查询
  422. function shuijingUpLvQuery(human, mainType, heroID, heroIndex)
  423. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  424. if heroGrid == nil then
  425. return
  426. end
  427. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  428. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  429. return
  430. end
  431. local equipID = heroGrid.equip[pos]
  432. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  433. if not shuijingUpNeedConfig then return end
  434. -- 上限判断
  435. local nextID = shuijingUpNeedConfig.nextID
  436. if nextID == 0 then return end
  437. local msgRet = Msg.gc.GC_SHUIJING_UPLV_QUERY
  438. msgRet.heroID = heroID
  439. msgRet.heroIndex = heroIndex
  440. msgRet.needJinbi = 0
  441. msgRet.needItemCnt = 0
  442. msgRet.needZuanshi = 0
  443. local nextID = shuijingUpNeedConfig.nextID
  444. if nextID ~= 0 then
  445. local tempConfig = EquipExcel.shuijingUpNeed[nextID]
  446. msgRet.needJinbi = tempConfig.money
  447. msgRet.needItemCnt = tempConfig.jinghua
  448. msgRet.needZuanshi = tempConfig.zuanshi
  449. end
  450. msgRet.equip[0] = 1
  451. local attrID = heroGrid.shuijingAttrID
  452. local tempAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  453. Grid.makeItem(msgRet.equip[1], nextID, 1, tempAttrID)
  454. Msg.send(msgRet, human.fd)
  455. end
  456. -- 水晶升级
  457. function shuijingUpLvDo(human, mainType, heroID, heroIndex)
  458. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  459. if heroGrid == nil then
  460. return
  461. end
  462. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  463. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  464. return
  465. end
  466. local equipID = heroGrid.equip[pos]
  467. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  468. if not shuijingUpNeedConfig then return end
  469. -- 上限判断
  470. local nextID = shuijingUpNeedConfig.nextID
  471. if nextID == 0 then return end
  472. local nextConfig = EquipExcel.shuijingUpNeed[nextID]
  473. if nextConfig == nil then return end
  474. -- 材料判断
  475. local needJinbi = nextConfig.money
  476. if human.db.jinbi < needJinbi then
  477. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  478. end
  479. local needItemCnt = nextConfig.jinghua
  480. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  481. if nowItemCnt< needItemCnt then
  482. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  483. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  484. return Broadcast.sendErr(human, strRet)
  485. end
  486. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  487. local needZuanshi = nextConfig.zuanshi
  488. if not ObjHuman.checkRMB(human, needZuanshi) then
  489. return
  490. end
  491. end
  492. -- 扣道具
  493. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  494. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  495. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  496. local needZuanshi = shuijingUpNeedConfig.zuanshi
  497. ObjHuman.decZuanshi(human, -needZuanshi, "shuijing_change")
  498. end
  499. --改db
  500. heroGrid.equip[pos] = nextID
  501. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  502. local attrID = heroGrid.shuijingAttrID
  503. heroGrid.shuijingAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  504. else
  505. local equipConfig = EquipExcel.equip[nextID]
  506. if not equipConfig then return end
  507. local randIdCnt = #equipConfig.shuijingAttrID
  508. local indexTemp = math.random(1,randIdCnt)
  509. heroGrid.shuijingAttrID = equipConfig.shuijingAttrID[indexTemp]
  510. end
  511. -- 计算属性并发送
  512. ObjHuman.doCalcHero(human,heroIndex)
  513. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  514. -- 通知客户端
  515. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  516. msgRet.heroID = heroID
  517. msgRet.heroIndex = heroIndex
  518. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  519. Msg.send(msgRet, human.fd)
  520. local msgRet = Msg.gc.GC_SHUIJING_UPLV_DO
  521. msgRet.heroID = heroID
  522. msgRet.heroIndex = heroIndex
  523. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  524. Msg.send(msgRet, human.fd)
  525. end
  526. -- 神器升级查询
  527. function shenqiUpLvQuery(human, heroID, heroIndex)
  528. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  529. if heroGrid == nil then
  530. return
  531. end
  532. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  533. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  534. return
  535. end
  536. local equipID = heroGrid.equip[pos]
  537. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  538. if not shenqiUpNeedConfig then return end
  539. -- 上限判断
  540. local nextID = shenqiUpNeedConfig.nextID
  541. if nextID == 0 then return end
  542. -- 下发信息
  543. local msgRet = Msg.gc.GC_SHENQI_UPLV_QUERY
  544. msgRet.heroID = heroID
  545. msgRet.heroIndex = heroIndex
  546. msgRet.needExp = shenqiUpNeedConfig.needExp
  547. Grid.makeItem(msgRet.equip, nextID, 1)
  548. Msg.send(msgRet, human.fd)
  549. end
  550. -- 神器升级
  551. function shenqiUpLvDo(human, heroID, heroIndex, equipIDList, equipCntList)
  552. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  553. if heroGrid == nil then
  554. return
  555. end
  556. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  557. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  558. return
  559. end
  560. local equipID = heroGrid.equip[pos]
  561. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  562. if not shenqiUpNeedConfig then return end
  563. -- 上限判断
  564. local nextID = shenqiUpNeedConfig.nextID
  565. if nextID == 0 then return end
  566. -- 判断消耗
  567. if equipIDList[0] ~= equipCntList[0] then
  568. return
  569. end
  570. for i=1, equipIDList[0] do
  571. local needEquipCnt = equipCntList[i]
  572. local nowEquipCnt = BagLogic.getItemCnt(human, equipIDList[i])
  573. if nowEquipCnt < needEquipCnt then
  574. return
  575. end
  576. end
  577. local totalExp = 0
  578. for i=1, equipIDList[0] do
  579. local id = equipIDList[i]
  580. local equipConfig = EquipExcel.equip[id]
  581. if equipConfig then
  582. local nowExp = equipConfig.shenqiExp
  583. local nowCnt = equipCntList[i]
  584. totalExp = totalExp + math.floor(nowExp * nowCnt)
  585. else
  586. local itemConfig = ItemExcel[id]
  587. if not itemConfig or (id ~= ItemDefine.ITEM_SHENQI_EXP_ID1 and
  588. id ~= ItemDefine.ITEM_SHENQI_EXP_ID2) then
  589. return
  590. end
  591. local nowExp = itemConfig.effect
  592. local nowCnt = equipCntList[i]
  593. totalExp = totalExp + math.floor(nowExp * nowCnt)
  594. end
  595. end
  596. local needExp = shenqiUpNeedConfig.needExp
  597. if totalExp < needExp then
  598. return Broadcast.sendErr(human, Lang.EQUIP_SHENQI_UP_ERR_EXP)
  599. end
  600. -- 扣道具
  601. for i=1, equipIDList[0] do
  602. local needEquipCnt = equipCntList[i]
  603. BagLogic.delItem(human, equipIDList[i], needEquipCnt, "shenqi_upLv")
  604. end
  605. -- 改db
  606. heroGrid.equip[pos] = nextID
  607. local backExp = totalExp - needExp
  608. local backCnt = math.floor(backExp/10)
  609. -- 返还物
  610. if backCnt > 0 then
  611. BagLogic.addItem(human, HeroDefine.DEFAULT_SHENQI_UPLV_BACK, backCnt, "shenqi_upLv_back", noSend)
  612. end
  613. -- 计算属性
  614. ObjHuman.doCalcHero(human,heroIndex)
  615. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  616. -- 通知客户端
  617. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  618. msgRet.heroID = heroID
  619. msgRet.heroIndex = heroIndex
  620. Grid.makeItem(msgRet.equip, nextID, 1)
  621. Msg.send(msgRet, human.fd)
  622. local msgRet = Msg.gc.GC_SHENQI_UPLV_DO
  623. msgRet.heroID = heroID
  624. msgRet.heroIndex = heroIndex
  625. if backCnt > 0 then
  626. msgRet.equip[0] = 1
  627. Grid.makeItem(msgRet.equip[1], HeroDefine.DEFAULT_SHENQI_UPLV_BACK,backCnt)
  628. else
  629. msgRet.equip[0] = 0
  630. end
  631. Msg.send(msgRet, human.fd)
  632. end
  633. -- 比较2件装备信息,返回较好的装备id
  634. function cmpEquip(equipID1, equipID2, heroConfig)
  635. if not equipID1 then return equipID2 end
  636. if not equipID2 then return equipID1 end
  637. if equipID1 == equipID2 then
  638. return equipID1
  639. end
  640. local config1 = EquipExcel.equip[equipID1]
  641. if not config1 then return equipID2 end
  642. local config2 = EquipExcel.equip[equipID2]
  643. if not config2 then return equipID1 end
  644. if config1.rare ~= config2.rare then
  645. return (config1.rare > config2.rare) and equipID1 or equipID2
  646. end
  647. if config1.level ~= config2.level then
  648. return (config1.level > config2.level) and equipID1 or equipID2
  649. end
  650. if heroConfig then -- 专属装备判断 阵营 职业
  651. if config1.camp == heroConfig.camp then return equipID1 end
  652. if config2.camp == heroConfig.camp then return equipID2 end
  653. if config1.job == heroConfig.job then return equipID1 end
  654. if config2.job == heroConfig.job then return equipID2 end
  655. end
  656. return equipID1
  657. end
  658. -- 根据部位和伙伴信息获取背包最好的装备id
  659. function getBagBestEquipID(human, pos, heroConfig)
  660. local bestEquipID = nil
  661. for k, equipGrid in pairs(human.db.equipBag) do
  662. local config = EquipExcel.equip[equipGrid.id]
  663. if config and config.subType == pos then
  664. bestEquipID = cmpEquip(bestEquipID, equipGrid.id, heroConfig)
  665. end
  666. end
  667. return bestEquipID
  668. end
  669. -- 是否有装备红点
  670. function isEquipDot(human, heroGrid)
  671. if human.db.lv < 9 then
  672. return false
  673. end
  674. if not heroGrid then return end
  675. local heroConfig = HeroExcel.hero[heroGrid.id]
  676. if not heroConfig then return end
  677. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  678. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  679. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  680. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  681. return true
  682. end
  683. end
  684. end
  685. end
  686. -- 是否有装备红点
  687. function isEquipDotByPos(human, heroGrid, pos)
  688. if human.db.lv < 9 then
  689. return false
  690. end
  691. if not heroGrid then return end
  692. local heroConfig = HeroExcel.hero[heroGrid.id]
  693. if not heroConfig then return end
  694. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  695. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  696. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  697. return 1
  698. end
  699. end
  700. end
  701. function getEquipAndFuwenByHeroIndex(human,heroID,heroIndex)
  702. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  703. if not heroGrid then return end
  704. local heroConfig = HeroExcel.hero[heroGrid.id]
  705. if not heroConfig then return end
  706. local equipTb = {}
  707. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  708. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  709. local equipID = heroGrid.equip and heroGrid.equip[pos] and heroGrid.equip[pos].id
  710. equipTb[pos] = equipID
  711. end
  712. end
  713. local fuwenTb = {}
  714. for pos = 1,2 do
  715. local fuwenIndex = heroGrid.fuwen and heroGrid.fuwen[pos]
  716. fuwenTb[pos] = fuwenIndex
  717. end
  718. return equipTb,fuwenTb
  719. end