From 4e3cf5828915b8de96eb86e9a5e58a3147deb202 Mon Sep 17 00:00:00 2001 From: Not a name Date: Mon, 16 Nov 2015 01:10:18 +0100 Subject: [PATCH 01/10] Added support of editing market prices in a global config. --- src/001-constants.lua | 1 + src/002-states.lua | 1 + src/006-hud.lua | 10 ++- src/007-ini.lua | 69 +++++++++++++++- tools/bundle.js | 186 ++++++++++++++++++++++-------------------- 5 files changed, 174 insertions(+), 93 deletions(-) diff --git a/src/001-constants.lua b/src/001-constants.lua index 9cbef5d..7d5c5b9 100644 --- a/src/001-constants.lua +++ b/src/001-constants.lua @@ -1,5 +1,6 @@ local LIB_REVISION = '{{VERSION}}' local LIB_CONFIG = [[{{CONFIG}}]] +local LIB_PRICES_CONFIG = [[{{PRICES_CONFIG}}]] local FOLDER_SETTINGS_PATH = '..\\Settings\\' local FOLDER_LOGS_PATH = '..\\Log\\' local FOLDER_CONFIG_PATH = '..\\Configs\\' diff --git a/src/002-states.lua b/src/002-states.lua index b2f0c3a..83a29cd 100644 --- a/src/002-states.lua +++ b/src/002-states.lua @@ -18,6 +18,7 @@ local _script = { town = "{{SCRIPT_TOWN}}", vocation = "{{SCRIPT_VOCATION}}", configHash = "{{SCRIPT_CONFIG_HASH}}", + pricesConfigHash = "{{PRICES_CONFIG_HASH}}", townexit = nil, channel = nil, diff --git a/src/006-hud.lua b/src/006-hud.lua index cd5065a..9290506 100644 --- a/src/006-hud.lua +++ b/src/006-hud.lua @@ -360,6 +360,10 @@ Hud = (function() end end + local function getItemValue(lootID) + return _config['Prices'][lootID] or xeno.getItemValue(lootID) + end + local function hudTrack(type, itemid, amount, skipUpdate) -- Loot / Supplies local hudItem = _hud.index[type][itemid] @@ -374,8 +378,9 @@ Hud = (function() --local hudValue = values and formatNumber((itemValue / (values.d * 60)) * count) .. ' gp' or '--' -- Get current count and values - local calculateValue = type == 'Supplies' and xeno.getItemCost or xeno.getItemValue + local calculateValue = type == 'Supplies' and xeno.getItemCost or getItemValue local itemValue = calculateValue(itemid) + local hudCount = (hudItem.rawCount or 0) + amount local hudValue = (hudItem.rawValue or 0) + (itemValue * amount) @@ -395,7 +400,6 @@ Hud = (function() else text = formatNumber(hudCount) .. ' (' .. formatNumber(hudValue) .. ' gp)' end - hudItemUpdate(type, itemid, text, skipUpdate) end @@ -459,7 +463,7 @@ Hud = (function() -- If difference is positive and corpse open, add to totals if difference > 0 and isCorpseOpen() then -- Add to overall total - local value = (xeno.getItemValue(lootID) * difference) + local value = (getItemValue(lootID) * difference) totalQueryValue = totalQueryValue + value hudTrack('Loot', lootID, difference) end diff --git a/src/007-ini.lua b/src/007-ini.lua index 25f01ea..51927f1 100644 --- a/src/007-ini.lua +++ b/src/007-ini.lua @@ -25,7 +25,13 @@ Ini = (function() section = s tbl[section] = tbl[section] or {} end + local key, value = string.match(line, "^([^%s]+)%s+=%s+([^;]+)") + + -- If the first try didnt work, check for a multi-word key + if not key then + key, value = string.match(line, '"(.+)"%s+=%s+([^;]*)') + end if key and value then -- Type casting if tonumber(value) ~= nil then @@ -47,7 +53,7 @@ Ini = (function() if section then if not tbl[section] then tbl[section] = {} - end + end tbl[section][key] = value end end @@ -57,6 +63,66 @@ Ini = (function() return tbl end + local function loadMarketPrices() + local configName = '[OX] Prices.ini' + local configPath = FOLDER_CONFIG_PATH .. configName + local file = io.open(configPath, 'r') + + -- Found config, compare config version against embedded config + if file then + local match = false + for line in file:lines() do + if string.match(line, '^; ::' .. _script.pricesConfigHash .. '$') then + match = true + break + end + end + if not match then + log('Updating script config file...') + file:close() + file = nil + end + end + + -- Could not find a config anywhere (or we wanted to update) + if not file then + -- Write the embedded config to disk + local defaultConfig = io.open(configPath, 'w+') + if defaultConfig then + defaultConfig:write(LIB_PRICES_CONFIG) + defaultConfig:close() + else + error('Could not write default config file.') + end + + -- Try again + file = io.open(configPath, 'r') + end + + local priceConfig = loadIniFile(file) + + local prices = {} + + -- Load default prices + if priceConfig['Default'] then + for name, price in pairs(priceConfig['Default']) do + local id = xeno.getItemIDByName(name) + prices[id] = price + end + end + + -- Load and overwrite with character specific config + if priceConfig[getSelfName()] then + for name, price in pairs(priceConfig[getSelfName()]) do + local id = xeno.getItemIDByName(name) + prices[id] = price + end + end + + return prices + end + + local function updateSupplyConfig() local function loadBlockSection(sectionName, extras) local section = _config[sectionName] @@ -183,6 +249,7 @@ Ini = (function() end _config = tbl + _config['Prices'] = loadMarketPrices() updateSupplyConfig() callback() end diff --git a/tools/bundle.js b/tools/bundle.js index 0cb5d66..ba1f8db 100644 --- a/tools/bundle.js +++ b/tools/bundle.js @@ -69,101 +69,109 @@ function buildFile(spawnName, luaOutputData, outputPath, outputName, buildCallba // Load spawn config fs.readFile(`./configs/${spawnName}.ini`, function (err, configData) { - if (err) throw err; - - // Determine vocation from spawnName - let vocationName = 'unknown'; - for (let i = 0; i < vocationTags.length; i++) { - let tag = vocationTags[i]; - if (spawnName.indexOf(tag) !== -1) { - vocationName = vocationsMap[tag]; - break; - } - } - - // Build script version - let version; - if (process.env.TRAVIS_TAG) - version = process.env.TRAVIS_TAG; - else if(process.env.TRAVIS_BRANCH) - version = `${process.env.TRAVIS_BRANCH}#${process.env.TRAVIS_BUILD_NUMBER}`; - else - version = 'local'; - - // Replace tokens - const configHash = crypto.createHash('md5').update(configData).digest('hex'); - let data = luaOutputData.toString('utf8'); - - data = data.replace('{{VERSION}}', version); - data = data.replace('{{SCRIPT_TOWN}}', townName); - data = data.replace('{{SCRIPT_NAME}}', spawnName); - data = data.replace('{{SCRIPT_SLUG}}', outputName); - data = data.replace('{{SCRIPT_VOCATION}}', vocationName); - data = data.replace('{{SCRIPT_CONFIG_HASH}}', configHash); - - // Insert config - data = data.replace('{{CONFIG}}', configData.toString('utf8').replace(':::::::::::::::', `::${configHash}`)); - - // Base 64 encode lua - let encodedLua = new Buffer(data).toString('base64'); - let encodedReload = new Buffer(reloadScript).toString('base64'); - let combinedWaypoints; - let developmentXML = ` - - - - - - `; - - let productionXML = ` - - - - - `; - - // Get all the town waypoints - let townPaths = glob.sync('./waypoints/towns/*.json'), - townWaypoints = []; - - readm(townPaths, (err, towns) => { - if (err) { - throw err; - } + fs.readFile(`./configs/Prices.ini`, function (pricesErr, pricesConfigData) { + if (err || pricesErr) throw err; - // Iterate through towns - towns.forEach((waypoints) => { - let townData = JSON.parse(waypoints); - // Iterate through waypoints in each town - townData.forEach((item) => { - // Add waypoint string to array - townWaypoints.push(`\n\t\t`); - }); - }); - // Combine waypoints - townWaypoints.push('\n'); - combinedWaypoints = townWaypoints.join(''); + // Determine vocation from spawnName + let vocationName = 'unknown'; + for (let i = 0; i < vocationTags.length; i++) { + let tag = vocationTags[i]; + if (spawnName.indexOf(tag) !== -1) { + vocationName = vocationsMap[tag]; + break; + } + } - // Combine spawn file with town waypoints - let insertPoint = '' + os.EOL; - let xbstCombinedData = xbstData.toString('utf8'); - xbstCombinedData = xbstCombinedData.replace(insertPoint, insertPoint + combinedWaypoints); - - // Inject sync script for live reloading - if (process.env.LIVE_RELOAD) - xbstCombinedData += '\n' + developmentXML; - // Production lua + // Build script version + let version; + if (process.env.TRAVIS_TAG) + version = process.env.TRAVIS_TAG; + else if(process.env.TRAVIS_BRANCH) + version = `${process.env.TRAVIS_BRANCH}#${process.env.TRAVIS_BUILD_NUMBER}`; else - xbstCombinedData += '\n' + productionXML; + version = 'local'; + + // Replace tokens + const configHash = crypto.createHash('md5').update(configData).digest('hex'); + const pricesConfigHash = crypto.createHash('md5').update(pricesConfigData).digest('hex'); + let data = luaOutputData.toString('utf8'); + + data = data.replace('{{VERSION}}', version); + data = data.replace('{{SCRIPT_TOWN}}', townName); + data = data.replace('{{SCRIPT_NAME}}', spawnName); + data = data.replace('{{SCRIPT_SLUG}}', outputName); + data = data.replace('{{SCRIPT_VOCATION}}', vocationName); + data = data.replace('{{SCRIPT_CONFIG_HASH}}', configHash); + data = data.replace('{{PRICES_CONFIG_HASH}}', pricesConfigHash); + + // Insert config + data = data.replace('{{CONFIG}}', configData.toString('utf8').replace(':::::::::::::::', `::${configHash}`)); + // Insert prices config + data = data.replace('{{PRICES_CONFIG}}', pricesConfigData.toString('utf8').replace(':::::::::::::::', `::${pricesConfigHash}`)); + + // Base 64 encode lua + let encodedLua = new Buffer(data).toString('base64'); + let encodedReload = new Buffer(reloadScript).toString('base64'); + let combinedWaypoints; + + let developmentXML = ` + + + + + + `; + + let productionXML = ` + + + + + `; + + // Get all the town waypoints + let townPaths = glob.sync('./waypoints/towns/*.json'), + townWaypoints = []; + + readm(townPaths, (err, towns) => { + if (err) { + throw err; + } + + // Iterate through towns + towns.forEach((waypoints) => { + let townData = JSON.parse(waypoints); + // Iterate through waypoints in each town + townData.forEach((item) => { + // Add waypoint string to array + townWaypoints.push(`\n\t\t`); + }); + }); - // Save XBST - fs.writeFile(outputPath, xbstCombinedData, function (err) { - console.log(colors.green(spawnName), outputPath); - if (buildCallback) - buildCallback(xbstCombinedData, timestamp); + // Combine waypoints + townWaypoints.push('\n'); + combinedWaypoints = townWaypoints.join(''); + + // Combine spawn file with town waypoints + let insertPoint = '' + os.EOL; + let xbstCombinedData = xbstData.toString('utf8'); + xbstCombinedData = xbstCombinedData.replace(insertPoint, insertPoint + combinedWaypoints); + + // Inject sync script for live reloading + if (process.env.LIVE_RELOAD) + xbstCombinedData += '\n' + developmentXML; + // Production lua + else + xbstCombinedData += '\n' + productionXML; + + // Save XBST + fs.writeFile(outputPath, xbstCombinedData, function (err) { + console.log(colors.green(spawnName), outputPath); + if (buildCallback) + buildCallback(xbstCombinedData, timestamp); + }); }); }); }); From b91463e7c6cc1872a7883de85019a312e3e3c0c7 Mon Sep 17 00:00:00 2001 From: Not a name Date: Mon, 16 Nov 2015 01:12:58 +0100 Subject: [PATCH 02/10] fixed quotes in default config --- configs/Prices.ini | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 configs/Prices.ini diff --git a/configs/Prices.ini b/configs/Prices.ini new file mode 100644 index 0000000..c52e635 --- /dev/null +++ b/configs/Prices.ini @@ -0,0 +1,13 @@ +; Market prices for Official XenoBot scripts +; ::::::::::::::: + +; These prices are loaded by every char +[Default] +"ice cube" = 250 + +; These prices are loaded only if your character name is "Character One". Change the name to something approperiate. +[Character One] +"ice cube" = 250 + +[Character Two] +"ice cube" = 250 \ No newline at end of file From c63dfa32b785bc0a652190f0ac14ad0c6315b249 Mon Sep 17 00:00:00 2001 From: Not a name Date: Mon, 16 Nov 2015 01:26:40 +0100 Subject: [PATCH 03/10] fixed indendation --- src/007-ini.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/007-ini.lua b/src/007-ini.lua index 51927f1..cd12b21 100644 --- a/src/007-ini.lua +++ b/src/007-ini.lua @@ -28,10 +28,10 @@ Ini = (function() local key, value = string.match(line, "^([^%s]+)%s+=%s+([^;]+)") - -- If the first try didnt work, check for a multi-word key + -- If the first try didnt work, check for a multi-word key if not key then - key, value = string.match(line, '"(.+)"%s+=%s+([^;]*)') - end + key, value = string.match(line, '"(.+)"%s+=%s+([^;]*)') + end if key and value then -- Type casting if tonumber(value) ~= nil then @@ -53,7 +53,7 @@ Ini = (function() if section then if not tbl[section] then tbl[section] = {} - end + end tbl[section][key] = value end end @@ -337,7 +337,7 @@ Ini = (function() -- Trigger within the range ['Experience'] = function(req) if req == 0 then return false end - local min, max = parseRange(req) + local min, max = parseRange(req) local timediff = os.time() - _script.start local gain = xeno.getSelfExperience() - _script.baseExp local hourlyexp = tonumber(math.floor(gain / (timediff / 3600))) or 0 @@ -348,7 +348,7 @@ Ini = (function() -- Trigger within the range ['Profit'] = function(req) if req == 0 then return false end - local min, max = parseRange(req) + local min, max = parseRange(req) local timediff = os.time() - _script.start local totalLooted = _hud.index['Statistics']['Looted'].value local totalWaste = _hud.index['Statistics']['Wasted'].value From 7d01442a62472a4c698a70a4c1bb374ece3b9eb8 Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Mon, 16 Nov 2015 08:37:38 -0600 Subject: [PATCH 04/10] Updated Prices.ini --- configs/Prices.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/configs/Prices.ini b/configs/Prices.ini index c52e635..9404c45 100644 --- a/configs/Prices.ini +++ b/configs/Prices.ini @@ -4,10 +4,12 @@ ; These prices are loaded by every char [Default] "ice cube" = 250 +"spider silk" = 3000 -; These prices are loaded only if your character name is "Character One". Change the name to something approperiate. +; These prices are loaded only if your character name is "Character One". +; Change the name to your character name. [Character One] "ice cube" = 250 [Character Two] -"ice cube" = 250 \ No newline at end of file +"ice cube" = 250 From 03b031881223be7b654fc143520fd5bf9cd7533c Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Mon, 16 Nov 2015 08:42:35 -0600 Subject: [PATCH 05/10] Updated 007-ini.lua --- src/007-ini.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/007-ini.lua b/src/007-ini.lua index cd12b21..564f27c 100644 --- a/src/007-ini.lua +++ b/src/007-ini.lua @@ -53,7 +53,7 @@ Ini = (function() if section then if not tbl[section] then tbl[section] = {} - end + end tbl[section][key] = value end end @@ -121,7 +121,7 @@ Ini = (function() return prices end - + local function updateSupplyConfig() local function loadBlockSection(sectionName, extras) @@ -237,7 +237,7 @@ Ini = (function() tbl['Anti Lure']['Creatures'] = lureTbl else tbl['Anti Lure']['Creatures'] = { - [string.lower(lureCreatures)] = true + [string.lower(lureCreatures)] = true } end end @@ -337,7 +337,7 @@ Ini = (function() -- Trigger within the range ['Experience'] = function(req) if req == 0 then return false end - local min, max = parseRange(req) + local min, max = parseRange(req) local timediff = os.time() - _script.start local gain = xeno.getSelfExperience() - _script.baseExp local hourlyexp = tonumber(math.floor(gain / (timediff / 3600))) or 0 @@ -348,7 +348,7 @@ Ini = (function() -- Trigger within the range ['Profit'] = function(req) if req == 0 then return false end - local min, max = parseRange(req) + local min, max = parseRange(req) local timediff = os.time() - _script.start local totalLooted = _hud.index['Statistics']['Looted'].value local totalWaste = _hud.index['Statistics']['Wasted'].value From 2490f0ccf807552677fe130e396ca132b8bc62f8 Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Mon, 16 Nov 2015 10:13:52 -0600 Subject: [PATCH 06/10] Update prices.ini --- configs/Prices.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/Prices.ini b/configs/Prices.ini index 9404c45..2c4652f 100644 --- a/configs/Prices.ini +++ b/configs/Prices.ini @@ -1,4 +1,4 @@ -; Market prices for Official XenoBot scripts +; Market prices for official XenoBot scripts ; ::::::::::::::: ; These prices are loaded by every char From 1b70edc5ac90600bff919927851da1e3811d8a7d Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Mon, 16 Nov 2015 10:22:02 -0600 Subject: [PATCH 07/10] Updated 007-ini.lua --- src/007-ini.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/007-ini.lua b/src/007-ini.lua index 564f27c..1329785 100644 --- a/src/007-ini.lua +++ b/src/007-ini.lua @@ -64,9 +64,7 @@ Ini = (function() end local function loadMarketPrices() - local configName = '[OX] Prices.ini' - local configPath = FOLDER_CONFIG_PATH .. configName - local file = io.open(configPath, 'r') + local file = io.open(MASTER_PRICES_CONFIG_PATH, 'r') -- Found config, compare config version against embedded config if file then @@ -82,10 +80,9 @@ Ini = (function() file:close() file = nil end - end -- Could not find a config anywhere (or we wanted to update) - if not file then + else -- Write the embedded config to disk local defaultConfig = io.open(configPath, 'w+') if defaultConfig then @@ -100,7 +97,6 @@ Ini = (function() end local priceConfig = loadIniFile(file) - local prices = {} -- Load default prices From 8c08c487d96f077ee7c6f65731d7be58f292e258 Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Mon, 16 Nov 2015 10:35:39 -0600 Subject: [PATCH 08/10] Update 007-ini.lua --- src/007-ini.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/007-ini.lua b/src/007-ini.lua index 1329785..26810da 100644 --- a/src/007-ini.lua +++ b/src/007-ini.lua @@ -64,7 +64,7 @@ Ini = (function() end local function loadMarketPrices() - local file = io.open(MASTER_PRICES_CONFIG_PATH, 'r') + local file = io.open(PRICES_CONFIG_PATH, 'r') -- Found config, compare config version against embedded config if file then From 3c384216eaba88c8d1085759c34be7d9d5cc0f95 Mon Sep 17 00:00:00 2001 From: Not a name Date: Mon, 16 Nov 2015 22:20:40 +0100 Subject: [PATCH 09/10] corym targeting settings --- waypoints/Venore East Coryms (EK).xbst | 5 +++-- waypoints/Venore North Coryms (EK).xbst | 5 +++-- waypoints/Venore South Coryms (EK).xbst | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/waypoints/Venore East Coryms (EK).xbst b/waypoints/Venore East Coryms (EK).xbst index 9e52190..2738855 100644 --- a/waypoints/Venore East Coryms (EK).xbst +++ b/waypoints/Venore East Coryms (EK).xbst @@ -58,8 +58,9 @@ - - + + + diff --git a/waypoints/Venore North Coryms (EK).xbst b/waypoints/Venore North Coryms (EK).xbst index 64f9896..79e2e77 100644 --- a/waypoints/Venore North Coryms (EK).xbst +++ b/waypoints/Venore North Coryms (EK).xbst @@ -58,8 +58,9 @@ - - + + + diff --git a/waypoints/Venore South Coryms (EK).xbst b/waypoints/Venore South Coryms (EK).xbst index cabad44..e8f3a67 100644 --- a/waypoints/Venore South Coryms (EK).xbst +++ b/waypoints/Venore South Coryms (EK).xbst @@ -58,8 +58,9 @@ - - + + + From 5bfd2a6bc335458951ace0978b91621e46732e37 Mon Sep 17 00:00:00 2001 From: Joshua Kelly Date: Tue, 17 Nov 2015 13:14:44 -0600 Subject: [PATCH 10/10] Update Prices.ini --- configs/Prices.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configs/Prices.ini b/configs/Prices.ini index 2c4652f..0ee619d 100644 --- a/configs/Prices.ini +++ b/configs/Prices.ini @@ -3,13 +3,13 @@ ; These prices are loaded by every char [Default] -"ice cube" = 250 -"spider silk" = 3000 +"golden helmet" = 250 +"dragon scale legs" = 3000 ; These prices are loaded only if your character name is "Character One". ; Change the name to your character name. [Character One] -"ice cube" = 250 +"longsword" = 25 [Character Two] -"ice cube" = 250 +"pickaxe" = 2