HeroEquip.lua 27 KB

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