// ==UserScript==
// @name zbiorkowy
// @description Automat do zbiórek MON
// @namespace soowal
// @include http://*.erepublik.com/*
// @include https://*.erepublik.com/*
// @exclude *cometchat*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @require https://greasyfork.org/scripts/3865-block/code/block.js?version=12027
// @version 1.05
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_xmlhttpRequest
// @grant GM_info
// @grant unsafeWindow
// ==/UserScript==
var engine = {
prefix : 'zbiorkowy_',
timer : null,
started : false,
timer2 : null,
counthitsen : 0,
cloneopt : {cloneFunctions: true, wrapReflectors: true},
background: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAYAAADL1t+KAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L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OgAgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahi4BABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQOAoQMAhg4AGDoAYOgAYOgAgKEDAIYOABg6ABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQOAoQMAhg4AGDoAYOgAYOgAgKEDAIYOABg6ABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQOAoQMAhg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYugQAYOgAgKEDAIYOABg6ABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQOAoQMAhg4AGDoAYOgAYOgAgKEDAIYOABg6ABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQOAoQMAhg4AGDoAYOgAYOgAgKEDAIYOABg6ABg6AGDoAIChAwCGDgCGDgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AGDoAGDoAIChAwCGDgAYOgAYOgBg6ACAoQMAhg4Ahg4AGDoAYOgAgKEDgKEDAIYOABg6AHCzAAAA//8DAIOSBIHyPvxdAAAAAElFTkSuQmCC',
addonurl: 'https://greasyfork.org/scripts/3270-zbiorkowy',
resethits : function()
{
GM_setValue(engine.prefix+'hits', 0);
},
checkVersion : function()
{
var last = GM_getValue(this.prefix+'checkversion', 0);
var now = new Date();
now = Math.floor(now.getTime() / 1000);
var diff = now - last;
if(diff > 3600)
{
GM_xmlhttpRequest({
method: "GET",
url: engine.addonurl,
headers: {
"Accept": "text/html"
},
onload: function(response)
{
var ver = $('dd.script-show-version', response.responseText);
if(!ver || !ver.html) return;
var verstr = ver.html().replace(/[\r \t\n]/g, '');
GM_setValue(engine.prefix+'newestversion', verstr);
}
});
GM_setValue(engine.prefix+'checkversion', now);
}
var version = GM_info.script.version;
var newest = GM_getValue(engine.prefix+'newestversion', '');
if(newest != '' && version * 1 < newest * 1)
{
var code = '<div style="background: #8b2d21; border: 2px #2e170f solid; border-left: 0px; border-right: 0px; margin-bottom: 3px; text-align: center; padding: 10px; font-size: 16px; color: white; cursor: pointer;" onclick="window.location=\''+engine.addonurl+'\'">Dostępna nowa wersja automatu zbiórkowego MON</div>';
$('#content').prepend(code);
}
},
adaptHits : function()
{
var wrote = parseInt($('#hityinput').val(), 10);
if(isNaN(wrote)) wrote = 0;
GM_setValue(engine.prefix+'hits', GM_getValue(engine.prefix+'hits', 0) + wrote);
$('#hityinput').val('');
},
getfirepower : function(link, my)
{
var q = 0;
if(link.indexOf('q1.') > 0) q = 20;
else if(link.indexOf('q2.') > 0) q = 40;
else if(link.indexOf('q3.') > 0) q = 60;
else if(link.indexOf('q4.') > 0) q = 80;
else if(link.indexOf('q5.') > 0) q = 100;
else if(link.indexOf('q6.') > 0) q = 120;
else if(link.indexOf('q7.') > 0) q = 200;
else if(link.indexOf('q10.') > 0 || link.indexOf('q10_') > 0) q = my ? -1 : 100;
return q;
},
calchits : function()
{
var enweapon = engine.getfirepower($("#enemy_weapon").attr('src'), false);
var myweapon = engine.getfirepower($('#scroller img').last().attr('src'), true);
var enstr = parseInt($('#enemy_skill').html().replace(/,/g, ''), 10);
var mystr = parseInt($('#fighter_skill').html().replace(/,/g, ''), 10);
var enhp = $('#enemy_life').attr('original-title') || $('#enemy_life').attr('title');
enhp = parseInt(enhp.substring(enhp.lastIndexOf(' ') + 1), 10);
var damage = Math.ceil((60 + ((mystr-enstr)/10)) * (1 + (myweapon-enweapon)/400) / 2 - 0.5);
var hits = Math.ceil(enhp / damage);
if(myweapon == -1) hits = 1;
return hits;
},
fight : function()
{
if(!engine.started) return;
var left = GM_getValue(engine.prefix+'hits', 0);
var hits = engine.calchits();
var hppoints = unsafeWindow.erepublik.citizen.energy;
if(left < hits)
{
engine.stopfightlayer();
return;
}
if(hppoints < 10 || hppoints / 10 < hits)
{
if($('#DailyConsumtionTrigger').hasClass('energy'))
{
engine.stopfightlayer();
return;
}
else
{
unsafeWindow.smallestFood.use = 1;
unsafeWindow.energy.eatFood();
return;
}
}
if($('#loader').is(':visible')) return;
unsafeWindow.shoot();
},
startfight : function()
{
engine.started = true;
engine.timer = setInterval(function() { engine.fight(); }, 1200);
engine.fight();
},
refresh : function()
{
$('#hity_zapas').html(GM_getValue(engine.prefix+'hits', 0));
},
stopfight : function()
{
engine.started = false;
clearTimeout(engine.timer);
},
stopfightlayer : function()
{
$('#cancelfight').hide();
$('#fighthity').show();
engine.stopfight();
engine.refresh();
},
addhits : function(num)
{
setTimeout(function()
{
var left = GM_getValue(engine.prefix+'hits', 0) - num;
GM_setValue(engine.prefix+'hits', Math.max(0,left));
engine.refresh();
}, 0);
},
modifiedFunction : function(data, status, jq)
{
if(jq.url.indexOf('military/fight-shoo') > -1)
{
var text = status.responseText;
var json = JSON.parse(text);
if(!json.error && (json.message == "ENEMY_KILLED" || json.message == "OK"))
{
var hits = json.user.earnedXp;
engine.addhits(hits);
if(engine.iscounthits()) engine.addcounthits(hits);
}
else
{
//engine.stopfightlayer();
}
}
},
modifyfunction : function()
{
register_event('zbiorkowy_myevent', function() { engine.modifiedFunction(unsafeWindow.zbiorkowy_myevent_data.data, unsafeWindow.zbiorkowy_myevent_data.status, unsafeWindow.zbiorkowy_myevent_data.jq); }, function()
{
window.$j(document).ajaxSuccess(function(data, status, jq)
{
window.zbiorkowy_myevent_data = {data : data, status : status, jq : jq};
var event = document.createEvent("Event");
event.initEvent("zbiorkowy_myevent", true, true);
document.dispatchEvent(event);
}
);
}
);
},
iscounthits : function()
{
return engine.counthitsen;
},
iscounthitsbase : function()
{
return GM_getValue(engine.prefix+'counthits', 0);
},
startcounthits : function()
{
GM_setValue(engine.prefix+'counthits', 1);
engine.counthitsen = 1;
$('#zbiorkaoff').show();
$('#zbiorkaon').hide();
if(engine.timer2 != null) clearTimeout(engine.timer2);
engine.timer2 = setInterval(function(){ engine.counthitsrefresh(); }, 100);
},
stopcounthits : function()
{
GM_setValue(engine.prefix+'counthits', 0);
engine.counthitsen = 0;
$('#zbiorkaon').show();
$('#zbiorkaoff').hide();
if(engine.timer2 != null) clearTimeout(engine.timer2);
engine.counthitsrefresh();
},
addcounthits : function(c)
{
setTimeout(function(){ GM_setValue(engine.prefix+'counterhits', GM_getValue(engine.prefix+'counterhits', 0) + c); }, 0);
},
resetcounthits : function()
{
GM_setValue(engine.prefix+'counterhits', 0);
engine.counthitsrefresh();
},
counthitsrefresh : function()
{
var text = GM_getValue(engine.prefix+'counterhits', 0)+''
if(!engine.iscounthits()) text = '<span style="color: #cccccc;">'+text+'</span>';
$('#hity_zbiorka').html(text);
},
init : function()
{
this.checkVersion();
if(window.location.toString().indexOf('military/battlefield/') > 0 && $('#fight_btn').is(':visible'))
{
var text = '<div style="width: 200px; line-height: 1.6em; color: white; background: url(\''+engine.background+'\'); border: 0px; -webkit-border-radius: 5px; -moz-border-radius: 5px; z-index: 100; border-radius: 5px; position: absolute; box-shadow: 0px 0px 10px #000000; top: 321px; left: 282px; text-align: center; font-size: 11px;"><div style="padding: 5px;">';
text += 'Hity: <input type="text" id="hityinput" value="" style="font-size: 11px; color: black; background: white; border: 1px solid black; width: 26px; padding: 1px 0px; text-align: center;" maxlength="4" /> <input type="submit" value="Fight" id="fighthity" style="padding: 0px; font-size: 11px;" /><input type="submit" value="Stop" id="cancelfight" style="padding: 0px; font-size: 11px;" />';
text += ' Zostało: <b id="hity_zapas">0</b> <a href="javascript:void(0);" style="color: #ff4444; font-size: 10px;" id="resethity">reset</a>';
text += '<br />Suma hitów: <b id="hity_zbiorka">0</b> <a href="javascript:void(0);" style="color: #44ff44; font-size: 10px;" id="zbiorkaon">zliczaj</a><a href="javascript:void(0);" style="color: #ff4444; font-size: 10px;" id="zbiorkaoff">nie licz</a> <span style="font-size: 10px; color: #999999;">|</span> <a href="javascript:void(0);" style="color: #ff4444; font-size: 10px;" id="resethity2">reset</a>';
text += '</div></div>';
$('#pvp').append(text);
$('#cancelfight').hide();
$('#zbiorkaoff').hide();
engine.counthitsrefresh();
if(engine.iscounthitsbase())
{
engine.startcounthits();
}
$('#zbiorkaon').mousedown(function(e)
{
engine.startcounthits();
return false;
});
$('#zbiorkaoff').mousedown(function(e)
{
engine.stopcounthits();
return false;
});
$('#resethity2').mousedown(function(e)
{
engine.resetcounthits();
return false;
});
$('#resethity').mousedown(function(e)
{
engine.resethits();
engine.refresh();
return false;
});
$('#cancelfight').mousedown(function(e)
{
engine.stopfightlayer();
return false;
});
$('#fighthity').mousedown(function(e)
{
$('#cancelfight').show();
$('#fighthity').hide();
engine.adaptHits();
engine.startfight();
engine.refresh();
return false;
});
engine.refresh();
engine.modifyfunction();
}
}
};
$(unsafeWindow.document).ready(function()
{
engine.init();
});