HeroEquip.lua 31 KB

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