game2006api/webapp/mt/HeroLevelAttr.php
aozhiwei d84d06da81 1
2022-06-14 10:26:24 +08:00

86 lines
2.1 KiB
PHP

<?php
namespace mt;
require_once('mt/StrHelper.php');
require_once('mt/AttrHelper.php');
use phpcommon;
class HeroLevelAttr {
public static function get($id)
{
return getXVal(self::getMetaList(), $id);
}
public static function addRandAttr($level, &$dbAttrs)
{
$newAttrs = array();
foreach (self::getMetaList() as $meta) {
if ($meta['level'] == $level) {
if (in_array(
$meta['type'],
array(
kHAT_ABS_VAL,
kHAT_RATE_VAL
)
)) {
$val = self::getAttrValue($meta);
if ($val > 0) {
array_push(
$newAttrs,
array(
'attr_id' => $meta['attr_id'],
'type' => $meta['type'],
'val' => $val,
));
}
}
}
}
AttrHelper::mergeAttr($dbAttrs, $newAttrs);
return true;
}
protected static function getAttrValue($meta)
{
$strs = explode('|', $meta['attr_weight']);
$totalSpace = 0;
foreach ($strs as $tmpStr) {
$strs2 = explode(':', $tmpStr);
if (count($strs2) == 2) {
$totalSpace += $strs2[1];
}
}
if ($totalSpace > 0) {
$randSpace = rand(0, $totalSpace);
$currSpace = 0;
foreach ($strs as $tmpStr) {
$strs2 = explode(':', $tmpStr);
if (count($strs2) == 2) {
$currSpace += $strs2[1];
}
if ($randSpace <= $currSpace) {
return $strs2[0];
}
}
}
return 0;
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('heroLevelAttr@heroLevelAttr.php');
}
return self::$metaList;
}
protected static $metaList;
}