Results 1 to 1 of 1

Thread: [php] Finding Altador Constellations and URLs

Hybrid View

  1. #1
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m

    [php] Finding Altador Constellations and URLs

    @(you need an account to see links)

    PHP Code:
    /**
     * Neopets constellation finder (altador plot).
     * Originally written in Javascript by Andy Nguyen, ported to PHP by Zachafer.
     */

    error_reporting(-1);

    class 
    ConstellationFinder
    {

        private 
    $data;

        public function 
    ConstellationFinder($starData)
        {
            
    $this->data $starData;
        }


        private 
    $dxArray = array(array(4080120160200), array(60120130190,
            
    110), array(208016014080), array(1401012016080), array(60120,
            
    060120), array(50170200190140), array(701404070100), array(10,
            
    100100190200), array(402040, -50, -60), array(40, -3010110120),
            array(-
    707000, -130), array(10120160170200));


        private 
    $dyArray = array(array(-30, -60, -60, -300), array(-2004060, -
            
    90), array(60800, -60, -80), array(-30, -80, -60, -7060), array(-300,
            
    140170140), array(70400, -90, -10), array(300, -120, -140, -120),
            array(-
    50, -13010, -500), array(40, -40, -80, -10120), array(-70, -140, -
            
    200, -170, -90), array(00, -707090), array(-140, -60, -190, -200));

        public static 
    $constNames = array(=> 'Dreamer'=> 'First to Rise'=>
            
    'Dancer'=> 'Collector'11 => 'Hunter'=> 'Thief'=> 'Farmer'=>
            
    'Sleeper'=> 'Wave'=> 'Gladiator'=> 'Gatherer'10 => 'Protector');

        public function 
    findPoints($name)
        {

            
    $j array_search($nameself::$constNames);

            if (
    $j === false)
                return 
    "Invalid name";

            
    $data $this->data;
            
    $data substr($data0strpos($data':'));
            
    $starArray = array();

            while ((
    $linePos strpos($data'|')) !== false) {
                
    $starCoords substr($data0$linePos);
                
    $starArray[substr($starCoords0strlen($starCoords) - 2)] = $starCoords;
                
    $data substr($datastrpos($data'|') + 1);
            }

            
    $starCoords $data;

            
    $starArray[substr($starCoords0strlen($starCoords) - 2)] = $starCoords;

            foreach (
    $starArray as $i) {
                
    $x intval(substr($i0strpos($i',')));
                
    $y intval(substr($istrpos($i',') + 1));

                if (
    array_key_exists(($x $this->dxArray[$j][0]) . "," . ($y $this->dyArray[$j][0]),
                    
    $starArray) && array_key_exists(($x $this->dxArray[$j][1]) . "," . ($y $this->
                    
    dyArray[$j][1]), $starArray) && array_key_exists(($x $this->dxArray[$j][2]) .
                    
    "," . ($y $this->dyArray[$j][2]), $starArray) && array_key_exists(($x $this->
                    
    dxArray[$j][3]) . "," . ($y $this->dyArray[$j][3]), $starArray) &&
                    
    array_key_exists(($x $this->dxArray[$j][4]) . "," . ($y $this->dyArray[$j][4]),
                    
    $starArray)) {
                    return array(
    "(" substr_replace($i'', -2) . ")""(" . ($x $this->dxArray[$j][0]) .
                        
    "," . ($y $this->dyArray[$j][0]) . ")""(" . ($x $this->dxArray[$j][1]) .
                        
    "," . ($y $this->dyArray[$j][1]) . ")""(" . ($x $this->dxArray[$j][2]) .
                        
    "," . ($y $this->dyArray[$j][2]) . ")""(" . ($x $this->dxArray[$j][3]) .
                        
    "," . ($y $this->dyArray[$j][3]) . ")""(" . ($x $this->dxArray[$j][4]) .
                        
    "," . ($y $this->dyArray[$j][4]) . ")");
                }

            }
            return array();
        }

        public function 
    findAll()
        {
            
    $retVal = array();
            foreach (
    self::$constNames as $name) {
                
    $retVal[$name] = $this->findPoints($name);
            }
            return 
    $retVal;
        }

        public function 
    makeURL($name)
        {
            
    $points $this->findPoints($name);
            foreach (
    $points as & $point)
                
    $point str_replace(array('('')'), ''$point);
            return 
    "star_submit=" $this->joinPoints($points$name);
        }

        private 
    $pointsOrder = array('Sleeper' => array(01101221344,
            
    34554), 'Dreamer' => array(01101221233234),
            
    'First to Rise' => array(0110122134454354),
            
    'Farmer' => array(01141510233234434151),
            
    'Dancer' => array(0112102134434554), 'Wave' =>
            array(
    01101221233234434554), 'Gladiator' =>
            array(
    030112102521303443455452),
            
    'Collector' => array(03011023353230535445),
            
    'Thief' => array(040201101520233245405,
            
    451), 'Gatherer' => array(01102523343245435,
            
    254), 'Protector' => array(04030102101314202,
            
    324303231404142), 'Hunter' => array(010412,
            
    1310242134314542434054));

        private function 
    joinPoints($points$name)
        {
            if (
    array_key_exists($name$this->pointsOrder)) {
                
    $submit '';
                
    $semiColon false;
                
    $order $this->pointsOrder[$name];
                
    $loopMax count($order);
                
    $x 0;
                while (
    $x $loopMax) {
                    
    $submit .= $points[$order[$x]];
                    if (++
    $x count($order))
                        if (
    $semiColon = !$semiColon)
                            
    $submit .= ';';
                        else
                            
    $submit .= '|';
                }
            }
            if (
    $name == 'Dreamer') {
                
    $submit .= '|' $points[5] . '|' $points[4] . ';' $points[3];
            } elseif (
    $name == 'Protector') {
                
    $submit .= '|' $points[5];
            }
            return 
    $submit;
        }

    Usage:
    Last edited by Zachafer; 03-26-2012 at 11:45 PM.

  2. The Following 5 Users Say Thank You to Zachafer For This Useful Post:

    j03 (03-20-2012),Josh (03-20-2012),Reemer (03-22-2012),Ronith (03-20-2012),zxzero (03-20-2012)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •