/** * Leveling sequentially from very first level up to highest possible until all experiences are spent. * @param Experiences $experiences * @return Level */ public function toTotalLevel(Experiences $experiences) { $currentExperiences = 0; $usedExperiences = 0; $maxLevelValue = 0; while ($usedExperiences + $currentExperiences <= $experiences->getValue()) { $level = $this->toLevel(new Experiences($currentExperiences, $this)); if ($maxLevelValue < $level->getValue()) { $usedExperiences += $currentExperiences; $maxLevelValue = $level->getValue(); } $currentExperiences++; } return new Level($maxLevelValue, $this); }
/** * @test */ public function I_can_get_experiences() { $experiences = new Experiences($value = 456, $this->getExperiencesTable(), Experiences::EXPERIENCES); self::assertSame($value, $experiences->getValue()); }