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

Loading…
Cancel
Save