/** * @param Clan $clan * @param Depot $depot * @param City $city * @return string */ public function clanSellBehavior(Clan $clan, Depot $depot, City $city) { $output = ''; $possessions = $depot->Assess(); foreach ($possessions as $possession) { if ($possession->getTgtype() != 'food') { $amt = $depot->GetValueByString($possession->getNamed()); $request = $this->rules->createRequest($clan, 'sell goods', $city->getId() . ',' . $possession->getId() . ',' . $amt); $result = $this->rules->submit($request); $output .= 'Clan' . $clan->getId() . ' ' . $result['Description']; } } return $output; }
/** * @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'); } }