/** * @test * @dataProvider provideSkillType * @param string $skillType */ public function I_can_get_skill_points($skillType) { $backgroundSkillPoints = BackgroundSkillPoints::getIt($spentBackgroundPoints = 7, $heritage = $this->createHeritage($heritageValue = 456)); $tables = $this->mockery(Tables::class)->shouldReceive('getBackgroundSkillsTable')->atLeast()->once()->andReturn($backgroundSkillsTable = $this->mockery(\stdClass::class))->getMock(); $backgroundSkillsTable->shouldReceive('getSkillPoints')->with($spentBackgroundPoints, ProfessionCode::FIGHTER, $skillType)->atLeast()->once()->andReturn($result = 'foo')->getMock(); /** @var Tables $tables */ self::assertSame($result, $backgroundSkillPoints->getSkillPoints($this->createProfession(ProfessionCode::FIGHTER), $skillType, $tables)); switch ($skillType) { case SkillTypeCode::PHYSICAL: self::assertSame($result, $backgroundSkillPoints->getPhysicalSkillPoints($this->createProfession(ProfessionCode::FIGHTER), $tables)); break; case SkillTypeCode::PSYCHICAL: self::assertSame($result, $backgroundSkillPoints->getPsychicalSkillPoints($this->createProfession(ProfessionCode::FIGHTER), $tables)); break; case SkillTypeCode::COMBINED: self::assertSame($result, $backgroundSkillPoints->getCombinedSkillPoints($this->createProfession(ProfessionCode::FIGHTER), $tables)); break; } }
/** * @param ProfessionFirstLevel $professionFirstLevel * @param Tables $tables * @param BackgroundSkillPoints $backgroundSkillPoints * * @return bool * @throws \DrdPlus\Skills\Exceptions\EmptyFirstLevelBackgroundSkillPoints */ private function checkPayByFirstLevelBackgroundSkillPoints(ProfessionFirstLevel $professionFirstLevel, Tables $tables, BackgroundSkillPoints $backgroundSkillPoints) { $relatedProperties = $this->sortAlphabetically($this->getRelatedProperties()); $firstLevelSkillPoints = 0; switch ($relatedProperties) { case $this->sortAlphabetically([Strength::STRENGTH, Agility::AGILITY]): $firstLevelSkillPoints = $backgroundSkillPoints->getPhysicalSkillPoints($professionFirstLevel->getProfession(), $tables); break; case $this->sortAlphabetically([Will::WILL, Intelligence::INTELLIGENCE]): $firstLevelSkillPoints = $backgroundSkillPoints->getPsychicalSkillPoints($professionFirstLevel->getProfession(), $tables); break; case $this->sortAlphabetically([Knack::KNACK, Charisma::CHARISMA]): $firstLevelSkillPoints = $backgroundSkillPoints->getCombinedSkillPoints($professionFirstLevel->getProfession(), $tables); break; } if ($firstLevelSkillPoints < 1) { throw new Exceptions\EmptyFirstLevelBackgroundSkillPoints('First level skill point has to come from the background.' . ' No skill point for properties ' . implode(',', $relatedProperties) . ' is available.'); } return true; }
private static function checkIfBackgroundSkillPointsAreTheSame(BackgroundSkillPoints $firstBackgroundSkillPoints, BackgroundSkillPoints $secondBackgroundSkillPoints) { if ($firstBackgroundSkillPoints->getSpentBackgroundPoints() !== $secondBackgroundSkillPoints->getSpentBackgroundPoints()) { throw new Exceptions\BackgroundSkillPointsAreNotSame('All skill points, originated in person background, have to use same background skill points.' . " Got different background skill points with values {$firstBackgroundSkillPoints->getSpentBackgroundPoints()}" . " and {$secondBackgroundSkillPoints->getSpentBackgroundPoints()}"); } }
private function sumSpentPoints(Heritage $heritage, BackgroundSkillPoints $backgroundSkillPoints, BelongingsValue $belongingsValue) { return $heritage->getSpentBackgroundPoints() + $backgroundSkillPoints->getSpentBackgroundPoints() + $belongingsValue->getSpentBackgroundPoints(); }
private static function createCombinedSkillEntities(Tables $tables, ProfessionFirstLevel $firstLevel) { $combinedSkillClasses = self::getListOfSkillClasses(CombinedSkill::class); $combinedSkillPoint = CombinedSkillPoint::createFromFirstLevelBackgroundSkillPoints($firstLevel, BackgroundSkillPoints::getIt(3, Heritage::getIt(5)), $tables); $requiredRankValue = new PositiveIntegerObject(1); $combinedSkillList = array_map(function ($combinedSkillClass) use($firstLevel, $combinedSkillPoint, $requiredRankValue) { /** @var CombinedSkill $combinedSkill */ $combinedSkill = new $combinedSkillClass($firstLevel); $combinedSkill->addSkillRank($combinedSkillPoint); return $combinedSkill; }, $combinedSkillClasses); $combinedSkills = new CombinedSkills(); foreach ($combinedSkillList as $combinedSkill) { $combinedSkills->addCombinedSkill($combinedSkill); } $combinedSkillPoint = CombinedSkillPoint::createFromFirstLevelBackgroundSkillPoints($firstLevel, BackgroundSkillPoints::getIt(3, Heritage::getIt(5)), $tables); $combinedSkillRank = new CombinedSkillRank(new Cooking($firstLevel), CombinedSkillPoint::createFromFirstLevelBackgroundSkillPoints($firstLevel, BackgroundSkillPoints::getIt(4, Heritage::getIt(5)), $tables), new PositiveIntegerObject(1)); return array_merge($combinedSkillList, [$combinedSkills, $combinedSkillPoint, $combinedSkillRank]); }