This commit is contained in:
aozhiwei 2022-09-17 14:50:14 +08:00
parent fb18ab8afb
commit cb0ab1ceb8

View File

@ -511,7 +511,22 @@ class BattleDataService extends BaseService {
private function randWeight($items)
{
$spaces = array();
$weights = array();
{
$weight = 0;
foreach ($items as $item) {
$weight += (int)($item * 10000);
array_push($weights, $weight);
}
}
if (count($weights) > 0) {
$rnd = rand(0, $weights[count($weights) - 1]);
for ($i = 0; $i < count($weights); ++$i) {
if ($rnd <= $weights[$i]) {
return $i;
}
}
}
return -1;
}