Example #1
0
            }
            // end mat validation loop
            if (sizeof($ERRORS) > 0) {
                draw_errors($ERRORS);
            } else {
                foreach ($item->grabMaterials() as $material) {
                    $item_stack = $ITEM_HASH[$material->getMaterialItemTypeId()];
                    if ($item_stack == null) {
                        // If the item is missing from the hash, something very bad has occured.
                        die('Something broke rather badly. Perhaps you should tell someone important?');
                    }
                    $required_quantity = $quantity * $material->getMaterialQuantity();
                    $item_stack->updateQuantity($item_stack->getQuantity() - $required_quantity);
                }
                // end remove mats loop
                $result = Item::stackFactory($User->getUserId(), $item->getRecipeCreatedItemTypeId(), $db);
                $result_quantity = $quantity * $item->getRecipeBatchQuantity();
                $result->updateQuantity($result->getQuantity() + $result_quantity);
                $word = $product->getItemName();
                if ($result_quantity > 1) {
                    $word = English_Inflector::pluralize($word);
                }
                $_SESSION['craft_notice'] = "You have created {$result_quantity} {$word}.";
                redirect('crafting');
            }
            // end no errors; craft
            break;
            // end craft
    }
    // end switch
}
Example #2
0
                     $ERRORS[] = 'This is a unique item that you already have.';
                 } elseif ($quantity > 1) {
                     $ERRORS[] = 'You can only have one of this item.';
                 }
             }
             // end unique item checks
         }
         // end stock entry exists
         if (sizeof($ERRORS) > 0) {
             draw_errors($ERRORS);
         } else {
             // Take away their money.
             $total = $stock->getPrice() * $quantity;
             $User->subtractCurrency($total);
             // Try and find a stack of this item in the user's inventory.
             $item = Item::stackFactory($User->getUserId(), $stock->getItemTypeId(), $db);
             $item->updateQuantity($item->getQuantity() + $quantity);
             // Remove the stock from the shope.
             $item_name = $stock->getItemName();
             // store this for later.
             $stock->sell($quantity);
             // Stock could #destroy() itself during the #sell(), so don't
             // use it anymore.
             unset($stock);
             $_SESSION['shop_notice'] = "You have purchased " . number_format($quantity) . " <strong>{$item_name}</strong> for " . format_currency($total) . "!";
             redirect("shop/{$shop->getShopId()}");
         }
         // end do purchase
         break;
         // end purchase
 }
Example #3
0
 /**
  * Transfer ownership of an item to a different user.
  * 
  * @param User $new_user
  * @param integer $quantity
  * @return bool
  **/
 public function giveItem(User $new_user, $quantity)
 {
     if ($quantity > $this->getQuantity()) {
         throw new ArgumentError("Argument quantity = {$quantity} exceeds maximum of {$this->getQuantity()}.");
     }
     $old_user = new User($this->db);
     $old_user = $old_user->findOneByUserId($this->getUserId());
     $old_username = '******';
     if ($old_user != null) {
         $old_username = $old_user->getUserName();
     }
     $given_item = Item::stackFactory($new_user->getUserId(), $this->getItemTypeId(), $this->db);
     $given_item->updateQuantity($given_item->getQuantity() + $quantity);
     $word = $given_item->getItemName();
     if ($quantity > 1) {
         $word = English_Inflector::pluralize($word);
     }
     $new_user->notify("{$old_username} has given you <strong>{$quantity} {$word}</strong>.", 'items');
     $this->updateQuantity($this->getQuantity() - $quantity);
     return true;
 }