It is now possible to call the "abholen" method for clan fights. Then the whole data required for the char will be calculated and assigned at once.

main
hecht 13 years ago
parent 84fe500a8a
commit cd765c128e

@ -17,7 +17,8 @@ function getCharAttackSet($char_id, $type) {
$set = array(1 => 0,2 => 0,3 => 0,4 => 0,5 => 0,6 => 0,7 => 0,8 => 0,9 => 0,10 => 0);
if(is_numeric($char_id)) {
$test = 'SELECT Attack_ID,Round FROM attackenset WHERE Char_ID = '.$char_id.' AND Type = '.$type;
$test = 'SELECT attack_id,`round` FROM attackenset WHERE Char_ID = '.$char_id.' AND Type = '.$type;
// echo $test . '<br>';
$qry = mysql_query($test);
}

@ -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;
}
?>

@ -56,7 +56,11 @@ function addAttackUsageToChar($char_id, $attacken){
// Erstmal die Attacken vermerken!
for($i=0;$i<count($attacken);$i++){
// So jetzt nur noch die reqs einpflegen
$sql = 'Update lernen set benutzt = benutzt + '.$attacken[$i]['anzahl'].' where name = \''.$attacken[$i]['a_name'].'\' and besitzer = '.$char_id;
if($$attacken[$i]['id'] === NULL) {
$sql = 'Update lernen set benutzt = benutzt + '.$attacken[$i]['anzahl'].' where name = \''.$attacken[$i]['a_name'].'\' and besitzer = '.$char_id;
} else {
$sql = 'Update lernen set benutzt = benutzt + '.$attacken[$i]['anzahl'].' where at_id = \''.$attacken[$i]['id'].'\' and besitzer = '.$char_id;
}
// echo $sql.'<br>';
mysql_query($sql);
}

@ -69,12 +69,26 @@ function displayAttacks($attacke1, $schaden1, $attacke2, $schaden2){
}
function displayFightNotAvailable() {
echo '<tr><td colspan="3"><table class="stylish" width="50%""><tr><td><table width="100%">';
echo '<tr>' .
'<th class="greenstats" colspan="4">Der Fight existiert nicht oder hat noch nicht angefangen!</th>'.
'</tr>';
echo '</table></td></tr>';
echo '</table>';
echo '</td></tr>';
}
function displayFightIsOngoing($char1_name, $char2_name) {
echo '<tr><td colspan="3"><table class="stylish" width="50%""><tr><td><table width="100%">';
echo '<tr>' .
'<td class="greenstats" colspan="4">Der Fight läuft noch!</td>'.
'<th class="greenstats" colspan="4">Der Fight läuft noch!</th>'.
'</tr>';
@ -338,7 +352,14 @@ function displayEventFight($event_id, $event_fight_id) {
echo '<html><head><link rel="stylesheet" type="text/css" href="design/FightStyle.css"></head><body><table width="100%">';
// :D
// first readout the required event data
$event_fight_data = mysql_fetch_assoc(mysql_query('SELECT *, visible <= now() as passed FROM event_fights WHERE event_id = ' . $event_id . ' AND event_fight_id = ' . $event_fight_id ));
$sql = 'SELECT *, visible <= now() as passed FROM event_fights WHERE event_id = ' . $event_id . ' AND event_fight_id = ' . $event_fight_id . ' AND `starting` <= now()';
//echo $sql . '<br>';
$event_fight_data = mysql_fetch_assoc(mysql_query($sql));
if(!$event_fight_data){
displayFightNotAvailable();
echo '</table></body></html>';
return;
}
// Okay and now get the data of the chars ;)
$sql = 'SELECT * FROM event_chars e where event_id = '.$event_id.' and event_char_id IN (SELECT event_char_id from event_fight_rounds where event_id = '.$event_id.' and event_fight_id = '.$event_fight_id.' and `round` = 0)';
// echo $sql . '<br>';
@ -357,7 +378,6 @@ function displayEventFight($event_id, $event_fight_id) {
// Platziere den Table-Header
echo '<tr><th class="top" colspan="3">'.$char1['char_name'].' Vs '.$char2['char_name'].'</th></tr>';
displayEventFightRound($char1, $char2, array(), array(), 0);
// now get the round data :D
$sql = 'SELECT * from event_fight_rounds WHERE event_id = ' .$event_id . ' AND event_fight_id = ' .$event_fight_id . ' and visible <= now()';
$qry = mysql_query($sql);
@ -370,11 +390,9 @@ function displayEventFight($event_id, $event_fight_id) {
}
for($i=0;$i<count($char1_rounds);$i++) {
displayEventFightRound($char1, $char2, $char1_rounds[$i], $char2_rounds[$i], $i+1);
displayEventFightRound($char1, $char2, $char1_rounds[$i], $char2_rounds[$i], $i);
}
// TODO: check if this fight is fully visible!
// readout the meta-data of this fight :D
$sql = 'SELECT * FROM event_fight_metadata WHERE event_id = ' .$event_id . ' AND event_fight_id = ' .$event_fight_id;
$qry = mysql_query($sql);
@ -406,24 +424,24 @@ function displayEventFightRound(array $char1_data, array $char2_data, array $cha
}
echo '<tr><th class="round" colspan="3">'.$runde.'</th></tr>';
$c1_str = $roundnr==0?$char1_data['strength']:$char1_round_data['strength'];
$c1_def = $roundnr==0?$char1_data['defense']:$char1_round_data['defense'];
$c1_spd = $roundnr==0?$char1_data['speed']:$char1_round_data['speed'];
$c1_stm = $roundnr==0?$char1_data['stamina']:$char1_round_data['stamina'];
$c1_lck = $roundnr==0?$char1_data['luck']:$char1_round_data['luck'];
$c1_hp = $roundnr==0?$char1_data['hp']:$char1_round_data['hp'];
$c1_str = $char1_round_data['strength'];
$c1_def = $char1_round_data['defense'];
$c1_spd = $char1_round_data['speed'];
$c1_stm = $char1_round_data['stamina'];
$c1_lck = $char1_round_data['luck'];
$c1_hp = $char1_round_data['hp'];
$c1_hpMax = $char1_data['hp'];
$c1_mp = $roundnr==0?$char1_data['mp']:$char1_round_data['mp'];
$c1_mp = $char1_round_data['mp'];
$c1_mpMax = $char1_data['mp'];
$c2_str = $roundnr==0?$char2_data['strength']:$char2_round_data['strength'];
$c2_def = $roundnr==0?$char2_data['defense']:$char2_round_data['defense'];
$c2_spd = $roundnr==0?$char2_data['speed']:$char2_round_data['speed'];
$c2_stm = $roundnr==0?$char2_data['stamina']:$char2_round_data['stamina'];
$c2_lck = $roundnr==0?$char2_data['luck']:$char2_round_data['luck'];
$c2_hp = $roundnr==0?$char2_data['hp']:$char2_round_data['hp'];
$c2_str = $char2_round_data['strength'];
$c2_def = $char2_round_data['defense'];
$c2_spd = $char2_round_data['speed'];
$c2_stm = $char2_round_data['stamina'];
$c2_lck = $char2_round_data['luck'];
$c2_hp = $char2_round_data['hp'];
$c2_hpMax = $char2_data['hp'];
$c2_mp = $roundnr==0?$char2_data['mp']:$char2_round_data['mp'];
$c2_mp = $char2_round_data['mp'];
$c2_mpMax = $char2_data['mp'];
// Bild + Avantarinfo | Attacken + Schaden | Bild + Avantarinfo

@ -18,7 +18,7 @@ include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/arena.inc.php');
function convertLearnIDToAttackID (array $learnids, $char_id) {
$result = array();
$sql = 'SELECT id, at_id FROM lernen WHERE id IN ('.implode(',', $learnids).') AND besitzer = ' . $char_id;
// echo $sql .'<br>';
// echo $sql .'<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
for($i=0;$i<count($learnids);$i++) {
@ -108,7 +108,6 @@ function calculateFight(array $char1, array $char2) {
}
}
$metaData = array();
$metaData['host'] = $char1['id'];
## Start the fight ;)
@ -117,7 +116,19 @@ function calculateFight(array $char1, array $char2) {
// An entry contains { char1_array*, char2_array*, atk_char1, atk_char2, dmg_char1, dmg_char2 }
// the char arrays contain the stats of the chars at the end of the round !
$rundenArray = array();
$chara_1['hp'] = $k_hp[0];
$chara_1['hp_max'] = $k_hp1[1];
$chara_1['mp'] = $k_mp[0];
$chara_1['mp_max'] = $k_mp1[1];
$chara_2['hp'] = $k_hp[1];
$chara_2['hp_max'] = $k_hp2[1];
$chara_2['mp'] = $k_hp[1];
$chara_2['mp_max'] = $k_hp2[1];
$runde['char1_array'] = $chara_1;
$runde['char2_array'] = $chara_2;
$rundenArray = array($runde);
$tmp_hp = array();
while ($k_hp[0] > $k_aufgabe[0] AND $k_hp[1] > $k_aufgabe[1] AND $x < 10) {
@ -203,8 +214,9 @@ function calculateFight(array $char1, array $char2) {
$runde['char1_array'] = $chara_1;
$runde['char2_array'] = $chara_2;
$runde['atk_char1'] = $technick1['name'];
$runde['atk_char2'] = $technick2['name'];
$runde['atk_char1'] = $k_attacke1[$x];
$runde['atk_char2'] = $k_attacke2[$x];
$runde['dmg_char1'] = $schaden_1;
$runde['dmg_char2'] = $schaden_2;

@ -25,6 +25,10 @@ function getUser($userid, $buffer_enabled = true) {
return $GLOBALS['user_buffered_instances'][$userid];
}
function addMoneyToUser($userid, $amount) {
mysql_query('update user set geld = geld + ' . $amount . ' WHERE id = ' .$userid);
}
function checkSessionPasswort($userid, $password){
$sql = 'SELECT passwort from user where id = \''.$userid.'\'';

@ -547,6 +547,7 @@ CREATE TABLE `event_chars` (
`defense` int(11) NOT NULL,
`luck` int(11) NOT NULL,
`stamina` int(11) NOT NULL,
`abgeholt` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`event_id`,`event_char_id`),
KEY `char_bild` (`char_bild`),
CONSTRAINT `event_chars_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE
@ -586,8 +587,8 @@ CREATE TABLE `event_fight_rounds` (
`defense` int(11) NOT NULL,
`luck` int(11) NOT NULL,
`stamina` int(11) NOT NULL,
`attack` varchar(30) NOT NULL,
`damage` varchar(30) NOT NULL,
`attack` varchar(30) DEFAULT NULL,
`damage` varchar(30) DEFAULT NULL,
`visible` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`event_id`,`event_fight_id`,`event_char_id`,`round`),
KEY `event_fight_rounds_chars` (`event_id`,`event_char_id`),
@ -604,7 +605,8 @@ DROP TABLE IF EXISTS `event_fights`;
CREATE TABLE `event_fights` (
`event_id` int(10) unsigned NOT NULL,
`event_fight_id` int(10) unsigned NOT NULL,
`visible` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`visible` timestamp NOT NULL,
`started` timestamp NOT NULL,
`host` int(10) unsigned NOT NULL,
`winner` int(10) unsigned NOT NULL,
PRIMARY KEY (`event_id`,`event_fight_id`),

Loading…
Cancel
Save