_rspErr(1,'type parameter error'); return ; } $fragmentList = []; Fragment::getFragmentList(function ($row) use(&$fragmentList,$type) { switch ($type){ case 1: { if ( $row['type'] == 1 || $row['type'] == 3){ array_push($fragmentList, $row); } } break; case 2: { if ( $row['type'] == 2 || $row['type'] == 4){ array_push($fragmentList, $row); }; } } }); $this->_rspData(array( 'fragment_list' => $fragmentList )); } public function syntheticFragmentPreview() { $type = getReqVal('type', 0); switch ($type) { case 1: { $itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE); $hero = array(); foreach ($itemMetaList as $meta){ array_push($hero,$meta['id']); } $mint = \services\FormulaService::Hero_Parts_Synthetic_Cost($this->hero_count); $this->_rspData(array( 'list' => $hero, 'mint' => $mint )); } break; case 2: { $itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE); $gun = array(); foreach ($itemMetaList as $meta){ array_push($gun,$meta['id']); } $mint = \services\FormulaService::Weapon_Parts_Synthetic_Cost($this->gun_count); $this->_rspData(array( 'list' => $gun, 'mint' => $mint )); } break; default: { $this->_rspErr(1, 'type parameter error'); return; } } } public function syntheticFragment(){ $type = getReqVal('type', 0); $unique_ids = getReqVal('unique_ids',''); $unique_id_special = getReqVal('unique_id_special',''); $item_id = getReqVal('item_id',''); $unique_id_arr = explode('|',$unique_ids); if (count($unique_id_arr) != 8){ $this->_rspErr(1,'Insufficient number of parameters'); return ; } switch ($type) { case 1: { if ($unique_id_special){ //指定合成英雄 $itemMeta = mt\Item::get($item_id); if (!$itemMeta){ $this->_rspErr(1,'item_id param error'); return ; } $fragmentDbSpecial = Fragment::getFragmentByIdx($unique_id_special); if (!$fragmentDbSpecial){ $this->_rspErr(1,'unique_id_special param error'); return ; } if ($fragmentDbSpecial['type'] != 3){ $this->_rspErr(1,'unique_id_special param error(type)'); return ; } $token_id_arr = array(); foreach ($unique_id_arr as $val){ $fragmentDb = Fragment::getFragmentByIdx($val); if (!$fragmentDb){ $this->_rspErr(1,'unique_ids param error'); return ; } if ($fragmentDb['type'] != 1){ $this->_rspErr(1,'unique_ids param error(type)'); return ; } array_push($token_id_arr,$fragmentDb['token_id']); } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Hero_Parts_Synthetic_Cost($this->hero_count) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } //销毁碎片 foreach ($token_id_arr as $val){ Fragment::deleteFragment(['token_id'=>$val]); } $this->_decItems($costItems); //生成NFT英雄 Nft::addNft($itemMeta); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addFragment(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'item_id' => $itemMeta['id'] )); }else{ //随机合成英雄 $token_id_arr = array(); foreach ($unique_id_arr as $val){ $fragmentDb = Fragment::getFragmentByIdx($val); if (!$fragmentDb){ $this->_rspErr(1,'unique_id param error'); return ; } if ($fragmentDb['type'] != 1){ $this->_rspErr(1,'unique_id param error(type)'); return ; } array_push($token_id_arr,$fragmentDb['token_id']); } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Hero_Parts_Synthetic_Cost($this->hero_count) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } //销毁碎片 foreach ($token_id_arr as $val){ Fragment::deleteFragment(['token_id'=>$val]); } $this->_decItems($costItems); $itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE); $key = rand(0,count($itemMetaList)-1); $itemMeta = $itemMetaList[$key]; //生成NFT英雄 Nft::addNft($itemMeta); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addFragment(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'item_id' => $itemMeta['id'] )); } } break; case 2: { if ($unique_id_special){ //指定合成枪械 $itemMeta = mt\Item::get($item_id); if (!$itemMeta){ $this->_rspErr(1,'item_id param error'); return ; } $fragmentDbSpecial = Fragment::getFragmentByIdx($unique_id_special); if (!$fragmentDbSpecial){ $this->_rspErr(1,'unique_id_special param error'); return ; } if ($fragmentDbSpecial['type'] != 4){ $this->_rspErr(1,'unique_id_special param error(type)'); return ; } $token_id_arr = array(); foreach ($unique_id_arr as $val){ $fragmentDb = Fragment::getFragmentByIdx($val); if (!$fragmentDb){ $this->_rspErr(1,'unique_ids param error'); return ; } if ($fragmentDb['type'] != 2){ $this->_rspErr(1,'unique_ids param error(type)'); return ; } array_push($token_id_arr,$fragmentDb['token_id']); } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Weapon_Parts_Synthetic_Cost($this->gun_count) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } //销毁碎片 foreach ($token_id_arr as $val){ Fragment::deleteFragment(['token_id'=>$val]); } $this->_decItems($costItems); //生成NFT英雄 Nft::addNft($itemMeta); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addFragment(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'item_id' => $itemMeta['id'] )); }else{ //随机合成枪械 $token_id_arr = array(); foreach ($unique_id_arr as $val){ $fragmentDb = Fragment::getFragmentByIdx($val); if (!$fragmentDb){ $this->_rspErr(1,'unique_id param error'); return ; } if ($fragmentDb['type'] != 2){ $this->_rspErr(1,'unique_id param error(type)'); return ; } array_push($token_id_arr,$fragmentDb['token_id']); } $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => \services\FormulaService::Weapon_Parts_Synthetic_Cost($this->gun_count) ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } //销毁碎片 foreach ($token_id_arr as $val){ Fragment::deleteFragment(['token_id'=>$val]); } $this->_decItems($costItems); $itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE); $key = rand(0,count($itemMetaList)-1); $itemMeta = $itemMetaList[$key]; //生成NFT英雄 Nft::addNft($itemMeta); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addFragment(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), 'item_id' => $itemMeta['id'] )); } } break; default: { $this->_rspErr(1, 'type parameter error'); return; } } } }