67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class Dailyselection
|
|
{
|
|
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
public static function randomBySlot($slot)
|
|
{
|
|
self::mustBeSlotGroupHash();
|
|
$metas = getXVal(self::$slotGroupHash, $slot);
|
|
if (empty($metas)) {
|
|
return null;
|
|
}
|
|
$totalWeight = 0;
|
|
foreach ($metas as $meta) {
|
|
$totalWeight += $meta['weight'];
|
|
}
|
|
if ($totalWeight > 0) {
|
|
$currWeight = 0;
|
|
$rnd = rand() % $totalWeight;
|
|
foreach ($metas as $meta) {
|
|
$currWeight += $meta['weight'];
|
|
if ($currWeight > $rnd) {
|
|
return $meta;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('Dailyselection@Dailyselection.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static function mustBeSlotGroupHash()
|
|
{
|
|
if (!self::$slotGroupHash) {
|
|
self::$slotGroupHash = array();
|
|
foreach (self::getMetaList() as $meta) {
|
|
$slots = explode("|", $meta['slot']);
|
|
foreach ($slots as $slot) {
|
|
if (!getXVal(self::$slotGroupHash, $slot)) {
|
|
self::$slotGroupHash[$slot] = array();
|
|
}
|
|
array_push(self::$slotGroupHash[$slot], $meta);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static $slotGroupHash;
|
|
protected static $metaList;
|
|
|
|
}
|