Ejemplo n.º 1
0
 public static function create($name, $type = inventory::TYPE_GENERAL, $character = null)
 {
     $char = null;
     if ($character instanceof character) {
         $char = $character;
     } else {
         if (is_numeric($char)) {
             $char = character::load_one($character);
         } else {
             if (is_string($char)) {
                 $char = character::load_one($character, 'name');
             } else {
                 if (!character::selected()) {
                     return false;
                 } else {
                     $char = character::current();
                 }
             }
         }
     }
     $inv = new static();
     $inv->char_id = $char->id;
     $inv->type = $type;
     $inv->name = $name;
     $inv->save();
     return $inv;
 }
Ejemplo n.º 2
0
 public function inventory_action($type)
 {
     $type = page::arg('type', $type, 'character');
     $charId = page::arg('character_id');
     $charName = page::arg('name');
     $itemType = page::arg('item_type', null, 'all');
     $char = null;
     if ($charId) {
         $char = character::load_one($charId);
     } else {
         if ($charName) {
             $char = character::load_one($charName, 'name');
         } else {
             if (!character::selected()) {
                 return api::result(false, array('message' => 'No_character_selected'));
             } else {
                 $char = character::current();
             }
         }
     }
     if (!$type) {
         $type = 'character';
     }
     $types = array('character' => inventory::TYPE_CHARACTER, 'vault' => inventory::TYPE_VAULT);
     $itemTypes = array('all' => null, 'usable' => item::TYPE_USABLE, 'enchantable' => item::TYPE_ENCHANTABLE, 'destroyable' => item::TYPE_DESTROYABLE, 'loot' => item::TYPE_LOOT, 'equippable' => item::TYPE_EQUIPPABLE, 'material' => item::TYPE_MATERIAL);
     if (!isset($types[$type])) {
         $itemType = (int) $type;
     }
     if (!array_key_exists($itemType, $itemTypes)) {
         return api::result(false, array('message' => 'Invalid_item_type'));
     }
     return api::result(true, array($char->inventory($types[$type])->items($itemTypes[$itemType], true)));
 }