diff --git a/ag/include/attackenset.inc.php b/ag/include/attackenset.inc.php index 1b872e4..66ead07 100644 --- a/ag/include/attackenset.inc.php +++ b/ag/include/attackenset.inc.php @@ -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 . '
'; $qry = mysql_query($test); } diff --git a/ag/include/event.inc.php b/ag/include/event.inc.php index 2b85a55..0c0c5a6 100644 --- a/ag/include/event.inc.php +++ b/ag/include/event.inc.php @@ -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 . '
'; 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 .'
'; + echo $sql .'
'; 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 .'
'; + echo $sql .'
'; 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; +} ?> \ No newline at end of file diff --git a/ag/include/exp.inc.php b/ag/include/exp.inc.php index ea839ea..330bf85 100644 --- a/ag/include/exp.inc.php +++ b/ag/include/exp.inc.php @@ -13,7 +13,7 @@ function beautifyNumericValue($value, $step){ // RUNDEN(POTENZ(10;ABRUNDEN(MAX(LOG(I3;10);2)))/4;0) $tmp = round(pow(10,floor(max(log($value,10),2)))/$step); return round($value / $tmp) * $tmp; - + } function calculateRequiredExpChars($level){ @@ -28,7 +28,7 @@ function calculateRequiredExpChars($level){ $g08 = pow($level*$level,8) * pow(10,-26); $g09 = pow($level*$level,9) * pow(10,-30); $g10 = pow($level*$level,10) * pow(10,-33); - + return beautifyNumericValue($g01 + $g02 + $g03 + $g04 + $g06 + $g07 + $g08 + $g09 + $g10, 8); // return $g01 + $g02 + $g03 + $g04 + $g06 + $g07 + $g08 + $g09 + $g10; } @@ -46,25 +46,29 @@ function calculateRequiredExpArena($level){ return beautifyNumericValue($g00 + $g01 + $g02 + $g03 + $g04, 8); } /** - * + * * @param $attacken array of 10 arrays with entry (anzahl and a_name) * @return unknown_type */ function addAttackUsageToChar($char_id, $attacken){ $char = getChar($char_id, false); // We really want the actual char!! - + // Erstmal die Attacken vermerken! for($i=0;$i'; mysql_query($sql); } - + // Sooo und nun gehts darum ob wir neue Attacken lernen können - + // Ersma die ganzen Infos laden - $sql = 'SELECT * FROM lernen where besitzer = '.$char_id; + $sql = 'SELECT * FROM lernen where besitzer = '.$char_id; $qry = mysql_query($sql); while($row = mysql_fetch_assoc($qry)){ $lern[$row['at_id']] = $row; // Zum späteren Check ob die Reqs erfüllt sind @@ -76,24 +80,24 @@ function addAttackUsageToChar($char_id, $attacken){ $zusatz = ' AND id NOT IN('.join($atkid,',').')'; } - // Lernbare Attacken auswählen + // Lernbare Attacken auswählen if(!is_null($char['frucht'])){ $sql = 'select * from attacken where (Frucht is NULL or Frucht = (Select id from wochen_markt where item = \''.$char['frucht'].'\')) and (rassen != \'\' and rassen != \'0\') and level <= '.$char['level'].$zusatz; } else { $sql = 'select * from attacken where (Frucht is NULL) and (rassen != \'\' and rassen != \'0\') and level <= '.$char['level'].$zusatz; } - + // echo $sql.'
'; - + $qry = mysql_query($sql); - + // Das geht leider nicht mit dieser Datenstruktur direkt auszuwählen $raceid[] = getCharRaceId($char_id); if(!is_null(getFusionRaceId($char_id))){ $raceid[] = getFusionRaceId($char_id); } - - // So und nun arbeite jede Attacke durch die nur im geringsten Lernbar sein könnte ... + + // So und nun arbeite jede Attacke durch die nur im geringsten Lernbar sein könnte ... while($row = mysql_fetch_assoc($qry)) { // Erstmal checken ob es eine Fruchtattacke ist (durch die SQL-Anweisung werden alle nicht zutreffenden Früchte ausgeblockt) $learnable = false; @@ -114,7 +118,7 @@ function addAttackUsageToChar($char_id, $attacken){ } } } - + if($learnable){ // Haben wir die benötigten Attacken auch oft genug genutzt?? $r_atck = preg_split('#,#', $row['req_atk']); @@ -122,17 +126,17 @@ function addAttackUsageToChar($char_id, $attacken){ if($r_atck[$u] != '0' && $lern[$r_atck[$u]]['benutzt'] < $row['geld']){ // Passt nicht? dann brauchen wir garnich weiter machen // echo 'Der Char kann '.$row['name'].' nicht lernen, weil er die Attacke '.$lern[$r_atck[$u]]['name'].' nur '.$lern[$r_atck[$u]]['benutzt'].' mal eingesetzt hat und nicht '.$row['geld'].'
'; - $learnable = false; + $learnable = false; break; } } } - + if($learnable){ mysql_query('INSERT lernen SET name=\''.$row['name'].'\', at_id=\''.$row['id'].'\', besitzer=\''.$char_id.'\', aktiv=\'1\''); echo ''; } - } + } } function addExpToChar($char_id, $n_exp){ @@ -146,7 +150,7 @@ function addExpToChar($char_id, $n_exp){ // Level UP!! $lvls++; $char['level']++; - + $char_exp[0] -= $char_exp[1]; $char_exp[1] = calculateRequiredExpChars($char['level']); $tp += calculateTrainingPoints($char['level']); @@ -180,7 +184,7 @@ function addExpToArena($user_id, $n_exp){ // Level UP!! $lvls++; $arena['level']++; - + $arena_exp[0] -= $arena_exp[1]; $arena_exp[1] = calculateRequiredExpArena($arena['level']); } diff --git a/ag/include/kampf_anzeige.inc.php b/ag/include/kampf_anzeige.inc.php index 1627ead..0b85ce9 100644 --- a/ag/include/kampf_anzeige.inc.php +++ b/ag/include/kampf_anzeige.inc.php @@ -69,12 +69,26 @@ function displayAttacks($attacke1, $schaden1, $attacke2, $schaden2){ } +function displayFightNotAvailable() { +echo ''; +echo '
'; + + +echo '' . + ''. + ''; + +echo '
Der Fight existiert nicht oder hat noch nicht angefangen!
'; +echo ''; + +} + function displayFightIsOngoing($char1_name, $char2_name) { echo ''; - 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'; - $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 diff --git a/ag/include/kampf_wrapper.inc.php b/ag/include/kampf_wrapper.inc.php index e07d46c..f908eb4 100644 --- a/ag/include/kampf_wrapper.inc.php +++ b/ag/include/kampf_wrapper.inc.php @@ -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 .'
'; +// echo $sql .'
'; $qry = mysql_query($sql); while($row = mysql_fetch_assoc($qry)) { for($i=0;$i $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; diff --git a/ag/include/user.inc.php b/ag/include/user.inc.php index 9f2e334..f36ab21 100644 --- a/ag/include/user.inc.php +++ b/ag/include/user.inc.php @@ -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.'\''; diff --git a/db/animegame_svn.sql b/db/animegame_svn.sql index 04339f5..2eae56d 100644 --- a/db/animegame_svn.sql +++ b/db/animegame_svn.sql @@ -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`),
'; echo '' . - ''. + ''. ''; @@ -338,7 +352,14 @@ function displayEventFight($event_id, $event_fight_id) { echo '
Der Fight läuft noch!Der Fight läuft noch!
'; // :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 . '
'; + $event_fight_data = mysql_fetch_assoc(mysql_query($sql)); + if(!$event_fight_data){ + displayFightNotAvailable(); + echo '
'; + 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 . '
'; @@ -357,7 +378,6 @@ function displayEventFight($event_id, $event_fight_id) { // Platziere den Table-Header echo '
'.$char1['char_name'].' Vs '.$char2['char_name'].'
'.$runde.'