SnP helper

By kabji Last update Jun 6, 2009 — Installed 87,058 times.

i have translated in french

in
Subscribe to i have translated in french 7 posts, 2 voices



la faucille Scriptwright

hi

ths for your good idea.

i have translated in french

how i can communicate the french version to you?

may i post on this website with link to your script ?

 
kabji Script's Author

I will work on to add multi-language cability to my script in next version.

 
la faucille Scriptwright

here is the script translated:

// ==UserScript==
// @name SnP Helper (Spy and Pillage Helper)
// @namespace ikariam
// @description Add caculate ship amount to spy warehouse report
// @include http://*.ikariam.*/*
// @exclude http://board.ikariam.*/*
// ==/UserScript==

var woodAmt = 0;
var wineAmt = 0;
var marbleAmt = 0;
var crystalAmt = 0;
var sulphurAmt = 0;
var totalAmt = 0;
var lootableAmt = 0;

//b= wood
//w=wines
//m=marble
//c=crystal
//s=sulphur
var data = {
"warehouse": [
{ b: 0, w: 0, m: 0, c: 0, s: 0 }, // 0
{ b: 260, w: 130, m: 130, c: 130, s: 130 }, // 1
{ b: 420, w: 210, m: 210, c: 210, s: 210 }, // 2
{ b: 580, w: 290, m: 290, c: 290, s: 290 }, // 3
{ b: 740, w: 370, m: 370, c: 370, s: 370 }, // 4
{ b: 900, w: 450, m: 450, c: 450, s: 450 }, // 5
{ b: 1060, w: 530, m: 530, c: 530, s: 530 }, // 6
{ b: 1220, w: 610, m: 610, c: 610, s: 610 }, // 7
{ b: 1380, w: 690, m: 690, c: 690, s: 690 }, // 8
{ b: 1540, w: 770, m: 770, c: 770, s: 770 }, // 9
{ b: 1700, w: 850, m: 850, c: 850, s: 850 }, // 10
{ b: 1860, w: 930, m: 930, c: 930, s: 930 }, // 11
{ b: 2020, w: 1010, m: 1010, c: 1010, s: 1010 }, // 12
{ b: 2180, w: 1090, m: 1090, c: 1090, s: 1090 }, // 13
{ b: 2340, w: 1170, m: 1170, c: 1170, s: 1170 }, // 14
{ b: 2500, w: 1250, m: 1250, c: 1250, s: 1250 }, // 15
{ b: 2660, w: 1330, m: 1330, c: 1330, s: 1330 }, // 16
{ b: 2820, w: 1410, m: 1410, c: 1410, s: 1410 }, // 17
{ b: 2980, w: 1490, m: 1490, c: 1490, s: 1490 }, // 18
{ b: 3140, w: 1570, m: 1570, c: 1570, s: 1570 }, // 19
{ b: 3300, w: 1650, m: 1650, c: 1650, s: 1650 }, // 20
{ b: 3460, w: 1730, m: 1730, c: 1730, s: 1730 }, // 21
{ b: 3620, w: 1810, m: 1810, c: 1810, s: 1810 }, // 22
{ b: 3780, w: 1890, m: 1890, c: 1890, s: 1890 }, // 23
{ b: 3940, w: 1970, m: 1970, c: 1970, s: 1970 }, // 24
{ b: 4100, w: 2050, m: 2050, c: 2050, s: 2050 }, // 25
{ b: 4260, w: 2130, m: 2130, c: 2130, s: 2130 }, // 26
{ b: 4420, w: 2210, m: 2210, c: 2210, s: 2210 }, // 27
{ b: 4580, w: 2290, m: 2290, c: 2290, s: 2290 }, // 28
{ b: 4740, w: 2370, m: 2370, c: 2370, s: 2370 }, // 29
{ b: 4900, w: 2450, m: 2450, c: 2450, s: 2450 }, // 30
{ b: 5060, w: 2530, m: 2530, c: 2530, s: 2530 } // 31
]
};

getElementsByClass = function(inElement, className, findIn)
{
var all = inElement.getElementsByTagName('*');
var elements = [];
for (var e = 0; e < all.length; e++)
{
if (findIn == true)
{
if (all[e].className.indexOf(className) > 0)
{
elements[elements.length] = all[e];
}
} else {
if (all[e].className == className)
{
elements[elements.length] = all[e];
}
}
}
return elements;
};

