_rspData(array( 'hero_list' => $heroList )); } public function heroDetails() { $unique_id = trim(getReqVal('unique_id', 0)); if ( ! $unique_id) { $this->_rspErr(1, 'Please enter instructions'); return; } $heroDb = Hero::find($unique_id); if (! $heroDb){ $this->_rspErr(1, "You don't have the hero yet"); return; } $hero = Hero::toDto($heroDb); $this->_rspData(array( 'data' => $hero )); } public function upgradeSkillCommon(){ $heroUniId = getReqVal('hero_uniid', 0); $skillIndex = getReqVal('skill_index', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, "You don't have the hero yet"); return; } $item = explode('|',$heroDb['skill_common']); $skill_common = \mt\SkillCommon::get($item[$skillIndex]); if (!$skill_common){ $this->_rspErr(1, "You don't have the skill yet"); return; } $next_skill_common = \mt\SkillCommon::get($skill_common['nextlv_skill']); if (! $next_skill_common){ $this->_rspErr(1, "It's already the highest level"); return; } if($heroDb['quality'] < $next_skill_common['skill_limit_star']){ $this->_rspErr(1, "Hero level is not enough"); return; } if($heroDb['skill_points'] < $next_skill_common['skill_point_cost']){ $this->_rspErr(1, "Not enough hero skill points"); return; } $item[$skillIndex] = $skill_common['nextlv_skill']; $where = [ 'skill_common'=>implode('|',$item), 'skill_points'=>$heroDb['skill_points']-$next_skill_common['skill_point_cost'], 'modifytime' => $this->_getNowTime() ]; Hero::update($heroUniId, $where); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'propery_chg' => $propertyChgService->toDto(), )); } public function upgradeSkill() { $heroUniId = getReqVal('hero_uniid', 0); $skillUniId = getReqVal('skill_uniid', 0); $skillIdx = getReqVal('skill_idx', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, "You don't have the hero yet"); return; } if (!in_array($skillIdx, array(0, 1))) { $this->_rspErr(1, 'skill_idx must be 0-1'); return; } $skill = \mt\Skill::get($skillUniId); if (!$skill){ $this->_rspErr(1, "You don't have the skill yet"); return; } $next_skill = \mt\Skill::get($skill['nextlv_skill']); if (!$next_skill){ $this->_rspErr(1, "It's already the highest level"); return; } if($heroDb['quality'] < $next_skill['skill_limit_star']){ $this->_rspErr(1, "Hero level is not enough"); return; } if(! $heroDb['skill_points'] || $heroDb['skill_points'] < $next_skill['skill_point']){ $this->_rspErr(1, "Not enough hero skill points"); return; } Hero::upgradeSkill($heroUniId,$skillIdx); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'propery_chg' => $propertyChgService->toDto(), )); } public function skinList() { $skinList = array(); SqlHelper::ormSelect( $this->_getSelfMysql(), 't_hero_skin', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$skinList) { array_push($skinList, HeroSkin::toDto($row)); } ); $this->_rspData(array( 'skin_list' => $skinList )); } public function takeonSkin() { $heroUniId = getReqVal('hero_uniid', 0); $skinId = getReqVal('skin_id', 0); $heroDb = Hero::find($heroUniId); $heroSkinDb = HeroSkin::find($skinId); if (!$heroDb) { $this->_rspErr(1, "You don't have the hero yet"); return; } if (!$heroSkinDb) { $this->_rspErr(2, "You don't have the skin yet"); return; } Hero::takeonSkin($heroUniId, $skinId); $this->_rspOk(); } public function getUpgradeLevelList() { $infos = array(); for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) { $heroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i); $info = null; if ($heroUniId) { $heroDb = Hero::find($heroUniId); if ($heroDb) { $heroDto = Hero::toDto($heroDb); $info = array( 'info' => $heroDto, 'countdown' => $heroDto['unlock_lefttime'] ); } } array_push($infos, $info); } $this->_rspData(array( 'infos' => $infos )); } public function getUpgradeQualityList() { $infos = array(); for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) { $heroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i); $info = null; if ($heroUniId) { $heroDb = Hero::find($heroUniId); if ($heroDb) { $heroDto = Hero::toDto($heroDb); $info = array( 'info' => $heroDto, 'countdown' => $heroDto['unlock_lefttime'] ); } } array_push($infos, $info); } $this->_rspData(array( 'infos' => $infos )); } public function receive() { $type = getReqVal('type', 0); $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, 'hero does not exist1'); return; } $heroDto = Hero::toDto($heroDb); if ($heroDto['unlock_lefttime'] > 0) { $this->_rspErr(1, 'Countdown is not over'); return; } $oldHero = $heroDto; $newHero = $heroDto; switch ($type) { case 1: { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) { $upHeroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i); if ($upHeroUniId == $heroUniId) { $idx = $i; $found = true; break; } } if (!$found) { $this->_rspErr(1, 'hero does not exist2'); return; } $this->_setV(TN_HERO_LEVEL_UP, $idx, 0); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addBagChg(); $propertyChgService->addUserChg(); $nextLevelMeta = null; $nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1); if ($nextLevelMeta) { $attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,1); $where = array( 'hero_lv' => $heroDb['hero_lv'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => 0, 'unlock_time' => 0, 'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point'] ); //免费英雄到底15级后生成NFT // if ($heroDb['hero_lv'] + 1 == 15 && !$heroDb['token_id']){ // $token_id = myself()->_getNowTime(); // if(!\services\NftService::addNft($heroDb['hero_id'],$token_id)){ // return ; // } // $where = array( // 'hero_lv' => $heroDb['hero_lv'] + 1, // 'token_id'=> $token_id, // 'rand_attr' => json_encode($attrs), // 'lock_type' => 0, // 'unlock_time' => 0, // 'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point'] // ); // } Hero::update($heroUniId, $where); if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) { myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1); } $newHeroDb = Hero::find($heroUniId); $newHero = Hero::toDto($newHeroDb); $rankActivityService = new services\RankActivityService(); $rankActivityService->heroUpgradeLevel($heroDb['hero_lv'] + 1); } $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'old_hero' => $oldHero, 'new_hero' => $newHero, )); } break; case 2: { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) { $upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i); if ($upHeroUniId == $heroUniId) { $idx = $i; $found = true; break; } } if (!$found) { $this->_rspErr(1, 'hero does not exist'); return; } $costHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, (int)$idx + 1000); $this->_setV(TN_HERO_QUALITY_UP, $idx, 0); $this->_setV(TN_HERO_QUALITY_UP, (int)$idx + 1000, 0); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addBagChg(); $propertyChgService->addUserChg(); $nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1); if ($nextQualityMeta) { $costHeroDb = Hero::find($costHeroUniId); if ($costHeroDb['token_id']){ SqlHelper::update( myself()->_getMarketMysql(), 't_nft', ['token_id'=>$costHeroDb['token_id']], ['deleted'=>1] ); }else{ Hero::update($costHeroUniId, array( 'account_id' => myself()->_getAccountId() . '!!!', ) ); } Hero::update($costHeroUniId, array( 'lock_type' => 0, 'unlock_time' => 0, ) ); $rnd = rand(1, 100); $probability = \services\FormulaService::Hero_Advanced_Probability($heroDb['quality'])*100; if ($rnd > $probability) { Hero::update($heroUniId, array( 'advanced_count' => $heroDb['advanced_count'] + 1, 'lock_type' => 0, 'unlock_time' => 0, ) ); $oldHero['advanced_count'] += 1; $newHero['advanced_count'] += 1; $this->_rspRawData(array( 'errcode' => 0, 'errmsg' => '', 'state' => 0, 'old_hero' => $oldHero, 'new_hero' => $newHero, //'errmsg' => 'advance failed', 'property_chg' => $propertyChgService->toDto(), )); return; } $heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality']); $nextHeroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality'] + 1); $heroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'],$heroLucky); $nextHeroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'] + 1,$nextHeroLucky); Hero::update($heroUniId, array( 'hero_tili' => $heroDb['hero_tili']+($nextHeroTili-$heroTili), 'skill_points' => $heroDb['skill_points'] + $nextQualityMeta['skill_point'], 'quality' => $heroDb['quality'] + 1, 'advanced_count' => $heroDb['advanced_count'] + 1, 'lock_type' => 0, 'unlock_time' => 0, ) ); if ($heroDb['quality'] + 1 > myself()->_getV(TN_HERO_MAX_QUALITY, 0)) { myself()->_setV(TN_HERO_MAX_QUALITY, 0, $heroDb['quality'] + 1); } $newHeroDb = Hero::find($heroUniId); $newHero = Hero::toDto($newHeroDb); error_log(json_encode(array( 'costHeroUniId' => $costHeroUniId, 'heroUniId' => $heroUniId ))); $rankActivityService = new services\RankActivityService(); $rankActivityService->heroUpgradeQuality($heroDb['quality'] + 1); } if (!$nextQualityMeta) { $this->_rspErr(1, 'quality is full'); return; } $this->_rspData(array( 'state' => 1, 'property_chg' => $propertyChgService->toDto(), 'old_hero' => $oldHero, 'new_hero' => $newHero, )); } break; default: { $this->_rspErr(1, 'type parameter error'); return; } break; } } public function upgradeLevel() { $heroUniId = getReqVal('hero_uniid', 0); $slotId = getReqVal('slot_id', 0); $heroDb = Hero::find($heroUniId); if (!in_array($slotId, array(0, kMaxHeroUpLevelNum - 1))) { $this->_rspErr(1, 'slot_id parameter error'); return; } { $srcHeroDb = Hero::find($this->_getV(TN_HERO_LEVEL_UP, $slotId)); if ($srcHeroDb) { $this->_rspErr(1, 'slot_id parameter error'); return; } } if (!$heroDb) { $this->_rspErr(1, 'hero does not exist'); return; } if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } $heroMeta = mt\Hero::get($heroDb['hero_id']); if (!$heroMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1); if (!$nextLevelMeta) { $this->_rspErr(5, "It's already the highest level"); return; } if ($heroDb['hero_lv']+1 <15){ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1) ) ); }else{ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1) ), array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => \services\FormulaService::Hero_Upgrade_CEC_Expend($heroDb['hero_lv']+1) ) ); } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); { Hero::update( $heroUniId, array( 'lock_type' => Hero::LEVEL_LOCK ) ); } $this->_setV(TN_HERO_LEVEL_UP, (int)$slotId, (int)$heroDb['idx']); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addBagChg(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeLevelPreview(){ $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, 'hero does not exist'); return; } $heroMeta = mt\Hero::get($heroDb['hero_id']); if (!$heroMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1); if (!$nextLevelMeta) { $this->_rspErr(5, "It's already the highest level"); return; } $newHeroDb = $heroDb; $newHeroDb['hero_lv'] += 1; $attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,0); $newHeroDb['rand_attr'] = json_encode($attrs); $cost['CEG'] = \services\FormulaService::Hero_Upgrade_CEG_Expend($newHeroDb['hero_lv']); $cost['CEC'] = \services\FormulaService::Hero_Upgrade_CEC_Expend($newHeroDb['hero_lv']); $heroDto = Hero::toDto($heroDb); $newHeroDto = Hero::toDto($newHeroDb); $this->_rspData(array( 'old_hero' => $heroDto, 'new_hero' => $newHeroDto, 'cost' => $cost )); } public function upgradeQuality() { $costHeroUniId = getReqVal('cost_hero_uniid', 0); $heroUniId = getReqVal('hero_uniid', 0); $slotId = getReqVal('slot_id', 0); $heroDb = Hero::find($heroUniId); if (!in_array($slotId, array(0, kMaxHeroUpQualityNum - 1))) { $this->_rspErr(1, 'slot_id parameter error'); return; } // if (!$heroDb['token_id']){ // $this->_rspErr(100, 'Free heroes cannot quality up'); // return; // } $costHeroDb = Hero::find($costHeroUniId); if (!$costHeroDb) { $this->_rspErr(1, 'cost hero parameter error'); return; } if ($heroDb['hero_id'] != $costHeroDb['hero_id']){ $this->_rspErr(100, 'You need the same kind of hero'); return; } if ($costHeroDb['quality']>1){ $this->_rspErr(100, 'Material hero quality too high'); return; } if ($costHeroDb['lock_type']) { $this->_rspErr(2, 'Cannot operate during locking'); return; } { $srcHeroDb = Hero::find($this->_getV(TN_HERO_QUALITY_UP, $slotId)); if ($srcHeroDb) { $this->_rspErr(1, 'slot_id parameter error'); return; } } { $idx = 0; $found = false; for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) { $upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i); if ($upHeroUniId == $heroUniId) { $idx = $i; $found = true; break; } } if ($found) { $this->_rspErr(1, 'hero already upgrading'); return; } } if (!$heroDb) { $this->_rspErr(1, 'hero does not exist'); return; } if ($heroDb['advanced_count'] >= mt\Parameter::getVal('advence_limit', 0)) { $this->_rspErr(1, 'hero does not exist'); return; } if ($heroDb['state'] != Hero::GETED_STATE) { $this->_rspErr(3, 'Trial hero cannot operate'); return; } if ($heroDb['lock_type']) { $this->_rspErr(2, 'Cannot operate during locking'); return; } if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, 'Cannot operate during locking'); return; } $heroMeta = mt\Hero::get($heroDb['hero_id']); if (!$heroMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1); if (!$nextQualityMeta) { $this->_rspErr(5, "It's already the highest quality"); return; } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['quality']+1) ), array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['quality']+1) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Hero::update($heroUniId, array( 'lock_type' => Hero::QUALITY_LOCK, 'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'], ) ); Hero::update($costHeroUniId, array( 'lock_type' => Hero::COST_LOCK, 'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'], ) ); $this->_setV(TN_HERO_QUALITY_UP, (int)$slotId, (int)$heroDb['idx']); $this->_setV(TN_HERO_QUALITY_UP, (int)$slotId + 1000, (int)$costHeroDb['idx']); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addBagChg(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeQualityPreview() { $heroUniId = getReqVal('hero_uniid', 0); $costHeroUniId = getReqVal('cost_hero_uniid', 0); $heroDb = Hero::find($heroUniId); $costHeroDb = Hero::find($costHeroUniId); if (!$heroDb || !$costHeroDb) { $this->_rspErr(100, 'server internal error'); return; } // if (!$heroDb['token_id']){ // $this->_rspErr(100, 'Free heroes cannot quality up'); // return; // } if ($heroDb['hero_id'] != $costHeroDb['hero_id']){ $this->_rspErr(100, 'You need the same kind of hero'); return; } if ($costHeroDb['quality']>1){ $this->_rspErr(100, 'Material hero quality too high'); return; } $heroMeta = mt\Hero::get($heroDb['hero_id']); if (!$heroMeta) { $this->_rspErr(100, 'server internal error'); return; } $nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1); if (!$nextQualityMeta) { $this->_rspErr(5, "It's already the highest level1"); return; } $newHeroDb = $heroDb; $newHeroDb['quality'] += 1; $cost['CEG'] = \services\FormulaService::Hero_Advanced_CEG_Expend($newHeroDb['quality']); $cost['CEC'] = \services\FormulaService::Hero_Advanced_CEC_Expend($newHeroDb['quality']); $heroDto = Hero::toDto($heroDb); $newHeroDto = Hero::toDto($newHeroDb); $this->_rspData(array( 'old_hero' => $heroDto, 'new_hero' => $newHeroDto, 'cost' => $cost )); } }