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); } }
/** * @param int $citizenId * @param int $amount * @param Entity\Industry $industry * @param int $quality * @return bool * @throws InvalidArgumentException */ public function donateItems($citizenId, $amount, Entity\Industry $industry, $quality) { return $this->donate($citizenId, 'items', $amount, ['industry_id' => $industry->getId(), 'quality' => $quality]); }
/** * {@inheritDoc} */ public function getCode() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array()); return parent::getCode(); }