Equip_QiangHua.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. Equip_QiangHua = {}
  2. local this = Equip_QiangHua
  3. local filename = "Equip_QiangHua"
  4. this.msgID = LuaNetMsg.Equip_QiangHua_MsgID
  5. function this.getData(actor)
  6. local tab = {}
  7. local data = this.tData
  8. return tab
  9. end
  10. -- function this.main(actor)
  11. -- local data = this.tData
  12. -- sendluamsg(actor,this.msgID,{sendType=1,tData = data})
  13. -- -- this.SendData(actor)
  14. -- end
  15. -- function this.SendData(actor)
  16. -- -- messagebox(actor,"发送更新前")
  17. -- local data = this.getData(actor)
  18. -- sendluamsg(actor,this.msgID,{sendType=2,data = data})
  19. -- end
  20. -- function this.sendDataToClient(actor)
  21. -- local data = {
  22. -- sendType = 999,
  23. -- tData = this.tData,
  24. -- data = this.getData(actor),
  25. -- }
  26. -- sendluamsg(actor,this.msgID,data)
  27. -- end
  28. function this.RefreshLevel(actor, itemId, cfgId)
  29. local alldata = EquipAndAppear.getLuaItemExtData(actor)
  30. local equipdata = alldata[itemId]
  31. if equipdata == nil then
  32. EquipAndAppear.initequipluaextdata(alldata, itemId)
  33. equipdata = alldata[itemId]
  34. end
  35. if equipdata.strengthlv == nil then
  36. equipdata.strengthlv = API.GetItemData(actor, itemId, "strengthlv") or 0
  37. equipdata.strengthattr = {}
  38. end
  39. setplaydef(actor, "T$luaitemextdata", alldata)
  40. local data = {
  41. sendType = 10,
  42. itemId = itemId,
  43. cfgId = cfgId
  44. }
  45. sendluamsg(actor, this.msgID, data)
  46. -- 推送红点
  47. sendluamsg(actor, LuaNetMsg.Equip_DuanZao_MsgID, {})
  48. info("RefreshLevel2")
  49. end
  50. function this.Click(actor, msgData)
  51. local mainPage = msgData.mainPage
  52. local subPage = msgData.subPage
  53. local par = msgData.par
  54. if mainPage == 1 then
  55. this.QiangHua(actor, msgData)
  56. elseif mainPage == 2 then
  57. end
  58. end
  59. function this.canQiangHua(actor, equipInfo, itemId)
  60. local wearBar = 1
  61. if equipInfo == nil and itemId == nil then
  62. return false
  63. end
  64. if equipInfo == nil then
  65. equipInfo = getbagiteminfo(actor, itemId, 1)
  66. end
  67. if equipInfo == nil then
  68. return false
  69. end
  70. local cfgId = equipInfo.cfgid
  71. local itemData = ConfigDataManager.getTable("cfg_item", "id", cfgId)[1]
  72. local strPart = tonumber(string.split(itemData.strpart, "#")[1])
  73. local wearBar = 1
  74. local equipPos = strPart
  75. local subType = itemData.subtype
  76. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar] then
  77. return false
  78. end
  79. -- cfg_item中subType字段
  80. if Equip_QiangHua_Data.tItemWearPos[subType] == nil then
  81. messagebox(actor, "该装备无法强化")
  82. return false
  83. end
  84. return true
  85. end
  86. function this.QiangHua(actor, msgData)
  87. local itemId = msgData.itemId
  88. local equipInfo = nil;
  89. if msgData.equipPos ~= 0 then
  90. equipInfo = getequipinfo(actor, itemId, 1)
  91. else
  92. equipInfo = getbagiteminfo(actor, itemId, 1)
  93. end
  94. local cfgId = equipInfo.cfgid
  95. local itemData = ConfigDataManager.getTable("cfg_item", "id", cfgId)[1]
  96. local strPart = tonumber(string.split(itemData.strpart, "#")[1])
  97. local subType = itemData.subtype
  98. local wearBar = 1
  99. local equipPos = strPart
  100. -- local wearBar = msgData.wearBar
  101. -- local equipPos = msgData.equipPos
  102. -- local costType = msgData.costType
  103. -- local equipIndex = gameequip.index(wearBar, equipPos)
  104. -- local equipInfo = getequipinfo(actor,equipIndex,0) --没有则返回空表
  105. -- local itemId = equipInfo.id
  106. local lv = API.GetItemData(actor, itemId, "strengthlv") or 0
  107. lv = lv + 1
  108. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar] then
  109. messagebox(actor, "不可强化的装备栏")
  110. return
  111. end
  112. -- cfg_item中subType字段
  113. if Equip_QiangHua_Data.tItemWearPos[subType] == nil then
  114. messagebox(actor, "该装备无法强化")
  115. return
  116. end
  117. local costGroup = Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar][equipPos].costGroup
  118. if not Equip_QiangHua_Data.tCostGroup[costGroup][lv] then
  119. messagebox(actor, "已强化至最高级!")
  120. return
  121. end
  122. -- 消耗
  123. local group = Equip_QiangHua_Data.tCostGroup[costGroup]
  124. local tCost = Equip_QiangHua_Data.tCostGroup[costGroup][lv]
  125. local tCoseReal = API.TableDeepcopy(tCost)
  126. -- 概率
  127. -- 基础概率
  128. local gailv = tCost.gailv
  129. if tCost.sChoice == true then
  130. local item = group[msgData.costName]
  131. if item ~= nil then
  132. local addgailv = item.addgailv and item.addgailv or 0
  133. gailv = gailv + addgailv
  134. local tmpCoseReal = {}
  135. for index, value in ipairs(tCoseReal) do
  136. if tCoseReal[index][1] == msgData.costName then
  137. table.insert(tmpCoseReal, tCoseReal[index]);
  138. break
  139. end
  140. end
  141. -- 星际宝石逻辑
  142. if msgData.costName == "星际宝石" and item.setLevel ~= nil then
  143. table.insert(tmpCoseReal, {"星际宝石", 1});
  144. lv = item.setLevel
  145. end
  146. tCoseReal = tmpCoseReal;
  147. else
  148. messagebox(actor, "请选择所需材料")
  149. return
  150. end
  151. end
  152. for index, value in ipairs(tCoseReal) do
  153. local item = group[tCoseReal[index][1]]
  154. if item ~= nil and item.name ~= nil then
  155. tCoseReal[index][1] = item.name
  156. end
  157. end
  158. if #tCoseReal <= 0 then
  159. messagebox(actor, "材料错误!")
  160. return
  161. end
  162. if not API.CheckItem(actor, tCoseReal) then
  163. messagebox(actor, "材料不足!")
  164. return
  165. end
  166. if not API.takeItem(actor, tCoseReal, "装备强化") then
  167. messagebox(actor, "材料不足!")
  168. return
  169. end
  170. -- 计算幸运属性概率
  171. if API.GetItemLuck(actor, itemId) then
  172. gailv = gailv + 25
  173. end
  174. -- 计算幸运道具概率
  175. local XingYunNum = msgData.XingYunNum and math.min(msgData.XingYunNum, 1) or 0
  176. if XingYunNum > 0 then
  177. local tcl = {{"合成幸运符", XingYunNum}}
  178. if not API.CheckItem(actor, tcl) then
  179. messagebox(actor, "材料不足!")
  180. return
  181. end
  182. if not API.takeItem(actor, tcl, "装备强化") then
  183. messagebox(actor, "材料不足!")
  184. return
  185. end
  186. gailv = gailv + (XingYunNum * 10)
  187. end
  188. local xiaohui = true
  189. local BaoHuNum = msgData.BaoHuNum and math.min(msgData.BaoHuNum, 1) or 0
  190. if BaoHuNum > 0 then
  191. local tcl = {{"合成保护符咒", BaoHuNum}}
  192. if API.CheckItem(actor, tcl) then
  193. if API.takeItem(actor, tcl, "装备强化") then
  194. xiaohui = false
  195. end
  196. end
  197. end
  198. if math.random(1, 100) > gailv then
  199. if tCost.failAddLevel ~= nil then
  200. lv = lv + tCost.failAddLevel - 1
  201. -- 刷新装备
  202. API.SetItemData(actor, itemId, "strengthlv", lv)
  203. -- 刷新流光
  204. API.refreshLiuGuang(actor, itemId)
  205. -- 通知客户端更新
  206. this.RefreshLevel(actor, itemId, cfgId)
  207. elseif tCost.failLevel ~= nil then
  208. if tCost.failLevel == -1 then
  209. -- local xiaohui = true
  210. -- local BaoHuNum = msgData.BaoHuNum or 0
  211. -- if BaoHuNum > 0 then
  212. -- local tcl = {{"合成保护符咒", BaoHuNum}}
  213. -- if API.CheckItem(actor, tcl) then
  214. -- if API.takeItem(actor, tcl) then
  215. -- xiaohui = false
  216. -- end
  217. -- end
  218. -- end
  219. if xiaohui then
  220. if equipInfo.equipindex ~= 0 then
  221. local itemId = equipInfo.id
  222. takeofftheequip(actor, equipInfo.equipindex)
  223. local bagIndex = gainbagidxbyitemid(actor, itemId)
  224. destroyitemafter(actor, bagIndex, "装备强化")
  225. local data = {
  226. sendType = 11
  227. }
  228. sendluamsg(actor, this.msgID, data)
  229. elseif equipInfo.bagindex ~= 0 then
  230. destroyitemafter(actor, equipInfo.bagindex, "装备强化")
  231. local data = {
  232. sendType = 11
  233. }
  234. sendluamsg(actor, this.msgID, data)
  235. return
  236. end
  237. end
  238. lv = 0
  239. -- 刷新装备
  240. API.SetItemData(actor, itemId, "strengthlv", lv)
  241. -- 刷新流光
  242. API.refreshLiuGuang(actor, itemId)
  243. -- 通知客户端更新
  244. this.RefreshLevel(actor, itemId, cfgId)
  245. return
  246. end
  247. lv = tCost.failLevel
  248. -- 刷新装备
  249. API.SetItemData(actor, itemId, "strengthlv", lv)
  250. -- 刷新流光
  251. API.refreshLiuGuang(actor, itemId)
  252. -- 通知客户端更新
  253. this.RefreshLevel(actor, itemId, cfgId)
  254. end
  255. -- --失败销毁装备机制
  256. -- if lv > 10 then
  257. -- local xiaohui = true
  258. -- local BaoHuNum = msgData.BaoHuNum or 0
  259. -- if BaoHuNum > 0 then
  260. -- local tcl = {{"合成保护符咒",BaoHuNum}}
  261. -- if API.CheckItem(actor,tcl) then
  262. -- if API.takeItem(actor,tCost) then
  263. -- xiaohui = false
  264. -- end
  265. -- end
  266. -- end
  267. -- if xiaohui then
  268. -- if equipInfo.equipindex ~= 0 then
  269. -- local itemId = equipInfo.id
  270. -- takeofftheequip(actor,equipInfo.equipindex)
  271. -- local bagIndex = gainbagidxbyitemid(actor,itemId)
  272. -- destroyitemafter(actor,bagIndex)
  273. -- messagebox(actor,"强化失败,装备销毁!")
  274. -- local data = {
  275. -- sendType = 11,
  276. -- }
  277. -- sendluamsg(actor,this.msgID,data)
  278. -- elseif equipInfo.bagindex ~= 0 then
  279. -- destroyitemafter(actor,equipInfo.bagindex)
  280. -- messagebox(actor,"强化失败,装备销毁!")
  281. -- return
  282. -- end
  283. -- end
  284. -- elseif lv > 7 then
  285. -- lv = 0
  286. -- end
  287. return
  288. end
  289. API.SetItemData(actor, itemId, "strengthlv", lv)
  290. -- info("刷新流光")
  291. -- 刷新流光
  292. API.refreshLiuGuang(actor, itemId)
  293. if tonumber(lv) >= 10 then
  294. local name = getrolefield(actor, "role.basic.name")
  295. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  296. -- 发送跑马灯
  297. noticeTip.noticeinfo(actor, StringIdConst.STRENGTHEN_ALL_SERVER, name, equipName, lv)
  298. -- 发送世界聊天提示
  299. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT503, name, equipName, lv)
  300. end
  301. local equipItemInfo = getequipinfo(actor, itemId, 1)
  302. local result = {{
  303. itemId = equipItemInfo.id,
  304. itemCfgId = equipItemInfo.cfgid
  305. }}
  306. -- HeChengQiangHuaTiaoZhan.CheckTaskIsFinish(actor,result)
  307. -- DaKaHuoDong.CheckTaskIsFinish(actor,DaKaHuoDong.taskType.forging,1)
  308. -- 检测穿戴条件 条件不足脱装备并且调用客户端刷新
  309. if msgData.equipPos ~= 0 then
  310. -- 刷新强化装备属性
  311. this.sendAttr(actor, itemId)
  312. if not this.checkTakeOnNeed(actor, itemId) then
  313. local equipIndex = gameequip.index(wearBar, equipPos)
  314. takeofftheequip(actor, equipIndex)
  315. local data = {
  316. sendType = 11
  317. }
  318. sendluamsg(actor, this.msgID, data)
  319. return
  320. end
  321. end
  322. -- 通知客户端更新
  323. this.RefreshLevel(actor, itemId, cfgId)
  324. EquipDurability.refreshDurability(actor, itemId)
  325. end
  326. -- 检测穿戴条件 条件不足脱装备并且调用客户端刷新
  327. function this.checkTakeOnNeed(actor, itemId)
  328. local tNeed = EquipFunc.getEquipStrengthNeed(actor, itemId)
  329. for i = 1, #tNeed do
  330. local attId = tNeed[i][1]
  331. local need = tNeed[i][2]
  332. local attName = attrid2name(actor, attId)
  333. if getattrinfo(actor, attName) < need then
  334. return false
  335. end
  336. end
  337. return true
  338. end
  339. -- 刷新强化装备属性
  340. function this.sendAttr(actor, itemId)
  341. local wearBar, equipPos = API.ItemId2WearBarAndPos(actor, itemId)
  342. local lv = API.GetItemData(actor, itemId, "strengthlv") or 0
  343. -- if lv <= 0 then
  344. -- addrolekmlattributes(actor,"装备强化属性"..wearBar.."#"..equipPos, {})
  345. -- return
  346. -- end
  347. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar] then
  348. return
  349. end
  350. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar][equipPos] then
  351. return
  352. end
  353. -- info("进入强化属性","强化属性")
  354. local equipInfo = getequipinfo(actor, itemId, 1)
  355. local equipindex = equipInfo.equipindex
  356. local durabilityAttPct = getequipdurability(actor, equipindex, 0) or 100
  357. local attPct = math.floor(durabilityAttPct / 100)
  358. local tAttr = EquipFunc.getEquipAllStrengthAttr(actor, itemId)
  359. -- info(tAttr,"tAttr","装备强化")
  360. local tab = {}
  361. for k, v in pairs(tAttr) do
  362. local attId = v[1]
  363. local val = v[2]
  364. if tab[attId] then
  365. tab[attId] = tab[attId] + val
  366. else
  367. tab[attId] = val * attPct
  368. end
  369. end
  370. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. equipPos, tab)
  371. end
  372. function this.takeOffEquip(actor, pos, itemId, itemCfgId)
  373. local wearBar = 1
  374. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. pos, {})
  375. end
  376. -- 穿戴装备后
  377. GameEvent.add(EventCfg.onTakeOnEquip, function(actor, pos, oldItemId, itemId, itemCfgId)
  378. this.sendAttr(actor, itemId)
  379. end, filename)
  380. -- 脱装备后
  381. GameEvent.add(EventCfg.onTakeOffEquip, function(actor, pos, itemId, itemCfgId)
  382. -- local wearBar,equipPos = API.ItemId2WearBarAndPos(actor,itemId)
  383. local wearBar = 1
  384. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. pos, {})
  385. end, filename)
  386. -- 重载配置
  387. -- GameEvent.add(EventCfg.onReloadScript,function(actor)
  388. -- this.sendDataToClient(actor)
  389. -- end,filename)
  390. -- 登录
  391. -- GameEvent.add(EventCfg.onLoginEnd,function(actor)
  392. -- this.sendDataToClient(actor)
  393. -- end,filename)
  394. function this.questQiangHua(actor, msgData)
  395. info(actor, "msgID111=" .. this.msgID)
  396. info(actor, "msgData.sendType=" .. msgData.sendType)
  397. info(actor, "msgData.sendType=" .. type(msgData.sendType))
  398. if msgData.sendType == 1 then
  399. this.main(actor)
  400. elseif msgData.sendType == 2 then
  401. this.SendData(actor)
  402. elseif msgData.sendType == 3 then
  403. this.Click(actor, msgData)
  404. end
  405. end
  406. -- GameEvent.add(EventCfg.onHandlereQuest,
  407. -- function(actor, msgID, msgData)
  408. -- info(actor,"msgID111="..this.msgID)
  409. -- info(actor,"msgData.sendType="..msgData.sendType)
  410. -- info(actor,"msgData.sendType="..type(msgData.sendType))
  411. -- if this.msgID ~= msgID then
  412. -- return
  413. -- end
  414. -- if msgData.sendType == 1 then
  415. -- this.main(actor)
  416. -- elseif msgData.sendType == 2 then
  417. -- this.SendData(actor)
  418. -- elseif msgData.sendType == 3 then
  419. -- this.Click(actor,msgData)
  420. -- end
  421. -- return true
  422. -- end
  423. -- , filename)
  424. -- 玩家进入视野
  425. GameEvent.add(EventCfg.onPlayerEnterView, function(actor, targetPlayer)
  426. end, this.filename)