2026-10-29 09:28:20 +00:00
|
|
|
<?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;
|
|
|
|
|
|
2026-10-31 09:50:31 +00:00
|
|
|
/** Mint coins at the village's academy; they belong to the player and pay for the villages beyond the first. */
|
2026-10-29 09:28:20 +00:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|