HeroEquip.lua 30 KB

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