Ejemplo n.º 1
0
 public function testInventorySortBySelfUse()
 {
     $inventory = new Inventory($this->char);
     $inventory->add('shuriken', 10);
     $inventory->add('amanita', 40);
     $sorted_inv = Inventory::of($this->char, $sort = 'self');
     // Foreach over the inventory to get the first item out.
     foreach ($sorted_inv as $item) {
         break;
     }
     $this->assertEquals($item['name'], 'Amanita Mushroom');
 }
Ejemplo n.º 2
0
 /**
  * View items and gold of char
  *
  * @return Response
  */
 public function index(Container $p_dependencies)
 {
     $char = Player::find(SessionFactory::getSession()->get('player_id'));
     $inv = Inventory::of($char, 'self');
     $inventory = [];
     $error = RequestWrapper::getPostOrGet('error');
     if ($error === 'noitem') {
         $error = 'No such item';
     }
     foreach ($inv as $item) {
         // Special format for display and looping
         $item['display'] = $item['item_display_name'] . $item['plural'];
         $item['self_use'] = (bool) $item['self_use'];
         $inventory[$item['item_id']] = $item;
     }
     $parts = ['error' => $error, 'gold' => $char->gold, 'gold_display' => number_format($char->gold), 'inventory' => $inventory, 'username' => $char->name(), 'char_id' => $char->id()];
     return $this->render($parts);
 }