Beispiel #1
0
 /**
  * @param SystemEntity $systemEntity
  * @return \common\entities\CelestialBody
  * @throws \yii\base\InvalidValueException
  */
 private function createCelestialBody(SystemEntity $systemEntity)
 {
     $galaxyModel = new GalaxyModel($systemEntity->getGalaxy());
     $allowedCelestialBodyTypes = $galaxyModel->getAllowedCelestialBodyTypes();
     $celestialBodyTypeIndex = rand(0, count($allowedCelestialBodyTypes) - 1);
     $celestialBodyType = $allowedCelestialBodyTypes[$celestialBodyTypeIndex];
     switch ($celestialBodyType) {
         case CelestialBodyEntity::DISCR_ASTEROID:
             $celestialBody = new AsteroidEntity();
             break;
         case CelestialBodyEntity::DISCR_ELECTRICITY_STORM:
             $celestialBody = new ElectricityStormEntity();
             break;
         case CelestialBodyEntity::DISCR_GAS_GIANT:
             $celestialBody = new GasGiantEntity();
             break;
         case CelestialBodyEntity::DISCR_GRAVIMETRIC_ANOMALY:
             $celestialBody = new GravimetricAnomalyEntity();
             break;
         case CelestialBodyEntity::DISCR_ICE_GIANT:
             $celestialBody = new IceGiantEntity();
             break;
         case CelestialBodyEntity::DISCR_ION_STORM:
             $celestialBody = new IonStormEntity();
             break;
         case CelestialBodyEntity::DISCR_SPATIAL_DISTORTION:
             $celestialBody = new SpatialDistortionEntity();
             break;
         case CelestialBodyEntity::DISCR_TERRESTRIAL_PLANET:
             $celestialBody = new TerrestrialPlanetEntity();
             break;
         case CelestialBodyEntity::DISCR_VOID:
             $celestialBody = new VoidEntity();
             break;
         default:
             throw new \yii\base\InvalidValueException("Can't create celestial body of type '{$celestialBodyType}'.");
     }
     return $celestialBody;
 }