function getUnFormatNumberBy3(num) {
var z = num.replace(/(\,)/g, "");
return z;
}

function getFormatNumberBy3(num, decpoint, sep, isFillFraction, fraction_len, zeroAllow) {
// check for missing parameters and use defaults if so
if (arguments.length < 2) {
sep = ",";
decpoint = ".";
}
if (arguments.length < 3) {
sep = ",";
}
if (arguments.length < 4) {
isFillFraction = false;
}
if (arguments.length < 5) {
fraction_len = 0;
}
if (arguments.length < 6) {
zeroAllow = false;
}

// need a string for operations
num = num.toString();
if (num.indexOf(".") < 0) {
num = num + decpoint;
}

// separate the whole number and the fraction if possible
var a = num.split(decpoint);
// decimal
var x = a[0];
// fraction
var y = a[1];
if (isFillFraction) {
var padLen = 0;
if (y != null) {
padLen = fraction_len - y.length;
}
for (var j = 0; j < padLen; j++) {
y = y + '0';
}
}

var rexNumeric = /[0-9]/i;
var strSign = "";
if (x.length > 0) {
strSign = x.substring(0, 1);
if (!rexNumeric.test(strSign)) {
x = x.substring(1, x.length);
} else {
strSign = "";
}
}

var z = "";
var result = "";

if (typeof(x) != "undefined") {
for (i = x.length - 1; i >= 0; i--)
z += x.charAt(i) != sep?x.charAt(i):'';

z = z.replace(/(\d{3})/g, "$1" + sep);
if (z.slice(-sep.length) == sep)
z = z.slice(0, -sep.length);
result = "";
for (i = z.length - 1; i >= 0; i--)
result += z.charAt(i);
if (typeof(y) != "undefined" && y.length > 0) {
result = result + decpoint + y;
}
}
if (result.charAt(0) == '.') {
result = '0' + result;
}
if (eval(getUnFormatNumberBy3(result) * 1) == 0) {
if (!zeroAllow) {
result = '';
}
}
result = strSign + result;
return result;
}

function calculateTotalAmt()
{
var resourcesTable = document.getElementById('resources');

if(resourcesTable)
{
var listElements = resourcesTable.getElementsByTagName('tr');

for (var i = 1; i < listElements.length; i++)
{
if(listElements[i].innerHTML.indexOf('Matériau de construction') > 0)
{
//alert('Wood');
var res = getElementsByClass(listElements[i], "count", false);
woodAmt = parseInt(res[0].innerHTML.replace(/,/g,''));
}
else if(listElements[i].innerHTML.indexOf('Vin') > 0)
{
//alert('Wine');
var res = getElementsByClass(listElements[i], "count", false);
wineAmt = parseInt(res[0].innerHTML.replace(/,/g,''));
}
else if(listElements[i].innerHTML.indexOf('Marbre') > 0)
{
//alert('Marble');
var res = getElementsByClass(listElements[i], "count", false);
marbleAmt = parseInt(res[0].innerHTML.replace(/,/g,''));
}
else if(listElements[i].innerHTML.indexOf('Verre de cristal') > 0)
{
//alert('Crystal Glass');
var res = getElementsByClass(listElements[i], "count", false);
crystalAmt = parseInt(res[0].innerHTML.replace(/,/g,''));
}
else if(listElements[i].innerHTML.indexOf('Soufre') > 0)
{
//alert('Sulphur');
var res = getElementsByClass(listElements[i], "count", false);
sulphurAmt = parseInt(res[0].innerHTML.replace(/,/g,''));
}
}

totalAmt = woodAmt+wineAmt+marbleAmt+crystalAmt+sulphurAmt;

//alert('Woods:'+woodAmt);
//alert('Wine:'+wineAmt);
//alert('marble:'+marbleAmt);
//alert('crystal:'+crystalAmt);
//alert('sulphur:'+sulphurAmt);
//alert('total:'+totalAmt);
}
}

function isTargetPage()
{
var resourcesTable = document.getElementById('resources');
if(resourcesTable)
{
return true;
}else
{
return false;
}
}

