game2006api/webapp/mt/GunLevel.php
aozhiwei f242f30c86 1
2022-01-06 19:13:13 +08:00

62 lines
1.5 KiB
PHP

<?php
namespace mt;
require_once('mt/AttrHelper.php');
use phpcommon;
class GunLevel {
public static function get($id)
{
return getXVal(self::getMetaList(), $id);
}
public static function getByQualityLevel($quality, $level)
{
self::mustBeQualityLevelHash();
return getXVal(self::$qualityLevelHash, $quality . '_' . $level, null);
}
public static function addRandAttr($levelMeta, &$attrs)
{
$attrArr = StrHelper::parseList($levelMeta['rand_attrs'], array('|', ':'));
foreach ($attrArr as $tuple) {
$attrId = $tuple[0];
$type = $tuple[1];
$val = rand($tuple[2], $tuple[3]);
foreach ($attrs as &$attr) {
if ($attr['attr_id'] == $attrId &&
$attr['type'] == $type) {
$attr['val'] += $val;
break;
}
}
}
return true;
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
}
return self::$metaList;
}
protected static function mustBeQualityLevelHash()
{
if (!self::$qualityLevelHash) {
self::$qualityLevelHash = array();
foreach (self::getMetaList() as $meta) {
self::$qualityLevelHash[$meta['quality'] . '_' . $meta['level']] = $meta;
}
}
}
protected static $metaList;
protected static $qualityLevelHash;
}