HeroEquip.lua 32 KB

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