HeroEquip.lua 31 KB

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