diff --git a/doc/Gun.py b/doc/Gun.py index 1bd057d5..c29e42b7 100644 --- a/doc/Gun.py +++ b/doc/Gun.py @@ -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(), '枪械-新'], + ] + }, ] diff --git a/webapp/controller/GunController.class.php b/webapp/controller/GunController.class.php index a1b93908..d3ee9798 100644 --- a/webapp/controller/GunController.class.php +++ b/webapp/controller/GunController.class.php @@ -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, + )); + } + } diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index 0290146a..8cd88b94 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -57,6 +57,11 @@ class Gun extends BaseModel { 'idx' => $gunUniId, ) ); + if ($row) { + if ($row['account_id'] != myself()->_getAccountId()) { + $row = null; + } + } return $row; }