fixed attack set and tournament generation

main
hecht 7 years ago
parent bbeb4c8630
commit 06e3937d96

@ -17,6 +17,8 @@ defineIfNotDefined('CLANKAMPF', 2);
//Anzahl der Runden pro Kampf //Anzahl der Runden pro Kampf
defineIfNotDefined('KAMPF_RUNDEN', 10); defineIfNotDefined('KAMPF_RUNDEN', 10);
$GLOBALS['char_buffered_attackset'] = array();
function createAttackSet($char_id, $type) { function createAttackSet($char_id, $type) {
if(!is_numeric($char_id) || !is_numeric($type)) { if(!is_numeric($char_id) || !is_numeric($type)) {
return false; return false;
@ -42,16 +44,20 @@ function deleteAttackSet($char_id, $type) {
return db_query($qry); return db_query($qry);
} }
function getAttackSet($char_id, $type) { function getAttackSet($char_id, $type, $buffer_enabled = true) {
if(!is_numeric($char_id) || !is_numeric($type)) { if(!is_numeric($char_id) || !is_numeric($type)) {
return false; return false;
} }
if (isset($GLOBALS['char_buffered_attackset'][$char_id]) && isset($GLOBALS['char_buffered_attackset'][$char_id][$type]) && $buffer_enabled) {
return $GLOBALS['char_buffered_attackset'][$char_id][$type];
}
$qry = db_query('SELECT attack_id, round FROM attackenset WHERE char_id = '.$char_id.' AND type = '.$type); $qry = db_query('SELECT attack_id, round FROM attackenset WHERE char_id = '.$char_id.' AND type = '.$type);
$set = array(); $set = array();
while ($result = mysqli_fetch_assoc($qry)) { while ($result = mysqli_fetch_assoc($qry)) {
$set[$result['round']] = $result['attack_id']; $set[$result['round']] = $result['attack_id'];
} }
$GLOBALS['char_buffered_attackset'][$char_id][$type] = $set;
return $set; return $set;
} }
@ -59,7 +65,7 @@ function updateAttackSet($char_id, $type, $newSet) {
if(!is_numeric($char_id) || !is_numeric($type) || !is_array($newSet) || count($newSet) == 0) { if(!is_numeric($char_id) || !is_numeric($type) || !is_array($newSet) || count($newSet) == 0) {
return false; return false;
} }
$oldset = getAttackSet($char_id, $type); $oldset = getAttackSet($char_id, $type, false);
for ($i = 1; $i < KAMPF_RUNDEN + 1; $i++) { for ($i = 1; $i < KAMPF_RUNDEN + 1; $i++) {
if($oldset[$i] != $newSet[$i]) { if($oldset[$i] != $newSet[$i]) {
@ -67,6 +73,7 @@ function updateAttackSet($char_id, $type, $newSet) {
db_query($qry); db_query($qry);
} }
} }
unset($GLOBALS['char_buffered_attackset'][$char_id][$type]);
return true; return true;
} }

@ -11,19 +11,19 @@ if($x > 0) {
################### PLAYER 1 ################### PLAYER 1
$k_starke[0] = round($k_starke[0] + (($k_ausdauer[0] / 20))-($k_starke[0]/50)); $k_starke[0] = round($k_starke[0] + ($k_ausdauer[0] / 10));
$k_speed[0] = round($k_speed[0] + ($k_ausdauer[0] / 10)); $k_speed[0] = round($k_speed[0] + ($k_ausdauer[0] / 10));
$k_ver[0] = round($k_ver[0] + ($k_ausdauer[0] / 10)); $k_ver[0] = round($k_ver[0] + ($k_ausdauer[0] / 20)-($k_ver[0]/50));
$k_ausdauer[0] = round($k_ausdauer[0] - ($k_ausdauer[0] /20)); $k_ausdauer[0] = round($k_ausdauer[0] - ($k_ausdauer[0] /20));
################### PLAYER 2 ################### PLAYER 2
$k_starke[1] = round($k_starke[1] + (($k_ausdauer[1] / 20))-($k_starke[1]/50)); $k_starke[1] = round($k_starke[1] + ($k_ausdauer[1] / 10));
$k_speed[1] = round($k_speed[1] + ($k_ausdauer[1] / 10)); $k_speed[1] = round($k_speed[1] + ($k_ausdauer[1] / 10));
$k_ver[1] = round($k_ver[1] + ($k_ausdauer[1] / 10)); $k_ver[1] = round($k_ver[1] + ($k_ausdauer[1] / 20)-($k_ver[1]/50));
$k_ausdauer[1] = round($k_ausdauer[1] - ($k_ausdauer[1] /20)); $k_ausdauer[1] = round($k_ausdauer[1] - ($k_ausdauer[1] /20));
} }
?> ?>

@ -243,6 +243,7 @@ function createTournament($tournament_type) {
function calculateTournament($tournament, $participants) { function calculateTournament($tournament, $participants) {
shuffle($participants); shuffle($participants);
$tournament_type = getTournamentType($tournament['type']);
$event_id = $tournament['event_id']; $event_id = $tournament['event_id'];
@ -275,7 +276,7 @@ function calculateTournament($tournament, $participants) {
} }
// echo 'nxt round<br>'; // echo 'nxt round<br>';
$round++; $round++;
if($tournament['randomize'] == 1) { if($tournament_type['randomize'] == 1) {
shuffle($n_chars); shuffle($n_chars);
} }
$char_array = $n_chars; $char_array = $n_chars;
@ -286,7 +287,7 @@ function calculateTournament($tournament, $participants) {
db_query('UPDATE event_chars SET block_begin = \''.$end_time_str.'\', block_end = \''.$end_time_str.'\' WHERE event_id = '.$event_id); db_query('UPDATE event_chars SET block_begin = \''.$end_time_str.'\', block_end = \''.$end_time_str.'\' WHERE event_id = '.$event_id);
// Seems that we have a winner :D // Seems that we have a winner :D
$fruit_item_str = getFruitItem($tournament['fruit_type'], $tournament['fruit_chance']); $fruit_item_str = getFruitItem($tournament_type['fruit_type'], $tournament_type['fruit_chance']);
if ($fruit_item_str !== NULL) { if ($fruit_item_str !== NULL) {
// add item in event_char_metadata // add item in event_char_metadata

Loading…
Cancel
Save