1
This commit is contained in:
parent
840236d613
commit
b6546f76d8
56
webapp/mt/BlindBox.php
Normal file
56
webapp/mt/BlindBox.php
Normal 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;
|
||||
|
||||
};
|
@ -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,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user