Beispiel #1
0
 /**
  * @param Session $session
  * @param FortData $data
  */
 public function __construct(Session $session, FortData $data)
 {
     if (!is_null($data->getType()) && $data->getType() != FortType::GYM()) {
         throw new InvalidArgumentException("Fort not a gym");
     }
     parent::__construct($session, $data);
     // TODO: team color
     // TODO: highest cp pokemon
     // TODO: xp
     // TODO: in battle
 }
 /**
  * @param bool $defaults
  * @throws Exception
  */
 public function execute($defaults = true)
 {
     $this->pokestops = [];
     $this->gyms = [];
     $this->wildPokemons = [];
     parent::execute($defaults);
     $resp = $this->getResponse();
     if ($resp->getStatus() != MapObjectsStatus::SUCCESS() || !$resp->hasMapCellsList()) {
         throw new Exception("Unable to retrieve map objects");
     }
     $mapCells = $resp->getMapCellsList();
     foreach ($mapCells as $mapCell) {
         /** @var MapCell $mapCell */
         if ($mapCell->hasFortsList()) {
             $forts = $mapCell->getFortsList();
             foreach ($forts as $fort) {
                 /** @var FortData $fort */
                 $fortType = $fort->getType();
                 $fortId = $fort->getId();
                 if (is_null($fortType) || $fortType == FortType::GYM()) {
                     if (!isset($this->gyms[$fortId])) {
                         $this->gyms[$fortId] = new Gym($this->session, $fort);
                     }
                 } elseif ($fortType == FortType::CHECKPOINT()) {
                     if (!isset($this->pokestops[$fortId])) {
                         $this->pokestops[$fortId] = new Pokestop($this->session, $fort);
                     }
                 }
             }
         }
         if ($mapCell->hasWildPokemonsList()) {
             $wildPokemons = $mapCell->getWildPokemonsList();
             foreach ($wildPokemons as $wildPokemon) {
                 $this->wildPokemons[] = new WildPokemon($wildPokemon);
             }
         }
     }
 }