Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function smartsearch($whbin,$itemX,$itemY) {
- $ver = 32; //item lenght, s6 e3
- if (substr($whbin,0,2)=='0x') $whbin=substr($whbin,2);
- $items = str_repeat('0', 120);
- $itemsm = str_repeat('1', 120);
- $i = 0;
- while ($i<120) {
- $_item = substr($whbin,($ver*$i), $ver);
- $check_ref = hexdec(substr($_item, 19,1))/16;
- if($check_ref == 0.5)
- $type = floor(hexdec(substr($_item,18,2))/16);
- else
- $type = round(hexdec(substr($_item,18,2))/16);
- $query = $this->db->query('SELECT size_x, size_y FROM mucore_shop_items WHERE i_id = '.hexdec(substr($_item,0,2)).' AND i_type = '.$type.'');
- if(hexdec(substr($_item,0,2)) != 255 && $type != 16){
- if($query->rowCount() < 1){
- $not_found = true;
- }
- else{
- $not_found = false;
- }
- }
- $res = $query->fetch(PDO::FETCH_ASSOC);
- $y = 0;
- while($y<$res['size_y']) {
- $y++;$x=0;
- while($x<$res['size_x']) {
- $items = substr_replace($items, '1', ($i+$x)+(($y-1)*8), 1);
- $x++;
- }
- }
- $i++;
- }
- $y = 0;
- while($y<$itemY) {
- $y++;$x=0;
- while($x<$itemX) {
- $x++;
- $spacerq[$x+(8*($y-1))] = true;
- }
- }
- $walked = 0;
- $i = 0;
- while($i<120) {
- if (isset($spacerq[$i])) {
- $itemsm = substr_replace($itemsm, '0', $i-1, 1);
- $last = $i;
- $walked++;
- }
- if ($walked==count($spacerq)) $i=119;
- $i++;
- }
- $useforlength = substr($itemsm,0,$last);
- $findslotlikethis='^'.str_replace('++','+',str_replace('1','+[0-1]+', $useforlength));
- ///echo '<pre>'.$useforlength.'</pre>';
- $i=0;$nx=0;$ny=0;
- while ($i<120) {
- if ($nx==8) { $ny++; $nx=0; }
- if ((@ereg($findslotlikethis, substr($items, $i, strlen($useforlength)))) && ($itemX+$nx<9) && ($itemY+$ny<16))
- return $i;
- $i++;
- $nx++;
- }
- if($not_found == true){
- return 1338;
- }
- return 1337;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement