extended the check

main
hecht 10 years ago
parent 5db0542833
commit c5bfc2d206

@ -22,7 +22,7 @@ function erstelleUser(){
}
function hasUserFreeCharSlot($user) {
function hasUserFreeCharSlot($user, $special = false) {
$chars = getCharsOfUser($user['id']);
$special_chars = 0;
$normal_chars = 0;
@ -33,15 +33,19 @@ function hasUserFreeCharSlot($user) {
$normal_chars++;
}
}
// The first special char is always on its special slot!
if($special_chars > 0)
$special_chars--;
$chars_avail = $normal_chars + $special_chars;
$slots_avail = $user['char_max'];
if($chars_avail < $slots_avail) {
return true;
if(!$special) {
if($special_chars > 0)
$special_chars--;
$chars_avail = $normal_chars + $special_chars;
$slots_avail = $user['char_max'];
return $chars_avail < $slots_avail;
} else {
return $special_chars < 2;
}
return false;
}
// Muss aus einem sicheren Kontext gestartet werden
@ -77,25 +81,8 @@ function erstelleChar($user, $rassen_id, $newname = '', $picture = '', $lvl = 1,
if($race['name'] != 'NPC') {
//Ueberprüfe ob ein Slot frei ist
$chars = getCharsOfUser($user['id']);
$normal = 0;
$special = 0;
foreach($chars as $row){
if($row['rasse'] == 'Kaioshin' || $row['fusion_rasse'] == 'Kaioshin' || $row['rasse'] == 'Shichibukai' || $row['fusion_rasse'] == 'Shichibukai'){
$special++;
} else{
$normal++;
}
}
$slots_avail = $user['char_max'];
if(!$special_char && $special <= 0){
$slots_used = $normal;
} else{
$slots_used = $normal + $special - 1;
}
// echo 'Slots used: '.$slots_used.'<br>Slots available: '.$slots_avail.'<br>';
if($slots_used >= $user['char_max']){
$check = hasUserFreeCharSlot($user, $special_char);
if(!$check){
displayErrorMessage(NULL,'Alle Slots sind schon belegt!!',displayHistoryBackLink());
return false;
}

Loading…
Cancel
Save