').appendTo('body');
$('#unit_box a').css({
float: 'left',
backgroundRepeat: 'no-repeat',
backgroundSize: '25px',
lineHeight: '2',
marginRight:'10px'
});
$('#unit_box span').css({
marginLeft: '27px',
});
$('#unit_box').draggable({
containment: "body",
snap: "body",
});
$('#unit_box').css({
position: 'absolute',
top: '100px',
left: '200px',
zIndex: getMaxZIndex() + 1,
display: 'none'
});
$('#unit_box .box_content').css({
background: 'url(http://s1.directupload.net/images/140206/8jd9d3ec.png) 94% 94% no-repeat',
backgroundSize: '140px'
});
$('#unit_box').bind("mousedown",function(){
$(this).get(0).style.zIndex = getMaxZIndex() + 1;
});
addComparisonTable("hack");
addComparisonTable("pierce");
addComparisonTable("distance");
addComparisonTable("ship");
$('#unit_box .t_hack').get(0).style.display = "block";
switchComparisonTables();
$('#unit_box hr').css({ border: '1px solid', color: '#804000', float:'none' });
}
function switchComparisonTables(){
$('#unit_box .hack, #unit_box .pierce, #unit_box .distance, #unit_box .ship').click(function(){
$('#unit_box [class^="t_"]').css({ display : "none" });
$('#unit_box .t_'+this.className).get(0).style.display = "block";
});
}
var ttpArray = [], t = 0;
function addComparisonTable(type){
var pos = {
att: { hack: "36%", pierce: "27%", distance: "45.5%", ship: "72.5%" },
def: { hack: "18%", pierce: "18%", distance: "18%", ship: "81.5%" }
};
var unitIMG = "http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png";
var strArray = [
"
'
];
for(var e in unitVal){
if(unitVal.hasOwnProperty(e)){
var valArray = [];
if(type === (unitVal[e].attack_type || "ship") && (e !== "militia")) {
valArray.att = Math.round(unitVal[e].attack*10 / unitVal[e].population) / 10;
valArray.def = Math.round(((unitVal[e].def_hack + unitVal[e].def_pierce + unitVal[e].def_distance)*10)/(3*unitVal[e].population)) / 10;
valArray.def = valArray.def || Math.round(unitVal[e].defense*10/unitVal[e].population) / 10;
valArray.speed = unitVal[e].speed;
valArray.booty = Math.round(((unitVal[e].booty)*10) / unitVal[e].population) / 10;
valArray.booty = valArray.booty || Math.round(((unitVal[e].capacity ? unitVal[e].capacity + 6 : 0)*10) / unitVal[e].population) / 10;
valArray.favor = Math.round((unitVal[e].favor *10)/ unitVal[e].population) / 10;
valArray.res = Math.round((unitVal[e].resources.wood + unitVal[e].resources.stone + unitVal[e].resources.iron)/(unitVal[e].population));
valArray.time = Math.round(unitVal[e].build_time / unitVal[e].population);
valArray.hero = (!uw.Game.is_hero_world && ((e === "griffin") || (e === "calydonian_boar")))? "-webkit-filter:grayscale(100%); filter: url(#GrayScale)": "";
strArray[0] += '
';
ttpArray[t] = unitVal[e].name; t++;
}
}
}
$('
').appendTo('#unit_box .box_content');
for(var i = 0; i <= t; i++){
$('.un'+i).tooltip(ttpArray[i]);
}
$('.tr_att').tooltip(LANG[LID].com.att);
$('.tr_def').tooltip(LANG[LID].com.def + " (Ø)");
$('.tr_spd').tooltip(LANG[LID].com.spd);
$('.tr_bty_'+ type).tooltip(((type!=="ship")? LANG[LID].com.bty : LANG[LID].com.cap));
$('.tr_res').tooltip(LANG[LID].com.res);
$('.tr_fav').tooltip(LANG[LID].com.fav);
$('.tr_tim').tooltip(LANG[LID].com.tim);
//$('#unit_box .box_content').css({ position: 'relative' });
$('#unit_box .bla').css({
height: '25px',
width: '25px',
backgroundSize: '100%',
float: 'left'
});
$('#unit_box .booty').css({
width: '25px',
height: '25px',
background: 'url(http://de.cdn.grepolis.com/images/game/layout/layout_2.56_compressed.png)',
backgroundSize: '3400%',
backgroundPosition: '0% 58.5%'
});
}
/*******************************************************************************************************************************
* Reports and Messages
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Storage of the selected filter (only in German Grepolis yet)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var filter = "all";
function saveFilter(){
$('#dd_filter_type_list .item-list div').each(function(){
$(this).click(function(){
filter = $(this).attr("name");
});
});
/*
var i = 0;
$("#report_list a").each(function () {
console.log((i++) +" = " + $(this).attr('data-reportid'));
});
*/
}
function loadFilter(){
if(!($('#dd_filter_type_list .selected').attr("name") === filter)){
$('#dd_filter_type .caption').get(0).click();
$('#dd_filter_type_list .item-list div[name='+ filter +']').get(0).click();
}
}
function removeReports(){
$("#report_list li:contains('spioniert')").each(function () {
//$(this).remove();
});
}
var zut = 0;
var messageArray = {};
function filterPlayer(){
if(!$('#message_filter_list').get(0)) {
$('
').appendTo('#folder_container');
$("#message_list").get(0).style.display = "none";
}
if(zut < parseInt($('.es_last_page').get(0).value, 10)-1){
$('.es_page_input').get(0).value = zut++;
$('.jump_button').get(0).click();
$("#message_list li:contains('')").each(function () {
$(this).appendTo('#message_filter_list');
});
} else {
zut = 1;
}
}
/*******************************************************************************************************************************
* World Wonder
* ----------------------------------------------------------------------------------------------------------------------------
* | ● click adjustment
* | ● Share calculation (= ratio of player points to alliance points)
* | ● Resources calculation & counter (stores amount)
* | ● Adds missing previous & next buttons on finished world wonders (better browsing through world wonders)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
// getPointRatio: Default
function getPointRatioFromGS(){
var gs = 0, AP = 0;
setTimeout(function(){
GM_xmlhttpRequest({
method: "GET",
url: "http://de.grepostats.com/world/" + WID + "/alliance/" + AID,
onload: function(response) {
gs = response.responseText;
gs = gs.substr(gs.indexOf("Punkte"));
gs = gs.substr(gs.indexOf("
"));
AP = parseInt(gs.replace(/\,/g, ''), 10);
//console.log("Allianzpunkte: " + AP);
ratio = 100 / AP * uw.Game.player_points;
GM_setValue(WID + "_ratio", ratio);
}
});
}, 0);
}
function getPointRatioFromAllianceRanking(){
ratio = 100 / parseInt($('.current_player .r_points').get(0).innerHTML, 10) * uw.Game.player_points;
setTimeout(function(){
GM_setValue(WID + "_ratio", ratio);
},0);
}
function getPointRatioFromAllianceMembers(){
var points = 0;
$('#ally_members_body tr').each(function(){
points += parseInt($(this).children().eq(2).text(), 10) || 0;
});
ratio = 100 / points * uw.Game.player_points;
setTimeout(function(){
GM_setValue(WID + "_ratio", ratio);
},0);
}
if(uw.location.pathname === "/game/index"){
var ww_res = JSON.parse(GM_getValue(WID + "_ww_res", '{}'));
}
// TODO: Split function...
function getResWW(){
var wndArray = uw.GPWindowMgr.getOpen(uw.Layout.wnd.TYPE_WONDERS);
for(var e in wndArray){
if(wndArray.hasOwnProperty(e)){
var wndID = "#gpwnd_" + wndArray[e].getID() + " ";
if(!$(wndID + '.wonder_finished').get(0)){
var res = 0,
ww_share = {total: {share:0, sum:0}, stage: {share:0, sum:0}},
ww_type = $(wndID + '.finished_image_small').attr('src').split("/")[6].split("_")[0], // Which world wonder?
res_stages = [ 2, 4, 6, 10, 16, 28, 48, 82, 140, 238], // Rohstoffmenge pro Rohstofftyp in 100.000 Einheiten
stage = parseInt($(wndID + '.wonder_expansion_stage span').get(0).innerHTML.split("/")[0], 10) + 1, // Derzeitige Füllstufe
speed = uw.Game.game_speed;
ww_res[ww_type] = ww_res[ww_type] || {};
ww_res[ww_type][stage] = ww_res[ww_type][stage] || 0;
if(!$(wndID + '.ww_ratio').get(0)) {
$('
').appendTo(wndID + '.wonder_res_container .trade');
$(wndID + '.wonder_header').prependTo(wndID + '.wonder_progress');
$(wndID + '.wonder_res_container .send_res').insertBefore(wndID + '.wonder_res_container .next_level_res');
}
$(wndID + '.wonder_progress').css({
margin: '0 auto 5px'
});
$(wndID + '.wonder_header').css({
textAlign: 'left',
margin: '10px -8px 12px 3px'
});
$(wndID + '.build_wonder_icon').css({
top: '25px',
});
$(wndID + '.wonder_progress_bar').css({
top: '54px',
});
$(wndID + '.wonder_controls').css({
height: '380px',
});
$(wndID + '.trade fieldset').css({
float: 'right',
});
$(wndID + '.wonder_res_container').css({
right: '29px'
});
$(wndID + '.ww_ratio').css({
position: 'relative',
height: 'auto'
});
$(wndID + 'fieldset').css({
height: 'auto'
});
$(wndID + '.town-capacity-indicator').css({
marginTop: '0px'
});
for(var d in res_stages){
if(res_stages.hasOwnProperty(d)){
ww_share.total.sum += res_stages[d];
}
}
ww_share.total.sum *= speed * 300000;
ww_share.total.share = parseInt(ratio * (ww_share.total.sum / 100), 10);
ww_share.stage.sum = speed * res_stages[stage-1] * 300000;
ww_share.stage.share = parseInt(ratio * (ww_share.stage.sum / 100), 10); // ( 3000 = 3 Rohstofftypen * 100000 Rohstoffe / 100 Prozent)
setResWW(stage, ww_type, ww_share, wndID);
$(wndID + '.wonder_res_container .send_resources_btn').click(function(){
ww_res[ww_type][stage] += parseInt($(wndID + '#ww_trade_type_wood input:text').get(0).value, 10);
ww_res[ww_type][stage] += parseInt($(wndID + '#ww_trade_type_stone input:text').get(0).value, 10);
ww_res[ww_type][stage] += parseInt($(wndID + '#ww_trade_type_iron input:text').get(0).value, 10);
//console.log(ww_res[ww_type][stage]);
setResWW(stage, ww_type, ww_share, wndID);
setTimeout(function(){
GM_setValue(WID + "_ww_res", JSON.stringify(ww_res));
}, 0);
});
} else {
$('
').appendTo(wndID + '.wonder_controls');
$(wndID + '.pos_Y').css({
top: '-266px',
});
}
}
}
}
function setResWW(stage, ww_type, ww_share, wndID){
//console.log(ww_res);
var width_stage, width_total, res_total = 0, disp_stage = "none", disp_total = "none";
for(var z in ww_res[ww_type]){
if(ww_res[ww_type].hasOwnProperty(z)){
res_total += ww_res[ww_type][z];
}
}
if(ww_share.stage.share > ww_res[ww_type][stage]){
width_stage = (242 / ww_share.stage.share) * ww_res[ww_type][stage];
} else {
width_stage = 0;
disp_stage = "block";
}
if(ww_share.total.share > res_total){
width_total = (242 / ww_share.total.share) * res_total;
} else {
width_total = 0;
disp_total = "block";
}
//console.log(ratio);
$(wndID + '.ww_ratio').get(0).innerHTML = "";
$(wndID + '.ww_ratio').append('
');
$('.ww_ratio .progress').css({
//position: 'absolute',
//textAlign: 'center',
lineHeight: '1',
color: 'white',
fontSize: '0.8em'
});
$(wndID + '.ww_perc').css({
position:'absolute',
width:'242px',
textAlign: 'center'
});
$(wndID + '.indicator4').css({
background: 'url(http://gpde.innogamescdn.com/images/game/layout/progressbars-sprite_2.53.png) no-repeat 0 0',
backgroundPosition: '0px -355px',
height: '10px',
zIndex: '13000',
width: '242px'
});
$(wndID + '.all_res').css({
background: 'url(http://de.cdn.grepolis.com/images/game/layout/resources_2.32.png) no-repeat 0 -90px',
width: '30px',
height: '30px',
margin: '0 auto',
marginLeft: '5px'
});
$(wndID + '.town-capacity-indicator').css({
marginTop: '0px'
});
$(wndID + '.ww_ratio').tooltip("
");
}
// Adds points to numbers
function pointNumber(number) {
var sep; if(LID === "de"){ sep = "."; } else { sep = ",";}
number = number.toString();
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (var i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0)) {
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
} else {
output+= sep + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
}
number = output;
}
return number;
}
/*******************************************************************************************************************************
* Farming Village Overview
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Color change on possibility of city festivals
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
function changeResColor(){
var res, res_min, i = 0;
$('#fto_town_list .fto_resource_count :last-child').reverseList().each(function(){
if($(this).parent().hasClass("stone")){
res_min = 18000;
} else {
res_min = 15000;
}
res = parseInt($(this).get(0).innerHTML, 10);
if((res >= res_min) && !($(this).hasClass("town_storage_full"))){
$(this).get(0).style.color = '#0A0';
}
if(res < res_min){
$(this).get(0).style.color = '#000';
}
});
}
/*******************************************************************************************************************************
* Conquest Info
* -----------------------------------------------------------------------------------------------------------------------------
* | ● Amount of supports und attacks in the conquest window
* | ● Layout adjustment (for reasons of clarity)
* | - TODO: conquest window of own cities
* -----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
function countMovements(){
var i = 0, a = 0;
$('#unit_movements .support').each(function(){
i++;
});
$('#unit_movements .attack_land, #unit_movements .attack_sea, #unit_movements .attack_takeover').each(function(){
a++;
});
var str = "
";
if($('.gpwindow_content .tab_content .bold').get(0)){
$('.gpwindow_content .tab_content .bold').append(str);
} else {
$('.gpwindow_content h4:eq(1)').append(str);
// TODO: set player link ?
/*
$('#unit_movements li div').each(function(){
//console.log($(this).get(0).innerHTML);
});
*/
}
$('.move_hr').css({
margin: '7px 0px 0px 0px',
backgroundColor: '#5F5242',
height: '2px',
border: '0px solid'
});
// smaller movements
$('#unit_movements').css({
fontSize: '0.80em'
});
$('.incoming').css({
width: '150px',
height: '45px',
float: 'left'
});
$('#unit_movements div').each(function(){
if($(this).attr('class') === "unit_movements_arrow"){
// delete placeholder for arrow of outgoing movements (there are no outgoing movements)
if(!$(this).get(0).style.background) { $(this).get(0).remove(); }
} else {
// realign texts
$(this).css({
margin: '3px',
paddingLeft: '3px'
});
}
});
$('.troops').css({
float: 'left',
margin: '0px 5px 0px 0px',
height:'18px',
width:'18px',
position: 'relative'
});
$('#count_def').css({
background: 'url(http://de.cdn.grepolis.com/images/game/place/losts.png)',
backgroundPosition: '0 -36px'
});
$('#count_off').css({
background: 'url(http://de.cdn.grepolis.com/images/game/place/losts.png)',
backgroundPosition: '0 0px'
});
}
/*******************************************************************************************************************************
* Town window
* ----------------------------------------------------------------------------------------------------------------------------
* | ● TownTabHandler (trade, attack, support,...)
* | ● Sent units box
* | ● Short duration: Display of 30% troop speed improvement in attack/support tab
* | ● Trade options:
* | - Ressource marks on possibility of city festivals
* | - Percentual Trade: Trade button
* | - Recruiting Trade: Selection boxes (ressource ratio of unit type + share of the warehouse capacity of the target town)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
// TODO: Change both functions in MultipleWindowHandler()
function TownTabHandler(action){
var wndArray, wndID, wndA;
wndArray = uw.GPWindowMgr.getOpen(uw.Layout.wnd.TYPE_TOWN);
for(var e in wndArray){
if(wndArray.hasOwnProperty(e)){
wndA = wndArray[e].getAction(); wndID = "#gpwnd_" + wndArray[e].getID() + " ";
if(wndA === action){
switch(action){
case "trading":
if(!$(wndID + '.rec_trade').get(0)){
addRecTrade(wndID);
}
if(!($(wndID + '.btn_trade').get(0))){
addPercentTrade(wndID, false);
}
//addTradeMarks(wndID, 15, 18, 15, "red"); // town festival
break;
case "support": case "attack":
if(options.way && !($('.js-casted-powers-viewport .unit_movement_boost').get(0) || $(wndID + '.short_duration').get(0))){
addShortDuration(wndID);
}
if(options.sen) {
addSentUnitsBox(wndID, action);
}
break;
case "rec_mark":
//addTradeMarks(wndID, 15, 18, 15, "lime");
break;
}
}
}
}
}
function WWTradeHandler(){
var wndArray, wndID, wndA;
wndArray = uw.GPWindowMgr.getOpen(uw.GPWindowMgr.TYPE_WONDERS);
for(var e in wndArray){
if(wndArray.hasOwnProperty(e)){
wndID = "#gpwnd_" + wndArray[e].getID() + " ";
if(!($(wndID + '.btn_trade').get(0) || $(wndID +'.next_building_phase').get(0) || $(wndID +'#ww_time_progressbar').get(0))){
addPercentTrade(wndID, true);
}
}
}
}
/*******************************************************************************************************************************
* ● Sent units box
*******************************************************************************************************************************/
var sentUnitsArray = JSON.parse(GM_getValue(WID +"_sentUnitsArray", '{ "attack": {}, "support": {} }'));
function addSentUnitsBox(wndID, action){
if(!$(wndID + '.sent_units_box').get(0)){
var selectedUnitsArray = {};
$('
').appendTo(wndID + '.attack_support_window');
/* New-Feature Info
$('
').prependTo(wndID + '.sent_units_box');
*/
updateSentUnitsBox(wndID, action);
$(wndID + '.icon_sent').css({
height: '20px',
marginTop: '-2px',
width: '20px',
backgroundSize: '17px',
paddingLeft: '0px',
marginLeft: '0px'
});
$(wndID + '.sent_units_box').css({
position: 'absolute',
right: '0px',
bottom: '16px',
width: '192px',
//border: '2px solid green',
//borderRadius: '5px',
//padding: '5px'
});
$(wndID + '.troops').css({ padding: '6px 0px 6px 6px' });
setTimeout(function(){
$(wndID +'.send_units_form a').each(function(){
$(this).click(function(){
selectedUnitsArray = getSelectUnits(wndID);
});
});
},10);
$(wndID + '.unit_input').on("blur", function(){
selectedUnitsArray = getSelectUnits(wndID);
});
/*
$(wndID + '.unit_container a').on("click", function(){
selectedUnitsArray[$(this).attr("id")] = $(wndID + '.unit_type_'+ $(this).attr("id")).val();
console.log($(this).attr("id"));
console.log(selectedUnitsArray);
});
*/
$(wndID + '#btn_sent_units_reset').click(function(){
// Overwrite old array
sentUnitsArray[action] = {}; updateSentUnitsBox(wndID, action);
});
$(wndID + '.attack_support_window .button').click(function(){
getSentUnits(wndID, action, selectedUnitsArray);
});
$(wndID + '#btn_attack_town').click(function(){
getSentUnits(wndID, action, selectedUnitsArray);
});
}
}
function getSelectUnits(wndID){
var selectedUnitsArray = {};
for(var u in unitVal){
if(unitVal.hasOwnProperty(u)){
var a = parseInt($(wndID + '.unit_type_'+ u).val(), 10);
if(a > 0){ selectedUnitsArray[u] = parseInt(a, 10); } else { delete selectedUnitsArray[u]; }
}
}
return selectedUnitsArray;
}
function getSentUnits(wndID, action, selectedUnitsArray){
var sentSuccess = true, capaShip = 0, capaUnit = 0, popUnit = 0, seaMovement = false;
var u = 0;
if(!$('#human_message').get(0)){
$('body').append('
');
}
// check if sending was successful
var human_message = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(u == 0){
if($('#human_message').attr("class").split(" ")[1] === "human_message_success"){
// Add selected units to sent units
for(var t in selectedUnitsArray){
if(selectedUnitsArray.hasOwnProperty(t)){
sentUnitsArray[action][t] = sentUnitsArray[action][t] || 0;
sentUnitsArray[action][t] += selectedUnitsArray[t];
}
}
updateSentUnitsBox(wndID, action);
}
}
u++; human_message.disconnect();
});
});
human_message.observe($('#human_message').get(0), { attributes: true, childList: false, characterData: false, attributeFilter: ["style"] });
}
function updateSentUnitsBox(wndID, action){
// Remove old unit list
$(wndID +'.sent_units_box .units_list').get(0).innerHTML = "";
// Add new unit list
for(var x in sentUnitsArray[action]){
if(sentUnitsArray[action].hasOwnProperty(x)){
if((sentUnitsArray[action][x] || 0) > 0){
$('
'+
''+ sentUnitsArray[action][x] +''+
'
').appendTo(wndID +'.sent_units_box .units_list');
}
}
}
setTimeout(function(){
GM_setValue(WID +"_sentUnitsArray", JSON.stringify(sentUnitsArray));
}, 0);
}
/*******************************************************************************************************************************
* ● Short duration
*******************************************************************************************************************************/
function addShortDuration(wndID){
$(wndID + '.way_duration').after('
0:00:00');
/*
$(wndID + '.arrival_time').after('
'+ $('.server_time_area').get(0).innerHTML.split(" ")[0] +'');
setInterval(function(){
var t = $(wndID + '.short_arrival').get(0).innerHTML.split(":"), s, m, h;
s = parseInt((parseInt(t[2], 10) + 1) % 60, 10);
m = parseInt((parseInt(t[1], 10) + (parseInt(t[2],10) + 1) / 60) % 60, 10);
h = parseInt((parseInt(t[0], 10) + (parseInt(t[1], 10) + (parseInt(t[2],10) + 1) / 60) / 60) % 24, 10);
$(wndID + '.short_arrival').get(0).innerHTML = h + ":" + m + ":" + s;
}, 1000);
*/
$(wndID + '.short_duration').tooltip("Verbesserte Truppenbewegung");
changeShortDuration(wndID);
// Style
$(wndID + '.duration_container').css({
width:'390px'
});
$(wndID + '.short_duration').css({
position: 'relative',
float: 'left',
color: 'darkgreen',
padding: '6px 3px 6px 30px',
background: 'url(http://666kb.com/i/ck2c7eohpyfa3yczt.png) no-repeat',
backgroundSize: '28px',
backgroundPosition: '4px 2px'
});
}
function changeShortDuration(wndID){
var duration = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes[0]){
calcShortDuration(wndID);
}
});
});
duration.observe($(wndID + '.way_duration').get(0), { attributes: false, childList: true, characterData: false});
}
function calcShortDuration(wndID){
var speed = uw.Game.game_speed, setupTime = 900/speed,
time = $(wndID + '.duration_container .way_duration').get(0).innerHTML.replace("~","").split(":"),
h,m,s;
time = (((parseInt(time[0], 10)*60 + parseInt(time[1], 10))*60 + parseInt(time[2], 10) - setupTime) / 1.3) + setupTime;
h = Math.floor(time/3600);
m = Math.floor((time - h*3600)/60);
s = Math.floor(time - h*3600 - m*60);
if(m < 10) { m = "0" + m; }
if(s < 10) { s = "0" + s; }
$(wndID + '.short_duration').get(0).innerHTML = "[~"+ h +":" + m + ":" + s + "]";
}
/*******************************************************************************************************************************
* ● Dropdown menu
*******************************************************************************************************************************/
// Preload images for drop down arrow buttons
var drop_over = new Image(); drop_over.src = "http://s7.directupload.net/images/140107/hna95u8a.png";
var drop_out = new Image(); drop_out.src = "http://s14.directupload.net/images/140107/ppsz5mxk.png";
function changeDropDownButton(){
/*
$('').appendTo('head');
*/
$('.arrow').css({
width: '18px',
height: '17px',
background: 'url('+ drop_out.src +') no-repeat -1px -1px',
position: 'absolute',
top: '2px',
right: '3px'
});
}
var o = 1;
/*******************************************************************************************************************************
* ● Recruiting Trade
*******************************************************************************************************************************/
var trade_count = 0, unit = "FS", percent = "0.0"; // Recruiting Trade
function addRecTrade(wndID){
var max_amount;
$('
'+
// DropDown-Button for unit
'
'+
'
'+
'
'+
'
'+ unit +'
'+
'
'+
'
'+
'
'+
// DropDown-Button for ratio
'
'+
'
'+
'
'+ Math.round(percent * 100)+'%
'+
'
'+
'
('+ trade_count +')').appendTo(wndID + ".content");
// Select boxes for unit and ratio
$('
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
').appendTo(wndID + ".rec_trade");
$('
'+
'
'+
'
0%
'+
'
5%
'+
'
10%
'+
'
17%
'+
'
20%
'+
'
25%
'+
'
33%
'+
'
50%
'+
'
').appendTo(wndID + ".rec_trade");
$(wndID + ".rec_trade [name='"+ unit +"']").toggleClass("sel");
// Styles
$(wndID + '.rec_trade').css({ position: 'absolute', left: '30px', top: '70px' });
$(wndID + '.select_rec_unit').css({
position: 'absolute',
top: '20px',
width: '84px',
display: "none"
});
$(wndID + '.select_rec_perc').css({
position: 'absolute',
left: '50px',
top: '20px',
width: '50px',
display: "none"
});
$(wndID + '.item-list').css({ maxHeight: '400px', maxWidth: '200px', align: "right" });
$(wndID + '.arrow').css({
width: '18px',
height: '18px',
background: 'url('+ drop_out.src +') no-repeat -1px -1px',
position: 'absolute',
});
$(wndID + '.option_s').css({
WebkitFilter: "grayscale(100%)",
filter: "url(#GrayScale)",
cursor: 'pointer',
color: 'black',
lineHeight: '14px',
float: 'left',
position: 'relative',
width: '40px',
margin: '0px',
padding: '0px'
});
$('.select_rec_unit .sel').css({"-webkit-filter" : "sepia(100%)", "filter": "url(#Sepia)"});
// hover effects of the elements in the drop menus
$(wndID + '.option_s').hover(
function(){
//console.log(this.className);
$(this).css({"-webkit-filter" : "grayscale(0%) sepia(0%)", "filter": "none"});
if(!($(this).hasClass("sel"))){
$('.option_s .sel').css({"-webkit-filter" : "grayscale(0%) sepia(100%)", "filter": "url(#Sepia)"});
}
},
function(){
$('.select_rec_unit .option_s').css({"-webkit-filter" : "grayscale(100%) sepia(0%)", "filter": "url(#GrayScale)"});
$('.select_rec_unit .sel').css({"-webkit-filter" : "grayscale(0%) sepia(100%)", "filter": "url(#Sepia)"});
}
);
$(wndID + '.option').hover(
function(){ $(this).css({color: '#fff', background: "#328BF1"}); },
function(){ $(this).css({color: '#000', background: "#FFEEC7"}); }
);
// click events of the drop menu
$(wndID + ' .select_rec_unit .option_s').each(function(){
$(this).click(function(e){
$(".select_rec_unit .sel").toggleClass("sel");
$("." + this.className.split(" ")[4]).toggleClass("sel");
unit = $(this).attr("name");
$('.drop_rec_unit .caption').attr("name", unit);
$('.drop_rec_unit .caption').each(function(){
$(this).get(0).innerHTML = unit;
});
$(this).parent().parent().get(0).style.display = "none";
$('.drop_rec_unit .caption').change();
});
});
$(wndID + ' .select_rec_perc .option').each(function(){
$(this).click(function(e){
$(this).parent().find(".sel").toggleClass("sel");
$(this).toggleClass("sel");
percent = $(this).attr("name");
$('.drop_rec_perc .caption').attr("name", percent);
$('.drop_rec_perc .caption').each(function(){
$(this).get(0).innerHTML = Math.round(percent * 100)+"%";
});
$(this).parent().parent().get(0).style.display = "none";
$('.drop_rec_perc .caption').change();
});
});
// show & hide drop menus on click
$(wndID + '.drop_rec_perc').click(function(e){
if($(e.target)[0].parentNode.parentNode.childNodes[3].style.display === "none"){
$(e.target)[0].parentNode.parentNode.childNodes[3].style.display = "block";
$(e.target)[0].parentNode.parentNode.childNodes[2].style.display = "none";
} else {
$(e.target)[0].parentNode.parentNode.childNodes[3].style.display = "none";
}
});
$(wndID + '.drop_rec_unit').click(function(e){
if($(e.target)[0].parentNode.parentNode.childNodes[2].style.display === "none"){
$(e.target)[0].parentNode.parentNode.childNodes[2].style.display = "block";
$(e.target)[0].parentNode.parentNode.childNodes[3].style.display = "none";
} else {
$(e.target)[0].parentNode.parentNode.childNodes[2].style.display = "none";
}
});
$(wndID).click(function(e){
var clicked = $(e.target);
if(!(clicked[0].parentNode.className.split(" ")[1] === "dropdown")){
$('#' + this.id + ' .select_rec_unit').get(0).style.display = "none";
}
});
// hover arrow change
$(wndID + '.dropdown').hover(function(e){
$(e.target)[0].parentNode.childNodes[3].style.background = "url('"+ drop_over.src +"') no-repeat -1px -1px";
}, function(e){
$(e.target)[0].parentNode.childNodes[3].style.background = "url('"+ drop_out.src +"') no-repeat -1px -1px";
});
$(wndID + ".drop_rec_unit .caption").attr("name", unit);
$(wndID + ".drop_rec_perc .caption").attr("name",percent);
$(wndID + '.drop_rec_unit').tooltip(LANG[LID].trd.uni);
$(wndID + '.drop_rec_perc').tooltip(LANG[LID].trd.rat);
var ratio = {NO: {w:0, s: 0, i: 0 },
FS: {w:1, s: 0.2308, i: 0.6154 },
BI: {w:1, s: 0.8750, i: 0.2250 },
SL: {w:0.55, s: 1, i: 0.4 },
RE: {w:0.6666, s: 0.3333, i: 1 },
SK: {w:1, s: 0, i: 0.8947 },
HO: {w:0, s: 0.5, i: 1 },
BS: {w:1, s: 0, i: 0.6250 },
SW: {w:0.4545, s: 1, i: 0.7273 }
};
if($('#town_capacity_wood .max').get(0)){
max_amount = parseInt($('#town_capacity_wood .max').get(0).innerHTML, 10);
} else {
max_amount = 25500;
}
$(wndID + '.caption').change(function(e){
//console.log($(this).attr('name') + ", " + unit + "; " + percent);
if(!(($(this).attr('name') === unit) || ($(this).attr('name') === percent))){
//trade_count = 0;
$('.rec_count').get(0).innerHTML = "(" + trade_count + ")";
}
var tmp = $(this).attr('name');
if($(this).parent().attr('class').split(" ")[0] === "drop_rec_unit"){
unit = tmp;
} else {
percent = tmp;
}
var max = (max_amount - 100)/1000;
addTradeMarks(max * ratio[unit].w, max * ratio[unit].s, max * ratio[unit].i, "lime");
var part = (max_amount - 1000) * parseFloat(percent); // -1000 als Puffer (sonst Überlauf wegen Restressies, die nicht eingesetzt werden können, vorallem bei FS und Biremen)
var rArray = uw.ITowns.getTown(uw.Game.townId).getCurrentResources();
var tradeCapacity = uw.ITowns.getTown(uw.Game.townId).getAvailableTradeCapacity();
var wood = ratio[unit].w * part;
var stone= ratio[unit].s * part;
var iron = ratio[unit].i * part;
if((wood > rArray.wood) || (stone > rArray.stone) || (iron > rArray.iron) || ( (wood + stone + iron) > tradeCapacity)) {
wood = stone = iron = 0;
$('.drop_rec_perc .caption').css({color:'#f00'});
//$('.' + e.target.parentNode.parentNode.className + ' .select_rec_perc .sel').css({color:'#f00'});
//$('.select_rec_perc .sel').css({color:'#f00'});
} else {
$('.' + e.target.parentNode.parentNode.className + ' .drop_rec_perc .caption').css({color:'#000'});
}
$("#trade_type_wood [type='text']").select().val(wood).blur();
$("#trade_type_stone [type='text']").select().val(stone).blur();
$("#trade_type_iron [type='text']").select().val(iron).blur();
});
$('#trade_button').click(function(){
trade_count++;
$('.rec_count').get(0).innerHTML = "(" + trade_count + ")";
});
$(wndID + '.rec_count').css({
position: 'absolute',
display: 'block',
left: '33px',
top: '95px',
width: '20px'
});
$(wndID + '.drop_rec_unit').css({
position: 'absolute',
display: 'block',
width: '50px',
overflow: 'visible'
});
$(wndID + '.drop_rec_perc').css({
position: 'absolute',
display: 'block',
left: '49px',
width: '55px',
color:'#000'
});
$(wndID + '.drop_rec_perc .caption').change();
}
/*******************************************************************************************************************************
* ● Ressources marks
*******************************************************************************************************************************/
function addTradeMarks(woodmark, stonemark, ironmark, color){
var max_amount, limit, wndArray = uw.GPWindowMgr.getOpen(uw.Layout.wnd.TYPE_TOWN), wndID;
for(var e in wndArray){
if(wndArray.hasOwnProperty(e)){
wndID = "#gpwnd_" + wndArray[e].getID() + " ";
if($(wndID + '.town-capacity-indicator').get(0)){
max_amount = $(wndID + '.amounts .max').get(0).innerHTML;
$('#trade_tab .c_'+ color).each(function(){
$(this).get(0).remove();
});
$('#trade_tab .progress').each(function(){
if($("p", this).length < 3) {
if($(this).parent().get(0).id != "big_progressbar"){
limit = 1000 * (242 / parseInt(max_amount, 10));
switch($(this).parent().get(0).id.split("_")[2]){
case "wood": limit = limit * woodmark; break;
case "stone": limit = limit * stonemark; break;
case "iron": limit = limit * ironmark; break;
}
$('
').appendTo(this);
}
}
});
}
}
}
}
/*******************************************************************************************************************************
* ● Percentual Trade
*******************************************************************************************************************************/
var rest_count = 0;
function addPercentTrade(wndID, ww){
var a = ""; var content = wndID + ".content";
if(ww) {
a = "ww_";
content = wndID + '.trade .send_res';
}
$('
').prependTo(content);
$(wndID + '.btn_trade').tooltip(LANG[LID].trd.prc);
setPercentTrade(wndID, ww);
$(wndID + '.btn').css({ width: '20px', overflow: 'visible', position: 'absolute', display: 'block' });
if(!ww){ $(wndID + '.content').css({ height: '320px' }); }
if(ww){
$(wndID + '.btn_trade').css({ left: '678px', top: '154px' });
} else {
$(wndID + '.btn_trade').css({ left: '336px', top: '135px' });
}
$(wndID + '.mid').css({ minWidth: '26px' });
$(wndID + '.img_trade').css({
width: '27px',
height: '27px',
top: '-3px',
float: 'left',
position: 'relative',
background: 'url("http://666kb.com/i/cjq6d72qk521ig1zz.png") no-repeat'
});
}
var res = {};
function setPercentTrade(wndID, ww){
var a = ""; if(ww) a = "ww_";
$(wndID + '.btn_trade').toggle(function(){
res.wood = {}; res.stone = {}; res.iron = {}; res.sum = {};
res.sum.amount = 0;
// Rohstoffmenge 0 setzen
setAmount(true, a, wndID);
// Rohstoffmenge insgesamt // TODO: ITowns.getTown(Game.townId).getCurrentResources(); ?
for(var e in res){
if(res.hasOwnProperty(e) && e != "sum") {
res[e].rest = false;
res[e].amount = parseInt($('.ui_resources_bar .'+ e +' .amount').get(0).innerHTML, 10);
res.sum.amount += res[e].amount;
}
}
// Prozentualer Anteil der Rohstoffe insgesamt
res.wood.percent = 100/res.sum.amount * res.wood.amount;
res.stone.percent = 100/res.sum.amount * res.stone.amount;
res.iron.percent = 100/res.sum.amount * res.iron.amount;
// Handelsmenge insgesamt
res.sum.cur = parseInt($(wndID + '#' + a + 'big_progressbar .caption .curr').get(0).innerHTML, 10);
res.sum.max = parseInt($(wndID + '#' + a + 'big_progressbar .caption .max').get(0).innerHTML, 10) - res.sum.cur;
// Menge der Rohstoffe am prozentualen Anteil der Handelsmenge (%)
res.wood.part = parseInt(res.sum.max/100 * res.wood.percent, 10);
res.stone.part = parseInt(res.sum.max/100 * res.stone.percent, 10);
res.iron.part = parseInt(res.sum.max/100 * res.iron.percent, 10);
for(var f in res){
if(res.hasOwnProperty(f) && f != "sum") {
if(!ww){
var i = 0;
$(wndID + '#town_capacity_'+ f +' .amounts span').each(function(){
res[f][i] = parseInt(this.innerHTML.replace('+', '').trim(), 10);
if(isNaN(res[f][i])) { res[f][i] = 0; }
i++;
});
res[f].cur = res[f][0] + res[f][1];
res[f].max = res[f][3] - res[f].cur;
if(res[f].max < 0) { res[f].max = 0; }
} else {
res[f].max = 30000;
}
}
}
// Rest von Bruchrechnung (0-2 Einheiten) zur Steinmenge addieren
res.stone.part += res.sum.max - (res.wood.part + res.stone.part + res.iron.part);
res.sum.rest = 0;
rest_count = 0;
calcRestAmount();
setAmount(false, a, wndID);
}, function(){
setAmount(true, a, wndID);
});
}
function calcRestAmount(){
// Rest aufteilen
if(res.sum.rest > 0){
for(var e in res){
if(res.hasOwnProperty(e) && e != "sum" && res[e].rest != true) {
res[e].part += res.sum.rest/(3 - rest_count);
}
}
res.sum.rest = 0;
}
// neuen Rest berechnen
for(var f in res){
if(res.hasOwnProperty(f) && f != "sum" && res[f].rest != true) {
if(res[f].max <= res[f].part) {
res[f].rest = true;
res.sum.rest += res[f].part - res[f].max;
rest_count += 1;
res[f].part = res[f].max;
}
}
}
// Rekursion
if(res.sum.rest > 0 && rest_count < 3){
calcRestAmount();
}
}
function setAmount(clear, a, wndID){
for(var e in res){
if(res.hasOwnProperty(e) && e != "sum") {
if(clear == true) { res[e].part = 0; }
$(wndID + "#" + a + "trade_type_" + e + ' [type="text"]').select().val(res[e].part).blur();
}
}
}
/*******************************************************************************************************************************
* Unit strength (blunt/sharp/distance) and Transport Capacity
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Unit strength: Unit menu
* | - Switching of def/off display with buttons
* | - Possible Selection of certain unit types
* | ● Unit strength: Siege
* | ● Unit strength: Barracks
* | ● Transport capacity: Unit menu
* | - Switching of transporter speed (+/- big transporter)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var def = true, blunt = 0, sharp = 0, dist = 0, shipsize = false;
function getSelectedUnitsMenu(){
var units = [];
if($(".units_land .units_wrapper .selected").length > 0){
$(".units_land .units_wrapper .selected").each(function(){
units[$(this).get(0).className.split(" ")[1]] = $(this).get(0).children[0].innerHTML;
});
} else {
$(".units_land .units_wrapper .unit").each(function(){
units[$(this).get(0).className.split(" ")[1]] = $(this).get(0).children[0].innerHTML;
});
}
return units;
}
// Calculate defensive strength
function calcDef(units){
var e; blunt = sharp = dist = 0;
for(e in units) {
if(units.hasOwnProperty(e)) {
blunt += units[e] * unitVal[e].def_hack;
sharp += units[e] * unitVal[e].def_pierce;
dist += units[e] * unitVal[e].def_distance;
}
}
}
// Calculate offensive strength
function calcOff(units, selectedUnits){
var e; blunt = sharp = dist = 0;
for(e in selectedUnits) {
if(selectedUnits.hasOwnProperty(e)) {
var attack = (units[e] || 0) * unitVal[e].attack;
switch(unitVal[e].attack_type){
case 'hack': blunt += attack; break;
case 'pierce': sharp += attack; break;
case 'distance':dist += attack; break;
}
}
}
}
/*******************************************************************************************************************************
* ● Unit strength: Unit menu
*******************************************************************************************************************************/
function setStrengthMenu() {
var unitsIn = uw.ITowns.getTown(uw.Game.townId).units(),
e, units = getSelectedUnitsMenu();
// Calculation
if(def==true){
calcDef(units);
} else {
calcOff(unitsIn, units);
}
$('#blunt').get(0).innerHTML = blunt;
$('#sharp').get(0).innerHTML = sharp;
$('#dist').get(0).innerHTML = dist;
setTransportCapacity(units);
}
function addStrengthMenu(){
$('
'+
'
'+
'

'+
'

'+
'
').appendTo('.units_land .content');
// transporter display
$('
'+
'
'+
' | '+
' | '+
'
'+
'
').appendTo('.units_naval .content');
// Styles
$('.ico').css({
height: '20px',
width: '20px'
});
$('.units_info_sprite').css({
background: 'url(http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png)',
backgroundSize: '100%'
});
$('.img_pierce').css({ backgroundPosition: '0px -20px' });
$('.img_dist').css({ backgroundPosition: '0px -40px' });
$('hr').css({
margin: '0px',
backgroundColor: '#5F5242',
height: '2px',
border: '0px solid'
});
$('.cont_left').css({
background: 'url(http://de.cdn.grepolis.com/images/game/layout/layout_units_nav_border.png)',
width:'65%',
display: 'table-cell'
});
$('.cont').css({
background:'url("http://gpde.innogamescdn.com/images/game/layout/layout_2.56_compressed.png") no-repeat -270px -354px'
});
$('.cont_right').css({
background:'url(http://de.cdn.grepolis.com/images/game/layout/layout_units_nav_border.png)',
width:'30%',
display: 'table-cell',
verticalAlign:'middle'
});
$('.img').css({
float:'right',
background:'none',
margin:'2px 8px 2px 0px'
});
$('.units_land .units_wrapper, .btn_gods_spells .checked').click(function(){
setTimeout(function(){
setStrengthMenu();
}, 100);
});
$('#off').css({"-webkit-filter" : "grayscale(80%)",
"filter": "url(#GrayScale)"});
// Buttons
$('#off').click(function(){
$('#strength .img_hack').get(0).style.backgroundPosition = '0% 36%';
$('#strength .img_pierce').get(0).style.backgroundPosition = '0% 27%';
$('#strength .img_dist').get(0).style.backgroundPosition = '0% 45%';
$('#str_font').get(0).style.color = "#edb";
// TODO: doesn't work in FF yet
$(this).css({"-webkit-filter" : "grayscale(0%)",
"filter": "none",
});
$('#def').css({"-webkit-filter" : "grayscale(80%)",
"filter": "url(#GrayScale)",
});
def = false;
setStrengthMenu();
});
$('#def').click(function(){
$('#strength .img_hack').get(0).style.backgroundPosition = '0% 0%';
$('#strength .img_pierce').get(0).style.backgroundPosition = '0% 9%';
$('#strength .img_dist').get(0).style.backgroundPosition = '0% 18%';
$('#str_font').get(0).style.color = "#fc6";
$(this).css({"-webkit-filter" : "grayscale(0%)",
"filter": "none"
});
$('#off').css({"-webkit-filter" : "grayscale(80%)",
"filter": "url(#GrayScale)",
});
def = true;
setStrengthMenu();
});
$('#def,#off,#transporter').hover(function() {
$(this).css('cursor','pointer');
});
$('#transporter').toggle(
function(){
$('#ship_img').get(0).src = img_big_transp;
shipsize = !shipsize;
setStrengthMenu();
},
function(){
$('#ship_img').get(0).src = img_small_transp;
shipsize = !shipsize;
setStrengthMenu();
}
);
data = uw.GameData;
unitVal = data.units;
}
/*******************************************************************************************************************************
* ● Unit strength: Siege
*******************************************************************************************************************************/
function addStrengthConquest(){
var units = [], str;
// units of the siege
$('#conqueror_units_in_town .unit').each(function(){
str = $(this).attr("class").split(" ")[4];
if(!unitVal[str].is_naval){
units[str] = parseInt($(this).get(0).children[0].innerHTML, 10);
//console.log($(this).attr("class").split(" ")[4]);
}
});
// calculation
calcDef(units);
$('
').appendTo('#conqueror_units_in_town');
$('#strength_eo').tooltip('Gesamteinheitenstärke der Belagerungstruppen');
$('#strength_eo .ico').css({
height: '20px',
width: '20px'
});
$('#strength_eo .units_info_sprite').css({
background: 'url(http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png)',
backgroundSize: '100%'
});
$('#strength_eo .img_pierce').css({ backgroundPosition: '0% 9%' });
$('#strength_eo .img_dist').css({ backgroundPosition: '0% 18%' });
$('#bl').get(0).innerHTML = blunt;
$('#sh').get(0).innerHTML = sharp;
$('#di').get(0).innerHTML = dist;
}
/*******************************************************************************************************************************
* ● Unit strength: Barracks
*******************************************************************************************************************************/
function setStrengthBarracks(){
if(!$('#strength_baracks').get(0)){
var units = [], pop = 0;
// whole units of the town
$('#units .unit_order_total').each(function(){
units[$(this).parent().parent().attr("id")] = $(this).get(0).innerHTML;
});
// calculation
calcDef(units);
// population space of the units
for(var e in units) {
if(units.hasOwnProperty(e)) {
pop += units[e] * unitVal[e].population;
}
}
$('
').appendTo('.ui-dialog #units');
$('
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' | 0 |
'+
'
'+
'
').appendTo('.ui-dialog #units');
$('.ui-dialog #units .ico').css({
height: '20px',
width: '20px'
});
$('.ui-dialog #units .units_info_sprite').css({
background: 'url(http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png)',
backgroundSize: '100%'
});
$('.ui-dialog #units .img_pierce').css({ backgroundPosition: '0% 9%' });
$('.ui-dialog #units .img_dist').css({ backgroundPosition: '0% 18%' });
$('#pop_baracks').tooltip('Bevölkerungszahl aller Landeinheiten der Stadt');
$('#strength_baracks').tooltip('Gesamteinheitenstärke stadteigener Truppen');
$('#b').get(0).innerHTML = blunt;
$('#s').get(0).innerHTML = sharp;
$('#d').get(0).innerHTML = dist;
$('#p').get(0).innerHTML = pop;
}
}
/*******************************************************************************************************************************
* ● Transporter capacity
*******************************************************************************************************************************/
function setTransportCapacity(){
var bigTransp = 0, smallTransp = 0, pop = 0, ship = 0, unit, berth, units = [];
// Ship space (available)
smallTransp = parseInt(uw.ITowns.getTown(parseInt(uw.Game.townId, 10)).units().small_transporter, 10);
if(isNaN(smallTransp)) smallTransp = 0;
if(shipsize){
bigTransp = parseInt(uw.ITowns.getTown(parseInt(uw.Game.townId, 10)).units().big_transporter, 10);
if(isNaN(bigTransp)) bigTransp = 0;
}
// Checking: Research berth
berth = 0;
if(uw.ITowns.getTown(uw.Game.townId).researches().hasBerth()){
berth = 6;
}
ship = bigTransp*(20 + berth) + smallTransp*(10 + berth);
units = uw.ITowns.getTown(uw.Game.townId).units();
// Ship space (required)
for(var e in units) {
if(units.hasOwnProperty(e)) {
if(unitVal[e]){ // without Heroes
if(!(unitVal[e].is_naval || unitVal[e].flying)){
pop += units[e] * unitVal[e].population;
}
}
}
}
$('#ship').get(0).innerHTML = pop + "/" + ship;
}
/*******************************************************************************************************************************
* Simulator
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Layout adjustment
* | ● Permanent display of the extended modifier box
* | ● Unit strength for entered units (without modificator influence yet)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
function changeSimulatorLayout(){
$('#place_simulator .game_body').css({
height: '457px'
});
// AutoFillIn
$('.place_insert_field[name="sim[mods][att][luck]"]').get(0).value = 0;
//$('.place_insert_field[name="sim[mods][att][morale]"]').get(0).value = 100;
// Mods
$('.place_sim_bonuses_heroes h4').prependTo('.place_sim_wrap_mods');
$('.place_sim_wrap_mods').css({
position: 'absolute',
right: '-17px'
});
$('.place_sim_wrap_mods .place_simulator_table .left_border').css({
width: '47px'
});
// Erweiterte Modulator-Box
$('.place_sim_wrap_mods_extended').removeClass().addClass("place_sim_wrap_mods_extend");
$('.place_sim_wrap_mods_extend').appendTo('.place_sim_wrap_mods');
$('.place_sim_wrap_mods_extend').css({
display: 'table',
position: 'relative',
width: '100px',
paddingTop: '6px'
});
$('.place_sim_bonuses_more_confirm').parent().get(0).style.display = "none";
$('.place_sim_showhide').remove();
$('.place_image').css({
width: '20px',
height:'20px',
backgroundSize: '100%',
margin: '1px'
});
$('.place_sim_wrap_mods_extend .place_image').each(function(){
var s = parseInt($(this).css('backgroundPosition').replace("px", "").split(" ")[1], 10)/2;
$(this).get(0).style.backgroundPosition = '0px '+s+'px';
});
$('.place_checkbox_field').each(function(){
$(this).click(function(){
$('.place_sim_bonuses_more_confirm').get(0).click();
});
});
// Einheitencontainer
$('#simulator_body .unit_container').css({
height: '50px',
width: '50px',
margin: '0px 3px 0px 1px'
});
$('.place_simulator_odd, .place_simulator_even').css({
textAlign: 'center'
});
$('.place_insert_field').css({
margin: '0px'
});
// Seeeinheiten-Box
$('.place_sim_sea_wrap h4').css({
float: 'left'
});
$('.place_sim_select_strategies').prependTo('.place_sim_sea_wrap');
$('.place_sim_select_strategies select').css({
width: '95px'
});
$('.place_sim_sea_wrap h4').prependTo('.place_sim_sea_wrap');
$('.place_sim_select_strategies select').get(0).children[0].innerHTML ="Standard";
$('.place_sim_select_strategies select').get(0).children[2].remove();
$('.place_sim_select_strategies').css({
marginLeft: '99px'
});
// Einheiten-Box
$('
').appendTo('#simulator_body');
$('#place_sim_wrap_units').css({
position: 'absolute',
bottom: '35px'
});
$('#place_simulator h4:last, .place_sim_select_gods_wrap').appendTo('#place_sim_wrap_units');
$('#place_sim_ground_units').appendTo('#place_sim_wrap_units');
$('#place_sim_wrap_units h4').prependTo('.place_sim_select_gods_wrap');
$('#place_sim_wrap_units h4').css({
float: 'left'
});
// Selectboxen
$('.place_sim_select_gods select').each(function(){
//$(this).get(0)[0].innerHTML = "Gottheit";
});
$('.place_sim_select_gods').css({
width: '105px'
});
$('.place_sim_select_gods select').css({
width: '80px'
});
$('.place_sim_select_gods_wrap').css({
padding: '0px'
});
$('#select_insert_units').css({
width: '130px'
});
//$('#select_insert_units').get(0)[1].innerHTML ="Angriff";
//$('#select_insert_units').get(0)[2].innerHTML ="Verteidigung";
$('.place_sim_select_gods_wrap .place_symbol, .place_sim_select_strategies .place_symbol').css({
margin: '3px 2px 0px 5px'
});
$('.place_sim_insert_units .place_symbol').css({
background: 'url(http://de.cdn.grepolis.com/images/game/towninfo/traveltime.png)',
backgroundSize: '140%',
backgroundPositionY: '-4px'
});
$('.place_attack').css({
float: 'left'
});
$('#simulator_body .att').css({
marginLeft: '19px'
});
// -> Heldenwelt
if(uw.Game.is_hero_world){
$('.place_sim_wrap_mods_extend tr').each(function(){
$(this).get(0).children[1].style.borderLeft = "none";
$(this).get(0).children[0].remove();
});
$('.place_sim_wrap_mods_extend').get(0).style.left = "-29px";
}
// -> Helden
if($('.place_sim_heroes_container').get(0)){
$('.place_sim_heroes_container').appendTo(".place_sim_wrap_mods");
$('#place_simulator h4:eq(2)').get(0).remove();
//$('
|
').appendTo(".place_sim_heroes_container tbody");
//$('.place_sim_heroes_container td:eq(2), .place_sim_heroes_container td:eq(3)').appendTo(".place_sim_heroes_container tr:eq(1)");
$('.place_sim_heroes_container').css({
position: 'absolute',
right: '26px',
paddingTop: '6px'
});
}
$('').appendTo('head');
setStrengthSimulator();
}
function afterSimulation(){
var lossArray = { att : { res: 0, fav: 0, pop: 0 }, def : { res: 0, fav: 0, pop: 0 } };
$('#place_sim_wrap_units .place_losses, #place_sim_naval_units .place_losses').each(function(){
var loss = parseInt($(this).get(0).innerHTML, 10) || 0;
if(loss > 0){
var unit = this.id.substring(26);
var side = this.id.split("_")[2];
lossArray[side].res += loss *(unitVal[unit].resources.wood + unitVal[unit].resources.stone + unitVal[unit].resources.iron);
lossArray[side].fav += loss * unitVal[unit].favor;
lossArray[side].pop += loss * unitVal[unit].population;
}
});
for(var x in lossArray){
if(lossArray.hasOwnProperty(x)){
for(var z in lossArray[x]){
if(lossArray[x].hasOwnProperty(z)){
$("#"+ x +"_"+ z).get(0).innerHTML = ((z === "res") && (lossArray[x][z] > 10000))? (Math.round(lossArray[x][z]/1000)+"k"):lossArray[x][z];
}
}
}
}
}
// Stärkeanzeige: Simulator
var unitsGround = { att: {}, def: {} }, unitsNaval = { att: {}, def: {} }, name ="";
function setStrengthSimulator() {
$('
'+
'
'+ LANG[LID].sim.str +'
'+
'
'+
''+
' | '+
' | '+
' | '+
' | '+
' | '+
'
'+
' | '+
'0 | '+
'0 | '+
'0 | '+
'0 | '+
'
'+
' | '+
'0 | '+
'0 | '+
'0 | '+
'0 | '+
'
'+
'
'+
'
'+ LANG[LID].sim.los +'
'+
'
'+
''+
' | '+
' | '+
' | '+
' | '+
'
'+
' | '+
'0 | '+
'0 | '+
'0 | '+
'
'+
' | '+
'0 | '+
'0 | '+
'0 | '+
'
'+
'
'+
'
').appendTo('#simulator_body');
$('#simu_table .ico').css({
height: '20px',
width: '20px'
});
$('#simu_table .units_info_sprite').css({
background: 'url(http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png)',
backgroundSize: '100%'
});
$('#simu_table .img_hack').css({ backgroundPosition: '0% 36%' });
$('#simu_table .img_pierce').css({ backgroundPosition: '0% 27%' });
$('#simu_table .img_dist').css({ backgroundPosition: '0% 45%' });
$('#simu_table .img_ship').css({ backgroundPosition: '0% 72%' });
$('#simu_table .img_fav').css({ background: 'url(http://gpde.innogamescdn.com/images/game/res/favor.png)', backgroundSize: '100%' });
$('#simu_table .img_res').css({ background: 'url(http://de.cdn.grepolis.com/images/game/units/units_info_sprite2.51.png) 0% 54%', backgroundSize: '100%' });
$('#simu_table .img_pop').css({ background: 'url(http://gpde.innogamescdn.com/images/game/res/pop.png)', backgroundSize: '100%' });
$('#simu_table .left_border').css({
width: '54px'
});
$('#simu_table .left_border').each(function(){
$(this)[0].align = 'center';
});
$('#simu_table .strength').tooltip(LANG[LID].sim.str + " (" + LANG[LID].sim.mod +")");
$('#simu_table .loss').tooltip(LANG[LID].sim.los);
// Klick auf Einheitenbild
$('.index_unit').click(function(){
var type = $(this).attr('class').split(" ")[4];
$('.place_insert_field[name="sim[units][att]['+type+']"]').change();
});
$('#place_sim_ground_units .place_insert_field, #place_sim_naval_units .place_insert_field').on('input change', function(){
name = $(this).attr("name").replace(/\]/g, "").split("[");
var str = this;
//console.log(str);
setTimeout(function(){
var unit_type = $(str).closest('.place_simulator_table').attr("id").split("_")[2],
val, e;
val = parseInt($(str).val(), 10);
val = val || 0;
if(unit_type == "ground"){
unitsGround[name[2]][name[3]] = val;
if(name[2] == "def"){
calcDef(unitsGround.def);
} else {
calcOff(unitsGround.att, unitsGround.att);
}
$('#' + name[2] + '_b').get(0).innerHTML = blunt;
$('#' + name[2] + '_s').get(0).innerHTML = sharp;
$('#' + name[2] + '_d').get(0).innerHTML = dist;
} else {
var att = 0, def = 0;
unitsNaval[name[2]][name[3]] = val;
if(name[2] == "def"){
for(e in unitsNaval.def) {
if(unitsNaval.def.hasOwnProperty(e)) {
def += unitsNaval.def[e] * unitVal[e].defense;
}
}
$('#def_ship').get(0).innerHTML = def;
} else {
for(e in unitsNaval.att) {
if(unitsNaval.att.hasOwnProperty(e)) {
att += unitsNaval.att[e] * unitVal[e].attack;
}
}
$('#att_ship').get(0).innerHTML = att;
}
}
}, 100);
});
// Abfrage wegen eventueller Spionageweiterleitung
getUnitInputs();
setTimeout(function(){
setChangeUnitInputs("def");
}, 100);
$('#select_insert_units').change(function(){
var side = $(this).find('option:selected').val();
setTimeout(function(){
getUnitInputs();
if(side === "att" || side === "def"){
setChangeUnitInputs(side);
}
}, 200);
});
}
function getUnitInputs(){
$('#place_sim_ground_units .place_insert_field, #place_sim_naval_units .place_insert_field').each(function(){
name = $(this).attr("name").replace(/\]/g, "").split("[");
var str = this;
var unit_type = $(str).closest('.place_simulator_table').attr("id").split("_")[2],
val, e;
val = parseInt($(str).val(), 10);
val = val || 0;
if(unit_type === "ground"){
unitsGround[name[2]][name[3]] = val;
} else {
var att = 0, def = 0;
unitsNaval[name[2]][name[3]] = val;
}
});
}
function setChangeUnitInputs(side){
$('.place_insert_field[name="sim[units][' + side + '][godsent]"]').change();
setTimeout(function(){
$('.place_insert_field[name="sim[units][' + side + '][colonize_ship]"]').change();
}, 100);
}
/*******************************************************************************************************************************
* Defensive form
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Adds a defensive form to the bbcode bar
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
// Funktion aufteilen...
function addForm(e){
var textareaId = "", bbcodeBarId = "";
switch (e) {
case "/alliance_forum/forum":
textareaId = "#forum_post_textarea";
bbcodeBarId = "#forum";
break;
case "/message/forward":
textareaId = "#message_message";
bbcodeBarId = "#message_bbcodes";
break;
case "/message/new":
textareaId = "#message_new_message";
bbcodeBarId = "#message_bbcodes";
break;
case "/message/view":
textareaId = "#message_reply_message";
bbcodeBarId = "#message_bbcodes";
break;
case "/player_memo/load_memo_content":
textareaId = "#memo_text_area";
bbcodeBarId = "#memo_edit";
break;
}
$('
').appendTo(bbcodeBarId + ' .bb_button_wrapper');
$('.def_form_button').css({
cursor: 'pointer',
marginTop:'3px'
});
$(bbcodeBarId + ' .dio_bbcode_option').css({
background: 'url("http://s14.directupload.net/images/140126/lt3hyb8j.png")',
display: 'block',
float: 'left',
width: '22px',
height: '23px',
margin: '0 3px 0 0',
position: 'relative',
});
$(bbcodeBarId + ' .def_form').css({
backgroundPosition: '-89px 0px'
});
var imgArray = {
wall: 'http://de.cdn.grepolis.com/images/game/main/wall.png',
tower: 'http://de.cdn.grepolis.com/images/game/main/tower.png',
hide: 'http://de.cdn.grepolis.com/images/game/main/hide.png',
spy: 'http://s7.directupload.net/images/140114/yr993xwc.png',
pop: 'http://s7.directupload.net/images/140114/4d6xktxm.png',
rev1: 'http://s7.directupload.net/images/140115/9cv6otiu.png',
rev0: 'http://s7.directupload.net/images/140115/aue4rg6i.png',
eo1: 'http://s1.directupload.net/images/140115/fkzlipyh.png',
eo0: 'http://s1.directupload.net/images/140115/hs2kg59c.png',
att: 'http://s1.directupload.net/images/140115/3t6uy4te.png',
sup: 'http://s7.directupload.net/images/140115/ty6szerx.png',
zeus: 'http://s1.directupload.net/images/140114/cdxecrpu.png',
hera: 'http://s1.directupload.net/images/140114/mve54v2o.png',
athena: 'http://s14.directupload.net/images/140114/kyqyedhe.png',
poseidon: 'http://s7.directupload.net/images/140114/tusr9oyi.png',
hades: 'http://s7.directupload.net/images/140114/huins2gn.png',
artemis: 'http://s7.directupload.net/images/140114/kghjhko8.png',
nogod: 'http://s1.directupload.net/images/140114/e7vmvfap.png',
captain: 'http://s14.directupload.net/images/140114/88gg75rc.png',
commander: 'http://s14.directupload.net/images/140114/slbst52o.png',
priest: 'http://s1.directupload.net/images/140114/glptekkx.png',
phalanx: 'http://s7.directupload.net/images/140114/e97wby6z.png',
ram: 'http://s7.directupload.net/images/140114/s854ds3w.png',
militia: 'http://wiki.en.grepolis.com/images/9/9b/Militia_40x40.png',
sword: 'http://wiki.en.grepolis.com/images/9/9c/Sword_40x40.png',
slinger: 'http://wiki.en.grepolis.com/images/d/dc/Slinger_40x40.png',
archer: 'http://wiki.en.grepolis.com/images/1/1a/Archer_40x40.png',
hoplite: 'http://wiki.en.grepolis.com/images/b/bd/Hoplite_40x40.png',
rider: 'http://wiki.en.grepolis.com/images/e/e9/Rider_40x40.png',
chariot: 'http://wiki.en.grepolis.com/images/b/b8/Chariot_40x40.png',
catapult: 'http://wiki.en.grepolis.com/images/f/f0/Catapult_40x40.png',
godsent: 'http://wiki.de.grepolis.com/images/6/6e/Grepolis_Wiki_225.png',
def_sum: 'http://s14.directupload.net/images/140127/6cxnis9r.png',
minotaur: 'http://wiki.de.grepolis.com/images/7/70/Minotaur_40x40.png',
manticore: 'http://wiki.de.grepolis.com/images/5/5e/Manticore_40x40.png',
zyclop: 'http://wiki.de.grepolis.com/images/6/66/Zyklop_40x40.png',
sea_monster:'http://wiki.de.grepolis.com/images/7/70/Sea_monster_40x40.png',
harpy: 'http://wiki.de.grepolis.com/images/8/80/Harpy_40x40.png',
medusa: 'http://wiki.de.grepolis.com/images/d/db/Medusa_40x40.png',
centaur: 'http://wiki.de.grepolis.com/images/5/53/Centaur_40x40.png',
pegasus: 'http://wiki.de.grepolis.com/images/5/54/Pegasus_40x40.png',
cerberus: 'http://wiki.de.grepolis.com/images/6/67/Zerberus_40x40.png',
fury: 'http://wiki.de.grepolis.com/images/6/67/Erinys_40x40.png',
griffin: 'http://wiki.de.grepolis.com/images/d/d1/Unit_greif.png',
calydonian_boar: 'http://wiki.de.grepolis.com/images/9/93/Unit_eber.png',
big_transporter: 'http://wiki.en.grepolis.com/images/0/04/Big_transporter_40x40.png',
bireme: 'http://wiki.en.grepolis.com/images/4/44/Bireme_40x40.png',
attack_ship: 'http://wiki.en.grepolis.com/images/e/e6/Attack_ship_40x40.png',
demolition_ship: 'http://wiki.en.grepolis.com/images/e/ec/Demolition_ship_40x40.png',
small_transporter: 'http://wiki.en.grepolis.com/images/8/85/Small_transporter_40x40.png',
trireme: 'http://wiki.en.grepolis.com/images/a/ad/Trireme_40x40.png',
colonize_ship: 'http://wiki.en.grepolis.com/images/d/d1/Colonize_ship_40x40.png',
move_icon: 'http://de.cdn.grepolis.com/images/game/unit_overview/',
bordure: 'http://s1.directupload.net/images/140126/8y6pmetk.png'
};
$('
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+ LANG[LID].bbc.sel[0] +'
'+
'
'+ LANG[LID].bbc.sel[1] +'
'+
'
'+ LANG[LID].bbc.sel[2] +'
'+
'
'+ LANG[LID].bbc.sel[3] +'
'+
'
'+
'
').appendTo(bbcodeBarId + ' .bb_button_wrapper');
$('.bb_def_chooser').css({
display: 'none',
top: '38px',
left: '510px',
position: 'absolute',
width: '190px',
zIndex: 10000
});
$(bbcodeBarId + " .bb_def_chooser .checkbox_new").click(function () {
$(this).toggleClass("checked");
});
$(bbcodeBarId + ' .def_form').toggle(function(){
$(this).parent().find(".bb_def_chooser").get(0).style.display = "block";
}, function(){
$(this).parent().find(".bb_def_chooser").get(0).style.display = "none";
});
$(bbcodeBarId + ' #dio_insert').click(function(){
var textarea = $(textareaId).get(0), text = $(textarea).val(), troop_table = "", troop_img = "", troop_count = "", separator = "", move_table = "", landunit_sum = 0;
$('.def_form').get(0).click();
if($('#f_uni').hasClass("checked")){
$('.units_land .unit, .units_naval .unit').each(function(){
troop_img += separator + '[img]' + imgArray[this.className.split(" ")[1]] + '[/img]';
troop_count += separator + '[center]' + $(this).find(".value").get(0).innerHTML + '[/center]';
separator = "[||]";
});
} else {
$('.units_land .unit').each(function(){
var a = this.className.split(" ")[1], def = (unitVal[a].def_hack + unitVal[a].def_pierce + unitVal[a].def_distance)/(3 * unitVal[a].population);
if(def > 10){
landunit_sum += parseInt($(this).find(".value").get(0).innerHTML, 10) * unitVal[a].population * ((def > 20) ? 2 : 1);
}
});
landunit_sum = (landunit_sum > 10000) ? ((Math.round(landunit_sum / 100))/10) + "k" : landunit_sum;
troop_img += '[img]'+ imgArray.def_sum +'[/img]';
troop_count += '[center]'+ landunit_sum +'[/center]';
separator = "[||]";
$('.units_naval .unit').each(function(){
troop_img += separator + '[img]' + imgArray[this.className.split(" ")[1]] + '[/img]';
troop_count += separator + '[center]' + $(this).find(".value").get(0).innerHTML + '[/center]';
});
}
if(troop_img !== ""){ troop_table = "\n[table][**]" + troop_img + "[/**][**]" + troop_count + "[/**][/table]\n"; }
var str = '[img]'+ imgArray.bordure + '[/img]'+
'\n\n[color=#006B00][size=12][u][b]'+ LANG[LID].bbc.ttl +' ([url="http://adf.ly/eDM1y"]©DIO-Tools[/url])[/b][/u][/size][/color]\n\n'+
//'[table][**][img]'+ imgArray.sup +'[/img][||]'+
'[size=12][town]' + uw.ITowns.getTown(uw.Game.townId).getId() + '[/town] ([player]'+ uw.Game.player_name +'[/player])[/size]'+
//'[||][img]'+ imgArray['rev' + (uw.ITowns.getTown(uw.Game.townId).hasConqueror()?1:0)] +'[/img][/**][/table]'+
'\n\n[i][b]'+ LANG[LID].bbc.inf +'[/b][/i]' + troop_table +
'[table][*]'+
'[img]'+ imgArray.wall +'[/img][|]\n'+
'[img]'+ imgArray.tower +'[/img][|]\n'+
'[img]'+ imgArray.phalanx +'[/img][|]\n'+
'[img]'+ imgArray.ram +'[/img][|]\n'+
($('#f_prm').hasClass("checked") ? '[img]'+ imgArray.commander +'[/img][|]\n' : ' ')+
($('#f_prm').hasClass("checked") ? '[img]'+ imgArray.captain +'[/img][|]\n' : ' ')+
($('#f_prm').hasClass("checked") ? '[img]'+ imgArray.priest +'[/img][|]\n' : ' ')+
($('#f_sil').hasClass("checked") ? '[center][img]'+imgArray.spy+'[/img][/center][|]\n' : ' ')+
'[img]'+ imgArray.pop +'[/img][|]\n'+
'[img]'+ imgArray[(uw.ITowns.getTown(uw.Game.townId).god() || "nogod")] +'[/img][/*]\n'+
'[**][center]' + uw.ITowns.getTown(uw.Game.townId).buildings().getBuildingLevel("wall")+ '[/center][||]'+
'[center]' + uw.ITowns.getTown(uw.Game.townId).buildings().getBuildingLevel("tower")+ '[/center][||]'+
'[center]' + (uw.ITowns.getTown(uw.Game.townId).researches().attributes.phalanx? '+' : '-') + '[/center][||]'+
'[center]' + (uw.ITowns.getTown(uw.Game.townId).researches().attributes.ram? '+' : '-')+ '[/center][||]'+
($('#f_prm').hasClass("checked") ? '[center]' + ((uw.Game.premium_features.commander >= uw.Timestamp.now())? '+' : '-') + '[/center][||]' : ' ')+
($('#f_prm').hasClass("checked") ? '[center]' + ((uw.Game.premium_features.captain >= uw.Timestamp.now())? '+' : '-')+ '[/center][||]' : ' ')+
($('#f_prm').hasClass("checked") ? '[center]' + ((uw.Game.premium_features.priest >= uw.Timestamp.now())? '+' : '-') + '[/center][||]' : ' ')+
($('#f_sil').hasClass("checked") ? '[center]' + Math.round(uw.ITowns.getTown(uw.Game.townId).getEspionageStorage()/1000) + 'k[/center][||]': ' ')+
'[center]' + uw.ITowns.getTown(uw.Game.townId).getAvailablePopulation() + '[/center][||]'+
'[center]' + $('.gods_favor_amount').get(0).innerHTML + '[/center]'+
'[/**][/table]';
var bb_count_str = parseInt(str.match(/\[/g).length, 10), bb_count_move = 0;
var i = 0;
if($('#f_mov').hasClass("checked")){
move_table += '\n[i][b]'+ LANG[LID].bbc.mov +'[/b][/i]\n[table]';
$('#toolbar_activity_commands').mouseover();
$('#toolbar_activity_commands_list .content .command').each(function(){
var cl = $(this).children()[0].className.split(" ");
if((cl[cl.length-1] === "returning" || cl[cl.length-1] === "revolt_arising" || cl[cl.length-1] === "revolt_running") && ((bb_count_str + bb_count_move) < 480)) {
move_table += (i%1) ? "" : "[**]";
i++;
move_table += "[img]" + imgArray.move_icon + cl[2] + ".png[/img][||]";
move_table += getArrivalTime($(this).children()[1].innerHTML) + (uw.Game.market_id === "de" ? " Uhr[||]" : " [||]");
move_table += "[town]" + JSON.parse(atob($(this).children()[2].firstChild.href.split("#")[1])).id + "[/town]";
move_table += (i%1) ? "[||]" : "[/**]";
}
bb_count_move = parseInt(move_table.match(/\[/g).length, 10);
});
if((bb_count_str + bb_count_move) > 480){
move_table += '[**]...[/**]';
}
$('#toolbar_activity_commands').mouseout();
//console.log((bb_count_str + bb_count_move));
move_table += (i%1) ? "[/**]" : "";
move_table += "[*][|][color=#800000][size=6][i] ("+ LANG[LID].bbc.dev +": ±1s)[/i][/size][/color][/*][/table]\n";
}
str += move_table + '[img]'+ imgArray.bordure + '[/img]';
$(textarea).val(text.substring(0, $(textarea).get(0).selectionStart) + str + text.substring($(textarea).get(0).selectionEnd));
});
}
function getArrivalTime(duration_time){
var server_time = $('.server_time_area').get(0).innerHTML.split(" ")[0].split(":"), arrival_time, s, m, h;
duration_time = duration_time.split(":");
s = parseInt(server_time[2], 10) + parseInt(duration_time[2], 10);
m = parseInt(server_time[1], 10) + parseInt(duration_time[1], 10) + ((s>=60)? 1 : 0);
h = parseInt(server_time[0], 10) + parseInt(duration_time[0], 10) + ((m>=60)? 1 : 0);
s = s%60; m = m%60; h = h%24;
s = ((s<10) ? "0" : "") + s;
m = ((m<10) ? "0" : "") + m;
h = ((h<10) ? "0" : "") + h;
arrival_time = h + ":" + m + ":" + s;
return arrival_time;
}
/*******************************************************************************************************************************
* Smiley box
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Display of a smiley selection box for text input fields (forum, messages, notes):
* | ● Used smileys: http://www.greensmilies.com/smilie-album/
* | + Own Grepolis smileys
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var smileyArray = { "standard": {}, "nature": {}, "grepolis": {}, "people": {}, "other":{} };
// smiley categories
smileyArray.button = [ "rollsmiliey", "smile" ];
smileyArray.standard = [
"smilenew", "i/cnfy7elqh8dotnsdp", "lol", "neutral_new", "afraid", "freddus_pacman", "auslachen2", "kolobok-sanduhr", "bussi2", "winken4", "flucht2", "panik4", "ins-auge-stechen",
"seb_zunge", "fluch4_GREEN", "baby_junge2", "blush-reloaded6", "frown", "verlegen", "blush-pfeif", "stevieh_rolleyes", "daumendreh2", "baby_taptap",
"sadnew", "hust", "confusednew", "idea2", "irre", "irre4", "sleep", "candle", "nicken", "no_sad",
"thumbs-up_new", "thumbs-down_new", "bravo2", "oh-no2", "kaffee2", "drunk", "saufen", "freu-dance", "hecheln", "headstand", "rollsmiliey", "eazy_cool01", "motz", "cuinlove", "biggrin"
];
smileyArray.nature = [
"dinosaurier07", "flu-super-gau", "ben_cat", "schwein", "hundeleine01", "blume", "ben_sharky", "ben_cow", "charly_bissig", "gehirnschnecke_confused", "mttao_fische", "mttao_angler",
"insel", "fliegeschnappen", "i/cifohy0y1cl7nckzw", /* Spinne */ "i/cifogx34asrswrcjw", /* Schiffbrüchiger */ "plapperhase", "ben_dumbo"
];
smileyArray.grepolis = [
"mttao_wassermann", "i/cigrmpfofys5xtiks", /* Hera */ "i/cifvfsu3e2sdiipn0", /* Medusa */ "i/cigmv8wnffb3v0ifg", /* Mantikor */ "i/cigrqlp2odi2kqo24", /* Zyklop */
"i/cj1l9gndtu3nduyvi", /* Minotaurus */ "i/cj2byjendffymp88t", /* Pegasus */ "i/cj2ccmi2x8mhcoikd", /* Hydra */
"silvester_cuinlove", "mttao_schuetze", "kleeblatt2", "wallbash", /* "glaskugel4", */ "musketiere_fechtend", /* "krone-hoch",*/ "i/cifojb85jytq5h07g", // Wikinger
"mttao_waage2", "steckenpferd", /* "kinggrin_anbeten2", */ "i/cifohielywpedbyh8", /* Grepo Love */ "skullhaufen", "pferdehaufen" // "i/ckajscggscw4s2u60"
];
smileyArray.people = [
"seb_hut5", "opa_boese2", "star-wars-yoda1-gruen", "hexefliegend", "snob", "seb_detektiv_ani", "seb_cowboy", "devil", "segen", "pirat5", "borg", "hexe3b",
"i/cifoqe3geok0jco5o", // Ägypter
"i/ciforgs313z0ae1cc", // Hippie
"eazy_polizei", "stars_elvis", "mttao_chefkoch", "nikolaus", "pirate3_biggrin", "batman_skeptisch", "tubbie1", "tubbie2", "tubbie3", "tubbie4"
];
smileyArray.other = [
"steinwerfen", "herzen02", "scream-if-you-can", "kolobok", "headbash", "liebeskummer", "bussi", "brautpaar-reis", "grab-schaufler2", "boxen2", "aufsmaul",
"sauf", "mttao_kehren", "sm", "weckruf", "klugscheisser2", "karte2_rot", "dagegen", "party","dafuer", "outofthebox", "pokal_gold", "koepfler", "transformer"
];
// Replace german sign smilies
if(LID !== "de"){
smileyArray.other[17] = "dagegen2";
smileyArray.other[19] = "dafuer2";
}
// Forum: extra smiley
if($(".editor_textbox_container").get(0)){
smileyArray.grepolis.push("i/ckajscggscw4s2u60");
}
var id = 0, error_count = 0;
var er = false;
// preload images
function loadSmileys(){
for(var e in smileyArray){
if(smileyArray.hasOwnProperty(e)) {
for(var f in smileyArray[e]){
if(smileyArray[e].hasOwnProperty(f)) {
var src = smileyArray[e][f];
smileyArray[e][f] = new Image();
smileyArray[e][f].className = "smiley" + (id++);
smileyArray[e][f].style.margin = '3px';
smileyArray[e][f].style.maxHeight = '35px';
smileyArray[e][f].style.cursor = 'pointer';
if(src.substring(0,2) == "i/" ) {
smileyArray[e][f].src = "http://666kb.com/" + src + ".gif";
} else {
if(er == false){
smileyArray[e][f].src = "http://www.greensmilies.com/smile/smiley_emoticons_" + src + ".gif";
} else {
smileyArray[e][f].src = 'http://s1.directupload.net/images/140128/93x3p4co.gif';
}
}
smileyArray[e][f].onerror = function () {
this.src = 'http://s1.directupload.net/images/140128/93x3p4co.gif';
};
}
}
}
}
}
// Forum smilies
if($(".editor_textbox_container").get(0)){
loadSmileys();
changeForumEditorLayout();
addSmileyBoxForum();
}
function changeForumEditorLayout(){
$('.blockrow').css({ border: "none" });
// Subject/Title
$($('.section div label[for="title"]').parent()).css({ float:"left", width:"36%", marginRight: "20px"});
$($('.section div label[for="subject"]').parent()).css({ float:"left", width:"36%", marginRight: "20px"});
$('.section div input').eq(0).css({ marginBottom: "-10px", marginTop: "10px"});
$('#display_posticon').remove();
// Posticons
$('.posticons table').css({ width: "50%", /*marginTop: "-16px"*/});
$('.posticons').css({ marginBottom: "-16px" });
$('.posticons').insertAfter($('.section div label[for="title"]').parent());
$('.posticons').insertAfter($('.section div label[for="subject"]').parent());
// Posticons hint
$('.posticons p').remove();
// Posticons: No Icon - radio button
$(".posticons [colspan='14']").parent().replaceWith($(".posticons [colspan='14']"));
$(".posticons [colspan='14']").children().wrap("
")
$(".posticons [colspan='14']").appendTo('.posticons tr:eq(0)');
$(".posticons [colspan='4']").remove();
}
function addSmileyBoxForum(){
$('
').insertAfter(".texteditor");
addSmileys("standard", "");
$('.smiley_hr').css({ margin: '3px 0px 0px 0px', color: '#086b18', border: '1px solid' });
$('.smiley_link').css({ color: '#0c450c' });
$('.smiley_link').hover(
function(){$(this).css({ color: '#14999E' });},
function(){$(this).css({ color: '#0c450c' });}
);
$('.smiley_box').css({ maxHeight: '90px', marginLeft: "5px", width: "99%", minHeight:"10px" });
$('.smiley_box_cont').css({ height: '100px', overflow: 'overlay' });
$('.group').css({ color:'#0c450c', marginRight: '10px', cursor:"pointer"}); $('.group[name="standard"]').css({ color:'#089421' });
$('.group').click(function(){
$('.group').each(function(){
$(this).get(0).style.color = '#0c450c';
});
$(this).get(0).style.color = '#089421';
// change smiley group
addSmileys($(this).get(0).name, "");
});
}
// insert smileys from arrays into smiley box
function addSmileys(type, bbcodeBarId){
// reset smilies
if($(bbcodeBarId + " .smiley_box_cont").get(0)) {$(bbcodeBarId + " .smiley_box_cont").get(0).innerHTML='';}
// add smilies
for(var e in smileyArray[type]){
if(smileyArray[type].hasOwnProperty(e)) {
$(smileyArray[type][e]).clone().appendTo(bbcodeBarId + " .smiley_box_cont");
$(bbcodeBarId +" ."+ smileyArray[type][e].className).click(function(){
var textarea;
if(uw.location.pathname === "/game/index"){
// hide smiley box
$(this).closest('.bb_button_wrapper').find(".smiley_button").click();
// find textarea
textarea = $(this).closest('.gpwindow_content').find("textarea").get(0);
} else {
if($('.editor_textbox_container').get(0)) {
textarea = $('.editor_textbox_container .cke_contents textarea').get(0);
} else {
$(this).appendTo('iframe .forum');
}
//$(textarea).val(text.substring(0, $(textarea).get(0).selectionStart) + "[img]"+ $(this).get(0).src + "[/img]" + text.substring($(textarea).get(0).selectionEnd));
}
var text = $(textarea).val();
$(textarea).val(text.substring(0, $(textarea).get(0).selectionStart) + "[img]"+ $(this).get(0).src + "[/img]" + text.substring($(textarea).get(0).selectionEnd));
});
}
}
}
// add smiley box
function addSmileyBox(e){
var bbcodeBarId = "";
switch (e) {
case "/alliance_forum/forum": bbcodeBarId = "#forum";
break;
case "/message/forward": bbcodeBarId = "#message_bbcodes";
break;
case "/message/new": bbcodeBarId = "#message_bbcodes";
break;
case "/message/view": bbcodeBarId = "#message_bbcodes";
break;
case "/player_memo/load_memo_content": bbcodeBarId = "#memo_edit";
break;
}
if(($(bbcodeBarId + ' #emots_popup_7').get(0) || $(bbcodeBarId + ' #emots_popup_15').get(0)) && PID == 84367){
$(bbcodeBarId + " .bb_button_wrapper").get(0).lastChild.remove();
}
$('

').appendTo(bbcodeBarId + ' .bb_button_wrapper');
$('
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
').appendTo(bbcodeBarId + ' .bb_button_wrapper');
$(bbcodeBarId + ' .smiley_button').css({
cursor: 'pointer',
margin:'3px 2px 2px 2px'
});
$(bbcodeBarId + ' .smiley_box').css({
zIndex: '5000',
position: 'absolute',
top: '27px',
left: '430px',
width: '300px',
display: 'none'
});
$(bbcodeBarId + ' .smiley_link').css({
color: '#086b18',
fontSize: '0.6em'
});
$(bbcodeBarId + ' .smiley_hr').css({
margin: '3px 0px 0px 0px',
color: '#086b18',
border: '1px solid'
});
$(bbcodeBarId + ' .group').css({
color:'#0c450c'
});
$(bbcodeBarId + ' .group[name="standard"]').css({
color:'#089421'
});
$(bbcodeBarId + ' .group').click(function(){
$("#"+ $(this).closest('.bb_button_wrapper').parent().get(0).id +' .group').each(function(){
$(this).get(0).style.color = '#0c450c';
});
$(this).get(0).style.color = '#089421';
// change smiley group
addSmileys($(this).get(0).name, "#"+ $(this).closest('.bb_button_wrapper').parent().get(0).id);
});
addSmileys("standard", bbcodeBarId);
// smiley box toggle
$(bbcodeBarId + " .smiley_button").toggle(
function(){
$(this).get(0).src = smileyArray.button[0].src;
$(this).closest('.bb_button_wrapper').find(".smiley_box").get(0).style.display = "block";
},
function(){
$(this).get(0).src = smileyArray.button[1].src;
$(this).closest('.bb_button_wrapper').find(".smiley_box").get(0).style.display = "none";
}
);
}
/*******************************************************************************************************************************
* Biremes counter
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Incremental update when calling a city (experimental, especially intended for siege worlds)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var count, townId, biriArray = JSON.parse(GM_getValue(WID + "_biri_data", "{}"));
function updateBiriCount(){
var sum =0, e;
for(e in biriArray) {
if(biriArray.hasOwnProperty(e)) {
sum += parseInt(biriArray[e], 10);
}
}
if(options.bir){
sum = sum.toString();
var str ="", fsize = ['1.4em', '1.2em', '1.15em', '1.1em', '1.0em'], i;
for(i = 0; i
" + sum[i] + "";
}
$('#bi_count').get(0).innerHTML = "" + str + "";
}
}
function getBiri(){
var biremeIn = parseInt(uw.ITowns.getTown(uw.Game.townId).units().bireme, 10),
biremeOut = parseInt(uw.ITowns.getTown(uw.Game.townId).unitsOuter().bireme, 10);
if(isNaN(biremeIn)) biremeIn = 0;
if(isNaN(biremeOut)) biremeOut = 0;
if(!biriArray[uw.Game.townId] || biriArray[uw.Game.townId] < (biremeIn + biremeOut)) {
biriArray[uw.Game.townId] = biremeIn;
}
updateBiriCount();
saveBiri();
}
function getBiriDocks(){
var windowID = uw.BuildingWindowFactory.getWnd().getID(),
biremeTotal = parseInt($('#gpwnd_' + windowID + ' #unit_order_tab_bireme .unit_order_total').get(0).innerHTML, 10);
if(!isNaN(biremeTotal)) biriArray[uw.Game.townId] = biremeTotal;
updateBiriCount();
saveBiri();
}
function getBiriAgora(){
var biremeTotal = parseInt(uw.ITowns.getTown(parseInt(uw.Game.townId, 10)).units().bireme, 10);
if(isNaN(biremeTotal)) biremeTotal = 0;
$('#units_beyond_list .bireme').each(function(){
biremeTotal += parseInt($(this).get(0).children[0].innerHTML, 10);
});
biriArray[uw.Game.townId] = biremeTotal;
updateBiriCount();
saveBiri();
}
function saveBiri(){
setTimeout(function(){
GM_setValue(WID + "_biri_data", JSON.stringify(biriArray));
}, 0);
}
function initBiri() {
$(".picomap_container").prepend("");
updateBiriCount();
$('#unit_count').css({
background: 'url(http://de.cdn.grepolis.com/images/game/units/units_sprite_90x90_compressed.jpg)',
height: '90px',
width: '90px',
position: 'relative',
margin: '5px 28px 0px 28px',
backgroundPosition: '-270px 0px'
});
$('#sea_id').css({
background: 'none',
fontSize: '25px',
cursor: 'auto',
height: '50px',
width: '50px',
position: 'relative'
});
if($('#tutorial_quest_container').get(0)){
$('#sea_id').prependTo('#tutorial_quest_container');
} else {
$('#sea_id').appendTo('#ui_box');
$('#sea_id').css({
position: 'absolute',
top: '75px',
left: '157px'
});
}
$('#bi_count').css({
color: '#826021',
position: 'relative',
top: '28px',
fontStyle: 'italic',
width: '79px'
});
$('.picomap_overlayer').tooltip(LANG[LID].set.bir[0]);
}
/*******************************************************************************************************************************
* Popups
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Available units (no supporting or outer units)
* | ● Improved favor
* | ● getTownTypes
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var groupUnitArray = {};
// TODO: split Function (getUnits, calcUnitsSum, availableUnits, countBiremes, getTownTypes)?
function getAllUnits(){
var townArray = uw.ITowns.getTowns(), groupArray = uw.ITowns.townGroups.getGroups(),
unitArray = {"sword":0, "archer":0, "hoplite":0, "chariot":0, "godsent":0, "rider":0, "slinger":0, "catapult":0, "small_transporter":0, "big_transporter":0,
"manticore":0, "harpy":0, "pegasus":0, "cerberus":0, "minotaur":0, "medusa":0, "zyklop":0, "centaur":0, "fury":0, "sea_monster":0 },
unitArraySea = {"bireme":0, "trireme":0, "attack_ship":0, "demolition_ship":0, "colonize_ship":0 };
if(uw.Game.is_hero_world){
unitArray = $.extend(unitArray, {"griffin":0, "calydonian_boar":0});
}
unitArray = $.extend(unitArray, unitArraySea);
for(var group in groupArray){
if(groupArray.hasOwnProperty(group)){
// clone Object "unitArray"
groupUnitArray[group] = Object.create(unitArray);
for(var town in groupArray[group]["towns"]){
if(groupArray[group]["towns"].hasOwnProperty(town)){
var type = { lo: 0, ld: 0, so: 0, sd: 0, fo: 0, fd: 0 }; // Type for TownList
for(var unit in unitArray){
if(unitArray.hasOwnProperty(unit)){
// All Groups: Available units
var tmp = parseInt(uw.ITowns.getTown(town).units()[unit], 10);
groupUnitArray[group][unit] += tmp || 0;
// Only for group "All"
if(group == -1){
//Bireme counter
if( unit === "bireme" && ((biriArray[townArray[town].id] || 0) < (tmp || 0))) {
biriArray[townArray[town].id] = tmp;
}
//TownTypes
if(!unitVal[unit].is_naval){
if(unitVal[unit].flying){
type.fd += ((unitVal[unit].def_hack + unitVal[unit].def_pierce + unitVal[unit].def_distance)/3 * (tmp || 0));
type.fo += (unitVal[unit].attack * (tmp || 0));
} else {
type.ld += ((unitVal[unit].def_hack + unitVal[unit].def_pierce + unitVal[unit].def_distance)/3 * (tmp || 0));
type.lo += (unitVal[unit].attack * (tmp || 0));
}
} else {
type.sd += (unitVal[unit].defense * (tmp || 0));
type.so += (unitVal[unit].attack * (tmp || 0));
}
}
}
}
// Only for group "All"
if(group == -1){
// Icon: DEF or OFF?
var z = ((type.sd + type.ld + type.fd) <= (type.so + type.lo + type.fo)) ? "o" : "d",
temp = 0;
for(var t in type){
if(type.hasOwnProperty(t)){
// Icon: Land/Sea/Fly (t[0]) + OFF/DEF (z)
if(temp < type[t]){
autoTownTypes[townArray[town].id] = t[0] + z;
temp = type[t];
}
// Icon: Troops Outside (overwrite)
if(temp < 1000){
autoTownTypes[townArray[town].id] = "no";
}
}
}
// Icon: Empty Town (overwrite)
var popBuilding = 0, buildVal = uw.GameData.buildings, levelArray = townArray[town].buildings().getLevels(),
popTotal = Math.floor(buildVal.farm.farm_factor * Math.pow(townArray[town].buildings().getBuildingLevel("farm"), buildVal.farm.farm_pow)), // Population from farm level
popPlow = townArray[town].researches().attributes.plow ? 200 : 0,
popFactor = townArray[town].buildings().getBuildingLevel("thermal") ? 1.1 : 1.0, // Thermal
popExtra = townArray[town].getPopulationExtra();
for(var b in levelArray){
if(levelArray.hasOwnProperty(b)){
popBuilding += Math.round(buildVal[b].pop * Math.pow(townArray[town].buildings().getBuildingLevel(b), buildVal[b].pop_factor));
}
}
townPopulation[town] = popTotal * popFactor + popPlow + popExtra - (popBuilding + townArray[town].getAvailablePopulation());
if((popTotal * popFactor + popPlow + popExtra - (popBuilding + townArray[town].getAvailablePopulation())) < 300){
autoTownTypes[townArray[town].id] = "po";
}
// Icon: Farm Incomplete
if(townArray[town].buildings().getBuildingLevel("farm") < 40){
//autoTownTypes[townArray[town].id] = "bu";
}
}
}
}
}
}
updateBiriCount();
saveBiri();
//if(options.pop) {
updateAvailableUnitsBox(groupUnitArray[-1]);
//}
}
function addAvailableUnitsBox(){
var groupArray = uw.ITowns.townGroups.getGroups();
$(''+
'
'+
'
'+
'
'+
'
'+ LANG[LID].uni + '
'+
'
'+
'
'+
'
'+
'
'+ groupArray[-1].name +'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
').appendTo('body');
for(var group in groupArray){
if(groupArray.hasOwnProperty(group)){
$('
'+ groupArray[group].name +'
').appendTo('#available_units_box .item-list');
}
}
// Styles
$('#available_units_box .drop_box').css({
float: 'left',
position: 'absolute',
top: '1px',
right: '0px',
width: '90px',
zIndex: '1'
});
$('#available_units_box h4').css({
color: 'rgb(128, 64, 0)',
width: '10px',
height: '25px',
marginLeft: '4px',
lineHeight: '1.9'
});
$('#available_units_box .drop_group').css({
width: '84px'
});
$('#available_units_box .select_group').css({
position: 'absolute',
width: '80px',
display: "none",
right: '3px'
});
//$('#available_units_box .item-list').css({ maxHeight: '400px', maxWidth: '200px', align: "right" });
$('#available_units_box .arrow').css({
width: '18px',
height: '18px',
background: 'url('+ drop_out.src +') no-repeat -1px -1px',
position: 'absolute'
});
// hover effects of the elements in the drop menu
$('#available_units_box .option').hover(
function(){ $(this).css({color: '#fff', background: "#328BF1"}); },
function(){ $(this).css({color: '#000', background: "#FFEEC7"}); }
);
// click events of the drop menu
$('#available_units_box .select_group .option').each(function(){
$(this).click(function(e){
$(this).parent().find(".sel").toggleClass("sel");
$(this).toggleClass("sel");
$('#available_units_box .drop_group .caption').attr("name", $(this).attr("name"));
$('#available_units_box .drop_group .caption').get(0).innerHTML = $(this).get(0).innerHTML;
$('#available_units_box .select_group')[0].style.display = "none";
updateAvailableUnitsBox(groupUnitArray[$(this).attr("name")]);
//$('#available_units_box .drop_group .caption').change();
});
});
// show & hide drop menu on click
$('#available_units_box .drop_group').click(function(){
if($('#available_units_box .select_group')[0].style.display === "none"){
$('#available_units_box .select_group')[0].style.display = "block";
} else {
$('#available_units_box .select_group')[0].style.display = "none";
}
});
$('#available_units_box').click(function(e){
var clicked = $(e.target);
if(!(clicked[0].parentNode.className.split(" ")[1] === "dropdown")){
$('#available_units_box .select_group').get(0).style.display = "none";
}
});
// hover arrow change
$('#available_units_box .dropdown').hover(function(e){
$(e.target)[0].parentNode.childNodes[3].style.background = "url('"+ drop_over.src +"') no-repeat -1px -1px";
}, function(e){
$(e.target)[0].parentNode.childNodes[3].style.background = "url('"+ drop_out.src +"') no-repeat -1px -1px";
});
//$("#available_units_box .drop_group .caption").attr("name", "All");
//$('#available_units_box .drop_group').tooltip();
$('#available_units_box').draggable({
containment: "body",
snap: "body",
});
$('#available_units_box').css({
color: 'rgb(12, 69, 12)',
position: 'absolute',
top: '100px',
left: '200px',
zIndex: getMaxZIndex() + 1,
display: 'none'
});
$('#available_units_box .box_content').css({
background: 'url(http://s1.directupload.net/images/140206/8jd9d3ec.png) 94% 94% no-repeat',
backgroundSize: '140px'
});
$('#available_units_box').bind("mousedown",function(){
$(this).get(0).style.zIndex = getMaxZIndex() + 1;
});
$('#available_units_box hr').css({ margin: '3px 0px 0px', border: '1px solid', color: 'rgb(128, 64, 0)'});
}
function updateAvailableUnitsBox(unitArray){
var i = 0, content = '
';
for(var u in unitArray){
if(unitArray.hasOwnProperty(u)){
if(((i%5 == 0) && (i!== 25)) || u == "bireme") {
content += " |
";
}
content += ' ' + unitArray[u] + ' ';
i++;
}
}
content += ' |
';
$('#available_units_box .box_content').get(0).innerHTML = "";
$('#available_units_box .box_content').append(content);
/*
$('#united_units').css({
height: '300px',
width: '300px',
position: 'relative'
});
*/
}
function unbindFavorPopup(){
$('.gods_favor_button_area, #favor_circular_progress').mouseover();
$('.gods_favor_button_area, #favor_circular_progress').bind('mouseover mouseout', function(){
return false;
});
$('.gods_area').bind('mouseover', function(){
setFavorPopup();
});
}
var godArray = {
zeus: ' 0px', //'http://s1.directupload.net/images/140116/mkhzwush.png',
hera: '-152px', //'http://s1.directupload.net/images/140116/58ob8z82.png',
poseidon: '-101px', //'http://s1.directupload.net/images/140116/dkfxrw2f.png',
athena: ' -50px', //'http://s14.directupload.net/images/140116/iprgopak.png',
hades: '-203px', //'http://s14.directupload.net/images/140116/c9juk95y.png',
artemis: '-305px', //'http://s14.directupload.net/images/140116/pdc8vxe2.png'
};
var godImg = new Image(); godImg.src = "http://s7.directupload.net/images/140118/j5gzsghx.png";
function setFavorPopup(){
var pic_row = "",
fav_row = "",
prod_row = "";
for(var g in godArray){
if(godArray.hasOwnProperty(g)){
if(uw.ITowns.player_gods.attributes.temples_for_gods[g]){
pic_row += '
| ';
fav_row += '
'+ uw.ITowns.player_gods.attributes[g + "_favor"] +' | ';
prod_row += '
'+ uw.ITowns.player_gods.attributes.production_overview[g].production +' | ';
}
}
}
var tool_element = $('
| '+ pic_row +'
'+
' | '+ fav_row +'
'+
'+ | '+ prod_row +'
'+
'
');
$('.gods_favor_button_area, #favor_circular_progress').tooltip(tool_element);
}
/*******************************************************************************************************************************
* GUI Optimization
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Modified spell box (smaller, moveable & position memory)
* | ● Larger taskbar and minimize daily reward-window on startup
* | ● Modify chat
* | ● Improved display of troops and trade activity boxes (movable with position memory on startup)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
// Spell box
function catchSpellBox(){
var spellbox = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
//console.log(mutation);
if(mutation.addedNodes[0]){
//console.log(mutation.addedNodes[0] + " " + mutation.attributeName);
changeSpellBox();
}
});
});
spellbox.observe($('.gods_spells_menu .content').get(0), { attributes: false, childList: true, characterData: false });
}
function initSpellBox(){
var spellbox_top, spellbox_left, spellbox_show;
$('').appendTo('head');
$(".gods_spells_menu").css({
height: $(".nui_units_box").height() +"px"
});
console.log($(".nui_units_box").height());
setTimeout(function(){
spellbox_show = GM_getValue("spellbox_show", false);
// Timeout nicht optimal!!!
setTimeout(function(){
if(spellbox_show) {
$('.btn_gods_spells').click();
}
}, 2500);
}, 0);
$('.btn_gods_spells').click(function(){
spellbox_show = !spellbox_show;
setTimeout(function(){
GM_setValue("spellbox_show", spellbox_show);
}, 0);
});
$('.nui_units_box').css({
display: 'block',
marginTop: '-8px',
position: 'relative'
});
$('.nui_right_box').css({
height: '158px'
});
$('.nui_units_box .bottom_ornament').css({
marginTop: '-28px',
position: 'relative'
});
$('.gods_spells_menu .top').css({
//marginTop: '-28px',
//backgroundPosition: 'right -232px'
});
$('.gods_area').css({
height: '170px'
});
$(".gods_spells_menu").draggable({
containment: "body",
distance: 10 ,
snap: "body, .gods_area, .nui_units_box, .ui_quickbar, .nui_main_menu, .minimized_windows_area, #island_quests_overview",
opacity: 0.7,
stop : function(){
spellbox_top = this.style.top;
spellbox_left = this.style.left;
setTimeout(function(){
GM_setValue("spellbox_top", spellbox_top);
GM_setValue("spellbox_left", spellbox_left);
}, 0);
//console.log(spellbox_top + " " + spellbox_left);
}
});
$(".gods_area .gods_spells_menu").before($('.nui_units_box'));
setTimeout(function(){
spellbox_top = GM_getValue("spellbox_top", "23%");
spellbox_left = GM_getValue("spellbox_left", "-150%");
//console.log(spellbox_top + " " + spellbox_left);
$('.gods_spells_menu').css({
position: 'absolute',
left: spellbox_left,
top: spellbox_top,
zIndex: '5000',
padding: '30px 0px 0px -4px'
});
}, 0);
}
function changeSpellBox(){
$(".gods_spells_menu").css({
height: $(".nui_units_box").height() + "px"
});
console.log($(".nui_units_box").height());
$('.god_container[data-god_id="zeus"]').css({
width: '43px',
float: 'left'
});
$('.god_container[data-god_id="zeus"] .powers_container').css({
background: 'none'
});
$('.god_container[data-god_id="athena"]').css({
width: '85px',
float: 'left'
});
$('.god_container[data-god_id="athena"] .powers_container').css({
background: 'none'
});
$('.content .title').each(function(){
$(this).get(0).remove();
});
//$('.gods_spells_menu .god_container[data-god_id="zeus"]').before('.god_container[data-god_id="poseidon"]');
if($('.bolt').get(0)) $('.bolt').get(0).remove();
if($('.earthquake').get(0)) $('.earthquake').get(0).remove();
if($('.pest').get(0)) $('.pest').get(0).remove();
}
// Minimize Daily reward window on startup
function minimizeDailyReward(){
var startup, daily_reward_minimized = false, town_window = false;
startup = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes[0]){
if($('#new_daily_reward').get(0) && !uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_SHOW_ON_LOGIN).isMinimized()){
uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_SHOW_ON_LOGIN).minimize();
}
}
});
});
startup.observe($('body').get(0), { attributes: false, childList: true, characterData: false});
setTimeout(function(){ startup.disconnect();}, 3000);
}
// Larger taskbar
function scaleTaskbar(){
$('.minimized_windows_area').get(0).style.width= "150%";
$('.minimized_windows_area').get(0).style.left= "-25%";
}
// hide fade out buttons => only for myself
function hideNavElements() {
if((PID == 84367) && (uw.Game.premium_features.curator<=uw.Timestamp.now())){
$('.nav').each(function() {
$(this).get(0).style.display = "none";
});
}
}
/*******************************************************************************************************************************
* Modify Chat
*******************************************************************************************************************************/
function popupChatUser(){
setTimeout(function(){
GM_xmlhttpRequest({
method: "POST",
url: "http://wwwapi.iz-smart.net/modules.php?name=Chaninfo&file=nicks&chan=Grepolis"+ uw.Game.market_id.toUpperCase(),
onload: function(response) {
//$('.nui_main_menu .chat .indicator').get(0).innerHTML =
//console.log(response.responseText);
//$('.nui_main_menu .chat .indicator').get(0).style.display = 'inline';
}
});
}, 0);
}
function initChatUser(){
$('.nui_main_menu .chat .button, .nui_main_menu .chat .name_wrapper').css({
WebkitFilter: 'hue-rotate(65deg)',
filter: 'url(#Hue1)'
});
updateChatUser();
setInterval(function(){ updateChatUser(); }, 300000);
$('.nui_main_menu .chat').mouseover(function(){
//popupChatUser();
});
if($('.nui_main_menu .chat').hasClass('disabled')){ $('.nui_main_menu .chat').removeClass('disabled');}
}
function updateChatUser(){
var market = uw.Game.market_id;
//if(uw.Game.market_id !== 'fr'){
setTimeout(function(){
GM_xmlhttpRequest({
method: "POST",
url: "http://api.relay-chat.de/compteur_js.php?chan="+ (market === "de" ? "Grepolis" + uw.Game.market_id.toUpperCase() : "GREPO"),
onload: function(response) {
$('.nui_main_menu .chat .indicator').get(0).innerHTML = response.responseText.split("'")[1];
$('.nui_main_menu .chat .indicator').get(0).style.display = 'inline';
}
});
}, 0);
//}
}
// Modify chat window
var chat_is_hidden = false, chatwnd_id;
function modifyChat() {
var host = { fr: 'irc.quakenet.org', def: 'flash.afterworkchat.de'}, market = uw.Game.market_id;
setTimeout(function(){ updateChatUser(); }, 10000); setTimeout(function(){ updateChatUser(); }, 30000);
//uw.GPWindowMgr.Create(uw.Layout.wnd.TYPE_CHAT);
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setWidth(300);
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setHeight(0);
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setPosition([0,'bottom']);
//console.log(uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT));
chatwnd_id = '#gpwnd_' + uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).getID();
//$(chatwnd_id).parent().children('.gpwindow_left').remove();
//$(chatwnd_id).parent().children('.gpwindow_right').remove();
//$(chatwnd_id).parent().children('.gpwindow_top').remove();
//$(chatwnd_id).parent().children('.gpwindow_bottom').remove();
//$(chatwnd_id).parent().parent().children('.ui-dialog-titlebar').remove();
var nickname = uw.Game.player_name.replace(/[.,:,+,*]/g,"").replace(/[=,\ ,-]/g,"_").replace(/ö/gi,"oe").replace(/ä/gi,"ae").replace(/ü/gi,"ue").replace(/ß/g,"ss");
nickname = "kνnm";
$('#chat').get(0).innerHTML = "";
$('
').appendTo("#chat");
//$('
').appendTo("#chat");
//$('
').appendTo("#chat");
//$('').appendTo('head');
/*
setTimeout(function(){
console.log("bla");
window.frames[0].document.getElementById('ircui').append("I was modified by JS!");
//$("iframe").contents().find("body").append("I was modified by JS!");
console.log(document.getElementById('web'));
console.log(document.getElementById('ircui'));
var li = document.createElement('li');
}, 5000);
*/
/*
$('.chat_left').css({
height: '190px',
width: '20px',
position: 'absolute',
right: '0px',
//background: 'url(http://s7.directupload.net/images/140410/m8n9eafe.png) no-repeat 2px 50%',
//backgroundSize: '19px 130%'
});
*/
//$(chatwnd_id).animate({ width: "300px"}, 800);
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setHeight(200);
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setPosition([0,'bottom']);
//$('#chat_controls').remove();
/*
$('.btn_hide_chat').toggle(function(){
$(chatwnd_id).parent().parent().animate({ width: "140px", left: "-120px"}, 800);
$(chatwnd_id).animate({ width: "140px"}, 800);
setTimeout(function(){
$('.btn_hide_chat').removeClass('left'); $('.btn_hide_chat').addClass('right');
}, 800);
chat_is_hidden = true;
}, function(){
$(chatwnd_id).parent().parent().animate({ width: "300px", left:"0px"}, 800);
$(chatwnd_id).animate({ width: "300px"}, 800);
setTimeout(function(){
$('.btn_hide_chat').removeClass('right'); $('.btn_hide_chat').addClass('left');
}, 800);
chat_is_hidden = false;
});
*/
//appendTo('.chat_elements');
/*
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
//$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
*/
//uw.Layout.playerProfile.open('Diony');
//uw.Layout.allianceProfile.open(69);
// Hide Chat in the menu
/*
setTimeout(function(){
$('.chat').get(0).remove();
$('.nui_main_menu .content ul').get(0).style.height = ($('.nui_main_menu .content ul').height() - 34) + "px";
},0);
*/
}
/*
$(window).resize(function() {
//uw.GPWindowMgr.getOpenFirst(uw.Layout.wnd.TYPE_CHAT).setPosition(['0px','bottom']);
if(chat_is_hidden){
//$(chatwnd_id).parent().parent().css({ left:"-120px"});
} else {
//$(chatwnd_id).parent().parent().css({ left:"0px"});
}
});
*/
/*******************************************************************************************************************************
* Activity boxes
* ----------------------------------------------------------------------------------------------------------------------------
* | ● Show troops and trade activity boxes
* | ● Boxes are magnetic & movable (position memory)
* ----------------------------------------------------------------------------------------------------------------------------
*******************************************************************************************************************************/
var box_standard = { trade: { top: 55, left: 450 }, commands : { top: 55, left: 250 } }, mut_toolbar, mut_command, mut_trade;
box = JSON.parse(GM_getValue("box", JSON.stringify(box_standard)));
function checkToolbarAtStart(){
if(parseInt($('.toolbar_activities .commands .count').get(0).innerHTML, 10) > 0){
$('#toolbar_activity_commands_list').get(0).style.display = "block";
} else {
$('#toolbar_activity_commands_list').get(0).style.display = "none";
}
if(parseInt($('.toolbar_activities .trades .count').get(0).innerHTML, 10) > 0){
$('#toolbar_activity_trades_list').get(0).style.display = "block";
} else {
$('#toolbar_activity_trades_list').get(0).style.display = "none";
}
}
function catchToolbarEvents(){
mut_toolbar = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes[0]){
//console.log(mutation);
if(mutation.target.id === "toolbar_activity_trades_list"){
draggableTradeBox();
} else {
draggableCommandBox();
}
mutation.addedNodes[0].remove();
}
});
});
mut_command = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes[0]){
if(mutation.addedNodes[0].nodeValue > 0){
$('#toolbar_activity_commands_list').get(0).style.display = "block";
} else {
$('#toolbar_activity_commands_list').get(0).style.display = "none";
}
}
});
});
mut_trade = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if(mutation.addedNodes[0]){
if(mutation.addedNodes[0].nodeValue > 0){
$('#toolbar_activity_trades_list').get(0).style.display = "block";
} else {
$('#toolbar_activity_trades_list').get(0).style.display = "none";
}
}
});
});
}
// moveable boxes
function draggableTradeBox(){
$("#toolbar_activity_trades_list").draggable({
containment: "body",
distance: 20,
snap: "body, .gods_area, .nui_units_box, .ui_quickbar, .nui_main_menu, .minimized_windows_area, .nui_left_box",
opacity: 0.7,
start : function () {
$("#fix_trade").remove();
},
stop : function () {
var pos = $('#toolbar_activity_trades_list').position();
box.trade.left = pos.left;
box.trade.top = pos.top;
setTimeout(function(){
GM_setValue("box", JSON.stringify(box));
}, 0);
$('').appendTo('head');
}
});
}
function draggableCommandBox(){
$("#toolbar_activity_commands_list").draggable({
containment: "body",
distance: 20,
snap: "body, .gods_area, .nui_units_box, .ui_quickbar, .nui_main_menu, .minimized_windows_area, .nui_left_box",
opacity: 0.7,
stop : function () {
var pos = $('#toolbar_activity_commands_list').position();
box.commands.left = pos.left;
box.commands.top = pos.top;
setTimeout(function(){
GM_setValue("box", JSON.stringify(box));
}, 0);
}
});
}
function showCommandsAndTrades(){
var observe_options = { attributes: false, childList: true, characterData: false};
catchToolbarEvents();
mut_toolbar.observe($('#toolbar_activity_commands_list').get(0), observe_options );
mut_toolbar.observe($('#toolbar_activity_trades_list').get(0), observe_options );
mut_command.observe($('.toolbar_activities .commands .count').get(0), observe_options );
mut_trade.observe($('.toolbar_activities .trades .count').get(0), observe_options );
$('#toolbar_activity_commands').mouseover();
$('#toolbar_activity_trades').mouseover();
$('#toolbar_activity_commands, #toolbar_activity_trades').unbind("mouseover");
$('#toolbar_activity_commands, #toolbar_activity_commands_list, #toolbar_activity_trades, #toolbar_activity_trades_list').unbind("mouseout");
$('#toolbar_activity_trades_list').unbind("click");
checkToolbarAtStart();
$('#toolbar_activity_commands_list').css({
left: box.commands.left + "px",
top: box.commands.top + "px"
});
$(''+
'').appendTo('head');
draggableCommandBox();
draggableTradeBox();
$('.toolbar_activities .commands').mouseover(function(){
$('#toolbar_activity_commands_list').get(0).style.display = "block";
});
$('.toolbar_activities .trades').mouseover(function(){
$('#toolbar_activity_trades_list').get(0).style.display = "block";
});
}
/*******************************************************************************************************************************
* Other stuff
*******************************************************************************************************************************/
function counter(time){
var type = "", today, counted, year, month, day;
if(uw.Game.market_id !== "zz"){
setTimeout(function(){
counted = JSON.parse(GM_getValue("Counter",'[ "00000000", false ]'));
today = new Date((time + 7200) * 1000);
year = today.getUTCFullYear();
month = ((today.getUTCMonth()+1) < 10 ? "0" : "") + (today.getUTCMonth()+1);
day = (today.getUTCDate() < 10 ? "0" : "") + today.getUTCDate();
today = year + month + day;
console.log(today);
if(counted[0] !== today){type += "d"; }
if(counted[1] == false){ type += "t"; }
if(type !== ""){
setTimeout(function(){
GM_xmlhttpRequest({
method: "GET",
url: "http://grepodio.heliohost.org/count.php?type="+ type + "&market="+ uw.Game.market_id + "&date="+ today,
onload: function(response) {
//console.log(response.responseText);
if(response.responseText.indexOf("tot") > -1){
counted[1] = true;
}
if(response.responseText.indexOf("dly") > -1){
counted[0] = today;
}
setTimeout(function(){
GM_setValue("Counter", JSON.stringify(counted));
}, 0);
}
});
}, 0);
}
},0);
}
}
/*
function xmas(){
$('
').appendTo('#ui_box');
$('#xmas').css({
background: 'url("http://www.greensmilies.com/smile/smiley_emoticons_weihnachtsmann_nordpol.gif") no-repeat',
height: '51px',
width: '61px',
position:'absolute',
bottom:'10px',
left:'60px',
zIndex:'2000'
});
$('#xmas').tooltip("HO HO HO, Frohe Weihnachten!");
}
function silvester(){
$('
').appendTo('#ui_box');
$('#silv').css({
//background: 'url("http://www.greensmilies.com/smile/buchstaben_0.gif") no-repeat',
//height: '57px',
//width: '34px',
position:'absolute',
bottom:'10px',
left:'70px',
zIndex:'10'
});
$('#silv').tooltip("Frohes Neues!");
}
function joke(){
setTimeout(function(){
if($('#grcgrc').get(0)){
$('
').appendTo('#ui_box');
$('#fight').css({
background: 'url("http://www.greensmilies.com/smile/smiley_emoticons_hoplit_speer4.gif") no-repeat',
height: '51px',
width: '61px',
position:'absolute',
bottom:'10px',
left:'39px',
zIndex:'2000'
});
$('#fight').tooltip("WWW.GREENSMILIES.COM");
}
}, 5000);
}
*/