武器升级

This commit is contained in:
hujiabin 2023-02-15 16:17:19 +08:00
parent 3d6face169
commit 0fcdfb2f2e
3 changed files with 83 additions and 0 deletions

View File

@ -197,4 +197,21 @@ class Gun(object):
['!infos', [_common.QualityingGun()], '升阶中的枪械列表'],
]
},
{
'name': 'upgradeLv',
'desc': '升等级',
'group': 'Gun',
'url': 'webapp/index.php?c=Gun&a=upgradeLv',
'params': [
_common.ReqHead(),
['gun_uniid', 0, '枪械唯一id'],
['cost_gun_uniid', 0, '材料武器id'],
],
'response': [
_common.RspHead(),
['property_chg', _common.PropertyChg(), '属性变更'],
['old_gun', _common.Gun(), '枪械-老'],
['new_gun', _common.Gun(), '枪械-新'],
]
},
]

View File

@ -816,4 +816,65 @@ class GunController extends BaseAuthedController {
));
}
public function upgradeLv(){
$gunUniId = getReqVal('gun_uniid', 0);
$costGunUniId = getReqVal('cost_gun_uniid', 0);
$gunDb = Gun::find($gunUniId);
$oldGun = Gun::toDto($gunDb);
$costGunDb = Gun::findEx($costGunUniId);
if (!$gunDb || !$costGunDb) {
$this->_rspErr(100, 'param error or null');
return;
}
if ($costGunDb['token_id']){
$this->_rspErr(100, 'NFT cannot be a material');
return;
}
if ($gunDb['gun_lv'] != $costGunDb['gun_lv']){
$this->_rspErr(100, 'You need the same level to do it');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] +1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
//升级所需消耗
// $costItems = array();
// $lackItem = null;
// if (!$this->_hasEnoughItems($costItems, $lackItem)) {
// $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
// return;
// }
// $this->_decItems($costItems);
$attrs = mt\GunLevel::addRandAttrNew($gunDb,1);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'] + 1,
'rand_attr' => json_encode($attrs),
));
Gun::update($costGunUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
)
);
$newGun = Gun::toDto(Gun::find($gunUniId));
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_gun' => $oldGun,
'new_gun' => $newGun,
));
}
}

View File

@ -57,6 +57,11 @@ class Gun extends BaseModel {
'idx' => $gunUniId,
)
);
if ($row) {
if ($row['account_id'] != myself()->_getAccountId()) {
$row = null;
}
}
return $row;
}