irfa / php-gatcha
使用 PHP 实现简单的物品 Gatcha
v2.1
2020-07-06 15:53 UTC
Requires
- php: >=5.4.0
- ext-json: *
This package is auto-updated.
Last update: 2024-09-22 07:49:01 UTC
README
此包适用于制作具有您指定概率的购物券、游戏物品等的 Gatcha 或抽奖
🛠️ 使用 Composer 安装
composer require irfa/php-gatcha
您可以从这里获取 Composer here
Laravel 中的使用
打开 config/app.php添加别名(可选)
'aliases' => [ ... 'Gatcha' => Irfa\Gatcha\Roll::class, ... ];
示例
... use Gatcha class Example { function index() { return Gatcha::put([ 'Item 1' => 29.4, 'Item 2' => 0.3])->spin(); } }
在 PHP 本地使用
require_once "vendor/autoload.php"; 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 ]; $item_get = Roll::put($items)->spin(); echo "Congratulations you get ".$item_get;
💻 使用 DropUp
此函数用于某些条件,如事件、奖金等。
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 返回
如果您想返回 JSON
Roll::put($items)->jsonSpin();
结果
{ "data":{ "item":"SomeItem" } }
如何贡献?
- 分支它 (https://github.com/irfaardy/php-gatcha/fork)
- 提交您的更改 (
git commit -m '一些新特性'
) - 推送到分支 (
git push origin x.x
) - 创建一个新的 Pull Request
问题
如果您发现问题或有错误,请在此处创建新问题 https://github.com/irfaardy/php-gatcha/issues/new