/** * @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; }
/** * @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); }
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)); } }
/** * Applicable to lower shield Restriction (Fight number malus), but can not make it positive. * * @param MissingShieldSkillTable $missingShieldSkillsTable * @param int $shieldRestriction * @return int * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast * @throws \Granam\Integer\Tools\Exceptions\NegativeIntegerCanNotBePositive */ public function getRestrictionWithShield(MissingShieldSkillTable $missingShieldSkillsTable, $shieldRestriction) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $malusFromRestriction = ToInteger::toNegativeInteger($shieldRestriction) + $missingShieldSkillsTable->getRestrictionBonusForSkill($this->getCurrentSkillRank()->getValue()); if ($malusFromRestriction > 0) { return 0; // skill can lower the malus, but can not give bonus } return $malusFromRestriction; }
/** * @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; }
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 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 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 $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)); }
/** * You can pay by a level (by its property adjustment respectively) or by two another skill points * (for example combined and psychical for a new physical). * * @param int $skillPointValue zero or one * @param ProfessionLevel $professionLevel * @param Tables|null $tables = null * @param BackgroundSkillPoints|null $backgroundSkillPoints = null * @param SkillPoint $firstPaidOtherSkillPoint = null * @param SkillPoint $secondPaidOtherSkillPoint = null * @throws \DrdPlus\Skills\Exceptions\UnexpectedSkillPointValue * @throws \DrdPlus\Skills\Exceptions\UnknownPaymentForSkillPoint * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ protected function __construct($skillPointValue, ProfessionLevel $professionLevel, Tables $tables = null, BackgroundSkillPoints $backgroundSkillPoints = null, SkillPoint $firstPaidOtherSkillPoint = null, SkillPoint $secondPaidOtherSkillPoint = null) { try { $skillPointValue = ToInteger::toPositiveInteger($skillPointValue); } catch (PositiveIntegerCanNotBeNegative $positiveIntegerCanNotBeNegative) { throw new Exceptions\UnexpectedSkillPointValue('Expected zero or one, got ' . ValueDescriber::describe($skillPointValue)); } if ($professionLevel instanceof ProfessionFirstLevel) { $this->professionFirstLevel = $professionLevel; } if ($professionLevel instanceof ProfessionNextLevel) { $this->professionNextLevel = $professionLevel; } $this->checkSkillPointPayment($skillPointValue, $tables, $this->professionFirstLevel, $this->professionNextLevel, $backgroundSkillPoints, $firstPaidOtherSkillPoint, $secondPaidOtherSkillPoint); $this->value = $skillPointValue; $this->backgroundSkillPoints = $backgroundSkillPoints; $this->firstPaidOtherSkillPoint = $firstPaidOtherSkillPoint; $this->secondPaidOtherSkillPoint = $secondPaidOtherSkillPoint; }
/** * @param int $skillRank * @return array * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredRowNotFound * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType */ public function getMalusesForWeaponSkill($skillRank) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return $this->getRow([ToInteger::toPositiveInteger($skillRank)]); }
/** * @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()); }