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

21 lines
670 B
PHP

<?php
namespace App\Actions;
use App\Engine\Military;
use App\Engine\Simulation;
use App\Models\User;
use App\Models\Village;
use Carbon\CarbonImmutable;
/** Train units at one military building; its queue runs on its own. */
final class Recruit extends VillageAction
{
public function __invoke(User $user, int $villageId, int $buildingId, string $unit, int $count): Village
{
return $this->mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) use ($buildingId, $unit, $count) {
Military::of($village, $sim)->recruit($this->building($village, $buildingId), $unit, $count, $now);
});
}
}