Cod: Selectaţi tot
public function checkPosition($newsize){
$slot=array(
"0" => 0,
"1" => 0,
"2" => 0,
"3" => 0,
"4" => 0,
"5" => 0,
"6" => 0,
"7" => 0,
"8" => 0,
"9" => 0,
"10" => 0,
"11" => 0,
"12" => 0,
"13" => 0,
"14" => 0,
"15" => 0,
"16" => 0,
"17" => 0,
"18" => 0,
"19" => 0,
"20" => 0,
"21" => 0,
"22" => 0,
"23" => 0,
"24" => 0,
"25" => 0,
"26" => 0,
"27" => 0,
"28" => 0,
"29" => 0,
"30" => 0,
"31" => 0,
"31" => 0,
"32" => 0,
"33" => 0,
"34" => 0,
"35" => 0,
"36" => 0,
"37" => 0,
"38" => 0,
"39" => 0,
"40" => 0,
"41" => 0,
"42" => 0,
"43" => 0,
"44" => 0,
);
$own_id=$_SESSION['user_id'];
$sql = "SELECT item.pos,item_proto.size AS item_size
FROM player.item
INNER JOIN player.item_proto
ON item_proto.vnum=item.vnum
WHERE item.owner_id=? AND item.window=?";
$stmt = $this->o_db->prepare($sql);
$stmt->execute(array($own_id,"MALL"));
$result =$stmt->FetchAll();
$nextposition = 0;
foreach($result as $exist){
$replace = array($exist['pos'] => 1);
$slot = array_replace( $slot, $replace);
if($exist['item_size'] == '2'){
$replace2 = array($exist['pos']+5=>1);
$slot = array_replace( $slot, $replace2);
}
if($exist['item_size'] == '3'){
$replace3 = array($exist['pos']+5=>1,$exist['pos']+10=>1);
$slot = array_replace( $slot, $replace3);
}
}
for($zorke=0;$zorke<=44;$zorke++){
if($newsize == '1'){
if($slot[$zorke] == '0'){
$nextposition = $zorke;
$zorke = 45;
}
if($zorke == 44)
{
$nextposition = 45;
$zorke = 45;
}
}
if($newsize == '2'){
if($slot[$zorke] == '0' && $slot[$zorke+5] == '0' ){
$nextposition = $zorke;
$zorke = 45;
}
if($zorke == 40){
$nextposition = 45;
$zorke = 45;
}
}
if($newsize == '3'){
if($slot[$zorke] == '0' && $slot[$zorke+5] == '0' && $slot[$zorke+10] == '0'){
$nextposition = $zorke;
$zorke = 45;
}
if($zorke == 35){
$nextposition = 45;
$zorke = 45;
}
}
}
return $nextposition;
}