/** * @param $cellIds * @param $latitude * @param $longitude * @param $altitude * @return MapObjects */ public function getMapObjectsCells($cellIds, $latitude, $longitude, $altitude) { $this->pokemonGoAPI->setLatitude((double) $latitude); $this->pokemonGoAPI->setLongitude((double) $longitude); $this->pokemonGoAPI->setAltitude((double) $altitude); if ($this->useCache && $this->pokemonGoAPI->currentTimeMillis() - $this->lastMapUpdate > $this->mapObjectsExpiry) { $this->lastMapUpdate = 0; $this->cachedMapObjects = new MapObjects($this->pokemonGoAPI); } $builder = new GetMapObjectsMessage(); $builder->setLatitude((double) $this->pokemonGoAPI->getLatitude()); $builder->setLongitude((double) $this->pokemonGoAPI->getLongitude()); $index = 0; foreach ($cellIds as $cellId) { $builder->addCellId($cellId); $builder->addSinceTimestampMs($this->lastMapUpdate); $index++; } $serverRequest = new ServerRequest(RequestType::GET_MAP_OBJECTS, $builder); $this->pokemonGoAPI->getRequestHandler()->sendServerRequests($serverRequest); $response = new GetMapObjectsResponse($serverRequest->getData()); $result = new MapObjects($this->pokemonGoAPI); foreach ($response->getMapCellsArray() as $mapCell) { $result->addNearbyPokemons($mapCell->getNearbyPokemonsArray()); $result->addCatchablePokemons($mapCell->getCatchablePokemonsArray()); $result->addWildPokemons($mapCell->getWildPokemonsArray()); $result->addDecimatedSpawnPoints($mapCell->getDecimatedSpawnPointsArray()); $result->addSpawnPoints($mapCell->getSpawnPointsArray()); foreach ($mapCell->getFortsArray() as $fort) { if ($fort->getType() == FortType::GYM) { $result->addGyms($fort); } elseif ($fort->getType() == FortType::CHECKPOINT) { $result->addPokestops($fort); } } } if ($this->useCache) { $this->cachedMapObjects->update($result); $result = $this->cachedMapObjects; $this->lastMapUpdate = $this->pokemonGoAPI->currentTimeMillis(); } return $result; }
public function update(MapObjects $other) { $this->nearbyPokemons = []; $this->addNearbyPokemons($other->getNearbyPokemons()); $this->catchablePokemons = []; $this->addCatchablePokemons($other->getCatchablePokemons()); $this->wildPokemons = []; $this->addWildPokemons($other->getWildPokemons()); $this->decimatedSpawnPoints = []; $this->addDecimatedSpawnPoints($other->getDecimatedSpawnPoints()); $this->spawnPoints = []; $this->addSpawnPoints($other->getSpawnPoints()); /* foreach($other->getGyms() as $otherGym) { foreach($this->getGyms() as $gym) { if ($otherGym->getId() == ($gym->getId())) { unset($this->gyms[$gym]); break; } } $this->gyms[] = $otherGym; } foreach($other->getPokestops() as $otherPokestop) { foreach($this->pokestops as $pokestop) { if ($otherPokestop->getId() == ($pokestop->getId())) { unset($this->pokestops[$pokestop]); break; } } $this->pokestops[] = $otherPokestop; }*/ }