HeroEquip.lua 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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, noSend)
  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. if not noSend then
  204. -- 通知客户端
  205. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTOFF
  206. msgRet.heroID = heroID
  207. msgRet.heroIndex = heroIndex
  208. msgRet.pos = pos
  209. Msg.send(msgRet, human.fd)
  210. end
  211. end
  212. -- 一键穿装
  213. function putOnQuick(human, heroID, heroIndex, equipID1, equipID2, equipID3, equipID4, equipID6)
  214. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  215. if heroGrid == nil then
  216. return
  217. end
  218. putOn(human, heroID, heroIndex, equipID1, true)
  219. putOn(human, heroID, heroIndex, equipID2, true)
  220. putOn(human, heroID, heroIndex, equipID3, true)
  221. putOn(human, heroID, heroIndex, equipID4, true)
  222. putOn(human, heroID, heroIndex, equipID6, true)
  223. ObjHuman.doCalcHero(human,heroIndex)
  224. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  225. HeroLogic.refreshDot(human, heroGrid.uuid)
  226. end
  227. -- 一键脱装
  228. function putOffQuick(human, heroID, heroIndex, noSendDy)
  229. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  230. if heroGrid == nil then
  231. return
  232. end
  233. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_WEAPON, true)
  234. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_CLOTH, true)
  235. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHOES, true)
  236. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHIPIN, true)
  237. putOff(human, heroID, heroIndex, ItemDefine.EQUIP_SUBTYPE_SHENQI, true)
  238. if not noSendDy then
  239. ObjHuman.doCalcHero(human,heroIndex)
  240. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  241. end
  242. end
  243. function doCalcHero(obj,attrs)
  244. local equip = obj.equip
  245. if not equip then return end
  246. local suitBonusTbl = HeroGem.suitAttrBonus(obj)
  247. local mathFloor = math.floor
  248. local equipSuitCntTable = nil
  249. for i = 1,ItemDefine.EQUIP_MAX_CNT do
  250. local equipGrid = equip[i]
  251. if equipGrid then
  252. local equipID = equipGrid.id
  253. local equipConfig = EquipExcel.equip[equipID]
  254. local baseRate = EquipLogic.getEquipBaseRate(equipGrid.quality)
  255. -- 水晶
  256. if equipConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  257. for _,v in ipairs(EquipExcel.shuijingAttr[obj.shuijingAttrID].attr) do
  258. RoleAttr.updateValue(v[1],v[2],attrs)
  259. end
  260. else
  261. --装备基础属性
  262. for _,v in ipairs(equipConfig.base) do
  263. RoleAttr.updateValue(v[1],mathFloor(v[2] * baseRate * (1 + (suitBonusTbl and suitBonusTbl.base or 0))),attrs)
  264. end
  265. -- 随机属性
  266. -- for key, value in pairs(equipGrid.attr) do
  267. -- RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
  268. -- end
  269. for _, attrData in ipairs(equipGrid.attr) do
  270. RoleAttr.updateValue(attrData[1], mathFloor(attrData[2] * baseRate) ,attrs)
  271. end
  272. local heroID = obj.id
  273. local heroConfig = HeroExcel.hero[heroID]
  274. if equipConfig.camp == heroConfig.camp then
  275. -- 阵营专属属性
  276. for _,v in ipairs(equipConfig.campAttr) do
  277. RoleAttr.updateValue(v[1],v[2],attrs)
  278. end
  279. end
  280. if equipConfig.job == heroConfig.job then
  281. -- 职业专属属性
  282. for _,v in ipairs(equipConfig.jobAttr) do
  283. RoleAttr.updateValue(v[1],v[2],attrs)
  284. end
  285. end
  286. if equipConfig.suit ~= 0 then
  287. equipSuitCntTable = equipSuitCntTable or {}
  288. equipSuitCntTable[equipConfig.suit] = equipSuitCntTable[equipConfig.suit] or {cnt = 0}
  289. equipSuitCntTable[equipConfig.suit].equipID = equipID
  290. equipSuitCntTable[equipConfig.suit].cnt = equipSuitCntTable[equipConfig.suit].cnt + 1
  291. end
  292. end
  293. end
  294. end
  295. -- 套装属性
  296. if equipSuitCntTable then
  297. for k, v in pairs(equipSuitCntTable) do
  298. if v.cnt > 1 then
  299. local equipIDTemp = v.equipID
  300. local equipConfigTemp = EquipExcel.equip[equipIDTemp]
  301. for i = 1, #equipConfigTemp.suitIm do
  302. local keyTemp = equipConfigTemp.suitIm[i][1]
  303. local valTemp = equipConfigTemp.suitIm[i][2]
  304. if v.cnt > i then
  305. if suitBonusTbl and suitBonusTbl[i+1] then
  306. --suitIm={{203,2500},{201,2500},{219,1500}}
  307. --这里i+1的原因是,装备套装属性配置suitIm中, idx为1的value是2件套加成, idx为2的是3件套加成,以此类推
  308. valTemp = valTemp * (1 + suitBonusTbl[i+1]) --宝石对套装的加成
  309. end
  310. RoleAttr.updateValue(keyTemp,valTemp,attrs)
  311. end
  312. end
  313. end
  314. end
  315. end
  316. end
  317. -- 激活水晶
  318. function jihuoShuijing(human, heroID, heroIndex)
  319. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  320. if heroGrid == nil then
  321. return
  322. end
  323. if heroGrid.lv < HeroDefine.JIHUO_SHUIJING_NEEDLV then
  324. return
  325. end
  326. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  327. if heroGrid.equip ~= nil and heroGrid.equip[pos] then
  328. return
  329. end
  330. --存db
  331. local equipID = HeroDefine.DEFAULT_SHUIJING_GET -- todo 20011
  332. local equipConfig = EquipExcel.equip[equipID]
  333. if not equipConfig then return end
  334. heroGrid.equip = heroGrid.equip or {}
  335. heroGrid.equip[pos] = equipID
  336. local randIdCnt = #equipConfig.shuijingAttrID
  337. local indexTemp = math.random(1,randIdCnt)
  338. local attrID = equipConfig.shuijingAttrID[indexTemp]
  339. heroGrid.shuijingAttrID = attrID
  340. -- 计算属性
  341. ObjHuman.doCalcHero(human,heroIndex)
  342. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  343. -- 通知客户端
  344. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  345. msgRet.heroID = heroID
  346. msgRet.heroIndex = heroIndex
  347. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  348. Msg.send(msgRet, human.fd)
  349. end
  350. -- 水晶转换的信息查询
  351. function shuijingTransQuery(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. local msgRet = Msg.gc.GC_SHUIJING_TRANS_QUERY
  364. msgRet.heroID = heroID
  365. msgRet.heroIndex = heroIndex
  366. msgRet.needJinbi = shuijingTransConfig.money
  367. msgRet.needItemCnt = shuijingTransConfig.jinghua
  368. Msg.send(msgRet, human.fd)
  369. end
  370. -- 水晶转换
  371. function shuijingTransDo(human, heroID, heroIndex)
  372. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  373. if heroGrid == nil then
  374. return
  375. end
  376. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  377. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  378. return
  379. end
  380. local equipID = heroGrid.equip[pos]
  381. local shuijingTransConfig = EquipExcel.shuijingTransNeed[equipID]
  382. if not shuijingTransConfig then return end
  383. -- 材料判断
  384. local needJinbi = shuijingTransConfig.money
  385. if human.db.jinbi < needJinbi then
  386. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  387. end
  388. local needItemCnt = shuijingTransConfig.jinghua
  389. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  390. if nowItemCnt< needItemCnt then
  391. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  392. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  393. return Broadcast.sendErr(human, strRet)
  394. end
  395. -- 扣道具
  396. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  397. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  398. local msgRet = Msg.gc.GC_SHUIJING_TRANS_DO
  399. msgRet.heroID = heroID
  400. msgRet.heroIndex = heroIndex
  401. -- 存db之前,先随机获得下一个水晶的属性
  402. local equipConfig = EquipExcel.equip[equipID]
  403. if not equipConfig then return end
  404. local randIdCnt = #equipConfig.shuijingAttrID
  405. local indexTemp = math.random(1,randIdCnt)
  406. -- todo 单单这样子会有漏洞。。。玩家可以把水晶A洗练出的属性保存到水晶B那里,需要注意!!太忙了,之后修改
  407. human.tempAttrID = equipConfig.shuijingAttrID[indexTemp]
  408. -- 通知客户端
  409. Grid.makeItem(msgRet.equip, equipID, 1, human.tempAttrID)
  410. Msg.send(msgRet, human.fd)
  411. end
  412. -- 水晶转换保存
  413. function shuijingTransSave(human, heroID, heroIndex)
  414. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  415. if heroGrid == nil then
  416. return
  417. end
  418. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  419. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  420. return
  421. end
  422. if human.tempAttrID == nil then
  423. return
  424. end
  425. local equipID = heroGrid.equip[pos]
  426. -- 改db
  427. heroGrid.shuijingAttrID = human.tempAttrID
  428. human.tempAttrID = nil
  429. -- 计算属性并发送
  430. ObjHuman.doCalcHero(human,heroIndex)
  431. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  432. -- 通知客户端
  433. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  434. msgRet.heroID = heroID
  435. msgRet.heroIndex = heroIndex
  436. Grid.makeItem(msgRet.equip, equipID, 1, heroGrid.shuijingAttrID)
  437. Msg.send(msgRet, human.fd)
  438. local msgRet = Msg.gc.GC_SHUIJING_TRANS_SAVE
  439. Msg.send(msgRet, human.fd)
  440. end
  441. -- 水晶升级查询
  442. function shuijingUpLvQuery(human, mainType, heroID, heroIndex)
  443. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  444. if heroGrid == nil then
  445. return
  446. end
  447. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  448. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  449. return
  450. end
  451. local equipID = heroGrid.equip[pos]
  452. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  453. if not shuijingUpNeedConfig then return end
  454. -- 上限判断
  455. local nextID = shuijingUpNeedConfig.nextID
  456. if nextID == 0 then return end
  457. local msgRet = Msg.gc.GC_SHUIJING_UPLV_QUERY
  458. msgRet.heroID = heroID
  459. msgRet.heroIndex = heroIndex
  460. msgRet.needJinbi = 0
  461. msgRet.needItemCnt = 0
  462. msgRet.needZuanshi = 0
  463. local nextID = shuijingUpNeedConfig.nextID
  464. if nextID ~= 0 then
  465. local tempConfig = EquipExcel.shuijingUpNeed[nextID]
  466. msgRet.needJinbi = tempConfig.money
  467. msgRet.needItemCnt = tempConfig.jinghua
  468. msgRet.needZuanshi = tempConfig.zuanshi
  469. end
  470. msgRet.equip[0] = 1
  471. local attrID = heroGrid.shuijingAttrID
  472. local tempAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  473. Grid.makeItem(msgRet.equip[1], nextID, 1, tempAttrID)
  474. Msg.send(msgRet, human.fd)
  475. end
  476. -- 水晶升级
  477. function shuijingUpLvDo(human, mainType, heroID, heroIndex)
  478. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  479. if heroGrid == nil then
  480. return
  481. end
  482. local pos = ItemDefine.EQUIP_SUBTYPE_SHUIJIN
  483. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  484. return
  485. end
  486. local equipID = heroGrid.equip[pos]
  487. local shuijingUpNeedConfig = EquipExcel.shuijingUpNeed[equipID]
  488. if not shuijingUpNeedConfig then return end
  489. -- 上限判断
  490. local nextID = shuijingUpNeedConfig.nextID
  491. if nextID == 0 then return end
  492. local nextConfig = EquipExcel.shuijingUpNeed[nextID]
  493. if nextConfig == nil then return end
  494. -- 材料判断
  495. local needJinbi = nextConfig.money
  496. if human.db.jinbi < needJinbi then
  497. return Broadcast.sendErr(human, Lang.COMMON_NO_JINBI)
  498. end
  499. local needItemCnt = nextConfig.jinghua
  500. local nowItemCnt = BagLogic.getItemCnt(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID)
  501. if nowItemCnt< needItemCnt then
  502. local strName = ItemDefine.getValue(ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, "name")
  503. local strRet = Util.format(Lang.COMMON_NO_ITEM, strName)
  504. return Broadcast.sendErr(human, strRet)
  505. end
  506. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  507. local needZuanshi = nextConfig.zuanshi
  508. if not ObjHuman.checkRMB(human, needZuanshi) then
  509. return
  510. end
  511. end
  512. -- 扣道具
  513. BagLogic.delItem(human, ItemDefine.ITEM_SHUIJING_UPLEVEL_ID, needItemCnt, "shuijing_change")
  514. ObjHuman.updateJinbi(human, -needJinbi, "shuijing_change")
  515. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  516. local needZuanshi = shuijingUpNeedConfig.zuanshi
  517. ObjHuman.decZuanshi(human, -needZuanshi, "shuijing_change")
  518. end
  519. --改db
  520. heroGrid.equip[pos] = nextID
  521. if mainType == HeroDefine.SHUIJING_UP_LV_LOCK then
  522. local attrID = heroGrid.shuijingAttrID
  523. heroGrid.shuijingAttrID = EquipExcel.shuijingAttr[attrID].lockNextID
  524. else
  525. local equipConfig = EquipExcel.equip[nextID]
  526. if not equipConfig then return end
  527. local randIdCnt = #equipConfig.shuijingAttrID
  528. local indexTemp = math.random(1,randIdCnt)
  529. heroGrid.shuijingAttrID = equipConfig.shuijingAttrID[indexTemp]
  530. end
  531. -- 计算属性并发送
  532. ObjHuman.doCalcHero(human,heroIndex)
  533. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  534. -- 通知客户端
  535. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  536. msgRet.heroID = heroID
  537. msgRet.heroIndex = heroIndex
  538. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  539. Msg.send(msgRet, human.fd)
  540. local msgRet = Msg.gc.GC_SHUIJING_UPLV_DO
  541. msgRet.heroID = heroID
  542. msgRet.heroIndex = heroIndex
  543. Grid.makeItem(msgRet.equip, nextID, 1, heroGrid.shuijingAttrID)
  544. Msg.send(msgRet, human.fd)
  545. end
  546. -- 神器升级查询
  547. function shenqiUpLvQuery(human, heroID, heroIndex)
  548. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  549. if heroGrid == nil then
  550. return
  551. end
  552. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  553. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  554. return
  555. end
  556. local equipID = heroGrid.equip[pos]
  557. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  558. if not shenqiUpNeedConfig then return end
  559. -- 上限判断
  560. local nextID = shenqiUpNeedConfig.nextID
  561. if nextID == 0 then return end
  562. -- 下发信息
  563. local msgRet = Msg.gc.GC_SHENQI_UPLV_QUERY
  564. msgRet.heroID = heroID
  565. msgRet.heroIndex = heroIndex
  566. msgRet.needExp = shenqiUpNeedConfig.needExp
  567. Grid.makeItem(msgRet.equip, nextID, 1)
  568. Msg.send(msgRet, human.fd)
  569. end
  570. -- 神器升级
  571. function shenqiUpLvDo(human, heroID, heroIndex, equipIDList, equipCntList)
  572. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  573. if heroGrid == nil then
  574. return
  575. end
  576. local pos = ItemDefine.EQUIP_SUBTYPE_SHENQI
  577. if heroGrid.equip == nil or heroGrid.equip[pos] == nil then
  578. return
  579. end
  580. local equipID = heroGrid.equip[pos]
  581. local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[equipID]
  582. if not shenqiUpNeedConfig then return end
  583. -- 上限判断
  584. local nextID = shenqiUpNeedConfig.nextID
  585. if nextID == 0 then return end
  586. -- 判断消耗
  587. if equipIDList[0] ~= equipCntList[0] then
  588. return
  589. end
  590. for i=1, equipIDList[0] do
  591. local needEquipCnt = equipCntList[i]
  592. local nowEquipCnt = BagLogic.getItemCnt(human, equipIDList[i])
  593. if nowEquipCnt < needEquipCnt then
  594. return
  595. end
  596. end
  597. local totalExp = 0
  598. for i=1, equipIDList[0] do
  599. local id = equipIDList[i]
  600. local equipConfig = EquipExcel.equip[id]
  601. if equipConfig then
  602. local nowExp = equipConfig.shenqiExp
  603. local nowCnt = equipCntList[i]
  604. totalExp = totalExp + math.floor(nowExp * nowCnt)
  605. else
  606. local itemConfig = ItemExcel[id]
  607. if not itemConfig or (id ~= ItemDefine.ITEM_SHENQI_EXP_ID1 and
  608. id ~= ItemDefine.ITEM_SHENQI_EXP_ID2) then
  609. return
  610. end
  611. local nowExp = itemConfig.effect
  612. local nowCnt = equipCntList[i]
  613. totalExp = totalExp + math.floor(nowExp * nowCnt)
  614. end
  615. end
  616. local needExp = shenqiUpNeedConfig.needExp
  617. if totalExp < needExp then
  618. return Broadcast.sendErr(human, Lang.EQUIP_SHENQI_UP_ERR_EXP)
  619. end
  620. -- 扣道具
  621. for i=1, equipIDList[0] do
  622. local needEquipCnt = equipCntList[i]
  623. BagLogic.delItem(human, equipIDList[i], needEquipCnt, "shenqi_upLv")
  624. end
  625. -- 改db
  626. heroGrid.equip[pos] = nextID
  627. local backExp = totalExp - needExp
  628. local backCnt = math.floor(backExp/10)
  629. -- 返还物
  630. if backCnt > 0 then
  631. BagLogic.addItem(human, HeroDefine.DEFAULT_SHENQI_UPLV_BACK, backCnt, "shenqi_upLv_back", noSend)
  632. end
  633. -- 计算属性
  634. ObjHuman.doCalcHero(human,heroIndex)
  635. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  636. -- 通知客户端
  637. local msgRet = Msg.gc.GC_HERO_EQUIP_PUTON
  638. msgRet.heroID = heroID
  639. msgRet.heroIndex = heroIndex
  640. Grid.makeItem(msgRet.equip, nextID, 1)
  641. Msg.send(msgRet, human.fd)
  642. local msgRet = Msg.gc.GC_SHENQI_UPLV_DO
  643. msgRet.heroID = heroID
  644. msgRet.heroIndex = heroIndex
  645. if backCnt > 0 then
  646. msgRet.equip[0] = 1
  647. Grid.makeItem(msgRet.equip[1], HeroDefine.DEFAULT_SHENQI_UPLV_BACK,backCnt)
  648. else
  649. msgRet.equip[0] = 0
  650. end
  651. Msg.send(msgRet, human.fd)
  652. end
  653. -- 比较2件装备信息,返回较好的装备id
  654. function cmpEquip(tNowequipGrid, tBagEquipGrid, heroConfig)
  655. if not tNowequipGrid or not tBagEquipGrid then
  656. return nil
  657. end
  658. --print("[cmpEquip] 装备ID ID1 = "..tNowequipGrid.id.." ID2 = "..tBagEquipGrid.id)
  659. --print("[cmpEquip] 11111")
  660. local tConfig1 = EquipExcel.equip[tNowequipGrid.id]
  661. local tConfig2 = EquipExcel.equip[tBagEquipGrid.id]
  662. if not tConfig1 or not tConfig2 then
  663. return tNowequipGrid
  664. end
  665. local nBaseRate1 = EquipLogic.getEquipBaseRate(tNowequipGrid.quality)
  666. local nBaseRate2 = EquipLogic.getEquipBaseRate(tBagEquipGrid.quality)
  667. local nScore1 = math.floor(tConfig1.score * nBaseRate1)
  668. local nScore2 = math.floor(tConfig2.score * nBaseRate2)
  669. --print("[cmpEquip] nBaseRate1 = "..nBaseRate1.." nScore1 = "..nScore1.." nBaseRate2 = "..nBaseRate2.." nScore2 = "..nScore2)
  670. -- 先比较评分
  671. if nScore1 ~= nScore2 then
  672. -- print("[cmpEquip] score 不同 score1 = "..nScore1.." score2 = "..nScore2)
  673. return (nScore1 >= nScore2) and tNowequipGrid or tBagEquipGrid
  674. end
  675. --print("[cmpEquip] 333333")
  676. if tConfig1.level and tConfig2.level and tConfig1.level ~= tConfig2.level then
  677. -- print("[cmpEquip] level 不同 level1 = "..tConfig1.level.." level2 = "..tConfig2.level)
  678. return (tConfig1.level >= tConfig2.level) and tNowequipGrid or tBagEquipGrid
  679. end
  680. --print("[cmpEquip] 4444")
  681. if not tNowequipGrid.quality then
  682. -- print("当前穿戴的装备没有品级 ID1 = "..tNowequipGrid.id)
  683. end
  684. if not tBagEquipGrid.quality then
  685. -- print("当前比较的装备没有品级 ID1 = "..tBagEquipGrid.id)
  686. end
  687. if tNowequipGrid.quality and tBagEquipGrid.quality then
  688. if tNowequipGrid.quality ~= tBagEquipGrid.quality then
  689. print("[cmpEquip] quality 不同 quality1 = "..tNowequipGrid.quality.." quality2 = "..tBagEquipGrid.quality)
  690. return (tNowequipGrid.quality >= tBagEquipGrid.quality) and tNowequipGrid or tBagEquipGrid
  691. else
  692. print("cmpEquip 当前装备品质相同")
  693. end
  694. end
  695. --print("[cmpEquip] 5555")
  696. return tNowequipGrid
  697. -- if heroConfig then -- 专属装备判断 阵营 职业
  698. -- -- if config1.camp == heroConfig.camp then return equipID1 end
  699. -- -- if config2.camp == heroConfig.camp then return equipID2 end
  700. -- -- if config1.job == heroConfig.job then return equipID1 end
  701. -- -- if config2.job == heroConfig.job then return equipID2 end
  702. -- end
  703. --print("cmpEquip 默认返回装备1 equipID1 = "..equipID1)
  704. end
  705. -- 根据部位和伙伴信息获取背包最好的装备id
  706. function getBagBestEquipID(human, pos, tNowequipGrid, nHeroStar, heroConfig)
  707. -- 当前最好的装备
  708. local tChoseEquipGrid = tNowequipGrid
  709. for k, equipGrid in pairs(human.db.equipBag) do
  710. local config = EquipExcel.equip[equipGrid.id]
  711. -- 装备位置相同,星级<=英雄星级,并且装备未穿戴
  712. if equipGrid and config and config.subType == pos
  713. and config.star <= nHeroStar and equipGrid.putUuid == nil then
  714. tChoseEquipGrid = cmpEquip(tChoseEquipGrid, equipGrid, heroConfig)
  715. if nil == tChoseEquipGrid then
  716. print("[getBagBestEquipID] 返回的值不正确")
  717. tChoseEquipGrid = tNowequipGrid
  718. end
  719. end
  720. end
  721. local nBestEquipID = tChoseEquipGrid.id
  722. if tNowequipGrid.id == tChoseEquipGrid.id
  723. and tNowequipGrid.quality == tChoseEquipGrid.quality
  724. and tNowequipGrid.score == tChoseEquipGrid.score and tNowequipGrid.level == tChoseEquipGrid.level then
  725. nBestEquipID = nil
  726. end
  727. return nBestEquipID
  728. end
  729. -- 是否有装备红点
  730. function isEquipDot(human, heroGrid)
  731. if human.db.lv < 9 then
  732. return false
  733. end
  734. if not heroGrid then return false end
  735. local heroConfig = HeroExcel.hero[heroGrid.id]
  736. if not heroConfig then return false end
  737. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  738. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  739. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  740. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  741. return true
  742. else
  743. if equipGrid ~= nil then
  744. local nEquipID = equipGrid.id
  745. local nBestEquipID = getBagBestEquipID(human, pos, equipGrid, heroGrid.star)
  746. if nil ~= nBestEquipID and nBestEquipID ~= nEquipID then
  747. -- print("[isEquipDot] heroID = "..heroGrid.id.." nEquipID = "..nEquipID.." nBestEquipID = "..nBestEquipID)
  748. return true
  749. end
  750. end
  751. end
  752. end
  753. end
  754. --print("[isEquipDot] 不存在更好的装备 ")
  755. return false
  756. end
  757. -- 是否有装备红点
  758. function isEquipDotByPos(human, heroGrid, pos)
  759. if human.db.lv < 9 then
  760. return false
  761. end
  762. if not heroGrid then return end
  763. local heroConfig = HeroExcel.hero[heroGrid.id]
  764. if not heroConfig then return end
  765. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  766. local equipGrid = heroGrid.equip and heroGrid.equip[pos]
  767. if equipGrid == nil and EquipLogic.getEquipByPos(human, heroGrid.star, pos) then
  768. return 1
  769. end
  770. end
  771. end
  772. function getEquipAndFuwenByHeroIndex(human,heroID,heroIndex)
  773. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  774. if not heroGrid then return end
  775. local heroConfig = HeroExcel.hero[heroGrid.id]
  776. if not heroConfig then return end
  777. local equipTb = {}
  778. for pos = 1, ItemDefine.EQUIP_MAX_CNT do
  779. if pos ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN then
  780. local equipID = heroGrid.equip and heroGrid.equip[pos] and heroGrid.equip[pos].id
  781. equipTb[pos] = equipID
  782. end
  783. end
  784. local fuwenTb = {}
  785. for pos = 1,2 do
  786. local fuwenIndex = heroGrid.fuwen and heroGrid.fuwen[pos]
  787. fuwenTb[pos] = fuwenIndex
  788. end
  789. return equipTb,fuwenTb
  790. end