예제 #1
0
 public function growAroundTile($index)
 {
     $this->freeIndexSearchIsRandom = true;
     $roundToBuild = 2;
     $map = $this->getMap();
     $position = new Tile($map->getAllTiles()[$index][self::COORDINATES][self::X], $map->getAllTiles()[$index][self::COORDINATES][self::Y]);
     $map->setTileDistance($index, self::COORDINATES);
     for ($round = self::DISTANCE; $round <= $roundToBuild; $round++) {
         $position->move(Directions::RIGHT_UP);
         foreach (Directions::getDirections() as $direction) {
             for ($step = 0; $step < $round; $step++) {
                 $tile = $position->move($direction);
                 if ($map->hasTile($tile)) {
                     if ($round == self::FIRST_ROUND) {
                         if ($map->isTileOnTheEdge($tile)) {
                             $newTileIndex = $map->getTileIndex($tile);
                             $map->setTileDistance($newTileIndex, self::DISTANCE);
                         }
                     }
                 } else {
                     $map->addTile($tile, $round);
                 }
             }
         }
     }
 }
예제 #2
0
 public function spawnToAll(Tile $t)
 {
     foreach ($this->server->api->player->getAll($t->level) as $player) {
         if ($player->eid !== false) {
             $t->spawn($player);
         }
     }
 }
