HeroEquip.lua 31 KB

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