Esempio n. 1
0
 public function PurchaseItem($entry, $quantity = 1)
 {
     if ($entry == null) {
         return false;
     }
     // Check to see if we have enough resources to purchase the item.
     $resources = $entry->GetRequiredResources();
     foreach ($resources as $resource) {
         $myResourceAmount = MarketResourceTransaction::GetAmountByUser($this, $resource->Type);
         if ($myResourceAmount < $resource->Amount) {
             return false;
         }
     }
     // If we've reached here, then we are not bankrupt. Remove the resources from the user's wallet. The syntax is (from MarketResourceTransaction.inc.php):
     // 		public static function Create($resources, $receiver = null, $sender = null, $comments = null, $creationUser = null)
     $tresources = array();
     foreach ($resources as $resource) {
         $tresources[] = new MarketResourceTransactionResource($resource->Type, -1 * $resource->Amount);
     }
     MarketResourceTransaction::Create($resources, $user, null, "MarketItemPurchase:" . $entry->Item->ID, null);
     global $MySQL;
     $query = "INSERT INTO " . System::$Configuration["Database.TablePrefix"] . "UserInventoryItems (inventoryitem_UserID, inventoryitem_ItemID) VALUES (" . $this->ID . ", " . $entry->Item->ID . ")";
     $result = $MySQL->query($query);
     if (!$result) {
         return false;
     }
     return true;
 }