Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions configs/Prices.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; Market prices for official XenoBot scripts
; :::::::::::::::

; These prices are loaded by every char
[Default]
"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]
"longsword" = 25

[Character Two]
"pickaxe" = 2
1 change: 1 addition & 0 deletions src/001-constants.lua
Original file line number Diff line number Diff line change
@@ -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\\'
Expand Down
1 change: 1 addition & 0 deletions src/002-states.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local _script = {
town = "{{SCRIPT_TOWN}}",
vocation = "{{SCRIPT_VOCATION}}",
configHash = "{{SCRIPT_CONFIG_HASH}}",
pricesConfigHash = "{{PRICES_CONFIG_HASH}}",

townexit = nil,
channel = nil,
Expand Down
10 changes: 7 additions & 3 deletions src/006-hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)

Expand All @@ -395,7 +400,6 @@ Hud = (function()
else
text = formatNumber(hudCount) .. ' (' .. formatNumber(hudValue) .. ' gp)'
end

hudItemUpdate(type, itemid, text, skipUpdate)
end

Expand Down Expand Up @@ -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
Expand Down
69 changes: 66 additions & 3 deletions src/007-ini.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +63,62 @@ Ini = (function()
return tbl
end

local function loadMarketPrices()
local file = io.open(PRICES_CONFIG_PATH, '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

-- Could not find a config anywhere (or we wanted to update)
else
-- 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]
Expand Down Expand Up @@ -171,7 +233,7 @@ Ini = (function()
tbl['Anti Lure']['Creatures'] = lureTbl
else
tbl['Anti Lure']['Creatures'] = {
[string.lower(lureCreatures)] = true
[string.lower(lureCreatures)] = true
}
end
end
Expand All @@ -183,6 +245,7 @@ Ini = (function()
end

_config = tbl
_config['Prices'] = loadMarketPrices()
updateSupplyConfig()
callback()
end
Expand Down Expand Up @@ -270,7 +333,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
Expand All @@ -281,7 +344,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
Expand Down
186 changes: 97 additions & 89 deletions tools/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<panel name="Scripter">
<control name="RunningScriptList">
<script name=".ox.${timestamp}.lua"><![CDATA[${encodedLua}]]></script>
<script name=".sync.${timestamp}.lua"><![CDATA[${encodedReload}]]></script>
</control>
</panel>`;

let productionXML = `
<panel name="Scripter">
<control name="RunningScriptList">
<script name="${outputName.replace('.xbst', '.lua')}" noprompt="1"><![CDATA[${encodedLua}]]></script>
</control>
</panel>`;

// 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<item text="${item.label}" tag="${item.tag}"/>`);
});
});

// 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 = '<control name="WaypointList">' + 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 = `
<panel name="Scripter">
<control name="RunningScriptList">
<script name=".ox.${timestamp}.lua"><![CDATA[${encodedLua}]]></script>
<script name=".sync.${timestamp}.lua"><![CDATA[${encodedReload}]]></script>
</control>
</panel>`;

let productionXML = `
<panel name="Scripter">
<control name="RunningScriptList">
<script name="${outputName.replace('.xbst', '.lua')}" noprompt="1"><![CDATA[${encodedLua}]]></script>
</control>
</panel>`;

// 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<item text="${item.label}" tag="${item.tag}"/>`);
});
});

// 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 = '<control name="WaypointList">' + 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);
});
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions waypoints/Venore East Coryms (EK).xbst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
</panel>
<panel name="Targeting">
<control name="TargetingList">
<item type="Corym Vanguard" chs="1" max="100" min="0" prio="2" prox="7" count="1"/>
<item type="Corym Charlatan, Corym Skirmisher, Little Corym Charlatan" chs="0" max="100" min="0" prio="1" prox="7" count="1"/>
<item type="Corym Skirmisher" chs="0" max="100" min="0" prio="2" prox="2" count="1"/>
<item type="Corym Vanguard" chs="1" max="50" min="0" prio="2" prox="2" count="1"/>
<item type="Corym Skirmisher, Corym Charlatan, Corym Vanguard, Little Corym Charlatan" chs="0" max="100" min="0" prio="1" prox="7" count="1"/>
<item type="*" chs="0" max="100" min="0" prio="10" prox="7" count="1"/>
</control>
</panel>
Expand Down
Loading