Kittens Game Data output

enter something useful

目前为 2015-06-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         Kittens Game Data output
// @namespace    https://greasyfork.org/en/scripts/10234-kittens-game-data-output
// @version      0.2.1
// @description  enter something useful
// @author       Yuriy
// @match        http://bloodrizer.ru/games/kittens/
// @grant        none
// ==/UserScript==

function initiate_script() {
    var data_out = document.createElement('div');
    data_out.id = 'data_container';
//    data_out.style.width = '100%';
    data_out.style.height = '150px';
    data_out.style.bottom = '0px';
    data_out.style.padding = '5px';
    data_out.style.position = 'absolute';
    data_out.style.background = "#878787"
    data_out.style.border = "2px solid #787878";
    data_out.style.borderRadius = '25px';
    data_out.innerHTML = '<div style="float: left; width: 340px;"> <table id="food_table_season" table-layout: fixed;></table></div></div><div style="float: left;"> <p id="food_balance_info"></p> </div>';
    document.body.appendChild(data_out);
    
    document.getElementById('data_container').style.display = '';
    document.getElementById('game').style.marginBottom = '200px';
    document.getElementById('footerLinks').style.marginBottom = '150px';
    document.body.style.backgroundPosition = 'center bottom 30px';
}

if (!document.getElementById('data_container')) {
  initiate_script();
}

function calculate_food_income_data(weather_ratio_val, seconds) {
    var total = 0;
    var subtotal = 0;
    
    total += gamePage.getEffect("catnip" + "PerTickBase")*5
    total *= 1+weather_ratio_val;
    
    var resMapProduction = gamePage.village.getResProduction();
    subtotal = resMapProduction['catnip']*5 || 0;
    subtotal *= (1 + gamePage.workshop.getEffect('catnip' + "Ratio"))
    
    total += subtotal;
    
    total *= (1 + gamePage.bld.getEffect('catnip' + "Ratio"))
    
    total *= (1 + gamePage.space.getEffect('catnip' + "Ratio"))
    
    total *= (1 + gamePage.religion.getEffect('catnip' + "Ratio"))
    
    var paragonRatio = gamePage.resPool.get("paragon").value * 0.01;
    paragonRatio = gamePage.bld.getHyperbolicEffect(paragonRatio, 2);
    
    total *= 1+paragonRatio
    
    if (gamePage.religion.getRU("solarRevolution").researched){
        total *= 1+(gamePage.religion.getProductionBonus() / 100)
	}
    
    total *= seconds;
    
    return total;
}

function calculate_food_data(weather_ratio_val, seconds) {
    var total = calculate_food_income_data(weather_ratio_val, seconds);
    
    var resMapConsumption = gamePage.village.getResConsumption();
    var resConsumption = resMapConsumption['catnip'] || 0;
    resConsumption = resConsumption * (1 + gamePage.bld.getEffect('catnip' + "DemandRatio", true));
    resConsumption *= 5;
    resConsumption *= seconds;
    
    total += resConsumption;
    
    return total
}

function val_to_printable(total) {
    var total_value = '';
    
    if(Math.abs(total)>1000){
        total = total / 1000;
        total = total.toFixed(1);
        total_value += total;
        total_value += ' k';
    }else{
        total = total.toFixed(2);
        total_value += total;
    }
    
    return total_value;
    
}

function generate_food_table(seconds, label) {
    var contents = '';
    //Define the table colomn widths
    contents += '<col width="100">';
    contents += '<col width="60">';
    contents += '<col width="60">';
    contents += '<col width="60">';
    contents += '<col width="60">';
    //The top of the table, describing what it is showing. Leave once cell blank at the start
    contents += '<tr>';
    contents += '<td style="text-align:center">'
    contents += ' '
    contents += '</td>';
    contents += '<td style="text-align:center" colspan="4">'
    contents += label
    contents += '</td>';
    contents += '</tr>';
    //Second level of the top of the table, describing what it is showing. Leave once cell blank at the start
    contents += '<tr>';
    contents += '<td style="text-align:center">'
    contents += ' '
    contents += '</td>';
    contents += '<td style="text-align:center">'
    contents += 'Winter'
    contents += '</td> <td style="text-align:center">'
    contents += 'Spring'
    contents += '</td> <td style="text-align:center">'
    contents += 'Summer'
    contents += '</td> <td style="text-align:center">'
    contents += 'Fall'
    contents += '</td>';
    contents += '</tr>';
    //Data for a good season
    contents += '<tr>';
    contents += '<td style="text-align:center">'
    contents += 'Good season'
    contents += '</td>';
    contents += '<td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(-0.60, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.65, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.15, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.15, seconds))
    contents += '</td>';
    contents += '</tr>';
    //Data for an average season
    contents += '<tr>';
    contents += '<td style="text-align:center">'
    contents += 'Normal season'
    contents += '</td>';
    contents += '<td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(-0.75, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.50, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.0, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.0, seconds))
    contents += '</td>';
    contents += '</tr>';
    //Data for a bad season
    contents += '<tr>';
    contents += '<td style="text-align:center">'
    contents += 'Bad season'
    contents += '</td>';
    contents += '<td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(-0.90, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(0.35, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(-0.15, seconds))
    contents += '</td> <td style="text-align:center">'
    contents += val_to_printable(calculate_food_data(-0.15, seconds))
    contents += '</td>';
    contents += '</tr>';
    return contents
}

function generate_food_balance_data() {
    var contents = '';
    contents += "Yearly food produced (avg): ";
    contents += val_to_printable(calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200))
    contents += "<br>";
    var resMapConsumption = gamePage.village.getResConsumption();
    var resConsumption = resMapConsumption['catnip'] || 0;
    resConsumption = resConsumption * (1 + gamePage.bld.getEffect('catnip' + "DemandRatio", true));
    resConsumption *= 5;
    resConsumption *= 800;
    contents += "Yearly food consumed (avg): ";
    contents += val_to_printable(-resConsumption);
    contents += "<br>";
    contents += "Surplus (or deficit): ";
    contents += val_to_printable(calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption);
    contents += "<br>";
    contents += "Surplus/consumed: ";
    if((calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100 >= 15) {
        contents += '<span style="color: green;">'
    }else if((calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100 <= 5 && (calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100 >= 0) {
        contents += '<span style="color: yellow;">'
    }else if((calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100 <= 5 && (calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100 < 0) {
        contents += '<span style="color: red;">'
    }else{
        contents += '<span">'
    }
    contents += val_to_printable((calculate_food_income_data(-0.75, 200)+calculate_food_income_data(0.50, 200)+calculate_food_income_data(0.0, 200)+calculate_food_income_data(0.0, 200)+resConsumption)/(-resConsumption)*100);
    contents += "%";
    contents += '</span>'
    contents += "<br>";
    return contents;
}

function output_data() {
    document.getElementById('food_table_season').innerHTML = generate_food_table(200, 'Food during seasons (/season)');
    document.getElementById('food_balance_info').innerHTML = generate_food_balance_data();
}

setInterval(output_data, 200);