Guest User

Untitled

a guest
Jan 9th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var icon = [
  2.     L.icon({
  3.         iconUrl: 'https://i.imgur.com/JV4loMJ.png' // Top
  4.     }),
  5.     L.icon({
  6.         iconUrl: 'https://i.imgur.com/wLFQgZs.png' // Left
  7.     }),
  8.     L.icon({
  9.         iconUrl: 'https://i.imgur.com/2WSSoiu.png' // Bottom
  10.     }),
  11.     L.icon({
  12.         iconUrl: 'https://i.imgur.com/ZSsbyUo.png' // Right
  13.     }),
  14.     L.icon({
  15.         iconUrl: 'https://i.imgur.com/9OiLpQI.png' // Top Gather
  16.     }),
  17.     L.icon({
  18.         iconUrl: 'https://i.imgur.com/h7G8p7A.png' // Left Gather
  19.     }),
  20.     L.icon({
  21.         iconUrl: 'https://i.imgur.com/FSn1xeT.png' // Bottom Gather
  22.     }),
  23.     L.icon({
  24.         iconUrl: 'https://i.imgur.com/o5sfNn9.png' // Right Gather
  25.     }),
  26.     L.icon({
  27.         iconUrl: 'https://i.imgur.com/SNNhHRg.png' // Top Fight
  28.     }),
  29.     L.icon({
  30.         iconUrl: 'https://i.imgur.com/0FSmYpx.png' // Left Fight
  31.     }),
  32.     L.icon({
  33.         iconUrl: 'https://i.imgur.com/bL4qVwp.png' // Bottom Fight
  34.     }),
  35.     L.icon({
  36.         iconUrl: 'https://i.imgur.com/Sq9lhLi.png' // Right Fight
  37.     }),
  38.     L.icon({
  39.         iconUrl: 'https://i.imgur.com/RDAiwDR.png' // Top Bank
  40.     }),
  41.     L.icon({
  42.         iconUrl: 'https://i.imgur.com/SG4cYn7.png' // Right Bank
  43.     }),
  44.     L.icon({
  45.         iconUrl: 'https://i.imgur.com/5FrhBic.png' // Left Bank
  46.     }),
  47.     L.icon({
  48.         iconUrl: 'https://i.imgur.com/DIa1tYO.png' // Bottom Bank
  49.     }),
  50.     L.icon({
  51.         iconUrl: 'https://i.imgur.com/Ez7V6wN.png' // Top Phenix
  52.     }),
  53.     L.icon({
  54.         iconUrl: 'https://i.imgur.com/GGhcCBd.png' // Left Phenix
  55.     }),
  56.     L.icon({
  57.         iconUrl: 'https://i.imgur.com/YdvBiSE.png' // Bottom Phenix
  58.     }),
  59.     L.icon({
  60.         iconUrl: 'https://i.imgur.com/BxUS6YK.png' // Right Phenix
  61.     }),
  62. ];
  63.  
  64. var actualMap;
  65. var pathData = [];
  66. var bankData = [];
  67. var phenixData = [];
  68. var ressources = [
  69.     [1, "Frêne"],
  70.     [8, "Chêne"],
  71.     [17, "Fer"],
  72.     [24, "Argent"],
  73.     [25, "Or"],
  74.     [26, "Pierre de Bauxite"],
  75.     [28, "If"],
  76.     [29, "Ebène"],
  77.     [30, "Orme"],
  78.     [31, "Erable"],
  79.     [32, "Charme"],
  80.     [33, "Châtaignier"],
  81.     [34, "Noyer"],
  82.     [35, "Merisier"],
  83.     [37, "Pierre de Kobalte"],
  84.     [38, "Blé"],
  85.     [39, "Houblon"],
  86.     [42, "Lin"],
  87.     [43, "Orge"],
  88.     [44, "Seigle"],
  89.     [45, "Avoine"],
  90.     [46, "Chanvre"],
  91.     [47, "Malt"],
  92.     [48, "Tas de patates"],
  93.     [52, "Etain"],
  94.     [53, "Pierre Cuivrée"],
  95.     [54, "Manganèse"],
  96.     [55, "Bronze"],
  97.     [61, "Edelweiss"],
  98.     [63, "Froment"],
  99.     [64, "Epeautre"],
  100.     [65, "Sorgho"],
  101.     [66, "Menthe Sauvage"],
  102.     [67, "Trèfle à 5 feuilles"],
  103.     [68, "Orchidée Freyesque"],
  104.     [71, "Greuvette"],
  105.     [72, "Somoon Agressif"],
  106.     [73, "Pwoulpe"],
  107.     [74, "Truite"],
  108.     [75, "Goujon"],
  109.     [76, "Poisson-Chaton"],
  110.     [77, "Crabe"],
  111.     [78, "Poisson Pané"],
  112.     [79, "Carpe d'Iem"],
  113.     [80, "Truite Vaseuse"],
  114.     [81, "Sardine Brillante"],
  115.     [82, "Coton"],
  116.     [84, "Puits"],
  117.     [98, "Bombu"],
  118.     [99, "Ombre étrange"],
  119.     [100, "Pichon"],
  120.     [101, "Oliviolet"],
  121.     [102, "Machine de force"],
  122.     [104, "Koinkoin"],
  123.     [108, "Bambou"],
  124.     [109, "Bambou sombre"],
  125.     [110, "Bambou sacré"],
  126.     [111, "Riz"],
  127.     [112, "Pandouille"],
  128.     [113, "Dolomite"],
  129.     [114, "Silicate"],
  130.     [121, "Kaliptus"],
  131.     [131, "Perce-neige"],
  132.     [132, "Poisskaille"],
  133.     [133, "Tremble"],
  134.     [134, "Frostiz"],
  135.     [135, "Obsidienne"],
  136.     [136, "Coquillage"],
  137.     [137, "Machine à coudre de Poss'Ybel"],
  138.     [138, "Fabrique"],
  139.     [139, "Table de cuisine de mauvaise qualité"],
  140.     [140, "Atelier de mauvaise qualité"],
  141.     [141, "Établi de mauvaise qualité"],
  142.     [142, "Machine à coudre de mauvaise qualité"],
  143.     [143, "Machine à jouets"],
  144.     [144, "Pressoir à poisson"],
  145.     [145, "Atelier d'Emballage"],
  146.     [146, "Paquet Cadeau"],
  147.     [147, "Atelier d'emballage de cadeaux"],
  148.     [148, "Atelier des alchimistes"],
  149.     [149, "Atelier des bijoutiers"],
  150.     [150, "Atelier des bouchers"],
  151.     [151, "Atelier des bouchers et chasseurs"],
  152.     [152, "Atelier des boucliers"],
  153.     [153, "Atelier des boulangers"],
  154.     [154, "Atelier des bricoleurs"],
  155.     [155, "Atelier des bûcherons"],
  156.     [156, "Atelier des chasseurs"],
  157.     [157, "Atelier des cordonniers"],
  158.     [158, "Atelier des forgemages"],
  159.     [159, "Atelier des forgerons"],
  160.     [160, "Atelier des mineurs"],
  161.     [161, "Atelier des paysans"],
  162.     [162, "Atelier des poissonniers"],
  163.     [163, "Atelier des poissonniers et pêcheurs"],
  164.     [164, "Atelier des pêcheurs"],
  165.     [165, "Atelier des sculpteurs"],
  166.     [166, "Atelier des tailleurs"],
  167.     [167, "Arène"],
  168.     [168, "Banque"],
  169.     [169, "Bar Akouda"],
  170.     [170, "Bibliothèque"],
  171.     [171, "Boutiques de Nowel"],
  172.     [172, "Dojo"],
  173.     [173, "Église"],
  174.     [174, "Épicerie"],
  175.     [175, "Fabricant de skis"],
  176.     [176, "Hôtel de ville"],
  177.     [177, "Hôtel des métiers"],
  178.     [178, "Kanojedo"],
  179.     [179, "Kolizéum"],
  180.     [180, "Milice"],
  181.     [181, "Médecin de Frigost"],
  182.     [182, "Taverne"],
  183.     [183, "Taverne Alakarte"],
  184.     [184, "Taverne Atolmond"],
  185.     [185, "Taverne d'Argent"],
  186.     [186, "Taverne de Djaul"],
  187.     [187, "Taverne de la Bagrutte"],
  188.     [188, "Taverne de la Chopenbois"],
  189.     [189, "Taverne de la Misère"],
  190.     [190, "Taverne de la Tabasse"],
  191.     [191, "Taverne de Lisa Kaya"],
  192.     [192, "Taverne de Sakaï"],
  193.     [193, "Taverne du Bwork"],
  194.     [194, "Taverne du Chabrulé"],
  195.     [195, "Taverne du Dernier Refuge"],
  196.     [196, "Taverne du Ferayeur"],
  197.     [197, "Taverne du Feubuk"],
  198.     [198, "Taverne du Pandawa Ivre"],
  199.     [199, "Taverne du Paradis Frigostien"],
  200.     [200, "Taverne du Pinchaut"],
  201.     [201, "Taverne du Ripate"],
  202.     [202, "Temple des guildes"],
  203.     [203, "Tour de Brâkmar"],
  204.     [204, "Tour des archives"],
  205.     [205, "Tour des ordres"],
  206.     [206, "Sous-marin Steamer"],
  207.     [207, "Autel"],
  208.     [208, "Krosmaster"],
  209.     [209, "Atelier d'Isidor Fèvre"],
  210.     [210, "Atelier d'Al Shab"],
  211.     [211, "Atelier de Frigostine"],
  212.     [212, "Atelier de Francky"],
  213.     [213, "Atelier de Dutch"],
  214.     [214, "Atelier de Brokkeitri"],
  215.     [215, "Atelier de Laurent Part"],
  216.     [216, "Atelier de Clarisse Tosha"],
  217.     [217, "Atelier d'Annette Daimpeau"],
  218.     [218, "Atelier de Carla Garfield"],
  219.     [219, "Métier d'Avenir"],
  220.     [220, "Tonneau d'explosifs"],
  221.     [221, "Fleur de Sutol"],
  222.     [222, "Barbecue"],
  223.     [223, "Cawotte fraîche"],
  224.     [224, "Alambic patiné de l'hôtel des métiers"],
  225.     [225, "Bouteille de Rhum"],
  226.     [226, "Ascenseur"],
  227.     [227, "Champignon"],
  228.     [228, "Table de Bowisse"],
  229.     [229, "Atelier de Mériana"],
  230.     [230, "Portail des Bworks"],
  231.     [231, "Distributeur de missions"],
  232.     [232, "Portail"],
  233.     [233, "Coffre en or"],
  234.     [234, "Glaçon"],
  235.     [235, "Aller vers"],
  236.     [236, "Pupitre"],
  237.     [237, "Table de planification"],
  238.     [238, "Aller vers l'instance A"],
  239.     [239, "Aller vers l'instance B"],
  240.     [240, "Aller vers l'instance C"],
  241.     [241, "Vieux Coffre XXIII"],
  242.     [242, "Etabli d'horloger"],
  243.     [243, "Coffre XI"],
  244.     [244, "Coffre XXIII"],
  245.     [245, "Coffre XXXI"],
  246.     [246, "Coffre LIX"],
  247.     [247, "Horloge en avance de 2 minutes"],
  248.     [248, "Horloge en retard de 3 minutes"],
  249.     [249, "Horloge en avance de 7 minutes"],
  250.     [250, "Horloge en retard de 8 minutes"],
  251.     [251, "Œufs de Tempax"],
  252.     [252, "Atelier des Voyageurs"],
  253.     [253, "Portail Eliotrope"],
  254.     [254, "Ortie"],
  255.     [255, "Sauge"],
  256.     [256, "Ginseng"],
  257.     [257, "Belladone"],
  258.     [258, "Mandragore"],
  259.     [259, "Noisetier"],
  260.     [260, "Maïs"],
  261.     [261, "Millet"],
  262.     [262, "Bloc de pierre"],
  263.     [263, "Brochet"],
  264.     [264, "Kralamoure"],
  265.     [265, "Anguille"],
  266.     [266, "Dorade Grise"],
  267.     [267, "Perche"],
  268.     [268, "Raie"],
  269.     [269, "Lotte"],
  270.     [270, "Requin Marteau-Faucille"],
  271.     [271, "Bar Rikain"],
  272.     [272, "Morue"],
  273.     [273, "Tanche"],
  274.     [274, "Espadon"],
  275.     [275, "Enclume de Mulic Bere"],
  276.     [276, "Établi de Mulic Bere"],
  277.     [277, "Atelier de Mulic Bere"],
  278.     [278, "Assembleur de Mulic Bere"],
  279.     [279, "Atelier du Mage Ax"],
  280.     [280, "Plate-forme Huppermage"],
  281.     [281, "Trèfle à 4 feuilles"],
  282.     [282, "Indiquer une sortie"],
  283.     [283, "Chathon"],
  284.     [284, "Escalier"],
  285.     [285, "Porte blindée"],
  286.     [286, "Atelier indicible"],
  287.     [287, "Aquajou"],
  288.     [288, "Salikrone"],
  289.     [289, "Quisnoa"],
  290.     [290, "Patelle"],
  291.     [291, "Écume de mer"],
  292.     [292, "Table de Travail"],
  293.     [293, "Écume de mer"],
  294.     [294, "Aquajou"],
  295.     [295, "Salikrone"],
  296.     [296, "Quisnoa"],
  297.     [297, "Patelle"],
  298.     [298, "Atelier de Natacha Manka"],
  299.     [299, "Œufs frais"]
  300. ];
  301. var picker = 4;
  302. var gatherData = [];
  303. var loadingFile = false;
  304.  
  305. document.getElementById('pickRessourceContainer').innerHTML +=
  306.     '<div id="pathSelecter" style= "  background: #212121; border-radius: 5px; padding: 10px; text-align:left; color: #fff; text-shadow: 0 0px 10px #000; box-shadow: 0 0 10px 0px rgba(0,0,0,0.6); font-family: arial; opacity: 0.95;">' +
  307.     '<table>' +
  308.     '<tr>' +
  309.     '<td><input id="pathTop" type="checkbox"> Haut </td>' +
  310.     '<td><input id="pathBottom" type="checkbox"> Bas </td>' +
  311.     '</tr>' +
  312.     '<tr>' +
  313.     '<td><input id="pathLeft" type="checkbox"> Gauche </td>' +
  314.     '<td><input id="pathRight" type="checkbox"> Droite</td>' +
  315.     '</tr>' +
  316.     '</table>' +
  317.     '</br>' +
  318.     '<div style="height: 3px;background-color: #151515;"></div>' +
  319.     '</br>' +
  320.     '<table>' +
  321.     '<tr>' +
  322.     '<td><input id="gather" type="checkbox"> Récolter </td>' +
  323.     '<td><input id="fight" type="checkbox"> Combattre </td>' +
  324.     '</tr>' +
  325.     '<tr>' +
  326.     '<td><input id="bank" type="checkbox"> Banque </td>' +
  327.     '<td><input id="phenix" type="checkbox"> Phenix </td>' +
  328.     '</tr>' +
  329.     '</table>' +
  330.     '</br>' +
  331.     '<div style="height: 3px;background-color: #151515;"></div>' +
  332.     '</br>' +
  333.     '<div style="text-align: center;">Ressources à récolter :</div>' +
  334.     '</br>' +
  335.     '<div id="ressourcePickerBot" style="text-align: center;"><span id="ressourcePickerCreator" class="pickRessource" onclick="newRessourcePicker();" style="background-color: #0000008a; background-position: -260px 0px;">+</span></div>' +
  336.     '</br>' +
  337.     '<div style="height: 3px;background-color: #151515;"></div>' +
  338.     '</br>' +
  339.     '<div style="text-align: center;"><button id="saveFile" onclick="generate()">Sauvegarder</button></div>' +
  340.     '</br>' +
  341.     '<div style="text-align: center;"><button id="deletePath" onclick="deletePath()">Supprimer</button></div>' +
  342.     '</br>' +
  343.     '<div style="text-align: center;"><input type="file" id="file" name="file"></div>' +
  344.     '</div>';
  345.  
  346. function checkMaps(mapcoord, array) {
  347.     for (let key = 0; key < array.length; key++) {
  348.         if (array[key][0] == mapcoord) {
  349.             return true;
  350.         }
  351.     }
  352.     return false;
  353. }
  354.  
  355. function getMapIndex(mapcoord, array) {
  356.     for (let key = 0; key < array.length; key++) {
  357.         if (array[key][0] == mapcoord) {
  358.             return key;
  359.         }
  360.     }
  361. }
  362.  
  363. function onMapClick() {
  364.  
  365.     if (!loadingFile)
  366.         actualMap = document.getElementById('mapCoordinates').innerText;
  367.  
  368.     if (document.getElementById("bank").checked) {
  369.         if (!checkMaps(actualMap, bankData)) {
  370.             bankData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false]);
  371.             createMarker(getMapIndex(actualMap, bankData), bankData);
  372.             deleteEmptyPath(bankData);
  373.         } else if (checkMaps(actualMap, bankData)) {
  374.             removeArrow(getMapIndex(actualMap, bankData), bankData);
  375.             deleteEmptyPath(bankData);
  376.         }
  377.         console.clear();
  378.         for (let key in bankData) {
  379.             console.log(key + ', map : ' + bankData[key][0] + ', top : ' + bankData[key][1] + ', bottom : ' + bankData[key][5] + ', right : ' + bankData[key][7] + ', left : ' + bankData[key][3]);
  380.         }
  381.     } else if (document.getElementById("phenix").checked) {
  382.         if (!checkMaps(actualMap, phenixData)) {
  383.             phenixData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false]);
  384.             createMarker(getMapIndex(actualMap, phenixData), phenixData);
  385.             deleteEmptyPath(phenixData);
  386.         } else if (checkMaps(actualMap, phenixData)) {
  387.             removeArrow(getMapIndex(actualMap, phenixData), phenixData);
  388.             deleteEmptyPath(phenixData);
  389.         }
  390.         console.clear();
  391.         for (let key in phenixData) {
  392.             console.log(key + ', map : ' + phenixData[key][0] + ', top : ' + phenixData[key][1] + ', bottom : ' + phenixData[key][5] + ', right : ' + phenixData[key][7] + ', left : ' + phenixData[key][3]);
  393.         }
  394.     } else {
  395.         if (!checkMaps(actualMap, pathData)) {
  396.             pathData.push([actualMap, false, undefined, false, undefined, false, undefined, false, undefined, false, false]);
  397.             createMarker(getMapIndex(actualMap, pathData), pathData);
  398.             deleteEmptyPath(pathData);
  399.         } else if (checkMaps(actualMap, pathData)) {
  400.             removeArrow(getMapIndex(actualMap, pathData), pathData);
  401.             deleteEmptyPath(pathData);
  402.         }
  403.         console.clear();
  404.         for (let key in pathData) {
  405.             console.log(key + ', map : ' + pathData[key][0] + ', top : ' + pathData[key][1] + ', bottom : ' + pathData[key][5] + ', right : ' + pathData[key][7] + ', left : ' + pathData[key][3] + ', gather : ' + pathData[key][9] + ', fight : ' + pathData[key][10]);
  406.         }
  407.     }
  408.  
  409.  
  410. }
  411.  
  412. function deleteEmptyPath(array) {
  413.     if (!array[getMapIndex(actualMap, array)][1] && !array[getMapIndex(actualMap, array)][3] && !array[getMapIndex(actualMap, array)][5] && !array[getMapIndex(actualMap, array)][7]) {
  414.         array.splice(getMapIndex(actualMap, array), 1);
  415.     }
  416. }
  417.  
  418. function removeArrow(key, array) {
  419.     removeArrowWay(key, array, "pathTop", 2, 4, 8, 12, 16, 0, 1, 0.3, 0);
  420.     removeArrowWay(key, array, "pathLeft", 4, 5, 9, 14, 17, 1, 3, 0.1, 0.25);
  421.     removeArrowWay(key, array, "pathBottom", 6, 6, 10, 15, 18, 2, 5, 0.3, 0.4);
  422.     removeArrowWay(key, array, "pathRight", 8, 7, 11, 13, 19, 3, 7, 0.5, 0.25);
  423. }
  424.  
  425. function removeArrowWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y) {
  426.     if (document.getElementById(className).checked) {
  427.         if (array[key][wayMarker] !== undefined) {
  428.             array[key][wayToggle] = false;
  429.             map.removeLayer(array[key][wayMarker]);
  430.             array[key][wayMarker] = undefined;
  431.         } else createMarkerWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y)
  432.     }
  433. }
  434.  
  435. function createMarker(key, array) {
  436.     createMarkerWay(key, array, "pathTop", 2, 4, 8, 12, 16, 0, 1, 0.3, 0);
  437.     createMarkerWay(key, array, "pathLeft", 4, 5, 9, 14, 17, 1, 3, 0.1, 0.25);
  438.     createMarkerWay(key, array, "pathBottom", 6, 6, 10, 15, 18, 2, 5, 0.3, 0.4);
  439.     createMarkerWay(key, array, "pathRight", 8, 7, 11, 13, 19, 3, 7, 0.5, 0.25);
  440. }
  441.  
  442. function createMarkerWay(key, array, className, wayMarker, gatherIcon, fightIcon, bankIcon, phenixIcon, moveIcon, wayToggle, x, y) {
  443.     if (document.getElementById(className).checked) {
  444.         if (document.getElementById("gather").checked) {
  445.             array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
  446.                 interactive: false,
  447.                 zIndexOffset: 5000,
  448.                 icon: icon[gatherIcon]
  449.             }).addTo(map);
  450.             array[key][9] = true;
  451.         } else if (document.getElementById("fight").checked) {
  452.             array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
  453.                 interactive: false,
  454.                 zIndexOffset: 5000,
  455.                 icon: icon[fightIcon]
  456.             }).addTo(map);
  457.             array[key][10] = true;
  458.         } else if (document.getElementById("bank").checked) {
  459.             array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + (x + 0.1), actualMap.split(", ")[1] * 1 + (y + 0.1)), {
  460.                 interactive: false,
  461.                 zIndexOffset: 5000,
  462.                 icon: icon[bankIcon]
  463.             }).addTo(map);
  464.             array[key][9] = true;
  465.         } else if (document.getElementById("phenix").checked) {
  466.             array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + (x + 0.2), actualMap.split(", ")[1] * 1 + (y + 0.2)), {
  467.                 interactive: false,
  468.                 zIndexOffset: 5000,
  469.                 icon: icon[phenixIcon]
  470.             }).addTo(map);
  471.             array[key][9] = true;
  472.         } else {
  473.             array[key][wayMarker] = L.marker(dofusXYToMapXY(actualMap.split(", ")[0] * 1 + x, actualMap.split(", ")[1] * 1 + y), {
  474.                 interactive: false,
  475.                 zIndexOffset: 5000,
  476.                 icon: icon[moveIcon]
  477.             }).addTo(map);
  478.         }
  479.         array[key][wayToggle] = true;
  480.     }
  481. }
  482.  
  483. function newRessourcePicker() {
  484.     document.getElementById("ressourcePickerBot").innerHTML = '<span id="pickRessource' + picker + '" class="pickRessource ressourceColor1" onclick="clickOnTypePicker(\'' + picker + '\');" data-name="" data-ressourceid=""' +
  485.         'style="background-position: -260px 0px; line-height: 49px !important; width: 49px !important; margin: 2px !important; height: 49px !important;">?</span>' + document.getElementById("ressourcePickerBot").innerHTML;
  486.     gatherData.push('pickRessource' + picker);
  487.     picker += 1;
  488. }
  489.  
  490. function pathGenerator(index, array) {
  491.     var path = "";
  492.     if (index !== undefined) {
  493.         if (array.length !== 0) {
  494.             if (array[index][1])
  495.                 path = "top";
  496.             if (array[index][5])
  497.                 path += (path === "" ? "" : "|") + "bottom";
  498.             if (array[index][3])
  499.                 path += (path === "" ? "" : "|") + "left";
  500.             if (array[index][7])
  501.                 path += (path === "" ? "" : "|") + "right";
  502.             return path;
  503.         }
  504.     }
  505. }
  506.  
  507. function afterPhenix(map) {
  508.     for (let index = 0; index < pathData.length; index++) {
  509.         if (map == pathData[index][0]) {
  510.             return index;
  511.         }
  512.     }
  513. }
  514.  
  515. function gatherFigh(index) {
  516.     var path = "";
  517.     if (pathData[index][9])
  518.         path = ", gather = true";
  519.     if (pathData[index][10])
  520.         path += ", fight = true";
  521.     return path;
  522. }
  523.  
  524. function addGather() {
  525.     let res = "";
  526.     for (let index = 0; index < gatherData.length; index++) {
  527.         let str = document.getElementById(gatherData[index]).outerHTML;
  528.         let regex = /data-name=\"(.*?)\"/g;
  529.         let matche = regex.exec(str);
  530.         for (let i = 0; i < ressources.length; i++) {
  531.             if (ressources[i][1] == matche[1]) {
  532.                 res += '\t' + ressources[i][0] + ',' + ' -- ' + ressources[i][1] + '\r\n';
  533.             }
  534.         }
  535.     }
  536.     return res;
  537. }
  538.  
  539. function generate() {
  540.     var txt = "-- Generated On Dofus-Map with Drigtime's SwiftPath Script Maker --\r\n";
  541.     txt += "GATHER = {\r\n";
  542.     txt += addGather();
  543.     txt += "} -- Les éléments à récolter\r\n" +
  544.         "OPEN_BAGS = true -- Ouvrir les sacs de ressources au fur et à mesure\r\n" +
  545.         "AUTO_DELETE = { } -- Les éléments à supprimer\r\n\r\n" +
  546.         "MAX_MONSTERS = 8 -- Le nombre maximum de monstres dans un groupe à combattre.\r\n" +
  547.         "MIN_MONSTERS = 1 -- Le nombre minimum de monstres dans un groupe à combattre.\r\n\r\n" +
  548.         "FORBIDDEN_MONSTERS = { } -- Monstres interdits\r\n" +
  549.         "FORCE_MONSTERS = { } -- Monstres obligatoires\r\n\r\n" +
  550.         "MAX_COMBAT = 800 -- Nombre de combats maximum\r\n" +
  551.         "\r\nfunction move()\r\n\treturn {\r\n" +
  552.         "\t\t{map = \"83887104\", path = \"396\"}, --Interieur banque Astrub vers Sortie--\r\n" +
  553.         "\t\t{map = \"54534165\", path = \"424\"}, --Interieur banque Frigost vers Sortie--\r\n" +
  554.         "\t\t{map = \"2885641\", path = \"424\"}, --Interieur banque Bonta vers Sortie--\r\n" +
  555.         "\t\t{map = \"99095051\", path = \"410\"}, --Interieur banque Amakna vers Sortie--\r\n" +
  556.         "\t\t{map = \"8912911\", path = \"424\"}, --Interieur banque Brakmar vers Sortie--\r\n" +
  557.         "\t\t{map = \"91753985\", path = \"396\"}, --Interieur banque Sufokia vers Sortie (Non fait)--\r\n" +
  558.         "\t\t{map = \"86511105\", door = \"452\"}, --Interieur banque Ottomaï vers Sortie--\r\n" +
  559.         "\t\t{map = \"8129542\", path = \"409\"}, --Interieur banque Pandala vers Sortie--\r\n" +
  560.         "\t\t{map = \"84935175\", path = \"425\"}, --Interieur banque Montagne Koalak vers Sortie--\r\n";
  561.     for (let key in pathData) {
  562.         txt += '\t\t{map = "' + pathData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, pathData) + '"' + gatherFigh(key) + '},\r\n';
  563.     }
  564.     txt += "\t}\r\nend\r\n\r\nfunction bank()\r\n\treturn {\r\n";
  565.     for (let key in bankData) {
  566.         txt += '\t\t{map = "' + bankData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, bankData) + '"},\r\n';
  567.     }
  568.     txt += "\t\t{map = \"84674566\", door = \"303\"}, --Devant banque Astrub--\r\n" +
  569.         "\t\t{map = \"83887104\", path = \"396\", npcBank = true}, --Banque Astrub--\r\n" +
  570.         "\t\t{map = \"54172457\", door = \"358\"}, --Devant banque Frigost--\r\n" +
  571.         "\t\t{map = \"54534165\", path = \"424\", npcBank = true}, --Banque Frigost--\r\n" +
  572.         "\t\t{map = \"147254\", door = \"383\"}, --Devant banque Bonta--\r\n" +
  573.         "\t\t{map = \"2885641\", path = \"424\", npcBank = true}, --Banque Bonta--\r\n" +
  574.         "\t\t{map = \"88081177\", door = \"216\"}, --Devant banque Amakna--\r\n" +
  575.         "\t\t{map = \"99095051\", path = \"410\", npcBank = true}, --Banque Amakna--\r\n" +
  576.         "\t\t{map = \"144931\", door = \"248\"}, --Devant banque Brakmar--\r\n" +
  577.         "\t\t{map = \"8912911\", path = \"424\", npcBank = true}, --Banque Brakmar--\r\n" +
  578.         "\t\t{map = \"90703872\", door = \"248\"}, --Devant banque Sufokia (Non fait)--\r\n" +
  579.         "\t\t{map = \"91753985\", path = \"396\", npcBank = true}, --Banque Sufokia--\r\n" +
  580.         "\t\t{map = \"155157\", door = \"355\"}, --Devant banque Ottomaï--\r\n" +
  581.         "\t\t{map = \"86511105\", door = \"452\", npcBank = true}, --Banque Ottomaï--\r\n" +
  582.         "\t\t{map = \"12580\", door = \"284\"}, --Devant banque Pandala--\r\n" +
  583.         "\t\t{map = \"8129542\", path = \"409\", npcBank = true}, --Banque Pandala--\r\n" +
  584.         "\t\t{map = \"73400323\", door = \"330\"}, --Devant banque Montagne Koalak--\r\n" +
  585.         "\t\t{map = \"84935175\", path = \"425\", npcBank = true}, --Banque Montagne Koalak--\r\n\t}\r\nend\r\n" +
  586.         "\r\n\r\nfunction phenix()\r\n\treturn {\r\n";
  587.     for (let key in phenixData) {
  588.         txt += '\t\t{map = "' + phenixData[key][0].replace(" ", "") + '", path = "' + pathGenerator(key, phenixData) + '"},\r\n';
  589.     }
  590.     txt += "\t\t{map = \"12,12\", phenix = \"184\", path = \"" + pathGenerator(afterPhenix("12, 12"), pathData) + "\"}, -- [Cimetière] [9,16]\r\n" +
  591.         "\t\t{map = \"-10,-54\", phenix = \"342\", path = \"" + pathGenerator(afterPhenix("-10, -54"), pathData) + "\"}, -- [Lande De Cania] [-9,-54]\r\n" +
  592.         "\t\t{map = \"2,-12\", phenix = \"272\", path = \"" + pathGenerator(afterPhenix("2, -12"), pathData) + "\"} -- [Coin Des Tofus] [2,-12]\r\n\t}\r\nend\r\n";
  593.     saveTextAsFile(txt);
  594. }
  595.  
  596. function saveTextAsFile(txt) {
  597.     var textToSaveAsBlob = new Blob([txt], {
  598.         type: "text/plain"
  599.     });
  600.     var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
  601.     var fileNameToSaveAs = "Trajet.lua";
  602.     var downloadLink = document.createElement("a");
  603.     downloadLink.download = fileNameToSaveAs;
  604.     downloadLink.innerHTML = "Download File";
  605.     downloadLink.href = textToSaveAsURL;
  606.     downloadLink.style.display = "none";
  607.     document.body.appendChild(downloadLink);
  608.     downloadLink.click();
  609. }
  610.  
  611. function deletePath() {
  612.     for (let index = 0; index < pathData.length; index) {
  613.         if (pathData[index][2]) map.removeLayer(pathData[index][2]);
  614.         if (pathData[index][4]) map.removeLayer(pathData[index][4]);
  615.         if (pathData[index][6]) map.removeLayer(pathData[index][6]);
  616.         if (pathData[index][8]) map.removeLayer(pathData[index][8]);
  617.         pathData.splice(index, 1);
  618.     }
  619.     for (let index = 0; index < bankData.length; index) {
  620.         if (bankData[index][2]) map.removeLayer(bankData[index][2]);
  621.         if (bankData[index][4]) map.removeLayer(bankData[index][4]);
  622.         if (bankData[index][6]) map.removeLayer(bankData[index][6]);
  623.         if (bankData[index][8]) map.removeLayer(bankData[index][8]);
  624.         bankData.splice(index, 1);
  625.     }
  626.     for (let index = 0; index < phenixData.length; index) {
  627.         if (phenixData[index][2]) map.removeLayer(phenixData[index][2]);
  628.         if (phenixData[index][4]) map.removeLayer(phenixData[index][4]);
  629.         if (phenixData[index][6]) map.removeLayer(phenixData[index][6]);
  630.         if (phenixData[index][8]) map.removeLayer(phenixData[index][8]);
  631.         phenixData.splice(index, 1);
  632.     }
  633.     console.clear();
  634. }
  635.  
  636. document.getElementById('file').onchange = function () {
  637.  
  638.     var file = this.files[0];
  639.     var content;
  640.     var reader = new FileReader();
  641.     reader.onload = function (progressEvent) {
  642.         // Entire file
  643.         content = this.result;
  644.         let regexPath = /function move\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
  645.         let regexBank = /function bank\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
  646.         let regexPhenix = /function phenix\(\)[\s\S]+?return.*?{\r\n([\s\S]+?)}\r\n.*end/g;
  647.         let result;
  648.         let matche = regexBank.exec(content);
  649.         loadingFile = true;
  650.         if (matche !== null) {
  651.             result = matche[1];
  652.             result = result.split('\r\n');
  653.             for (let index = 0; index < result.length; index++) {
  654.                 matche = /map.?=.?"(.*?)"/g.exec(result[index]);
  655.                 if (matche !== null) actualMap = matche[1];
  656.                 actualMap = actualMap.replace(/,/g, ", ");
  657.                 if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
  658.                     matche = /top/g.exec(result[index]);
  659.                     if (matche !== null) document.getElementById("pathTop").checked = true;
  660.                     matche = /left/g.exec(result[index]);
  661.                     if (matche !== null) document.getElementById("pathLeft").checked = true;
  662.                     matche = /bottom/g.exec(result[index]);
  663.                     if (matche !== null) document.getElementById("pathBottom").checked = true;
  664.                     matche = /right/g.exec(result[index]);
  665.                     if (matche !== null) document.getElementById("pathRight").checked = true;
  666.                     document.getElementById("bank").checked = true;
  667.                     onMapClick();
  668.                     document.getElementById("pathTop").checked = false;
  669.                     document.getElementById("pathLeft").checked = false;
  670.                     document.getElementById("pathBottom").checked = false;
  671.                     document.getElementById("pathRight").checked = false;
  672.                     document.getElementById("bank").checked = false;
  673.                 }
  674.             }
  675.         }
  676.         matche = regexPath.exec(content);
  677.         if (matche !== null) {
  678.             result = matche[1];
  679.             result = result.split('\r\n');
  680.             for (let index = 0; index < result.length; index++) {
  681.                 matche = /map.?=.?"(.*?)"/g.exec(result[index]);
  682.                 if (matche !== null) actualMap = matche[1];
  683.                 actualMap = actualMap.replace(/,/g, ", ");
  684.                 if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
  685.                     matche = /top/g.exec(result[index]);
  686.                     if (matche !== null) document.getElementById("pathTop").checked = true;
  687.                     matche = /left/g.exec(result[index]);
  688.                     if (matche !== null) document.getElementById("pathLeft").checked = true;
  689.                     matche = /bottom/g.exec(result[index]);
  690.                     if (matche !== null) document.getElementById("pathBottom").checked = true;
  691.                     matche = /right/g.exec(result[index]);
  692.                     if (matche !== null) document.getElementById("pathRight").checked = true;
  693.                     matche = /gather/g.exec(result[index]);
  694.                     if (matche !== null) document.getElementById("gather").checked = true;
  695.                     matche = /fight/g.exec(result[index]);
  696.                     if (matche !== null) document.getElementById("fight").checked = true;
  697.                     onMapClick();
  698.                     document.getElementById("pathTop").checked = false;
  699.                     document.getElementById("pathLeft").checked = false;
  700.                     document.getElementById("pathBottom").checked = false;
  701.                     document.getElementById("pathRight").checked = false;
  702.                     document.getElementById("gather").checked = false;
  703.                     document.getElementById("fight").checked = false;
  704.                 }
  705.             }
  706.         }
  707.         matche = regexPhenix.exec(content);
  708.         if (matche !== null) {
  709.             result = matche[1];
  710.             result = result.split('\r\n');
  711.             for (let index = 0; index < result.length; index++) {
  712.                 matche = /map.?=.?"(.*?)"/g.exec(result[index]);
  713.                 if (matche !== null) actualMap = matche[1];
  714.                 actualMap = actualMap.replace(/,/g, ", ");
  715.                 if (/(-|)[0-9]+?,\s(-|)[0-9]+?/g.exec(actualMap)) {
  716.                     matche = /top/g.exec(result[index]);
  717.                     if (matche !== null) document.getElementById("pathTop").checked = true;
  718.                     matche = /left/g.exec(result[index]);
  719.                     if (matche !== null) document.getElementById("pathLeft").checked = true;
  720.                     matche = /bottom/g.exec(result[index]);
  721.                     if (matche !== null) document.getElementById("pathBottom").checked = true;
  722.                     matche = /right/g.exec(result[index]);
  723.                     if (matche !== null) document.getElementById("pathRight").checked = true;
  724.                     document.getElementById("phenix").checked = true;
  725.                     onMapClick();
  726.                     document.getElementById("pathTop").checked = false;
  727.                     document.getElementById("pathLeft").checked = false;
  728.                     document.getElementById("pathBottom").checked = false;
  729.                     document.getElementById("pathRight").checked = false;
  730.                     document.getElementById("phenix").checked = false;
  731.                 }
  732.             }
  733.         }
  734.         loadingFile = false;
  735.     };
  736.     reader.readAsText(file);
  737. };
  738.  
  739. function keypressHandler(evt) {
  740.     var keyCode = evt.key;
  741.     switch (keyCode) {
  742.         case "z":
  743.             if (!document.getElementById("pathTop").checked)
  744.                 document.getElementById("pathTop").checked = true;
  745.             else
  746.                 document.getElementById("pathTop").checked = false;
  747.             break;
  748.         case "q":
  749.             if (!document.getElementById("pathLeft").checked)
  750.                 document.getElementById("pathLeft").checked = true;
  751.             else
  752.                 document.getElementById("pathLeft").checked = false;
  753.             break;
  754.         case "s":
  755.             if (!document.getElementById("pathBottom").checked)
  756.                 document.getElementById("pathBottom").checked = true;
  757.             else
  758.                 document.getElementById("pathBottom").checked = false;
  759.             break;
  760.         case "d":
  761.             if (!document.getElementById("pathRight").checked)
  762.                 document.getElementById("pathRight").checked = true;
  763.             else
  764.                 document.getElementById("pathRight").checked = false;
  765.             break;
  766.         default:
  767.             break;
  768.     }
  769. }
  770.  
  771. map.on('click', onMapClick);
  772. document.addEventListener("keypress", keypressHandler, false);
Advertisement
Add Comment
Please, Sign In to add comment