119 lines
3.5 KiB
PHP
119 lines
3.5 KiB
PHP
<?php
|
|
|
|
|
|
namespace mt;
|
|
|
|
require_once('mt/AttrHelper.php');
|
|
require_once('mt/StrHelper.php');
|
|
require_once('mt/Item.php');
|
|
|
|
use phpcommon;
|
|
|
|
class ChipAttr {
|
|
const ROLE_CHIP_SUBTYPE = 1;
|
|
const GUN_CHIP_SUBTYPE = 2;
|
|
protected static $metaList;
|
|
protected static $attrPoolList;
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('chip@chip.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static function getAttrPoolList()
|
|
{
|
|
if (!self::$attrPoolList) {
|
|
self::$attrPoolList = getMetaTable('chipAttrPool@chipAttrPool.php');
|
|
}
|
|
return self::$attrPoolList;
|
|
}
|
|
|
|
public static function getAttrPool($chip){
|
|
$temp = array();
|
|
$attrWeight = 0;
|
|
foreach (self::getAttrPoolList() as $item){
|
|
if ($item['chip_type'] == $chip['chip_type']){
|
|
$attrWeight += $item['attr_weight'];
|
|
for ($i = 0; $i < $item['attr_weight']; $i++) {
|
|
$temp[] = $item;
|
|
}
|
|
}
|
|
}
|
|
$attr_pool = $temp[rand(0, $attrWeight -1)];
|
|
if ($attr_pool){
|
|
$attr_pool['num_weight'] = explode('|',$attr_pool['num_weight']);
|
|
foreach ($attr_pool['num_weight'] as $key =>$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;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |