Ivor Barhansky 2022-02-01 17:13:17 +00:00
parent 7bafd5cf10
commit 1bbefb9d8c

42
Home.md

@ -20,48 +20,6 @@ MARIADB 10+
* https://github.com/WalkWeb/Browser-MMORPG-Level-System
* https://habrahabr.ru/post/123391/
### Дроп итемов с шансом выпадения
```PHP
<?php
function numberOfDecimals($value)
{
if ((int)$value == $value) {
return 0;
}
else if (! is_numeric($value)) {
return false;
}
return strlen($value) - strrpos($value, '.') - 1;
}
function roulette($items)
{
$sumOfPercents = 0;
foreach($items as $itemsPercent) {
$sumOfPercents += $itemsPercent;
}
$decimals = numberOfDecimals($sumOfPercents);
$multiplier = 1;
for ($i=0; $i < $decimals; $i++) {
$multiplier *= 10;
}
$sumOfPercents *= $multiplier;
$rand = rand(1, $sumOfPercents);
$rangeStart = 1;
foreach($items as $itemKey => $itemsPercent) {
$rangeFinish = $rangeStart + ($itemsPercent * $multiplier);
if($rand >= $rangeStart && $rand <= $rangeFinish) {
return $itemKey;
}
$rangeStart = $rangeFinish + 1;
}
}
$items = array('item-1' => 0.25, 'item-2' => 0.5, 'item-3' => 5, 'item-4' => 4.25333);
echo roulette($items);
```
### Принцип модераторской затычки прямо из чата
```PHP