game2006api/webapp/mt/HeroLevelAttr.php
2023-03-14 16:44:59 +08:00

105 lines
2.6 KiB
PHP

<?php
namespace mt;
require_once('mt/StrHelper.php');
require_once('mt/AttrHelper.php');
require_once('mt/Hero.php');
use phpcommon;
class HeroLevelAttr {
private static $BASE_ATTR = [kHAT_Hp,kHAT_Atk,kHAT_Def,kHAT_Critical,kHAT_CriDamage,kHAT_Dodge,kHAT_Ruduce];
public static function find($id)
{
return getXVal(self::getMetaList(), $id);
}
public static function addRandAttr($meta,$type){
if ($type == 1){
$attr = array(
array(
'attr_id' => kHAT_Hp,
'val' => self::getAttrValue($meta)
),
array(
'attr_id' => kHAT_Atk,
'val' => self::getAttrValue($meta)
),
array(
'attr_id' => kHAT_Def,
'val' => self::getAttrValue($meta)
),
);
}else{
$attr = array(
array(
'attr_id' => kHAT_Hp,
'val' => self::getAttrValueMin($meta)
),
array(
'attr_id' => kHAT_Atk,
'val' => self::getAttrValueMin($meta)
),
array(
'attr_id' => kHAT_Def,
'val' => self::getAttrValueMin($meta)
),
);
}
return $attr;
}
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 getAttrValueMin($meta)
{
$strs = explode('|', $meta['attr_weight']);
foreach ($strs as $tmpStr) {
$strs2 = explode(':', $tmpStr);
return $strs2[0];
}
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('heroLevelAttr@heroLevelAttr.php');
}
return self::$metaList;
}
protected static $metaList;
}