EquipDurability.lua 34 KB

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