Esempio n. 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;
     }
 }
 function game_loot($loot_id = null)
 {
     $this->render(false);
     $this->Loot->contain(array('Item'));
     $someLoot = $this->Loot->find('first', array('conditions' => array('Loot.character_id' => $this->characterInfo['id'], 'Loot.id' => $loot_id)));
     if (!empty($someLoot)) {
         $this->loadModel('Inventory');
         $this->loadModel('Drop');
         // Bagid en index opvragen
         if ($bagIndex = $this->Drop->hasFreeSpace($this->characterInfo['id'], $someLoot['Item']['id'], true)) {
             $dataInventory['Inventory']['index'] = $bagIndex['index'];
             $dataInventory['Inventory']['bag_id'] = $bagIndex['bag_id'];
             $dataInventory['Inventory']['character_id'] = $this->characterInfo['id'];
             $dataInventory['Inventory']['item_id'] = $someLoot['Item']['id'];
             // Save to inventory
             if ($this->Inventory->save($dataInventory)) {
                 App::import('Model', 'Quest');
                 $Quest = new Quest();
                 $Quest->update(null, $this->characterInfo['id']);
                 $someLoot['Loot']['looted'] = 'yes';
                 $this->Loot->save($someLoot);
                 // Kijken of dit item als eerst gevonden is voor deze gebruiker...
                 if (isset($someLoot['Item']['character_id']) && $someLoot['Item']['character_id'] == 0) {
                     $thisItem['Item']['character_id'] = $this->characterInfo['id'];
                     $thisItem['Item']['discovered'] = date('Y-m-d H:i:s');
                     $this->Item->save($thisItem);
                 }
                 if ($someLoot['Item']['']) {
                     echo '1';
                 }
                 exit;
             }
         }
     }
     echo '0';
     exit;
 }