diff --git a/webapp/bootstrap/constant.php b/webapp/bootstrap/constant.php new file mode 100644 index 00000000..7e22cfcb --- /dev/null +++ b/webapp/bootstrap/constant.php @@ -0,0 +1,63 @@ +_rspErr(2, '锁定期间不能操作'); return; } + $heroMeta = mt\Hero::get($heroDb['hero_id']); + if (!$heroMeta) { + $this->_rspErr(100, '服务器内部错误'); + return; + } $currLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv']); if (!$currLevelMeta) { $this->_rspErr(100, '服务器内部错误'); @@ -156,8 +161,9 @@ class HeroController extends BaseAuthedController { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } + $baseAttrs = mt\Hero::getHeroAttr($heroMeta); $attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); - $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs); + $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs); if (!$ret) { $this->_rspErr(2, '服务器内部错误'); return; @@ -200,6 +206,11 @@ class HeroController extends BaseAuthedController { $this->_rspErr(2, '锁定期间不能操作'); return; } + $heroMeta = mt\Hero::get($heroDb['hero_id']); + if (!$heroMeta) { + $this->_rspErr(100, '服务器内部错误'); + return; + } $currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']); if (!$currQualityMeta) { $this->_rspErr(100, '服务器内部错误'); @@ -249,13 +260,14 @@ class HeroController extends BaseAuthedController { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } + $baseAttrs = mt\Hero::getHeroAttr($heroMeta); $attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); { $obtainAttrs = mt\HeroQuality::getRandAttr($nextQualityMeta); mt\AttrHelper::mergeAttr($attrs, $obtainAttrs); } { - $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs); + $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs); if (!$ret) { $this->_rspErr(2, '服务器内部错误'); return; diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 9325b70c..a02cc677 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -5,6 +5,7 @@ namespace models; require_once('mt/Hero.php'); require_once('mt/HeroLevel.php'); require_once('mt/HeroQuality.php'); +require_once('mt/AttrHelper.php'); require_once('models/HeroSkin.php'); use mt; @@ -61,6 +62,11 @@ class Hero extends BaseModel { $lockType = $row['lock_type']; $unlockTime = $row['unlock_time']; } + $heroMeta = mt\Hero::get($row['hero_id']); + if ($heroMeta) { + $baseAttr = mt\Hero::getHeroAttr($heroMeta); + mt\AttrHelper::mergeAttr($attr, $baseAttr); + } $dto = array( 'hero_uniid' => $row['idx'], 'hero_id' => $row['hero_id'], diff --git a/webapp/mt/AttrHelper.php b/webapp/mt/AttrHelper.php index 87ec960e..0476bf11 100644 --- a/webapp/mt/AttrHelper.php +++ b/webapp/mt/AttrHelper.php @@ -24,4 +24,46 @@ class AttrHelper { } } + public static function addRandAttrs($cfgAttrs, $num, $baseAttrs, &$dbAttrs) + { + $matchedAttrs = array(); + foreach ($cfgAttrs as $cfgAttr) { + $attrId = $cfgAttr[0]; + $type = $cfgAttr[1]; + if (array_find($dbAttrs, function($val) use ( $attrId, $type) { + return $val['attr_id'] == $attrId && $val['type'] == $type; + })) { + array_push($matchedAttrs, $cfgAttr); + } else if (array_find($baseAttrs, function($val) use ($attrId, $type) { + return $val['attr_id'] == $attrId && $val['type'] == $type; + })) { + array_push($matchedAttrs, $cfgAttr); + } + } + shuffle($matchedAttrs); + for ($i = 0; $i < $num; ++$i) { + if ($i < $matchedAttrs) { + $cfgAttr = $matchedAttrs[$i]; + + $attrId = $cfgAttr[0]; + $type = $cfgAttr[1]; + $val = rand($cfgAttr[2], $cfgAttr[3]); + $found = false; + foreach ($dbAttrs as &$attr) { + if ($attr['attr_id'] == $attrId && + $attr['type'] == $type) { + $found = true; + } + } + if ($found) { + array_push($dbAttrs, array( + 'attr_id' => $attrId, + 'type' => $type, + 'val' => $val + )); + } + } + } + } + } diff --git a/webapp/mt/Hero.php b/webapp/mt/Hero.php index 6a1f7dae..02896b2c 100644 --- a/webapp/mt/Hero.php +++ b/webapp/mt/Hero.php @@ -17,6 +17,37 @@ class Hero { return count($values) > 0 ? $values[0] : 0; } + public static function getHeroAttr($meta) + { + $fields = array( + array( + 'attr_id' => kHAT_Hp, + 'field_name' => 'hp' + ), + array( + 'attr_id' => kHAT_Atk, + 'field_name' => 'damage' + ), + array( + 'attr_id' => kHAT_Def, + 'field_name' => 'defence' + ), + array( + 'attr_id' => kHAT_Speed, + 'field_name' => 'move_speed' + ), + ); + $attr = array(); + foreach ($fields as $field) { + array_push($attr, array( + 'attr_id' => $field['attr_id'], + 'type' => kHAT_ABS_VAL, + 'val' => (int)$meta[$field['field_name']] + )); + } + return $attr; + } + protected static function getMetaList() { if (!self::$metaList) { diff --git a/webapp/mt/HeroLevel.php b/webapp/mt/HeroLevel.php index e12fa7c7..7eb10386 100644 --- a/webapp/mt/HeroLevel.php +++ b/webapp/mt/HeroLevel.php @@ -19,21 +19,12 @@ class HeroLevel { return getXVal(self::$qualityLevelHash, $quality . '_' . $level, null); } - public static function addRandAttr($levelMeta, &$attrs) + public static function addRandAttr($levelMeta, $baseAttrs, &$dbAttrs) { - $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; - } - } - } + $nums = explode(':', $levelMeta['rand_attrs_num']); + $num = rand($nums[0], $nums[1]); + $cfgAttrs = StrHelper::parseList($levelMeta['rand_attrs'], array('|', ':')); + AttrHelper::addRandAttrs($cfgAttrs, $num, $baseAttrs, $dbAttrs); return true; }