public function __construct(HeightInCm $heightInCm, DistanceTable $distanceTable) { $heightInMeters = $heightInCm->getValue() / 100; /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $distance = new Distance($heightInMeters, Distance::M, $distanceTable); // height is bonus of distance in fact $this->value = $distance->getBonus()->getValue(); }
/** * @test */ public function I_can_create_distance_measurement_in_meters_or_kilometers_or_light_years() { $distanceTable = new DistanceTable(); $inKm = new Distance($value = 123, $unit = Distance::KM, $distanceTable); self::assertSame((double) $value, $inKm->getValue()); self::assertSame($unit, $inKm->getUnit()); self::assertSame((double) $value, $inKm->getKilometers()); self::assertSame((double) ($value * 1000), $inKm->getMeters()); self::assertSame(102, $inKm->getBonus()->getValue()); $inM = new Distance($value = 456, $unit = Distance::M, $distanceTable); self::assertSame((double) $value, $inM->getValue()); self::assertSame($unit, $inM->getUnit()); self::assertSame((double) $value, $inM->getMeters()); self::assertSame((double) ($value / 1000), $inM->getKilometers()); self::assertSame(53, $inM->getBonus()->getValue()); $inLightYears = new Distance($value = 1, $unit = Distance::LIGHT_YEAR, $distanceTable); self::assertSame((double) $value, $inLightYears->getValue()); self::assertSame((double) $value, $inLightYears->getLightYears()); self::assertSame($unit, $inLightYears->getUnit()); self::assertSame(319, $inLightYears->getBonus()->getValue()); }
/** * @param LightSourceCode $lightSourceCode * @param Distance $distance * @return int */ public function calculateLightingQualityInDistance(LightSourceCode $lightSourceCode, Distance $distance) { return $this->getPowerOfLightSource($lightSourceCode) - 2 * $distance->getBonus()->getValue(); }
/** * Distance modifier can be solved very roughly by a simple table or more precisely with continual values by a calculation. * This uses that calculation. * See PPH page 104 left column. * * @param EncounterRange $currentEncounterRange * @param Distance $distance * @param MaximalRange $currentMaximalRange * @return int * @throws Exceptions\DistanceIsOutOfMaximalRange * @throws Exceptions\EncounterRangeCanNotBeGreaterThanMaximalRange * @throws DistanceOutOfKnownValues */ public function getAttackNumberModifierByDistance(Distance $distance, EncounterRange $currentEncounterRange, MaximalRange $currentMaximalRange) { if ($distance->getBonus()->getValue() > $currentMaximalRange->getValue()) { // comparing distance bonuses in fact throw new Exceptions\DistanceIsOutOfMaximalRange("Given distance {$distance->getBonus()} ({$distance->getMeters()} meters)" . " is out of maximal range {$currentMaximalRange}" . ' (' . $currentMaximalRange->getInMeters($this->tables->getDistanceTable()) . ' meters)'); } if ($currentEncounterRange->getValue() > $currentMaximalRange->getValue()) { throw new Exceptions\EncounterRangeCanNotBeGreaterThanMaximalRange("Got encounter range {$currentEncounterRange} greater than given maximal range {$currentMaximalRange}"); } $attackNumberModifier = $this->tables->getContinuousAttackNumberByDistanceTable()->getAttackNumberModifierByDistance($distance); if ($distance->getBonus()->getValue() > $currentEncounterRange->getValue()) { // comparing distance bonuses in fact $attackNumberModifier += $currentEncounterRange->getValue() - $distance->getBonus()->getValue(); // always negative } return $attackNumberModifier; }
/** * @test * @expectedException \OutOfRangeException */ public function I_can_not_convert_too_high_value_to_bonus() { $distanceTable = new DistanceTable(); $distance = new Distance(901, Distance::KM, $distanceTable); $distance->getBonus(); }
/** * Gives race height as bonus of distance (height in cm). * Useful for speed and fight modifiers. * * @param RacesTable $racesTable * @param DistanceTable $distanceTable * @return int */ public function getHeight(RacesTable $racesTable, DistanceTable $distanceTable) { $heightInMeters = $this->getHeightInCm($racesTable) / 100; /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $distance = new Distance($heightInMeters, Distance::M, $distanceTable); return $distance->getBonus()->getValue(); }