当前位置: 首页>>代码示例>>PHP>>正文


PHP Inventory::getBag方法代码示例

本文整理汇总了PHP中Inventory::getBag方法的典型用法代码示例。如果您正苦于以下问题:PHP Inventory::getBag方法的具体用法?PHP Inventory::getBag怎么用?PHP Inventory::getBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Inventory的用法示例。


在下文中一共展示了Inventory::getBag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 function game_view($id = null)
 {
     if (!isset($id)) {
         $this->render('/pages/view/notfound');
         exit;
     }
     $this->Bag->recursive = 2;
     $this->Bag->Item->unbindModel(array('belongsTo' => array('Group')));
     $bag = $this->Bag->find('first', array('conditions' => array('Bag.character_id' => $this->characterInfo['id'], 'Bag.id' => $id)));
     if (empty($bag)) {
         $this->render('/pages/view/notfound');
         exit;
     }
     App::import('Model', 'Inventory');
     $Inventory = new Inventory();
     $inventories = $Inventory->getBag($bag['Bag']['id']);
     $new_inventories = array();
     foreach ($inventories as $inv) {
         $new_inventories[$inv['Inventory']['index']] = $inv;
     }
     $this->set('inventories', $new_inventories);
     $this->set('bag', $bag);
 }
开发者ID:MortalROs,项目名称:Naxasius-Game-Engine,代码行数:23,代码来源:bags_controller.php

示例2: hasFreeSpace

 /**
  * Calculates the free space of a character. If the item can stack
  * to another item it will be allowed to loot.
  * @todo set this place somewhere else. E.g. bag.
  *
  * @param int $character_id the ID of the current character
  * @param int $item_id the ID of the lootable item
  * @param boolean $returnBagIndex set true to return an array with a `bag_id` and `index`
  * @return array|boolean if there is not space left it returns a false. @see $returnBagIndex for array
  */
 function hasFreeSpace($character_id = null, $item_id = null, $returnBagIndex = false)
 {
     App::import('Model', 'Bag');
     $Bag = new Bag();
     $Bag->unbindModelAll();
     $Bag->bindModel(array('belongsTo' => array('Item')));
     $Bag->Item->unbindModelAll();
     $Bag->Item->bindModel(array('hasAndBelongsToMany' => array('Stat')));
     $Bag->recursive = 2;
     $bags = $Bag->find('all', array('conditions' => array('Bag.character_id' => $character_id)));
     $total_slots = 0;
     $total_slots_filled = 0;
     $bag_ids = array();
     $firstBagIndex = array();
     $bag_counts = array();
     $bag_indexes = array();
     foreach ($bags as $bag) {
         $bag_ids[] = $bag['Bag']['id'];
         $total_slots += $bag['Item']['StatNamed']['slots'];
         $bag_counts[$bag['Bag']['id']] = $bag['Item']['StatNamed']['slots'];
     }
     App::import('Model', 'Inventory');
     $Inventory = new Inventory();
     $inventories = $Inventory->getBag($bag_ids);
     foreach ($inventories as $inventory) {
         if ($inventory['Item']['id'] == $item_id && $inventory['Item']['stackable'] > $inventory[0]['count']) {
             if ($returnBagIndex == true) {
                 return array('bag_id' => $inventory['Inventory']['bag_id'], 'index' => $inventory['Inventory']['index']);
             } else {
                 return true;
             }
         }
         $bag_indexes[$inventory['Inventory']['bag_id']][$inventory['Inventory']['index']] = 1;
         $total_slots_filled++;
     }
     if ($total_slots_filled < $total_slots) {
         if ($returnBagIndex == true) {
             foreach ($bag_counts as $bag_id => $count) {
                 if ($count > 0) {
                     asort($bag_indexes);
                     $last_index = 0;
                     for ($i = 1; $i <= $bag_counts[$bag_id]; $i++) {
                         if (!isset($bag_indexes[$bag_id][$i])) {
                             $firstBagIndex = array('bag_id' => $bag_id, 'index' => $i);
                             break 2;
                         }
                     }
                 }
             }
             $firstBagIndex['bag_id'] = !isset($firstBagIndex['bag_id']) || $firstBagIndex['bag_id'] == 0 ? $bag_ids[0] : $firstBagIndex['bag_id'];
             $firstBagIndex['index'] = !isset($firstBagIndex['index']) || $firstBagIndex['index'] == 0 ? 1 : $firstBagIndex['index'];
             return $firstBagIndex;
         } else {
             return true;
         }
     }
     return false;
 }
开发者ID:MortalROs,项目名称:Naxasius-Game-Engine,代码行数:68,代码来源:drop.php


注:本文中的Inventory::getBag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。