Actions

MediaWiki

Common.js: Difference between revisions

From Necroxia Origin

mNo edit summary
m (Replaced content with "→‎Any JavaScript here will be loaded for all users on every page load.: mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=t...")
Tag: Replaced
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
$("#testdiv").each(function() {
mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=text/javascript' );
var parent = $(this);
//var inputs = ['currentRoom', 'currentCount', 'answerNumber'];
var inputs = [
['currentRoom', 1, 32, 1, 'Escribe aqui el numero de la habitacion en que te encuentras:'], ['answerNumber', 31, 93, 77,'Escribe aqui el numero al que necesitas llegar:'], ['currentCount', 0, 999, 0,'Escribe aqui tu cuenta actual:']
];
//var textToPrint = "";
//var d = document.createElement('div');
$(this).append("<table id='table1' border='1px'></table>");
//$('#table1').append("<tr><td colspan='2' align='center'>Teleport Calculator</td></tr>");
for (i = 0; i < inputs.length; i++) {
$('#table1').append("<tr><td>"+inputs[i][4]+"</td><td><input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/></td></tr>");
//$(this).append("<input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/>");
//$(this).append("<br> id="+inputs[i][0]+" name="+inputs[i][0]+" min="+inputs[i][1]+" max="+inputs[i][2]+" value="+inputs[i][3]);
}
$('#table1').append("<tr><td colspan='2' style='text-align:center'><button id='button1'>Summit</button></td></tr>");
$(this).append("<p id='parrafo1'><span id=span1></span></p>");
$('#button1').click( function() {
getPossibleTeleports( $('#currentRoom').val(), $('#currentCount').val(), $('#answerNumber').val());
//$('#text1').remove();
//$('#span1').html(textToPrint);
});
//var currentRoom = $('#currentRoom').val();
//$(this).append("<br>"+currentRoom);
//$(this).append("<br> " + $("input[id=currentRoom]").value);
});
 
const totalRooms = 32; // total de habitacion que debe pasar
const minCount = 31;
const maxCount = 93;
 
function getPossibleTeleports(currentRoom, currentCount, answerNumberIni) {
var isPossible = false;
var a = 0;
var b = 0;
var c = 0;
var outputText = '';
var roomsLeft = totalRooms - currentRoom;
var answerNumber = answerNumberIni - currentCount;
if (validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni)){
return false;
}
//if (isCorrect === false) {
//return true;
// getPossibleTeleports();
// }
while (c <= roomsLeft) {
a = calculateA(answerNumber, roomsLeft, c);
b = calculateB(answerNumber, roomsLeft, c);
if (a !== -1 && b !== -1 && ((a + b + c) === roomsLeft) && ((a + (2 * b) + (3 * c)) === answerNumber)){
//outputText += 'sum1: ' + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ' -> a: ' + a + ', b: ' + b + ', c: ' + c + ' - Rooms: ' + roomsLeft + ', AnswerNumber: ' + answerNumber + '<br>';
//alert(`sum1: ` + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ` -> a: ` + a + `, b: ` + b + `, c: ` + c + ` - Rooms: ` + roomsLeft + `, AnswerNumber: ` + answerNumber);
isPossible = true;
break;
}
//console.log("sum1: ", (a + b + c), ", sum2: ", (a + (2 * b) + (3 * c))," -> a: ", a,", b: ", b,", c: ", c," - Rooms: ", roomsLeft, ", AnswerNumber: ", answerNumber);
//alert(`sum1: ` + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ` -> a: ` + a + `, b: ` + b + `, c: ` + c + ` - Rooms: ` + roomsLeft + `, AnswerNumber: ` + answerNumber);
c++;
}
if (isPossible === true) {
outputText += 'Puedes tomar el <b>Teleport 1 </b>(<b>' + a + '</b>) veces, el <b>Teleport 2</b> (<b>' + b + '</b>) veces y el <b>Teleport 3</b> (<b>' + c + '</b>) veces.';
//alert(`Puedes tomar (` + a + `) veces T1, (` + b + `) veces T2, (` + c + `) veces T3.`);
} else {
outputText += 'Debes ir hasta el ultimo Teleport para reiniciar tu Cuenta, no es posible completar la Quest con tu cuenta actual.';
//alert(`no es posible, debes reiniciar tu cuenta ${c} !`);
}
//getPossibleTeleports();
// alert(`Existen en total ${totalRooms} habitaciones!`);
//document.getElementById("answer").innerHTML = outputText;
$('#span1').html(outputText);
return true;
}
 
 
 
 
 
function validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni){
var isError = false;
var outputText = '';
if (currentRoom < 1 || currentRoom > totalRooms || currentRoom % 1 !== 0) {
outputText += 'El numero de tu habitacion actual debe ser un <b>entero</b> entre <b>1</b> y <b>' + totalRooms + '</b> .<br>';
isError = true;
}
if (answerNumberIni < minCount || answerNumberIni > maxCount || answerNumberIni % 1 !== 0) {
outputText += 'el numero al que necesitas llegar debe ser un <b>entero</b> entre <b>' + minCount + '</b> y <b>' + maxCount + '</b>.<br>';
isError = true;
}
if (currentCount < 0 || currentCount % 1 !== 0) {
outputText += 'Tu cuenta debe ser un <b>entero</b> mayor o igual a 0.<br>';
isError = true;
}
if (answerNumber < 0) {
outputText += 'Tu cuenta es muy alta debes reiniciar.<br>';
isError = true;
}
if (isError) {
//document.getElementById("answer").innerHTML = outputText;
$('#span1').html(outputText);
}
return isError;
}
 
function calculateA(answerNumber, roomsLeft, c){
var a = c + (2 * roomsLeft) - answerNumber;
//console.log(a, " = ", c , " + (2 * ", roomsLeft, ") - ",answerNumber)
if (a < 0 || a % 1 !== 0){
//console.log("a % 1 = ",a % 1);
return -1;
}
return a;
}
 
function calculateB(answerNumber, roomsLeft, c){
var b = answerNumber - roomsLeft - (2 * c);
//console.log(b, " = ", answerNumber , " - ",roomsLeft ," - (2 * ", c, ")")
if (b < 0 || b % 1 !== 0){
//console.log("b % 1 = ",b % 1)
return -1;
}
return b;
}

Latest revision as of 12:08, 1 September 2020

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load( '/w/index.php?title=MediaWiki:UrsagrodonTeleportCalculator.js&action=raw&ctype=text/javascript' );