javascript
// JavaScript Document
//English description
// Javascript Object for Common Ogame Calculations
// Created by Konstantinos Tsatsarounos
// Emails: konstantinos.tsatsarounos@gmail.com, admin@infogeek.gr
//Website: www.infogeek.gr
// Δημιουργός: Κωνσταντίνος Τσατσαρούνος
/*Αντικείμενο για τους πιο συνηθισμένους υπολογισμούς για πλοία στο Ogame.
Παραδείγματα:
RC.metalcost επιστρέφει την αξία σε μεταλλο του ανακυκλωτη
RC.crystalcost επιστρέφει το κόστος σε κρύσταλλο του ανακυκλωτή
RC.deutcost επιστρέφει το κόστος σε δευτέριο του ανακυκλωτή
RC.resvalue επιστρέφει το σύνολο της αξίας σε πόρους του ανακυκλωτή
RC.dbvalue επιστρέφει το σύνολο μετάλλου και κρυστάλλου του ανακυκλωτή
RC.resforships(ποσοτητα για πλοία - αριθμός) επιστρεφει την αξία σε πόρους της ποσότητας των ανακυκλωτων μέσα στην παρενθεση, αναλυτικά.
RC.shipsfores(μέταλλο, κρύσταλλο, δευτέριο) επιστρέφει το πόσα πλοία μπορείς να φτιάξεις με τους πόρους στην παρένθεση*/
/*
Examples:
RC.metalcost return the metal cost of a recycler
RC.crystalcost return the crystal cost of a recycler
RC.deutcost return the deuterium cost of a recycler
RC.resvalue return the total cost of a recycler
RC.dbvalue return the amount of metal + crystal of a recycler
RC.resforships(amount of ships - integer) return the cost in resources of a recycler, for the given number
RC.shipsfores(metal, crystal, deuterium) return the number of ships which can be manufactured for the given number of resources*/
*/
function ship(metal,crystal,deuterium){
this.metalcost= (typeof(metal)!='undefined' && !isNaN(metal))? eval(metal) : 0;
this.crystalcost= (typeof(crystal)!='undefined' && !isNaN(crystal))? eval(crystal) : 0;
this.deutcost= (typeof(deuterium)!='undefined' && !isNaN(deuterium))? eval(deuterium) : 0;
this.resvalue=0;
this.dbvalue =0;
if(this.metalcost!='undefined' && this.crystalcost!='undefined' && this.deutcost!='undefined'){
this.resvalue= this.metalcost + this.crystalcost + this.deutcost;
this.dbvalue = this.metalcost + this.crystalcost;
this.resforships = function(amount){
amount = (amount=='undefined' || amount==' ' || isNaN(amount)) ? 0 : amount;
var res = [this.metalcost,this.crystalcost,this.deutcost];
res[0]=amount*res[0];
res[1]=amount*res[1];
res[2]=amount*res[2];
res = res.join(',');
return res;
}
this.shipsfores= function(M,C,D){
M= (M!='undefined' && !isNaN(M)) ? M : 0;
C= (C!='undefined' && !isNaN(C)) ? C : 0;
D= (D!='undefined' && !isNaN(D)) ? D : 0;
var arr = [M,C,D];
arr[0]= Math.floor(arr[0]/this.metalcost);
arr[1]= Math.floor(arr[1]/this.crystalcost);
arr[2]= Math.floor(arr[2]/this.deutcost);
return Math.min.apply(null,arr);
}
}
else {this.resvalue = 'empty method'; this.dbvalue='empty method';}
}
//Ορισμοί αντικειμένων πλοίων
var SC = new ship(2000,2000,0);
var LC = new ship(6000,6000,0);
var LF = new ship(3000,1000,0);
var HF = new ship(6000,4000,0);
var CR = new ship(20000,7000,2000);
var BS = new ship(45000,15000,0);
var BC = new ship(30000,40000,15000);
var DST = new ship(60000,50000,15000);
var DSR = new ship(5000000,4000000,1000000);
var BM = new ship(50000,25000,15000);
var RC = new ship(10000,6000,2000);
var ESP = new ship(0,1000,0);
var SS = new ship(0,2000,500);
var CS = new ship(10000,20000,10000);
/* Πολλαπλασιάζει ποσότητες πλοίων με την αξία τους σε πόρους!
Βαζεις σε ένα πίνακα ποσότητες για όλα τα πλοία, 0 εάν δεν θέλεις κάποιο πλοίο στην ανάλογη θέση και τον βάζεις μέσα στην ResVCalc πχ: pinakas = ResVCalc(pinakas); και επιστρέφει στην ίδια θέση την αξία των πλοίων του κάθε τύπου σε πόρους!*/
function ResVCalc(amounts){
amounts[0] = amounts[0] * SC.resvalue *0.25;
amounts[1] = amounts[1] * LC.resvalue *0.25;
amounts[2] = amounts[2] * LF.resvalue;
amounts[3] = amounts[3] * HF.resvalue;
amounts[4] = amounts[4] * CR.resvalue;
amounts[5] = amounts[5] * BS.resvalue;
amounts[6] = amounts[6] * BC.resvalue;
amounts[7] = amounts[7] * BM.resvalue;
amounts[8] = amounts[8] * DST.resvalue;
amounts[9] = amounts[9] * DSR.resvalue;
amounts[10] = amounts[10] * RC.resvalue*0.25;
amounts[11] = amounts[11] * ESP.resvalue*0;
amounts[12] = amounts[12] * SS.resvalue*0.25;
amounts[13] = amounts[13] * CS.resvalue*0.25;
return amounts;
}
// Μετατρέπει κείμενο με τρεις αριθμούς χωρισμένους με κόμμα (,) σε πίνακα τριών θέσεων!
// '15000,586000,45600' => 1 => 15000, 2 => 58600, 3 => 45600
function Digit3Catching(text){
regxp = /^\d{0,},\d{0,},\d{0,}$/,sdxp = /[0-9]{0,}/g;
text = (regxp.test(text)) ? text.split(',') : '';
if(text!=''){
for(var i=0; i<3; i++){ text[i]=Number(text[i])}
// Μετατροπές σε αριθμούς
}
else{ text = "<span style='color:red'>Λάθος εισαγωγή</span>";}
return text;
}