$item){ $attr_pool['num_weight'][$key] = explode(':',$item); } $weight = 0; $tempData = array (); foreach ($attr_pool['num_weight'] as $one) { $weight += $one[1]; for ($i = 0; $i < $one[1]; $i++) { $tempData[] = $one; } } $k = rand(0, $weight -1); $attr_pool['val'] = $tempData[$k][0]; unset($attr_pool['num_weight']); } return $attr_pool; } // public static function generateOneAttr($type){ //// $itemMeta = Item::get($item_id); //// return self::getAttrPool(self::getAttrByItemId($itemMeta['id'])); // //// $attr_pool = self::getAttrPool(self::getAttrByItemId($itemMeta['id'])); //// $attr = emptyReplace(json_decode($chip['rand_attr'], true), array()); //// array_push($attr,$attr_pool); //// return $attr; // if ($type == self::ROLE_CHIP_SUBTYPE){ // $chip = self::getNodeChip(); // $attr = $chip[ array_rand($chip)]; // return self::getAttrPool($attr); // } // if ($type == self::GUN_CHIP_SUBTYPE){ // $chip = self::getGunChip(); // $attr = $chip[ array_rand($chip)]; // return self::getAttrPool($attr); // } // return array(); // } // // // // private static function getNodeChip(){ // $node_chip = array(); // foreach (self::getMetaList() as $item){ // if ($item['chip_type'] == self::ROLE_CHIP_SUBTYPE){ // array_push($node_chip,$item); // } // } // return $node_chip; // } // // private static function getGunChip(){ // $gun_chip = array(); // foreach (self::getMetaList() as $item){ // if ($item['chip_type'] == self::GUN_CHIP_SUBTYPE){ // array_push($gun_chip,$item); // } // } // return $gun_chip; // } public static function getAttrByItemId($item_id){ foreach (self::getMetaList() as $item){ if ($item['item_id'] == $item_id){ return $item; } } } }