This commit is contained in:
aozhiwei 2022-04-04 10:29:36 +08:00
parent 840236d613
commit b6546f76d8
2 changed files with 76 additions and 0 deletions

56
webapp/mt/BlindBox.php Normal file
View File

@ -0,0 +1,56 @@
<?php
namespace mt;
class BlindBox {
public static function randItem($boxId, $groupId)
{
self::mustBeGroupHash();
$key = $boxId . '_' . $groupId;
$spaceKey = $key . '_rand_space';
$spaceVal = getXVal(self::$groupHash, $spaceKey, 0);
$rndVal = $spaceVal > 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;
};

View File

@ -261,4 +261,24 @@ class MarketService extends BaseService {
return str_replace("\n", '\n', $str); 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,
));
}
}
}
} }