/** * @test * @return WoundBoundary */ public function I_can_get_property_easily() { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $woundsLimit = new WoundBoundary(new Toughness(Strength::getIt($strength = 6), RaceCode::getIt(RaceCode::DWARF), SubRaceCode::getIt(SubRaceCode::MOUNTAIN), new RacesTable()), new WoundsTable()); self::assertSame(22, $woundsLimit->getValue()); return $woundsLimit; }
/** * @test * @return FatigueBoundary */ public function I_can_get_property_easily() { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $fatigueLimit = new FatigueBoundary(new Endurance(Strength::getIt($strength = 1), Will::getIt($will = 2)), new FatigueTable(new WoundsTable())); self::assertSame((int) round(($strength + $will) / 2) + 10, $fatigueLimit->getValue()); return $fatigueLimit; }
/** * @test * @expectedException \DrdPlus\Person\ProfessionLevels\Exceptions\InvalidZeroLevelRank * @expectedExceptionMessageRegExp ~[^\d]0[^\d]~ */ public function I_can_not_create_it_with_higher_level_thank_zero() { $professionZeroLevel = ProfessionZeroLevel::createZeroLevel($commoner = Commoner::getIt()); $reflection = new \ReflectionClass(ProfessionZeroLevel::class); /** @see \DrdPlus\Person\ProfessionLevels\ProfessionLevel::__construct */ $constructor = $reflection->getMethod('__construct'); $constructor->setAccessible(true); $constructor->invokeArgs($professionZeroLevel, [$commoner, LevelRank::getIt(1), Strength::getIt(0), Agility::getIt(0), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(0), Charisma::getIt(0)]); }
public function __construct(ProfessionLevels $professionLevels) { $this->nextLevelsStrength = Strength::getIt($professionLevels->getNextLevelsStrengthModifier()); $this->nextLevelsAgility = Agility::getIt($professionLevels->getNextLevelsAgilityModifier()); $this->nextLevelsKnack = Knack::getIt($professionLevels->getNextLevelsKnackModifier()); $this->nextLevelsWill = Will::getIt($professionLevels->getNextLevelsWillModifier()); $this->nextLevelsIntelligence = Intelligence::getIt($professionLevels->getNextLevelsIntelligenceModifier()); $this->nextLevelsCharisma = Charisma::getIt($professionLevels->getNextLevelsCharismaModifier()); }
/** * @test */ public function I_can_create_it() { $zeroLevel = $this->createZeroLevel(); $firstLevel = $this->createFirstLevel('fighter'); $withFirstLevelOnly = new ProfessionLevels($zeroLevel, $firstLevel); self::assertNotNull($withFirstLevelOnly); $anotherInstance = ProfessionLevels::createIt($zeroLevel, $firstLevel); self::assertEquals($withFirstLevelOnly, $anotherInstance); $yetAnotherInstance = ProfessionLevels::createIt($zeroLevel, $firstLevel); self::assertNotSame($anotherInstance, $yetAnotherInstance); $withExplicitlyEmptyNextLevels = ProfessionLevels::createIt($zeroLevel, $firstLevel, []); self::assertEquals($withFirstLevelOnly, $withExplicitlyEmptyNextLevels); $withNextLevels = ProfessionLevels::createIt($zeroLevel, $firstLevel, $nextLevels = [ProfessionNextLevel::createNextLevel(Fighter::getIt(), LevelRank::getIt(2), Strength::getIt(1), Agility::getIt(0), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(1), Charisma::getIt(0))]); self::assertNotEquals($withFirstLevelOnly, $withNextLevels); }
/** * @param string $propertyCodeTooHigh * * @test * @dataProvider providePropertyCodeOneByOne * @expectedException \DrdPlus\Person\ProfessionLevels\Exceptions\TooHighNextLevelPropertyIncrement */ public function I_can_not_create_next_level_with_too_high_property_increment($propertyCodeTooHigh) { ProfessionNextLevel::createNextLevel($this->createProfession(ProfessionCode::FIGHTER), $levelRank = LevelRank::getIt(2), Strength::getIt($propertyCodeTooHigh === Strength::STRENGTH ? 2 : 0), Agility::getIt($propertyCodeTooHigh === Agility::AGILITY ? 2 : 0), Knack::getIt($propertyCodeTooHigh === Knack::KNACK ? 2 : 0), Will::getIt($propertyCodeTooHigh === Will::WILL ? 2 : 0), Intelligence::getIt($propertyCodeTooHigh === Intelligence::INTELLIGENCE ? 2 : 0), Charisma::getIt($propertyCodeTooHigh === Charisma::CHARISMA ? 2 : 0)); }
/** * @param Race $race * @param GenderCode $genderCode * @param ExceptionalityProperties $exceptionalityProperties * @param ProfessionLevels $professionLevels * @param WeightInKg $weightInKgAdjustment * @param HeightInCm $heightInCm * @param Age $age * @param Tables $tables * @throws Exceptions\TooLowStrengthAdjustment */ public function __construct(Race $race, GenderCode $genderCode, ExceptionalityProperties $exceptionalityProperties, ProfessionLevels $professionLevels, WeightInKg $weightInKgAdjustment, HeightInCm $heightInCm, Age $age, Tables $tables) { $this->firstLevelProperties = new FirstLevelProperties($race, $genderCode, $exceptionalityProperties, $professionLevels, $weightInKgAdjustment, $heightInCm, $age, $tables); $this->nextLevelsProperties = new NextLevelsProperties($professionLevels); $this->strength = Strength::getIt($this->firstLevelProperties->getFirstLevelStrength()->getValue() + $this->nextLevelsProperties->getNextLevelsStrength()->getValue()); $this->agility = Agility::getIt($this->firstLevelProperties->getFirstLevelAgility()->getValue() + $this->nextLevelsProperties->getNextLevelsAgility()->getValue()); $this->knack = Knack::getIt($this->firstLevelProperties->getFirstLevelKnack()->getValue() + $this->nextLevelsProperties->getNextLevelsKnack()->getValue()); $this->will = Will::getIt($this->firstLevelProperties->getFirstLevelWill()->getValue() + $this->nextLevelsProperties->getNextLevelsWill()->getValue()); $this->intelligence = Intelligence::getIt($this->firstLevelProperties->getFirstLevelIntelligence()->getValue() + $this->nextLevelsProperties->getNextLevelsIntelligence()->getValue()); $this->charisma = Charisma::getIt($this->firstLevelProperties->getFirstLevelCharisma()->getValue() + $this->nextLevelsProperties->getNextLevelsCharisma()->getValue()); // delivered properties $this->toughness = new Toughness($this->getStrength(), $race->getRaceCode(), $race->getSubraceCode(), $tables->getRacesTable()); $this->endurance = new Endurance($this->getStrength(), $this->getWill()); $this->speed = new Speed($this->getStrength(), $this->getAgility(), $this->getHeight()); $this->senses = new Senses($this->getKnack(), RaceCode::getIt($race->getRaceCode()), SubRaceCode::getIt($race->getSubraceCode()), $tables->getRacesTable()); // aspects of visage $this->beauty = new Beauty($this->getAgility(), $this->getKnack(), $this->getCharisma()); $this->dangerousness = new Dangerousness($this->getStrength(), $this->getWill(), $this->getCharisma()); $this->dignity = new Dignity($this->getIntelligence(), $this->getWill(), $this->getCharisma()); /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $this->fightNumber = new FightNumber(ProfessionCode::getIt($professionLevels->getFirstLevel()->getProfession()->getValue()), $this, $this->getHeight()); $this->attack = new Attack($this->getAgility()); $this->shooting = new Shooting($this->getKnack()); $this->defenseNumber = new DefenseNumber($this->getAgility()); $this->defenseAgainstShooting = new DefenseNumberAgainstShooting($this->getDefenseNumber(), $this->getSize()); $this->woundsLimit = new WoundBoundary($this->getToughness(), $tables->getWoundsTable()); $this->fatigueLimit = new FatigueBoundary($this->getEndurance(), $tables->getFatigueTable()); }
public static function createSkillsEntity(Tables $tables) { return Skills::createSkills(ProfessionLevels::createIt(ProfessionFirstLevel::createFirstLevel($profession = Fighter::getIt()), [ProfessionNextLevel::createNextLevel($profession, LevelRank::getIt(2), Strength::getIt(0), Agility::getIt(1), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(1), Charisma::getIt(0))]), BackgroundSkillPoints::getIt(2, Heritage::getIt(7)), $tables, new PhysicalSkills(), new PsychicalSkills(), new CombinedSkills()); }
/** * @param Commoner $commoner * @param \DateTimeImmutable|null $levelUpAt * @return ProfessionZeroLevel * @throws Exceptions\InvalidZeroLevelRank */ public static function createZeroLevel(Commoner $commoner, \DateTimeImmutable $levelUpAt = null) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return new static($commoner, new LevelRank(0), Strength::getIt(0), Agility::getIt(0), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(0), Charisma::getIt(0), $levelUpAt); }
/** * @param Strength $strength * @param Will $will */ public function __construct(Strength $strength, Will $will) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ parent::__construct(SumAndRound::average($strength->getValue(), $will->getValue())); }
/** * @test */ public function I_can_get_base_of_wounds_for_used_weapon_with_current_strength() { $axe = $this->createMeleeWeaponCode('foo', 'axe'); $currentStrength = Strength::getIt(123); $tables = $this->createTables(); $tables->shouldReceive('getWeaponlikeTableByWeaponlikeCode')->with($axe)->andReturn($meleeWeaponlikesTable = $this->createMeleeWeaponlikesTable()); $meleeWeaponlikesTable->shouldReceive('getWoundsOf')->with($axe)->andReturn(789); $tables->shouldReceive('getBaseOfWoundsTable')->andReturn($baseOfWoundsTable = $this->mockery(BaseOfWoundsTable::class)); $baseOfWoundsTable->shouldReceive('calculateBaseOfWounds')->with(789, $currentStrength)->andReturn(456); $tables->shouldReceive('getWeaponlikeStrengthSanctionsTableByCode')->andReturn($meleeWeaponSanctionsTable = $this->createMeleeWeaponSanctionsTable()); $tables->shouldReceive('getArmamentsTableByArmamentCode')->with($axe)->andReturn($meleeWeaponlikesTable); $meleeWeaponlikesTable->shouldReceive('getRequiredStrengthOf')->with($axe)->andReturn(555); $meleeWeaponSanctionsTable->shouldReceive('getBaseOfWoundsSanction')->with(555 - 123)->andReturn(234); self::assertSame(456 + 234, (new Armourer($tables))->getBaseOfWoundsUsingWeaponlike($axe, $currentStrength)); }
private function sumProperties(Strength $strengthIncrement, Agility $agilityIncrement, Knack $knackIncrement, Will $willIncrement, Intelligence $intelligenceIncrement, Charisma $charismaIncrement) { return $strengthIncrement->getValue() + $agilityIncrement->getValue() + $knackIncrement->getValue() + $willIncrement->getValue() + $intelligenceIncrement->getValue() + $charismaIncrement->getValue(); }
/** * @param Profession $profession * @param \DateTimeImmutable|null $levelUpAt * @return ProfessionFirstLevel * @throws \DrdPlus\Person\ProfessionLevels\Exceptions\InvalidFirstLevelPropertyValue */ public static function createFirstLevel(Profession $profession, \DateTimeImmutable $levelUpAt = null) { return new static($profession, new LevelRank(1), Strength::getIt(self::getBasePropertyFirstLevelModifier(Strength::STRENGTH, $profession)), Agility::getIt(self::getBasePropertyFirstLevelModifier(Agility::AGILITY, $profession)), Knack::getIt(self::getBasePropertyFirstLevelModifier(Knack::KNACK, $profession)), Will::getIt(self::getBasePropertyFirstLevelModifier(Will::WILL, $profession)), Intelligence::getIt(self::getBasePropertyFirstLevelModifier(Intelligence::INTELLIGENCE, $profession)), Charisma::getIt(self::getBasePropertyFirstLevelModifier(Charisma::CHARISMA, $profession)), $levelUpAt); }
/** * Affects activities using strength, agility or knack, see PPH page 113, right column, bottom. * @param Strength $strength * @param Weight $cargoWeight * @return int negative number or zero * @throws \DrdPlus\Tables\Measurements\Partials\Exceptions\BonusRequiresInteger */ public function getMalusFromLoad(Strength $strength, Weight $cargoWeight) { $requiredStrength = $cargoWeight->getBonus()->getValue(); $missingStrength = $requiredStrength - $strength->getValue(); $malus = -SumAndRound::half($missingStrength); // see PPH page 113, right column if ($malus > 0) { return 0; } return $malus; }
/** * @param int|IntegerInterface $strengthValue * @return Strength */ public function createStrength($strengthValue) { return Strength::getIt($strengthValue); }
/** * @return int 0+ */ public function getStrengthLossBecauseOfLimit() { return $this->firstLevelUnlimitedStrength->getValue() - $this->getFirstLevelStrength()->getValue(); }
/** * @param Strength $strength * @param RaceCode $raceCode * @param SubRaceCode $subraceCode * @param RacesTable $racesTable */ public function __construct(Strength $strength, RaceCode $raceCode, SubRaceCode $subraceCode, RacesTable $racesTable) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ parent::__construct($strength->getValue() + $racesTable->getToughness($raceCode, $subraceCode)); }
/** * See PPH page 91, right column * * @param ArmamentCode $armamentCode * @param Size $bodySize * @param Strength $currentStrength * @return int positive number * @throws \DrdPlus\Tables\Armaments\Exceptions\UnknownArmament */ public function getMissingStrengthForArmament(ArmamentCode $armamentCode, Strength $currentStrength, Size $bodySize) { $requiredStrength = $this->tables->getArmamentsTableByArmamentCode($armamentCode)->getRequiredStrengthOf($armamentCode); $missingStrength = $requiredStrength - $currentStrength->getValue(); if ($armamentCode instanceof ArmorCode) { // only armor weight is related to body size $missingStrength += $bodySize->getValue(); } if ($missingStrength < 0) { // missing strength can not be negative, of course return 0; } return $missingStrength; }
/** * @param ExceptionalityFate $fate * @param ProfessionLevel $professionLevel * @param int $chosenStrengthValue * @param int $chosenAgilityValue * @param int $chosenKnackValue * @param int $chosenWillValue * @param int $chosenIntelligenceValue * @param int $chosenCharismaValue * @return ChosenProperties */ public function createChosenProperties(ExceptionalityFate $fate, ProfessionLevel $professionLevel, $chosenStrengthValue, $chosenAgilityValue, $chosenKnackValue, $chosenWillValue, $chosenIntelligenceValue, $chosenCharismaValue) { $this->checkChosenProperties($chosenStrength = Strength::getIt($chosenStrengthValue), $chosenAgility = Agility::getIt($chosenAgilityValue), $chosenKnack = Knack::getIt($chosenKnackValue), $chosenWill = Will::getIt($chosenWillValue), $chosenIntelligence = Intelligence::getIt($chosenIntelligenceValue), $chosenCharisma = Charisma::getIt($chosenCharismaValue), $professionLevel, $fate); return new ChosenProperties($chosenStrength, $chosenAgility, $chosenKnack, $chosenWill, $chosenIntelligence, $chosenCharisma); }
/** * @return array */ public static function createEntities() { $professionLevels = new ProfessionLevels(ProfessionZeroLevel::createZeroLevel(Commoner::getIt()), ProfessionFirstLevel::createFirstLevel($profession = Theurgist::getIt())); $professionLevels->addLevel(ProfessionNextLevel::createNextLevel($profession, LevelRank::getIt(2), Strength::getIt(1), Agility::getIt(0), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(1), Charisma::getIt(0))); return [ProfessionZeroLevel::createZeroLevel(Commoner::getIt()), ProfessionFirstLevel::createFirstLevel(Fighter::getIt()), ProfessionNextLevel::createNextLevel(Wizard::getIt(), LevelRank::getIt(2), Strength::getIt(1), Agility::getIt(1), Knack::getIt(0), Will::getIt(0), Intelligence::getIt(0), Charisma::getIt(0)), $professionLevels]; }
/** * @test * @dataProvider getCombination * * @param Race $race * @param GenderCode $genderCode * @param ExceptionalityProperties $exceptionalityProperties * @param ProfessionLevels $professionLevels * @param Tables $tables * @param WeightInKg $weightInKgAdjustment * @param HeightInCm $heightInCmAdjustment * @param Age $age * @param int $expectedStrength * @param int $expectedAgility * @param int $expectedKnack * @param int $expectedWill * @param int $expectedIntelligence * @param int $expectedCharisma */ public function I_can_create_properties_for_any_combination(Race $race, GenderCode $genderCode, ExceptionalityProperties $exceptionalityProperties, ProfessionLevels $professionLevels, Tables $tables, WeightInKg $weightInKgAdjustment, HeightInCm $heightInCmAdjustment, Age $age, $expectedStrength, $expectedAgility, $expectedKnack, $expectedWill, $expectedIntelligence, $expectedCharisma) { $properties = new PropertiesByLevels($race, $genderCode, $exceptionalityProperties, $professionLevels, $weightInKgAdjustment, $heightInCmAdjustment, $age, $tables); self::assertInstanceOf(FirstLevelProperties::class, $properties->getFirstLevelProperties()); self::assertInstanceOf(NextLevelsProperties::class, $properties->getNextLevelsProperties()); self::assertSame($expectedStrength, $properties->getStrength()->getValue(), "{$race} {$genderCode}"); self::assertSame($expectedAgility, $properties->getAgility()->getValue(), "{$race} {$genderCode}"); self::assertSame($expectedKnack, $properties->getKnack()->getValue(), "{$race} {$genderCode}"); self::assertSame($expectedWill, $properties->getWill()->getValue(), "{$race} {$genderCode}"); self::assertSame($expectedIntelligence, $properties->getIntelligence()->getValue(), "{$race} {$genderCode}"); self::assertSame($expectedCharisma, $properties->getCharisma()->getValue(), "{$race} {$genderCode}"); self::assertSame($weightInKgAdjustment, $properties->getWeightInKgAdjustment()); self::assertGreaterThan($weightInKgAdjustment->getValue(), $properties->getWeightInKg()->getValue(), "{$race} {$genderCode}"); self::assertSame($heightInCmAdjustment, $properties->getHeightInCmAdjustment()); self::assertGreaterThan($heightInCmAdjustment->getValue(), $properties->getHeightInCm()->getValue(), "{$race} {$genderCode}"); self::assertEquals($expectedHeight = new Height($properties->getHeightInCm(), $tables->getDistanceTable()), $properties->getHeight()); self::assertSame($age, $properties->getAge()); $expectedToughness = new Toughness(Strength::getIt($expectedStrength), $race->getRaceCode(), $race->getSubraceCode(), $tables->getRacesTable()); self::assertInstanceOf(Toughness::class, $properties->getToughness()); self::assertSame($expectedToughness->getValue(), $properties->getToughness()->getValue(), "{$race} {$genderCode}"); $expectedEndurance = new Endurance(Strength::getIt($expectedStrength), Will::getIt($expectedWill)); self::assertInstanceOf(Endurance::class, $properties->getEndurance()); self::assertSame($expectedEndurance->getValue(), $properties->getEndurance()->getValue(), "{$race} {$genderCode}"); $expectedSize = Size::getIt($race->getSize($genderCode, $tables) + 1); /* size bonus by strength */ self::assertInstanceOf(Size::class, $properties->getSize(), "{$race} {$genderCode}"); self::assertSame($expectedSize->getValue(), $properties->getSize()->getValue(), "{$race} {$genderCode}"); $expectedSpeed = new Speed(Strength::getIt($expectedStrength), Agility::getIt($expectedAgility), $expectedHeight); self::assertInstanceOf(Speed::class, $properties->getSpeed(), "{$race} {$genderCode}"); self::assertSame($expectedSpeed->getValue(), $properties->getSpeed()->getValue(), "{$race} {$genderCode}"); $expectedSenses = new Senses(Knack::getIt($expectedKnack), RaceCode::getIt($race->getRaceCode()), SubRaceCode::getIt($race->getSubraceCode()), $tables->getRacesTable()); self::assertInstanceOf(Senses::class, $properties->getSenses()); self::assertSame($expectedSenses->getValue(), $properties->getSenses()->getValue(), "{$race} {$genderCode}"); $expectedBeauty = new Beauty(Agility::getIt($expectedAgility), Knack::getIt($expectedKnack), Charisma::getIt($expectedCharisma)); self::assertInstanceOf(Beauty::class, $properties->getBeauty()); self::assertSame($expectedBeauty->getValue(), $properties->getBeauty()->getValue(), "{$race} {$genderCode}"); $expectedDangerousness = new Dangerousness(Strength::getIt($expectedStrength), Will::getIt($expectedWill), Charisma::getIt($expectedCharisma)); self::assertInstanceOf(Dangerousness::class, $properties->getDangerousness()); self::assertSame($expectedDangerousness->getValue(), $properties->getDangerousness()->getValue(), "{$race} {$genderCode}"); $expectedDignity = new Dignity(Intelligence::getIt($expectedIntelligence), Will::getIt($expectedWill), Charisma::getIt($expectedCharisma)); self::assertInstanceOf(Dignity::class, $properties->getDignity()); self::assertSame($expectedDignity->getValue(), $properties->getDignity()->getValue(), "{$race} {$genderCode}"); $expectedFightValue = $expectedAgility + (SumAndRound::ceil($expectedHeight->getValue() / 3) - 2); self::assertInstanceOf(FightNumber::class, $properties->getFightNumber()); self::assertSame($expectedFightValue, $properties->getFightNumber()->getValue(), "{$race} {$genderCode} with height {$expectedHeight}"); $expectedAttack = new Attack(Agility::getIt($expectedAgility)); self::assertInstanceOf(Attack::class, $properties->getAttack()); self::assertSame($expectedAttack->getValue(), $properties->getAttack()->getValue(), "{$race} {$genderCode}"); $expectedShooting = new Shooting(Knack::getIt($expectedKnack)); self::assertInstanceOf(Shooting::class, $properties->getShooting()); self::assertSame($expectedShooting->getValue(), $properties->getShooting()->getValue(), "{$race} {$genderCode}"); $expectedDefense = new DefenseNumber(Agility::getIt($expectedAgility)); self::assertInstanceOf(DefenseNumber::class, $properties->getDefenseNumber()); self::assertSame($expectedDefense->getValue(), $properties->getDefenseNumber()->getValue(), "{$race} {$genderCode}"); $expectedDefenseAgainstShooting = new DefenseNumberAgainstShooting($expectedDefense, $expectedSize); self::assertInstanceOf(DefenseNumberAgainstShooting::class, $properties->getDefenseAgainstShooting()); self::assertSame($expectedDefenseAgainstShooting->getValue(), $properties->getDefenseAgainstShooting()->getValue(), "{$race} {$genderCode}"); $expectedWoundBoundary = new WoundBoundary($expectedToughness, $tables->getWoundsTable()); self::assertInstanceOf(WoundBoundary::class, $properties->getWoundBoundary()); self::assertSame($expectedWoundBoundary->getValue(), $properties->getWoundBoundary()->getValue()); $expectedFatigueBoundary = new FatigueBoundary($expectedEndurance, $tables->getFatigueTable()); self::assertInstanceOf(FatigueBoundary::class, $properties->getFatigueBoundary()); self::assertSame($expectedFatigueBoundary->getValue(), $properties->getFatigueBoundary()->getValue()); }
/** * @param Strength $strength * @param Agility $agility * @param Height $height */ public function __construct(Strength $strength, Agility $agility, Height $height) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ parent::__construct(SumAndRound::average($strength->getValue(), $agility->getValue()) + SumAndRound::ceil($height->getValue() / 3) - 2); }
/** * @param Strength $strength * @param Athletics $athletics */ public function __construct(Strength $strength, Athletics $athletics) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ parent::__construct($strength->getValue() + 21 + $athletics->getAthleticsBonus()->getValue()); }