-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
/* | ||
Author:Irfa Ardiansyah <[email protected]> | ||
Simple Items Gatcha with PHP | ||
v2.1 | ||
https://github.com/irfaardy/php-gacha | ||
*/ | ||
namespace Irfa\Gatcha; | ||
|
||
|
@@ -12,32 +14,68 @@ class Roll extends Roulette { | |
|
||
private static $items; | ||
|
||
/** | ||
* Put items to $items. | ||
*/ | ||
public static function put($items) | ||
{ | ||
self::$items = $items; | ||
|
||
return new static(); | ||
} | ||
|
||
/** | ||
* Spin Roullete. | ||
* | ||
* @return string | ||
*/ | ||
public static function spin() | ||
{ | ||
return self::getItem(); | ||
} | ||
|
||
/** | ||
* Spin Roullete json result. | ||
* | ||
* @return json | ||
*/ | ||
public static function jsonSpin() | ||
{ | ||
$ret = self::getItem(); | ||
return self::jsonItem($ret); | ||
} | ||
|
||
/** | ||
* Add dropup rate. | ||
* | ||
* @param string $item | ||
* @param float $rate | ||
* @return mixed | ||
*/ | ||
public static function dropUp($items, $rate) | ||
{ | ||
$items_bucket = self::$items; | ||
self::putDropUp(self::itemDropUp($items_bucket, $items, $rate)); | ||
return new static(); | ||
} | ||
|
||
/** | ||
* Get Spinned items. | ||
* | ||
* @return string | ||
*/ | ||
private static function getItem() { | ||
$ret = self::get(self::$items); | ||
self::$items = null; | ||
return $ret; | ||
} | ||
|
||
/** | ||
* put dropup item to $items variable. | ||
* | ||
* @param array $arr | ||
* @return void | ||
*/ | ||
private static function putDropUp($arr) { | ||
foreach ($arr as $k => $v) { | ||
self::$items[$k] = $v; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,37 @@ | |
/* | ||
Author:Irfa Ardiansyah <[email protected]> | ||
Simple Items Gatcha with PHP | ||
v2.1 | ||
https://github.com/irfaardy/php-gacha | ||
*/ | ||
namespace Irfa\Gatcha\Roulette; | ||
|
||
use Exception; | ||
|
||
class RateUp { | ||
|
||
/** | ||
* Add drop up rate to items. | ||
* | ||
* @param mixed $item_list | ||
* @param array $items | ||
* @param float $rate | ||
* @return array | ||
*/ | ||
protected static function _itemDropUp($item_list, $items, $rate) | ||
{ | ||
$rt = new RateUp(); | ||
return $rt->calc_rate($item_list, $items, $rate); | ||
} | ||
|
||
/** | ||
* Calculate Drop Up Rate. | ||
* | ||
* @param mixed $item_list | ||
* @param array $items | ||
* @param float $rate | ||
* @return array | ||
*/ | ||
private function calc_rate($item_list, $items, $rate) | ||
{ | ||
$item = []; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,46 @@ | |
/* | ||
Author:Irfa Ardiansyah <[email protected]> | ||
Simple Items Gatcha with PHP | ||
v2.1 | ||
https://github.com/irfaardy/php-gacha | ||
*/ | ||
namespace Irfa\Gatcha\Roulette; | ||
|
||
use Exception; | ||
use Irfa\Gatcha\Roulette\RateUp; | ||
|
||
class Roulette extends RateUp { | ||
|
||
|
||
/** | ||
* encode to Json. | ||
* | ||
* @param string $dt | ||
* @return json | ||
*/ | ||
protected static function jsonItem($dt) { | ||
$data['data'] = ['item' => $dt]; | ||
return json_encode($data); | ||
} | ||
|
||
/** | ||
* Add drop up rate to items. | ||
* | ||
* @param mixed $item_list | ||
* @param array $items | ||
* @param float $rate | ||
* @return array | ||
*/ | ||
protected static function itemDropUp($item_list, $items, $rate) | ||
{ | ||
return self::_itemDropUp($item_list, $items, $rate); | ||
} | ||
|
||
/** | ||
* Get Item. | ||
* | ||
* @param array $item | ||
* @return string | ||
*/ | ||
protected static function get($items) { | ||
if (is_array($items)) | ||
{ | ||
|