1
This commit is contained in:
parent
fb18ab8afb
commit
cb0ab1ceb8
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user