Giter VIP home page Giter VIP logo

php-gacha's Introduction

๐ŸŽฒSimple Items Gacha with PHP

Code Climate Maintainabillity Scrutinizer Code Quality Build Status Latest Stable Version License PHP Composer time tracker

Buy Me A Coffee


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.php
add 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?

  1. Fork it (https://github.com/irfaardy/php-gatcha/fork)
  2. Commit your changes (git commit -m 'some New Feature')
  3. Push to the branch (git push origin x.x)
  4. 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


php-gacha's People

Contributors

irfaardy avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-gacha's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.