changes on the way of calculating exp and money at generic_tournaments. Also the processing of the results is now cleaned up :)
parent
715d41301e
commit
c327197f69
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* Created on 11.08.2008
|
||||
*
|
||||
* @copyright (c) 2009 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
|
||||
# Um die Datenbank nutzen zu koennen muss eine db.inc.php erstellt werden, bitte diese nicht in die Versionskontrolle einfügen!!
|
||||
|
||||
#####Online Bitte für localhost eintragen!!
|
||||
$db_host = "localhost";
|
||||
$db_user ="root";
|
||||
$db_passwort ="jodiho82";
|
||||
$db_name = "test_ag";
|
||||
|
||||
$main_db_name = "otherdatabasename";
|
||||
$GLOBALS['mumble_db_name'] = "anotheradatabasename";
|
||||
|
||||
if(!isset($conn)){
|
||||
$conn = mysql_connect($db_host, $db_user, $db_passwort);
|
||||
$db = mysql_select_db($db_name, $conn);
|
||||
}
|
||||
?>
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2010 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
//set_time_limit(0);
|
||||
|
||||
$art_1 ="gross";
|
||||
|
||||
function rand_array($array)
|
||||
{
|
||||
$maxarray=count($array)-1;
|
||||
mt_srand((double)microtime()*1000000);
|
||||
for($i=$maxarray; $i>=0; $i--)
|
||||
{
|
||||
if($i>0) $zufall=mt_rand(0,$i);
|
||||
else $zufall=0;
|
||||
$temp=$array[$i];
|
||||
$array[$i]=$array[$zufall];
|
||||
$array[$zufall]=$temp;
|
||||
$newarray[]=$array[$i];
|
||||
array_pop($array);
|
||||
}
|
||||
return $newarray;
|
||||
}
|
||||
|
||||
include "db.php";
|
||||
|
||||
$chars_max = mysql_num_rows(mysql_query("SELECT id FROM chars WHERE rasse !='NPC' ORDER BY level DESC LIMIT 512"));
|
||||
|
||||
if($chars_max<512) {
|
||||
echo "keine 512 spieler.";
|
||||
exit;
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM turnier_kampf WHERE art='$art_1'");
|
||||
|
||||
|
||||
$char1 = mysql_query("SELECT id FROM chars WHERE rasse !='NPC' ORDER BY level DESC LIMIT 512");
|
||||
while($row=mysql_fetch_array($char1))
|
||||
{
|
||||
$test2[]=$row['id'];
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
$test2 = rand_array($test2);
|
||||
$test2 = array_unique($test2);
|
||||
}
|
||||
|
||||
|
||||
while(count($test2)<512);
|
||||
|
||||
$test3=$test2;
|
||||
reset($test3);
|
||||
while(current($test3)!=end($test2))
|
||||
{
|
||||
if(empty($list)) $list=current($test3);
|
||||
else $list.=','.next($test3);
|
||||
}
|
||||
|
||||
$result=mysql_query("SELECT * FROM chars WHERE id IN(".$list.") LIMIT 512");
|
||||
while($row=mysql_fetch_array($result))
|
||||
{
|
||||
$charas[$row['id']]=$row;
|
||||
}
|
||||
|
||||
$a8=0;
|
||||
$b8=1;
|
||||
|
||||
$round = 1;
|
||||
while($a8 < 512)
|
||||
{
|
||||
$chara_1 = $charas[$test2[$a8]];
|
||||
$chara_2 = $charas[$test2[$b8]];
|
||||
include "turnier_kampf.php";
|
||||
$a8+=2;
|
||||
$b8+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while($round < 9)
|
||||
{
|
||||
unset($test9);
|
||||
|
||||
|
||||
$chars_win = mysql_Query("SELECT win FROM turnier_kampf WHERE round='$round' AND art='$art_1'");
|
||||
while($row9 = mysql_fetch_array($chars_win))
|
||||
{
|
||||
$test9[]=$row9['win'];
|
||||
}
|
||||
$round++;
|
||||
$k9=0;
|
||||
$l9=1;
|
||||
while($k9 < count($test9))
|
||||
{
|
||||
$chara_1 = $charas[$test9[$k9]];
|
||||
$chara_2 = $charas[$test9[$l9]];
|
||||
include "turnier_kampf.php";
|
||||
$k9+=2;
|
||||
$l9+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM turnier1 WHERE art='$art_1'");
|
||||
?>
|
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2011 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
|
||||
include_once 'exp.inc.php';
|
||||
include_once 'char.inc.php';
|
||||
include_once ('messagefunctions.inc.php');
|
||||
|
||||
/**
|
||||
* This function is ment to replace the copy&paste calculation that was previously when processing the result of a tournament.
|
||||
* @param string $name the name of the tournament (gross, klein, etc.)
|
||||
* @param int $additionalExpPerRound the amount of experience a char should get when reaching to the next level
|
||||
* @param int $additionalMoneyPerRound the amount of experience a char should get when reaching to the next level
|
||||
*/
|
||||
function generateTournamentResults($name, $additionalExpPerRound, $additionalMoneyPerRound) {
|
||||
// Generates a Ranking of the Chars like that based on the round, so [0] array( char1), [1] array(char2), [2] array(char3, char4) and so on!
|
||||
// the date containing is the CharId, the experience and money is transfered automatically ;)
|
||||
|
||||
$charArray = array();
|
||||
|
||||
$charids = array();
|
||||
|
||||
// First calculate the money and exp the char gets just for doing good at fights ;)
|
||||
$qry = mysql_query('select char1, char2, exp1, exp2, geld1, geld2, round from turnier_kampf where art = \''.$name.'\' order by round asc');
|
||||
|
||||
while($fight = mysql_fetch_assoc($qry)) {
|
||||
if(!isset($charArray[$fight['char1']])) {
|
||||
$charArray[$fight['char1']] = array('exp' => 0, 'money' => 0);
|
||||
$charids[$fight['char1']] = 1;
|
||||
}
|
||||
$charArray[$fight['char1']]['exp'] += $fight['exp1'];
|
||||
$charArray[$fight['char1']]['money'] += $fight['geld1'];
|
||||
|
||||
if(!isset($charArray[$fight['char2']])) {
|
||||
$charArray[$fight['char2']] = array('exp' => 0, 'money' => 0);
|
||||
$charids[$fight['char2']] = 1;
|
||||
}
|
||||
$charArray[$fight['char2']]['exp'] += $fight['exp2'];
|
||||
$charArray[$fight['char2']]['money'] += $fight['geld2'];
|
||||
}
|
||||
|
||||
$returnArray = array();
|
||||
|
||||
// Now calculate the money and exp the char gets just for proceeding in the tournament (in this case ... order the chars right away ;))
|
||||
$qry = mysql_query('Select count(win) as anzahl, win from turnier_kampf where art = \''.$name.'\' group by win order by count(win) desc');
|
||||
$maxRank = -1;
|
||||
while ($participant = mysql_fetch_assoc($qry)) {
|
||||
$charids[$participant['win']] = 0; // okay we already proceeded this one :)
|
||||
// okay, first add experience the the $charArray !!
|
||||
$charArray[$participant['win']]['exp'] += $additionalExpPerRound * $participant['anzahl'];
|
||||
$charArray[$participant['win']]['money'] += $additionalMoneyPerRound * $participant['anzahl'];
|
||||
if($maxRank == -1) {
|
||||
$maxRank = $participant['anzahl'];
|
||||
}
|
||||
$returnArray[$maxRank - $participant['anzahl']][] = $participant['win'];
|
||||
// add all the experience collected in this tournament at once ;)
|
||||
addExpToChar($participant['win'], $charArray[$participant['win']]['exp']);
|
||||
// the char is now already buffered, so no problem with that ;)
|
||||
$char = getChar($participant['win']);
|
||||
$sql = 'UPDATE user set geld = geld + ' . $charArray[$participant['win']]['money'] . ' WHERE id = ' . $char['besitzer'];
|
||||
echo $sql . ' <br>';
|
||||
mysql_query($sql);
|
||||
}
|
||||
|
||||
foreach ($charids as $key => $value) {
|
||||
if($value === 1) { // we did not have processed this id when processing the winners -> it is a ultimate loser!
|
||||
$returnArray[$maxRank][] = $key;
|
||||
|
||||
addExpToChar($key, $charArray[$key]['exp']);
|
||||
// the char is now already buffered, so no problem with that ;)
|
||||
$char = getChar($key);
|
||||
$sql = 'UPDATE user set geld = geld + ' . $charArray[$key]['money'] . ' WHERE id = ' . $char['besitzer'];
|
||||
echo $sql . ' <br>';
|
||||
mysql_query($sql);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo 'The results!<br>';
|
||||
print_r($returnArray);
|
||||
|
||||
return $returnArray; // return the array for further investigations like giving out a nature fruit ;), preventing from deletion etc.
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Rank of a char using the depth of the charid in the ranking array. E.g. 0 is for 1., 1 is for 2., 2 is for 3.-4., ...
|
||||
* @param int $depth the depth
|
||||
*/
|
||||
function generateRanglistString($depth) {
|
||||
if(!is_numeric($depth) || $depth < 0) {
|
||||
return 'NaN.';
|
||||
}
|
||||
if($depth <= 1) {
|
||||
return ($depth + 1).'.'; // 1. and 2.
|
||||
} else {
|
||||
return (pow(2, $depth - 1) + 1) . '. - '.(pow(2, $depth)).'.';
|
||||
}
|
||||
}
|
||||
|
||||
function distributeShopPoints(array $prices, array $winners, $reason) {
|
||||
$n = min(count($prices), count($winners));
|
||||
for($i = 0; $i<$n; $i++) {
|
||||
$points = $prices[$i];
|
||||
foreach($winners[$i] as $winner) {
|
||||
// echo $winner . ' <br>';
|
||||
$char = getChar($winner); // buffered so will not cause in a sql statement all the time!
|
||||
$userid = $char['besitzer'];
|
||||
$sql = 'UPDATE user set pkt = pkt + '.$points.' WHERE id = '. $userid;
|
||||
echo $sql . ' <br>';
|
||||
mysql_query($sql);
|
||||
insertUserTickerMessage($userid, $points .' IP durch den '.generateRanglistString($i).' Platz im '.$reason.' erhalten!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function distributeClanPrices(array $prices, array $results, $reason) {
|
||||
$n = min(count($prices), count($results));
|
||||
|
||||
for($i = 0; $i<$n; $i++) {
|
||||
$points = $prices[$i];
|
||||
foreach($results[$i] as $winner) {
|
||||
$char = getChar($winner); // buffered so will not cause in a sql statement all the time!
|
||||
$userid = $char['besitzer'];
|
||||
$data = mysql_fetch_assoc(mysql_query('Select clan from user where id = ' .$userid ));
|
||||
if(is_numeric($data['clan'])) {
|
||||
$sql = 'UPDATE clan SET geld = geld + ' . $points . ' WHERE id = ' . $data['clan'];
|
||||
echo $sql . ' <br>';
|
||||
mysql_query($sql);
|
||||
insertClanTickerMessage($row['clan'], 'Das Preisgeld von '.$points.' für den '.generateRanglistString($i).' Platz im '.$reason.' erhalten!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
@ -1,127 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2010 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
//set_time_limit(0);
|
||||
|
||||
$art_1 ="klein";
|
||||
|
||||
function rand_array($array)
|
||||
{
|
||||
$maxarray=count($array)-1;
|
||||
mt_srand((double)microtime()*1000000);
|
||||
for($i=$maxarray; $i>=0; $i--)
|
||||
{
|
||||
if($i>0) $zufall=mt_rand(0,$i);
|
||||
else $zufall=0;
|
||||
$temp=$array[$i];
|
||||
$array[$i]=$array[$zufall];
|
||||
$array[$zufall]=$temp;
|
||||
$newarray[]=$array[$i];
|
||||
array_pop($array);
|
||||
}
|
||||
return $newarray;
|
||||
}
|
||||
|
||||
include "db.php";
|
||||
|
||||
$max_charakter = mysql_num_rows(mysql_query("SELECT id FROM chars WHERE level<='25' and fusion='nein' AND char_type = '' LIMIT 32"));
|
||||
|
||||
if($max_charakter<32) {
|
||||
exit;
|
||||
}
|
||||
mysql_query("DELETE FROM turnier_kampf WHERE art='$art_1'");
|
||||
|
||||
|
||||
|
||||
$char1 = mysql_query("SELECT charakter FROM turnier1 WHERE art='$art_1'");
|
||||
while($row=mysql_fetch_array($char1))
|
||||
{
|
||||
$test2[]=$row['charakter'];
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if(count($test2)<32)
|
||||
{ // WHERE status='Frei'
|
||||
list($count) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM chars WHERE level<='25' and fusion='nein' AND char_type = '' "));
|
||||
|
||||
if(($count+count($test2))>=32)
|
||||
{
|
||||
$result = mysql_query("SELECT id FROM chars WHERE level<='25' AND char_type = '' and fusion='nein' ORDER BY RAND() LIMIT ".(32-count($test2)));
|
||||
while($char_name2=mysql_fetch_array($result))
|
||||
{
|
||||
$test2[]=$char_name2['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$test2 = rand_array($test2);
|
||||
$test2 = array_unique($test2);
|
||||
}
|
||||
|
||||
|
||||
while(count($test2)<32);
|
||||
|
||||
$test3=$test2;
|
||||
reset($test3);
|
||||
while(current($test3)!=end($test2))
|
||||
{
|
||||
if(empty($list)) $list=current($test3);
|
||||
else $list.=','.next($test3);
|
||||
}
|
||||
|
||||
$result=mysql_query("SELECT * FROM chars WHERE id IN(".$list.") LIMIT 32");
|
||||
while($row=mysql_fetch_array($result))
|
||||
{
|
||||
|
||||
$charas[$row['id']]=$row;
|
||||
}
|
||||
|
||||
$a8=0;
|
||||
$b8=1;
|
||||
|
||||
$round = 1;
|
||||
while($a8 < 32)
|
||||
{
|
||||
$chara_1 = $charas[$test2[$a8]];
|
||||
$chara_2 = $charas[$test2[$b8]];
|
||||
include "turnier_kampf.php";
|
||||
$a8+=2;
|
||||
$b8+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while($round < 5)
|
||||
{
|
||||
unset($test9);
|
||||
|
||||
|
||||
$chars_win = mysql_Query("SELECT win FROM turnier_kampf WHERE round='$round' AND art='$art_1'");
|
||||
while($row9 = mysql_fetch_array($chars_win))
|
||||
{
|
||||
$test9[]=$row9['win'];
|
||||
}
|
||||
$round++;
|
||||
$k9=0;
|
||||
$l9=1;
|
||||
while($k9 < count($test9))
|
||||
{
|
||||
$chara_1 = $charas[$test9[$k9]];
|
||||
$chara_2 = $charas[$test9[$l9]];
|
||||
include "turnier_kampf.php";
|
||||
$k9+=2;
|
||||
$l9+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM turnier1 WHERE art='$art_1'");
|
||||
?>
|
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2010 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
$art_1 ="wochen";
|
||||
//set_time_limit(0);
|
||||
function rand_array($array)
|
||||
{
|
||||
$maxarray=count($array)-1;
|
||||
mt_srand((double)microtime()*1000000);
|
||||
for($i=$maxarray; $i>=0; $i--)
|
||||
{
|
||||
if($i>0) $zufall=mt_rand(0,$i);
|
||||
else $zufall=0;
|
||||
$temp=$array[$i];
|
||||
$array[$i]=$array[$zufall];
|
||||
$array[$zufall]=$temp;
|
||||
$newarray[]=$array[$i];
|
||||
array_pop($array);
|
||||
}
|
||||
return $newarray;
|
||||
}
|
||||
|
||||
include "db.php";
|
||||
|
||||
$max_charakter = mysql_num_rows(mysql_query("SELECT id FROM chars LIMIT 64"));
|
||||
|
||||
if($max_charakter<64) {
|
||||
exit;
|
||||
}
|
||||
mysql_query("DELETE FROM turnier_kampf WHERE art='$art_1'");
|
||||
|
||||
$char1 = mysql_query("SELECT charakter FROM turnier1 WHERE art='$art_1'");
|
||||
while($row=mysql_fetch_array($char1))
|
||||
{
|
||||
$test2[]=$row['charakter'];
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if(count($test2)<64)
|
||||
{ // WHERE status='Frei'
|
||||
list($count) = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM chars"));
|
||||
|
||||
if(($count+count($test2))>=64)
|
||||
{
|
||||
$result = mysql_query("SELECT id FROM chars WHERE status='Frei' AND rasse !='NPC' ORDER BY RAND() LIMIT ".(64-count($test2)));
|
||||
while($char_name2=mysql_fetch_array($result))
|
||||
{
|
||||
$test2[]=$char_name2['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$test2 = rand_array($test2);
|
||||
$test2 = array_unique($test2);
|
||||
}
|
||||
|
||||
|
||||
while(count($test2)<64);
|
||||
|
||||
$test3=$test2;
|
||||
reset($test3);
|
||||
while(current($test3)!=end($test2))
|
||||
{
|
||||
if(empty($list)) $list=current($test3);
|
||||
else $list.=','.next($test3);
|
||||
}
|
||||
|
||||
$result=mysql_query("SELECT * FROM chars WHERE id IN(".$list.") LIMIT 64");
|
||||
while($row=mysql_fetch_array($result))
|
||||
{
|
||||
|
||||
$charas[$row['id']]=$row;
|
||||
}
|
||||
|
||||
$a8=0;
|
||||
$b8=1;
|
||||
|
||||
$round = 1;
|
||||
while($a8 < 64)
|
||||
{
|
||||
$chara_1 = $charas[$test2[$a8]];
|
||||
$chara_2 = $charas[$test2[$b8]];
|
||||
include "turnier_kampf.php";
|
||||
$a8+=2;
|
||||
$b8+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while($round < 6)
|
||||
{
|
||||
unset($test9);
|
||||
|
||||
|
||||
$chars_win = mysql_Query("SELECT win FROM turnier_kampf WHERE round='$round' AND art='$art_1'");
|
||||
while($row9 = mysql_fetch_array($chars_win))
|
||||
{
|
||||
$test9[]=$row9['win'];
|
||||
}
|
||||
$round++;
|
||||
$k9=0;
|
||||
$l9=1;
|
||||
while($k9 < count($test9))
|
||||
{
|
||||
$chara_1 = $charas[$test9[$k9]];
|
||||
$chara_2 = $charas[$test9[$l9]];
|
||||
include "turnier_kampf.php";
|
||||
|
||||
$k9+=2;
|
||||
$l9+=2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM turnier1 WHERE art='$art_1' ");
|
||||
?>
|
Loading…
Reference in new issue