示例#1
0
 /**
  * @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');
     }
 }