30 lines
986 B
PHP
30 lines
986 B
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Engine\Nobility;
|
|
use App\Engine\Simulation;
|
|
use App\Game\GameRuleViolation;
|
|
use App\Models\User;
|
|
use App\Models\Village;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
/** Mint coins at the village's academy; they belong to the player and pay for noble slots. */
|
|
final class MintCoins extends VillageAction
|
|
{
|
|
public function __invoke(User $user, int $villageId, int $count): Village
|
|
{
|
|
if ($count < 1) {
|
|
throw new GameRuleViolation('count', 'Mint at least one coin.');
|
|
}
|
|
|
|
return $this->mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) use ($count) {
|
|
if (! $village->buildings->contains('type', 'academy')) {
|
|
throw new GameRuleViolation('requires', 'Coins are minted at an academy.');
|
|
}
|
|
$sim->pay(Nobility::of($village)->rules()->coinCost($count));
|
|
$village->player->increment('coins', $count);
|
|
});
|
|
}
|
|
}
|