예제 #3
0
 public function isTileOnTheEdge(Tile $tile)
 {
     foreach ($this->tiles as $item) {
         if ($item[self::COORDINATES] == $tile->getCoordinates()) {
             if ($item[self::DISTANCE] == self::IS_ON_THE_EDGE) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #4
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $this->getLevel()->setBlock($block, $this, true, true);
     $nbt = new Compound("", [new String("id", Tile::FLOWER_POT), new Int("id", $this->id), new Int("data", $this->data), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
     Tile::createTile(Tile::FLOWER_POT, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     return true;
 }
예제 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $map = Map::findOrFail($this->argument('map'));
     $minimap = $map->minimap;
     if (!$minimap->locked || $this->option('force')) {
         // Call dibs on editing this minimap
         $supernow = new Carbon();
         $this->info('[' . Carbon::now() . '] Locking and processing map ' . $map->id);
         $minimap->updated_at = new \DateTime();
         $minimap->locked = true;
         $minimap->save();
         // Load the tiles. May take some time. =)
         $tiles = Tile::where('mapid', $map->id)->where('posz', 7)->get();
         // Prepare the canvas, maestro!
         \OTWorlds\MinimapPainter::$filename = $minimap->path;
         \OTWorlds\MinimapPainter::load($map->width, $map->height);
         foreach ($tiles as $tile) {
             \OTWorlds\MinimapPainter::paint(intval($tile->posx), intval($tile->posy), intval($tile->itemid));
         }
         // Finish up
         \OTWorlds\MinimapPainter::save();
         // Let other processes edit this map again
         $minimap->locked = false;
         $minimap->save();
         $donenow = new Carbon();
         $this->info('[' . $donenow->now() . '] Done. Processed ' . $tiles->count() . ' tiles in ' . $donenow->diffInSeconds($supernow) . ' seconds.');
     } else {
         $this->error('Minimap is locked. Either another process is using it, or the last one crashed. Use --force to ignore.');
     }
 }
 public function BuildBoard($board_array)
 {
     foreach ($board_array as $index => $letter) {
         if ($letter != '') {
             if (Tile::Check($letter)) {
                 $this->board[$index] = new Tile(strtoupper($letter));
             }
         }
     }
 }
예제 #7
0
 private function tileToHTML(Tile $tile, array $screenCoords, Coordinates $coordinates)
 {
     $classTile = 'clear';
     $label = '';
     if (!$tile->isClear()) {
         $classTile = 'occupied';
     }
     if ($tile->hasGoalPathMarker()) {
         $classTile = 'goalPath';
     }
     if ($tile->hasStartMarker()) {
         $classTile = 'start';
         $label = 'start';
     }
     if ($tile->hasGoalMarker()) {
         $classTile = 'goal';
         $label = 'goal';
     }
     return '<div class="tile ' . $classTile . '" style="left:' . $screenCoords[0] . 'px; top:' . $screenCoords[1] . 'px; width:' . $this->tile_size . 'px; height:' . $this->tile_size . 'px;" title="' . $coordinates->__toString() . '">' . $label . '</div>';
 }
예제 #8
0
 public function loadFields($Game)
 {
     // load board layout
     for ($x = $this->dimensions['min_x']; $x <= $this->dimensions['max_x']; $x++) {
         for ($y = $this->dimensions['min_y']; $y <= $this->dimensions['max_y']; $y++) {
             // load fields
             $Field = $this->getField(array('x' => $x, 'y' => $y));
             // load placed tile?
             $sql = "\r\n\t\t\t\t\tSELECT `tile_id` FROM `placed_tiles`\r\n\t\t\t\t\tWHERE `game_id`  = {$Game->id}\r\n\t\t\t\t\t  AND `field_id` = {$Field->id}\r\n\t\t\t\t";
             $result = mysql_query($sql) or die('guhaswlkgdads' . mysql_error());
             if (mysql_num_rows($result) != 0) {
                 $row = mysql_fetch_assoc($result);
                 $Tile = new Tile();
                 $Tile->id = $row['tile_id'];
                 $Tile->init();
                 $Field->Tile = $Tile;
             }
             $this->board_layout[$x][$y] = $Field;
         }
     }
 }
예제 #9
0
 public function __construct($name, $size, $order)
 {
     $this->name = $name;
     $this->size = $size;
     $this->order = $order;
     $guage = new Tile("gauge-0.png", array("N" => true, "W" => true, "S" => false, "E" => false));
     $guage->setOwner($this);
     $top = new Tile("gauge-top-0.png", array("N" => false, "W" => false, "S" => true, "E" => false));
     $top->setOwner($this);
     $valve = new Tile("valve-closed.png", array("N" => false, "W" => false, "S" => false, "E" => true));
     $valve->setOwner($this);
     $midLine = $size / 2;
     if ($order == 1) {
         $this->pipeline[$midLine - 1][$size + 2] = $guage;
         $guage->setRowNum($midLine - 1);
         $guage->setColNum($size + 2);
         $this->pipeline[$midLine - 2][$size + 2] = $top;
         $top->setRowNum($midLine - 2);
         $top->setColNum($size + 2);
         $this->pipeline[$midLine - 2][1] = $valve;
         $valve->setRowNum($midLine - 2);
         $valve->setColNum(1);
     } else {
         $this->pipeline[$midLine + 1][$size + 2] = $top;
         $top->setRowNum($midLine + 1);
         $top->setColNum($size + 2);
         $this->pipeline[$midLine + 2][$size + 2] = $guage;
         $guage->setRowNum($midLine + 2);
         $guage->setColNum($size + 2);
         $this->pipeline[$midLine + 3][1] = $valve;
         $valve->setRowNum($midLine + 3);
         $valve->setColNum(1);
     }
     $this->updateClk();
 }
예제 #10
0
 /**
  * 
  *
  * @param int $width
  * @param int $height
  * @param ImageHandler $imageHandler
  */
 public function __construct($width, $height, ImageHandler $imageHandler)
 {
     $img = $imageHandler->createImage($width, $height);
     $color = imagecolorallocate($img, self::$backgroundColor['r'], self::$backgroundColor['g'], self::$backgroundColor['b']);
     imagefilledrectangle($img, 0, 0, $width, $height, $color);
     $crossColor = imagecolorallocate($img, self::$crossColor['r'], self::$crossColor['g'], self::$crossColor['b']);
     imageline($img, 0, 0, $width, $height, $crossColor);
     imageline($img, 0, $height, $width, 0, $crossColor);
     imageline($img, 0, 0, $width - 1, 0, $crossColor);
     imageline($img, $width - 1, 0, $width - 1, $height, $crossColor);
     imageline($img, $width - 1, $height - 1, 0, $height - 1, $crossColor);
     imageline($img, 0, $height - 1, 0, 0, $crossColor);
     $stringColor = imagecolorallocate($img, self::$stringColor['r'], self::$stringColor['g'], self::$stringColor['b']);
     imagestring($img, 2, 0, 0, self::$string, $stringColor);
     parent::__construct($img);
 }
예제 #11
0
 public function setPlayer($p1, $p2)
 {
     $this->p1 = new Player($p1, $this->size, 1);
     $this->turn = $this->p1;
     $this->p2 = new Player($p2, $this->size, 2);
     $midLine = $this->size / 2;
     $guage = new Tile("gauge-0.png", array("N" => true, "W" => true, "S" => false, "E" => false));
     $guage->setOwner($this->p1);
     $top = new Tile("gauge-top-0.png", array("N" => false, "W" => false, "S" => true, "E" => false));
     $top->setOwner($this->p1);
     $valve = new Tile("valve-closed.png", array("N" => false, "W" => false, "S" => false, "E" => true));
     $valve->setOwner($this->p1);
     $this->allPipes[$midLine - 1][$this->size + 2] = $guage;
     $guage->setRowNum($midLine - 1);
     $guage->setColNum($this->size + 2);
     $this->allPipes[$midLine - 2][$this->size + 2] = $top;
     $top->setRowNum($midLine - 2);
     $top->setColNum($this->size + 2);
     $this->allPipes[$midLine - 2][1] = $valve;
     $valve->setRowNum($midLine - 2);
     $valve->setColNum(1);
     $guage = new Tile("gauge-0.png", array("N" => true, "W" => true, "S" => false, "E" => false));
     $guage->setOwner($this->p2);
     $top = new Tile("gauge-top-0.png", array("N" => false, "W" => false, "S" => true, "E" => false));
     $top->setOwner($this->p2);
     $valve = new Tile("valve-closed.png", array("N" => false, "W" => false, "S" => false, "E" => true));
     $valve->setOwner($this->p2);
     $this->allPipes[$midLine + 1][$this->size + 2] = $top;
     $top->setRowNum($midLine + 1);
     $top->setColNum($this->size + 2);
     $this->allPipes[$midLine + 2][$this->size + 2] = $guage;
     $guage->setRowNum($midLine + 2);
     $guage->setColNum($this->size + 2);
     $this->allPipes[$midLine + 3][1] = $valve;
     $valve->setRowNum($midLine + 3);
     $valve->setColNum(1);
 }
예제 #12
0
 public function setValues()
 {
     parent::setValues();
     if (isset($this->data["data_fill"])) {
         $this->data_fill = $this->data["data_fill"];
     }
     if (isset($this->data["footer"])) {
         $this->footer = $this->data["footer"];
     }
 }
 /**
  * get map tile from its numbers
  *
  * @param int $x x number of the tile
  * @param int $y y number of the tile
  * @param int $zoom map zoom
  * @return Tile
  */
 public function getTile($x, $y, $zoom)
 {
     $tx = $x;
     $ty = $y;
     $this->_validateTileNumbers($tx, $ty, $zoom);
     if (!$this->_useTileImage) {
         $tile = new EmptyTile($this->getTileWidth(), $this->getTileHeight(), $this->_imageHandler);
     } else {
         if ($this->_useCache && $this->_tileCache->hasTile($tx, $ty, $zoom)) {
             //if tile image is in cache, take it from there
             $image = $this->_tileCache->getTile($tx, $ty, $zoom);
             $tile = new Tile($image);
         } else {
             $image = $this->_loadImage($this->_createUrl($tx, $ty, $zoom));
             if ($image === false) {
                 //when loading an image failed
                 $tile = new EmptyTile($this->getTileWidth(), $this->getTileHeight(), $this->_imageHandler);
             } else {
                 $this->_tileCache->addTile($image, $tx, $ty, $zoom);
                 $tile = new Tile($image);
             }
         }
     }
     $tile->setWorldMap($this->getWorldMap($zoom));
     $tile->setTileData($x, $y, $zoom);
     $tile->setImageHandler($this->_imageHandler);
     return $tile;
 }
예제 #14
0
 public function pairWith(Tile $tile)
 {
     if ($this->isPaired() or $tile->isPaired()) {
         return false;
     }
     $this->data["pairx"] = $tile->x;
     $this->data["pairz"] = $tile->z;
     $tile->data["pairx"] = $this->x;
     $tile->data["pairz"] = $this->z;
     $this->server->api->tile->spawnToAll($this);
     $this->server->api->tile->spawnToAll($tile);
     $this->server->handle("tile.update", $this);
     $this->server->handle("tile.update", $tile);
 }
예제 #15
0
 public function printTiles()
 {
     print '
     <div id="widget_scroll_container">';
     foreach ($this->tile_containers as $index => $tile_container) {
         print '
         <div class="widget_container ' . $tile_container['size'] . (strlen($tile_container['theme']) ? $tile_container['theme'] : '') . '" data-num="' . $index . '">';
         foreach ($tile_container['tiles'] as $tile_data) {
             $tile = new Tile();
             $tile->setName($tile_data['name']);
             $tile->setSize($tile_data['size']);
             $tile->setThumbnail($tile_data['thumbnail']);
             $tile->setContent($tile_data['content']);
             $tile->setUrl($tile_data['url']);
             $tile->setTheme($tile_data['theme']);
             $tile->setLink($tile_data['link']);
             if (isset($tile_data['colour'])) {
                 $tile->setColour($tile_data['colour']);
             }
             $tile->display();
         }
         print '
         </div>';
     }
     print '
     </div>';
 }