/** * 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; }
/** * See PPH page 95 left column. * * @param EncounterRange $encounterRange * @return MaximalRange */ public static function createForRangedWeapon(EncounterRange $encounterRange) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return new static($encounterRange->getValue() + 12); }