game-village-politics-backend/app/Actions/EndLevy.php

25 lines
695 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Actions;
use App\Engine\Military;
use App\Engine\Simulation;
use App\Game\GameRuleViolation;
use App\Models\User;
use App\Models\Village;
use Carbon\CarbonImmutable;
/** Send the militia back to work before the levy runs out. */
final class EndLevy extends VillageAction
{
public function __invoke(User $user, int $villageId): Village
{
return $this->mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) {
if (! $village->militia) {
throw new GameRuleViolation('not_found', 'No levy under way.');
}
Military::of($village, $sim)->endLevy($now);
});
}
}