| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971 |
- EquipDurability = {}
- local filename = "EquipDurability"
- EquipDurability.equipWhereAndPos = {
- -- [穿戴栏] = {
- -- [耐久类型] = {装备位1,装备位2}, 耐久类型1=武器耐久流程 2=防具耐久类型 3=饰品耐久类型
- -- }
- -- 基础装备
- [1] = {
- -- 部位为2的.单独处理.因为副手有武器或盾牌的区别.它可能是武器.可能是防具
- [1] = {1, 3},
- [2] = {4, 5, 6, 7, 8, 9, 15, 16},
- [3] = {10, 11, 12, 13, 14}
- }
- }
- local quiverId = 20230111
- function EquipDurability.onLoginEnd(actor)
- end
- -- 获取抵抗值
- function EquipDurability.getDiKangZhi(actor, itemId)
- local dikangzhi = 11280
- return dikangzhi
- end
- -- 获取耐久基础值 道具表 + 强化规则
- function EquipDurability.getBaseDurability(actor, itemId)
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- local maxDurability = ConfigDataManager.getTableValue("cfg_item", "Durability", "id", cfgId) or 0
- if maxDurability == "" then
- maxDurability = 0
- end
- local strenthLevel = EquipFunc.getEquipStrengthLevel(actor, itemId)
- local strenthDurability = 0
- if strenthLevel > 0 then
- for i = 1, strenthLevel do
- if i <= 4 then
- strenthDurability = strenthDurability + 1
- elseif i <= 9 then
- strenthDurability = strenthDurability + 2
- elseif i == 10 then
- strenthDurability = strenthDurability + 3
- elseif i == 11 then
- strenthDurability = strenthDurability + 4
- elseif i == 12 then
- strenthDurability = strenthDurability + 5
- elseif i == 13 then
- strenthDurability = strenthDurability + 6
- elseif i == 14 then
- strenthDurability = strenthDurability + 7
- elseif i == 15 then
- strenthDurability = strenthDurability + 8
- end
- end
- end
- return maxDurability + strenthDurability
- end
- -- 获取装备耐久度 return 最大耐久
- function EquipDurability.getMaxDurability(actor, itemId)
- -- 根据道具表获取基础耐久度
- local maxDurability = EquipDurability.getBaseDurability(actor, itemId)
- -- 最终耐久度 基础耐久度 * 抵抗值
- maxDurability = maxDurability * EquipDurability.getDiKangZhi(actor, itemId)
- return maxDurability
- end
- -- 物品进入背包后 初始化耐久度
- function EquipDurability.iniData(actor, itemId, itemCfgId, index)
- local mainType = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId)
- if mainType ~= "2" then
- return
- end
- -- 坐骑道具默认发放且穿戴 穿戴的时候道具不存在 无法设置变量会报错 所以坐骑类型return
- if subType == "16" then
- return
- end
- if API.GetItemData(actor, itemId, "setDurability") == 1 then
- return
- end
- local maxDurability = EquipDurability.getMaxDurability(actor, itemId)
- info("物品耐久初始化:maxDurability" .. maxDurability, "装备耐久")
- EquipDurability.addDurability(actor, itemId, maxDurability)
- API.SetItemData(actor, itemId, "setDurability", 1)
- end
- GameEvent.add(EventCfg.addbag, function(actor, itemId, itemCfgId, index)
- EquipDurability.iniData(actor, itemId, itemCfgId, index)
- end, filename)
- -- 修理气泡 客户端
- -- local popoverPanel = GUI:GetUI("dev/ui/Preview/Panel/KLPopover/KLPopoverPanel")
- -- popoverPanel:SetPopoverData(PopoverType.Tip_EquipDurability)
- -- popoverPanel:RefreshUI()
- -- 扣除装备耐久
- -- 获取当前耐久
- function EquipDurability.getNowDurability(actor, itemId)
- return API.GetItemData(actor, itemId, "Durability") or 0
- end
- -- 增加装备耐久
- function EquipDurability.addDurability(actor, itemId, num)
- local Durability = EquipDurability.getNowDurability(actor, itemId)
- API.SetItemData(actor, itemId, "Durability", Durability + num)
- EquipDurability.refreshAttr(actor, itemId)
- end
- -- 降低装备扣除耐久速度
- function EquipDurability.getNewDelDurabilityNum(actor, itemId, num, DurabilityType)
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- -- local mainType = ConfigDataManager.getTableValue("cfg_item", "type", "id", cfgId)
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- if DurabilityType == 1 or DurabilityType == 2 then
- -- 武器防具
- local delDurability1 = getattrinfo(actor, "delDurability1")
- if delDurability1 > 0 then
- if tonumber(subType) <= 9 then
- num = math.ceil(num * (1 - delDurability1))
- end
- end
- -- 守护坐骑
- local delDurability3 = getattrinfo(actor, "delDurability3")
- if delDurability3 > 0 then
- if tonumber(subType) == 14 or tonumber(subType) == 16 then
- num = math.ceil(num * (1 - delDurability3))
- end
- end
- elseif DurabilityType == 3 then
- -- 首饰
- local delDurability2 = getattrinfo(actor, "delDurability2")
- if delDurability2 > 0 then
- if tonumber(subType) == 10 or tonumber(subType) == 11 then
- num = math.ceil(num * (1 - delDurability2))
- end
- end
- end
- return num
- end
- -- 扣除装备耐久 DurabilityType 1=武器耐久类型 2=防具耐久类型 3=首饰耐久类型
- function EquipDurability.delDurability(actor, itemId, num, DurabilityType)
- -- 装备耐久扣完了.
- if EquipDurability.getNowDurabilityPct(actor, itemId) <= 0 then
- return
- end
- local Durability = EquipDurability.getNowDurability(actor, itemId)
- num = EquipDurability.getNewDelDurabilityNum(actor, itemId, num, DurabilityType)
- API.SetItemData(actor, itemId, "Durability", Durability - num)
- EquipDurability.refreshAttr(actor, itemId)
- end
- -- 获取当前耐久百分比
- function EquipDurability.getNowDurabilityPct(actor, itemId)
- local nowDurability = EquipDurability.getNowDurability(actor, itemId)
- local maxDurability = EquipDurability.getMaxDurability(actor, itemId)
- -- 配置表不对.导致所有装备都无法修理
- if maxDurability == 0 then
- maxDurability = 1
- end
- return (maxDurability + nowDurability) / maxDurability * 100
- end
- function EquipDurability.refreshDurability(actor, itemId)
- local pct = EquipDurability.getNowDurabilityPct(actor, itemId)
- local attPct = 100
- if pct <= 0 then
- attPct = 0
- elseif pct < 20 then
- attPct = 50
- elseif pct < 30 then
- attPct = 70
- elseif pct < 50 then
- attPct = 80
- end
- local equipInfo = getequipinfo(actor, itemId, 1)
- local equipindex = equipInfo.equipindex
- if equipindex ~= 0 then
- setequipdurability(actor, equipindex, 0, attPct)
- else
- setequipdurability(actor, itemId, 1, attPct)
- end
- end
- function EquipDurability.refreshAttr(actor, itemId)
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- if tonumber(subType) == 14 then
- return
- end
- local pct = EquipDurability.getNowDurabilityPct(actor, itemId)
- local attPct = 100
- if pct <= 50 then
- sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
- sendType = 2,
- itemId = itemId,
- pct = pct
- }) -- 通知气泡
- end
- if pct <= 0 then
- attPct = 0
- elseif pct < 20 then
- attPct = 50
- elseif pct < 30 then
- attPct = 70
- elseif pct < 50 then
- attPct = 80
- end
- local equipInfo = getequipinfo(actor, itemId, 1)
- local equipindex = equipInfo.equipindex
- if equipindex ~= 0 then
- setequipdurability(actor, equipindex, 0, attPct)
- else
- setequipdurability(actor, itemId, 1, attPct)
- end
- -- info("equipindex="..equipindex,type(equipindex),"equipindex")
- -- 处理强化属性
- -- Equip_QiangHua.sendAttr(actor, itemId)
- end
- -- function EquipDurability.OpenPopover(actor,itemId)
- -- end
- -- function EquipDurability.getbasicattr(actor)
- -- local equipIndex = gameequip.index(1, 1)
- -- local equipInfo = getequipinfo(actor,equipIndex,0)
- -- local itemId = equipInfo.id
- -- local equipInfo = getequipinfo(actor,itemId,1)
- -- local basicattr = equipInfo.basicattr
- -- info(basicattr,"basicattr")
- -- end
- -- 获取武器每次攻击要扣除的耐久度
- function EquipDurability.getDelDurability_1(actor, target, itemId)
- local armor = getattrinfo(target, "armor") -- 防御值
- armor = math.max(armor, 1)
- local equipInfo = getequipinfo(actor, itemId, 1)
- local basicattr = equipInfo.basicattr
- local minAtk = 1
- local maxAtk = 1
- for i = 1, #basicattr do
- local attrid = basicattr[i].attrid
- if attrid == 201021 then
- minAtk = basicattr[i].value
- end
- if attrid == 201011 then
- maxAtk = basicattr[i].value
- end
- end
- local delDurability = armor * 2 / (minAtk + maxAtk / 2)
- delDurability = math.ceil(delDurability) * 10
- local zhuangbeiyingdutishengRate = getattrinfo(target, "zhuangbeiyingdutishengRate") -- 装备硬度提升
- if zhuangbeiyingdutishengRate > 0 then
- delDurability = delDurability * (1 - zhuangbeiyingdutishengRate)
- end
- return delDurability
- end
- function EquipDurability.getDelDurability_1_1(equipInfo)
- local basicattr = equipInfo.basicattr
- local minAtk = 1
- local maxAtk = 1
- for i = 1, #basicattr do
- local attrid = basicattr[i].attrid
- if attrid == 201021 then
- minAtk = basicattr[i].value
- end
- if attrid == 201011 then
- maxAtk = basicattr[i].value
- end
- end
- local armor = math.max(minAtk, 1) * 0.3
- local delDurability = armor * 2 / (minAtk + maxAtk / 2)
- delDurability = math.ceil(delDurability) * 10
- -- local zhuangbeiyingdutishengRate = getattrinfo(target, "zhuangbeiyingdutishengRate") -- 装备硬度提升
- -- if zhuangbeiyingdutishengRate > 0 then
- -- delDurability = delDurability * (1 - zhuangbeiyingdutishengRate)
- -- end
- return delDurability
- end
- -- 获取防具每次被攻击要扣除的耐久度(坐骑和守护类型到时候也放进来 做判断)
- function EquipDurability.getDelDurability_2(target, damage, itemId, equipInfo2)
- local career = getbaseinfo(target, "getbasecareer")
- local pct = 3
- if career == 1 then
- pct = 3
- elseif career == 2 then
- pct = 3
- elseif career == 3 then
- pct = 2
- elseif career == 4 then
- pct = 7
- elseif career == 5 then
- pct = 6
- elseif career == 6 then
- pct = 3
- end
- local equipInfo = nil
- if equipInfo2 ~= nil then
- equipInfo = equipInfo2
- else
- equipInfo = getequipinfo(target, itemId, 1)
- end
- local basicattr = equipInfo.basicattr
- local armor = 1
- for i = 1, #basicattr do
- local attrid = basicattr[i].attrid
- if attrid == 206011 then
- armor = basicattr[i].value
- end
- end
- local delDurability = damage / (armor * pct + 0)
- delDurability = math.ceil(delDurability)
- return delDurability * 10
- end
- -- 获取时间类型 如果在非安全区 每经过一分钟扣除额耐久度
- function EquipDurability.getDelDurability_3(actor, target, itemId)
- return 10
- end
- function EquipDurability.isArmor(actor, equipInfo)
- local basicattr = equipInfo.basicattr
- for i = 1, #basicattr do
- local attrid = basicattr[i].attrid
- if attrid == 206011 then
- return true
- end
- end
- return false
- end
- function EquipDurability.attackCost(actor)
- local count = APIGetInt(actor, "ZC_DurabilityHurtCount")
- if count == 0 then
- return
- end
- APISetInt(actor, "ZC_DurabilityHurtCount", 0)
- local wearBar = 1
- local DurabilityType = 1
- local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
- for i = 1, #tEquipPos do
- local equipPos = tEquipPos[i]
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- local delDurability = EquipDurability.getDelDurability_1_1(equipInfo) * count
- EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
- end
- end
- local equipIndex = gameequip.index(1, 2)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- if not EquipDurability.isArmor(actor, equipInfo) then
- if equipInfo.cfgid == quiverId then
- else
- local delDurability = EquipDurability.getDelDurability_1_1(equipInfo) * count
- EquipDurability.delDurability(actor, itemId, delDurability, 1)
- end
- end
- end
- end
- function EquipDurability.attackCareer3(actor)
- local career = getbaseinfo(actor, "getbasecareer")
- if career ~= 3 then
- return
- end
- local equipIndex = gameequip.index(1, 2)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- if equipInfo.cfgid == quiverId then
- EquipDurability.costQuiver(actor, equipIndex, equipInfo, 1)
- end
- end
- sendluamsg(actor, 90000510, {})
- end
- -- 攻击后 废弃
- function EquipDurability.attack(actor, fightParam)
- local target = fightParam.target
- local castertype = fightParam.castertype
- if castertype == MapObjectType.PLAYER then
- local wearBar = 1
- local DurabilityType = 1
- local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
- for i = 1, #tEquipPos do
- local equipPos = tEquipPos[i]
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- local delDurability = EquipDurability.getDelDurability_1(actor, target, itemId)
- EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
- end
- end
- end
- local equipIndex = gameequip.index(1, 2)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- if not EquipDurability.isArmor(actor, equipInfo) then
- if equipInfo.cfgid == quiverId then
- EquipDurability.costQuiver(actor, equipIndex, equipInfo, 1)
- else
- local delDurability = EquipDurability.getDelDurability_1(actor, target, itemId)
- EquipDurability.delDurability(actor, itemId, delDurability, 1)
- end
- end
- end
- local career = getbaseinfo(actor, "getbasecareer")
- -- 弓箭手需要刷新箭袋耐久
- if career == 3 then
- sendluamsg(actor, 90000510, {})
- end
- end
- function EquipDurability.takeonequip(actor, pos, oldItemId, itemId, itemCfgId)
- if pos ~= 3 then
- return
- end
- local career = getbaseinfo(actor, "getbasecareer")
- career = tonumber(career)
- if career ~= 3 then
- return
- end
- local wearBar = 1
- local equipPos = 2
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- return
- end
- local bagIndex = EquipDurability.getBagQuiverId(actor)
- if bagIndex ~= 0 then
- putontheequip(actor, bagIndex, equipIndex)
- end
- end
- function EquipDurability.costQuiver(actor, equipIndex, equipInfo, durabilityType)
- local itemId = equipInfo.id
- local delDurability = EquipDurability.getDiKangZhi(actor, itemId)
- EquipDurability.delDurability(actor, itemId, delDurability, durabilityType)
- -- 耐久消耗完了.摧毁这个装备
- if EquipDurability.getNowDurabilityPct(actor, itemId) <= 0 then
- -- 先穿上新的箭筒.
- local items = getallbagiteminfo(actor)
- for index, value in ipairs(items) do
- local item = items[index]
- if item.cfgid == quiverId then
- putontheequip(actor, item.bagindex, equipIndex)
- break
- end
- end
- local bagIndex = gainbagidxbyitemid(actor, itemId)
- if bagIndex ~= 0 then
- destroyitemafter(actor, bagIndex, "装备耐久")
- end
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if EquipDurability.getNowDurabilityPct(actor, equipInfo.id) <= 0 then
- APISetInt(actor, "ZC_Quiver_Durability", 1, 1)
- end
- end
- end
- function EquipDurability.getBagQuiverId(actor)
- local items = getallbagiteminfo(actor)
- for index, value in ipairs(items) do
- local item = items[index]
- if item.cfgid == quiverId then
- if EquipDurability.getNowDurabilityPct(actor, item.id) <= 0 then
- local bagIndex = gainbagidxbyitemid(actor, item.id)
- if bagIndex ~= 0 then
- destroyitemafter(actor, bagIndex, "装备耐久")
- end
- else
- return item.bagindex
- end
- end
- end
- return 0
- end
- function EquipDurability.destroyWearQuiver(actor, equipIndex)
- local checkBag = {}
- local paramMap = {}
- paramMap["cfgid"] = quiverId
- paramMap["itemcount"] = 1
- table.insert(checkBag, paramMap)
- local canPutBag1 = checkitemscanputbag(actor, checkBag)
- if tonumber(canPutBag1) ~= 0 then
- takeofftheequip(actor, equipIndex)
- return true
- end
- return false
- end
- function EquipDurability.updateQuiver(actor)
- local selfType = getbaseinfo(actor, "mapobjecttype")
- if selfType == MapObjectType.PLAYER then
- local isQuiverDestory = APIGetInt(actor, "ZC_Quiver_Durability", 1)
- if isQuiverDestory ~= 1 then
- return
- end
- else
- return
- end
- local wearBar = 1
- local equipPos = 2
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local nowDurabilityPct = EquipDurability.getNowDurabilityPct(actor, equipInfo.id)
- if nowDurabilityPct <= 0 and EquipDurability.destroyWearQuiver(actor, equipIndex) then
- local bagIndex = EquipDurability.getBagQuiverId(actor)
- if bagIndex ~= 0 then
- putontheequip(actor, bagIndex, equipIndex)
- end
- end
- end
- -- 刷新一下箭筒信息
- equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local nowDurabilityPct = EquipDurability.getNowDurabilityPct(actor, equipInfo.id)
- APISetInt(actor, "ZC_Quiver_Durability", nowDurabilityPct <= 0 and 1 or 0, 1)
- else
- APISetInt(actor, "ZC_Quiver_Durability", 1, 1)
- end
- end
- function EquipDurability.beattackMark(actor, target, targethurt, targettype)
- if targettype ~= MapObjectType.PLAYER then
- return
- end
- local damage = APIGetInt(target, "ZC_DurabilityDamage", 1)
- if damage == nil then
- damage = 0
- end
- local count = APIGetInt(target, "ZC_DurabilityDamageCount", 1)
- if count == nil then
- count = 0
- end
- damage = damage + targethurt
- count = count + 1
- APISetInt(target, "ZC_DurabilityDamage", damage, 1)
- APISetInt(target, "ZC_DurabilityDamageCount", count, 1)
- end
- function EquipDurability.underattackCost(actor)
- local damage = APIGetInt(actor, "ZC_DurabilityDamage", 1)
- if damage == nil then
- damage = 0
- end
- local count = APIGetInt(actor, "ZC_DurabilityDamageCount", 1)
- if count == nil then
- count = 0
- end
- if count == 0 then
- return
- end
- APISetInt(actor, "ZC_DurabilityDamage", 0, 1)
- APISetInt(actor, "ZC_DurabilityDamageCount", 0, 1)
- local damageCoe = damage / count
- local wearBar = 1
- local DurabilityType = 2
- local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
- -- 筛出穿戴了的 然后随机取一个
- local tab = {}
- for i = 1, #tEquipPos do
- local equipPos = tEquipPos[i]
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) and table.count(equipInfo) > 0 then
- local itemId = equipInfo.id
- if equipInfo.cfgid ~= quiverId then
- -- table.insert(tab, {
- -- itemId = itemId,
- -- equipPos = equipPos,
- -- equipIndex = equipIndex
- -- })
- -- local index = math.random(1, #tab)
- -- local itemId = tab[index].itemId
- -- local equipPos = tab[index].equipPos
- -- local equipIndex = tab[index].equipIndex
- -- info("本次受到攻击扣除equipPos="..equipPos.."#equipIndex="..equipIndex.."的耐久:"..delDurability,"扣耐久")
- local delDurability = EquipDurability.getDelDurability_2(actor, damageCoe, itemId, equipInfo) * count
- EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
- end
- end
- -- if #tab > 0 then
- -- end
- end
- local equipIndex = gameequip.index(1, 2)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- if EquipDurability.isArmor(actor, equipInfo) then
- local delDurability = EquipDurability.getDelDurability_2(actor, damageCoe, itemId, equipInfo) * count
- EquipDurability.delDurability(actor, itemId, delDurability, 2)
- end
- end
- end
- -- 被攻击后 废弃
- function EquipDurability.underattack(actor, damage)
- local wearBar = 1
- local DurabilityType = 2
- local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
- -- 筛出穿戴了的 然后随机取一个
- local tab = {}
- for i = 1, #tEquipPos do
- local equipPos = tEquipPos[i]
- local equipIndex = gameequip.index(wearBar, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- if equipInfo.cfgid ~= quiverId then
- table.insert(tab, {
- itemId = itemId,
- equipPos = equipPos,
- equipIndex = equipIndex
- })
- end
- end
- if #tab > 0 then
- local index = math.random(1, #tab)
- local itemId = tab[index].itemId
- -- local equipPos = tab[index].equipPos
- -- local equipIndex = tab[index].equipIndex
- -- info("本次受到攻击扣除equipPos="..equipPos.."#equipIndex="..equipIndex.."的耐久:"..delDurability,"扣耐久")
- local delDurability = EquipDurability.getDelDurability_2(actor, damage, itemId, equipInfo)
- EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
- end
- end
- local equipIndex = gameequip.index(1, 2)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- if EquipDurability.isArmor(actor, equipInfo) then
- local delDurability = EquipDurability.getDelDurability_2(actor, damage, itemId, equipInfo)
- EquipDurability.delDurability(actor, itemId, delDurability, 2)
- end
- end
- end
- function EquipDurability.beattack(actor, target, targethurt, targettype)
- -- if targettype == MapObjectType.PLAYER then
- -- EquipDurability.underattack(target, targethurt)
- -- end
- end
- -- GameEvent.add(EventCfg.AttackDamage,function(paramMap,fightResult,tAddHurt)
- -- local caster = paramMap.caster --—— 攻击对象
- -- local target = paramMap.target --—— 受击对象
- -- local targethurt = fightResult.targethurt --受击者伤害
- -- local targettype = paramMap.targettype --—— 受击者类型
- -- if targettype == MapObjectType.PLAYER then
- -- EquipDurability.underattack(target,targethurt)
- -- end
- -- end,filename)
- -- 饰品类 不在安全区的时间
- function EquipDurability.Timer(actor)
- if not getbaseinfo(actor, "safearea") then
- local wearBar = 1
- local DurabilityType = 3
- local tEquipPos = EquipDurability.equipWhereAndPos[wearBar][DurabilityType]
- for i = 1, #tEquipPos do
- local equipPos = tEquipPos[i]
- local equipIndex = gameequip.index(1, equipPos)
- local equipInfo = getequipinfo(actor, equipIndex, 0) -- 没有则返回空表
- if next(equipInfo) then
- local itemId = equipInfo.id
- local delDurability = EquipDurability.getDelDurability_3(actor, itemId)
- EquipDurability.delDurability(actor, itemId, delDurability, DurabilityType)
- end
- end
- end
- end
- -- 获取所有可修理装备的唯一id
- function EquipDurability.getAllXiuLiEquip(actor)
- -- local wearBar = 1
- local tab = {}
- local equips = getputonequipinfo(actor)
- for k, equip in pairs(equips) do
- if equip.cfgid ~= quiverId then
- table.insert(tab, equip.id)
- end
- end
- -- for equipPos = 1, 16 do
- -- local equipIndex = gameequip.index(wearBar, equipPos)
- -- local equipInfo = getequipinfo(actor, equipIndex, 0)
- -- if next(equipInfo) and equipInfo.cfgid ~= quiverId then
- -- table.insert(tab, equipInfo.id)
- -- end
- -- end
- return tab
- end
- function EquipDurability.onReqEquipXiuLi(actor, msgData)
- local mainType = msgData.mainType
- -- 单件修理
- if mainType == 1 then
- local itemId = msgData.itemId
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- if tonumber(subType) == 14 then
- messagebox(actor, "守护类装备不可修理")
- return
- end
- local MaxDurability = EquipDurability.getMaxDurability(actor, itemId)
- local NowDurability = EquipDurability.getNowDurability(actor, itemId)
- if NowDurability >= MaxDurability then
- messagebox(actor, "耐久度已满 无需修理")
- return
- end
- local addDurability = MaxDurability - NowDurability
- local price = EquipFunc.getXiuLiPrice(actor, itemId, equipInfo)
- local tab = {
- [10010001] = price
- }
- if not Bag.checkCostMap(actor, tab) then
- messagebox(actor, "金币不足" .. price)
- return
- end
- Bag.costMap(actor, tab, "修理费用")
- -- info(price,"price","修理")
- -- info(MaxDurability,"MaxDurability","修理")
- -- info(NowDurability,"NowDurability","修理")
- -- info(MaxDurability-NowDurability,"MaxDurability-NowDurability","修理")
- EquipDurability.addDurability(actor, itemId, addDurability)
- sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
- sendType = 1
- })
- -- 全部修理
- elseif mainType == 2 then
- local tab = EquipDurability.getAllXiuLiEquip(actor)
- local price = 0
- for i = 1, #tab do
- local itemId = tab[i]
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- local nowDurabilityv = EquipDurability.getNowDurabilityPct(actor, itemId)
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- if nowDurabilityv < 100 and tonumber(subType) ~= 14 then
- local tmpPrice = EquipFunc.getXiuLiPrice(actor, itemId, equipInfo)
- price = price + tmpPrice
- end
- end
- if price <= 0 then
- messagebox(actor, "没有需要修理的装备")
- return
- end
- local tCost = {
- [10010001] = price
- }
- if not Bag.checkCostMap(actor, tCost) then
- messagebox(actor, "金币不足,修理失败" .. price)
- return
- end
- Bag.costMap(actor, tCost, "修理费用")
- for i = 1, #tab do
- local itemId = tab[i]
- local equipInfo = getequipinfo(actor, itemId, 1)
- local cfgId = equipInfo.cfgid
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
- local NowDurability = EquipDurability.getNowDurability(actor, itemId)
- local addDurability = -NowDurability
- if tonumber(subType) ~= 14 then
- EquipDurability.addDurability(actor, itemId, addDurability)
- end
- end
- sendluamsg(actor, LuaNetMsg.Equip_XiuLi_MsgID, {
- sendType = 1
- })
- -- 设置装备当前耐久度
- elseif mainType == 3 then
- local itemId = msgData.itemId
- local num = msgData.inputText * EquipDurability.getDiKangZhi(actor, itemId)
- if num < 0 then
- EquipDurability.delDurability(actor, itemId, math.abs(num))
- else
- EquipDurability.addDurability(actor, itemId, num)
- end
- end
- end
- -- 修理装备
- -- GameEvent.add(EventCfg.onHandlereQuest,
- -- function(actor, msgID,msgData)
- -- if LuaNetMsg.Equip_XiuLi_MsgID ~= msgID then
- -- return
- -- end
- -- local mainType = msgData.mainType
- -- --单件修理
- -- if mainType == 1 then
- -- local itemId = msgData.itemId
- -- local equipInfo = getequipinfo(actor,itemId,1)
- -- local cfgId = equipInfo.cfgid
- -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- -- if tonumber(subType) == 14 then
- -- messagebox(actor,"守护类装备不可修理")
- -- return
- -- end
- -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
- -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
- -- if NowDurability >= MaxDurability then
- -- messagebox(actor,"耐久度已满 无需修理")
- -- return
- -- end
- -- local addDurability = MaxDurability-NowDurability
- -- local price = EquipFunc.getXiuLiPrice(actor,itemId)
- -- local tab = {[10010001] = price}
- -- if not Bag.checkCostMap(actor, tab) then
- -- messagebox(actor,"金币不足"..price)
- -- return
- -- end
- -- Bag.costMap(actor, tab, "修理费用")
- -- -- info(price,"price","修理")
- -- -- info(MaxDurability,"MaxDurability","修理")
- -- -- info(NowDurability,"NowDurability","修理")
- -- -- info(MaxDurability-NowDurability,"MaxDurability-NowDurability","修理")
- -- EquipDurability.addDurability(actor,itemId,addDurability)
- -- sendluamsg(actor,LuaNetMsg.Equip_XiuLi_MsgID,{sendType=1})
- -- --全部修理
- -- elseif mainType == 2 then
- -- local tab = EquipDurability.getAllXiuLiEquip(actor)
- -- local price = 0
- -- for i = 1,#tab do
- -- local itemId = tab[i]
- -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
- -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
- -- local equipInfo = getequipinfo(actor,itemId,1)
- -- local cfgId = equipInfo.cfgid
- -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- -- if NowDurability < MaxDurability and tonumber(subType) ~= 14 then
- -- price = price + EquipFunc.getXiuLiPrice(actor,itemId)
- -- end
- -- end
- -- if price <= 0 then
- -- messagebox(actor,"没有需要修理的装备")
- -- return
- -- end
- -- local tCost = {[10010001] = price}
- -- if not Bag.checkCostMap(actor, tCost) then
- -- messagebox(actor,"金币不足"..price)
- -- return
- -- end
- -- Bag.costMap(actor, tCost, "修理费用")
- -- for i = 1,#tab do
- -- local itemId = tab[i]
- -- local equipInfo = getequipinfo(actor,itemId,1)
- -- local cfgId = equipInfo.cfgid
- -- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
- -- local MaxDurability = EquipDurability.getMaxDurability(actor,itemId)
- -- local NowDurability = EquipDurability.getNowDurability(actor,itemId)
- -- local addDurability = MaxDurability-NowDurability
- -- if tonumber(subType) ~= 14 then
- -- EquipDurability.addDurability(actor,itemId,addDurability)
- -- end
- -- end
- -- sendluamsg(actor,LuaNetMsg.Equip_XiuLi_MsgID,{sendType=1})
- -- --设置装备当前耐久度
- -- elseif mainType == 3 then
- -- local itemId = msgData.itemId
- -- local num = msgData.inputText * EquipDurability.getDiKangZhi(actor,itemId)
- -- if num < 0 then
- -- EquipDurability.delDurability(actor,itemId,math.abs(num))
- -- else
- -- EquipDurability.addDurability(actor,itemId,num)
- -- end
- -- end
- -- return true
- -- end
- -- , filename)
|