(function(){ "use strict"; var BATTLE_INVALID = 0, BATTLE_BASIC = 1, BATTLE_NIGHT = 2, BATTLE_AERIAL = 4, // Sortie Boss Node Indicator // FIXME: this is not for translation. to test sortie status SORTIE_STRING = { faild : "Did not reach boss", fresh : "Did not able to hurt", graze : "Hurt the boss a little", light : "Lightly Damages the Boss", modrt : "Moderately Damages the Boss", heavy : "Heavily Damages the Boss", despe : "Leaves the boss below 10HP", endur : "Leaves the boss below 2HP", destr : "Completely destroys" }; /* KC3 Sortie Logs Arguments: tabRefer -- StrategyTab object reference callable -- database function */ window.KC3SortieLogs = function(tabCode) { this.tabSelf = KC3StrategyTabs[tabCode]; this.maps = {}; this.selectedWorld = 0; this.selectedMap = 0; this.itemsPerPage = 20; this.currentSorties = []; this.stegcover64 = ""; this.exportingReplay = false; /* INIT Prepares static data needed ---------------------------------*/ this.init = function(){ }; /* RELOAD Prepares reloadable data ---------------------------------*/ this.reload = function(){ if(typeof localStorage.maps != "undefined"){ this.maps = JSON.parse( localStorage.maps ); }else{ return false; } }; /* EXECUTE Places data onto the interface ---------------------------------*/ this.execute = function(){ var self = this; // On-click world menus $(".tab_"+tabCode+" .world_box").on("click", function(){ if(!$(".world_text",this).text().length) { return false; } KC3StrategyTabs.gotoTab(null, $(this).data("world_num")); }); // Toggleable world scroll $(".tab_"+tabCode+" .world_shift").on("click", function(){ var le,cr,re; le = 0; cr = $(window).data("world_off"); re = $(window).data("world_max"); $(window).data("world_off",cr = Math.max(le,Math.min(re,(function(e){ if(e.hasClass("disabled")) return cr; else if(e.hasClass("left")) return cr-1; else if(e.hasClass("right")) return cr+1; else return cr; })($(this))))); updateScrollItem("world", 116); }); // On-click map menus $(".tab_"+tabCode+" .map_list").on("click", ".map_box", function(){ KC3StrategyTabs.gotoTab(null, self.selectedWorld, $(this).data("map_num")); }); // Toggleable map scroll $(".tab_"+tabCode+" .map_shift").on("click", function(){ var le,cr,re; le = 0; cr = $(window).data("map_off"); re = $(window).data("map_max"); $(window).data("map_off",cr = Math.max(le,Math.min(re,(function(e){ if(e.hasClass("disabled")) return cr; else if(e.hasClass("left")) return cr-1; else if(e.hasClass("right")) return cr+1; else return cr; })($(this))))); updateScrollItem("map", 97); }); // On-click sortie ID export battle $(".sortie_list").on("click", ".sortie_id", function(){ self.exportBattleImg(parseInt($(this).text())); }); // On-click sortie toggles $(".tab_"+tabCode+" .sortie_list").on("click", ".sortie_box .sortie_toggles .sortie_toggle", function(){ var targetName = $(this).data("target"); var targetParent = $(this).parent().parent().parent(); var targetBox = targetParent.find("."+targetName); var expandedQualif = !$(this).hasClass("sortie_toggle_in"); var expandedBefore = $(".sortie_toggle.active:not(.sortie_toggle_in)",$(this).parent()).length; if( $(this).hasClass("active") ){ $(this).removeClass("active"); }else{ $(this).addClass("active"); } var expandedAfter = $(".sortie_toggle.active:not(.sortie_toggle_in)",$(this).parent()).length; // Show or hide the target box targetBox.slideToggle(undefined,function(){ if(expandedQualif && expandedBefore < 1) targetParent.addClass("expanded"); }); if(expandedQualif && expandedAfter < 1) targetParent.removeClass("expanded"); }); if(!!KC3StrategyTabs.pageParams[1]){ this.switchWorld(KC3StrategyTabs.pageParams[1], KC3StrategyTabs.pageParams[2]); } else { // Select default opened world this.switchWorld($(".tab_"+tabCode+" .world_box.active").data("world_num")); } }; /* SWITCH WORLD Handle event on a world has been selected by clicking menu or by url ---------------------------------*/ this.switchWorld = function(worldNum, mapNum){ var self = this; self.selectedWorld = Number(worldNum); $(".tab_"+tabCode+" .world_box").removeClass("active"); $(".tab_"+tabCode+" .world_box[data-world_num={0}]".format(self.selectedWorld)).addClass("active"); $(".tab_"+tabCode+" .map_list").empty().css("width","").css("margin-left",""); $(".tab_"+tabCode+" .page_list").empty(); $(".tab_"+tabCode+" .sortie_list").empty(); var countWorlds = $(".tab_"+tabCode+" .world_box").length; var worldOffset = $(window).data("world_off"); var selectOffset = $(".tab_"+tabCode+" .world_box[data-world_num={0}]".format(self.selectedWorld)).index(); if(typeof worldOffset === "undefined"){ $(window).data("world_off", Math.min(selectOffset, countWorlds-6)); } else if(selectOffset < worldOffset){ $(window).data("world_off", selectOffset); } else if(selectOffset >= 6+((tabCode=="maps")&1) && worldOffset < selectOffset-5){ $(window).data("world_off", selectOffset-5); } $(window).data("world_max", Math.max(0, countWorlds-6)); updateScrollItem("world", 116); if(self.selectedWorld !== 0){ // Add all maps in this world selection var mapBox,countMaps; mapBox = $(".tab_"+tabCode+" .factory .map_box").clone().appendTo(".tab_"+tabCode+" .map_list"); $(".map_title", mapBox) .text((function(x){ return (x>=10) ? KC3Meta.term("StrategyEventGo") : ("All W"+x); })(self.selectedWorld)); for(countMaps = 1;!!self.maps["m"+self.selectedWorld+countMaps];countMaps++){} $(".tab_"+tabCode+" .map_list").css("width",Math.max(7,countMaps)*100); mapBox.attr("data-map_num", 0); $(window).data("map_off", (self.selectedWorld > 10 && countMaps >= 8) ? 1 : 0); $(window).data("map_max", Math.max(0,countMaps-7)); mapBox.addClass("empty"); mapBox.addClass("active"); updateScrollItem("map", 97); var diffStr = ["E","N","H"]; // Check player's map list $.each(self.maps, function(index, element){ var cWorld = (""+element.id).substr(0, (""+element.id).length-1); var cMap = (""+element.id).substr((""+element.id).length-1); // If this map is part of selected world if(cWorld == self.selectedWorld){ mapBox = $(".tab_"+tabCode+" .factory .map_box").clone().appendTo(".tab_"+tabCode+" .map_list"); mapBox.attr("data-map_num", cMap); $(".map_title", mapBox).text((cWorld>=10 ? "E" : cWorld)+" - "+cMap+(function(x){ switch(x){ case 1: case 2: case 3: return " " + diffStr[x-1]; default: return ""; } })(element.difficulty)); // Check unselected difficulty if(cWorld >= 10 && !element.difficulty) { mapBox.addClass("noclearnogauge"); $(".map_hp_txt", mapBox).text("No difficulty"); } else { // EASY MODO STRIKES BACK if(ConfigManager.info_troll && element.difficulty==1) { mapBox.addClass("easymodokimoi"); } // If this map is already cleared if(element.clear == 1){ $(".map_hp_txt", mapBox).text("Cleared!"); mapBox.addClass("cleared"); }else{ mapBox.addClass("notcleared"); // If HP-based gauge if(typeof element.maxhp != "undefined"){ if(element.curhp>(element.baseHp || 1)){ // i want to approach last kill as JUST DO IT instead leaving 1HP only. if((element.maxhp === 9999) || (element.curhp === 9999)) $(".map_hp_txt", mapBox).text( "???? / ????" ); else $(".map_hp_txt", mapBox).text( element.curhp+" / "+element.maxhp ); $(".map_bar", mapBox).css("width", ((element.curhp/element.maxhp)*80)+"px"); }else{ mapBox.addClass("noclearnogauge"); if(ConfigManager.info_troll) mapBox .addClass("justdoit") .attr("title","just kill her already, yesterday you said tommorow! JUST DO IT!!!"); // placeholder class... $(".map_hp_txt", mapBox).text(KC3Meta.term("StrategyEvents1HP")); } // If kill-based gauge }else{ var totalKills = KC3Meta.gauge( element.id ); var killsLeft = totalKills - element.kills; if(totalKills){ if(killsLeft > 1) $(".map_hp_txt", mapBox).text( killsLeft+" / "+totalKills+" kills left"); else $(".map_hp_txt", mapBox).text( KC3Meta.term("StrategyEvents1HP") ); $(".map_bar", mapBox).css("width", ((killsLeft/totalKills)*80)+"px"); } else { mapBox.addClass("noclearnogauge"); $(".map_hp_txt", mapBox).text("Not cleared"); } } } } } }); $("