Added a funtion to create a overview which can be used to calculate newly learned attacks or display how many has to be done ;)

main
hecht 13 years ago
parent 6db4c3bf4d
commit b3fd6bb1a6

@ -283,4 +283,76 @@ function getFusionRaceId($charid){
}
/**
* This function returns an overview about the
*/
function getAttacksforChar($charid) {
$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';
$qry = mysql_query($sql);
echo '<br>'.$sql.'<br>';
// The first index is the id of the attack!
// then there is the basic information like
//
// entries {id, name, levelups, benutzt, unknown}
// ==> id, name, required level, times that it has been used , if its still unkown (bool)
// entry {req} -> array {id, name, reggs}
// ==> [0] => first requirenment -> id, name, amount level ups required, times to be used
// ==> [n] => nth requirenment -> ...
$overview = array();
$attacke = array();
$requires = array();
while($row = mysql_fetch_assoc($qry)) {
$attacke[$row['id']] = $row;
$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>';
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>';
// only one attack required :) => use reference
$other_attack = &$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) {
$reggs = 0;
}
$overview[$row['id']]['req'][] = array('id' => $other_attack['id'], 'name' => $other_attack['name'], 'reggs' => $reggs);
} else {
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++) {
$other_attack = &$attacke[$attack_ids[$i]];
// => this is the id of the required attack, so easy going :)
$reggs = ($attacke[$row['id']]['geld'] - $other_attack['benutzt']);
if($reggs < 0) {
$reggs = 0;
}
$overview[$row['id']]['req'][] = array('id' => $other_attack['id'], 'name' => $other_attack['name'], 'reggs' => $reggs);
}
}
}
return $overview;
}
?>
Loading…
Cancel
Save