プラグイン開発者向けのガチャ用ライブラリ
PHP 8.0
PocketMine-MP 4.0.0
- VirionToolsを
plugins
の中に配置します - サーバーを再起動します
plugin_data/VirionTools/builds
にダウンロードしたGacha.phar
を配置します- コマンドラインより、
$ iv Gacha [導入したいプラグインの名前]
を実行します
[サンプルコード]
https://github.com/Rark7040/GachaExample
合計の確率が100%に満たないもしくはそれより多い場合、
全ての排出アイテムに対し、比率的に均等に確率が調整されます
$gacha = new Gacha(
'TestGacha',
'example',
new GachaMessages(),
new RandomItemTable(
PMGachaItem::create(Rarity::create('N', 60), VanillaItems::COAL()),
PMGachaItem::create(Rarity::create('R', 20), VanillaItems::IRON_INGOT()),
PMGachaItem::create(Rarity::create('SR', 8), VanillaItems::GOLD_INGOT()),
PMGachaItem::create(Rarity::create('SSR', 3), VanillaItems::DIAMOND()),
PMGachaItem::create(Rarity::create('UR', 0.6), VanillaItems::EMERALD()),
),
new ExampleTicket()
);
$gacha->roll($player, 1);
Other Code
<?php
declare(strict_types=1);
namespace rarkhopper\gacha_example;
use pocketmine\item\Item;
use pocketmine\player\Player;
use pocketmine\world\sound\PopSound;
use rarkhopper\gacha\IGachaItem;
use rarkhopper\gacha\IRarity;
use rarkhopper\gacha\Rarity;
class PMGachaItem implements IGachaItem{
protected Rarity $rarity;
protected Item $item;
public static function create(Rarity $rarity, Item $item):static{
$instance = new static;
$instance->rarity = $rarity;
$instance->item = $item;
return $instance;
}
public function getRarity():IRarity{
return $this->rarity;
}
public function giveItem(Player $player):void{
$player->sendMessage('['.$this->getRarity()->getName().'] '.$this->item->getName());
$player->getInventory()->addItem(clone $this->item);
$world = $player->getWorld();
$world->addSound($player->getPosition(), new PopSound());
}
}
<?php
declare(strict_types=1);
namespace rarkhopper\gacha_example;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
use rarkhopper\gacha\ITicket;
class ExampleTicket implements ITicket{
public function has(Player $player, int $count):bool{
return $player->getInventory()->contains(VanillaItems::GOLD_NUGGET()->setCount($count));
}
public function consume(Player $player, int $count):void{
$player->getInventory()->removeItem(VanillaItems::GOLD_NUGGET()->setCount($count));
}
}