@ -16,6 +16,25 @@ define('EVENT_LIGA', 4);
define('EVENT_WANTED', 5);
define('EVENT_WANTED', 5);
define('EVENT_CLAN_FIGHT', 6);
define('EVENT_CLAN_FIGHT', 6);
// The fights duration is fixed
define('DURATION_FIGHT', 0);
// The fights duration is resolved by the amount of rounds
define('DURATION_ROUND', 1);
// The fights duration is fixed but the time ouf rounds is resolved!
define('DURATION_FIGHT_RESOLVED_ROUNDS', 2);
define('KEY_LOGE', 'LOGE');
define('KEY_SITZ', 'SITZ');
define('KEY_STEH', 'STEH');
define('KEY_EXP_CHAR1', 'EXP_CHAR1');
define('KEY_EXP_CHAR2', 'EXP_CHAR2');
define('KEY_GELD_CHAR1', 'GELD_CHAR1');
define('KEY_GELD_CHAR2', 'GELD_CHAR2');
define('KEY_AXP_CHAR1', 'AXP_CHAR1');
define('KEY_AXP_CHAR2', 'AXP_CHAR2');
define('KEY_ITM_CHAR1', 'ITM_CHAR1');
/**
/**
* Creates an event for a given type and returns the id of this event!
* Creates an event for a given type and returns the id of this event!
* @param string $type
* @param string $type
@ -59,18 +78,28 @@ function addParticipant($event_id, array $char) {
* Persists a fight of one event.
* Persists a fight of one event.
* @param int $event_id
* @param int $event_id
* @param array combined array that is calculated in the kampf_wrapper
* @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
* @return int the id of the fight
* @return int the id of the fight
*/
*/
function persistFight($event_id, array $combinedArray) {
function persistFight($event_id, array $combinedArray, $startTimestamp, $durationType, $durationValue ) {
// persist a fight of two chars (calculated by the wrapper) ^^"
// persist a fight of two chars (calculated by the wrapper) ^^"
//echo 'The fight was about ' . count($combinedArray) . ' rounds < br > ';
//echo 'The fight was about ' . count($combinedArray) . ' rounds < br > ';
$roundsArray = $combinedArray['rounds'];
$winnerId = $combinedArray['winner'];
$hostId = $combinedArray['host'];
$data = $combinedArray['data'];
// first get a fight id ;).
// first get a fight id ;).
$finished = FALSE;
$finished = FALSE;
while(!$finished) {
while(!$finished) {
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$row = mysql_fetch_row(mysql_query($sql));
$row = mysql_fetch_row(mysql_query($sql));
mysql_query('INSERT INTO event_fights(event_id, event_fight_id) values('.$event_id.', \''.$row[0].'\')');
mysql_query('INSERT INTO event_fights(event_id, event_fight_id, host, winner ) values('.$event_id.', \''.$row[0].'\, '. $hostId . ', ' . $winnerId . ')');
$finished = mysql_affected_rows() > 0;
$finished = mysql_affected_rows() > 0;
$event_fight_id = $row[0];
$event_fight_id = $row[0];
}
}
@ -79,28 +108,33 @@ function persistFight($event_id, array $combinedArray) {
for($round = 0; $round < count ( $ combined Array) ; $ round + + ) {
for($round = 0; $round < count ( $ rounds Array) ; $ round + + ) {
// persist this round ^^"
// persist this round ^^"
// first persist char1
// first persist char1
$chara_1 = $combined Array[$round]['char1_array'];
$chara_1 = $rounds Array[$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 = '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'] .'\', \''. $combined Array[$round]['dmg_char1'] .'\')';
$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'] .'\', \''. $rounds Array[$round]['dmg_char1'] .'\')';
// echo $sql .'< br > ';
// echo $sql .'< br > ';
mysql_query($sql);
mysql_query($sql);
// now persist char2
// now persist char2
$chara_2 = $combined Array[$round]['char2_array'];
$chara_2 = $rounds Array[$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 = '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'] .'\', \''. $combined Array[$round]['dmg_char2'] .'\')';
$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'] .'\', \''. $rounds Array[$round]['dmg_char2'] .'\')';
// echo $sql .'< br > ';
// echo $sql .'< br > ';
mysql_query($sql);
mysql_query($sql);
}
// Okay now do we have any additional data left?
foreach ($data as $key => $value) {
$sql = 'INSERT INTO event_fight_metadata(event_id, event_fight_id, key, value) values('.$event_id.','.$event_fight_id.',\''.$key.'\',\''.$value.'\')';
mysql_query($sql);
}
}
}
}