Fix: the getAttacksforChar now returns all learned and currently learnable attacks. The order item is the level.

main
hecht 13 years ago
parent b3fd6bb1a6
commit 4a000b3ca5

@ -285,16 +285,35 @@ function getFusionRaceId($charid){
/**
* This function returns an overview about the
* @param $charid the id of the character
* @param $mode 0 = show all available attacks, 1 = show all unavailable attacks, 2 = show both!
*/
function getAttacksforChar($charid) {
function getAttacksforChar($charid, $mode = 0) {
$char = getChar($charid);
$char_race = getCharRaceId($charid);
echo '<br>';
// first read out basic information about our attacks
$sql = 'select a.name, a.id, a.level, substr(a.req_atk, 1, locate(\',0\', a.req_atk) - 1) as req_atk , geld, ifnull((select l.benutzt from lernen l where l.besitzer = '.$char['id'].' and at_id = a.id),0) as benutzt, a.id not in (select l.at_id from lernen l where l.besitzer = '.$char['id'].') as unknown from attacken a where find_in_set('.$char_race.', a.rassen) order by level';
// $sql = 'select a.name, a.id, a.level, if(find_in_set(\'0\', req_atk) = 0, a.req_atk, substr(a.req_atk, 1, locate(\',0\', a.req_atk) - 1)) as req_atk , geld, ifnull((select l.benutzt from lernen l where l.besitzer = '.$char['id'].' and at_id = a.id),0) as benutzt, a.id not in (select l.at_id from lernen l where l.besitzer = '.$char['id'].') as unknown from attacken a where find_in_set('.$char_race.', a.rassen) order by level';
$sql_append = '';
if($char['frucht'] !== NULL) {
$sql_append1 = ' OR (frucht = (Select id from wochen_markt where item = \''.$char['frucht'].'\')) ';
$sql_append2 = ' AND (frucht <> (Select id from wochen_markt where item = \''.$char['frucht'].'\')) ';
}
// First sql to include all currently learnable attacks
$sql = 'SELECT a.name, a.id, a.level, a.geld, if(find_in_set(\'0\', req_atk) = 0, a.req_atk, substr(a.req_atk, 1, locate(\',0\', a.req_atk) - 1)) as req_atk, ifnull(l.benutzt, 0) as benutzt, if(l.benutzt is null,1,0) as unknown from attacken a left join lernen l on a.id = l.at_id AND l.besitzer = '.$char['id']. ' where find_in_set('.$char_race.', a.rassen) <> 0 '.$sql_append1;
// Second sql to include all currently not learnable attacks (due to an other fruit or fusion race)
$sql2 = 'SELECT a.name, a.id, a.level, a.geld, if(find_in_set(\'0\', req_atk) = 0, a.req_atk, substr(a.req_atk, 1, locate(\',0\', a.req_atk) - 1)) as req_atk, ifnull(l.benutzt, 0) as benutzt, if(l.benutzt is null,1,0) as unknown from lernen l inner join attacken a on l.at_id = a.id where besitzer = '.$char['id'].' and find_in_set('.$char_race.', a.rassen) = 0 '.$sql_append2;
// make a union out of both (TODO: maybe an outer join would result into the same result)
$sql = '('.$sql.') union distinct ('.$sql2.') order by level';
$qry = mysql_query($sql);
echo '<br>'.$sql.'<br>';
if($qry === FALSE) // print sql on error
echo '<br>'.$sql.'<br>';
// The first index is the id of the attack!
// then there is the basic information like
@ -312,23 +331,30 @@ function getAttacksforChar($charid) {
while($row = mysql_fetch_assoc($qry)) {
$attacke[$row['id']] = $row;
if($row['unknown'] == 0 && $mode == 1) {
continue;
} else if($row['unknown'] == 1 && $mode == 0) {
continue;
}
$overview[$row['id']] = array('id' => $row['id'], 'name' => $row['name'], 'levelups' => ($row['level'] - $char['level']), 'benutzt' => $row['benutzt'], 'unknown' => $row['unknown'] == 1);
// as it is straight forward (on level) we already can calculate the dependencies
if($overview[$row['id']]['levelups'] < 0) {
$overview[$row['id']]['levelups'] = 0;
}
echo $attacke[$row['id']]['name'] . ' = ' . $attacke[$row['id']]['req_atk'] . '<br>';
// echo $attacke[$row['id']]['name'] . ' = ' . $attacke[$row['id']]['req_atk'] . '<br>';
if($attacke[$row['id']]['req_atk'] == 0) {
echo 'Nothing to do<br>';
// nothing :D
$attacke[$row['id']]['req'] = array(0);
} else if(strpos($attacke[$row['id']]['req_atk'], ',') === FALSE) {
echo 'One thing to do<br>';
// echo 'One thing to do<br>';
// only one attack required :) => use reference
$other_attack = &$attacke[$row['id']]['req_atk'];
$other_attack = &$attacke[$attacke[$row['id']]['req_atk']];
// => this is the id of the required attack, so easy going :)
$reggs = ($attacke[$row['id']]['geld'] - $other_attack['benutzt']);
if($reggs < 0) {
@ -336,7 +362,7 @@ function getAttacksforChar($charid) {
}
$overview[$row['id']]['req'][] = array('id' => $other_attack['id'], 'name' => $other_attack['name'], 'reggs' => $reggs);
} else {
echo 'More things to do<br>';
// echo 'More things to do<br>';
// multiple attacks required :(
$attack_ids = explode(',',$attacke[$row['id']]['req_atk']);
for($i=0;$i<count($attack_ids);$i++) {
@ -355,4 +381,4 @@ function getAttacksforChar($charid) {
}
?>
?>

Loading…
Cancel
Save