Пример #1
0
 public function testReset()
 {
     $celestialBodyEntity = $this->celestialBody;
     $celestialBodySpecialtiesRepository = $this->em->getRepository(CelestialBodySpecialtyEntity::class);
     /* @var $celestialBodySpecialtiesRepository CelestialBodySpecialtyRepository */
     $this->specify('Resetting a celestial body should make it suitable for new players.', function () use($celestialBodyEntity, $celestialBodySpecialtiesRepository) {
         $terrestrialPlanetModel = CelestialBodyFactory::create($celestialBodyEntity, $celestialBodySpecialtiesRepository);
         $terrestrialPlanetModel->reset();
         expect('there should be no outpost on the celestial body', $celestialBodyEntity->getOutpost())->null();
         expect('the celestial body should have one specialty', $celestialBodyEntity->getSpecialties()->count())->equals(1);
         expect('the celestial body should have a moon', $celestialBodyEntity->getSpecialties())->contains($celestialBodySpecialtiesRepository->getMoon());
         expect('building costs should be at 100%', $celestialBodyEntity->getSpecs()->getEffects()->getBuildingCost())->equals(1.0);
         expect('building time should be at 100%', $celestialBodyEntity->getSpecs()->getEffects()->getBuildingTime())->equals(1.0);
         expect('fleet scanner range should be at 100%', $celestialBodyEntity->getSpecs()->getEffects()->getFleetScannerRange())->equals(1.0);
         expect('research should be at 100%', $celestialBodyEntity->getSpecs()->getEffects()->getResearchPoints())->equals(1.0);
         expect('taxes should be at 100%', $celestialBodyEntity->getSpecs()->getEffects()->getTaxes())->equals(1.0);
         expect('gravity should be at 100%', $celestialBodyEntity->getSpecs()->getGravity())->equals(1.0);
         expect('living conditions should be at 100%', $celestialBodyEntity->getSpecs()->getLivingConditions())->equals(1.0);
         expect('chemicals should be at 100%', $celestialBodyEntity->getSpecs()->getResourceDensity()->getChemicals())->equals(1.0);
         expect('ice should be at 30%', $celestialBodyEntity->getSpecs()->getResourceDensity()->getIce())->equals(0.3);
         expect('iron should be at 100%', $celestialBodyEntity->getSpecs()->getResourceDensity()->getIron())->equals(1.0);
     });
 }
Пример #2
0
 /**
  * Selects a celestial body that should be used for a new player.
  * 
  * @todo could use a better algorithm. Maybe place new players in areas that
  *       are not too densly populated.
  *       Or place them among other players just having started playing.
  *       Currently, we simply take any celestial body that doesn't yet have
  *       an owner.
  * 
  * @return \common\models\TerrestrialPlanet
  */
 public function getTerrestrialPlanetForNewPlayer()
 {
     $celestialBodyEntity = $this->celestialBodyRepository->findForNewPlayer();
     if ($celestialBodyEntity instanceof TerrestrialPlanetEntity) {
         $terrestrialPlanetEntity = $celestialBodyEntity;
     } else {
         $this->em->detach($celestialBodyEntity);
         // This is the bad part.
         // Maybe there's a better alternative?
         $discrTerrestrialPlanet = CelestialBodyEntity::DISCR_TERRESTRIAL_PLANET;
         $query = "UPDATE celestialbody SET discr = {$discrTerrestrialPlanet} WHERE id = {$celestialBodyEntity->getId()}";
         $this->em->getConnection()->exec($query);
         // this is now a terrestrial planet
         $terrestrialPlanetEntity = $this->celestialBodyRepository->find($celestialBodyEntity->getId());
     }
     $terrestrialPlanetModel = CelestialBodyFactory::create($terrestrialPlanetEntity, $this->celestialBodySpecialtyRepository);
     $terrestrialPlanetModel->reset();
     return $terrestrialPlanetModel;
 }