diff --git a/aard_inventory.changelog b/aard_inventory.changelog index 5005638..26769eb 100644 --- a/aard_inventory.changelog +++ b/aard_inventory.changelog @@ -1,6 +1,16 @@ dbot.changelog = {} +dbot.changelog[2.0008] = +{ + { change = drlDbotChangeLogTypeNew, + desc = "Updated "dinv priority display ..." to show all level blocks at once" + }, + { change = drlDbotChangeLogTypeMisc, + desc = "Refactored priority framework in preparation for a priority GUI" + } +} + dbot.changelog[2.0007] = { { change = drlDbotChangeLogTypeMisc, @@ -65,7 +75,7 @@ dbot.changelog[2.0002] = dbot.changelog[2.0001] = { { change = drlDbotChangeLogTypeFix, - desc = "Fixed update framework for older r1825 mush builds" + desc = "Fixed update framework to support older r1825 mush builds" }, { change = drlDbotChangeLogTypeFix, desc = "Properly handles if someone cancels a quit command" diff --git a/aard_inventory.xml b/aard_inventory.xml index 2aad75f..08af427 100644 --- a/aard_inventory.xml +++ b/aard_inventory.xml @@ -87,7 +87,7 @@ dbot.version : Module to track version and changelog information and update the save_state="y" date_written="2017-08-12 08:45:15" requires="4.98" - version="2.0007" + version="2.0008" > = v.minLevel) and (levelNum <= v.maxLevel) then - priorityBlock = v - break; - end -- if + -- Alphabetize the priorities before we list them + local sortedPriorities = {} + local numPriorities = 0 + for k,_ in pairs(inv.priority.table) do + table.insert(sortedPriorities, k) + numPriorities = numPriorities + 1 end -- for + table.sort(sortedPriorities, function (v1, v2) return v1 < v2 end) - -- Verify that we found an appropriate priority block for our level - if (priorityBlock == nil) then - dbot.warn("inv.priority.get: Failed to find a priority block for level " .. - levelNum .. " in priority \"" .. priorityName .. "\"") - return nil + if (numPriorities == 0) then + dbot.info("Priority table is empty") + else + dbot.print("@WPriorities:") + for _, priority in ipairs(sortedPriorities) do + dbot.print("@W \"@C" .. priority .. "@W\"@w") + end -- for end -- if - return priorityBlock.priorities, DRL_RET_SUCCESS - -end -- inv.priority.get + return inv.tags.stop(invTagsPriority, endTag, DRL_RET_SUCCESS) +end -- inv.priority.list function inv.priority.display(priorityName, endTag) local retval = DRL_RET_SUCCESS if (priorityName == nil) or (priorityName == "") then - dbot.warn("inv.priority.display: Missing priorityName parameter") + dbot.warn("inv.priority.display: Missing priorityName parameter") return inv.tags.stop(invTagsPriority, endTag, DRL_RET_INVALID_PARAM) end -- if @@ -10558,87 +10459,44 @@ function inv.priority.display(priorityName, endTag) return inv.tags.stop(invTagsPriority, endTag, DRL_RET_MISSING_ENTRY) end -- if - for i, priorityBlock in ipairs(priority) do - retval = inv.priority.displayBlock(priorityBlock, priorityName) - if (retval ~= DRL_RET_SUCCESS) then - dbot.warn("inv.priority.display: Failed to display priority block " .. i .. " for priority " .. - priorityName .. ": " .. dbot.retval.getString(retval)) - break - end -- if - end -- for + local priString = inv.priority.tableToString(priority, false, true, true) + + dbot.print("@WPriority: \"@C" .. priorityName .. "@W\"\n") + dbot.print(priString) return inv.tags.stop(invTagsPriority, endTag, retval) end -- inv.priority.display -function inv.priority.displayBlock(priorityBlock, priorityName) +function inv.priority.edit(priorityName, level, endTag) local retval = DRL_RET_SUCCESS - if (priorityBlock == nil) then - dbot.warn("inv.priority.displayBlock: Missing priority block parameter") - return DRL_RET_INVALID_PARAM + if (priorityName == nil) or (priorityName == "") then + dbot.warn("inv.priority.edit: priority name is missing!") + return inv.tags.stop(invTagsPriority, endTag, DRL_RET_INVALID_PARAM) end -- if - if (priorityBlock.minLevel == nil) or (priorityBlock.maxLevel == nil) or - (priorityBlock.priorities == nil) then - dbot.warn("inv.priority.displayBlock: Missing priority block components") - return DRL_RET_MISSING_ENTRY + if (inv.priority.table[priorityName] == nil) then + dbot.warn("inv.priority.edit: Priority \"@C" .. priorityName .. "@W\" does not exist") + return inv.tags.stop(invTagsPriority, endTag, DRL_RET_MISSING_ENTRY) end -- if - dbot.print("@WPriority \"@C" .. priorityName .. "@W\": Levels @G" .. priorityBlock.minLevel .. - "@W - @G" .. priorityBlock.maxLevel) - - -- We can't sort a table so create a temporary array and then sort the temporary array - local priorityArray = {} - for k, v in pairs(priorityBlock.priorities) do - table.insert(priorityArray, { name = k, value = v }) - end -- for - table.sort(priorityArray, function (v1, v2) return v1.value < v2.value end) - - -- Print the priorities in sorted order - for _, priorityEntry in ipairs(priorityArray) do - local valueColor = "@W" - if (priorityEntry.value < 0.7) then - valueColor = "@R" - elseif (priorityEntry.value > 1.4) then - valueColor = "@G" - end -- if - - if (priorityEntry.value ~= 0) then - dbot.print(string.format(" @y%12s @W= %s%.3f", priorityEntry.name, valueColor, priorityEntry.value)) - end -- if - end -- for + --FIXME: add the utils call here return retval -end -- inv.priority.displayBlock +end -- inv.priority.edit -function inv.priority.list(endTag) - if (inv.priority == nil) or (inv.priority.table == nil) then - dbot.error("inv.priority.list: Priority table is missing!") - return inv.tags.stop(invTagsPriority, endTag, DRL_RET_INTERNAL_ERROR) - end -- if +function inv.priority.split(priorityName, level, endTag) +--FIXME: add this! - -- Alphabetize the priorities before we list them - local sortedPriorities = {} - local numPriorities = 0 - for k,_ in pairs(inv.priority.table) do - table.insert(sortedPriorities, k) - numPriorities = numPriorities + 1 - end -- for - table.sort(sortedPriorities, function (v1, v2) return v1 < v2 end) +end -- inv.priority.split - if (numPriorities == 0) then - dbot.info("Priority table is empty") - else - dbot.print("@WPriorities:") - for _, priority in ipairs(sortedPriorities) do - dbot.print("@W \"@C" .. priority .. "@W\"@w") - end -- for - end -- if - return inv.tags.stop(invTagsPriority, endTag, DRL_RET_SUCCESS) -end -- inv.priority.list +function inv.priority.join(priorityName, level, endTag) +--FIXME: add this! + +end -- inv.priority.join function inv.priority.compare(priorityName1, priorityName2, endTag) @@ -10703,6 +10561,229 @@ function inv.priority.compare(priorityName1, priorityName2, endTag) end -- inv.priority.compare +function inv.priority.new(priorityName) + local retval = DRL_RET_SUCCESS + + if (priorityName == nil) or (priorityName == "") then + dbot.warn("inv.priority.new: priority name is missing!") + return DRL_RET_INVALID_PARAM + end -- if + + if (inv.priority.table[priorityName] ~= nil) then + dbot.warn("Skipping request for new priority \"@C" .. priorityName .. "@W\": priority already exists") + return DRL_RET_INVALID_PARAM + end -- if + + local priorities = {} + for _, entry in ipairs(inv.priority.fieldTable) do + priorities[entry[2]] = 0 + end -- if + + retval = inv.priority.add(priorityName, { { minLevel = 1, maxLevel = 291, priorities = priorities } }) + if (retval ~= DRL_RET_SUCCESS) then + dbot.warn("inv.priority.new: Failed to add priority \"@C" .. priorityName .. "@W\": " .. + dbot.retval.getString(retval)) + end -- if + + return retval +end -- inv.priority.new + + +function inv.priority.add(priorityName, priorityTable) + if (priorityName == nil) or (priorityName == "") then + dbot.warn("inv.priority.add: Missing priorityName parameter") + return DRL_RET_INVALID_PARAM + end -- if + + if (priorityTable == nil) then + dbot.warn("inv.priority.add: priorityTable is nil") + return DRL_RET_INVALID_PARAM + end -- if + + inv.priority.table[priorityName] = priorityTable + + local retval = inv.priority.save() + if (retval ~= DRL_RET_SUCCESS) then + dbot.warn("inv.priority.add: Failed to save priorities: " .. dbot.retval.getString(retval)) + end -- if + + return retval +end -- inv.priority.add + + +function inv.priority.remove(priorityName) + local retval + + if (priorityName == nil) or (priorityName == "") then + dbot.warn("inv.priority.remove: Missing priorityName parameter") + return DRL_RET_INVALID_PARAM + end -- if + + if (inv.priority.table[priorityName] == nil) then + dbot.warn("inv.priority.remove: Priority table does not contain an entry for priority \"" .. + priorityName .. "\"") + return DRL_RET_MISSING_ENTRY + end -- if + + inv.priority.table[priorityName] = nil + + retval = inv.priority.save() + if (retval ~= DRL_RET_SUCCESS) then + dbot.warn("inv.priority.remove: Failed to save priorities: " .. dbot.retval.getString(retval)) + end -- if + + return retval +end -- inv.priority.remove + + +-- Returns table/nil, return value +function inv.priority.get(priorityName, level) + + if (priorityName == nil) or (priorityName == "") then + dbot.warn("inv.priority.get: Missing priorityName parameter") + return nil, DRL_RET_INVALID_PARAM + end -- if + + local levelNum = tonumber(level or "none") + if (levelNum == nil) then + dbot.warn("inv.priority.get: level parameter is not a number") + return nil, DRL_RET_INVALID_PARAM + end -- if + + local priority = inv.priority.table[priorityName] + + if (priority == nil) then + dbot.warn("inv.priority.get: Priority \"" .. priorityName .. "\" is not in the priority table") + return nil, DRL_RET_MISSING_ENTRY + end -- if + + -- Find the priority block for our level + local priorityBlock = nil + for i,v in ipairs(priority) do + if (levelNum >= v.minLevel) and (levelNum <= v.maxLevel) then + priorityBlock = v + break; + end -- if + end -- for + + -- Verify that we found an appropriate priority block for our level + if (priorityBlock == nil) then + dbot.warn("inv.priority.get: Failed to find a priority block for level " .. + levelNum .. " in priority \"" .. priorityName .. "\"") + return nil + end -- if + + return priorityBlock.priorities, DRL_RET_SUCCESS + +end -- inv.priority.get + + +-- Returns string, retval +--[[ String format looks something like this: + + Field L001- L050- L100- L201- + Name L049 L099 L200 L299 + + int 0.800 0.900 1.000 1.000 + str 1.000 1.000 0.800 0.700 + ... +--]] +function inv.priority.tableToString(priorityTable, doDisplayUnused, doDisplayColors, doDisplayDesc) + local retval = DRL_RET_SUCCESS + local generalPrefix, generalSuffix = "", "" + local fieldPrefix, fieldSuffix = "", "" + local levelPrefix, levelSuffix = "", "" + local descPrefix, descSuffix = "", "" + + if doDisplayColors then + generalPrefix, generalSuffix = "@W", "@w" + fieldPrefix, fieldSuffix = "@C", "@w" + levelPrefix, levelSuffix = "@W", "@W" + descPrefix, descSuffix = "@c", "@w" + end -- if + + -- Create the first line of the header + local priString = generalPrefix .. string.format("%12s", "Field") + for _, blockEntry in ipairs(priorityTable) do + priString = priString .. string.format(" %sL%03d-%s", levelPrefix, blockEntry.minLevel, levelSuffix) + end -- for + + -- Create the second line of the header + priString = priString .. string.format("\n%12s", "Name") + for _, blockEntry in ipairs(priorityTable) do + priString = priString .. string.format(" %sL%03d%s ", levelPrefix, blockEntry.maxLevel, levelSuffix) + end -- for + priString = priString .. "\n" .. generalSuffix + + for _, fieldEntry in ipairs(inv.priority.fieldTable) do + local fieldName = fieldEntry[1] + local fieldDesc = fieldEntry[2] + local useField = true + + -- Check if we should display this field or not. We only use the field if at least one entry + -- block has a non-zero entry for the field or if the doDisplayUnused param is true. + if (not doDisplayUnused) then + useField = false + + for _, blockEntry in ipairs(priorityTable) do + local fieldValue = tonumber(blockEntry.priorities[fieldName] or "") or 0 + + if (fieldValue ~= 0) then + useField = true + break + end -- if + end -- if + end -- if + + if (useField) then + priString = priString .. fieldPrefix .. string.format("\n%12s", fieldName) .. fieldSuffix + + for _, blockEntry in ipairs(priorityTable) do + local fieldValue = tonumber(blockEntry.priorities[fieldName] or "") or 0 + local valuePrefix, valueSuffix = "", "" + + if doDisplayColors then + if (fieldValue <= 0) then + valuePrefix = "@R" + elseif (fieldValue < 0.5) then + valuePrefix = "@r" + elseif (fieldValue < 0.8) then + valuePrefix = "@y" + elseif (fieldValue < 1.4) then + valuePrefix = "@w" + elseif (fieldValue < 5) then + valuePrefix = "@g" + else + valuePrefix = "@G" + end -- if + + valueSuffix = "@W" + end -- if + + priString = priString .. valuePrefix .. string.format(" %5.2f", fieldValue) .. valueSuffix + end -- for + + if doDisplayDesc then + priString = priString .. " : " .. descPrefix .. fieldDesc .. descSuffix + end -- if + end -- if + end -- for + + return priString, retval +end -- inv.priority.tableToString + + +-- Returns priority table entry, retval +function inv.priority.stringToTable(priorityString) + local retval = DRL_RET_SUCCESS + local priEntry = {} + +--FIXME: add this! + + return priEntry, retval +end -- inv.priority.stringToTable + + function inv.priority.addDefault() local retval @@ -11654,6 +11735,69 @@ function inv.priority.addDefault() end -- inv.priority.addDefault +-- ordinal number, name, and description of each possible priority field +inv.priority.fieldTable = { + + { "str" , "Value of 1 point of the strength stat" }, + { "int" , "Value of 1 point of the intelligence stat" }, + { "wis" , "Value of 1 point of the wisdom stat" }, + { "dex" , "Value of 1 point of the dexterity stat" }, + { "con" , "Value of 1 point of the constitution stat" }, + { "luck" , "Value of 1 point of the luck stat" }, + + { "dam" , "Value of 1 point of damroll" }, + { "hit" , "Value of 1 point of hitroll" }, + + { "avedam" , "Value of 1 point of primary weapon ave damage" }, + { "offhandDam" , "Value of 1 point of offhand weapon ave damage" }, + + { "hp" , "Value of 1 hit point" }, + { "mana" , "Value of 1 mana point" }, + { "moves" , "Value of 1 movement point" }, + + { "sanctuary" , "Value placed on the sanctuary effect " }, + + { "haste" , "Value placed on the haste effect " }, + { "flying" , "Value placed on the flying effect " }, + { "invis" , "Value placed on the invisible effect " }, + { "regeneration", "Value placed on the regeneration effect" }, + { "detectinvis" , "Value placed on the detect invis effect " }, + { "detecthidden", "Value placed on the detect hidden effect " }, + { "detectevil" , "Value placed on the detect evil effect " }, + { "detectgood" , "Value placed on the detect good effect " }, + { "detectmagic" , "Value placed on the detect magic effect " }, + + { "dualwield" , "Value of an item's dual wield effect" }, + { "irongrip" , "Value of an item's irongrip effect" }, + { "shield" , "Value of a shield's damage reduction effect" }, + + { "allmagic" , "Value of 1 point in each magical resist type" }, + { "allphys" , "Value of 1 point in each physical resist type" }, + + { "bash" , "Value of 1 point of bash physical resistance" }, + { "pierce" , "Value of 1 point of pierce physical resistance" }, + { "slash" , "Value of 1 point of slash physical resistance" }, + + { "acid" , "Value of 1 point of acid magical resistance" }, + { "air" , "Value of 1 point of air magical resistance" }, + { "cold" , "Value of 1 point of cold magical resistance" }, + { "disease" , "Value of 1 point of disease magical resistance" }, + { "earth" , "Value of 1 point of earth magical resistance" }, + { "electric" , "Value of 1 point of electric magical resistance" }, + { "energy" , "Value of 1 point of energy magical resistance" }, + { "fire" , "Value of 1 point of fire magical resistance" }, + { "holy" , "Value of 1 point of holy magical resistance" }, + { "light" , "Value of 1 point of light magical resistance" }, + { "magic" , "Value of 1 point of magic magical resistance" }, + { "mental" , "Value of 1 point of mental magical resistance" }, + { "negative" , "Value of 1 point of negative magical resistance" }, + { "poison" , "Value of 1 point of poison magical resistance" }, + { "shadow" , "Value of 1 point of shadow magical resistance" }, + { "sonic" , "Value of 1 point of sonic magical resistance" }, + { "water" , "Value of 1 point of water magical resistance" } +} + + ---------------------------------------------------------------------------------------------------- -- -- Module to score items and sets based on a specified priority, level, and handicap