_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 gunDetails(){ $unique_id = trim(getReqVal('unique_id', 0)); if ( ! $unique_id) { $this->_rspErr(1, 'Please enter instructions'); return; } $gunDb = Gun::find($unique_id); if (! $gunDb){ $this->_rspErr(1, "You don't have the gun yet"); return; } $gun = Gun::toDto($gunDb); $this->_rspData(array( 'data' => $gun )); } 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(); Gun::getGunList(function ($row) use(&$gunList) { array_push($gunList, Gun::toDto($row)); }); $this->_rspData(array( 'gun_list' => $gunList )); } public function upgradeLevel() { $gunUniId = getReqVal('gun_uniid', 0); $slotId = getReqVal('slot_id', 0); $gunDb = Gun::find($gunUniId); if (!in_array($slotId, array(0, kMaxHeroUpLevelNum - 1))) { $this->_rspErr(1, 'slot_id parameter error'); return; } { $srcGunDb = Gun::find($this->_getV(TN_GUN_LEVEL_UP, $slotId)); if ($srcGunDb) { $this->_rspErr(1, 'slot_id parameter error'); return; } } if (!$gunDb) { $this->_rspErr(1, 'The gun does not exist'); 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; } $nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] +1); if (!$nextLevelMeta) { $this->_rspErr(5, "It's already the highest level"); return; } if ($gunDb['gun_lv']+1 <15){ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Weapon_Upgrade_CEG_Expend($gunDb['hero_lv']+1) ) ); }else{ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Weapon_Upgrade_CEG_Expend($gunDb['hero_lv']+1) ), array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => \services\FormulaService::Weapon_Upgrade_CEC_Expend($gunDb['hero_lv']+1) ) ); } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Gun::update($gunUniId, array( 'lock_type' => Gun::LEVEL_LOCK, ) ); $this->_setV(TN_GUN_LEVEL_UP, (int)$slotId, (int)$gunDb['idx']); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addGunChg(); $propertyChgService->addBagChg(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeLevelPreview(){ $gunUniId = getReqVal('gun_uniid', 0); $gunDb = Gun::find($gunUniId); if (!$gunDb) { $this->_rspErr(1, 'The gun does not exist'); 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; } $newGunDb = $gunDb; $newGunDb['gun_lv'] += 1; $attrs = mt\GunLevel::addRandAttrNew($gunDb,0); $newGunDb['rand_attr'] = json_encode($attrs); $cost['CEG'] = \services\FormulaService::Weapon_Upgrade_CEG_Expend( $newGunDb['gun_lv']); $cost['CEC'] = \services\FormulaService::Weapon_Upgrade_CEC_Expend( $newGunDb['gun_lv']); $gunDto = Gun::toDto($gunDb); $newGunDto = Gun::toDto($newGunDb); $this->_rspData(array( 'old_gun' => $gunDto, 'new_gun' => $newGunDto, 'cost' => $cost )); } public function upgradeQuality() { $costGunUniId = getReqVal('cost_gun_uniid', 0); $gunUniId = getReqVal('gun_uniid', 0); $slotId = getReqVal('slot_id', 0); $gunDb = Gun::find($gunUniId); if (!in_array($slotId, array(0, kMaxHeroUpQualityNum - 1))) { $this->_rspErr(1, 'slot_id parameter error'); return; } // if (!$gunDb['token_id']){ // $this->_rspErr(100, 'Free heroes cannot quality up'); // return; // } $costGunDb = Gun::find($costGunUniId); if (!$costGunDb) { $this->_rspErr(1, 'cost hero parameter error'); return; } if ($gunDb['gun_id'] != $costGunDb['gun_id']){ $this->_rspErr(100, 'You need the same kind of hero'); return; } if ($costGunDb['quality']>1){ $this->_rspErr(100, 'Material gun quality too high'); return; } if ($costGunDb['lock_type']) { $this->_rspErr(2, 'Cannot operate during locking'); return; } { $srcGunDb = Gun::find($this->_getV(TN_GUN_QUALITY_UP, $slotId)); if ($srcGunDb) { $this->_rspErr(1, 'slot_id parameter error'); return; } } { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) { $upGunUniId = $this->_getV(TN_GUN_QUALITY_UP, $i); if ($upGunUniId == $gunUniId) { $idx = $i; $found = true; break; } } if ($found) { $this->_rspErr(1, 'gun already upgrading'); return; } } 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['lock_type']) { $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; } $nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1); if (!$nextQualityMeta) { $this->_rspErr(5, "It's already the highest level1"); return; } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Weapon_Advanced_CEG_Expend($gunDb['quality']+1) ), array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => \services\FormulaService::Weapon_Advanced_CEC_Expend($gunDb['quality']+1) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Gun::update($gunUniId, array( 'lock_type' => Gun::QUALITY_LOCK, 'unlock_time' => $this->_getNowTime() + 20, ) ); Gun::update($costGunUniId, array( 'lock_type' => Gun::COST_LOCK, 'unlock_time' => $this->_getNowTime() + 20, ) ); $this->_setV(TN_GUN_QUALITY_UP, (int)$slotId, (int)$gunDb['idx']); $this->_setV(TN_GUN_QUALITY_UP, (int)$slotId + 1000, (int)$costGunDb['idx']); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addGunChg(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeQualityPreview() { $costGunUniId = getReqVal('cost_gun_uniid', 0); $gunUniId = getReqVal('gun_uniid', 0); $gunDb = Gun::find($gunUniId); $costGunDb = Gun::find($costGunUniId); if (!$gunDb || !$costGunDb) { $this->_rspErr(100, 'server internal error'); return; } // if (!$gunDb['token_id']){ // $this->_rspErr(100, 'Free gun cannot quality up'); // return; // } if ($gunDb['gun_id'] != $costGunDb['gun_id']){ $this->_rspErr(100, 'You need the same kind of hero'); return; } if ($costGunDb['quality']>1){ $this->_rspErr(100, 'Material gun quality too high'); return; } $itemMeta = mt\Item::get($gunDb['gun_id']); if (!$itemMeta) { $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; } $newGunDb = $gunDb; $newGunDb['quality'] += 1; $cost['CEG'] = \services\FormulaService::Weapon_Advanced_CEG_Expend($newGunDb['quality']); $cost['CEC'] = \services\FormulaService::Weapon_Advanced_CEC_Expend($newGunDb['quality']); $gunDto = Gun::toDto($gunDb); $newGunDto = Gun::toDto($newGunDb); $this->_rspData(array( 'old_gun' => $gunDto, 'new_gun' => $newGunDto, 'cost' => $cost )); } public function receive(){ $type = getReqVal('type', 0); $gunUniId = getReqVal('gun_uniid', 0); $gunDb = Gun::find($gunUniId); if (!$gunDb) { $this->_rspErr(1, 'gun does not exist1'); return; } $gunDto = Gun::toDto($gunDb); if ($gunDto['unlock_lefttime'] > 0) { $this->_rspErr(1, 'Countdown is not over'); return; } $oldGun = $gunDto; $newGun = $gunDto; switch ($type) { case 1: { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) { $upHeroUniId = $this->_getV(TN_GUN_LEVEL_UP, $i); if ($upHeroUniId == $gunUniId) { $idx = $i; $found = true; break; } } if (!$found) { $this->_rspErr(1, 'gun does not exist2'); return; } $this->_setV(TN_GUN_LEVEL_UP, $idx, 0); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addUserChg(); $nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] + 1); if ($nextLevelMeta) { $attrs = mt\GunLevel::addRandAttrNew($gunDb,1); $where = array( 'gun_lv' => $gunDb['gun_lv'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => 0, 'unlock_time' => 0, ); Gun::update($gunUniId,$where); if ($gunDb['gun_lv'] + 1 > myself()->_getV(TN_GUN_MAX_LEVEL, 0)) { myself()->_setV(TN_GUN_MAX_LEVEL, 0, $gunDb['gun_lv'] + 1); } $newGunDb = Gun::find($gunUniId); $newGun = Gun::toDto($newGunDb); $rankActivityService = new services\RankActivityService(); $rankActivityService->heroUpgradeLevel($gunDb['gun_lv'] + 1); } $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'old_gun' => $oldGun, 'new_gun' => $newGun, )); } break; case 2: { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) { $upGunUniId = $this->_getV(TN_GUN_QUALITY_UP, $i); if ($upGunUniId == $gunUniId) { $idx = $i; $found = true; break; } } if (!$found) { $this->_rspErr(1, 'gun does not exist'); return; } $costGunUniId = $this->_getV(TN_GUN_QUALITY_UP, (int)$idx + 1000); $this->_setV(TN_GUN_QUALITY_UP, $idx, 0); $this->_setV(TN_GUN_QUALITY_UP, (int)$idx + 1000, 0); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addGunChg(); $propertyChgService->addUserChg(); $nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1); if ($nextQualityMeta) { $costGunDb = Gun::find($costGunUniId); if ($costGunDb['token_id']){ SqlHelper::update( myself()->_getMarketMysql(), 't_nft', ['token_id'=>$costGunDb['token_id']], ['deleted'=>1] ); }else{ Gun::update($costGunUniId, array( 'account_id' => myself()->_getAccountId() . '!!!', 'lock_type' => 0, 'unlock_time' => 0, ) ); } Gun::update($costGunUniId, array( 'lock_type' => 0, 'unlock_time' => 0, ) ); $rnd = rand(1, 100); $probability = \services\FormulaService::Weapon_Advanced_Probability($gunDb['quality'] + 1)*100; if ($rnd > $probability) { Gun::update($gunUniId, array( 'lock_type' => 0, 'unlock_time' => 0, ) ); $this->_rspRawData(array( 'errcode' => 0, 'errmsg' => '', 'state' => 0, 'old_gun' => $oldGun, 'new_gun' => $newGun, //'errmsg' => 'advance failed', 'property_chg' => $propertyChgService->toDto(), )); return; } $gunLucky = \services\FormulaService::Weapon_Advanced_Lucky_Value($gunDb['quality']); $nextGunLucky = \services\FormulaService::Weapon_Advanced_Lucky_Value($gunDb['quality'] + 1); $durability = \services\FormulaService::Weapon_NFT_Maximum_Durability($gunDb['quality'],$gunLucky); $nextDurability = \services\FormulaService::Weapon_NFT_Maximum_Durability($gunDb['quality'] + 1,$nextGunLucky); Gun::update($gunUniId, array( 'durability' => $gunDb['durability']+($nextDurability-$durability), 'quality' => $gunDb['quality'] + 1, 'lock_type' => 0, 'unlock_time' => 0, ) ); if ($gunDb['quality'] + 1 > myself()->_getV(TN_GUN_MAX_QUALITY, 0)) { myself()->_setV(TN_GUN_MAX_QUALITY, 0, $gunDb['quality'] + 1); } $newGunDb = Gun::find($gunUniId); $newGun = Gun::toDto($newGunDb); error_log(json_encode(array( 'costGunUniId' => $costGunUniId, 'gunUniId' => $gunUniId ))); $rankActivityService = new services\RankActivityService(); $rankActivityService->heroUpgradeQuality($gunDb['quality'] + 1); } if (!$nextQualityMeta) { $this->_rspErr(1, 'quality is full'); return; } $this->_rspData(array( 'state' => 1, 'property_chg' => $propertyChgService->toDto(), 'old_gun' => $oldGun, 'new_gun' => $newGun, )); } break; default: { $this->_rspErr(1, 'type parameter error'); return; } break; } } }