mutate($user, $villageId, function (Simulation $sim, Village $village, CarbonImmutable $now) use ($buildingId) { $building = $this->building($village, $buildingId); $offer = $sim->upgradeOffer($building) ?? throw new GameRuleViolation('max_level', 'Already at max level.'); if ($offer['blocked'] === 'villagers') { throw new GameRuleViolation('villagers', 'Not enough free villagers: build up the farm.'); } $sim->pay($offer['cost']); $sim->enqueue([ 'building_id' => $building->id, 'type' => $building->type, 'action' => BuildOrder::UPGRADE, 'target_level' => $offer['target_level'], 'cost' => $offer['cost'], ], $now); }); } }