irfa / php-gatcha
Simple Items Gatcha with PHP
Fund package maintenance!
Patreon
Ko Fi
buymeacoff.ee/irfaardy
Installs: 2 190
Dependents: 0
Suggesters: 0
Security: 0
Stars: 33
Watchers: 3
Forks: 14
Open Issues: 1
Type:package
Requires
- php: >=5.4.0
- ext-json: *
This package is auto-updated.
Last update: 2024-11-22 08:07:13 UTC
README
This package is useful for making gacha or lottery for shopping coupons, game items, etc. with the percentage of possibilities that you have specified
🛠️ Installation with Composer
composer require irfa/php-gatcha
You can get Composer here
Usage in Laravel
Open config/app.phpadd aliases (optional)
'aliases' => [ ... 'Gatcha' => Irfa\Gatcha\Roll::class, ... ];
Example:
... use Gatcha class Example { function index() { return Gatcha::put([ 'Item 1' => 29.4, 'Item 2' => 0.3])->spin(); } }
Usage in PHP Native
require_once "vendor/autoload.php"; use Irfa\Gatcha\Roll;`
💻 Basic Usage
$items = [ 'common ITEM1' => 70, // 70% chance 'Rare ITEM 2' => 29.4, // 29.4% chance 'Super Rare ITEM' => 0.3, // 0.3% chance 'Super Rare ITEM 2' => 0.3, 'Super Super Rare ITEM' => 0.003, // 0.003% chance ]; $item_get = Roll::put($items)->spin(); echo "Congratulations you get ".$item_get;
💻 Using DropUp
This function is used for certain conditions such as events, bonuses, etc.
use Irfa\Gatcha\Roll; $items = [ 'common ITEM1' => 70, // 70% chance 'Rare ITEM 2' => 29.4, // 29.4% chance 'Super Rare ITEM' => 0.3, // 0.3% chance 'Super Rare ITEM 2' => 0.3, 'Super Super Rare ITEM' => 0.003, // 0.003% chance ]; Roll::put($items) if(date('Y-m-d') == '2020-03-21') //example event date { Roll::dropUp(['Super Rare ITEM', 'Super Rare ITEM 2'], 200)//Drop up rate 200% ->dropUp('common ITEM1', 300); //Drop up rate 300% //Parameters items (items index in array), rate in percent } $item_get = Roll::spin(); echo "Congratulations you get ".$item_get;
💻 JSON Return
If you want return to json
Roll::put($items)->jsonSpin();
Result:
{ "data":{ "item":"SomeItem" } }
How to Contributing?
- Fork it (https://github.com/irfaardy/php-gatcha/fork)
- Commit your changes (
git commit -m 'some New Feature'
) - Push to the branch (
git push origin x.x
) - Create a new Pull Request
Issue
If you found issues or bug please create new issues here https://github.com/irfaardy/php-gacha/issues/new