function showTotal()
{
var tbodys = document.getElementsByTagName('tbody');

// Total
totalElement = document.createElement("tr");
td1 = document.createElement("td");
td1.setAttribute("class","job");
td1.innerHTML = 'Ressources totales:';

td2 = document.createElement("td");
td2.innerHTML = getFormatNumberBy3(totalAmt, ".", ",", false, 0, true);

totalElement.appendChild(td1);
totalElement.appendChild(td2);

//Warehouse Level
levelElement = document.createElement("tr");
td1 = document.createElement("td");
td1.setAttribute("class","job");
td1.innerHTML = 'Niveau d entrepôt:';

td2 = document.createElement("td");
var wareDiv = <>
<input /> (nombre seulement)
</>;
td2.innerHTML = wareDiv;
td2.addEventListener("change",calculateShip,false);

levelElement.appendChild(td1);
levelElement.appendChild(td2);

// Lootable Amount
lootElement = document.createElement("tr");
td1 = document.createElement("td");
td1.setAttribute("class","job");
td1.innerHTML = 'Pillable:';

td2 = document.createElement("td");
td2.setAttribute("id","lootableId");
td2.innerHTML = '0';

lootElement.appendChild(td1);
lootElement.appendChild(td2);

// Ship Amount
shipElement = document.createElement("tr");
td1 = document.createElement("td");
td1.setAttribute("class","job");
td1.innerHTML = 'Nbr. de bateaux:';

td2 = document.createElement("td");
td2.setAttribute("id","shipId");
td2.innerHTML = '0';

shipElement.appendChild(td1);
shipElement.appendChild(td2);

// Enjoy!!
enjoyElement = document.createElement("tr");
td1 = document.createElement("td");
td1.setAttribute("class","job");
td1.innerHTML = '';

td2 = document.createElement("td");
td2.innerHTML = 'Raider bien ^_^ (adapté à Ikariam.fr)';

enjoyElement.appendChild(td1);
enjoyElement.appendChild(td2);

tbodys[0].appendChild(totalElement);
tbodys[0].appendChild(levelElement);
tbodys[0].appendChild(lootElement);
tbodys[0].appendChild(shipElement);
tbodys[0].appendChild(enjoyElement);
}

function validateInput()
{
//validate input
var level = document.getElementById('warehouseLevelId');

if(isNaN(level.value))
{
alert('SVP, n entrer que des valeurs');
level.value='0';
level.focus();
return false;
}else
{
if(parseInt(level.value) > 31 || parseInt(level.value) < 0)
{
alert('SVP, n entrer que des valeurs entre(0-31)');
level.value='0';
level.focus();
return false;
}
}

return true;
}

function calculateShip()
{
if(!validateInput())
{
document.getElementById('warehouseLevelId').value = '0';
}

//find safe amt
var level = document.getElementById('warehouseLevelId');
if (typeof(data['warehouse'][level.value]) != "undefined") {

var b = data['warehouse'][level.value].b;
var w = data['warehouse'][level.value].w;
var m = data['warehouse'][level.value].m;
var c = data['warehouse'][level.value].c;
var s = data['warehouse'][level.value].s;

b = woodAmt - b;
w = wineAmt - w;
m = marbleAmt - m;
c = crystalAmt - c;
s = sulphurAmt - s;

if(b < 0) b = 0;
if(w < 0) w = 0;
if(m < 0) m = 0;
if(c < 0) c = 0;
if(s < 0) s = 0;

lootableAmt = b + w + m + c + s;

}

document.getElementById('lootableId').innerHTML = getFormatNumberBy3(lootableAmt, ".", ",", false, 0, true);

// cal ship
document.getElementById('shipId').innerHTML = Math.ceil(lootableAmt / 500);

}

function snpInit()
{
if(isTargetPage())
{
//Calculate Amount
calculateTotalAmt();

//Insert Result
showTotal();

//Caculate Ship and lootable amt
calculateShip();
}
}

snpInit();

 
kabji Script's Author

I change logic in query for resource amount to not rely on any languages.

Please test my new version, Is it worked on your server?

 
la faucille Scriptwright

i just tested and its ok on ikariam.fr

thks ;)

i suggest to keep in memory the last warehouse level for each "name of town" and "player"
to accelerate the first check of good target.

i know is heavy but usely

 
kabji Script's Author

Good idea. Thanks.

City ID is a unique key and GreaseMonkey have getter and setter.

 
la faucille Scriptwright

go go go on your computer and do a great script for the raider

maybe you can change the name and choose a name like : pro looting or raider looter pro... or fast looting

but a big thank to help my mind (i'm lazy to count) lol

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel