/**
  * @param string $code
  * @param Percents $percents
  * @return int
  * @throws \DrdPlus\Tables\Partials\Exceptions\UnexpectedPercents
  * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType
  * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredRowNotFound
  */
 protected function getBonusBy($code, Percents $percents)
 {
     if ($percents->getValue() > 100 && !$this->canBeMore($code)) {
         throw new Exceptions\UnexpectedPercents('For ' . ValueDescriber::describe($code) . " can be percents of addition only between zero and one hundred, got {$percents}");
     }
     $bonusFrom = $this->getBonusBorder($code, self::BONUS_FROM);
     $bonusTo = $this->getBonusBorder($code, self::BONUS_TO);
     if ($bonusFrom < $bonusTo) {
         // has to swap start and end
         list($bonusFrom, $bonusTo) = [$bonusTo, $bonusFrom];
     }
     $difference = $bonusTo - $bonusFrom;
     $addition = $difference * $percents->getRate();
     $totalBonus = $bonusFrom + $addition;
     return SumAndRound::round($totalBonus);
 }
 /**
  * @param int $value
  * @throws \DrdPlus\Tables\Body\Healing\Exceptions\UnexpectedHealingConditionsPercents
  */
 public function __construct($value)
 {
     try {
         parent::__construct($value);
     } catch (UnexpectedPercents $unexpectedPercents) {
         throw new Exceptions\UnexpectedHealingConditionsPercents($unexpectedPercents->getMessage());
     }
 }
 /**
  * @param mixed $value
  * @throws \DrdPlus\Tables\Body\Resting\Exceptions\UnexpectedRestingSituationPercents
  */
 public function __construct($value)
 {
     try {
         parent::__construct($value);
     } catch (UnexpectedPercents $unexpectedPercents) {
         throw new Exceptions\UnexpectedRestingSituationPercents($unexpectedPercents->getMessage());
     }
 }
 /**
  * @param mixed $value
  * @throws \DrdPlus\Tables\Environments\Exceptions\UnexpectedDifficultyPercents
  */
 public function __construct($value)
 {
     try {
         parent::__construct($value);
     } catch (UnexpectedPercents $unexpectedPercents) {
         throw new Exceptions\UnexpectedDifficultyPercents($unexpectedPercents->getMessage());
     }
     if ($this->getValue() > 100) {
         throw new Exceptions\UnexpectedDifficultyPercents('Percents can be from zero to one hundred, got ' . ValueDescriber::describe($value));
     }
 }
 /**
  * @param mixed $value
  * @throws \DrdPlus\Tables\Equipment\Riding\Exceptions\UnexpectedDefianceOfWildPercents
  */
 public function __construct($value)
 {
     try {
         parent::__construct($value);
     } catch (UnexpectedPercents $unexpectedPercents) {
         throw new Exceptions\UnexpectedDefianceOfWildPercents($unexpectedPercents->getMessage());
     }
     if ($this->getValue() > 100) {
         throw new Exceptions\UnexpectedDefianceOfWildPercents('Expected percents of defiance for wild animal to be from zero to one hundred, got ' . ValueDescriber::describe($value));
     }
 }