From ddd78b4659c7c25df248e68213fa837790e32ca2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 4 Nov 2022 12:50:41 +0800 Subject: [PATCH] 1 --- .../controller/BlockChainController.class.php | 87 ++++--------------- webapp/mt/Item.php | 51 +++++------ 2 files changed, 38 insertions(+), 100 deletions(-) diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 6b8d422d..7764b175 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -197,7 +197,8 @@ class BlockChainController extends BaseAuthedController { public function evolveChip() { - + $tokenId1 = getReqVal('token_id1', ''); + $tokenIds = explode('|', getReqVal('token_ids', '')); } public function mintShardBatchUser() @@ -242,82 +243,26 @@ class BlockChainController extends BaseAuthedController { $tokenId = ''; $tokenType = ''; - if (count($tokenIds) <= 0) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - - $part = 0; - $hasSpecHero = false; - $hasSpecGun = false; - $specCount = 0; - foreach ($tokenIds as $itemId) { - $itemMeta = mt\Item::get($itemId); - if (!$itemMeta || !mt\Item::isFragment($itemMeta)) { - myself()->_rspErr(1, 'token_ids paramaer error'); + { + $heros = array(); + $guns = array(); + $specHeros = array(); + $specGuns = array(); + mt\Item::groupFragment($tokenIds, $heros, $guns, $specHeros, $specGuns); + if (count($tokenIds) != ( + count($heros) + count($guns) + count($specHeros) + count($specGuns) + )) { + myself()->_rspErr(101, 'token_ids paramater error'); return; } - if ($part == 0) { - if (!($itemMeta['sub_type'] == 3 || - $itemMeta['sub_type'] == 4)) { - $part = $itemMeta['sub_type']; - } else { - if ($itemMeta['sub_type'] == 3) { - $hasSpecHero = true; - } - if ($itemMeta['sub_type'] == 4) { - $hasGunHero = true; - } - ++$specCount; - } - } else { - if ($part != $itemMeta['sub_type']) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - } - } - if ($specCount > 1) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - if ($part == 1) { - if ($hasSpecGun) { - myself()->_rspErr(1, 'token_ids paramaer error'); + if (count($specHeros) + count($specGuns) > 1) { + myself()->_rspErr(101, 'token_ids paramater error'); return; } - $tokenType = Nft::HERO_TYPE; - if (!mt\Item::canMixHero($tokenIds)) { - myself()->_rspErr(1, 'token_ids paramaer error'); + if (count($heros) > 0 && count($guns) > 0) { + myself()->_rspErr(101, 'token_ids paramater error'); return; } - if ($hasSpecHero) { - $itemMeta = mt\Item::get($itemId); - if (!$itemMeta || $itemMeta['type'] != mt\Item::HERO_TYPE) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - } - } else if ($part == 2) { - if ($hasSpecHero) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - $tokenType = Nft::EQUIP_TYPE; - if (!mt\Item::canMixGun($tokenIds)) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - if ($hasSpecGun) { - $itemMeta = mt\Item::get($itemId); - if (!$itemMeta || $itemMeta['type'] != mt\Item::GUN_TYPE) { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; - } - } - } else { - myself()->_rspErr(1, 'token_ids paramaer error'); - return; } $tokenId = BuyRecord::genOrderId diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 0c88dd98..d2650a4a 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -275,8 +275,8 @@ class Item { return $itemMeta['type'] == self::FRAGMENT_TYPE; } - public static function canMixHero($itemIds) { - $ok = true; + public static function groupFragment($tokenIds, &$heros, &$guns, &$specHeros, &$specGuns) + { $heroItemIds = array( 110110, 110120, @@ -287,23 +287,6 @@ class Item { 110170, 110180 ); - foreach ($heroItemIds as $itemId1) { - $found = false; - foreach ($itemIds as $itemId2) { - if ($itemId1 == $itemId2) { - $found = true; - break; - } - } - if (!$found) { - return false; - } - } - return $ok; - } - - public static function canMixGun($itemIds) { - $ok = true; $gunItemIds = array( 110210, 110220, @@ -314,19 +297,29 @@ class Item { 110270, 110280 ); - foreach ($gunItemIds as $itemId1) { - $found = false; - foreach ($itemIds as $itemId2) { - if ($itemId1 == $itemId2) { - $found = true; - break; - } + foreach ($tokenIds as $tokenId) { + if (in_array($tokenId, $heroItemIds)) { + array_push($heros, $tokenId); + } + if (in_array($tokenId, $gunItemIds)) { + array_push($gun, $tokenId); + } + switch ($tokenId) { + case 110100: + { + array_push($specHeros, $tokenId); + } + break; + case 110200: + { + array_push($gunHeros, $tokenId); + } + break; + default: + { } - if (!$found) { - return false; } } - return $ok; } protected static function getMetaList()