// -Numlock-
var version = "1.3";
var word_unit_speed = 0; //a világ egységsebessége
var word_speed = 0; //a világ sebessége
//audio
var sound;//a hangjelzéshez az interválok beállításához/leállításához
var snd= null;
var mp = 0;
var difference; //a kh és a gép órájának az eltérése, későbbi kalkuláláshoz
var gameTimeIsMore; //true/false, későbbi kulkuláláshoz
var basic_units_url = "https://dshu.innogamescdn.com/asset/8edf6f3/graphic/unit/unit_";
var units_speeds ={"spear": 18,"sword": 22,"axe": 18,"archer": 18,"spy": 9,"light": 10,"marcher": 10,"heavy": 11,"ram": 30,"catapult": 30,"knight": 10,"snob": 35};
var village_units = {}; //az egységek eltárolása
var all_targets = 0; //cp kordik összszámban(HTML elementek id-jéhez)
var calculations = []; // tömb ami majd tárolni fogja az összes indítás teljes adatait
var village_groups; //a a falucsoportnevek és data-id ik lementéséhez
var saved_groups = {}; //a village_groups tároló csoportok falutartalmainak a lekérése után eltárolja a script hogy ne keljen ismételten majd lekérni
var registry = {}; //nyílvántartás a tervezés folyamán a színezésekhez, parancs összegek kiiratásához a html optionokhoz
var coords_of_all_villages = [];
var names_of_all_villages = [];
var sounds = [];
var groupp = [], // az alsó 3 egy asynchronos ajax loophoz kell, ami betölti a falvakat a csoportokból amk le voltak mentve
ident = [],
progress = 0;
var storage_keys;
//sound DB
function playsound(id){
if(snd!=null) snd.pause();
let ind= sounds.findIndex((sound)=>{return sound.id==id});
if(ind==-1) return
snd = new Audio(sounds[ind].base64);
snd.play();
}
function toBase64(file){
return new Promise((resolve, reject) => {
console.log(file);
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
});
}
async function soundInputChanged(){
const file = document.querySelector('#soundInp').files[0];
let res = await toBase64(file)
let sound={
id:new Date().getTime().toString(),
name:file.name,
size:file.size,
type:file.type,
base64:res
}
await soundDb.saveSound(sound);
sounds = await soundDb.loadSounds(sound);
renderSounds();
}
function renderSounds(){
$('#choosed_sound').html(`
${sounds.map((sound)=>{
return `<option value="${sound.id}">${sound.name}</option>`
}).join('')}
`);
}
class soundDB {
db;
inited=false;
async init(){
this.db = await this.loadDB();
console.log("loaded sound DB ");
this.inited=true;
}
async checkInit(){
if(!this.inited)
await this.init();
}
async loadSounds(){
await this.checkInit();
return new Promise(async (resolve,reject)=>{
if (!this.db.objectStoreNames.contains('sounds')){
resolve([]);
return;
}
let transSounds = this.db.transaction("sounds");
let reqSounds = await transSounds.objectStore("sounds").getAll();
reqSounds.onsuccess= () =>{
resolve(reqSounds.result.map((sound)=> JSON.parse(sound.data)))
}
})
}
async saveSound(sound){
await this.checkInit();
let transaction = this.db.transaction("sounds", "readwrite");
await transaction.objectStore("sounds").put({id:sound.id,data:JSON.stringify(sound)});
}
async removeSound(id){
await this.checkInit();
let transaction = this.db.transaction("sounds", "readwrite");
await transaction.objectStore("sounds").delete(id);
}
async loadDB(){
return new Promise((resolve,reject)=>{
let openRequest = indexedDB.open("TW_SOUND", 1);
openRequest.onupgradeneeded = function() {
let db = openRequest.result;
if (!db.objectStoreNames.contains('sounds'))
db.createObjectStore('sounds', {keyPath: 'id', autoIncrement: false});
openRequest.onsuccess = function() {
resolve(openRequest.result);
};
};
openRequest.onsuccess = function() {
resolve(openRequest.result);
};
openRequest.onerror = function() {
console.error("Error", openRequest.error);
throw new Error(openRequest.error.message);
};
})
}
}
var soundDb = new soundDB();
//sitter
dep = "";
if(document.location.href.indexOf("?t=") > -1){//helyettesítés alatt van??
dep = document.location.href.match(/t=\d+/)[0];
}
if(document.location.href.indexOf("game.php?") > -1){
//firssítésekkel kapcsolatos értesítés ha új verzió jelenik meg
if(localStorage.getItem("plannerStorage") == null){
console.log("remove");
set_default_storageKeys();
if(localStorage.getItem("plannerversion") != null){
localStorage.removeItem("plannerversion"); // a kövi verzióig az előző verzió key-t töröljük azoknál akik használják a scriptet
if(confirm("Új verzió! A script 80%-ában történtek változtatások illetve kibővítések. A fórumon a main témában a leírás/használati utasítás teljesen át lett írva. Részletek a fórumon, az 'Ok' gombra kattintva a script elnavigál oda.")){
window.open("https://forum.klanhaboru.hu/index.php?threads/csoportos-t%C3%A1mad%C3%A1sszervez%C5%91-ind%C3%ADt%C3%A1si-asszisztens.5084/");
}
}
}
if(document.location.href.indexOf(document.location.host + "/game.php?" + dep + "village=" + game_data.village.id + "&screen=overview_villages&mode=units&type=own_home&group=0&page=-1&type=own_home") > -1){
//---------------
if(document.location.host.indexOf("hu67") > -1){
word_unit_speed = 0.62;
word_speed = 1.6;
}else if(document.location.host.indexOf("hu68") > -1){
word_unit_speed = 1;
word_speed = 1;
}else if(document.location.host.indexOf("hu69") > -1){
word_unit_speed = 1;
word_speed = 2;
}else if(document.location.host.indexOf("hu71") > -1){
word_unit_speed = 0.625;
word_speed = 1.6;
}else if(document.location.host.indexOf("hu62") > -1){
word_unit_speed = 0.8;
word_speed = 1.2;
}else if(document.location.host.indexOf("hu63") > -1){
word_unit_speed = 0.5;
word_speed = 2;
}else{
var key = document.location.host.match(/\w+\d+/)[0];
if(localStorage.getItem(key + "word") == null){
if (window.confirm("A script nem rendelkezik a világ/egység sebességekkel, ezek nélkül a számítgatások hibásak lesznek. A folytatás előtt, kérlek add meg ezeket. Az 'Ok' gombra kattintva a script egy új lapon elnavigál a világ beállításainak a weboldalára, ahonnan ezeket az adatokat megtalálhatod és megadhatod a script számára.")){
speedToScrn();
}
}else{
word_speed = parseFloat(localStorage.getItem(key + "word"));
word_unit_speed = parseFloat(localStorage.getItem(key + "unit"));
}
}
//---------------
storage_keys = JSON.parse(localStorage.getItem("plannerStorage"));
readUnits();
get_allGroup();
read_village_groups();
create_controller();
create_tooltip();
refresh_filter_event_listeners();
pretty_part();
actualizing_settings();
}else if(document.location.href.indexOf("screen=memo") > -1){
memo_assistant();
}else{
document.location.href = "https://" + document.location.host + "/game.php?" + dep + "village=" + game_data.village.id + "&screen=overview_villages&mode=units&type=own_home&group=0&page=-1&type=own_home";
}
}
function pretty_part(){
$(".top_bar").css({"background-image": "url(https://indexrprogs.netlify.com/tst_img.png)", "text-align": "center"});
$(".top_bar").html(`<label class = 'scriptName'>Attack planner</label> <label class = 'scriptVersion'>v1.3</label>
<br>
<input class = "butt" type="button" value = "Használati útmutató" onclick= "help_page()">
<input class = "butt" type="button" value = "Kibeszélő" onclick= "discuss_page()">
<input class = "butt speed_form" type="button" value = "Világ/egységsebesség" onclick= "speedToScrn()">
<input class = "butt" type="button" value = "Project Export/Import" onclick= "project_saver_loader()">`);
//<input class = "butt" type="button" value = "Auto szervezés" onclick= "RPA_form()" style = "color: cyan;">
$("body").css("background-position", "");
$("#menu_row").html("");
$("body").append("<style>a{color: #1f2c2f}</style>");
}
function discuss_page(){
window.open("https://forum.klanhaboru.hu/index.php?threads/csoportos-t%C3%A1mad%C3%A1sszervez%C5%91-ind%C3%ADt%C3%A1si-asszisztens.5090/");
}
function help_page(){
window.open("https://forum.klanhaboru.hu/index.php?threads/csoportos-t%C3%A1mad%C3%A1sszervez%C5%91-ind%C3%ADt%C3%A1si-asszisztens.5084/");
}
async function memo_assistant(){
sounds = await soundDb.loadSounds();
$("#content_value").prepend(`<div class = "content-border" style = "margin-bottom: 10px; padding: 5px;">
<label style = "color: #603000;"><b>Hang file hozzáadása: </b></label>
<input id="soundInp" onchange="soundInputChanged()" type="file" accept=".mp3"/><br>
<label style = "color: #603000;"><b>A még indítandó parancsok száma: </b></label><b><span id = "launches" style = "color: #603000;">0</span></b><br>
<label style = "color: #603000;"><b>Válassz hangjelzést: </b></label>
<select id = "choosed_sound" size = "1" style = "width: 100px; border-radius: 4px;">
${sounds.map((sound)=>{
return `<option value="${sound.id}">${sound.name}</option>`
}).join('')}
</select>
<input id = "testSound" class = "butt" type = "button" value = "Teszt"><input id = "delSound" class = "butt" type = "button" value = "Törlés"><br>
<input id = "notif_time" type = "number" value = "5" style = "width: 30px; border-radius: 4px; margin-bottom: 5px;">
<label for = "notif_time" style = "color: #603000;"> <b>- percel indítás előtt jelezzen</b></label><br>
<input id = "notif_during" type = "number" value = "40" style = "width: 30px; border-radius: 4px;">
<label for = "notif_during" style = "color: #603000;"> <b>- másodpercen keresztül jelezzen majd kapcsoljon ki (ha nem kapcsolod le manuálisan)</b></label><br>
<label class = "wrong_commands" style = "color: red;" hidden><b>Figyelem! Hibás parancsok lettek észlelve a táblázatban! Ezeket a parancsokat a script figyelmen kívül fogja hagyni</b></label><br>
<input id = "setit" class = "butt" type = "button" value = "Élesítés">
<input id = "stop_play" class = "stopbutt" type = "button" value = "Elhallgattat" hidden>
<style>.butt{margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px lime;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.butt:hover {background-color:#68e431;}.butt:active{position:relative;top:1px;}.stopbutt{margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px yellow;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.stopbutt:hover {background-color:yellow;}.stopbutt:active{position:relative;top:1px;}</style>
</div>`);
//indítások beolvasása és az eltérések figyelembe vétele
var game_time = new Date();
game_time.setFullYear(parseInt($("#serverDate").text().match(/\d+/g)[2]));
game_time.setMonth(parseInt($("#serverDate").text().match(/\d+/g)[1]) - 1);
game_time.setDate(parseInt($("#serverDate").text().match(/\d+/g)[0]));
game_time.setHours(parseInt($("#serverTime").text().match(/\d+/g)[0]));
game_time.setMinutes(parseInt($("#serverTime").text().match(/\d+/g)[1]));
game_time.setSeconds(parseInt($("#serverTime").text().match(/\d+/g)[2]));
if(game_time > new Date()){
var dif_date = new Date(game_time - new Date());
difference = dif_date.getTime();
gameTimeIsMore = true;
}else{
var dif_date = new Date(new Date() - game_time);
difference = dif_date.getTime();
gameTimeIsMore = false;
}
var tables = $(".bbcodetable");
for(var y = 0; y < tables.length; y++){
//ellenőrzés hogy a táblázat a script által generált-e
if($(".bbcodetable").eq(y).find("tr").eq(0).find("th").length != 7 && $(".bbcodetable").eq(y).find("tr").eq(0).text().indexOf("Innen") < 0){
continue;
}
var rows = $(tables[y]).find("tr");
$(rows[0]).prepend(`<th></th>`);
for(var x = 1; x < rows.length; x++){
//gyorsgomb létrehozása a gyülekezőhelyhez
var from = $(rows[x]).find("td").eq(1).find("a").eq(0).attr("href");
var to = $(rows[x]).find("td").eq(2).find("a").eq(0).attr("href");
//ha a cp kordi nem létezik
if(to == undefined){
$(".wrong_commands").prop("hidden", false);
$(rows[x]).prepend(`<td></td>`);
$(rows[x]).find("td").eq(3).attr("style", "background: orangered;");
$(rows[x]).find("td").eq(6).attr("style", "background: orangered;");
$(rows[x]).find("td").eq(7).attr("style", "background: orangered;");
continue;
}
from = from.match(/\d+/g)[1];
to = to.match(/\d+/g)[1];
$(rows[x]).prepend(`<td><a class = "quick_open" title = "/game.php?village=${from}&screen=place&target=${to}" href = "javascript:;"><img src = "https://dshu.innogamescdn.com/asset/bf21430/graphic//buildings/place.png"></a></td>`);
//a még indítandók kiszűrése és az indítottak zöldelése
var launch = $(tables[y]).find("tr").eq(x).find("td").eq(7).text();
console.log(launch);
console.log(launch.match(/\d+/g));
var llaunch_time = new Date();
llaunch_time.setFullYear(parseInt(launch.match(/\d+/g)[0]));
llaunch_time.setMonth(parseInt(launch.match(/\d+/g)[1]) - 1);
llaunch_time.setDate(parseInt(launch.match(/\d+/g)[2]));
llaunch_time.setHours(parseInt(launch.match(/\d+/g)[3]));
llaunch_time.setMinutes(parseInt(launch.match(/\d+/g)[4]));
llaunch_time.setSeconds(parseInt(launch.match(/\d+/g)[5]));
var time_now = new Date();
if(gameTimeIsMore){
time_now.setMilliseconds(time_now.getMilliseconds() + difference);
if(llaunch_time > time_now){
calculations.push({launch:llaunch_time.getTime(), table: y, row: x});
}else{
$(tables[y]).find("tr").eq(x).find("td").eq(7).attr("style", "background: lime;");
}
}else{
time_now.setMilliseconds(time_now.getMilliseconds() - difference);
if(llaunch_time > time_now){
calculations.push({launch:llaunch_time.getTime(), table: y, row: x});
}else{
$(tables[y]).find("tr").eq(x).find("td").eq(7).attr("style", "background: lime;");
}
}
}
}
$("#launches").text(calculations.length);
//$(".image_place").attr("style", "background-image: url(https://dshu.innogamescdn.com/asset/bf21430/graphic//buildings/place.png);");
$("a.quick_open").click(function(){
window.open("https://" + document.location.host + $(this).attr("title"));
});
$("#delSound").click(async function(){
soundDb.removeSound($("#choosed_sound").val())
sounds = await soundDb.loadSounds(sound);
renderSounds();
});
$("#testSound").click(function(){
playsound($("#choosed_sound").val())
});
$("#choosed_sound").change(function(){
playsound($("#choosed_sound").val())
});
$("#setit").click(function(){
if(parseInt($("#launches").text()) == 0){
UI.ErrorMessage("Nem talható egyetlen még indítás előtt álló parancs sem ami a script által volt generálva táblázat formában!", 5000);
}else if(parseInt($("#notif_during").val()) / 60 > parseInt($("#notif_time").val())) {
UI.ErrorMessage("A hangjelzési folyamat nem tarthat " + $("#notif_during").val() + " másodpercen keresztül mert az már meghaladja az indítás pillanatát is. Az élesítés visszavonva...", 5000);
}else{
calculations.sort(function(a, b){return a.launch - b.launch});
$(this).attr("style", "background: red;");
$(this).attr("value", "Élesítve!");
sound = setInterval(checkForLaunch, 5000);
$("head > title").text(">>Élesítve<<");
}
});
$("#stop_play").click(function(){
$("td[style='background: yellow;']").attr("style", "background: lime;");
$(this).prop("hidden", true);
calculations.shift();
$("#launches").text(calculations.length);
mp = 0;
})
}
function checkForLaunch(){
if(calculations.length == 0){
$("#setit").attr("style", "background: #6c4824;");
$("#setit").attr("value", "Élesítés!");
clearInterval(sound);
$("head > title").text(">>Befejezett<<");
return;
}
var time = new Date(); // 13:58:00
time.setMinutes(time.getMinutes() + parseInt($("#notif_time").val()))
if(gameTimeIsMore){
time.setMilliseconds(time.getMilliseconds() + difference);
}else{
time.setMilliseconds(time.getMilliseconds() - difference);
}
var send_time = new Date(calculations[0].launch); // 13:56:00
if(send_time < time){
$(".bbcodetable").eq(calculations[0].table).find("tr").eq(calculations[0].row).find("td").eq(7).attr("style", "background: yellow;");
playsound($("#choosed_sound").val())
$("#stop_play").prop("hidden", false);
mp += 5;
}
if(mp >= parseInt($("#notif_during").val())){
$(".bbcodetable").eq(calculations[0].table).find("tr").eq(calculations[0].row).find("td").eq(7).attr("style", "background: red;");
$("#stop_play").prop("hidden", true);
calculations.shift();
$("#launches").text(calculations.length);
mp = 0;
}
}
function return_auto_saved_projects(){
/*[{"date": 222-22-22
"target_length" : 33
"commands_length"
"to_load": {}
}]*/
var list_of_saves = storage_keys.auto_saves;
var html = "";
if(list_of_saves.length == 0){
return "<option class = 'auto_save_option' value = 'empty'>Nincsenek mentések</option>"
}
for(var x = 0; x < list_of_saves.length; x++){
html += `<option class = "auto_save_option" value = "${list_of_saves[x]["date"]}">${list_of_saves[x]["date"] + " Célpontok:" + list_of_saves[x]["target_length"] + " Parancsok:" + list_of_saves[x]["commands_length"]}</option>`
}
return html;
}
function swith_to_auto_saves(){
if($("#switcher").val() == "Auto mentések"){
$("#switcher").val("Manuál mentések");
$("#imp_exp_text").css("display", "none");
$("#auto_saved_projects_list").css("display", "inline");
$("#importt").attr("onclick", `project_import('selected')`);
$("#exportt").css("display", "none");
$("#imp_exp_help").text("Válassz mentést és katt az Import gombra");
}else{
$("#switcher").val("Auto mentések");
$("#imp_exp_text").css("display", "inline");
$("#auto_saved_projects_list").css("display", "none");
$("#importt").attr("onclick", `project_import('user')`);
$("#exportt").css("display", "inline");
$("#imp_exp_help").text("Illeszd be az előzőleg exportált Projectet ha be szeretnéd Importálni, majd kattints az Import gombra, vagy az Export gombra ha lementeni szeretnéd a tervezést, és a lementendő szöveg a szövegmezőben megjelenik.");
}
}
function project_saver_loader(){
$("body").append(`<div id = "automation_form" style = "width: 728px; border: 1px solid black; margin: 5px; padding: 10px; position: fixed; top: 50px; background-color: #edd8ad;">
<label id = "imp_exp_help">Illeszd be az előzőleg exportált Projectet ha be szeretnéd Importálni, majd kattints az Import gombra, vagy az Export gombra ha lementeni szeretnéd a tervezést, és a lementendő szöveg a szövegmezőben megjelenik.</label>
<br>
<textarea id = "imp_exp_text" rows="10" cols="100" style = "border-radius: 5px; margin: 5px; display: inline;"></textarea>
<select id = "auto_saved_projects_list" size = "4" style = "margin: 5px; width: 270px; border-radius: 4px; display: none;">${return_auto_saved_projects()}</select>
<br>
<input id = "importt" class = "butt" type="button" value = "Import" onclick= "project_import('user')">
<input id = "exportt" class = "butt" type="button" value = "Export" onclick= "project_export()">
<input id = "switcher" class = "butt" type="button" value = "Auto mentések" onclick= "swith_to_auto_saves()">
<input class = "butt" type="button" value = "Bezárás" onclick= "project_imp_exp_close()">
</div>`);
}
function project_import(type){
var imp_storage,
arrayy = "";
if(type == "selected"){ // ha automentést töltünk be
var which_array = $(".auto_save_option:selected").val();
if(which_array == undefined || which_array == "empty"){
UI.ErrorMessage("A betöltés nem lehetésges. Válassz egy mentést!", 2000);
return;
}
for(var x = 0; x < storage_keys.auto_saves.length; x++){
if(storage_keys.auto_saves[x]["date"] == which_array){
arrayy = storage_keys.auto_saves[x]["to_load"];
}
}
}else if(type == "user"){ // ha manuál mentést töltünk be
if($("#imp_exp_text").val() == ""){UI.ErrorMessage("Nincs mit importálni!", 2000); return;}
arrayy = $("#imp_exp_text").val();
}
try{
imp_storage = JSON.parse(arrayy);
}catch(exp){
UI.ErrorMessage("A lementett tervezés sérült, nem lehetséges a beimportálása.", 3000);
return;
}
if($("#targets_container").html() != ""){
if(! confirm("Figyelem, az eddigi tervezéseid el fognak veszni! Biztosan folytatod?")){
return;
}
//$("#targets_container").html("");
}
registry = {};
all_targets = imp_storage.target_id.length + imp_storage.empty_targets.length;
//Valamit tartalmazó célpontok
for(var x = 0; x < imp_storage.target_id.length; x++){
if($(`#${imp_storage.target_id[x]}`).length == 0){
$("#targets_container").append(`<div id = "${imp_storage.target_id[x]}" class = "target" style = "padding-bottom: 3px; margin-bottom: 10px; padding-left: 5px; border: 0.5px solid #4e2d05; border-radius: 3px;">
<p><span style = "color: black;"><b>${imp_storage.target_infos[x]}</b></span></p>
<a href = "javascript:;" onclick = "newAttacker(${imp_storage.target_id[x].replace("target", "")})">Új parancs hozzáadása</a>
<br>
<a class = "delete_target" href = "javascript:;">Célpont törlése</a>
</div>`);
}
$(`#${imp_storage.target_id[x]}`).append(`<div class = "command_container">
<span > Innen </span>
<select class = "villages_drop_down" size = "1" style = "width: 150px; border-radius: 4px;" disabled>
<option value = "${imp_storage.drop_downs[x]}" selected>${imp_storage.drop_downs_text[x]}</option>
</select> Típus
<select class = "command_type" size = "1" style = "width: 100px; margin-top: 3px; margin-bottom: 2px; border-radius: 4px;" disabled>
<option value = "${imp_storage.types[x]}" selected>${imp_storage.types[x]}</option>
</select>
<span > Leglassabb egység </span>
<select class = "slowest_unit" size = "1" style = "width: 100px; border-radius: 4px;" >
${default_option_group("slowest")}
</select>
<span > Gyorsító </span>
<select class = "accelerator" size = "1" style = "width: 45px; border-radius: 4px;" >
${default_option_group("accelerator")}
</select>
<a class= "delete_attacker" href = "javascript:;">Törlés</a>
</div>`);
// slowest lepipálása
$(`#${imp_storage.target_id[x]}`).find(".slowest_unit:last").children(`option[value="${imp_storage.slowests[x]}"]`).prop("selected", true);
$(`#${imp_storage.target_id[x]}`).find(".accelerator:last").children(`option[value="${imp_storage.accelerators[x]}"]`).prop("selected", true);
if(registry[imp_storage.drop_downs[x] + imp_storage.types[x]] == undefined){
registry[imp_storage.drop_downs[x] + imp_storage.types[x]] = 1;
}else{
registry[imp_storage.drop_downs[x] + imp_storage.types[x]] += 1;
}
}
//Üres célpontok
for(var x = 0; x < imp_storage.empty_targets.length; x++){
$("#targets_container").append(`<div id = "${imp_storage.empty_targets[x]}" class = "target" style = "padding-bottom: 3px; margin-bottom: 10px; padding-left: 5px; border: 0.5px solid #4e2d05; border-radius: 3px;">
<p><span style = "color: black;"><b>${imp_storage.empty_target_infos[x]}</b></span></p>
<a href = "javascript:;" onclick = "newAttacker(${imp_storage.empty_targets[x].replace("target", "")})">Új parancs hozzáadása</a>
<br>
<a class = "delete_target" href = "javascript:;">Célpont törlése</a>
</div>`);
}
// és a vége
$("#targets_container").find("p").css({"background-color": "#c1a264 !important", "background-image": "url(https://indexrprogs.netlify.com/hidden_header_aqua.png)", "background-repeat": "repeat-x", "cursor": "pointer", "position" : "relative", "left": "-2px", "padding-left": "5px"});
refresh_event_listeners(); //egy funkció ami a gombnyomásra történő eseményeket kezeli / annak a frissítése
}
function project_export(type){
if($(".villages_drop_down").length == 0 && $(".target").length == 0){UI.ErrorMessage("Nincs mit exportálni!", 3000);return}
var exp_storage = {"target_id": [], "target_infos": [], "drop_downs": [], "drop_downs_text": [], "types": [], "slowests": [], "accelerators": [], "empty_targets": [], "empty_target_infos": []};
var picked_commands = $(".villages_drop_down");
$(".villages_drop_down").each(function(){
exp_storage.target_id.push($(this).parent().parent().attr("id"));
exp_storage.target_infos.push($(this).parent().siblings("p").text());
exp_storage.drop_downs.push($(this).val());
var index_of_name = coords_of_all_villages.indexOf($(this).val());
exp_storage.drop_downs_text.push(names_of_all_villages[index_of_name]);
exp_storage.types.push($(this).siblings(".command_type").val());
exp_storage.slowests.push($(this).siblings(".slowest_unit").val());
exp_storage.accelerators.push($(this).siblings(".accelerator").val());
});
//üres cp-k eltárolása
var targets = $(".target");
$(targets).each(function(){
if(exp_storage.target_id.indexOf($(this).attr("id")) < 0){
exp_storage.empty_targets.push($(this).attr("id"));
exp_storage.empty_target_infos.push($(this).children("p").text());
}
});
//for autosave
if(type == "autosave"){
return JSON.stringify(exp_storage);
}
//for user
$("#imp_exp_text").text(JSON.stringify(exp_storage));
}
function project_imp_exp_close(){
$("#automation_form").remove();
}
function manual_planner_saving(){
if($(".villages_drop_down").length == 0 && $(".target").length == 0){UI.ErrorMessage("Nincs mit lementeni!", 3000);return}
if(storage_keys.auto_saves.length == 4){ // mivel csak 3-at menthetünk le, ezért ha már 3 van, akkor a legrégebbit töröljük
storage_keys.auto_saves[0] = storage_keys.auto_saves[1];
storage_keys.auto_saves[1] = storage_keys.auto_saves[2];
storage_keys.auto_saves[2] = storage_keys.auto_saves[3];
storage_keys.auto_saves.splice(3, 1);
}
var data_for_save = {"date": "", "target_length": 0, "commands_length": 0, "to_load": {}};
var nw_date = new Date();
data_for_save.date = nw_date.getFullYear() + "-" + (nw_date.getMonth() + 1) + "-" + nw_date.getDate() + " " + nw_date.getHours() + ":" + nw_date.getMinutes() + ":" + nw_date.getSeconds();
data_for_save.target_length = $(".target").length;
data_for_save.commands_length = $(".command_container").length;
data_for_save.to_load = project_export("autosave");
storage_keys.auto_saves.push(data_for_save);
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
UI.SuccessMessage("Mentve!", 2000);
}
function read_village_groups(){
var group_items = $(".group-menu-item"); //falucsoport begyűjtése az oldalról a legördülő listákhoz
var optionss = "";
for(var x = 0; x < group_items.length; x++){
optionss += `<option value="${group_items[x].getAttribute("data-group-id")}">${group_items[x].innerText}</option>`;
}
village_groups = optionss + '<option value="0" selected = "selected">Minden falu</option>';
}
//vezérlőpanel létrehozása(html)
function create_controller(){
$("#paged_view_content > table").eq(1).after(`<div id="main_script">
<div id = "targets_container" class = "vis_item" style = "margin-bottom: 10px;"></div>
<label style = "color: #603000;"><b><i>Koordináta/ták: </b></i></label>
<input id = "target_coord" type = "text" placeholder = "123,456 vagy 789|111" style = "width: 110px; text-align: center; border-radius: 4px; color: #603000;">
<label style = "color: #603000;"><i><b> Érkezés: </b></i></label>
<input id = "arriving_time" type = "text" placeholder = "éééé-hh-nn óó:pp:mp:ms" value = "${new Date().getFullYear() + "-" + parseInt(new Date().getMonth() + 1) + "-" + new Date().getDate() + " " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds() + ":000"}" style = "width: 150px; text-align: center; border-radius: 4px; color: #603000;">
<label style = "color: #603000;"><i><b> Jegyzet: </b></i></label>
<input id = "note_for_target" type = "text" placeholder = "Éles, vagy akármi" style = "width: 100px; text-align: center; border-radius: 4px; color: #603000; margin-bottom: 10px;">
<input class = "butt" type="button" value = "Hozzáadás" onclick= "addNewTargets()">
<br>
<a href = "javascript:;" onclick = "calculateLaunches()">Az indítások kiszámolása és a táblázat generálása</a>
<br>
<a href = "javascript:;" onclick = "manual_planner_saving()">Tervezés lementése</a>
<br>
<a class = "filterr" href = "javascript:;">Szűrési beállításokat mutat/elrejt</a>
<br>
<div id = "filtering" hidden>
<br>
<table id = "for_types" class = "vis" style="width: 100%;">
<tr><th colspan="7">A parancs típusokhoz tartozó szűrők és kisegítő lehetőségek</th></tr>
<tr>
<th>Parancs típus</th>
<th>Falu csoport</th>
<th>Korlát</th>
<th>Jelző szín</th>
<th>Leglassabb unit</th>
<th>Gyorsító</th>
<th></th>
</tr>
${listing_the_command_types()}
<tr>
<th>Új hozzáadás:</th>
<td colspan = "6">
<input id = "new_type_name" type = "text" placeholder = "Típus név" style = "width: 110px; text-align: center; border-radius: 4px; color: #603000;">
<input id= "add_new_type" class = "butt" type="button" value = "Hozzáadás">
</td>
</tr>
<tr>
<th colspan = "7"></th>
</tr>
<tr>
<th rowspan = "3">
A falu listák
<br>
rendezése
</th>
<td colspan = "6">
<input identif = "0" class = "vill_sorting_radio" type = "radio" name="vill_sorting"> a legközelebbitől a legtávolabbiig
</td>
</tr>
<tr>
<td colspan = "6">
<input identif = "1" class = "vill_sorting_radio" type = "radio" name="vill_sorting"> alapértelmezzetten
</td>
</tr>
<tr>
<td colspan = "6">
<input identif = "2" class = "vill_sorting_radio" type = "radio" name="vill_sorting"> a legtávolabbitól a legközelebbiig
</td>
</tr>
</table>
</div>
<style>#targets_container{background-color: #ecd6ad;}.scriptName{font-family: "Comic Sans MS", cursive, sans-serif;font-size: 20px;letter-spacing: -0.4px;word-spacing: 2.6px;color: white;font-weight: 800;text-decoration: none solid rgb(68, 68, 68);font-style: normal;text-transform: none;}.scriptVersion{font-family: "Comic Sans MS", cursive, sans-serif;font-size: 15px;letter-spacing: -0.4px;word-spacing: 2.6px;color: white;font-weight: 800;text-decoration: none solid rgb(68, 68, 68);font-style: normal;text-transform: none;}.butt{margin: 0px 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px black,inset 0px 3px 5px #ff7e00;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.butt:hover {background-color:peru;}.butt:active{position:relative;top:1px;}</style>
<br>
</div>`);
$(".filterr").click(function(){$("#filtering").toggle(1000)}); //a szűrő megjelenítése és elrejtése kattintásra
UI.SuccessMessage("A script sikeresen futtatva!", 2000);
}
function listing_the_command_types(){
var html = "";
for(var x = 0; x < storage_keys.filter.saved_command_types.length; x++){
html += `<tr><td><b>${storage_keys.filter.saved_command_types[x]}</b></td>
<td>
<select identif = "${storage_keys.filter.saved_command_types[x]}" class = "type_for" size = "1" style = "width: 100px; border-radius: 4px;">${village_groups}</select>
</td>
<td>
<input identif = "${storage_keys.filter.saved_command_types[x]}" class = "color_under_for" type = "number" value = "${storage_keys.filter.saved_command_types_under[storage_keys.filter.saved_command_types[x]]}" style = "width: 30px; border-radius: 4px;">
</td>
<td>
<input identif = "${storage_keys.filter.saved_command_types[x]}" class = "color_for" type="color" value="${storage_keys.filter.saved_command_types_color[storage_keys.filter.saved_command_types[x]]}">
</td>
<td>
<select identif = "${storage_keys.filter.saved_command_types[x]}" class = "slowest_for" size = "1" style = "width: 80px; border-radius: 4px;">${default_option_group("slowest")}</select>
</td>
<td>
<select identif = "${storage_keys.filter.saved_command_types[x]}" class = "accelerator_for" size = "1" style = "width: 45px; border-radius: 4px;">${default_option_group("accelerator")}</select>
</td>
<td>
<a identif = "${storage_keys.filter.saved_command_types[x]}" class = "remove_type" href="javascript:;">Törlés</a>
</td></tr>`}
return html;
}
//új cp koordináta hozzáadása
function addNewTargets(){
// a "all_targets" változó a létrehozandó cp sorszáma
// a "coords" változó a hozzáadandó koordinátának az eltárolásárara szolgál illetve az azokhoz majd tartozó támadó falvaid
var coordinates = $("#target_coord").val();
if(coordinates == ""){
return;
}
var coord1 = coordinates.match(/\d+\|\d+/g);
var coord2 = coordinates.match(/\d+,\d+/g);
try{for(var x = 0; x < coord2.length; x++){coord2[x] = coord2[x].replace(",", "|")}}catch(ex){}
//visszavont prompt
if(coord1 == undefined && coord2 == undefined){
alert("'" + coordinates + "' -ban nem sikerült a koordinátát/kat kiszűrni. Kérlek, ellenőrízd hogy a feltételeknek megfelelően írtad-e be azt/azokat.");
return;
}
//nincs benne koord.
if(coord1 == null && coord2 == null){
alert("'" + coordinates + "' -ban nem sikerült a koordinátát/kat kiszűrni. Kérlek, ellenőrízd hogy a feltételeknek megfelelően írtad-e be azt/azokat.");
return;
}
var arrival = $("#arriving_time").val();
if(arrival == ""){
return;
}
try{
arrival = arrival.match(/\d+-\d+-\d+\s+\d+:\d+:\d+:\d+/)[0];
}catch{
alert("'" + $("#arriving_time").val() + "' -ban nem sikerült az érkezési dátumot és időt kiszűrni. Kérlek, ellenőrízd hogy a feltételeknek megfelelően írtad-e be.");
return;
}
var note = $("#note_for_target").val();
if(coord1 != null && coord2 != null){
for(var x = 0; x < coord2.length; x++){
coord1.push(coord2[x]);
insertTargets(coord1, coord1.length, arrival, note);
}
}else if(coord2 != null){
insertTargets(coord2, coord2.length, arrival, note);
}else if(coord1 != null){
insertTargets(coord1, coord1.length, arrival, note);
}
$("#target_coord").val("");
$("#note_for_target").val("");
}
function insertTargets(targets, lengthh, arrival, note){
for(var x = 0; x < lengthh; x++){
var title = document.createElement("p");
title.innerHTML = "<span style = 'color: black;'><b>" + targets[x] + " " + arrival + " " + note + "</b></span>";
var target_inner_container = document.createElement("div");
target_inner_container.setAttribute("id", "target" + all_targets);
target_inner_container.setAttribute("class", "target");
target_inner_container.setAttribute("style", "padding-bottom: 3px; margin-bottom: 10px; padding-left: 5px; border: 0.5px solid #4e2d05; border-radius: 3px;");
var delete_container = document.createElement("a");
delete_container.setAttribute("href", "javascript:;");
delete_container.setAttribute("class", "delete_target");
delete_container.innerText = "Célpont törlése";
var new_attacker = document.createElement("a");
new_attacker.setAttribute("href", "javascript:;");
new_attacker.setAttribute("onclick", "newAttacker(" + all_targets + ")");
new_attacker.innerText = "Új parancs hozzáadása";
document.getElementById("targets_container").appendChild(target_inner_container);
document.getElementById("target" + all_targets).appendChild(title);
target_inner_container.appendChild(new_attacker);
target_inner_container.innerHTML += "<br>";
target_inner_container.appendChild(delete_container);
all_targets++;
//a cp koordináta adatainak a kiszínezése
$("#targets_container").find("p").css({"background-color": "#c1a264 !important", "background-image": "url(https://indexrprogs.netlify.com/hidden_header_aqua.png)", "background-repeat": "repeat-x", "cursor": "pointer", "position" : "relative", "left": "-2px", "padding-left": "5px"});
refresh_event_listeners(); //egy funkció ami a gombnyomásra történő eseményeket kezeli / annak a frissítése
}
}
function newAttacker(container){
var target_inner_container = document.getElementById("target" + container);
$("#target" + container).append(`<div class = "command_container">
<span > Innen </span><select class = "empty_villages" size = "1" style = "width: 150px; border-radius: 4px;" ></select> Típus
<select class = "inactive_type" size = "1" style = "width: 100px; margin-top: 3px; margin-bottom: 2px; border-radius: 4px;">
${return_command_types_for_select()}
</select>
<span > Leglassabb egység </span>
<select class = "slowest_unit" size = "1" style = "width: 100px; border-radius: 4px;" >
${default_option_group("slowest")}
</select>
<span > Gyorsító </span>
<select class = "accelerator" size = "1" style = "width: 45px; border-radius: 4px;" >${default_option_group("accelerator")}</select>
<a class= "delete_attacker" href = "javascript:;">Törlés</a>
</div>
`);
refresh_event_listeners(); //egy funkszió ami a gombnyomásra történő eseményeket kezeli / annak a frissítése
}
function RPA_form(){
// a falucsoportok beolvasása
var group_items = $(".group-menu-item"); //falucsoport begyűjtése az oldalról a legördülő listákhoz
var optionss = "";
for(var x = 0; x < group_items.length; x++){
optionss += `<option value="${group_items[x].getAttribute("data-group-id")}">${group_items[x].innerText}</option>`;
}
//----
$("body").append(`<div id = "automation_form" style = "border: 1px solid black; margin: 5px; padding: 10px; position: fixed; top: 100px; background-color: #edd8ad;">
A parancsokhoz, ebből a csoportból keressen falukat
<select size = "1" id = "automation_for_nukes" style = "width: 150px; border-radius: 4px; margin-bottom: 3px;">${optionss}<option value = "empty" disabled selected>-Válassz-</option></select>
<br>
Célpontonkénti kívánt nuke parancs mennyiség: <input id="automation_nuke_number" type="number" value="2" style="width: 40px;">
<br><br>
<table class="vis">
<tr>
<th colspan = "2">
Falvak felhasználása, ahol min. ennyi tanyahelynyi egység van
</th>
</tr>
<tr>
<td colspan = "2">
<span class="icon header population"> </span>
<input id="min_space_nuke" type="number" value="20100" style="width: 50px;">
vagy <img src="https://dshu.innogamescdn.com/asset/f98fa6f/graphic/unit/unit_axe.png" title="Bárdos">
<input id="min_space_nuke_axe" type="number" value="6500" style="width: 40px;">
<img src="https://dshu.innogamescdn.com/asset/f98fa6f/graphic/unit/unit_light.png" title="Bárdos">
<input id="min_space_nuke_light" type="number" value="2700" style="width: 40px;">
<img src="https://dshu.innogamescdn.com/asset/f98fa6f/graphic/unit/unit_ram.png" title="Bárdos">
<input id="min_space_nuke_ram" type="number" value="400" style="width: 35px;">
<img src="https://dshu.innogamescdn.com/asset/f98fa6f/graphic/unit/unit_catapult.png" title="Bárdos">
<input id="min_space_nuke_catapult" type="number" value="100" style="width: 35px;">
</td>
</tr>
<tr>
<th colspan = "2">
Indítással kapcsolatos beállítások:
</th>
</tr>
<tr>
<td colspan = "2">
<input id="forbit_time" type="checkbox">
Ilyen idők közé ne essen indítás
<input id="min_forbid_time" type="text" value="23:30:00" style="width: 60px;" disabled> -
<input id="max_forbid_time" type="text" value="05:00:00" style="width: 60px;" disabled>
</td>
</tr>
<tr>
<td rowspan="3">
Szervezés
</td>
<td>
<input id="from_min" name="distance" type="radio"> a legközelebbi falvaktól
</td>
</tr>
<tr>
<td>
<input id="from_whatever" name="distance" type="radio" checked> keverten
</td>
</tr>
<tr>
<td>
<input id="from_max" name="distance" type="radio"> a legtávolabbi falvaktól
</td>
</tr>
</table>
</div>`);
}
function calculateLaunches(){
//számolások előtti ellenőrzések
var ss = parseInt($("#for_types").find("option[value='empty']:selected").length);
$("div[style='background: red;']").removeAttr("style");
if($("select.villages_drop_down").length < 1){
UI.ErrorMessage("Parancsok nélkül nincs mit számolni...", 3000);
return;
}
if($("option[value='empty']:selected").length - ss > 0){
$("option[value='empty']:selected").parent().parent(".command_container").attr("style", "background: red;");
UI.ErrorMessage("Nem töltöttél ki minden parancsot", 3000);
return;
}
if(word_unit_speed == 0 || word_speed == 0){
if (window.confirm("Nem adtad meg a világ és az egység sebességeket. Ezek nélkül a script nem tud indításokat számolni. Szeretnéd őket megadni most?")){
speedToScrn();
return;
}else{
return;
}
}
var err;
$(".command_type").each(function(){
if($(this).children("option:selected").val().indexOf("nemes") > -1 && $(this).siblings(".slowest_unit").children("option:selected").text().indexOf("Nemes") == -1){
err = "nemes";
}
if($(this).children("option:selected").val().indexOf("Nuke") > -1 && $(this).siblings(".slowest_unit").children("option:selected").text().indexOf("Kos") == -1){
err = "nuke";
}
if($(this).children("option:selected").val().indexOf("Kos") > -1 && $(this).siblings(".slowest_unit").children("option:selected").text().indexOf("Kos") == -1){
err = "kosfake";
}
if($(this).children("option:selected").val().indexOf("Fake") > -1 && $(this).siblings(".slowest_unit").children("option:selected").text().indexOf("Kos") == -1){
err = "simafake";
}
});
if(err == "nemes" && window.confirm("Figyelmeztetés!\nEgy vagy több nemeses típusú parancsnál nem a 'Nemes' van kiválasztva leglassabb egységként! Biztosan folytatod?") == false){
return;
}else if(err == "nuke" && window.confirm("Figyelmeztetés!\nEgy vagy több 'Nuke' típusú parancsnál nem a 'Kos' van kiválasztva leglassabb egységként! Biztosan folytatod?") == false){
return;
}else if(err == "kosfake" && window.confirm("Figyelmeztetés!\nEgy vagy több 'Kos fake vonat' típusú parancsnál nem a 'Kos' van kiválasztva leglassabb egységként! Biztosan folytatod?") == false){
return;
}else if(err == "simafake" && window.confirm("Figyelmeztetés!\nEgy vagy több 'Fake' típusú parancsnál nem a 'Kos' van kiválasztva leglassabb egységként! Biztosan folytatod?") == false){
return;
}
// auto_save
if(storage_keys.auto_saves.length == 4){ // mivel csak 3-at menthetünk le, ezért ha már 3 van, akkor a legrégebbit töröljük
storage_keys.auto_saves[0] = storage_keys.auto_saves[1];
storage_keys.auto_saves[1] = storage_keys.auto_saves[2];
storage_keys.auto_saves[2] = storage_keys.auto_saves[3];
storage_keys.auto_saves.splice(3, 1);
}
var data_for_save = {"date": "", "target_length": 0, "commands_length": 0, "to_load": {}};
var nw_date = new Date();
data_for_save.date = nw_date.getFullYear() + "-" + (nw_date.getMonth() + 1) + "-" + nw_date.getDate() + " " + nw_date.getHours() + ":" + nw_date.getMinutes() + ":" + nw_date.getSeconds();
data_for_save.target_length = $(".target").length;
data_for_save.commands_length = $(".command_container").length;
data_for_save.to_load = project_export("autosave");
storage_keys.auto_saves.push(data_for_save);
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
// az indításonkénti adatok kiszámítása és eltárolása a calculations változó tömbbe
var targets = document.getElementsByClassName("target");
for(var current_target = 0; current_target < targets.length; current_target++){
var attackers = targets[current_target].getElementsByClassName("villages_drop_down");
var types = targets[current_target].getElementsByClassName("command_type");
var slowests = targets[current_target].getElementsByClassName("slowest_unit");
var accelerators = targets[current_target].getElementsByClassName("accelerator");
var full_data = $(".target").eq(current_target).children("p").text();
var target_coord = {x:"",y:""};
target_coord.x = full_data.match(/\d+/g)[0];
target_coord.y = full_data.match(/\d+/g)[1];
var target_arrival = full_data.match(/\d+-\d+-\d+\s+\d+:\d+:\d+:\d+/)[0];
var arrival_year, arrival_month, arrival_day, arrival_hour, arrival_minute, arrival_second, arrival_millisecond;
arrival_year = target_arrival.match(/\d\d\d\d/)[0];
arrival_month = target_arrival.match(/\d+/g)[1];
arrival_day = target_arrival.match(/\d+/g)[2];
arrival_hour = target_arrival.match(/\d+/g)[3];
arrival_minute = target_arrival.match(/\d+/g)[4];
arrival_second = target_arrival.match(/\d+/g)[5];
arrival_millisecond = target_arrival.match(/\d+/g)[6];
if(arrival_month.length == 1){arrival_month = "0" + arrival_month;}
if(arrival_day.length == 1){arrival_day = "0" + arrival_day;}
if(arrival_hour.length == 1){arrival_hour = "0" + arrival_hour;}
if(arrival_minute.length == 1){arrival_minute = "0" + arrival_minute;}
if(arrival_second.length == 1){arrival_second = "0" + arrival_second;}
if(arrival_millisecond.length == 1){arrival_millisecond = "00" + arrival_millisecond;}
if(arrival_millisecond.length == 2){arrival_millisecond = "0" + arrival_millisecond;}
for(var current_attacker = 0; current_attacker < attackers.length; current_attacker++){
// az érkezési dátum és idő eltárolása
var date = new Date();
date.setFullYear(parseInt(arrival_year));
date.setMonth(parseInt(arrival_month) - 1);
date.setDate(parseInt(arrival_day));
date.setHours(parseInt(arrival_hour));
date.setMinutes(parseInt(arrival_minute));
date.setSeconds(parseInt(arrival_second));
date.setMilliseconds(parseInt(arrival_millisecond));
//az indítással kapcsolatos teljes információjának a létrehozása
var launch_info = {
from: attackers[current_attacker].options[attackers[current_attacker].selectedIndex].value,
to: target_coord.x + "|" + target_coord.y,
type: types[current_attacker].options[types[current_attacker].selectedIndex].value,
slowest: slowests[current_attacker].options[slowests[current_attacker].selectedIndex].value,
arriving: arrival_year + "-" + arrival_month + "-" + arrival_day + "\n" + arrival_hour + ":" + arrival_minute + ":" + arrival_second + ":" + arrival_millisecond,
launch: 0 // lentebbről számol és beilleszt
};
//honnan és hová koordináták
var from_x, from_y, to_x, to_y;
from_x = launch_info.from.match(/\d+/g)[0];
from_y = launch_info.from.match(/\d+/g)[1];
to_x = target_coord.x;
to_y = target_coord.y;
//leglassabb kiválasztott egység / gyorsító
var accelerator = "0." + accelerators[current_attacker].options[accelerators[current_attacker].selectedIndex].value;
accelerator = parseFloat(accelerator);
var slwest_speed = units_speeds[launch_info.slowest.replace(".png", "")];
// a koordináták közti mezőbeli távolság
var distance = Math.sqrt(Math.pow(from_x - to_x, 2) + Math.pow(from_y - to_y, 2));
//az utazási idő kiszámítása milliszekundumban
var travel_time_in_millisec = (slwest_speed / word_speed / (word_unit_speed + (word_unit_speed * accelerator))) * distance * 60 * 1000;
// az érkezési dátumból való utazási idő levonása ami az indítás időpontját jelképezi majd
date.setMilliseconds(date.getMilliseconds() - travel_time_in_millisec);
launch_info.launch = date.getTime();
//az indítással kapcsolatos teljes információjának lementése a változó tömbben, ami majd a táblázat létrehozásához kellesz
calculations.push(launch_info);
}
}
//a változó tömbben indítási sorrendbe rakjuk a parancsokat
calculations.sort(function(a, b){return a.launch - b.launch});
generateTableText();// a szöveges táblázat létrehozása
}
function generateTableText(){
//mert 1 jegyzetbe csak 70 parancs fér
var needed_tables = Math.ceil(calculations.length / 50);
if(needed_tables > 1){
alert("Figyelem! A jegyzetben egy lapon egyszerre csak 1000 db '[' és ']' ilyen karakterek lehetnek. A szervezésed parancs mennyisége túl nagy, egy táblázatban nem fogod tudni az összes parancsot a jegyzetben egy lapra lementeni, mert a KH nem fogja hagyni hogy lementsd. Ezért a script " + needed_tables + " db táblázatot fog neked most kiadni. Ezeket a jegyzetben külön lapokra kell elmentened. Ha az asszisztenst is használni kívánod majd, akkor az majd magának betölti az összes lapon lévő táblázatot.");
}
$(".textarea").remove();
$(".copyT").remove();
var progr = 1;
for(var y = 0; y < needed_tables; y++){
//szöveg tároló html element és a az indítások táblázat létrehozása szöveg formában
var full_text = "[table][**][||]Innen[||]Ide[||]Típus[||][||]Csapódás[||]Indítás[/**]";
for(var x = 0; 0 < calculations.length && x < 50;x++){
var next = calculations[0];
var date = new Date(next.launch);
var month = (date.getMonth() + 1).toString(),
datee = date.getDate().toString(),
hour = date.getHours().toString(),
minute = date.getMinutes().toString(),
sec = date.getSeconds().toString();
if(month.length == 1){month = "0" + month;}
if(datee.length == 1){datee = "0" + datee;}
if(hour.length == 1){hour = "0" + hour;}
if(minute.length == 1){minute = "0" + minute;}
if(sec.length == 1){sec = "0" + sec;}
full_text += `[*][b]#${progr}[/b][|][coord]${next.from}[/coord][|][coord]${next.to}[/coord][|]${next.type}[|][img]${basic_units_url + next.slowest}[/img][|]${next.arriving}[|][b]${date.getFullYear()}-${month}-${datee}\n${hour}:${minute}:${sec}[/b]`;
progr++;
calculations.shift();
}
full_text += "[/table]";
$("#targets_container").append(`
<textarea class = "table${y} textarea" rows="10" cols="100" style = "border-radius: 5px;" hidden>${full_text}</textarea>
<br>
<button class = "copyT copyT${y}" onclick = "copyLaunches(${y})">Kimásolás</button><br>
<style>.copyT{margin: 5px; margin-bottom: 15px; backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px lime;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.copyT:hover {background-color:#68e431;}.copyT:active{position:relative;top:1px;}</style>`);
$(".table" + y).toggle(2000);
}
}
function get_sorted_villages(group_number, target_coord){
var splitted_target = target_coord.split("|");
var sort_identif = $(".vill_sorting_radio:checked").attr("identif");
console.log(sort_identif);
var to_sort = saved_groups[group_number].join("wer");
to_sort = to_sort.split("wer");
if(sort_identif == "0"){ // a legközelebbítől a legtávolabbiig
console.log("0");
to_sort.sort(function(a, b){
var coord_a = a.match(/\d+/g),
coord_b = b.match(/\d+/g),
dist_a = Math.sqrt(Math.pow(coord_a[0] - splitted_target[0], 2) + Math.pow(coord_a[1] - splitted_target[1], 2)),
dist_b = Math.sqrt(Math.pow(coord_b[0] - splitted_target[0], 2) + Math.pow(coord_b[1] - splitted_target[1], 2));
return dist_a - dist_b;
});
return "<option value = 'empty' selected disabled>-Válassz-</option>" + to_sort.join();
}else if(sort_identif == "2"){ // a legtávolabbitól a legközelebbiig
console.log("2");
to_sort.sort(function(a, b){
var coord_a = a.match(/\d+/g),
coord_b = b.match(/\d+/g),
dist_a = Math.sqrt(Math.pow(coord_a[0] - splitted_target[0], 2) + Math.pow(coord_a[1] - splitted_target[1], 2)),
dist_b = Math.sqrt(Math.pow(coord_b[0] - splitted_target[0], 2) + Math.pow(coord_b[1] - splitted_target[1], 2));
return dist_b - dist_a;
});
return "<option value = 'empty' selected disabled>-Válassz-</option>" + to_sort.join();
}else{ // alapértelmezett
console.log("1");
return "<option value = 'empty' selected disabled>-Válassz-</option>" + to_sort.join();
}
}
async function refresh_event_listeners(){
//a cp koordináta törlése
$(".delete_target").unbind('click');
$(".delete_target").click(function(){
$(this).parent().remove();
var contained_commands = $(this).siblings(".command_container");
$(contained_commands).each(function(){
if($(this).children(".villages_drop_down").length != 0){
var coord = $(this).children(".villages_drop_down").val(),
type = $(this).children(".command_type").val();
registry[coord + type] -= 1;
}
});
refresh_info_about_villages();
});
//parancs törlése
$("a.delete_attacker").unbind('click');
$("a.delete_attacker").click(function(){
$(this).parent().remove();
if($(this).siblings(".villages_drop_down").length != 0){
var coord = $(this).siblings(".villages_drop_down").val(),
type = $(this).siblings(".command_type").val();
registry[coord + type] -= 1;
}
refresh_info_about_villages();
});
//a cp koordináta adatainak megváltoztatása
$("p").unbind('click');
$("p").click(function(){
var current_text = $(this).text();
var new_text = prompt("Végezd el az igényelt változtatásokat.", current_text);
if(new_text != undefined){// a prompt nem került visszavonásra
var coord1 = new_text.match(/\d+\|\d+/);
var coord2 = new_text.match(/\d+,\d+/);
var arrival = new_text.match(/\d+-\d+-\d+\s+\d+:\d+:\d+:\d+/);
if(coord1 == null && coord2 == null){
alert("'" + new_text + "' - ben " + "nem sikerült a koordinátát kiszűrni, vagyis nem felel meg egy engedélyezett sablonnak sem ('xxx|yyy' vagy 'xxx,yyy'), ezért a változtatások nem kerülnek mentésre.");
return;
}else if(arrival == null || arrival == undefined){
alert("'" + new_text + "' - ben " + "nem sikerült az érkezési dátumot és időt kiszűrni, vagyis nem felel meg az engedélyezett sablonnak ('éééé-hh-nn óó:pp:mp:ms'), ezért a változtatások nem kerülnek mentésre.");
return;
}
}else{// a promptot visszavonták
return;
}
$(this).html("<span style = 'color: black;'><b>" + new_text + "</b></span>");
UI.SuccessMessage("Mentve!", 500);
});
$(".inactive_type").unbind('change');
$(".inactive_type").change(function(){
var identif = $(this).children("option:selected").val();
var group_number = storage_keys.filter.selected_group_for_command_type[identif];
$(this).siblings(".empty_villages").html(get_sorted_villages(group_number, $(this).parent().siblings("p").text().match(/\d+\|\d+/g)[0]));
$(this).siblings(".slowest_unit").find(`option[value='${storage_keys.filter.selected_slowest_for_command_type[identif]}']`).prop("selected", true);
$(this).siblings(".accelerator").find(`option[value='${storage_keys.filter.selected_accelerator_for_command_type[identif]}']`).prop("selected", true);
$(this).siblings(".empty_villages").attr("class", "under_choose");
$(this).prop("disabled", true);
//---------------------------------------Next_Step
/*/a leglassabb egység autokipipálás
if($(this).children("option:selected").val() == "Nuke" || $(this).children("option:selected").val() == "Fake" || $(this).children("option:selected").val() == "Kos fake vonat"){
$(this).siblings(".slowest_unit").children("option").eq(8).attr("selected", "selected");
}else if($(this).children("option:selected").val().indexOf("nemes") > -1){ //erősítésen kívül, minden más az nemes
$(this).siblings(".slowest_unit").children("option").eq(11).attr("selected", "selected");
}*/
refresh_event_listeners();
refresh_info_about_villages();
});
$(".under_choose").unbind('change');
$(".under_choose").change(function() {
$(this).attr("size", "1");
$(this).attr("class", "villages_drop_down");
$(this).prop("disabled", true);
$(this).siblings(".inactive_type").attr("class", "command_type");
var type = $(this).siblings(".command_type").children("option:selected").val();
var coord = $(this).val();
if(registry[coord + type] != undefined){
registry[coord + type] += 1;
}else{
registry[coord + type] = 1;
}
refresh_event_listeners();
refresh_info_about_villages();
});
$(".under_choose").unbind('mouseenter mouseleave mouseover mouseout');
$(".under_choose").hover(function(){
$(this).attr("size", "15");
},function(){ // leave hover
$(this).attr("size", "1");
});
$(".under_choose").children().unbind('mouseenter mouseleave mouseover mouseout');
$(".under_choose").children().hover(function(){
$("#script_tooltip").css("display", "inline");
var target_coord = $(this).parent().parent().siblings("p").text().match(/\d+\|\d+/g)[0],
coord = $(this).val(),
arriv_time = $(this).parent().parent().siblings("p").text().match(/\d+:\d+:\d+:\d+/g)[0],
arriv_date = $(this).parent().parent().siblings("p").text().match(/\d+-\d+-\d+/g)[0],
accelerator = "0." + $(this).parent().siblings(".accelerator").val();
arriv_date = arriv_date.split("-");arriv_date = arriv_date.join(":");
var arriving = arriv_date + ":" + arriv_time;
refresh_tooltip_units_in_village(coord);
set_tooltip_travel_time(coord, target_coord, accelerator);
set_tooltip_launch_time(coord, target_coord, arriving, accelerator);
},function(){ // leave hover
$("#script_tooltip").css("display", "none");
});
}
async function refresh_info_about_villages(){
$(".under_choose").children("option").removeAttr("style");
//-------------
var registry_length = Object.keys(registry).length;
for(var x = 0; x < registry_length; x++){
var type = Object.keys(registry)[x].replace(/\d+\|\d+/, ""),
coord = Object.keys(registry)[x].match(/\d+\|\d+/g)[0],
count = registry[Object.keys(registry)[x]];
if(count >= $(`.color_under_for[identif='${type}']`).val()){
var color = $(`.color_for[identif='${type}']`).val();
$(`option[value='${coord}']`).attr("style", `background: ${color};`)
}
}
}
//a világ és egység sebességének a változtatásához létrehozandó form
function speedToScrn(){
if(word_speed == 0){
window.open("https://" + document.location.host + "/page/settings");
$("body").append(`<div id="speeds_input_form">
<input name = "word_speed" type = "number" placeholder = "Világ sebesség" style = "width: 90px; border-radius: 4px; position: absolute; left: 118px; top: 30px; text-align: center;">
<input name = "unit_speed" type = "number" placeholder = "Egység sebesség" style = "width: 90px; border-radius: 4px; position: absolute; left: 118px; top: 60px; text-align: center;">
<input class = "confirmbutt" type = "button" value = "Elment" style = "width: 60px; border-radius: 4px; position: absolute; left: 100px; top: 110px;">
<input class = "cancelbutt" type = "button" value = "Mégsem" style = "width: 60px; border-radius: 4px; position: absolute; left: 168px; top: 110px;">
<style>.confirmbutt {margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px lime;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.confirmbutt:hover {background-color:#68e431;}.confirmbutt:active{position:relative;top:1px;}.cancelbutt {margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px red;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.cancelbutt:hover {background-color:#ed3d2d;}.cancelbutt:active{position:relative;top:1px;}</style></div>`);
$("#speeds_input_form").css({
"background-image": "url('https://indexrprogs.netlify.com/input_img.png')",
"position": "fixed",
"top": "30%",
"left": $(window).height() - 130 +"px",
"width": "325px",
"height": "183px"
});
$(".shadedBG").css("filter", "blur(1px)");
$("input.confirmbutt").unbind('click');
$("input.confirmbutt").click(function(){
if($("input[name='word_speed']").val() == "" || $("input[name='unit_speed']").val() == ""){
alert("Valamelyik mezőt üresen hagytad vagy nem korrektül írtad be a számot.");
return;
}
var w_speed = parseFloat($("input[name='word_speed']").val());
var u_speed = parseFloat($("input[name='unit_speed']").val());
var key = document.location.host.match(/\w+\d+/)[0];
localStorage.setItem(key+"word", w_speed);
localStorage.setItem(key+"unit", u_speed);
word_speed = w_speed;
word_unit_speed = u_speed;
UI.SuccessMessage("A beállítások sikeresen frissítve lettek!", 3000);
$("#speeds_input_form").remove();
$(".shadedBG").css("filter", "blur(0px)");
});
$("input.cancelbutt").unbind('click');
$("input.cancelbutt").click(function(){
$("#speeds_input_form").remove();
$(".shadedBG").css("filter", "blur(0px)");
});
}else{
UI.InfoMessage("Világ sebesség: " + word_speed + " Egység sebesség: " + word_unit_speed + " Kattints duplán a változtatáshoz", 4000);
}
$("input.speed_form").unbind('dblclick');
$("input.speed_form").dblclick(function(){
window.open("https://" + document.location.host + "/page/settings");
$("body").append(`<div id="speeds_input_form">
<input name = "word_speed" type = "number" placeholder = "Világ sebesség" style = "width: 90px; border-radius: 4px; position: absolute; left: 118px; top: 30px; text-align: center;">
<input name = "unit_speed" type = "number" placeholder = "Egység sebesség" style = "width: 90px; border-radius: 4px; position: absolute; left: 118px; top: 60px; text-align: center;">
<input class = "confirmbutt" type = "button" value = "Elment" style = "width: 60px; border-radius: 4px; position: absolute; left: 100px; top: 110px;">
<input class = "cancelbutt" type = "button" value = "Mégsem" style = "width: 60px; border-radius: 4px; position: absolute; left: 168px; top: 110px;">
<style>.confirmbutt {margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px lime;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.confirmbutt:hover {background-color:#68e431;}.confirmbutt:active{position:relative;top:1px;}.cancelbutt {margin: 5px;backface-visibility: hidden;position: relative;cursor: pointer;white-space: nowrap;background: #6c4824;border-radius: 4px;border: 1px solid #000000;border-width: 1px 1px 1px 1px;padding: 1px 5px 1px 5px;box-shadow: 0px 0px 5px #6c4824,inset 0px 3px 5px red;color: #ffffff;font-size: 12px;font-family: verdana;font-weight: 500;font-style: normal;text-shadow: 0px -1px 0px rgba(0%,0%,0%,0.4);}.cancelbutt:hover {background-color:#ed3d2d;}.cancelbutt:active{position:relative;top:1px;}</style></div>`);
$("#speeds_input_form").css({
"background-image": "url('https://indexrprogs.netlify.com/input_img.png')",
"position": "fixed",
"top": "30%",
"left": $(window).height() - 130 +"px",
"width": "325px",
"height": "183px"
});
$(".shadedBG").css("filter", "blur(1px)");
$("input.confirmbutt").unbind('click');
$("input.confirmbutt").click(function(){
if($("input[name='word_speed']").val() == "" || $("input[name='unit_speed']").val() == ""){
alert("Valamelyik mezőt üresen hagytad vagy nem korrektül írtad be a számot.");
return;
}
var w_speed = parseFloat($("input[name='word_speed']").val());
var u_speed = parseFloat($("input[name='unit_speed']").val());
var key = document.location.host.match(/\w+\d+/)[0];
localStorage.setItem(key+"word", w_speed);
localStorage.setItem(key+"unit", u_speed);
word_speed = w_speed;
word_unit_speed = u_speed;
UI.SuccessMessage("A beállítások sikeresen frissítve lettek!", 3000);
$("#speeds_input_form").remove();
$(".shadedBG").css("filter", "blur(0px)");
});
$("input.cancelbutt").unbind('click');
$("input.cancelbutt").click(function(){
$("#speeds_input_form").remove();
$(".shadedBG").css("filter", "blur(0px)");
});
});
}
function create_tooltip(){
var table_content = "<tr><th></th>";
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
table_content += `<th><img src = "${basic_units_url + game_data.units[x] + ".png"}"></th>`
}
table_content += "</tr>"
table_content += "<tr><th>Csapatok</th>"
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
table_content += `<td class = "units_${game_data.units[x]}">0</td>`
}
table_content += "</tr>"
table_content += "<tr><th>Menetidő</th>"
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
table_content += `<td class = "trvl_time_${game_data.units[x]}">00:00:00</td>`
}
table_content += "</tr>"
table_content += "<tr><th rowspan='2'>Indítás</th>"
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
table_content += `<td class = "lnch_date_${game_data.units[x]}">2020-5-20</td>`
}
table_content += "</tr>"
table_content += "<tr>"
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
table_content += `<td class = "lnch_time_${game_data.units[x]}">00:00:00</td>`
}
table_content += "</tr>"
$("body").append(`<div id = "script_tooltip" style = " display: none; border-radius: 2px; border: 1px solid black; margin: 5px; padding: 10px; position: fixed; top: 50px; background-color: #edd8ad;">
<table id = "script_tooltip_content" class="vis">
${table_content}
</table>
</div>`);
}
async function refresh_tooltip_units_in_village(coord, target_coord, arriving, accelerator){
for(var x = 0; x < game_data.units.length; x++){ // csapatok betöltése
if(game_data.units[x] == "militia"){continue}
var val = village_units[coord][game_data.units[x]]
$(`.units_${game_data.units[x]}`).text(val);
}
}
async function set_tooltip_travel_time(coord, target_coord, accelerator){
var coord_x_y = coord.split("|"),
target_coord_x_y = target_coord.split("|"),
accelerator = parseFloat(accelerator);
coord_x_y[0] = parseInt(coord_x_y[0]);coord_x_y[1] = parseInt(coord_x_y[1]);target_coord_x_y[0] = parseInt(target_coord_x_y[0]);target_coord_x_y[1] = parseInt(target_coord_x_y[1]);
var distance = Math.sqrt(Math.pow(coord_x_y[0] - target_coord_x_y[0], 2) + Math.pow(coord_x_y[1] - target_coord_x_y[1], 2));
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
var travel_time_in_millisec = (units_speeds[game_data.units[x]] / word_speed / (word_unit_speed + (word_unit_speed * accelerator))) * distance * 60 * 1000;
var now = new Date(),
will = new Date();
will.setMilliseconds(will.getMilliseconds() + travel_time_in_millisec);
var diff = new Date(will.getTime() - now.getTime());
var travel_hours = parseInt(travel_time_in_millisec / 60 / 60 / 1000),
travel_minutes = diff.getMinutes(),
travel_seconds = diff.getSeconds();
$(`.trvl_time_${game_data.units[x]}`).text(travel_hours + ":" + travel_minutes + ":" + travel_seconds);
}
}
async function set_tooltip_launch_time(coord, target_coord, arriving, accelerator){
var coord_x_y = coord.split("|"),
arriving_splitted = arriving.split(":"),
target_coord_x_y = target_coord.split("|");
accelerator = parseFloat(accelerator);
coord_x_y[0] = parseInt(coord_x_y[0]);coord_x_y[1] = parseInt(coord_x_y[1]);target_coord_x_y[0] = parseInt(target_coord_x_y[0]);target_coord_x_y[1] = parseInt(target_coord_x_y[1]);arriving_splitted[0] = parseInt(arriving_splitted[0]);arriving_splitted[1] = parseInt(arriving_splitted[1]);arriving_splitted[2] = parseInt(arriving_splitted[2]);arriving_splitted[3] = parseInt(arriving_splitted[3]);
for(var x = 0; x < arriving_splitted.length; x++){arriving_splitted[x] = parseInt(arriving_splitted[x])}
var distance = Math.sqrt(Math.pow(coord_x_y[0] - target_coord_x_y[0], 2) + Math.pow(coord_x_y[1] - target_coord_x_y[1], 2));
for(var x = 0; x < game_data.units.length; x++){
if(game_data.units[x] == "militia"){continue}
var travel_time_in_millisec = (units_speeds[game_data.units[x]] / word_speed / (word_unit_speed + (word_unit_speed * accelerator))) * distance * 60 * 1000;
var launch = new Date();
launch.setFullYear(arriving_splitted[0]);launch.setMonth(arriving_splitted[1] - 1);launch.setDate(arriving_splitted[2]);launch.setHours(arriving_splitted[3]);launch.setMinutes(arriving_splitted[4]);launch.setSeconds(arriving_splitted[5]);launch.setMilliseconds(launch.getMilliseconds() - travel_time_in_millisec);
$(`.lnch_date_${game_data.units[x]}`).html(launch.getFullYear() + "-" + (launch.getMonth() + 1) + "-" + launch.getDate());
$(`.lnch_time_${game_data.units[x]}`).html(launch.getHours() + ":" + launch.getMinutes() + ":" + launch.getSeconds());
}
}
function readUnits(){
var all_villages = $(".row_marker");
var word_units = game_data.units;
for(var x = 0; x < all_villages.length; x++){
match_coord = $(".row_marker").eq(x).find("td").eq(0).text(); match_coord = match_coord.match(/\d+\|\d+/)[0];
var units = $(".row_marker").eq(x).find(".unit-item");
village_units[match_coord] = {};
for(var y = 0; y < units.length; y++){
if(word_units[y] == "militia"){continue}
village_units[match_coord][word_units[y]] = $(".row_marker").eq(x).find(".unit-item").eq(y).text();
}
}
}
function get_allGroup(){
//saját faluk legördülő listájához
var villages_container = document.getElementById("units_table");
var villages = villages_container.getElementsByTagName("tbody");
var villages_htmldropdown = [];
for(var x = 0; x < villages.length; x++){
var coord = villages[x].getElementsByTagName("td")[0].innerText.match(/\d+\|\d+/)[0],
village_name = villages[x].getElementsByTagName("td")[0].innerText;
villages_htmldropdown.push('<option value="' + coord + '">' + village_name + '</option>');
coords_of_all_villages.push(coord);
names_of_all_villages.push(village_name);
}
saved_groups["0"] = villages_htmldropdown;
}
function copyLaunches(ident){
var textArea = document.getElementsByClassName("textarea")[ident];
/*Szöveg kim.*/
textArea.select();
textArea.setSelectionRange(0, 99999); //telókra
document.execCommand("copy");
UI.SuccessMessage("Adatok kimásolva!", 2000);
}
//--------
function return_command_types_for_select(){
var html = "";
for(var x = 0; x < storage_keys.filter.saved_command_types.length; x++){
html += `<option value="${storage_keys.filter.saved_command_types[x]}">${storage_keys.filter.saved_command_types[x]}</option>
`}
html += '<option value = "empty" selected = "selected" disabled>-Válassz-</option>';
return html;
}
function set_default_storageKeys(){
localStorage.setItem("plannerStorage", `{
"version": "1.3",
"filter":{
"saved_command_types":["Nuke", "Erősítés", "Fake", "4 nemes - éles", "4 nemes - fake"],
"saved_command_types_color":{"Nuke": "#ff0000", "Erősítés":"#00ff00", "Fake": "#ffff00", "4 nemes - éles": "#ff8000", "4 nemes - fake": "#ffa448"},
"saved_command_types_under":{"Nuke": 1, "Erősítés": 1, "Fake": 1, "4 nemes - éles": 1, "4 nemes - fake": 1},
"selected_group_for_command_type":{"Nuke": 0, "Erősítés": 0, "Fake": 0, "4 nemes - éles": 0, "4 nemes - fake": 0},
"selected_slowest_for_command_type":{"Nuke": "ram.png", "Erősítés": "empty", "Fake": "ram.png", "4 nemes - éles": "snob.png", "4 nemes - fake": "snob.png"},
"selected_accelerator_for_command_type":{"Nuke": 0, "Erősítés": 0, "Fake": 0, "4 nemes - éles": 0, "4 nemes - fake": 0},
"sorting": 1
},
"auto_saves": []
}`);
}
//a lögördülőbe adja vissza a falvakat HTML options formában egy bizonyos csoportba amik tartoznak
function getGroupVillages(htmll){
var trs = $(htmll).find(".quickedit-vn");
var villages = [];
for(var x = 0; x < trs.length; x++){
villages.push('<option value ="' + trs[x].innerText.match(/\d+\|\d+/) + '">' + trs[x].innerText + '</option>');
}
return villages;
}
async function refresh_filter_event_listeners(){
$(".vill_sorting_radio").unbind('change');
$(".vill_sorting_radio").change(function(){
storage_keys.filter.sorting = parseInt($(this).attr("identif"));
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
})
$(".remove_type").unbind('click');
$(".remove_type").click(function(){
var identif = $(this).attr("identif"),
index = storage_keys.filter.saved_command_types.indexOf(identif);
storage_keys.filter.saved_command_types.splice(index, 1);
delete storage_keys.filter.saved_command_types_color[identif];
delete storage_keys.filter.saved_command_types_under[identif];
delete storage_keys.filter.selected_slowest_for_command_type[identif];
delete storage_keys.filter.selected_accelerator_for_command_type[identif];
delete storage_keys.filter.selected_group_for_command_type[identif];
$(this).parent().parent().remove();
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
refresh_filter_event_listeners();
});
$(".type_for").unbind('change');
$(".type_for").change(function(){
var indentif = $(this).attr("identif"),
selcd_val = $(this).children("option:selected").val();
if(saved_groups[selcd_val] == undefined){
var res;
$.ajax({url: document.location.href.replace("group=0","group=" + selcd_val), async: false, success: function(result){
res = result;
}});
saved_groups[selcd_val] = getGroupVillages(res);
}
storage_keys.filter.selected_group_for_command_type[indentif] = selcd_val;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
});
$(".color_under_for").unbind('change');
$(".color_under_for").change(function(){
var indentif = $(this).attr("identif"),
selcd_val = $(this).val();
storage_keys.filter.saved_command_types_under[indentif] = selcd_val;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
});
$(".color_for").unbind('change');
$(".color_for").change(function(){
var indentif = $(this).attr("identif"),
selcd_val = $(this).val();
storage_keys.filter.saved_command_types_color[indentif] = selcd_val;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
});
$(".slowest_for").unbind('change');
$(".slowest_for").change(function(){
var indentif = $(this).attr("identif"),
selcd_val = $(this).children("option:selected").val();
storage_keys.filter.selected_slowest_for_command_type[indentif] = selcd_val;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
});
$(".accelerator_for").unbind('change');
$(".accelerator_for").change(function(){
var indentif = $(this).attr("identif"),
selcd_val = $(this).children("option:selected").val();
storage_keys.filter.selected_accelerator_for_command_type[indentif] = selcd_val;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
});
$("#add_new_type").unbind('click');
$("#add_new_type").click(function(){
var type_name = $("#new_type_name").val();
if(type_name.length > 50){
UI.ErrorMessage("Túl hosszú a típus név. Max. 50 karakter", 3000);
return;
}else if(type_name.length == 0){
UI.ErrorMessage("Adj nevet a típusnak!", 2000);
return;
}
var html = `<tr><td><b>${type_name}</b></td>
<td>
<select identif = "${type_name}" class = "type_for" size = "1" style = "width: 100px; border-radius: 4px;">${village_groups}</select>
</td>
<td>
<input identif = "${type_name}" class = "color_under_for" type = "number" value = "1" style = "width: 30px; border-radius: 4px;">
</td>
<td>
<input identif = "${type_name}" class = "color_for" type="color" value="#ffffff">
</td>
<td>
<select identif = "${type_name}" class = "slowest_for" size = "1" style = "width: 80px; border-radius: 4px;">${default_option_group("slowest")}</select>
</td>
<td>
<select identif = "${type_name}" class = "accelerator_for" size = "1" style = "width: 45px; border-radius: 4px;">${default_option_group("accelerator")}</select>
</td>
<td>
<a identif = "${type_name}" class = "remove_type" href="javascript:;">Törlés</a>
</td></tr>`;
$(html).insertBefore($(this).parent().parent());
storage_keys.filter.saved_command_types.push(type_name);
storage_keys.filter.saved_command_types_color[type_name] = "#ffffff";
storage_keys.filter.saved_command_types_under[type_name] = 1;
storage_keys.filter.selected_group_for_command_type[type_name] = 0;
storage_keys.filter.selected_slowest_for_command_type[type_name] = "empty";
storage_keys.filter.selected_accelerator_for_command_type[type_name] = 0;
localStorage.setItem("plannerStorage", JSON.stringify(storage_keys));
refresh_filter_event_listeners();
});
}
function actualizing_settings(){
for(var x = 0; x < storage_keys.filter.saved_command_types.length; x++){
var type = storage_keys.filter.saved_command_types[x],
selected_villgroup_for = storage_keys.filter.selected_group_for_command_type[type],
selected_slowest_for = storage_keys.filter.selected_slowest_for_command_type[type],
selected_accelerator_for = storage_keys.filter.selected_accelerator_for_command_type[type];
$(`.type_for[identif='${type}']`).children(`option[value='${selected_villgroup_for}']`).prop("selected", true);
$(`.slowest_for[identif='${type}']`).children(`option[value='${selected_slowest_for}']`).prop("selected", true);
$(`.accelerator_for[identif='${type}']`).children(`option[value='${selected_accelerator_for}']`).prop("selected", true);
if(selected_villgroup_for != 0){
groupp.push(selected_villgroup_for);
ident.push(type);
}
}
$(".vill_sorting_radio").eq(storage_keys.filter.sorting).prop("checked", true);
async_reading_village_groups();
}
function async_reading_village_groups(){
if(groupp.length == 0){
return;
}
$.ajax({url: document.location.href.replace("group=0","group=" + groupp[0]), async: true, success: function(result){
saved_groups[groupp[0]] = getGroupVillages(result);
progress++;
groupp.shift();
ident.shift();
setTimeout(async_reading_village_groups, 500);
}});
}
function default_option_group(which){
if(which == "slowest"){
return '<option value="spear.png">Lándzsa</option><option value="sword.png">Kardos</option><option value="axe.png">Bárdos</option><option value="archer.png">Ijjász</option><option value="spy.png">Kém</option><option value="light.png">Könnyűló</option><option value="marcher.png">Lovasijjász</option><option value="heavy.png">Nehézló</option><option value="ram.png">Kos</option><option value="catapult.png">Katapult</option><option value="knight.png">Lovag</option><option value="snob.png">Nemes</option><option value = "empty" selected = "selected" disabled>-Válassz-</option>';
}else if(which == "accelerator"){
var html = "";
for(var x = 0; x < 51; x++){
if(x == 0){
html+= '<option value="0">0%</option>';
}else if( x < 10){
html+= `<option value="0${x}">${x}%</option>`;
}else{
html+= `<option value="${x}">${x}%</option>`;
}
}
return html;
}
}