Lines
100.00%
18 / 18
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| 17 | final readonly class UsableEnhancements | |
| 18 | { | |
| 19 | /** @return list<EnhancementItem> */ | |
| 20 | public static function among(CurrencyShop $shop, Equipment $held, Hero $hero): array | |
| 21 | { | |
| 22 | $usable = []; | |
| 23 | foreach ($shop->inventory as $sold) { | |
| 24 | if (!self::usable($sold, $shop, $held, $hero)) { | |
| 25 | continue; | |
| 26 | } | |
| 27 | ||
| 28 | $usable[] = $sold; | |
| 29 | } | |
| 30 | ||
| 31 | return $usable; | |
| 32 | } | |
| 33 | ||
| 34 | /** @phpstan-assert-if-true EnhancementItem $sold */ | |
| 35 | private static function usable(Item $sold, CurrencyShop $shop, Equipment $held, Hero $hero): bool | |
| 36 | { | |
| 37 | return ( | |
| 38 | $sold instanceof EnhancementItem | |
| 39 | && $sold->fits($held) | |
| 40 | && $sold->level->value <= $hero->level->value | |
| 41 | && ($hero->tags->has(PlayerTag::Member) || !$sold->tags->has(ItemTag::MemberOnly)) | |
| 42 | && $shop->price($sold->id)->isSomeAnd( | |
| 43 | static fn(ItemPrice $price): bool => ( | |
| 44 | $price->amount instanceof Gold | |
| 45 | && $hero->inventory->wallet->affords($price) | |
| 46 | ), | |
| 47 | ) | |
| 48 | ); | |
| 49 | } | |
| 50 | } |