This commit is contained in:
aozhiwei 2022-01-13 14:28:18 +08:00
parent a7e8ed5917
commit c264b23a56
2 changed files with 20 additions and 16 deletions

View File

@ -125,6 +125,11 @@ class GunController extends BaseAuthedController {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$currLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv']);
if (!$currLevelMeta) {
$this->_rspErr(100, '服务器内部错误');
@ -169,8 +174,9 @@ class GunController extends BaseAuthedController {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$baseAttrs = mt\Item::getBaseAttrs($itemMeta);
$attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $attrs);
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, '服务器内部错误');
return;
@ -213,6 +219,11 @@ class GunController extends BaseAuthedController {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$currQualityMeta = mt\GunQuality::getByQuality($gunDb['quality']);
if (!$currQualityMeta) {
$this->_rspErr(100, '服务器内部错误');
@ -262,13 +273,14 @@ class GunController extends BaseAuthedController {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$baseAttrs = mt\Item::getBaseAttrs($itemMeta);
$attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
{
$obtainAttrs = mt\GunQuality::getRandAttr($nextQualityMeta);
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
}
{
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $attrs);
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, '服务器内部错误');
return;

View File

@ -2,6 +2,7 @@
namespace mt;
require_once('mt/StrHelper.php');
require_once('mt/AttrHelper.php');
use phpcommon;
@ -19,21 +20,12 @@ class GunLevel {
return getXVal(self::$qualityLevelHash, $quality . '_' . $level, null);
}
public static function addRandAttr($levelMeta, &$attrs)
public static function addRandAttr($levelMeta, $baseAttrs, &$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;
}
}
}
$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;
}