EquipDurability.lua 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. EquipDurability = {}
  2. local filename = "EquipDurability"
  3. EquipDurability.equipWhereAndPos = {
  4. -- [穿戴栏] = {
  5. -- [耐久类型] = {装备位1,装备位2}, 耐久类型1=武器耐久流程 2=防具耐久类型 3=饰品耐久类型
  6. -- }
  7. -- 基础装备
  8. [1] = {
  9. -- 部位为2的.单独处理.因为副手有武器或盾牌的区别.它可能是武器.可能是防具
  10. [1] = {1, 3},
  11. [2] = {4, 5, 6, 7, 8, 9, 15, 16},
  12. [3] = {10, 11, 12, 13, 14}
  13. }
  14. }
  15. local quiverId = 20230111
  16. function EquipDurability.onLoginEnd(actor)
  17. end
  18. -- 获取抵抗值
  19. function EquipDurability.getDiKangZhi(actor, itemId)
  20. local dikangzhi = 11280
  21. return dikangzhi
  22. end
  23. -- 获取耐久基础值 道具表 + 强化规则
  24. function EquipDurability.getBaseDurability(actor, itemId)
  25. local equipInfo = getequipinfo(actor, itemId, 1)
  26. local cfgId = equipInfo.cfgid
  27. local maxDurability = ConfigDataManager.getTableValue("cfg_item", "Durability", "id", cfgId) or 0
  28. if maxDurability == "" then
  29. maxDurability = 0
  30. end
  31. local strenthLevel = EquipFunc.getEquipStrengthLevel(actor, itemId)
  32. local strenthDurability = 0
  33. if strenthLevel > 0 then
  34. for i = 1, strenthLevel do
  35. if i <= 4 then
  36. strenthDurability = strenthDurability + 1
  37. elseif i <= 9 then
  38. strenthDurability = strenthDurability + 2
  39. elseif i == 10 then
  40. strenthDurability = strenthDurability + 3
  41. elseif i == 11 then
  42. strenthDurability = strenthDurability + 4
  43. elseif i == 12 then
  44. strenthDurability = strenthDurability + 5
  45. elseif i == 13 then
  46. strenthDurability = strenthDurability + 6
  47. elseif i == 14 then
  48. strenthDurability = strenthDurability + 7
  49. elseif i == 15 then
  50. strenthDurability = strenthDurability + 8
  51. end
  52. end
  53. end
  54. return maxDurability + strenthDurability
  55. end
  56. -- 获取装备耐久度 return 最大耐久
  57. function EquipDurability.getMaxDurability(actor, itemId)
  58. -- 根据道具表获取基础耐久度
  59. local maxDurability = EquipDurability.getBaseDurability(actor, itemId)
  60. -- 最终耐久度 基础耐久度 * 抵抗值
  61. maxDurability = maxDurability * EquipDurability.getDiKangZhi(actor, itemId)
  62. return maxDurability
  63. end
  64. -- 物品进入背包后 初始化耐久度
  65. function EquipDurability.iniData(actor, itemId, itemCfgId, index)
  66. local mainType = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
  67. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId)
  68. if mainType ~= "2" then
  69. return
  70. end
  71. -- 坐骑道具默认发放且穿戴 穿戴的时候道具不存在 无法设置变量会报错 所以坐骑类型return
  72. if subType == "16" then
  73. return
  74. end
  75. if API.GetItemData(actor, itemId, "setDurability") == 1 then
  76. return
  77. end
  78. local maxDurability = EquipDurability.getMaxDurability(actor, itemId)
  79. info("物品耐久初始化:maxDurability" .. maxDurability, "装备耐久")
  80. EquipDurability.addDurability(actor, itemId, maxDurability)
  81. API.SetItemData(actor, itemId, "setDurability", 1)
  82. end
  83. GameEvent.add(EventCfg.addbag, function(actor, itemId, itemCfgId, index)
  84. EquipDurability.iniData(actor, itemId, itemCfgId, index)
  85. end, filename)
  86. -- 修理气泡 客户端
  87. -- local popoverPanel = GUI:GetUI("dev/ui/Preview/Panel/KLPopover/KLPopoverPanel")
  88. -- popoverPanel:SetPopoverData(PopoverType.Tip_EquipDurability)
  89. -- popoverPanel:RefreshUI()
  90. -- 扣除装备耐久
  91. -- 获取当前耐久
  92. function EquipDurability.getNowDurability(actor, itemId)
  93. return API.GetItemData(actor, itemId, "Durability") or 0
  94. end
  95. -- 增加装备耐久
  96. function EquipDurability.addDurability(actor, itemId, num)
  97. local Durability = EquipDurability.getNowDurability(actor, itemId)
  98. API.SetItemData(actor, itemId, "Durability", Durability + num)
  99. EquipDurability.refreshAttr(actor, itemId)
  100. end
  101. -- 降低装备扣除耐久速度
  102. function EquipDurability.getNewDelDurabilityNum(actor, itemId, num, DurabilityType)
  103. local equipInfo = getequipinfo(actor, itemId, 1)
  104. local cfgId = equipInfo.cfgid
  105. -- local mainType = ConfigDataManager.getTableValue("cfg_item", "type", "id", cfgId)
  106. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  107. if DurabilityType == 1 or DurabilityType == 2 then
  108. -- 武器防具
  109. local delDurability1 = getattrinfo(actor, "delDurability1")
  110. if delDurability1 > 0 then
  111. if tonumber(subType) <= 9 then
  112. num = math.ceil(num * (1 - delDurability1))
  113. end
  114. end
  115. -- 守护坐骑
  116. local delDurability3 = getattrinfo(actor, "delDurability3")
  117. if delDurability3 > 0 then
  118. if tonumber(subType) == 14 or tonumber(subType) == 16 then
  119. num = math.ceil(num * (1 - delDurability3))
  120. end
  121. end
  122. elseif DurabilityType == 3 then
  123. -- 首饰
  124. local delDurability2 = getattrinfo(actor, "delDurability2")
  125. if delDurability2 > 0 then
  126. if tonumber(subType) == 10 or tonumber(subType) == 11 then
  127. num = math.ceil(num * (1 - delDurability2))
  128. end
  129. end
  130. end
  131. return num
  132. end
  133. -- 扣除装备耐久 DurabilityType 1=武器耐久类型 2=防具耐久类型 3=首饰耐久类型
  134. function EquipDurability.delDurability(actor, itemId, num, DurabilityType)
  135. -- 装备耐久扣完了.
  136. if EquipDurability.getNowDurabilityPct(actor, itemId) <= 0 then
  137. return
  138. end
  139. local Durability = EquipDurability.getNowDurability(actor, itemId)
  140. num = EquipDurability.getNewDelDurabilityNum(actor, itemId, num, DurabilityType)
  141. API.SetItemData(actor, itemId, "Durability", Durability - num)
  142. EquipDurability.refreshAttr(actor, itemId)
  143. end
  144. -- 获取当前耐久百分比
  145. function EquipDurability.getNowDurabilityPct(actor, itemId)
  146. local nowDurability = EquipDurability.getNowDurability(actor, itemId)
  147. local maxDurability = EquipDurability.getMaxDurability(actor, itemId)
  148. -- 配置表不对.导致所有装备都无法修理
  149. if maxDurability == 0 then
  150. maxDurability = 1
  151. end
  152. return (maxDurability + nowDurability) / maxDurability * 100
  153. end
  154. function EquipDurability.refreshDurability(actor, itemId)
  155. local pct = EquipDurability.getNowDurabilityPct(actor, itemId)
  156. local attPct = 100
  157. if pct <= 0 then
  158. attPct = 0
  159. elseif pct < 20 then
  160. attPct = 50
  161. elseif pct < 30 then
  162. attPct = 70
  163. elseif pct < 50 then
  164. attPct = 80
  165. end
  166. local equipInfo = getequipinfo(actor, itemId, 1)
  167. local equipindex = equipInfo.equipindex
  168. if equipindex ~= 0 then
  169. setequipdurability(actor, equipindex, 0, attPct)
  170. else
  171. setequipdurability(actor, itemId, 1, attPct)
  172. end
  173. end
  174. function EquipDurability.refreshAttr(actor, itemId)
  175. local equipInfo = getequipinfo(actor, itemId, 1)
  176. local cfgId = equipInfo.cfgid
  177. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  178. if tonumber(subType) == 14 then
  179. return
  180. end
  181. local pct = EquipDurability.getNowDurabilityPct(actor, itemId)
  182. local attPct = 100
  183. if pct <= 50 then
  184. sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
  185. sendType = 2,
  186. itemId = itemId,
  187. pct = pct
  188. }) -- 通知气泡
  189. end
  190. if pct <= 0 then
  191. attPct = 0
  192. elseif pct < 20 then
  193. attPct = 50
  194. elseif pct < 30 then
  195. attPct = 70
  196. elseif pct < 50 then
  197. attPct = 80
  198. end
  199. local equipInfo = getequipinfo(actor, itemId, 1)
  200. local equipindex = equipInfo.equipindex
  201. if equipindex ~= 0 then
  202. setequipdurability(actor, equipindex, 0, attPct)
  203. else
  204. setequipdurability(actor, itemId, 1, attPct)
  205. end
  206. -- info("equipindex="..equipindex,type(equipindex),"equipindex")
  207. -- 处理强化属性
  208. -- Equip_QiangHua.sendAttr(actor, itemId)
  209. end
  210. -- function EquipDurability.OpenPopover(actor,itemId)
  211. -- end
  212. -- function EquipDurability.getbasicattr(actor)
  213. -- local equipIndex = gameequip.index(1, 1)
  214. -- local equipInfo = getequipinfo(actor,equipIndex,0)
  215. -- local itemId = equipInfo.id
  216. -- local equipInfo = getequipinfo(actor,itemId,1)
  217. -- local basicattr = equipInfo.basicattr
  218. -- info(basicattr,"basicattr")
  219. -- end
  220. -- 获取武器每次攻击要扣除的耐久度
  221. function EquipDurability.getDelDurability_1(actor, target, itemId)
  222. local armor = getattrinfo(target, "armor") -- 防御值
  223. armor = math.max(armor, 1)
  224. local equipInfo = getequipinfo(actor, itemId, 1)
  225. local basicattr = equipInfo.basicattr
  226. local minAtk = 1
  227. local maxAtk = 1
  228. for i = 1, #basicattr do
  229. local attrid = basicattr[i].attrid
  230. if attrid == 201021 then
  231. minAtk = basicattr[i].value
  232. end
  233. if attrid == 201011 then
  234. maxAtk = basicattr[i].value
  235. end
  236. end
  237. local delDurability = armor * 2 / (minAtk + maxAtk / 2)
  238. delDurability = math.ceil(delDurability) * 10
  239. local zhuangbeiyingdutishengRate = getattrinfo(target, "zhuangbeiyingdutishengRate") -- 装备硬度提升
  240. if zhuangbeiyingdutishengRate > 0 then
  241. delDurability = delDurability * (1 - zhuangbeiyingdutishengRate)
  242. end
  243. return delDurability
  244. end
  245. function EquipDurability.getDelDurability_1_1(equipInfo)
  246. local basicattr = equipInfo.basicattr
  247. local minAtk = 1
  248. local maxAtk = 1
  249. for i = 1, #basicattr do
  250. local attrid = basicattr[i].attrid
  251. if attrid == 201021 then
  252. minAtk = basicattr[i].value
  253. end
  254. if attrid == 201011 then
  255. maxAtk = basicattr[i].value
  256. end
  257. end
  258. local armor = math.max(minAtk, 1) * 0.3
  259. local delDurability = armor * 2 / (minAtk + maxAtk / 2)
  260. delDurability = math.ceil(delDurability) * 10
  261. -- local zhuangbeiyingdutishengRate = getattrinfo(target, "zhuangbeiyingdutishengRate") -- 装备硬度提升
  262. -- if zhuangbeiyingdutishengRate > 0 then
  263. -- delDurability = delDurability * (1 - zhuangbeiyingdutishengRate)
  264. -- end
  265. return delDurability
  266. end
  267. -- 获取防具每次被攻击要扣除的耐久度(坐骑和守护类型到时候也放进来 做判断)
  268. function EquipDurability.getDelDurability_2(target, damage, itemId, equipInfo2)
  269. local career = getbaseinfo(target, "getbasecareer")
  270. local pct = 3
  271. if career == 1 then
  272. pct = 3
  273. elseif career == 2 then
  274. pct = 3
  275. elseif career == 3 then
  276. pct = 2
  277. elseif career == 4 then
  278. pct = 7
  279. elseif career == 5 then
  280. pct = 6
  281. elseif career == 6 then
  282. pct = 3
  283. end
  284. local equipInfo = nil
  285. if equipInfo2 ~= nil then
  286. equipInfo = equipInfo2
  287. else
  288. equipInfo = getequipinfo(target, itemId, 1)
  289. end
  290. local basicattr = equipInfo.basicattr
  291. local armor = 1
  292. for i = 1, #basicattr do
  293. local attrid = basicattr[i].attrid
  294. if attrid == 206011 then
  295. armor = basicattr[i].value
  296. end
  297. end
  298. local delDurability = damage / (armor * pct + 0)
  299. delDurability = math.ceil(delDurability)
  300. return delDurability * 10
  301. end
  302. -- 获取时间类型 如果在非安全区 每经过一分钟扣除额耐久度
  303. function EquipDurability.getDelDurability_3(actor, target, itemId)
  304. return 10
  305. end
  306. function EquipDurability.isArmor(actor, equipInfo)
  307. local basicattr = equipInfo.basicattr
  308. for i = 1, #basicattr do
  309. local attrid = basicattr[i].attrid
  310. if attrid == 206011 then
  311. return true
  312. end
  313. end
  314. return false
  315. end
  316. function EquipDurability.attackCost(actor)
  317. local count = APIGetInt(actor, "ZC_DurabilityHurtCount")
  318. if count == 0 then
  319. return
  320. end
  321. APISetInt(actor, "ZC_DurabilityHurtCount", 0)
  322. local wearBar = 1
  323. local DurabilityType = 1
  324. local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
  325. for i = 1, #tEquipPos do
  326. local equipPos = tEquipPos[i]
  327. local equipIndex = gameequip.index(wearBar, equipPos)
  328. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  329. if next(equipInfo) then
  330. local itemId = equipInfo.id
  331. local delDurability = EquipDurability.getDelDurability_1_1(equipInfo) * count
  332. EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
  333. end
  334. end
  335. local equipIndex = gameequip.index(1, 2)
  336. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  337. if next(equipInfo) then
  338. local itemId = equipInfo.id
  339. if not EquipDurability.isArmor(actor, equipInfo) then
  340. if equipInfo.cfgid == quiverId then
  341. else
  342. local delDurability = EquipDurability.getDelDurability_1_1(equipInfo) * count
  343. EquipDurability.delDurability(actor, itemId, delDurability, 1)
  344. end
  345. end
  346. end
  347. end
  348. function EquipDurability.attackCareer3(actor)
  349. local career = getbaseinfo(actor, "getbasecareer")
  350. if career ~= 3 then
  351. return
  352. end
  353. local equipIndex = gameequip.index(1, 2)
  354. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  355. if next(equipInfo) then
  356. if equipInfo.cfgid == quiverId then
  357. EquipDurability.costQuiver(actor, equipIndex, equipInfo, 1)
  358. end
  359. end
  360. sendluamsg(actor, 90000510, {})
  361. end
  362. -- 攻击后 废弃
  363. function EquipDurability.attack(actor, fightParam)
  364. local target = fightParam.target
  365. local castertype = fightParam.castertype
  366. if castertype == MapObjectType.PLAYER then
  367. local wearBar = 1
  368. local DurabilityType = 1
  369. local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
  370. for i = 1, #tEquipPos do
  371. local equipPos = tEquipPos[i]
  372. local equipIndex = gameequip.index(wearBar, equipPos)
  373. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  374. if next(equipInfo) then
  375. local itemId = equipInfo.id
  376. local delDurability = EquipDurability.getDelDurability_1(actor, target, itemId)
  377. EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
  378. end
  379. end
  380. end
  381. local equipIndex = gameequip.index(1, 2)
  382. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  383. if next(equipInfo) then
  384. local itemId = equipInfo.id
  385. if not EquipDurability.isArmor(actor, equipInfo) then
  386. if equipInfo.cfgid == quiverId then
  387. EquipDurability.costQuiver(actor, equipIndex, equipInfo, 1)
  388. else
  389. local delDurability = EquipDurability.getDelDurability_1(actor, target, itemId)
  390. EquipDurability.delDurability(actor, itemId, delDurability, 1)
  391. end
  392. end
  393. end
  394. local career = getbaseinfo(actor, "getbasecareer")
  395. -- 弓箭手需要刷新箭袋耐久
  396. if career == 3 then
  397. sendluamsg(actor, 90000510, {})
  398. end
  399. end
  400. function EquipDurability.takeonequip(actor, pos, oldItemId, itemId, itemCfgId)
  401. if pos ~= 3 then
  402. return
  403. end
  404. local career = getbaseinfo(actor, "getbasecareer")
  405. career = tonumber(career)
  406. if career ~= 3 then
  407. return
  408. end
  409. local wearBar = 1
  410. local equipPos = 2
  411. local equipIndex = gameequip.index(wearBar, equipPos)
  412. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  413. if next(equipInfo) then
  414. return
  415. end
  416. local bagIndex = EquipDurability.getBagQuiverId(actor)
  417. if bagIndex ~= 0 then
  418. putontheequip(actor, bagIndex, equipIndex)
  419. end
  420. end
  421. function EquipDurability.costQuiver(actor, equipIndex, equipInfo, durabilityType)
  422. local itemId = equipInfo.id
  423. local delDurability = EquipDurability.getDiKangZhi(actor, itemId)
  424. EquipDurability.delDurability(actor, itemId, delDurability, durabilityType)
  425. -- 耐久消耗完了.摧毁这个装备
  426. if EquipDurability.getNowDurabilityPct(actor, itemId) <= 0 then
  427. -- 先穿上新的箭筒.
  428. local items = getallbagiteminfo(actor)
  429. for index, value in ipairs(items) do
  430. local item = items[index]
  431. if item.cfgid == quiverId then
  432. putontheequip(actor, item.bagindex, equipIndex)
  433. break
  434. end
  435. end
  436. local bagIndex = gainbagidxbyitemid(actor, itemId)
  437. if bagIndex ~= 0 then
  438. destroyitemafter(actor, bagIndex, "装备耐久")
  439. end
  440. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  441. if EquipDurability.getNowDurabilityPct(actor, equipInfo.id) <= 0 then
  442. APISetInt(actor, "ZC_Quiver_Durability", 1, 1)
  443. end
  444. end
  445. end
  446. function EquipDurability.getBagQuiverId(actor)
  447. local items = getallbagiteminfo(actor)
  448. for index, value in ipairs(items) do
  449. local item = items[index]
  450. if item.cfgid == quiverId then
  451. if EquipDurability.getNowDurabilityPct(actor, item.id) <= 0 then
  452. local bagIndex = gainbagidxbyitemid(actor, item.id)
  453. if bagIndex ~= 0 then
  454. destroyitemafter(actor, bagIndex, "装备耐久")
  455. end
  456. else
  457. return item.bagindex
  458. end
  459. end
  460. end
  461. return 0
  462. end
  463. function EquipDurability.destroyWearQuiver(actor, equipIndex)
  464. local checkBag = {}
  465. local paramMap = {}
  466. paramMap["cfgid"] = quiverId
  467. paramMap["itemcount"] = 1
  468. table.insert(checkBag, paramMap)
  469. local canPutBag1 = checkitemscanputbag(actor, checkBag)
  470. if tonumber(canPutBag1) ~= 0 then
  471. takeofftheequip(actor, equipIndex)
  472. return true
  473. end
  474. return false
  475. end
  476. function EquipDurability.updateQuiver(actor)
  477. local selfType = getbaseinfo(actor, "mapobjecttype")
  478. if selfType == MapObjectType.PLAYER then
  479. local isQuiverDestory = APIGetInt(actor, "ZC_Quiver_Durability", 1)
  480. if isQuiverDestory ~= 1 then
  481. return
  482. end
  483. else
  484. return
  485. end
  486. local wearBar = 1
  487. local equipPos = 2
  488. local equipIndex = gameequip.index(wearBar, equipPos)
  489. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  490. if next(equipInfo) then
  491. local nowDurabilityPct = EquipDurability.getNowDurabilityPct(actor, equipInfo.id)
  492. if nowDurabilityPct <= 0 and EquipDurability.destroyWearQuiver(actor, equipIndex) then
  493. local bagIndex = EquipDurability.getBagQuiverId(actor)
  494. if bagIndex ~= 0 then
  495. putontheequip(actor, bagIndex, equipIndex)
  496. end
  497. end
  498. end
  499. -- 刷新一下箭筒信息
  500. equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  501. if next(equipInfo) then
  502. local nowDurabilityPct = EquipDurability.getNowDurabilityPct(actor, equipInfo.id)
  503. APISetInt(actor, "ZC_Quiver_Durability", nowDurabilityPct <= 0 and 1 or 0, 1)
  504. else
  505. APISetInt(actor, "ZC_Quiver_Durability", 1, 1)
  506. end
  507. end
  508. function EquipDurability.beattackMark(actor, target, targethurt, targettype)
  509. if targettype ~= MapObjectType.PLAYER then
  510. return
  511. end
  512. local damage = APIGetInt(target, "ZC_DurabilityDamage", 1)
  513. if damage == nil then
  514. damage = 0
  515. end
  516. local count = APIGetInt(target, "ZC_DurabilityDamageCount", 1)
  517. if count == nil then
  518. count = 0
  519. end
  520. damage = damage + targethurt
  521. count = count + 1
  522. APISetInt(target, "ZC_DurabilityDamage", damage, 1)
  523. APISetInt(target, "ZC_DurabilityDamageCount", count, 1)
  524. end
  525. function EquipDurability.underattackCost(actor)
  526. local damage = APIGetInt(actor, "ZC_DurabilityDamage", 1)
  527. if damage == nil then
  528. damage = 0
  529. end
  530. local count = APIGetInt(actor, "ZC_DurabilityDamageCount", 1)
  531. if count == nil then
  532. count = 0
  533. end
  534. if count == 0 then
  535. return
  536. end
  537. APISetInt(actor, "ZC_DurabilityDamage", 0, 1)
  538. APISetInt(actor, "ZC_DurabilityDamageCount", 0, 1)
  539. local damageCoe = damage / count
  540. local wearBar = 1
  541. local DurabilityType = 2
  542. local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
  543. -- 筛出穿戴了的 然后随机取一个
  544. local tab = {}
  545. for i = 1, #tEquipPos do
  546. local equipPos = tEquipPos[i]
  547. local equipIndex = gameequip.index(wearBar, equipPos)
  548. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  549. if next(equipInfo) and table.count(equipInfo) > 0 then
  550. local itemId = equipInfo.id
  551. if equipInfo.cfgid ~= quiverId then
  552. -- table.insert(tab, {
  553. -- itemId = itemId,
  554. -- equipPos = equipPos,
  555. -- equipIndex = equipIndex
  556. -- })
  557. -- local index = math.random(1, #tab)
  558. -- local itemId = tab[index].itemId
  559. -- local equipPos = tab[index].equipPos
  560. -- local equipIndex = tab[index].equipIndex
  561. -- info("本次受到攻击扣除equipPos="..equipPos.."#equipIndex="..equipIndex.."的耐久:"..delDurability,"扣耐久")
  562. local delDurability = EquipDurability.getDelDurability_2(actor, damageCoe, itemId, equipInfo) * count
  563. EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
  564. end
  565. end
  566. -- if #tab > 0 then
  567. -- end
  568. end
  569. local equipIndex = gameequip.index(1, 2)
  570. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  571. if next(equipInfo) then
  572. local itemId = equipInfo.id
  573. if EquipDurability.isArmor(actor, equipInfo) then
  574. local delDurability = EquipDurability.getDelDurability_2(actor, damageCoe, itemId, equipInfo) * count
  575. EquipDurability.delDurability(actor, itemId, delDurability, 2)
  576. end
  577. end
  578. end
  579. -- 被攻击后 废弃
  580. function EquipDurability.underattack(actor, damage)
  581. local wearBar = 1
  582. local DurabilityType = 2
  583. local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
  584. -- 筛出穿戴了的 然后随机取一个
  585. local tab = {}
  586. for i = 1, #tEquipPos do
  587. local equipPos = tEquipPos[i]
  588. local equipIndex = gameequip.index(wearBar, equipPos)
  589. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  590. if next(equipInfo) then
  591. local itemId = equipInfo.id
  592. if equipInfo.cfgid ~= quiverId then
  593. table.insert(tab, {
  594. itemId = itemId,
  595. equipPos = equipPos,
  596. equipIndex = equipIndex
  597. })
  598. end
  599. end
  600. if #tab > 0 then
  601. local index = math.random(1, #tab)
  602. local itemId = tab[index].itemId
  603. -- local equipPos = tab[index].equipPos
  604. -- local equipIndex = tab[index].equipIndex
  605. -- info("本次受到攻击扣除equipPos="..equipPos.."#equipIndex="..equipIndex.."的耐久:"..delDurability,"扣耐久")
  606. local delDurability = EquipDurability.getDelDurability_2(actor, damage, itemId, equipInfo)
  607. EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
  608. end
  609. end
  610. local equipIndex = gameequip.index(1, 2)
  611. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  612. if next(equipInfo) then
  613. local itemId = equipInfo.id
  614. if EquipDurability.isArmor(actor, equipInfo) then
  615. local delDurability = EquipDurability.getDelDurability_2(actor, damage, itemId, equipInfo)
  616. EquipDurability.delDurability(actor, itemId, delDurability, 2)
  617. end
  618. end
  619. end
  620. function EquipDurability.beattack(actor, target, targethurt, targettype)
  621. -- if targettype == MapObjectType.PLAYER then
  622. -- EquipDurability.underattack(target, targethurt)
  623. -- end
  624. end
  625. -- GameEvent.add(EventCfg.AttackDamage,function(paramMap,fightResult,tAddHurt)
  626. -- local caster = paramMap.caster --—— 攻击对象
  627. -- local target = paramMap.target --—— 受击对象
  628. -- local targethurt = fightResult.targethurt --受击者伤害
  629. -- local targettype = paramMap.targettype --—— 受击者类型
  630. -- if targettype == MapObjectType.PLAYER then
  631. -- EquipDurability.underattack(target,targethurt)
  632. -- end
  633. -- end,filename)
  634. -- 饰品类 不在安全区的时间
  635. function EquipDurability.Timer(actor)
  636. if not getbaseinfo(actor, "safearea") then
  637. local wearBar = 1
  638. local DurabilityType = 3
  639. local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
  640. for i = 1, #tEquipPos do
  641. local equipPos = tEquipPos[i]
  642. local equipIndex = gameequip.index(1, equipPos)
  643. local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
  644. if next(equipInfo) then
  645. local itemId = equipInfo.id
  646. local delDurability = EquipDurability.getDelDurability_3(actor, itemId)
  647. EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
  648. end
  649. end
  650. end
  651. end
  652. -- 获取所有可修理装备的唯一id
  653. function EquipDurability.getAllXiuLiEquip(actor)
  654. -- local wearBar = 1
  655. local tab = {}
  656. local equips = getputonequipinfo(actor)
  657. for k, equip in pairs(equips) do
  658. if equip.cfgid ~= quiverId then
  659. table.insert(tab, equip.id)
  660. end
  661. end
  662. -- for equipPos = 1, 16 do
  663. -- local equipIndex = gameequip.index(wearBar, equipPos)
  664. -- local equipInfo = getequipinfo(actor, equipIndex, 0)
  665. -- if next(equipInfo) and equipInfo.cfgid ~= quiverId then
  666. -- table.insert(tab, equipInfo.id)
  667. -- end
  668. -- end
  669. return tab
  670. end
  671. function EquipDurability.onReqEquipXiuLi(actor, msgData)
  672. local mainType = msgData.mainType
  673. -- 单件修理
  674. if mainType == 1 then
  675. local itemId = msgData.itemId
  676. local equipInfo = getequipinfo(actor, itemId, 1)
  677. local cfgId = equipInfo.cfgid
  678. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  679. if tonumber(subType) == 14 then
  680. messagebox(actor, "守护类装备不可修理")
  681. return
  682. end
  683. local MaxDurability = EquipDurability.getMaxDurability(actor, itemId)
  684. local NowDurability = EquipDurability.getNowDurability(actor, itemId)
  685. if NowDurability >= MaxDurability then
  686. messagebox(actor, "耐久度已满 无需修理")
  687. return
  688. end
  689. local addDurability = MaxDurability - NowDurability
  690. local price = EquipFunc.getXiuLiPrice(actor, itemId, equipInfo)
  691. local tab = {
  692. [10010001] = price
  693. }
  694. if not Bag.checkCostMap(actor, tab) then
  695. messagebox(actor, "金币不足" .. price)
  696. return
  697. end
  698. Bag.costMap(actor, tab, "修理费用")
  699. -- info(price,"price","修理")
  700. -- info(MaxDurability,"MaxDurability","修理")
  701. -- info(NowDurability,"NowDurability","修理")
  702. -- info(MaxDurability-NowDurability,"MaxDurability-NowDurability","修理")
  703. EquipDurability.addDurability(actor, itemId, addDurability)
  704. sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
  705. sendType = 1
  706. })
  707. -- 全部修理
  708. elseif mainType == 2 then
  709. local tab = EquipDurability.getAllXiuLiEquip(actor)
  710. local price = 0
  711. for i = 1, #tab do
  712. local itemId = tab[i]
  713. local equipInfo = getequipinfo(actor, itemId, 1)
  714. local cfgId = equipInfo.cfgid
  715. local nowDurabilityv = EquipDurability.getNowDurabilityPct(actor, itemId)
  716. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  717. if nowDurabilityv < 100 and tonumber(subType) ~= 14 then
  718. local tmpPrice = EquipFunc.getXiuLiPrice(actor, itemId, equipInfo)
  719. price = price + tmpPrice
  720. end
  721. end
  722. if price <= 0 then
  723. messagebox(actor, "没有需要修理的装备")
  724. return
  725. end
  726. local tCost = {
  727. [10010001] = price
  728. }
  729. if not Bag.checkCostMap(actor, tCost) then
  730. messagebox(actor, "金币不足,修理失败" .. price)
  731. return
  732. end
  733. Bag.costMap(actor, tCost, "修理费用")
  734. for i = 1, #tab do
  735. local itemId = tab[i]
  736. local equipInfo = getequipinfo(actor, itemId, 1)
  737. local cfgId = equipInfo.cfgid
  738. local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  739. -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
  740. local NowDurability = EquipDurability.getNowDurability(actor, itemId)
  741. local addDurability = -NowDurability
  742. if tonumber(subType) ~= 14 then
  743. EquipDurability.addDurability(actor, itemId, addDurability)
  744. end
  745. end
  746. sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
  747. sendType = 1
  748. })
  749. -- 设置装备当前耐久度
  750. elseif mainType == 3 then
  751. local itemId = msgData.itemId
  752. local num = msgData.inputText * EquipDurability.getDiKangZhi(actor, itemId)
  753. if num < 0 then
  754. EquipDurability.delDurability(actor, itemId, math.abs(num))
  755. else
  756. EquipDurability.addDurability(actor, itemId, num)
  757. end
  758. end
  759. end
  760. -- 修理装备
  761. -- GameEvent.add(EventCfg.onHandlereQuest,
  762. -- function(actor, msgID,msgData)
  763. -- if LuaNetMsg.Equip_XiuLi_MsgID ~= msgID then
  764. -- return
  765. -- end
  766. -- local mainType = msgData.mainType
  767. -- --单件修理
  768. -- if mainType == 1 then
  769. -- local itemId = msgData.itemId
  770. -- local equipInfo = getequipinfo(actor,itemId,1)
  771. -- local cfgId = equipInfo.cfgid
  772. -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  773. -- if tonumber(subType) == 14 then
  774. -- messagebox(actor,"守护类装备不可修理")
  775. -- return
  776. -- end
  777. -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
  778. -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
  779. -- if NowDurability >= MaxDurability then
  780. -- messagebox(actor,"耐久度已满 无需修理")
  781. -- return
  782. -- end
  783. -- local addDurability = MaxDurability-NowDurability
  784. -- local price = EquipFunc.getXiuLiPrice(actor,itemId)
  785. -- local tab = {[10010001] = price}
  786. -- if not Bag.checkCostMap(actor, tab) then
  787. -- messagebox(actor,"金币不足"..price)
  788. -- return
  789. -- end
  790. -- Bag.costMap(actor, tab, "修理费用")
  791. -- -- info(price,"price","修理")
  792. -- -- info(MaxDurability,"MaxDurability","修理")
  793. -- -- info(NowDurability,"NowDurability","修理")
  794. -- -- info(MaxDurability-NowDurability,"MaxDurability-NowDurability","修理")
  795. -- EquipDurability.addDurability(actor,itemId,addDurability)
  796. -- sendluamsg(actor,LuaNetMsg.Equip_XiuLi_MsgID,{sendType=1})
  797. -- --全部修理
  798. -- elseif mainType == 2 then
  799. -- local tab = EquipDurability.getAllXiuLiEquip(actor)
  800. -- local price = 0
  801. -- for i = 1,#tab do
  802. -- local itemId = tab[i]
  803. -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
  804. -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
  805. -- local equipInfo = getequipinfo(actor,itemId,1)
  806. -- local cfgId = equipInfo.cfgid
  807. -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  808. -- if NowDurability < MaxDurability and tonumber(subType) ~= 14 then
  809. -- price = price + EquipFunc.getXiuLiPrice(actor,itemId)
  810. -- end
  811. -- end
  812. -- if price <= 0 then
  813. -- messagebox(actor,"没有需要修理的装备")
  814. -- return
  815. -- end
  816. -- local tCost = {[10010001] = price}
  817. -- if not Bag.checkCostMap(actor, tCost) then
  818. -- messagebox(actor,"金币不足"..price)
  819. -- return
  820. -- end
  821. -- Bag.costMap(actor, tCost, "修理费用")
  822. -- for i = 1,#tab do
  823. -- local itemId = tab[i]
  824. -- local equipInfo = getequipinfo(actor,itemId,1)
  825. -- local cfgId = equipInfo.cfgid
  826. -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  827. -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
  828. -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
  829. -- local addDurability = MaxDurability-NowDurability
  830. -- if tonumber(subType) ~= 14 then
  831. -- EquipDurability.addDurability(actor,itemId,addDurability)
  832. -- end
  833. -- end
  834. -- sendluamsg(actor,LuaNetMsg.Equip_XiuLi_MsgID,{sendType=1})
  835. -- --设置装备当前耐久度
  836. -- elseif mainType == 3 then
  837. -- local itemId = msgData.itemId
  838. -- local num = msgData.inputText * EquipDurability.getDiKangZhi(actor,itemId)
  839. -- if num < 0 then
  840. -- EquipDurability.delDurability(actor,itemId,math.abs(num))
  841. -- else
  842. -- EquipDurability.addDurability(actor,itemId,num)
  843. -- end
  844. -- end
  845. -- return true
  846. -- end
  847. -- , filename)