Example #1
0
 /**
  * Looting an Item from an Obstacle in the game map
  *
  * @param int the id of the character
  * @param int the id of the areas_obstacles_item
  */
 function loot($characterInfo = null, $areas_obstacles_item_id = null)
 {
     if ($this->canLoot($areas_obstacles_item_id, $characterInfo['id'], $characterInfo['area_id'])) {
         // Opslaan die handel
         App::import('Model', 'AreasObstaclesItem');
         $AreasObstaclesItem = new AreasObstaclesItem();
         $drop = $AreasObstaclesItem->find('first', array('conditions' => array('AreasObstaclesItem.id' => $areas_obstacles_item_id)));
         $data['Drop']['areas_obstacle_item_id'] = $drop['AreasObstaclesItem']['id'];
         $data['Drop']['item_id'] = $drop['AreasObstaclesItem']['item_id'];
         $data['Drop']['character_id'] = $characterInfo['id'];
         $dataInventory['Inventory']['item_id'] = $drop['AreasObstaclesItem']['item_id'];
         $dataInventory['Inventory']['character_id'] = $characterInfo['id'];
         if ($this->save($data)) {
             // Item opvragen, en eventueel de character_id invullen als deze character de eerste is...
             App::import('Model', 'Item');
             $Item = new Item();
             $Item->unbindModelAll();
             $thisItem = $Item->find('first', array('conditions' => array('Item.id' => $drop['AreasObstaclesItem']['item_id'])));
             if (isset($thisItem['Item']['character_id']) && $thisItem['Item']['character_id'] == 0) {
                 $thisItem['Item']['character_id'] = $characterInfo['id'];
                 $thisItem['Item']['discovered'] = date('Y-m-d H:i:s');
                 $Item->save($thisItem);
             }
             App::import('Model', 'Inventory');
             $Inventory = new Inventory();
             // Bagid en index opvragen
             $bagIndex = $this->hasFreeSpace($characterInfo['id'], $drop['AreasObstaclesItem']['item_id'], true);
             $dataInventory['Inventory']['index'] = $bagIndex['index'];
             $dataInventory['Inventory']['bag_id'] = $bagIndex['bag_id'];
             // Save to inventory
             if ($Inventory->save($dataInventory)) {
                 App::import('Model', 'Quest');
                 $Quest = new Quest();
                 $Quest->update(null, $characterInfo['id']);
                 // Item is nu in de inventory... We kunnen eventueel questen updaten nu
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }