<?php
/*
 *
 * @copyright (c) 2010 animegame.eu
 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
 *
 */
include "db.php";
include_once('path.inc.php'); // get the path ;)
include_once ('inclu/messagefunctions.inc.php');
include_once ('inclu/halloffame.inc.php');
include_once ('inclu/fruitdistribution.inc.php');
include_once ('inclu/exp.inc.php');
include_once (ROOT_PATH.'/include/usergroup.inc.php');
include_once ('inclu/turnier.inc.php');
include_once ('inclu/char.inc.php');

// calculate the avg level of the chars participating
$sql = '(Select distinct(char1) as x from turnier_kampf where art = \'gross\' ) union (Select distinct(char2) as x from turnier_kampf where art = \'gross\' )';

$charids = array();
$qry1 = mysql_query($sql);
while($row = mysql_fetch_assoc($qry1)){
	$charids[] = $row['x'];
}

$sql2 = 'Select avg(level) as dlevel from chars where id in ('.join(',', $charids).')';
$row = mysql_fetch_assoc(mysql_query($sql2));

$dlevel = ceil($row['dlevel']);

// do the stuff for the whole exp and money distribution there ;)
$results = generateTournamentResults('gross', 250000, 2000000);
$rang1 = getChar($results[0][0]);

insertIntoHallOfFame('Weltturnier', $rang1['id'], $rang1['besitzer']);

//$natur_frucht = mysql_num_rows(mysql_query("SELECT id FROM wochen_markt WHERE art='natur'"));		///wieviel TF gibt es?.

////////////////FRUCHT ARRAY
//include "array.php";
distributeFruit($rang1['besitzer']);

//Schutz vor automatischem löschen hinzufügen für den sieger :)
$usergroups = getUserGroups($rang1['besitzer']);
if(!isUserInGroup($usergroups, INAKTIV_LOESCHSCHUTZ) && !isUserInGroup($usergroups, AKTIV_LOESCHSCHUTZ)) {
	addUserToGroup($rang1['besitzer'], INAKTIV_LOESCHSCHUTZ);
}

// Durchschnittslevel


$summe = 20000000/(1+exp(5-$dlevel/14));

// Now distribute the shop points ;)

$prices[] = 100; // 1.
$prices[] = 90;  // 2.
$prices[] = 75;  // 3. + 4.
$prices[] = 50;  // 5. - 8.
$prices[] = 25;  // 9. - 16.

$cprices[] = ceil($summe/2);
$cprices[] = ceil($summe/4);
$cprices[] = ceil($summe/8);

distributeShopPoints($prices, $results, 'Weltturnier');
distributeClanPrices($cprices, $results, 'Weltturnier');

?>