@ -73,8 +73,7 @@ function addParticipant($event_id, array $char) {
* @param int $event_id
* @param array combined array that is calculated in the kampf_wrapper
* @param int $startTimestamp unix timestamp for the start of the battle
* @param int $durationType the duration value (see the DURATION constants)
* @param int $durationValue the amount of time in minutes
* @param int $endTimestamp unix timestamp for the end of the battle
* @return int the id of the fight
*/
function persistFight($event_id, array $combinedArray, $startTimestamp, $endTimestamp) {
@ -92,9 +91,11 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $endTime
while(!$finished) {
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$row = mysql_fetch_row(mysql_query($sql));
$sql = 'INSERT INTO event_fights(event_id, event_fight_id, host, winner, visible) values('.$event_id.', \''.$row[0].'\', '. $hostId . ', ' . $winnerId .', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
if(mysql_query($sql) === FALSE)
$sql = 'INSERT INTO event_fights(event_id, event_fight_id, host, winner, `starting`, visible) values('.$event_id.', \''.$row[0].'\', '. $hostId . ', ' . $winnerId .', \''.date("Y-m-d H:i:s",$startTimestamp).'\', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
if(mysql_query($sql) === FALSE) {
echo $sql . '< br > ';
break;
}
$finished = mysql_affected_rows() > 0;
$event_fight_id = $row[0];
}
@ -110,18 +111,18 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $endTime
$chara_1 = $roundsArray[$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, visible)';
$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'].', \''. $roundsArray[$round]['atk_char1'] .'\', \''. $roundsArray[$round]['dmg_char1'] .'\ ', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
$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'].', '. ($roundsArray[$round]['atk_char1']===NULL?'NULL': '\''.$roundsArray[$round]['atk_char1'].'\'' ).', '. ($roundsArray[$round]['dmg_char1']===NULL?'NULL': '\''.$roundsArray[$round]['dmg_char1'].'\'' ). ', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
// echo $sql .'< br > ';
echo $sql .'< br > ';
mysql_query($sql);
// now persist char2
$chara_2 = $roundsArray[$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, visible)';
$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'].', \' '. $roundsArray[$round]['atk_char2'] .'\', \''. $roundsArray[$round]['dmg_char2'] .'\', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
$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'].', '. ( $roundsArray[$round]['atk_char2']===NULL?'NULL': '\''.$roundsArray[$round]['atk_char2'] .'\'' ).' , '. ($roundsArray[$round]['dmg_char2']===NULL?'NULL': ' \''.$roundsArray[$round]['dmg_char2'].'\'' ). ', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
// echo $sql .'< br > ';
echo $sql .'< br > ';
mysql_query($sql);
}
@ -161,5 +162,125 @@ function getEventStatus($charid) {
}
}
function abholenChar(array $user, $event_id, $char_id) {
// okay, first checking the basic things
$char = getChar($charid);
if($char['besitzer'] != $user) {
return 'Du kannst den Char nicht abholen weil er dir nicht gehört!!';
}
$ressource = 'User:'.$user_ida['id'];
if(!semaphoreUP($ressource)){ // TRUE, diese Anfrage darf bearbeitet werden
return 'Verarbeitung gerade in Gange, bitte warten...';
}
$event_char = getEventChar($event_id, $char_id);
if($event_char === NULL) {
semaphoreDown($ressource); // free the previously reserved semaphore!
return 'Der Char hat an diesem Event garnicht teil genommen!';
}
if($event_char['abgeholt'] == TRUE) {
semaphoreDown($ressource); // free the previously reserved semaphore!
return 'Der Char wurde schon abgeholt!';
}
// now get the ids of fights that the char has at the event!
$fight_ids = getEventFightIdsByChar($event_id, $char_id);
if(count($fight_ids) < = 0) {
semaphoreDown($ressource); // free the previously reserved semaphore!
return 'Der Char hat in diesem Event keinen Fight bestritten!';
}
$char_exp = 0;
$char_aexp = 0;
$char_geld = 0;
// Okay and now calculate those fights?
// Get the "chars" data :)
foreach ($fight_ids as $fight_id) {
$fight = getEventFight($event_id, $fight_id);
$fight_meta = getEventFightMetaData($event_id, $fight_id);
if($fight['host'] == $char_id) {
$char_exp += $fight_meta['KEY_EXP_CHAR1'];
$char_aexp += $fight_meta['KEY_AXP_CHAR1'];
$char_geld += $fight_meta['KEY_GELD_CHAR1'];
} else {
$char_exp += $fight_meta['KEY_EXP_CHAR2'];
$char_aexp += $fight_meta['KEY_AXP_CHAR2'];
$char_geld += $fight_meta['KEY_GELD_CHAR2'];
}
}
// add the experience to the char
addExpToChar($char_id, $char_exp);
// add the experience to the arena
if($char_aexp > 0) {
addExpToArena($char['besitzer'], $char_aexp);
}
addMoneyToUser($char['besitzer'], $char_geld);
// Okay and now we want to learn the attacks :)
$sql = 'SELECT attack, count(attack) as anzahl FROM event_fight_rounds e group by attack where event_id = ' . $event_id . ' AND event_char_id = ' . $char_id;
$qry = mysql_query($sql);
$attacken_usage = array();
while($row = mysql_fetch_assoc($qry)) {
$attacken_usage[] = array('id' => $row['attack'], 'anzahl' => $row['anzahl']);
}
addAttackUsageToChar($char_id, $attacken_usage);
return $fight_ids; // Return the fight ids that the char has participated in!
}
function getEvent($event_id) {
$result = mysql_fetch_assoc(mysql_query('SELECT * FROM events WHERE event_id = ' . $event_id));
if($result)
return $result;
return NULL;
}
function getEventChar($event_id, $event_char_id) {
$result = mysql_fetch_assoc(mysql_query('SELECT * FROM event_chars WHERE event_id = ' . $event_id . ' AND event_char_id = ' . $event_char_id));
if($result)
return $result;
return NULL;
}
function getEventFight($event_id, $event_fight_id) {
$result = mysql_fetch_assoc(mysql_query('SELECT * FROM event_fights WHERE event_id = ' . $event_id. ' AND event_fight_id = ' .$event_fight_id ));
if($result)
return $result;
return NULL;
}
function getEventFightMetaData($event_id, $event_fight_id) {
$qry = mysql_query('SELECT * FROM event_fight_metadata WHERE event_id = ' . $event_id. ' AND event_fight_id = ' .$event_fight_id);
while($row = mysql_fetch_assoc($qry)) {
$result[$row['key']]= $row['value'];
}
return $result;
}
function getEventFightIds($event_id) {
$qry = mysql_query('SELECT event_fight_id FROM event_fights WHERE event_id = ' . $event_id . ' ORDER by event_fight_id ASC');
$result = array();
while($row = mysql_fetch_assoc($qry)) {
$result[]= $row['event_fight_id'];
}
return $result;
}
// this is more tricky XD
function getEventFightIdsByChar($event_id, $event_char_id) {
$sql = 'SELECT event_fight_id FROM event_fight_rounds where event_id = ' . $event_id . ' AND event_char_id = ' . $event_char_id . ' AND `round` = 0';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$result[]= $row['event_fight_id'];
}
return $result;
}
?>