Lines
100.00%
6 / 6
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| LevelProgression | 100.00% | 6 / 6 | 100.00% | 4 / 4 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| earn | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| next | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| recount | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Core\Player\Hero\Progression; | |
| 6 | ||
| 7 | use Lorekeeper\Core\Game\Level\Experience; | |
| 8 | use Lorekeeper\Core\Support\Gauge; | |
| 9 | ||
| 10 | final class LevelProgression | |
| 11 | { | |
| 12 | /** @param Gauge<Experience> $experience */ | |
| 13 | public function __construct( | |
| 14 | public private(set) Gauge $experience, | |
| 15 | ) {} | |
| 16 | ||
| 17 | public function earn(Experience $amount): void | |
| 18 | { | |
| 19 | $maximum = $this->experience->maximum; | |
| 20 | $earned = min($maximum->value, $this->experience->current->value + $amount->value); | |
| 21 | $this->experience = new Gauge(new Experience($earned), $maximum); | |
| 22 | } | |
| 23 | ||
| 24 | public function next(Experience $toNext): void | |
| 25 | { | |
| 26 | $this->experience = new Gauge(new Experience(0), $toNext); | |
| 27 | } | |
| 28 | ||
| 29 | /** @param Gauge<Experience> $experience */ | |
| 30 | public function recount(Gauge $experience): void | |
| 31 | { | |
| 32 | $this->experience = $experience; | |
| 33 | } | |
| 34 | } |