From 7cb5286758024ff30daa9b2bb8be22655e63a1a9 Mon Sep 17 00:00:00 2001 From: Wil Thieme Date: Mon, 26 Feb 2024 11:18:26 -0500 Subject: [PATCH] styling --- README.md | 2 +- campaign/scripts/backupitemstat.lua | 14 +- campaign/scripts/calculatesave.lua | 12 +- campaign/scripts/item_main2.lua | 14 +- campaign/scripts/itemdamage.lua | 16 +- scripts/broken_itemdurability.lua | 264 +++++++++++++++++----------- scripts/damage_itemdurability.lua | 54 +++--- scripts/hhp_itemdurability.lua | 27 ++- scripts/info_itemdurability.lua | 214 +++++++++++----------- 9 files changed, 364 insertions(+), 253 deletions(-) diff --git a/README.md b/README.md index b164c00..dc38111 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ If the item is a suit of armor or a shield, the bonus it grants to AC is halved, When attacking with a weapon, it will be checked for the "fragile" quality and broken automatically on a natural 1. If the weapon is already broken, the weapon will be destroyed instead. # Compatibility and Instructions -This extension has been tested with [FantasyGrounds Unity](https://www.fantasygrounds.com/home/FantasyGroundsUnity.php) v4.4.9 (2023-12-18). +This extension has been tested with [FantasyGrounds Unity](https://www.fantasygrounds.com/home/FantasyGroundsUnity.php) v4.5.0 (2024-02-21). # Features * Simplifies tracking hitpoints of weapons, armor, and equipment. diff --git a/campaign/scripts/backupitemstat.lua b/campaign/scripts/backupitemstat.lua index a763dad..9b11d5c 100644 --- a/campaign/scripts/backupitemstat.lua +++ b/campaign/scripts/backupitemstat.lua @@ -6,22 +6,26 @@ function backupValue() local nodeItem = window.getDatabaseNode() - local nItemBrokenState = DB.getValue(nodeItem, 'broken') + local nItemBrokenState = DB.getValue(nodeItem, "broken") local nItemValue = DB.getValue(nodeItem, getName()) - if nItemBrokenState == 0 and string.lower(DB.getValue(nodeItem, 'type', '')) == 'armor' then - DB.setValue(nodeItem, getName() .. '.backup', 'number', nItemValue) + if nItemBrokenState == 0 and string.lower(DB.getValue(nodeItem, "type", "")) == "armor" then + DB.setValue(nodeItem, getName() .. ".backup", "number", nItemValue) end end function onInit() - if super and super.onInit then super.onInit() end + if super and super.onInit then + super.onInit() + end onValueChanged() end function onValueChanged() - if super and super.onValueChanged then super.onValueChanged() end + if super and super.onValueChanged then + super.onValueChanged() + end backupValue() end diff --git a/campaign/scripts/calculatesave.lua b/campaign/scripts/calculatesave.lua index 48243c9..4391917 100644 --- a/campaign/scripts/calculatesave.lua +++ b/campaign/scripts/calculatesave.lua @@ -26,20 +26,26 @@ function updateSaves() end function update(...) - if super and super.update then super.update(...) end + if super and super.update then + super.update(...) + end updateSaveVisibility() end function onValueChanged() - if super and super.onValueChanged then super.onValueChanged() end + if super and super.onValueChanged then + super.onValueChanged() + end updateSaves() updateSaveVisibility() end function onInit() - if super and super.onInit then super.onInit() end + if super and super.onInit then + super.onInit() + end onValueChanged() end diff --git a/campaign/scripts/item_main2.lua b/campaign/scripts/item_main2.lua index 71b6c4a..8d5d73e 100644 --- a/campaign/scripts/item_main2.lua +++ b/campaign/scripts/item_main2.lua @@ -23,19 +23,21 @@ function HHDVisibility(bReadOnly) end function update() - if super and super.update then super.update() end + if super and super.update then + super.update() + end local nodeRecord = getDatabaseNode() local bReadOnly = WindowManager.getReadOnlyState(nodeRecord) - local bID = LibraryData.getIDState('item', nodeRecord) + local bID = LibraryData.getIDState("item", nodeRecord) local sItemSubwindow = type_stats.getValue() -- 'item_main_armor', 'item_main_weapon', or '' - WindowManager.callSafeControlUpdate(self, 'substance', bReadOnly, not bID) - WindowManager.callSafeControlUpdate(self, 'size', bReadOnly) - WindowManager.callSafeControlUpdate(self, 'thickness', bReadOnly) + WindowManager.callSafeControlUpdate(self, "substance", bReadOnly, not bID) + WindowManager.callSafeControlUpdate(self, "size", bReadOnly) + WindowManager.callSafeControlUpdate(self, "thickness", bReadOnly) - if sItemSubwindow == 'item_main_armor' then + if sItemSubwindow == "item_main_armor" then thickness.setVisible(false) thickness_label.setVisible(false) end diff --git a/campaign/scripts/itemdamage.lua b/campaign/scripts/itemdamage.lua index b83183b..2d1ba31 100644 --- a/campaign/scripts/itemdamage.lua +++ b/campaign/scripts/itemdamage.lua @@ -5,19 +5,21 @@ -- luacheck: globals onDrop onValueChanged setDamageLevel checkDamageLevel update function onDrop(_, _, draginfo) - if string.find(draginfo.getDescription(), '%[DAMAGE', 1) then + if string.find(draginfo.getDescription(), "%[DAMAGE", 1) then ItemDurabilityDamage.splitDamageTypes(window.getDatabaseNode(), draginfo.getDescription()) end end function setDamageLevel(color, damageLevel) window.itemdamage.setColor(color) - DB.setValue(window.getDatabaseNode(), 'broken', 'number', damageLevel) + DB.setValue(window.getDatabaseNode(), "broken", "number", damageLevel) end function checkDamageLevel() local nItemHitpoints = window.hitpoints.getValue() or 0 - if nItemHitpoints == 0 then return end + if nItemHitpoints == 0 then + return + end if nItemHitpoints >= 1 then local nPercentDmg = window.itemdamage.getValue() / nItemHitpoints * 100 @@ -34,13 +36,17 @@ function checkDamageLevel() end function onValueChanged() - if super and super.onValueChanged then super.onValueChanged() end + if super and super.onValueChanged then + super.onValueChanged() + end checkDamageLevel() end function onInit() - if super and super.onInit then super.onInit() end + if super and super.onInit then + super.onInit() + end onValueChanged() end diff --git a/scripts/broken_itemdurability.lua b/scripts/broken_itemdurability.lua index 7c69d63..ba2c3ac 100644 --- a/scripts/broken_itemdurability.lua +++ b/scripts/broken_itemdurability.lua @@ -8,13 +8,16 @@ function handleBrokenItem(nodeItem) -- @param nodeItem A databasenode pointing to the damaged item. -- @return tDamagedWeapons A table of databasenodes pointing to the damaged item on the actions tab. local function handleWeaponNodeArgs() - local nodeChar = DB.getChild(nodeItem, '...') - local sItemName = DB.getValue(nodeItem, 'name', '') + local nodeChar = DB.getChild(nodeItem, "...") + local sItemName = DB.getValue(nodeItem, "name", "") local sUnbrokenItemName = sItemName:sub(10) local tDamagedWeapons = {} - for _, nodeWeapon in ipairs(DB.getChildList(nodeChar, 'weaponlist')) do - if sItemName == DB.getValue(nodeWeapon, 'name', '') or sUnbrokenItemName == DB.getValue(nodeWeapon, 'name', '') then + for _, nodeWeapon in ipairs(DB.getChildList(nodeChar, "weaponlist")) do + if + sItemName == DB.getValue(nodeWeapon, "name", "") + or sUnbrokenItemName == DB.getValue(nodeWeapon, "name", "") + then table.insert(tDamagedWeapons, nodeWeapon) end end @@ -27,30 +30,38 @@ function handleBrokenItem(nodeItem) local tDamagedWeapons = handleWeaponNodeArgs() if bIsBroken then - if not ItemManager.isShield(nodeItem) then DB.setValue(nodeItem, 'bonus', 'number', DB.getValue(nodeItem, 'bonusbak', 0) - 2) end - DB.setValue(nodeItem, 'critical', 'string', 'x2') + if not ItemManager.isShield(nodeItem) then + DB.setValue(nodeItem, "bonus", "number", DB.getValue(nodeItem, "bonusbak", 0) - 2) + end + DB.setValue(nodeItem, "critical", "string", "x2") for _, vNode in pairs(tDamagedWeapons) do - DB.setValue(vNode, 'name', 'string', '[BROKEN] ' .. DB.getValue(vNode, 'name', '')) - DB.setValue(vNode, 'bonus', 'number', DB.getValue(nodeItem, 'atkbonusbak', 0) - 2) - DB.setValue(vNode, 'critatkrange', 'number', 20) - - for _, vvNode in ipairs(DB.getChildList(vNode, 'damagelist')) do - DB.setValue(vvNode, 'bonus', 'number', DB.getValue(nodeItem, 'dmgbonusbak', 0) - 2) - if DB.getValue(vvNode, 'critmult', 2) > 2 then DB.setValue(vvNode, 'critmult', 'number', 2) end + DB.setValue(vNode, "name", "string", "[BROKEN] " .. DB.getValue(vNode, "name", "")) + DB.setValue(vNode, "bonus", "number", DB.getValue(nodeItem, "atkbonusbak", 0) - 2) + DB.setValue(vNode, "critatkrange", "number", 20) + + for _, vvNode in ipairs(DB.getChildList(vNode, "damagelist")) do + DB.setValue(vvNode, "bonus", "number", DB.getValue(nodeItem, "dmgbonusbak", 0) - 2) + if DB.getValue(vvNode, "critmult", 2) > 2 then + DB.setValue(vvNode, "critmult", "number", 2) + end end end else - if not ItemManager.isShield(nodeItem) then DB.setValue(nodeItem, 'bonus', 'number', DB.getValue(nodeItem, 'bonusbak', 0)) end - DB.setValue(nodeItem, 'critical', 'string', DB.getValue(nodeItem, 'criticalbak', 'x2')) + if not ItemManager.isShield(nodeItem) then + DB.setValue(nodeItem, "bonus", "number", DB.getValue(nodeItem, "bonusbak", 0)) + end + DB.setValue(nodeItem, "critical", "string", DB.getValue(nodeItem, "criticalbak", "x2")) for _, vNode in pairs(tDamagedWeapons) do - local sItemName = DB.getValue(vNode, 'name', '') - if sItemName:find('%[BROKEN%]') then DB.setValue(vNode, 'name', 'string', string.gsub(sItemName, '%[BROKEN%]%s', '')) end - DB.setValue(vNode, 'bonus', 'number', DB.getValue(nodeItem, 'atkbonusbak', 0)) - DB.setValue(vNode, 'critatkrange', 'number', DB.getValue(nodeItem, 'critatkrangebak', 20)) - for _, vvNode in ipairs(DB.getChildList(vNode, 'damagelist')) do - DB.setValue(vvNode, 'bonus', 'number', DB.getValue(nodeItem, 'dmgbonusbak', 0)) - if DB.getValue(vvNode, 'critmultbak', 2) > 2 then - DB.setValue(vvNode, 'critmult', 'number', DB.getValue(nodeItem, 'critmultbak', 2)) + local sItemName = DB.getValue(vNode, "name", "") + if sItemName:find("%[BROKEN%]") then + DB.setValue(vNode, "name", "string", string.gsub(sItemName, "%[BROKEN%]%s", "")) + end + DB.setValue(vNode, "bonus", "number", DB.getValue(nodeItem, "atkbonusbak", 0)) + DB.setValue(vNode, "critatkrange", "number", DB.getValue(nodeItem, "critatkrangebak", 20)) + for _, vvNode in ipairs(DB.getChildList(vNode, "damagelist")) do + DB.setValue(vvNode, "bonus", "number", DB.getValue(nodeItem, "dmgbonusbak", 0)) + if DB.getValue(vvNode, "critmultbak", 2) > 2 then + DB.setValue(vvNode, "critmult", "number", DB.getValue(nodeItem, "critmultbak", 2)) end end end @@ -58,182 +69,218 @@ function handleBrokenItem(nodeItem) end local function brokenItemCost() - local sItemCostBak = DB.getValue(nodeItem, 'costbak', ''):gsub(',+', ''):gsub('%s+', '') + local sItemCostBak = DB.getValue(nodeItem, "costbak", ""):gsub(",+", ""):gsub("%s+", "") - if bIsBroken and sItemCostBak ~= '' then + if bIsBroken and sItemCostBak ~= "" then --- This function rounds nNum to nDecimalPlaces (or to a whole number) local function round(nNum, nDecimalPlaces) - if not nNum then return 0 end + if not nNum then + return 0 + end local nMult = 10 ^ (nDecimalPlaces or 0) return math.floor(nNum * nMult + 0.5) / nMult end - local nItemCostSeperator = string.find(sItemCostBak, string.match(sItemCostBak, '[%D]')) + local nItemCostSeperator = string.find(sItemCostBak, string.match(sItemCostBak, "[%D]")) DB.setValue( nodeItem, - 'cost', - 'string', + "cost", + "string", round(tonumber(string.sub(sItemCostBak, 1, nItemCostSeperator - 1)) or 0 * 0.75, nil) - .. ' ' + .. " " .. string.sub(sItemCostBak, nItemCostSeperator) ) elseif not bIsBroken then - DB.setValue(nodeItem, 'cost', 'string', DB.getValue(nodeItem, 'costbak', '')) + DB.setValue(nodeItem, "cost", "string", DB.getValue(nodeItem, "costbak", "")) end end brokenItemCost() - if ItemManager.isWeapon(nodeItem) then brokenWeapon() end + if ItemManager.isWeapon(nodeItem) then + brokenWeapon() + end local function brokenArmor() - for _, nodeName in ipairs({ 'bonus', 'ac', 'checkpenalty' }) do + for _, nodeName in ipairs({ "bonus", "ac", "checkpenalty" }) do local value if bIsBroken then - value = math.floor(DB.getValue(nodeItem, nodeName .. 'bak', 0) / 2) + value = math.floor(DB.getValue(nodeItem, nodeName .. "bak", 0) / 2) else - value = DB.getValue(nodeItem, nodeName .. 'bak', 0) + value = DB.getValue(nodeItem, nodeName .. "bak", 0) end - DB.setValue(nodeItem, nodeName, 'number', value) + DB.setValue(nodeItem, nodeName, "number", value) end end - if ItemManager.isArmor(nodeItem) then brokenArmor() end - if ItemManager.isShield(nodeItem) and StringManager.contains(Extension.getExtensions(), 'FG-PFRPG-Advanced-Item-Actions') then + if ItemManager.isArmor(nodeItem) then + brokenArmor() + end + if + ItemManager.isShield(nodeItem) + and StringManager.contains(Extension.getExtensions(), "FG-PFRPG-Advanced-Item-Actions") + then brokenWeapon() end end local function removeBackup() - for _, nodeName in ipairs({ 'cost', 'bonus', 'ac', 'checkpenalty', 'damage', 'critical', 'atkbonus', 'critatkrange', 'dmgbonus', 'critmult' }) do - if DB.getValue(nodeItem, nodeName .. 'bak') then DB.deleteChild(nodeItem, nodeName .. 'bak') end + for _, nodeName in ipairs({ + "cost", + "bonus", + "ac", + "checkpenalty", + "damage", + "critical", + "atkbonus", + "critatkrange", + "dmgbonus", + "critmult", + }) do + if DB.getValue(nodeItem, nodeName .. "bak") then + DB.deleteChild(nodeItem, nodeName .. "bak") + end end end local function makeBackup() - DB.setValue(nodeItem, 'costbak', 'string', DB.getValue(nodeItem, 'cost', '')) + DB.setValue(nodeItem, "costbak", "string", DB.getValue(nodeItem, "cost", "")) - for _, nodeName in ipairs({ 'bonus', 'ac', 'checkpenalty' }) do - DB.setValue(nodeItem, nodeName .. 'bak', 'number', DB.getValue(nodeItem, nodeName, 0)) + for _, nodeName in ipairs({ "bonus", "ac", "checkpenalty" }) do + DB.setValue(nodeItem, nodeName .. "bak", "number", DB.getValue(nodeItem, nodeName, 0)) end - DB.setValue(nodeItem, 'damagebak', 'string', DB.getValue(nodeItem, 'damage', '')) - DB.setValue(nodeItem, 'criticalbak', 'string', DB.getValue(nodeItem, 'critical', 'x2')) + DB.setValue(nodeItem, "damagebak", "string", DB.getValue(nodeItem, "damage", "")) + DB.setValue(nodeItem, "criticalbak", "string", DB.getValue(nodeItem, "critical", "x2")) local tDamagedWeapons = handleWeaponNodeArgs() for _, vNode in pairs(tDamagedWeapons) do - DB.setValue(nodeItem, 'atkbonusbak', 'number', DB.getValue(vNode, 'bonus', 0)) - DB.setValue(nodeItem, 'critatkrangebak', 'number', DB.getValue(vNode, 'critatkrange', 20)) - for _, vvNode in ipairs(DB.getChildList(vNode, 'damagelist')) do - DB.setValue(nodeItem, 'dmgbonusbak', 'number', DB.getValue(vvNode, 'bonus', 0)) - DB.setValue(nodeItem, 'critmultbak', 'number', DB.getValue(vvNode, 'critmult', 2)) + DB.setValue(nodeItem, "atkbonusbak", "number", DB.getValue(vNode, "bonus", 0)) + DB.setValue(nodeItem, "critatkrangebak", "number", DB.getValue(vNode, "critatkrange", 20)) + for _, vvNode in ipairs(DB.getChildList(vNode, "damagelist")) do + DB.setValue(nodeItem, "dmgbonusbak", "number", DB.getValue(vvNode, "bonus", 0)) + DB.setValue(nodeItem, "critmultbak", "number", DB.getValue(vvNode, "critmult", 2)) end end end - local sItemName = DB.getValue(nodeItem, 'name', '') - if sItemName == '' then return end + local sItemName = DB.getValue(nodeItem, "name", "") + if sItemName == "" then + return + end - local nBrokenState = DB.getValue(nodeItem, 'broken', 0) - local messagedata = { sender = DB.getValue(nodeItem, '...name'), font = 'emotefont' } + local nBrokenState = DB.getValue(nodeItem, "broken", 0) + local messagedata = { sender = DB.getValue(nodeItem, "...name"), font = "emotefont" } - if nBrokenState == 2 and not sItemName:find('%[DESTROYED%]') then - if OptionsManager.isOption('DESTROY_ITEM', 'gone') then + if nBrokenState == 2 and not sItemName:find("%[DESTROYED%]") then + if OptionsManager.isOption("DESTROY_ITEM", "gone") then DB.deleteNode(nodeItem) - elseif OptionsManager.isOption('DESTROY_ITEM', 'unequipped') then - DB.setValue(nodeItem, 'carried', 'number', 0) - DB.setValue(nodeItem, 'name', 'string', '[DESTROYED] ' .. DB.getValue(nodeItem, 'name', '')) + elseif OptionsManager.isOption("DESTROY_ITEM", "unequipped") then + DB.setValue(nodeItem, "carried", "number", 0) + DB.setValue(nodeItem, "name", "string", "[DESTROYED] " .. DB.getValue(nodeItem, "name", "")) end - messagedata.text = string.format(Interface.getString('char_actions_weapon_destroyed'), sItemName) + messagedata.text = string.format(Interface.getString("char_actions_weapon_destroyed"), sItemName) Comm.deliverChatMessage(messagedata) - elseif nBrokenState == 1 and not sItemName:find('%[BROKEN%]') then + elseif nBrokenState == 1 and not sItemName:find("%[BROKEN%]") then makeBackup() brokenPenalties(true) - DB.setValue(nodeItem, 'name', 'string', '[BROKEN] ' .. DB.getValue(nodeItem, 'name', '')) + DB.setValue(nodeItem, "name", "string", "[BROKEN] " .. DB.getValue(nodeItem, "name", "")) - messagedata.text = string.format(Interface.getString('char_actions_weapon_broken'), sItemName) + messagedata.text = string.format(Interface.getString("char_actions_weapon_broken"), sItemName) Comm.deliverChatMessage(messagedata) else brokenPenalties(false) removeBackup() - if sItemName:find('%[BROKEN%]') then DB.setValue(nodeItem, 'name', 'string', sItemName:gsub('%[BROKEN%]%s', '')) end + if sItemName:find("%[BROKEN%]") then + DB.setValue(nodeItem, "name", "string", sItemName:gsub("%[BROKEN%]%s", "")) + end end end -local function onBrokenChanged(node) handleBrokenItem(DB.getParent(node)) end +local function onBrokenChanged(node) + handleBrokenItem(DB.getParent(node)) +end local function getWeaponName(s) - local sWeaponName = s:gsub('%[ATTACK%s#?%d*%s?%(%u%)%]', '') - sWeaponName = sWeaponName:gsub('%[%u+%]', '') - if sWeaponName:match('%[USING%s') then sWeaponName = sWeaponName:match('%[USING%s(.-)%]') end - sWeaponName = sWeaponName:gsub('%[.+%]', '') - sWeaponName = sWeaponName:gsub(' %(vs%. .+%)', '') + local sWeaponName = s:gsub("%[ATTACK%s#?%d*%s?%(%u%)%]", "") + sWeaponName = sWeaponName:gsub("%[%u+%]", "") + if sWeaponName:match("%[USING%s") then + sWeaponName = sWeaponName:match("%[USING%s(.-)%]") + end + sWeaponName = sWeaponName:gsub("%[.+%]", "") + sWeaponName = sWeaponName:gsub(" %(vs%. .+%)", "") sWeaponName = StringManager.trim(sWeaponName) - return sWeaponName or '' + return sWeaponName or "" end -- examine weapon properties to check if fragile local function isFragile(nodeWeapon) - local sWeaponProperties = DB.getValue(nodeWeapon, 'properties', ''):lower() - local bIsFragile = (sWeaponProperties:find('fragile') or 0) > 0 - local bIsMasterwork = sWeaponProperties:find('masterwork') or false - local bIsBone = sWeaponProperties:find('bone') or false - local bIsMagic = DB.getValue(nodeWeapon, 'bonus', 0) > 0 + local sWeaponProperties = DB.getValue(nodeWeapon, "properties", ""):lower() + local bIsFragile = (sWeaponProperties:find("fragile") or 0) > 0 + local bIsMasterwork = sWeaponProperties:find("masterwork") or false + local bIsBone = sWeaponProperties:find("bone") or false + local bIsMagic = DB.getValue(nodeWeapon, "bonus", 0) > 0 return (bIsFragile and not bIsMagic and (not bIsMasterwork or bIsBone)) end local function notifyNoHitpoints(rSource, sWeaponName) local messagedata = { sender = rSource.sName, - font = 'emotefont', - text = string.format(Interface.getString('char_actions_fragile_unknownhp'), sWeaponName), + font = "emotefont", + text = string.format(Interface.getString("char_actions_fragile_unknownhp"), sWeaponName), } Comm.deliverChatMessage(messagedata) end -- if weapon is fragile, set as broken or destroyed and post a chat message. local function breakWeapon(nodeWeapon, sWeaponName, rSource) - if not nodeWeapon or not isFragile(nodeWeapon) then return end + if not nodeWeapon or not isFragile(nodeWeapon) then + return + end - local nBroken = DB.getValue(nodeWeapon, 'broken', 0) - local nItemHitpoints = DB.getValue(nodeWeapon, 'hitpoints', 0) - local nItemDamage = DB.getValue(nodeWeapon, 'itemdamage', 0) + local nBroken = DB.getValue(nodeWeapon, "broken", 0) + local nItemHitpoints = DB.getValue(nodeWeapon, "hitpoints", 0) + local nItemDamage = DB.getValue(nodeWeapon, "itemdamage", 0) if nBroken == 0 then - DB.setValue(nodeWeapon, 'broken', 'number', 1) + DB.setValue(nodeWeapon, "broken", "number", 1) if nItemHitpoints == 0 then notifyNoHitpoints(rSource, sWeaponName) return end - DB.setValue(nodeWeapon, 'itemdamage', 'number', math.floor(nItemHitpoints / 2) + math.max(nItemDamage, 1)) + DB.setValue(nodeWeapon, "itemdamage", "number", math.floor(nItemHitpoints / 2) + math.max(nItemDamage, 1)) elseif nBroken == 1 then - DB.setValue(nodeWeapon, 'broken', 'number', 2) + DB.setValue(nodeWeapon, "broken", "number", 2) if nItemHitpoints == 0 then notifyNoHitpoints(rSource, sWeaponName) return end - DB.setValue(nodeWeapon, 'itemdamage', 'number', nItemHitpoints + math.max(nItemDamage, 1)) + DB.setValue(nodeWeapon, "itemdamage", "number", nItemHitpoints + math.max(nItemDamage, 1)) end local messagedata = { sender = rSource.sName, - font = 'emotefont', - text = string.format(Interface.getString('char_actions_fragile'), sWeaponName), + font = "emotefont", + text = string.format(Interface.getString("char_actions_fragile"), sWeaponName), } Comm.deliverChatMessage(messagedata) end -- luacheck: globals onFumbleBreakWeapon function onFumbleBreakWeapon(rSource, sDesc) - if not ActorManager.isPC(rSource) then return end + if not ActorManager.isPC(rSource) then + return + end local sWeaponName = getWeaponName(sDesc) - if string.find(sDesc, '%[CONFIRM%]') or sWeaponName == '' then return end + if string.find(sDesc, "%[CONFIRM%]") or sWeaponName == "" then + return + end - for _, nodeWeapon in ipairs(DB.getChildList(ActorManager.getCreatureNode(rSource), 'weaponlist')) do - local sWeaponNameFromNode = getWeaponName(DB.getValue(nodeWeapon, 'name', '')) + for _, nodeWeapon in ipairs(DB.getChildList(ActorManager.getCreatureNode(rSource), "weaponlist")) do + local sWeaponNameFromNode = getWeaponName(DB.getValue(nodeWeapon, "name", "")) if sWeaponNameFromNode == sWeaponName then - local _, sWeaponNode = DB.getValue(nodeWeapon, 'shortcut', '') + local _, sWeaponNode = DB.getValue(nodeWeapon, "shortcut", "") breakWeapon(DB.findNode(sWeaponNode), sWeaponName, rSource) break end @@ -245,19 +292,30 @@ end local onPostAttackResolve_old local function onPostAttackResolve_new(rSource, rTarget, rRoll, rMessage, ...) onPostAttackResolve_old(rSource, rTarget, rRoll, rMessage, ...) - if rRoll.sResult == 'fumble' then onFumbleBreakWeapon(rSource, rRoll.sDesc) end + if rRoll.sResult == "fumble" then + onFumbleBreakWeapon(rSource, rRoll.sDesc) + end end function onInit() - OptionsManager.registerOption2('DESTROY_ITEM', false, 'option_header_game', 'opt_lab_item_destroyed', 'option_entry_cycler', { - labels = 'enc_opt_item_destroyed_gone', - values = 'gone', - baselabel = 'enc_opt_item_destroyed_unequipped', - baseval = 'unequipped', - default = 'unequipped', - }) - - if Session.IsHost then DB.addHandler(DB.getPath('charsheet.*.inventorylist.*.broken'), 'onUpdate', onBrokenChanged) end + OptionsManager.registerOption2( + "DESTROY_ITEM", + false, + "option_header_game", + "opt_lab_item_destroyed", + "option_entry_cycler", + { + labels = "enc_opt_item_destroyed_gone", + values = "gone", + baselabel = "enc_opt_item_destroyed_unequipped", + baseval = "unequipped", + default = "unequipped", + } + ) + + if Session.IsHost then + DB.addHandler(DB.getPath("charsheet.*.inventorylist.*.broken"), "onUpdate", onBrokenChanged) + end onPostAttackResolve_old = ActionAttack.onPostAttackResolve ActionAttack.onPostAttackResolve = onPostAttackResolve_new diff --git a/scripts/damage_itemdurability.lua b/scripts/damage_itemdurability.lua index 2d9e438..8fed504 100644 --- a/scripts/damage_itemdurability.lua +++ b/scripts/damage_itemdurability.lua @@ -6,19 +6,23 @@ -- After processing, the total is rounded down. -- Finally, it is returned to the calling function. local function adjustDamageTypes(nDmgTotal, tTypes, bIsRanged) - if not nDmgTotal then return 0 end + if not nDmgTotal then + return 0 + end - local tNone = { 'nonlethal', 'critical', 'positive', 'negative' } + local tNone = { "nonlethal", "critical", "positive", "negative" } - local tPFEnergyHalf = { 'fire', 'cold', 'acid', 'lightning', 'sonic' } + local tPFEnergyHalf = { "fire", "cold", "acid", "lightning", "sonic" } - local t35eEnergyHalf = { 'electricity', 'fire' } - local t35eEnergyQuarter = { 'cold' } + local t35eEnergyHalf = { "electricity", "fire" } + local t35eEnergyQuarter = { "cold" } - if bIsRanged then nDmgTotal = nDmgTotal / 2 end + if bIsRanged then + nDmgTotal = nDmgTotal / 2 + end for _, v in pairs(tTypes) do - v = string.gsub(v, '%s+', '') + v = string.gsub(v, "%s+", "") for _, vv in pairs(tNone) do if vv == v then nDmgTotal = 0 @@ -58,16 +62,18 @@ end local function findTypedDamage(sDamage, bIsRanged) local nFieldStart = 1 - local sDmgStart = string.find(sDamage, '%(', nFieldStart) + local sDmgStart = string.find(sDamage, "%(", nFieldStart) local sDmg = string.sub(sDamage, sDmgStart + 1, string.len(sDamage) - 1) - local nDmgTotalStart = string.find(sDmg, '=', nFieldStart) - if nDmgTotalStart then sDmg = string.sub(sDmg, nDmgTotalStart + 1, string.len(sDamage)) end + local nDmgTotalStart = string.find(sDmg, "=", nFieldStart) + if nDmgTotalStart then + sDmg = string.sub(sDmg, nDmgTotalStart + 1, string.len(sDamage)) + end - local sTypes = string.lower(string.sub(sDamage, nFieldStart, sDmgStart - 2) .. ',') + local sTypes = string.lower(string.sub(sDamage, nFieldStart, sDmgStart - 2) .. ",") local tTypes = {} repeat - local nNextI = string.find(sTypes, ',', nFieldStart) + local nNextI = string.find(sTypes, ",", nFieldStart) table.insert(tTypes, string.sub(sTypes, nFieldStart, nNextI - 1)) nFieldStart = nNextI + 1 until nFieldStart > string.len(sTypes) @@ -77,15 +83,17 @@ end --- This function local function setItemDamage(nodeItem, nDmgTotal, nBypassThresh) - local nHardness = DB.getValue(nodeItem, 'hardness') + local nHardness = DB.getValue(nodeItem, "hardness") if nBypassThresh then - if nBypassThresh > nHardness then nHardness = 0 end + if nBypassThresh > nHardness then + nHardness = 0 + end end local nModifiedDamage = nDmgTotal - nHardness if nModifiedDamage > 0 then - local nPreviousDmg = DB.getValue(nodeItem, 'itemdamage') - DB.setValue(nodeItem, 'itemdamage', 'number', nPreviousDmg + nModifiedDamage) + local nPreviousDmg = DB.getValue(nodeItem, "itemdamage") + DB.setValue(nodeItem, "itemdamage", "number", nPreviousDmg + nModifiedDamage) end end @@ -101,9 +109,11 @@ local function sumTypes(nodeItem, tDamageTypes, nBypassThresh) for _, v in ipairs(tDamageTypes) do local nFieldStart = 1 - if string.find(v, '%[DAMAGE %(R%)%]', nFieldStart) then bIsRanged = true end + if string.find(v, "%[DAMAGE %(R%)%]", nFieldStart) then + bIsRanged = true + end - local nTypePosition = string.find(v, '%[TYPE: ', nFieldStart) + local nTypePosition = string.find(v, "%[TYPE: ", nFieldStart) if nTypePosition then local nFieldStop = string.len(v) local sDamage = string.sub(v, nTypePosition + 7, nFieldStop - 1) -- format is "slashing (1d4+5=4)" @@ -123,13 +133,15 @@ function splitDamageTypes(nodeItem, sDragInfo) local nFieldStart = 1 local tDamageTypes = {} repeat - local nexti_s = string.find(sDragInfo, '%[', nFieldStart) - local nexti_e = string.find(sDragInfo, '%]', nFieldStart) + local nexti_s = string.find(sDragInfo, "%[", nFieldStart) + local nexti_e = string.find(sDragInfo, "%]", nFieldStart) table.insert(tDamageTypes, string.sub(sDragInfo, nexti_s, nexti_e)) nFieldStart = nexti_e + 1 until nFieldStart > string.len(sDragInfo) local nBypassThresh = nil - if string.find(string.lower(sDragInfo), 'adamantine', 1) then nBypassThresh = 20 end + if string.find(string.lower(sDragInfo), "adamantine", 1) then + nBypassThresh = 20 + end sumTypes(nodeItem, tDamageTypes, nBypassThresh) end diff --git a/scripts/hhp_itemdurability.lua b/scripts/hhp_itemdurability.lua index 07398de..db661bb 100644 --- a/scripts/hhp_itemdurability.lua +++ b/scripts/hhp_itemdurability.lua @@ -13,8 +13,8 @@ end local function getItemHp(nodeItem, tSubstanceStats) local function getArmorHpFromAc() - local nArmorHpAc = DB.getValue(nodeItem, 'ac', 0) * 5 - local sItemSize = DB.getValue(nodeItem, 'size', ''):lower() + local nArmorHpAc = DB.getValue(nodeItem, "ac", 0) * 5 + local sItemSize = DB.getValue(nodeItem, "size", ""):lower() for k, v in pairs(ItemDurabilityInfo.tSizes) do if k == sItemSize then nArmorHpAc = nArmorHpAc * v @@ -27,13 +27,14 @@ local function getItemHp(nodeItem, tSubstanceStats) local nArmorHpAc = getArmorHpFromAc(nodeItem) local nItemHpPerIn = tSubstanceStats.nItemHpPerIn or 0 - local nItemThickness = DB.getValue(nodeItem, 'thickness', 0) + local nItemThickness = DB.getValue(nodeItem, "thickness", 0) local nItemHp if ItemManager.isArmor(nodeItem) then nItemHp = (nArmorHpAc * (tSubstanceStats.nArmorHpMult or 1)) + (tSubstanceStats.nArmorHpBonus or 0) elseif ItemManager.isWeapon(nodeItem) then - nItemHp = (nItemHpPerIn * nItemThickness * (tSubstanceStats.nWeaponHpMult or 1)) + (tSubstanceStats.nWeaponHpBonus or 0) + nItemHp = (nItemHpPerIn * nItemThickness * (tSubstanceStats.nWeaponHpMult or 1)) + + (tSubstanceStats.nWeaponHpBonus or 0) else nItemHp = (nItemHpPerIn * nItemThickness) end @@ -58,9 +59,19 @@ function miscHardness(nodeItem) -- luacheck: ignore end function calculateHHP(nodeItem) - local tSubstanceStats = getSubstanceStats(DB.getValue(nodeItem, 'substance', ''):lower()) + local tSubstanceStats = getSubstanceStats(DB.getValue(nodeItem, "substance", ""):lower()) - local nItemEnhancementBonus = DB.getValue(nodeItem, 'bonus', 0) - DB.setValue(nodeItem, 'hardness', 'number', math.floor(getItemHardness(nodeItem, tSubstanceStats) + (nItemEnhancementBonus * 2), nil)) - DB.setValue(nodeItem, 'hitpoints', 'number', math.floor(getItemHp(nodeItem, tSubstanceStats) + (nItemEnhancementBonus * 10), nil)) + local nItemEnhancementBonus = DB.getValue(nodeItem, "bonus", 0) + DB.setValue( + nodeItem, + "hardness", + "number", + math.floor(getItemHardness(nodeItem, tSubstanceStats) + (nItemEnhancementBonus * 2), nil) + ) + DB.setValue( + nodeItem, + "hitpoints", + "number", + math.floor(getItemHp(nodeItem, tSubstanceStats) + (nItemEnhancementBonus * 10), nil) + ) end diff --git a/scripts/info_itemdurability.lua b/scripts/info_itemdurability.lua index 8a27266..7b12d53 100644 --- a/scripts/info_itemdurability.lua +++ b/scripts/info_itemdurability.lua @@ -4,123 +4,123 @@ -- luacheck: globals aMaterials aMaterials = { -- materials from Special Materials list - ['abysium'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['angelskin'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 5 }, - ['aszite'] = { ['nHardness'] = 15, ['nItemHpPerIn'] = 20 }, - ['magic bridge basalt'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, -- not sure about this hp/in figure - ['blight quartz'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 10 }, - ['bone'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 12 }, -- I made up this nItemHpPerIn + ["abysium"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["angelskin"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 5 }, + ["aszite"] = { ["nHardness"] = 15, ["nItemHpPerIn"] = 20 }, + ["magic bridge basalt"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, -- not sure about this hp/in figure + ["blight quartz"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 10 }, + ["bone"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 12 }, -- I made up this nItemHpPerIn -- ['brass'] = { ['nHardness'] = 9, ['nItemHpPerIn'] = 0 }, -- This should exist, but doesn't - ['chitin'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 12 }, -- I made this up based on bone - ['coral'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 12 }, -- I made this up based on bone - ['cryptstone'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['blood crystal'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 10, ['nWeaponHpMult'] = 0.5 }, - ['darkleaf cloth'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 20 }, - ['darkwood'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, - ['dragonhide'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 10 }, + ["chitin"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 12 }, -- I made this up based on bone + ["coral"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 12 }, -- I made this up based on bone + ["cryptstone"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["blood crystal"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 10, ["nWeaponHpMult"] = 0.5 }, + ["darkleaf cloth"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 20 }, + ["darkwood"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, + ["dragonhide"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 10 }, -- hide of a dragon is typically between 1/2 inch and 1 inch thick - ['druchite'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 40 }, - ['eel hide'] = { ['nHardness'] = 2, ['nItemHpPerIn'] = 5 }, - ['elysian bronze'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, + ["druchite"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 40 }, + ["eel hide"] = { ["nHardness"] = 2, ["nItemHpPerIn"] = 5 }, + ["elysian bronze"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, -- ['bronze'] = { ['nHardness'] = 9, ['nItemHpPerIn'] = 10 }, -- bronze armor has hardness 9 and bronze weapons use the same hardness as their base weapon - ['gold'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 12 }, -- I made up this nItemHpPerIn - ['greenwood'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, - ['griffon mane'] = { ['nHardness'] = 1, ['nItemHpPerIn'] = 2 }, - ['horacalcum'] = { ['nHardness'] = 15, ['nItemHpPerIn'] = 30, ['nArmorHpMult'] = 1.25, ['nWeaponHpMult'] = 1.25 }, - ['inubrix'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, - ['cold iron'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['mindglass'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['noqual'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, + ["gold"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 12 }, -- I made up this nItemHpPerIn + ["greenwood"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, + ["griffon mane"] = { ["nHardness"] = 1, ["nItemHpPerIn"] = 2 }, + ["horacalcum"] = { ["nHardness"] = 15, ["nItemHpPerIn"] = 30, ["nArmorHpMult"] = 1.25, ["nWeaponHpMult"] = 1.25 }, + ["inubrix"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, + ["cold iron"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["mindglass"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["noqual"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, -- ['obsidian'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, -- obsidian weapons have half the hardness of their base weapon - ['siccatite'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, -- I made this up based on iron/steel - ['alchemical silver'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10 }, -- I made this up based on iron/steel - ['silversheen'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10 }, - ['glaucite'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['spiresteel'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['net'] = { ['nHardness'] = 2, ['nItemHpPerIn'] = 5 }, -- I made this up based on leather - ['living steel'] = { ['nHardness'] = 15, ['nItemHpPerIn'] = 35 }, - ['singing steel'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 20 }, - ['sunsilver'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10 }, - ['silver'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10 }, + ["siccatite"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, -- I made this up based on iron/steel + ["alchemical silver"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 10 }, -- I made this up based on iron/steel + ["silversheen"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 10 }, + ["glaucite"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["spiresteel"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["net"] = { ["nHardness"] = 2, ["nItemHpPerIn"] = 5 }, -- I made this up based on leather + ["living steel"] = { ["nHardness"] = 15, ["nItemHpPerIn"] = 35 }, + ["singing steel"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 20 }, + ["sunsilver"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 10 }, + ["silver"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 10 }, -- This silver entry is a workaround because nobody says "alchemical silver" in their weapon names -- ['viridium'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10 }, -- viridium weapons have half the hardness of their base weapon - ['voidglass'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['whipwood'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 10, ['nWeaponHpBonus'] = 5 }, - ['wyroot'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, + ["voidglass"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["whipwood"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 10, ["nWeaponHpBonus"] = 5 }, + ["wyroot"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, -- substances from Damaging Items list - ['glass'] = { ['nHardness'] = 1, ['nItemHpPerIn'] = 1 }, - ['paper'] = { ['nHardness'] = 0, ['nItemHpPerIn'] = 2 }, - ['cloth'] = { ['nHardness'] = 0, ['nItemHpPerIn'] = 2 }, - ['fabric'] = { ['nHardness'] = 0, ['nItemHpPerIn'] = 2 }, -- Just in case - ['rope'] = { ['nHardness'] = 0, ['nItemHpPerIn'] = 2 }, - ['ice'] = { ['nHardness'] = 0, ['nItemHpPerIn'] = 3 }, - ['leather'] = { ['nHardness'] = 2, ['nItemHpPerIn'] = 5 }, - ['hide'] = { ['nHardness'] = 2, ['nItemHpPerIn'] = 5 }, - ['wood'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, - ['wooden'] = { ['nHardness'] = 5, ['nItemHpPerIn'] = 10 }, -- Just in case - ['stone'] = { ['nHardness'] = 8, ['nItemHpPerIn'] = 15 }, - ['iron'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['steel'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, - ['metal'] = { ['nHardness'] = 10, ['nItemHpPerIn'] = 30 }, -- This isn't accurate but it's ok - ['mithral'] = { ['nHardness'] = 15, ['nItemHpPerIn'] = 30 }, - ['adamantine'] = { ['nHardness'] = 20, ['nItemHpPerIn'] = 40, ['nArmorHpMult'] = 1.33 }, + ["glass"] = { ["nHardness"] = 1, ["nItemHpPerIn"] = 1 }, + ["paper"] = { ["nHardness"] = 0, ["nItemHpPerIn"] = 2 }, + ["cloth"] = { ["nHardness"] = 0, ["nItemHpPerIn"] = 2 }, + ["fabric"] = { ["nHardness"] = 0, ["nItemHpPerIn"] = 2 }, -- Just in case + ["rope"] = { ["nHardness"] = 0, ["nItemHpPerIn"] = 2 }, + ["ice"] = { ["nHardness"] = 0, ["nItemHpPerIn"] = 3 }, + ["leather"] = { ["nHardness"] = 2, ["nItemHpPerIn"] = 5 }, + ["hide"] = { ["nHardness"] = 2, ["nItemHpPerIn"] = 5 }, + ["wood"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, + ["wooden"] = { ["nHardness"] = 5, ["nItemHpPerIn"] = 10 }, -- Just in case + ["stone"] = { ["nHardness"] = 8, ["nItemHpPerIn"] = 15 }, + ["iron"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["steel"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, + ["metal"] = { ["nHardness"] = 10, ["nItemHpPerIn"] = 30 }, -- This isn't accurate but it's ok + ["mithral"] = { ["nHardness"] = 15, ["nItemHpPerIn"] = 30 }, + ["adamantine"] = { ["nHardness"] = 20, ["nItemHpPerIn"] = 40, ["nArmorHpMult"] = 1.33 }, } -- luacheck: globals tItems tItems = { -- adventuring supplies - ['vial'] = 'glass', - ['potion'] = 'glass', - ['scroll of'] = 'paper', - ['wand'] = 'wood', - ['torch'] = 'wood', - ['bottle'] = 'glass', - ['outfit'] = 'cloth', - ['bag'] = 'cloth', - ['backpack'] = 'cloth', - ['tent'] = 'cloth', + ["vial"] = "glass", + ["potion"] = "glass", + ["scroll of"] = "paper", + ["wand"] = "wood", + ["torch"] = "wood", + ["bottle"] = "glass", + ["outfit"] = "cloth", + ["bag"] = "cloth", + ["backpack"] = "cloth", + ["tent"] = "cloth", -- weapons - ['sword'] = 'steel', - ['rapier'] = 'steel', - ['halberd'] = 'steel', - ['axe'] = 'steel', - ['dagger'] = 'steel', - ['quarterstaff'] = 'wood', - ['spear'] = 'wood', - ['club'] = 'wood', - ['mace'] = 'steel', - ['kukri'] = 'steel', - ['machete'] = 'steel', - ['knife'] = 'steel', - ['razor'] = 'steel', - ['sling'] = 'leather', + ["sword"] = "steel", + ["rapier"] = "steel", + ["halberd"] = "steel", + ["axe"] = "steel", + ["dagger"] = "steel", + ["quarterstaff"] = "wood", + ["spear"] = "wood", + ["club"] = "wood", + ["mace"] = "steel", + ["kukri"] = "steel", + ["machete"] = "steel", + ["knife"] = "steel", + ["razor"] = "steel", + ["sling"] = "leather", -- armor - ['tunic'] = 'rope', - ['chain'] = 'steel', - ['plate'] = 'steel', - ['mail'] = 'steel', - ['buckler'] = 'steel', - ['tower'] = 'steel', + ["tunic"] = "rope", + ["chain"] = "steel", + ["plate"] = "steel", + ["mail"] = "steel", + ["buckler"] = "steel", + ["tower"] = "steel", } -- luacheck: globals tSizes tSizes = { -- hitpoint multipliers for each size category - ['colossal'] = 16, - ['gargantuan'] = 8, - ['huge'] = 4, - ['large'] = 2, - ['medium'] = 1, - ['small'] = 0.5, - ['tiny'] = 0.25, - ['diminutive'] = 0.125, - ['fine'] = 0.0625, + ["colossal"] = 16, + ["gargantuan"] = 8, + ["huge"] = 4, + ["large"] = 2, + ["medium"] = 1, + ["small"] = 0.5, + ["tiny"] = 0.25, + ["diminutive"] = 0.125, + ["fine"] = 0.0625, } --- This function fills the size and substance fields, if empty. @@ -130,9 +130,11 @@ tSizes = { -- @see findSubstance(nodeItem) -- luacheck: globals fillAttributes function fillAttributes(nodeItem) - local sItemSize = DB.getValue(nodeItem, 'size', ''):lower() - if sItemSize == '' then sItemSize = DB.getValue(nodeItem, '...size', 'medium'):lower() end - DB.setValue(nodeItem, 'size', 'string', sItemSize) + local sItemSize = DB.getValue(nodeItem, "size", ""):lower() + if sItemSize == "" then + sItemSize = DB.getValue(nodeItem, "...size", "medium"):lower() + end + DB.setValue(nodeItem, "size", "string", sItemSize) --- This function searches sItemProps, sItemName, and tItemParser for any of the keys in aSubstances. -- If it ever finds one, it stops searching and returns the key. @@ -140,7 +142,7 @@ function fillAttributes(nodeItem) -- @param nodeItem The item to be examined. -- @return sSubstance A string containing the material the item is most likely constructed of. local function findSubstance() - local sSubstance = '' + local sSubstance = "" local function setSubstance(string, searchterm, material) if string:match(searchterm) then @@ -150,17 +152,27 @@ function fillAttributes(nodeItem) end for kk, vv in pairs(tItems) do - if setSubstance(DB.getValue(nodeItem, 'name', ''):lower(), kk, vv) then break end + if setSubstance(DB.getValue(nodeItem, "name", ""):lower(), kk, vv) then + break + end end for k, _ in pairs(aMaterials) do - if setSubstance(DB.getValue(nodeItem, 'properties', ''):lower(), k, k) then break end - if setSubstance(DB.getValue(nodeItem, 'name', ''):lower(), k, k) then break end + if setSubstance(DB.getValue(nodeItem, "properties", ""):lower(), k, k) then + break + end + if setSubstance(DB.getValue(nodeItem, "name", ""):lower(), k, k) then + break + end end return sSubstance end - if DB.getValue(nodeItem, 'substance', '') == '' then DB.setValue(nodeItem, 'substance', 'string', findSubstance()) end + if DB.getValue(nodeItem, "substance", "") == "" then + DB.setValue(nodeItem, "substance", "string", findSubstance()) + end - if DB.getValue(nodeItem, 'hardness', 0) == 0 and DB.getValue(nodeItem, 'hitpoints', 0) == 0 then ItemDurabilityHHP.calculateHHP(nodeItem) end + if DB.getValue(nodeItem, "hardness", 0) == 0 and DB.getValue(nodeItem, "hitpoints", 0) == 0 then + ItemDurabilityHHP.calculateHHP(nodeItem) + end end