|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rottenwood\KingdomBundle\Command\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Rottenwood\KingdomBundle\Entity\Money; |
|
6
|
|
|
use Rottenwood\KingdomBundle\Entity\Robot; |
|
7
|
|
|
use Rottenwood\KingdomBundle\Entity\Room; |
|
8
|
|
|
use Rottenwood\KingdomBundle\Exception\RoomNotFound; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** {@inheritDoc} */ |
|
16
|
|
|
class CreateRobotCommand extends ContainerAwareCommand |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** {@inheritDoc} */ |
|
20
|
|
|
protected function configure() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->setName('kingdom:create:robot'); |
|
23
|
|
|
$this->setDescription('Создание робота'); |
|
24
|
|
|
|
|
25
|
|
|
$this->addArgument( |
|
26
|
|
|
'name', |
|
27
|
|
|
InputArgument::REQUIRED, |
|
28
|
|
|
'имя робота' |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$this->addArgument( |
|
32
|
|
|
'roomId', |
|
33
|
|
|
InputArgument::REQUIRED, |
|
34
|
|
|
'id комнаты рождения' |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** {@inheritDoc} */ |
|
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
40
|
|
|
{ |
|
41
|
|
|
$name = $input->getArgument('name'); |
|
42
|
|
|
$roomId = $input->getArgument('roomId'); |
|
43
|
|
|
|
|
44
|
|
|
$output->write('Создание робота ... '); |
|
45
|
|
|
|
|
46
|
|
|
$container = $this->getContainer(); |
|
47
|
|
|
|
|
48
|
|
|
$roomRepository = $container->get('kingdom.room_repository'); |
|
49
|
|
|
|
|
50
|
|
|
/** @var Room $room */ |
|
51
|
|
|
$room = $roomRepository->find($roomId); |
|
52
|
|
|
|
|
53
|
|
|
if (!$room) { |
|
54
|
|
|
throw new RoomNotFound(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$em = $roomRepository->getEntityManager(); |
|
58
|
|
|
$userService = $container->get('kingdom.user_service'); |
|
59
|
|
|
|
|
60
|
|
|
$cyrillicName = $userService->transliterate($name); |
|
61
|
|
|
|
|
62
|
|
|
$robot = new Robot(); |
|
63
|
|
|
$robot->setName($cyrillicName); |
|
64
|
|
|
$robot->setRoom($room); |
|
65
|
|
|
$this->createMoney($robot, $container); |
|
66
|
|
|
|
|
67
|
|
|
$em->persist($robot); |
|
68
|
|
|
$em->flush($robot); |
|
69
|
|
|
|
|
70
|
|
|
$output->writeln('Робот создан!'); |
|
71
|
|
|
|
|
72
|
|
|
$output->writeln('===================================='); |
|
73
|
|
|
$output->writeln('Id: ' . $robot->getId()); |
|
74
|
|
|
$output->writeln('Имя: ' . $robot->getName()); |
|
75
|
|
|
$output->writeln( |
|
76
|
|
|
sprintf( |
|
77
|
|
|
'Комната: [%d]%s %d/%d (%d)', |
|
78
|
|
|
$room->getId(), |
|
79
|
|
|
$room->getName(), |
|
80
|
|
|
$room->getX(), |
|
81
|
|
|
$room->getY(), |
|
82
|
|
|
$room->getZ() |
|
83
|
|
|
) |
|
84
|
|
|
); |
|
85
|
|
|
$output->writeln('===================================='); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Создание денег игрока |
|
90
|
|
|
* @param Robot $robot |
|
91
|
|
|
* @param ContainerInterface $container |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
|
|
private function createMoney(Robot $robot, ContainerInterface $container) |
|
95
|
|
|
{ |
|
96
|
|
|
$money = new Money($robot); |
|
97
|
|
|
$moneyRepository = $container->get('kingdom.money_repository'); |
|
98
|
|
|
$moneyRepository->persist($money); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|