Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getMap(Player $observer, int $width, int $height, int $inDegrees, int $size = 16){ // No compass
- $to = (int)sqrt($size);
- $centerPs = new Vector3($observer->x >> $to, 0, $observer->z >> $to);
- $map = [];
- $centerFaction = $this->factionInPoint($observer->getX(), $observer->getZ());
- if($centerFaction == Null) $centerFaction = "Wilderness";
- $head = TF::GREEN . " (" . $centerPs->getX() . "," . $centerPs->getZ() . ") " . $centerFaction . " " . TF::WHITE;
- $head = TF::GOLD . str_repeat("_", (($width - strlen($head)) / 2)) . ".[" . $head . TF::GOLD . "]." . str_repeat("_", (($width - strlen($head)) / 2));
- $map[] = $head;
- $halfWidth = $width / 2;
- $halfHeight = $height / 2;
- $width = $halfWidth * 2 + 1;
- $height = $halfHeight * 2 + 1;
- $topLeftPs = new Vector3($centerPs->x + -$halfWidth, 0, $centerPs->z + -$halfHeight);
- // Get the compass
- $asciiCompass = self::getASCIICompass($inDegrees, TF::RED, TF::GOLD);
- // Make room for the list of names
- $height--;
- /** @var string[] $fList */
- $fList = array();
- $chrIdx = 0;
- $overflown = false;
- $chars = self::MAP_KEY_CHARS;
- // For each row
- for ($dz = 0; $dz < $height; $dz++){
- // Draw and add that row
- $row = "";
- for ($dx = 0; $dx < $width; $dx++){
- if($dx == $halfWidth && $dz == $halfHeight){
- $row .= (self::MAP_KEY_SEPARATOR);
- continue;
- }
- if(!$overflown && $chrIdx >= strlen(self::MAP_KEY_CHARS)) $overflown = true;
- $herePs = $topLeftPs->add($dx, 0, $dz);
- $hereFaction = $this->factionInPoint($herePs->x << $to, $herePs->z << $to);
- $contains = in_array($hereFaction, $fList, true);
- if($hereFaction === NULL){
- $row .= self::MAP_KEY_WILDERNESS;
- } elseif(!$contains && $overflown){
- $row .= self::MAP_KEY_OVERFLOW;
- } else {
- if(!$contains) $fList[$chars{$chrIdx++}] = $hereFaction;
- $fchar = array_search($hereFaction, $fList);
- $row .= $this->getColorForTo($observer, $hereFaction) . $fchar;
- }
- }
- $line = $row; // ... ---------------
- // Add the compass
- if($dz == 0) $line = $asciiCompass[0] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
- if($dz == 1) $line = $asciiCompass[1] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
- if($dz == 2) $line = $asciiCompass[2] . "" . substr($row, 3 * strlen(self::MAP_KEY_SEPARATOR));
- $map[] = $line;
- }
- $fRow = "";
- foreach ($fList as $char => $faction){
- $fRow .= $this->getColorForTo($observer, $faction) . $char . ": " . $faction . " ";
- }
- if($overflown) $fRow .= self::MAP_OVERFLOW_MESSAGE;
- $fRow = trim($fRow);
- $map[] = $fRow;
- return $map;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement