0;
$id = $row[0];
}
return $id;
}
/**
* Adds a participant to a given event
* @param int event_id
* @param array $char
* @return int the id of the participant (usually the charid), NULL on failure!
*/
function addParticipant($event_id, array $char) {
// Okay now add the char ;)
$user = getUser($char['besitzer']);
$hp = explode(',', $char['hp']);
$mp = explode(',', $char['mp']);
$sql = 'INSERT INTO event_chars(event_id, event_char_id, char_id, char_name, char_bild, user_id, user_name, hp, mp, strength, speed, defense, luck, stamina)';
$sql .= ' value('. $event_id . ', '.$char['id'] .', '.$char['id'] .', \''.$char['name'].'\', \''.$char['bild'].'\', '.$char['besitzer'].', \''.$user['nickname'].'\', '.$hp[1].', '.$mp[1].', '.$char['starke'].', '.$char['speed'].', '.$char['verteidigung'].', '.$char['glueck'].', '.$char['ausdauer'].')';
// echo $sql . '
';
mysql_query($sql);
if(mysql_affected_rows() == 0)
return NULL;
return $char['id'];
}
/**
* Persists a fight of one event.
* @param int $event_id
* @param array combined array that is calculated in the kampf_wrapper
* @return int the id of the fight
*/
function persistFight($event_id, array $combinedArray) {
// persist a fight of two chars (calculated by the wrapper) ^^"
//echo 'The fight was about ' . count($combinedArray) . ' rounds
';
// first get a fight id ;).
$finished = FALSE;
while(!$finished) {
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$row = mysql_fetch_row(mysql_query($sql));
mysql_query('INSERT INTO event_fights(event_id, event_fight_id) values('.$event_id.', \''.$row[0].'\')');
$finished = mysql_affected_rows() > 0;
$event_fight_id = $row[0];
}
// now we have a $event_fight_id ;) lets insert the other stuff ;)
for($round = 0; $round < count($combinedArray) ; $round++) {
// persist this round ^^"
// first persist char1
$chara_1 = $combinedArray[$round]['char1_array'];
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_1['id'].','. $chara_1['hp'].', '. $chara_1['mp'].', '. $chara_1['starke'].', '. $chara_1['speed'].', '. $chara_1['verteidigung'].', '. $chara_1['glueck'].', '. $chara_1['ausdauer'].', \''. $combinedArray[$round]['atk_char1'] .'\', \''. $combinedArray[$round]['dmg_char1'] .'\')';
// echo $sql .'
';
mysql_query($sql);
// now persist char2
$chara_2 = $combinedArray[$round]['char2_array'];
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_2['id'].', '. $chara_2['hp'].', '. $chara_2['mp'].', '. $chara_2['starke'].', '. $chara_2['speed'].', '. $chara_2['verteidigung'].', '. $chara_2['glueck'].', '. $chara_2['ausdauer'].', \''. $combinedArray[$round]['atk_char2'] .'\', \''. $combinedArray[$round]['dmg_char2'] .'\')';
// echo $sql .'
';
mysql_query($sql);
}
}
?>