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 ... '); }
function indexAction() { $db = $this->get('db'); $session = $this->get('session'); $aid = $session->get('aid'); $player = new Agent($aid); $player->setDb($db); $player->load(); $cid = $player->getCity(); $city = new City($cid); $city->setDb($db); $city->load(); $persona = new Persona($player->getPersona()); $persona->setDb($db); $persona->load(); $player->setDb(null); $player->setIsplayer(null); $player->setPtype(null); return $this->render('GameBundle:Game:characterview.html.twig', array('myCity' => $city, 'myCharacter' => $player, 'myReputation' => $persona)); }
function indexAction() { $db = $this->get('db'); $session = $this->get('session'); $aid = $session->get('aid'); $player = new Agent($aid); $player->setDb($db); $player->load(); $cid = $player->getCity(); $city = new City($cid); $city->setDb($db); $city->load(); $myName = $player->getNamed(); $myCoin = $player->getCoin(); $myCity = $city->getNamed(); $myTradeIncome = $city->getTradeincome(); // City's property reflects tomorrow's income from markets $myTotalIncome = $myTradeIncome; $myBuildingCosts = 0; $myTotalCosts = $myBuildingCosts; $myTotal = $myCoin + ceil($myTotalIncome) - $myTotalCosts; $myBuildings = []; return $this->render('GameBundle:Game:estateview.html.twig', array('myName' => $myName, 'myCoin' => $myCoin, 'myCity' => $myCity, 'myTradeIncome' => $myTradeIncome, 'myBuildingCosts' => $myBuildingCosts, 'myTotal' => $myTotal, 'myBuildings' => $myBuildings)); }
/** * @param IDepotHaver $issuer * @param City $city * @param $good * @param $amt * @return array */ public function buyGoods(IDepotHaver $issuer, $city, $good, $amt) { $depot = new Depot($issuer->getDepot()); $depot->setDb($this->db); $depot->load(); $tgp = new TradegoodPlatonic($good); $tgp->setDb($this->db); $tgp->load(); $city = new City($city); $city->setDb($this->db); $city->load(); if (empty($depot) | empty($tgp)) { return $this->getResult('Event failure', 'Null depot or tradegood'); } // Calculate costs, taxes, etc. $purse = $issuer->getCoin(); $cost = $amt * $tgp->tradevalue; // If we have sufficient coin if ($purse >= $cost) { $this->SetCoins($issuer, $purse - $cost); $city->taxTrade($cost); $currentStores = $depot->GetValueByString($tgp->named); $depot->setValueByString($tgp->named, $currentStores + $amt); return $this->getResult('Success', 'bought ' . $amt . ' ' . $tgp->named . ' for ' . $cost . ' coin'); } else { return $this->getResult('Illegal move', 'attempted to purchase ' . $amt . ' ' . $tgp->named . ' but had insufficient coin'); } }
/** * Returns the first city found within the selected range * * @param int $x * @param int $y * @param int width * @return City|null */ public function findNearestCity($x, $y) { $query = "SELECT id FROM game.city WHERE x>=" . ($x - 8) . " AND x<=" . ($x + 8) . " AND y>=" . ($y - 8) . " AND y<=" . ($y + 8) . ";"; $this->db->setQuery($query); $this->db->query(); $ObjList = $this->db->loadObjectList(); if (!empty($ObjList)) { shuffle($ObjList); $loadObj = array_shift($ObjList); $city = new City($loadObj->id); $city->setDb($this->db); $city->load(); return $city; } else { return null; } }