/** * @param int $spentBackgroundPoints * @param Heritage $heritage * @return AbstractHeritageDependent * @throws \Granam\Integer\Tools\Exceptions\Runtime */ public static function getIt($spentBackgroundPoints, Heritage $heritage) { $spentBackgroundPoints = ToInteger::toInteger($spentBackgroundPoints); self::checkSpentBackgroundPointsLimits($spentBackgroundPoints); self::checkBackgroundPointsAgainstHeritage($spentBackgroundPoints, $heritage); return self::getEnum($spentBackgroundPoints); }
/** * @param int|IntegerInterface $value * @return AbstractIntegerProperty * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function sub($value) { $decreased = static::getIt($this->getValue() - ToInteger::toInteger($value)); $decreased->adoptHistory($this); // prepends history of predecessor return $decreased; }
protected static function checkSpentBackgroundPointsLimits($backgroundPoints) { $backgroundPoints = ToInteger::toInteger($backgroundPoints); if ($backgroundPoints < self::MIN_BACKGROUND_POINTS || $backgroundPoints > self::MAX_BACKGROUND_POINTS) { throw new UnexpectedBackgroundPoints('Spent background points has to be between ' . self::MIN_BACKGROUND_POINTS . ' and ' . self::MAX_BACKGROUND_POINTS . ", got {$backgroundPoints}"); } }
/** * @param int $hoursPerDay * @return int * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\UnexpectedHoursPerDayForTimeBonusAdjustment * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredColumnNotFound * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ private function getBonusAdjustmentForHoursPerDay($hoursPerDay) { try { return $this->getValue([ToInteger::toInteger($hoursPerDay)], self::ADJUSTMENT_HEADER); } catch (RequiredRowNotFound $requiredRowDataNotFound) { throw new Exceptions\UnexpectedHoursPerDayForTimeBonusAdjustment('Expected 1 to 24 hours of activity per day, got ' . ValueDescriber::describe($hoursPerDay) . ' From what universe you came from?'); } }
/** * @param int|IntegerInterface $value * @return AbstractDerivedProperty * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function sub($value) { $decreased = clone $this; // clones history as well $decreased->value -= ToInteger::toInteger($value); $decreased->noticeChange(); return $decreased; }
/** * @param int $rideValue * @throws \DrdPlus\Tables\Equipment\Riding\Exceptions\InvalidRideValue * @throws \Granam\Integer\Exceptions\PositiveIntegerCanNotBeNegative */ public function __construct($rideValue) { try { $this->rideValue = ToInteger::toInteger($rideValue); } catch (ToIntegerException $toIntegerException) { throw new Exceptions\InvalidRideValue($toIntegerException->getMessage()); } }
/** * @return float|int * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function getValue() { if ($this->getUnit() === self::ROUND) { // only rounds are always integer return ToInteger::toInteger(parent::getValue()); } return parent::getValue(); }
/** * @param int $simplifiedBonus * @return WeightBonus * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast * @throws \DrdPlus\Tables\Measurements\Partials\Exceptions\BonusRequiresInteger */ public function getBonusFromSimplifiedBonus($simplifiedBonus) { try { return $this->createBonus(ToInteger::toInteger($simplifiedBonus) + 12); } catch (\Granam\Integer\Tools\Exceptions\WrongParameterType $exception) { throw new BonusRequiresInteger($exception->getMessage()); } }
/** * @param int $value * @throws \DrdPlus\Tables\Measurements\Partials\Exceptions\BonusRequiresInteger */ protected function __construct($value) { try { $this->value = ToInteger::toInteger($value); } catch (\Granam\Integer\Tools\Exceptions\WrongParameterType $exception) { throw new Exceptions\BonusRequiresInteger($exception->getMessage()); } }
/** * @param int|IntegerInterface $skillRank * @param string $parameterName * @return int * @throws \DrdPlus\Tables\Armaments\Partials\Exceptions\UnexpectedSkillRank * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredColumnNotFound */ protected function getValueForSkillRank($skillRank, $parameterName) { try { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return $this->getValue([ToInteger::toInteger($skillRank)], $parameterName); } catch (RequiredRowNotFound $requiredRowNotFound) { throw new Exceptions\UnexpectedSkillRank('Expected skill rank from 0 to 3, got ' . ValueDescriber::describe($skillRank)); } }
/** * @param mixed $value * @throws \DrdPlus\Tables\Partials\Exceptions\UnexpectedPercents */ public function __construct($value) { try { $value = ToInteger::toInteger($value); } catch (ToIntegerException $toIntegerException) { throw new Exceptions\UnexpectedPercents('Invalid percent value ' . $toIntegerException->getMessage()); } if ($value < 0) { throw new Exceptions\UnexpectedPercents('Percents can be from zero to one hundred, got ' . ValueDescriber::describe($value)); } $this->value = $value; }
/** * @param int|IntegerInterface $missingStrength * @return array|mixed[]; * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function getSanctionsForMissingStrength($missingStrength) { $missingStrength = ToInteger::toInteger($missingStrength); $currentRow = []; foreach ($this->getIndexedValues() as $currentRow) { if ($currentRow[self::MISSING_STRENGTH] >= $missingStrength) { return $currentRow; // rows are ordered from lowest to highest missing strength } } return $currentRow; // row with highest missing strength is the last }
/** * @param int $missingStrength * @param AthleticsInterface $athletics * @return array * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast * @throws \DrdPlus\Tables\Body\FatigueByLoad\Exceptions\OverloadedAndCanNotMove */ private function getRowFittingToMissingStrength($missingStrength, AthleticsInterface $athletics) { $missingStrength = ToInteger::toInteger($missingStrength) - $athletics->getAthleticsBonus()->getValue(); $usedMaximalMissingStrength = false; $desiredRow = []; foreach ($this->getIndexedValues() as $maximalMissingStrength => $row) { if ($maximalMissingStrength >= $missingStrength && ($usedMaximalMissingStrength === false || $usedMaximalMissingStrength > $maximalMissingStrength)) { $desiredRow = $row; $usedMaximalMissingStrength = $maximalMissingStrength; } } if (!$desiredRow) { // overload is so big so person can not move throw new Exceptions\OverloadedAndCanNotMove("Missing strength {$missingStrength} causes overload so the being can not move at all" . ($athletics->getAthleticsBonus()->getValue() > 0 ? " even with athletics {$athletics->getAthleticsBonus()}" : '')); } return $desiredRow; }
/** * @param int|string|float|IntegerInterface $value * @return int * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ protected function sanitizeValue($value) { return ToInteger::toInteger($value); }
/** * @param int|IntegerInterface $bonus * @return int */ public function tenMinifyBonus($bonus) { // see PPH page 72, left column /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return ToInteger::toInteger($bonus) - 20; }
/** * @param IntegerInterface|int $size * @return DistanceBonus * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ public function sizeToDistanceBonus($size) { return $this->createBonus(ToInteger::toInteger($size) + 12); }
/** * @param $value * @return int * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ private function parseBonus($value) { return ToInteger::toInteger($this->parseNumber($value)); }
private function normalizeValueForType($value, $type) { $value = trim($value); switch ($type) { case self::BOOLEAN: return ToBoolean::toBoolean($value, false); case self::INTEGER: return $value === '' ? false : ToInteger::toInteger($this->normalizeMinus($value)); case self::POSITIVE_INTEGER: return $value === '' ? false : ToInteger::toPositiveInteger($this->normalizeMinus($value)); case self::NEGATIVE_INTEGER: return $value === '' ? false : ToInteger::toNegativeInteger($this->normalizeMinus($value)); case self::FLOAT: return $value === '' ? false : ToFloat::toFloat($this->normalizeMinus($value)); default: // string return $value; } }
/** * @param mixed $value * * @return int */ protected function normalizeValue($value) { return ToInteger::toInteger($value); }
/** * @return int */ public function getValue() { // turning float to integer (without value lost) /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return ToInteger::toInteger(parent::getValue()); }