示例#1
0
 public function getNeighborZoneList(Zone $zone, $distance = 1)
 {
     $coords = GameGridProvider::buildCoordsFromAddress($zone->getIdentity());
     $grid = $coords['zoneCoords'];
     $sector = $coords['sectorCoords'];
     $neg = -1 * $distance;
     $pos = $distance + 1;
     $neighbors = [];
     $zoneMax = $this->ZONE_MAX;
     $secMax = $this->SEC_MAX;
     $secMin = $this->SEC_MIN;
     $zoneX = $zoneMax['x'];
     $zoneY = $zoneMax['y'];
     $zoneZ = $zoneMax['z'];
     for ($x = $neg; $x < $pos; $x++) {
         for ($y = $neg; $y < $pos; $y++) {
             for ($z = $neg; $z < $pos; $z++) {
                 if ($x == 0 && $y == 0 && $z == 0) {
                     continue;
                 }
                 $new = [];
                 $sec = [];
                 $new['x'] = $grid['x'] + $x;
                 $new['y'] = $grid['y'] + $y;
                 $new['z'] = $grid['z'] + $z;
                 $sec['x'] = $sector['x'];
                 $sec['y'] = $sector['y'];
                 $sec['z'] = $sector['z'];
                 if ($new['x'] < 0) {
                     $new['x'] = $zoneX - ($new['x'] + 1);
                     $sec['x'] -= 1;
                 }
                 if ($new['x'] > $zoneX) {
                     $new['x'] = $new['x'] - $zoneX;
                     $sec['x'] += 1;
                 }
                 if ($new['y'] < 0) {
                     $new['y'] = $zoneY - ($new['y'] + 1);
                     $sec['y'] -= 1;
                 }
                 if ($new['y'] > $zoneY) {
                     $new['y'] = $new['y'] - $zoneY;
                     $sec['y'] += 1;
                 }
                 if ($new['z'] < 0) {
                     $new['z'] = $zoneZ - ($new['z'] + 1);
                     $sec['z'] -= 1;
                 }
                 if ($new['z'] > $zoneZ) {
                     $new['z'] = $new['z'] - $zoneZ;
                     $sec['z'] += 1;
                 }
                 if ($sec['x'] > $secMax['x'] || $sec['x'] < $secMin['x'] || $sec['y'] > $secMax['y'] || $sec['y'] < $secMin['y'] || $sec['z'] > $secMax['z'] || $sec['z'] < $secMin['z']) {
                     continue;
                 }
                 $neighbors[] = GameGridProvider::buildAddressFromCoords($sec, $new);
             }
         }
     }
     return $neighbors;
 }
示例#2
0
文件: Zone.php 项目: JordanRL/eden
 public function distanceToZone(Zone $zone)
 {
     return $this->distanceToAddress($zone->getIdentity());
 }