From b6546f76d8198c0ec78c27734ceea56bafe88b75 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 4 Apr 2022 10:29:36 +0800 Subject: [PATCH] 1 --- webapp/mt/BlindBox.php | 56 +++++++++++++++++++++++++++++++ webapp/services/MarketService.php | 20 +++++++++++ 2 files changed, 76 insertions(+) create mode 100644 webapp/mt/BlindBox.php diff --git a/webapp/mt/BlindBox.php b/webapp/mt/BlindBox.php new file mode 100644 index 00000000..4acde085 --- /dev/null +++ b/webapp/mt/BlindBox.php @@ -0,0 +1,56 @@ + 0 ? rand() % $spaceVal : 0; + + $groups = getXVal(self::$groupHash, $key); + foreach ($groups as $group) { + if ($rndVal <= $group['_weight']) { + return $group; + } + } + return null; + } + + protected static function mustBeGroupHash() + { + if (is_null(self::$groupHash)) { + self::$groupHash = array(); + foreach (self::getMetaList() as $meta) { + $key = $meta['box_id'] . '_' . $meta['group_id']; + $spaceKey = $key . '_rand_space'; + + $spaceVal = getXVal(self::$groupHash, $spaceKey, 0) + $meta['weight']; + self::$groupHash[$spaceKey] = $spaceVal; + + $meta['_weight'] = $spaceVal; + if (!getXVal(self::$groupHash, $key)) { + self::$groupHash[$key] = array(); + } + array_push(self::$groupHash[$key], $meta); + } + } + } + + protected static function getMetaList() + { + if (!self::$metaList) { + self::$metaList = getMetaTable('blindBox@blindBox.php'); + } + return self::$metaList; + } + + protected static $metaList; + protected static $groupHash; + +}; diff --git a/webapp/services/MarketService.php b/webapp/services/MarketService.php index a6f49448..e86eb94e 100644 --- a/webapp/services/MarketService.php +++ b/webapp/services/MarketService.php @@ -261,4 +261,24 @@ class MarketService extends BaseService { return str_replace("\n", '\n', $str); } + public static function openBox($itemMeta, &$items) + { + if ($itemMeta['type'] == mt\Item::BLIND_BOX_TYPE) { + //group1:100|group2:100|group3:100 + $groups = StrHelper::parseList($meta['param1'], array('|', ':')); + foreach ($groups as $group) { + + } + } else { + $tokenType = Nft::getTokenType($itemMeta); + if ($tokenType != Nft::NONE_TYPE) { + array_push($items, array( + 'need' => 1, + 'item_id' => $itemMeta['id'], + 'token_type' => $tokenType, + )); + } + } + } + }