예제 #1
0
 protected function updateStorageStatus()
 {
     $output = $this->output;
     $now = time();
     $needsUpdate = $this->storageLastUpdate === null || $this->storageUpdateInterval <= $now - $this->storageLastUpdate;
     if ($needsUpdate === false) {
         return;
     }
     $output->writeln('<comment>Updating the storage...</comment>' . "\r");
     $this->toBuy = $this->amountToRefill;
     $inventory = $this->managementModule->getInventory();
     $this->storageLastUpdate = $now;
     if (!isset($inventory['items'][$this->industry->getId()][$this->quality])) {
         $inStorage = 0;
     } else {
         $inStorage = (int) $inventory['items'][$this->industry->getId()][$this->quality];
     }
     $this->toBuy -= $inStorage;
     if ($this->toBuy > 0) {
         $output->writeln('<comment>You already have ' . $inStorage . ' of ' . $this->industry->getName() . ' in storage,' . ' so you need to buy only: ' . $this->toBuy . '.</comment>');
         $availableSlots = $inventory['storage']['maximum'] - $inventory['storage']['current'];
         if ($this->toBuy > $availableSlots) {
             $this->toBuy = $availableSlots;
             $output->writeln('<comment>Unfortunately, you have only ' . $availableSlots . ' slots available in storage.</comment>');
             $output->writeln('<comment>You can buy maximum ' . $this->toBuy . ' of products.</comment>');
         }
     } else {
         $this->toBuy = 0;
         $output->writeln('<comment>You already have ' . $inStorage . ' of ' . $this->industry->getName() . ' in storage.</comment>');
         $output->writeln('<comment>Waiting ' . $this->storageUpdateInterval . ' seconds until next storage update.</comment>');
         sleep($this->storageUpdateInterval);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getName()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getName', array());
     return parent::getName();
 }