Exemple #1
0
 /**
  * Добыча ресурсов
  * //TODO[Rottenwood]: Рефакторинг. Перенести в ObtainService
  * @param RoomResource $resource
  * @param EntityManager $em
  * @param array $result
  * @param UserService $userService
  * @param Item $resourceItem
  * @param Room $room
  * @return array
  */
 public function obtain(RoomResource $resource, EntityManager $em, array $result, UserService $userService, Item $resourceItem, Room $room) : array
 {
     if ($this->user->isBusy()) {
         $this->result->setWaitstate($this->user->getWaitstate());
         return [];
     }
     $userService->addWaitstate($this->user, $this->waitState);
     $this->reduceQuantity($em, $resource->getId(), $userService);
     $result['obtained'] = $this->quantityToObtain;
     $resourceQuantity = $resource->getQuantity();
     $result['resources'][$resourceItem->getId()] = $resourceQuantity;
     if ($resourceQuantity <= 0) {
         /** @var Grass[] $grassTypes */
         $grassTypes = $em->getRepository(Grass::class)->findAll();
         $grassType = $grassTypes[array_rand($grassTypes)];
         $room->setType($grassType);
         $result['typeChanged'] = true;
         $em->remove($resource);
     }
     return $result;
 }
Exemple #2
0
 /**
  * @param Room $room
  * @param int $x
  * @param int $y
  * @return array
  */
 private function addRoom(Room $room, int $x, int $y) : array
 {
     return ['x' => $x, 'y' => $y, 'pic' => $room->getType()->getPicture()];
 }
Exemple #3
0
 /**
  * Может ли персонаж войти в комнату
  * @param Room $room
  * @return bool
  */
 private function userCanWalkToRoom(Room $room) : bool
 {
     return $room->getType()->userCanWalk();
 }
Exemple #4
0
 /**
  * @param Room $room
  * @param int  $x
  * @param int  $y
  * @return array
  */
 private function addRoom(Room $room, $x, $y)
 {
     return ['x' => $x, 'y' => $y, 'pic' => $room->getType()->getPicture()];
 }