Equip_QiangHua.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. -- 计算幸运属性概率
  167. if API.GetItemLuck(actor, itemId) then
  168. gailv = gailv + 25
  169. end
  170. -- 计算幸运道具概率
  171. local XingYunNum = msgData.XingYunNum and math.min(msgData.XingYunNum, 1) or 0
  172. if XingYunNum > 0 then
  173. local tcl = {{"合成幸运符", XingYunNum}}
  174. if not API.CheckItem(actor, tcl) then
  175. messagebox(actor, "合成幸运符不足!")
  176. return
  177. end
  178. gailv = gailv + (XingYunNum * 10)
  179. end
  180. local xiaohui = true
  181. local BaoHuNum = msgData.BaoHuNum and math.min(msgData.BaoHuNum, 1) or 0
  182. if BaoHuNum > 0 then
  183. local tcl = {{"合成保护符咒", BaoHuNum}}
  184. if not API.CheckItem(actor, tcl) then
  185. messagebox(actor, "合成保护符咒不足!")
  186. return
  187. else
  188. xiaohui = false
  189. end
  190. end
  191. if XingYunNum > 0 then
  192. local tcl = {{"合成幸运符", XingYunNum}}
  193. if not API.takeItem(actor, tcl, "装备强化") then
  194. messagebox(actor, "合成幸运符不足!!")
  195. return
  196. end
  197. end
  198. if BaoHuNum > 0 then
  199. local tcl = {{"合成保护符咒", BaoHuNum}}
  200. if not API.takeItem(actor, tcl, "装备强化") then
  201. messagebox(actor, "合成保护符咒不足!!")
  202. return
  203. end
  204. end
  205. if not API.takeItem(actor, tCoseReal, "装备强化") then
  206. messagebox(actor, "材料不足!!")
  207. return
  208. end
  209. if math.random(1, 100) > gailv then
  210. if tCost.failAddLevel ~= nil then
  211. lv = lv + tCost.failAddLevel - 1
  212. -- 刷新装备
  213. API.SetItemData(actor, itemId, "strengthlv", lv)
  214. -- 刷新流光
  215. API.refreshLiuGuang(actor, itemId)
  216. -- 通知客户端更新
  217. this.RefreshLevel(actor, itemId, cfgId)
  218. elseif tCost.failLevel ~= nil then
  219. if tCost.failLevel == -1 then
  220. -- local xiaohui = true
  221. -- local BaoHuNum = msgData.BaoHuNum or 0
  222. -- if BaoHuNum > 0 then
  223. -- local tcl = {{"合成保护符咒", BaoHuNum}}
  224. -- if API.CheckItem(actor, tcl) then
  225. -- if API.takeItem(actor, tcl) then
  226. -- xiaohui = false
  227. -- end
  228. -- end
  229. -- end
  230. if xiaohui then
  231. if equipInfo.equipindex ~= 0 then
  232. local itemId = equipInfo.id
  233. takeofftheequip(actor, equipInfo.equipindex)
  234. local bagIndex = gainbagidxbyitemid(actor, itemId)
  235. destroyitemafter(actor, bagIndex, "装备强化")
  236. local data = {
  237. sendType = 11
  238. }
  239. sendluamsg(actor, this.msgID, data)
  240. elseif equipInfo.bagindex ~= 0 then
  241. destroyitemafter(actor, equipInfo.bagindex, "装备强化")
  242. local data = {
  243. sendType = 11
  244. }
  245. sendluamsg(actor, this.msgID, data)
  246. return
  247. end
  248. end
  249. lv = 0
  250. -- 刷新装备
  251. API.SetItemData(actor, itemId, "strengthlv", lv)
  252. -- 刷新流光
  253. API.refreshLiuGuang(actor, itemId)
  254. -- 通知客户端更新
  255. this.RefreshLevel(actor, itemId, cfgId)
  256. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, {issuccess=false})
  257. return
  258. end
  259. lv = tCost.failLevel
  260. -- 刷新装备
  261. API.SetItemData(actor, itemId, "strengthlv", lv)
  262. -- 刷新流光
  263. API.refreshLiuGuang(actor, itemId)
  264. -- 通知客户端更新
  265. this.RefreshLevel(actor, itemId, cfgId)
  266. end
  267. -- --失败销毁装备机制
  268. -- if lv > 10 then
  269. -- local xiaohui = true
  270. -- local BaoHuNum = msgData.BaoHuNum or 0
  271. -- if BaoHuNum > 0 then
  272. -- local tcl = {{"合成保护符咒",BaoHuNum}}
  273. -- if API.CheckItem(actor,tcl) then
  274. -- if API.takeItem(actor,tCost) then
  275. -- xiaohui = false
  276. -- end
  277. -- end
  278. -- end
  279. -- if xiaohui then
  280. -- if equipInfo.equipindex ~= 0 then
  281. -- local itemId = equipInfo.id
  282. -- takeofftheequip(actor,equipInfo.equipindex)
  283. -- local bagIndex = gainbagidxbyitemid(actor,itemId)
  284. -- destroyitemafter(actor,bagIndex)
  285. -- messagebox(actor,"强化失败,装备销毁!")
  286. -- local data = {
  287. -- sendType = 11,
  288. -- }
  289. -- sendluamsg(actor,this.msgID,data)
  290. -- elseif equipInfo.bagindex ~= 0 then
  291. -- destroyitemafter(actor,equipInfo.bagindex)
  292. -- messagebox(actor,"强化失败,装备销毁!")
  293. -- return
  294. -- end
  295. -- end
  296. -- elseif lv > 7 then
  297. -- lv = 0
  298. -- end
  299. -- 通知客户端更新
  300. this.RefreshLevel(actor, itemId, cfgId)
  301. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, {issuccess=false})
  302. return
  303. end
  304. API.SetItemData(actor, itemId, "strengthlv", lv)
  305. -- info("刷新流光")
  306. -- 刷新流光
  307. API.refreshLiuGuang(actor, itemId)
  308. if tonumber(lv) >= 10 then
  309. local name = getrolefield(actor, "role.basic.name")
  310. local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId)
  311. -- 发送跑马灯
  312. noticeTip.noticeinfo(actor, StringIdConst.STRENGTHEN_ALL_SERVER, name, equipName, lv)
  313. -- 发送世界聊天提示
  314. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT503, name, equipName, lv)
  315. end
  316. local equipItemInfo = getequipinfo(actor, itemId, 1)
  317. local result = {{
  318. itemId = equipItemInfo.id,
  319. itemCfgId = equipItemInfo.cfgid
  320. }}
  321. -- HeChengQiangHuaTiaoZhan.CheckTaskIsFinish(actor,result)
  322. -- DaKaHuoDong.CheckTaskIsFinish(actor,DaKaHuoDong.taskType.forging,1)
  323. -- 检测穿戴条件 条件不足脱装备并且调用客户端刷新
  324. if msgData.equipPos ~= 0 then
  325. -- 刷新强化装备属性
  326. this.sendAttr(actor, itemId)
  327. if not this.checkTakeOnNeed(actor, itemId) then
  328. local equipIndex = gameequip.index(wearBar, equipPos)
  329. takeofftheequip(actor, equipIndex)
  330. local data = {
  331. sendType = 11
  332. }
  333. sendluamsg(actor, this.msgID, data)
  334. return
  335. end
  336. end
  337. -- 通知客户端更新
  338. this.RefreshLevel(actor, itemId, cfgId)
  339. EquipDurability.refreshDurability(actor, itemId)
  340. sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, {issuccess=true})
  341. end
  342. -- 检测穿戴条件 条件不足脱装备并且调用客户端刷新
  343. function this.checkTakeOnNeed(actor, itemId)
  344. local tNeed = EquipFunc.getEquipStrengthNeed(actor, itemId)
  345. for i = 1, #tNeed do
  346. local attId = tNeed[i][1]
  347. local need = tNeed[i][2]
  348. local attName = attrid2name(actor, attId)
  349. if getattrinfo(actor, attName) < need then
  350. return false
  351. end
  352. end
  353. return true
  354. end
  355. -- 刷新强化装备属性
  356. function this.sendAttr(actor, itemId)
  357. local wearBar, equipPos = API.ItemId2WearBarAndPos(actor, itemId)
  358. local lv = API.GetItemData(actor, itemId, "strengthlv") or 0
  359. -- if lv <= 0 then
  360. -- addrolekmlattributes(actor,"装备强化属性"..wearBar.."#"..equipPos, {})
  361. -- return
  362. -- end
  363. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar] then
  364. return
  365. end
  366. if not Equip_QiangHua_Data.tEquipWearBarAndPos[wearBar][equipPos] then
  367. return
  368. end
  369. -- info("进入强化属性","强化属性")
  370. local equipInfo = getequipinfo(actor, itemId, 1)
  371. local equipindex = equipInfo.equipindex
  372. local durabilityAttPct = getequipdurability(actor, equipindex, 0) or 100
  373. local attPct = math.floor(durabilityAttPct / 100)
  374. local tAttr = EquipFunc.getEquipAllStrengthAttr(actor, itemId)
  375. -- info(tAttr,"tAttr","装备强化")
  376. local tab = {}
  377. for k, v in pairs(tAttr) do
  378. local attId = v[1]
  379. local val = v[2]
  380. if tab[attId] then
  381. tab[attId] = tab[attId] + val
  382. else
  383. tab[attId] = val * attPct
  384. end
  385. end
  386. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. equipPos, tab)
  387. end
  388. function this.takeOffEquip(actor, pos, itemId, itemCfgId)
  389. local wearBar = 1
  390. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. pos, {})
  391. end
  392. -- 穿戴装备后
  393. GameEvent.add(EventCfg.onTakeOnEquip, function(actor, pos, oldItemId, itemId, itemCfgId)
  394. this.sendAttr(actor, itemId)
  395. end, filename)
  396. -- 脱装备后
  397. GameEvent.add(EventCfg.onTakeOffEquip, function(actor, pos, itemId, itemCfgId)
  398. -- local wearBar,equipPos = API.ItemId2WearBarAndPos(actor,itemId)
  399. local wearBar = 1
  400. addrolekmlattributes(actor, "装备强化属性" .. wearBar .. "#" .. pos, {})
  401. end, filename)
  402. -- 重载配置
  403. -- GameEvent.add(EventCfg.onReloadScript,function(actor)
  404. -- this.sendDataToClient(actor)
  405. -- end,filename)
  406. -- 登录
  407. -- GameEvent.add(EventCfg.onLoginEnd,function(actor)
  408. -- this.sendDataToClient(actor)
  409. -- end,filename)
  410. function this.questQiangHua(actor, msgData)
  411. info(actor, "msgID111=" .. this.msgID)
  412. info(actor, "msgData.sendType=" .. msgData.sendType)
  413. info(actor, "msgData.sendType=" .. type(msgData.sendType))
  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. end
  422. -- GameEvent.add(EventCfg.onHandlereQuest,
  423. -- function(actor, msgID, msgData)
  424. -- info(actor,"msgID111="..this.msgID)
  425. -- info(actor,"msgData.sendType="..msgData.sendType)
  426. -- info(actor,"msgData.sendType="..type(msgData.sendType))
  427. -- if this.msgID ~= msgID then
  428. -- return
  429. -- end
  430. -- if msgData.sendType == 1 then
  431. -- this.main(actor)
  432. -- elseif msgData.sendType == 2 then
  433. -- this.SendData(actor)
  434. -- elseif msgData.sendType == 3 then
  435. -- this.Click(actor,msgData)
  436. -- end
  437. -- return true
  438. -- end
  439. -- , filename)
  440. -- 玩家进入视野
  441. GameEvent.add(EventCfg.onPlayerEnterView, function(actor, targetPlayer)
  442. end, this.filename)