_getSelfMysql(), 't_gun_skin', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$skinList) { array_push($skinList, GunSkin::toDto($row)); } ); $this->_rspData(array( 'skin_list' => $skinList )); } public function talentList() { $talentList = array(); SqlHelper::ormSelect( $this->_getSelfMysql(), 't_gun_talent', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$talentList) { array_push($talentList, GunTalent::toDto($row)); } ); $this->_rspData(array( 'talent_list' => $talentList )); } public function upgradeTalentLv() { $talentId = getReqVal('talent_id', 0); $talentDb = GunTalent::find($talentId); $currLv = isset($talentDb) ? $talentDb['talent_lv'] : 1; $growMeta = mt\GunTalentGrow::getByIdLv($talentId, $currLv + 1); if (!$growMeta) { $this->_rspErr(2, "It's already the highest level"); return; } $ormUserInfo = $this->_getOrmUserInfo(); if ($ormUserInfo['level'] < $growMeta['need_user_level']) { $this->_rspErr(3, 'User level not reached'); return; } $costList = mt\GunTalentGrow::getCostList($growMeta); $lackItem = array(); if (!$this->_hasEnoughItems($costList, $lackItem)) { $this->_rspErr(3, 'Lack of materials'); return; } $this->_decItems($costList); GunTalent::upgradeLv($talentId, $currLv + 1); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto() )); } public function gunList() { $gunList = array(); SqlHelper::ormSelect( $this->_getSelfMysql(), 't_gun', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$gunList) { array_push($gunList, Gun::toDto($row)); } ); $this->_rspData(array( 'gun_list' => $gunList )); } public function upgradeLevel() { $costItemId = getReqVal('cost_item_id', 0); $gunUniId = getReqVal('gun_uniid', 0); $gunDb = Gun::find($gunUniId); if (!$gunDb) { $this->_rspErr(1, 'The gun does not exist'); return; } if ($gunDb['state'] != Gun::GETED_STATE) { $this->_rspErr(3, 'The trial gun cannot be operated'); return; } if ($gunDb['unlock_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } $itemMeta = mt\Item::get($gunDb['gun_id']); if (!$itemMeta) { $this->_rspErr(100, 'server internal error'); return; } $currLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv']); if (!$currLevelMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv'] + 1); if (!$nextLevelMeta) { $this->_rspErr(5, "It's already the highest level"); return; } $costItems = array(); switch ($costItemId) { case V_ITEM_GOLD: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currLevelMeta['gold'] ) ); } break; case V_ITEM_DIAMOND: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currLevelMeta['diamond'] ) ); } break; default: { $this->_rspErr(2, 'Payment method not supported'); return; } break; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $baseAttrs = mt\Item::getBaseAttrs($itemMeta); mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs()); $attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array()); $ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs); if (!$ret) { $this->_rspErr(2, 'server internal error'); return; } $this->_decItems($costItems); Gun::update($gunUniId, array( 'gun_lv' => $gunDb['gun_lv'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => Gun::LEVEL_LOCK, 'unlock_time' => $this->_getNowTime() + $currLevelMeta['time'], 'unlock_trade_time' => $this->_getNowTime() + $currLevelMeta['time'] + mt\Parameter::getVal('gun_lock_transaction_time', 0) ) ); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addGunChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeQuality() { $costItemId = getReqVal('cost_item_id', 0); $gunUniId = getReqVal('gun_uniid', 0); $gunDb = Gun::find($gunUniId); if (!$gunDb) { $this->_rspErr(1, 'The gun does not exist'); return; } if ($gunDb['state'] != Gun::GETED_STATE) { $this->_rspErr(3, 'The trial gun cannot be operated'); return; } if ($gunDb['unlock_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } $itemMeta = mt\Item::get($gunDb['gun_id']); if (!$itemMeta) { $this->_rspErr(100, 'server internal error'); return; } $currQualityMeta = mt\GunQuality::getByQuality($gunDb['quality']); if (!$currQualityMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1); if (!$nextQualityMeta) { $this->_rspErr(5, "It's already the highest level1"); return; } $nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'] + 1, $gunDb['gun_lv']); if (!$nextLevelMeta) { $this->_rspErr(5, "It's already the highest level2"); return; } $costItems = array(); switch ($costItemId) { case V_ITEM_GOLD: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currQualityMeta['gold'] ) ); } break; case V_ITEM_DIAMOND: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currQualityMeta['diamond'] ) ); } break; default: { $this->_rspErr(2, 'Payment method not supported'); return; } break; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $baseAttrs = mt\Item::getBaseAttrs($itemMeta); mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs()); $attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array()); { $obtainAttrs = mt\GunQuality::getRandAttr($nextQualityMeta); mt\AttrHelper::mergeAttr($attrs, $obtainAttrs); } { $ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs); if (!$ret) { $this->_rspErr(2, 'server internal error'); return; } } $this->_decItems($costItems); Gun::update($gunUniId, array( 'gun_lv' => $gunDb['gun_lv'], 'quality' => $gunDb['quality'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => Gun::QUALITY_LOCK, 'unlock_time' => $this->_getNowTime() + $currQualityMeta['time'], 'unlock_trade_time' => $this->_getNowTime() + $currQualityMeta['time'] + mt\Parameter::getVal('gun_lock_transaction_time', 0) ) ); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addGunChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } }