protected function execute(InputInterface $input, OutputInterface $output) { /** @var LoggerInterface $logger */ $logger = $this->getContainer()->get('logger'); $logger->info('DailyBudgets begun ... '); $map = $this->getContainer()->get('service_map'); $agents = $this->getContainer()->get('service_agent'); $db = $this->getContainer()->get('db'); $allCities = $map->getCitiesByID(); foreach ($allCities as $k => $c) { $city = new City($c->id); $city->setDb($db); $city->load(); $agentList = $agents->getAgentsByCity($c->id); foreach ($agentList as $j => $a) { $agent = new Agent($a->id); $agent->setDb($db); $agent->load(); $agent->setTradeincome($city->getTradeincome()); $income = $agent->getCoin() + ceil($city->getTradeincome()); $logger->info('The estate of ' . $agent->getNamed() . ' collected ' . $city->getTradeincome() . ' from nearby markets'); $agent->setCoin($income); $agent->update(); } $city->setTradeincome(0.0); $city->update(); } $logger->info('DailyBudgets complete ... '); }
/** * @param $userid * @param $named * @param $culture * @param $city * @param $allegiance * @return int */ private function newPlayerAgent($userid, $named, $culture, $city, $allegiance) { // Create an undefined object to be assembled and pass it the DB $agent = new Agent(null); $agent->setDb($this->db); // Plunk, plonk, plonk $agent->setIsplayer(true); $agent->setUserid($userid); $agent->setNamed($named); $agent->setCulture($culture); // Get the player's chosen city out of the DB $query = 'SELECT * FROM game.city WHERE named="' . $city . '";'; $this->db->setQuery($query); $this->db->query(); $dbObject = $this->db->loadObject(); // Plunk, plonk, city data $agent->setX($dbObject->x); $agent->setY($dbObject->y); $agent->setCity($dbObject->id); $agent->setActivity('idle'); // Create a new buildinglist and point the value of $this->holdings to its primary key $query = 'INSERT INTO game.estate(id) VALUES(null);'; $this->db->setQuery($query); $this->db->query(); $agent->setHoldings($this->db->getLastInsertId()); // Ditto for a blank persona $query = 'INSERT INTO game.persona(id) VALUES(null);'; $this->db->setQuery($query); $this->db->query(); $agent->setPersona($this->db->getLastInsertId()); // Plunk $agent->setAllegiance($allegiance); // Insert the new Agent into SQL and return the primary key $agent->update(); return $this->db->getLastInsertId(); }