added handling of inverse auctions

main
hecht 7 years ago
parent 3029796ae7
commit 9a61d1eabc

@ -217,10 +217,6 @@ if($gain == 'Anmeldung'){
// echo $sql.'<br>'; // echo $sql.'<br>';
$qry = db_query($sql); $qry = db_query($sql);
while(($row = mysqli_fetch_assoc($qry)) && count($cid) < $anzahl){ while(($row = mysqli_fetch_assoc($qry)) && count($cid) < $anzahl){
// exclude winners of old tournaments in case requested
// exclude fusions that have participated multiple times in tournaments in case requested
// echo $row['id'].'<br>'; // echo $row['id'].'<br>';
$cid[] = $row['id']; $cid[] = $row['id'];
} }

@ -16,36 +16,43 @@ include('path.inc.php');
include_once (ROOT_PATH.'/include/sqlwrapper.inc.php'); include_once (ROOT_PATH.'/include/sqlwrapper.inc.php');
include_once (ROOT_PATH.'/include/event.inc.php'); include_once (ROOT_PATH.'/include/event.inc.php');
include_once (ROOT_PATH.'/include/halloffame.inc.php'); include_once (ROOT_PATH.'/include/halloffame.inc.php');
include_once (ROOT_PATH.'/include/tournament.inc.php');
// First run schedule tournaments
runScheduledTournaments();
$tournaments = array(); $tournaments = array();
$tournament_event_ids = array(); $tournament_event_ids = array();
$qry = db_query('SELECT * FROM turniere WHERE ausgewertet = FALSE'); $qry = db_query('SELECT * FROM tournament WHERE ausgewertet = FALSE');
while ($row = mysqli_fetch_assoc($qry)) { while ($row = mysqli_fetch_assoc($qry)) {
$tournament_event_ids[] = $row['event_id']; $tournament_event_ids[] = $row['event_id'];
$tournaments[$row['event_id']] = $row; $tournaments[$row['event_id']] = $row;
} }
$sql = 'select event_id, MAX(visible) < now() as done, MAX(event_fight_id) as final_fight_id FROM event_fights WHERE event_id IN ('.join(',', $tournament_event_ids).') GROUP BY event_id'; if (count($tournaments) > 0) {
$qry = db_query($sql); $sql = 'select event_id, MAX(visible) < now() as done, MAX(event_fight_id) as final_fight_id FROM event_fights WHERE event_id IN ('.join(',', $tournament_event_ids).') GROUP BY event_id';
$qry = db_query($sql);
$tournaments_done = array(); $tournaments_done = array();
while ($row = mysqli_fetch_assoc($qry)) { while ($row = mysqli_fetch_assoc($qry)) {
if ($row['done']) { if ($row['done']) {
$event_id = $row['event_id']; $event_id = $row['event_id'];
$tournament = $tournaments[$event_id]; $tournament = $tournaments[$event_id];
$tournament_type = getTournamentType($tournament['type']);
// determine the winner of the tournament ... // determine the winner of the tournament ...
$final_fight = getEventFight($event_id, $row['final_fight_id']); $final_fight = getEventFight($event_id, $row['final_fight_id']);
$winner_char = getEventChar($event_id, $final_fight['winner']); $winner_char = getEventChar($event_id, $final_fight['winner']);
$row = mysqli_fetch_assoc(db_query('Select max(id) as round from online')); $row = mysqli_fetch_assoc(db_query('Select max(id) as round from online'));
insertIntoHallOfFameFull($row['round'], $tournament['art'], $winner_char['char_id'], $winner_char['char_name'], $winner_char['user_id'], $winner_char['user_name'], '\''.$tournament['datum'].'\'', $tournament['id']); insertIntoHallOfFameFull($row['round'], $tournament_type['name'], $winner_char['char_id'], $winner_char['char_name'], $winner_char['user_id'], $winner_char['user_name'], '\''.$tournament['datum'].'\'', $tournament['id']);
$tournaments_done[] = $tournament['id']; $tournaments_done[] = $tournament['id'];
} }
} }
if (count($tournaments_done) > 0) { if (count($tournaments_done) > 0) {
db_query('UPDATE turniere SET ausgewertet = TRUE WHERE id IN ('.join(',', $tournaments_done).')'); db_query('UPDATE tournament SET ausgewertet = TRUE WHERE id IN ('.join(',', $tournaments_done).')');
}
} }

@ -13,6 +13,8 @@ include_once("path.inc.php");
include_once (ROOT_PATH.'/include/sqlwrapper.inc.php'); include_once (ROOT_PATH.'/include/sqlwrapper.inc.php');
include_once(ROOT_PATH. "/include/defines.inc.php"); include_once(ROOT_PATH. "/include/defines.inc.php");
include_once(ROOT_PATH. "/include/random.inc.php"); include_once(ROOT_PATH. "/include/random.inc.php");
include_once(ROOT_PATH. "/include/items.inc.php");
include_once(ROOT_PATH. "/include/messagefunctions.inc.php");
// Da es wichtig ist, dass die Querys korrekt abgehandelt werden wurde folgender Code eingefuehrt // Da es wichtig ist, dass die Querys korrekt abgehandelt werden wurde folgender Code eingefuehrt
@ -24,15 +26,71 @@ function database_query($sql){
return $tmp; return $tmp;
} }
function bearbeiteAbgelaufeneInverseAuktion($auktion) {
$item = array('table_name' => $auktion['tablename'], 'id' => $auktion['itemid']);
$min_max = mysqli_fetch_row(db_query('SELECT min(range_from), max(range_to) from inverse_auktion_gebote WHERE auktionsid = '.$auktion['auktionsid']));
echo '<p>Min: '.$min_max[0].', Max: '.$min_max[1].'</p>';
$winner = NULL;
$cost = NULL;
if ($min_max[0] != NULL) {
for ($i = $min_max[0]; $i <= $min_max[1]; ++$i) {
$row = mysqli_fetch_row(db_query('SELECT distinct(bieter), count(*) from inverse_auktion_gebote WHERE auktionsid = '.$auktion['auktionsid'].' AND '.$i.' between range_from and range_to'));
if ( $row[1] == 1 ) {
// we have a winner!!!
echo '<p>Spieler '.$row[0].' hat die inverse auktion mit dem betrag '.$i.' gewonnen!</p>';
$winner = $row[0];
$cost = $i;
break;
}
}
}
$message_suffix = '"'.$auktion['itemname'].'" ('.$auktion['anzahl'].'x): Auktion von '.$auktion['anbietername'].' mit Deadline '.$auktion['deadline'].'.';
$lose_message = NULL;
if ($cost === NULL) {
$lose_message = 'Leider gab ein kein kleinstes einmaliges Gebot. Das item wurde deshalb nicht versteigert!';
} else {
$lose_message = 'Leider hat jemand anderes das kleinste einmalige Gebot abgegeben. Das item wurde f&uuml;r '.displayMoney($cost).' versteigert';
}
db_query('DELETE FROM auktion WHERE auktionsid = '.$auktion['auktionsid']);
$qry = db_query('SELECT bieter FROM inverse_auktion_gebote WHERE auktionsid = '.$auktion['auktionsid']);
while ($row = mysqli_fetch_row($qry)) {
if ($winner != $row[0]) {
sendMessage('Auktionsmarkt', $row[0], 'Inverse Versteigerung verloren!', $lose_message.' '.$message_suffix);
}
}
if ($winner !== NULL) {
createItemForUser($item, $winner, $auktion['anzahl']);
$msg = 'Herzlichen Gl&uuml;ckwunsch, du hast die inverse Versteigerung (f&uuml;r '.displayMoney($cost).') gewonnen!';
sendMessage('Auktionsmarkt', $winner, 'Inverse Versteigerung gewonnen!', $msg.' '.$message_suffix);
sendMessage('Auktionsmarkt', $auktion['anbieter'], 'Item versteigert!', 'Item in inverser Auktion f&uuml;r '.displayMoney($cost).' versteigert! '.$message_suffix);
db_query('UPDATE user SET geld = geld - '.$cost.' WHERE id = '.$winner);
} else {
sendMessage('Auktionsmarkt', $auktion['anbieter'], 'Item nicht versteigert!', 'Item in inverser Auktion wurde nicht versteigert! '.$message_suffix);
createItemForUser($item, $auktion['anbieter'], $auktion['anzahl']);
}
}
// Handelt eine einzelne Auktion ab // Handelt eine einzelne Auktion ab
// @Return nichts // @Return nichts
function bearbeiteAbgelaufeneAuktion($auktionsid){ function bearbeiteAbgelaufeneAuktion($auktionsid){
// echo '<br>bearbeite '.$auktionsid.'</br>'; // echo '<br>bearbeite '.$auktionsid.'</br>';
$qry = database_query('SELECT u.nickname AS anbietername, u2.nickname AS bietername, a.auktionsid,a.anbieter,a.bieter,a.itemid,a.itemname,a.tablename,a.anzahl,a.startgebot,a.aktuellesgebot,a.deadline,a.startdate,a.cheatingverdacht, TIMESTAMPDIFF(Minute,now(),deadline) AS zeitdifferenz FROM auktion AS a INNER JOIN user as u ON a.anbieter = u.id LEFT JOIN user as u2 ON a.bieter = u2.id WHERE auktionsid = '.$auktionsid); $qry = database_query('SELECT u.nickname AS anbietername, u2.nickname AS bietername, a.*, TIMESTAMPDIFF(Minute,now(),deadline) AS zeitdifferenz FROM auktion AS a INNER JOIN user as u ON a.anbieter = u.id LEFT JOIN user as u2 ON a.bieter = u2.id WHERE auktionsid = '.$auktionsid);
if(mysqli_num_rows($qry) == 0){ return NULL; } if(mysqli_num_rows($qry) == 0){ return NULL; }
$result = mysqli_fetch_assoc($qry); $result = mysqli_fetch_assoc($qry);
if ($result['type'] == 2) {
bearbeiteAbgelaufeneInverseAuktion($result);
return;
}
$itemreceiver = ''; $itemreceiver = '';
// Nun muss geprüft werden, ob überhaupt jemand geboten hat! // Nun muss geprüft werden, ob überhaupt jemand geboten hat!
@ -154,7 +212,7 @@ function insertAuktionen(){
$item_table = 'wochen_ware'; $item_table = 'wochen_ware';
$item_id = $frucht[mt_random_wrapper(0,$fruchtcount-1)]; $item_id = $frucht[mt_random_wrapper(0,$fruchtcount-1)];
} }
$test = 'INSERT INTO auktion (itemid, itemname, tablename, anbieter, anzahl, deadline, startgebot, startdate) VALUES('.$item_id.',\'Geheim!\',\''.$item_table.'\',1,1,'.$deadline.','.$startgebot.','.$start.')'; $test = 'INSERT INTO auktion (itemid, type, itemname, tablename, anbieter, anzahl, deadline, startgebot, startdate) VALUES('.$item_id.',2,\'Geheim!\',\''.$item_table.'\',1,1,'.$deadline.','.$startgebot.','.$start.')';
// echo $test."<br>\n"; // echo $test."<br>\n";
database_query($test); database_query($test);
} }

Loading…
Cancel
Save