67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Websocket\Controllers;
|
|
|
|
use App\Actions\CancelMovement;
|
|
use App\Actions\PlanMarch;
|
|
use App\Actions\SendSupportHome;
|
|
use App\Actions\SendTroops;
|
|
use App\Actions\WithdrawSupport;
|
|
use App\Presenters\VillagePresenter;
|
|
use App\Websocket\GameController;
|
|
|
|
/**
|
|
* rally.preview {village_id, x, y, units, mode}: target, distance and travel time.
|
|
* rally.send {village_id, type, x, y, units, mode, catapult_target}, rally.cancel {village_id, movement_id},
|
|
* rally.sendHome {village_id, home_village_id}, rally.withdraw {village_id, host_village_id}:
|
|
* each answers with the fresh village state.
|
|
*/
|
|
class RallyController extends GameController
|
|
{
|
|
public function preview()
|
|
{
|
|
return $this->play(fn () => app(PlanMarch::class)(
|
|
auth()->user(),
|
|
(int) request('village_id'),
|
|
(int) request('x'),
|
|
(int) request('y'),
|
|
(array) request('units', []),
|
|
request('mode'),
|
|
));
|
|
}
|
|
|
|
public function send()
|
|
{
|
|
return $this->village(fn () => app(SendTroops::class)(
|
|
auth()->user(),
|
|
(int) request('village_id'),
|
|
(string) request('type'),
|
|
(int) request('x'),
|
|
(int) request('y'),
|
|
(array) request('units', []),
|
|
request('mode'),
|
|
request('catapult_target'),
|
|
));
|
|
}
|
|
|
|
public function cancel()
|
|
{
|
|
return $this->village(fn () => app(CancelMovement::class)(auth()->user(), (int) request('village_id'), (int) request('movement_id')));
|
|
}
|
|
|
|
public function sendHome()
|
|
{
|
|
return $this->village(fn () => app(SendSupportHome::class)(auth()->user(), (int) request('village_id'), (int) request('home_village_id')));
|
|
}
|
|
|
|
public function withdraw()
|
|
{
|
|
return $this->village(fn () => app(WithdrawSupport::class)(auth()->user(), (int) request('village_id'), (int) request('host_village_id')));
|
|
}
|
|
|
|
private function village(\Closure $action)
|
|
{
|
|
return $this->play(fn () => VillagePresenter::present($action(), now()->toImmutable()));
|
|
}
|
|
}
|