javascript:
// Sample template (can add/remove troops)
// Fills in only availabale troops so works both for def/off villages
var scavengeOptions = {
'Great Gatherers': [
{ type: 'spear', count: 10 },
{ type: 'sword', count: 10 },
{ type: 'axe', count: 10 },
{ type: 'light', count: 3 },
],
'Clever Collectors': [
{ type: 'spear', count: 10 },
{ type: 'sword', count: 10 },
{ type: 'axe', count: 10 },
{ type: 'light', count: 3 },
],
'Humble Haulers': [
{ type: 'spear', count: 10 },
{ type: 'sword', count: 10 },
{ type: 'axe', count: 10 },
{ type: 'light', count: 3 },
],
'Lackadaisical Looters': [
{ type: 'spear', count: 10 },
{ type: 'sword', count: 10 },
{ type: 'axe', count: 10 },
{ type: 'light', count: 3 },
],
};
var unitsCapacity = {
'spear': 25, 'sword': 15, 'archer': 10, 'axe': 10,
'heavy': 50, 'light': 80, 'marcher': 50, 'knight': 100
}
checkCorrectPage();
run();
function run() {
let btn = null;
for (const option in scavengeOptions) {
btn = findNextButton(option);
if (btn) {
fillInTroops(option, getAvailableUnits(), btn);
break;
}
}
}
function fillInTroops(option, availableUnits, button) {
scavengeOptions[option].forEach(units => {
const type = units.type;
const count = units.count;
let requiredCapacity = availableUnits[type] < count ? availableUnits[type] : count;
$(`input.unitsInput[name='${type}']`).val(requiredCapacity).trigger("change");
$(button).focus();
});
}
function findNextButton(option) {
let btn = $(`.scavenge-option:contains("${option}")`).find('a:contains("Start")');
if (btn.length > 0 && !$(btn).hasClass('btn-disabled')) return btn;
}
function getAvailableUnits() {
let availableUnits = {};
$('.units-entry-all').each((i, e) => {
const unitName = $(e).attr("data-unit");
const count = $(e).text().replace(/[()]/, '');
availableUnits[unitName] = parseInt(count);
});
return availableUnits;
}
function checkCorrectPage() {
const doc = document;
if (window.frames.length > 0 && window.main != null) doc = window.main.document;
const url = doc.URL;
if (url.indexOf('screen=place&mode=scavenge') == -1) alert('Use the script in the Rally point - Scavenging page!');
}