Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ PICASSO_IMAGE_GENERATION_MODEL=dall-e-2
PICASSO_IMAGE_QTY=1

JOKENPO_TIMER=15
JACKPOT_TIMER=15
179 changes: 179 additions & 0 deletions app/Entities/JackpotEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace App\Entities;

class JackpotEntity
{
/**
* The game ID.
*
* @var int $gameId
*/

/**
* The possible multipliers.
*
* @var array $rules
*/
public $multipliers = [
'zebra' => 0,
'pinguin' => 1,
'borboleta' => 2,
'macaco' => 3,
'coruja' => 4
];

/**
* The game probabilities.
*
* @var array $probabilities
*/
public $probabilities = [
'zebra' => [0, 45], // 45% of chance to win
'pinguin' => [45, 65], // 20% of chance to win
'borboleta' => [65, 85], // 20% of chance to win
'macaco' => [85, 95], // 10% of chance to win
'coruja' => [95, 100] // 5% of chance to win
];

/**
* The possible labels.
*
* @var array $labels
*/
public $labels = [
'zebra' => '🦓',
'pinguin' => '🐧',
'borboleta' => '🦋',
'macaco' => '🐒',
'coruja' => '🦉'
];

/**
* The possible messages.
*
* @var array $messages
*/
public $messages = [
'zebra' => 'Vish, deu zebra! Perdeu suas coins! 💸',
'pinguin' => 'Opa deu pinguin! Você manteve suas coins para o proximo jogo!',
'borboleta' => 'Borboleta chegando dobrando suas coins! 💵💵',
'macaco' => 'Macaco chegou pulando e com o rolex no pulso **triplicando suas coins**! 💰💰',
'coruja' => '💲😎 Você conseguiu a maior recompensa! **Suas coins x4** 😎💲'
];

/**
* The possible options.
*
* @var array $options
*/
public $options = ['pinguin', 'borboleta', 'macaco', 'coruja'];

/**
* The game result.
*
* @var string $gameResult
*/
public $gameResult;

/**
* Movements of all players
* @var JackpotPlayerEntity[] $players
*/
public $players = [];

public function __construct(public int $gameId) {}

/**
* Get the game ID.
*
* @return int
*/
public function getId()
{
return $this->gameId;
}

/**
* Get the emoji for a bet.
*
* @param string $move
* @return string
*/
public function getEmoji(string $bet): string
{
return $this->labels[$bet];
}

/**
* Set the player's bet.
*
* @param JackpotPlayerEntity $player
* @return false|array
*/
public function setPlayerBet(JackpotPlayerEntity $player): bool
{
foreach ($this->players as $bet) {
if ($bet->getDiscordId() === $player->getDiscordId()) {
return false;
}
}

$this->players[] = $player;
return true;
}

/**
* Get the players.
*
* @return array
*/
public function getPlayers(): array
{
return $this->players;
}

public function getPlayerMultiplier($player): string
{
$playerBet = $player->getBet();
$gameMultiplier = $this->multipliers[$player->getBet()];
return $playerBet * $gameMultiplier;
}

public function getGameResult(): string
{
return $this->gameResult;
}

public function getGameMultiplier(): string
{
return $this->multipliers[$this->gameResult];
}

/**
* Set the game result.
*
* @return string
*/
public function setGameResult()
{
$result = '';

// generate a random number between 0 and 99
$randomNumber = mt_rand(0, 99);

// loop through the probabilities and check if the random number is less than the probability
foreach ($this->probabilities as $label => $probability) {
if ($randomNumber >= $probability[0] && $randomNumber < $probability[1]) {
$result = $label;
}
}

$this->gameResult = $result;
}

public function getGameMessage(): string
{
return $this->messages[$this->gameResult];
}
}
51 changes: 51 additions & 0 deletions app/Entities/JackpotPlayerEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Entities;

class JackpotPlayerEntity
{
/**
* The player ID.
*
* @var string $discordId
*/

/**
* The result of the game.
*
* @var null|string
*/
public ?string $result = null;

public function __construct(public string $discordId) {}

/**
* Get the player ID.
*
* @return string
*/
public function getDiscordId()
{
return $this->discordId;
}

/**
* Get the result of the game.
*
* @return string
*/
public function getResult()
{
return $this->result;
}

/**
* Set the result of the game.
*
* @param string $result
*/
public function setResult($result)
{
$this->result = $result;
}
}
20 changes: 20 additions & 0 deletions app/Models/Jackpot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Jackpot extends Model
{
protected $table = 'jackpots';

protected $fillable = [
'created_by',
'game_result',
];

public function created_by()
{
return $this->belongsTo(User::class, 'created_by');
}
}
27 changes: 27 additions & 0 deletions app/Models/JackpotPlayer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class JackpotPlayer extends Model
{
protected $table = 'jackpot_players';

protected $fillable = [
'jackpot_id',
'user_id',
'bet',
'result',
];

public function jackpot()
{
return $this->belongsTo(Jackpot::class, 'jackpot_id');
}

public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
}
103 changes: 103 additions & 0 deletions app/SlashCommands/JackpotCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace App\SlashCommands;

use Discord\Parts\Interactions\Interaction;
use Discord\Voice\VoiceClient;
use Laracord\Commands\SlashCommand;
use App\Repositories\UserRepository;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage;
use App\Entities\JackpotEntity;
use App\Models\Jackpot;
use App\Models\JackpotPlayer;
use App\SlashCommands\Traits\Jackpot\PlayJackpot;

class JackpotCommand extends SlashCommand
{
use PlayJackpot;

/**
* The command name.
*
* @var string
*/
protected $name = 'jackpot';

/**
* The command description.
*
* @var string
*/
protected $description = 'Tente sua sorte no Jackpot!';

/**
* The command options.
*
* @var array
*/
protected $options = [];

/**
* The permissions required to use the command.
*
* @var array
*/
protected $permissions = [];

/**
* Indicates whether the command requires admin permissions.
*
* @var bool
*/
protected $admin = false;

/**
* Indicates whether the command should be displayed in the commands list.
*
* @var bool
*/
protected $hidden = false;

/**
* The game instance.
*
* @var JokenpoEntity[]
*/
protected array $games = [];

/**
* Game timers counters.
*
* @var array
*/
protected array $counters = [];

/**
* Handle the slash command.
*
* @param \Discord\Parts\Interactions\Interaction $interaction
* @return mixed
*/
public function handle($interaction)
{
$game = new JackpotEntity(1);

$this->setGame($game);
$this->setCounter($game, env('JACKPOT_TIMER', 30));

$interaction->respondWithMessage(
$this->buildGameMessage($game)
)->then(fn() => $this->startCounter($interaction, $game));
}

/**
* The command interaction routes.
*/
public function interactions(): array
{
return [
'action:{gameId}' => fn(Interaction $interaction, int $gameId) => $this->playJackpot($interaction, $gameId),
];
}
}
Loading