Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/4 currencies #13

Merged
merged 2 commits into from May 12, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Currency handling, and currency transfer handling

  • Loading branch information...
johnothecoder committed May 12, 2019
commit 53bffcb059656a886c0268f36bed3ec194f8e9f7
@@ -0,0 +1,59 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:53
*/
namespace JohnoTheCoder\MafiaOnline\Data\Model\Game;
/**
* Class Transfer
* @package JohnoTheCoder\MafiaOnline\Data\Model\Game
*/
class Transfer extends Model
{
public $fillable = [
'from_character_id',
'to_character_id',
'currency',
'amount'
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function sender()
{
return $this->belongsTo(Character::class, 'from_character_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function recipient()
{
return $this->belongsTo(Character::class, 'to_character_id');
}
/**
* @param Character $from
* @param Character $to
* @param string $currency
* @param int $amount
* @return $this
*/
public function setDetails(Character $from, Character $to, string $currency, int $amount)
{
$this->from_character_id = $from->id;
$this->to_character_id = $to->id;
$this->currency = $currency;
$this->amount = $amount;
$this->save();
$this->refresh();
return $this;
}
}
@@ -0,0 +1,61 @@
<?php
namespace JohnoTheCoder\MafiaOnline\Events\Game;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use JohnoTheCoder\MafiaOnline\Data\Model\Game\Character;
use JohnoTheCoder\MafiaOnline\Data\Model\Game\Rank;
class CurrencyTransferred
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var Character
*/
public $from;
/**
* @var Character
*/
public $to;
/**
* @var string
*/
public $currency;
/**
* @var int
*/
public $amount;
public function __construct(
Character $from,
Character $to,
string $currency,
int $amount
){
$this->from = $from;
$this->to = $to;
$this->currency = $currency;
$this->amount = $amount;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
@@ -19,12 +19,12 @@ class RankUp
/**
* @var Character
*/
protected $character;
public $character;
/**
* @var Rank
*/
protected $rank;
public $rank;
/**
* RankUp constructor.
@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:15
*/
namespace JohnoTheCoder\MafiaOnline\Exceptions\Game;
class CurrencyNotOnHandException extends \Exception
{
}
@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:14
*/
namespace JohnoTheCoder\MafiaOnline\Exceptions\Game;
class InvalidCurrencyAmountSpecifiedException extends \Exception
{
}
@@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:11
*/
namespace JohnoTheCoder\MafiaOnline\Exceptions\Game;
/**
* Class InvalidCurrencyException
* @package JohnoTheCoder\MafiaOnline\Exceptions\Game
*/
class InvalidCurrencyException extends \Exception
{
}
@@ -0,0 +1,71 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:08
*/
namespace JohnoTheCoder\MafiaOnline\Game\Contracts;
use JohnoTheCoder\MafiaOnline\Data\Model\Game\Character;
use JohnoTheCoder\MafiaOnline\Exceptions\Game\CurrencyNotOnHandException;
use JohnoTheCoder\MafiaOnline\Exceptions\Game\InvalidCurrencyAmountSpecifiedException;
use JohnoTheCoder\MafiaOnline\Exceptions\Game\InvalidCurrencyException;
/**
* Interface HandlesCurrency
* @package JohnoTheCoder\MafiaOnline\Game\Contracts
*/
interface HandlesCurrency
{
const CASH = 'cash';
const BONDS = 'bearer_bonds';
const BULLETS = 'bullets';
/**
* @param Character $character
* @param string $currency
* @param int $amount
* @throws InvalidCurrencyException
* @throws InvalidCurrencyAmountSpecifiedException
* @return mixed
*/
public function creditCurrency(Character $character, string $currency, int $amount): void;
/**
* @param Character $character
* @param string $currency
* @param int $amount
* @throws InvalidCurrencyException
* @throws InvalidCurrencyAmountSpecifiedException
* @throws CurrencyNotOnHandException
* @return mixed
*/
public function debitCurrency(Character $character, string $currency, int $amount): void;
/**
* @param Character $character
* @param string $currency
* @param int $amount
* @throws InvalidCurrencyException
* @return bool
*/
public function characterHasOnHand(Character $character, string $currency, int $amount): bool;
/**
* @param string $currency
* @return bool
* @throws InvalidCurrencyException
*/
public function validateCurrency(string $currency): bool;
/**
* @param int $amount
* @return bool
* @throws InvalidCurrencyAmountSpecifiedException
*/
public function validateAmount(int $amount): bool;
}
@@ -0,0 +1,36 @@
<?php
/**
* Created by PhpStorm.
* User: matthewjohnson
* Date: 12/05/2019
* Time: 18:10
*/
namespace JohnoTheCoder\MafiaOnline\Game\Contracts;
use JohnoTheCoder\MafiaOnline\Data\Model\Game\Transfer;
use JohnoTheCoder\MafiaOnline\Exceptions\Game\InvalidCurrencyException;
use JohnoTheCoder\MafiaOnline\Data\Model\Game\Character;
/**
* Interface TransfersCurrency
* @package JohnoTheCoder\MafiaOnline\Game\Contracts
*/
interface TransfersCurrency
{
/**
* @param Character $from
* @param Character $to
* @param string $currency
* @param int $amount
* @throws InvalidCurrencyException
* @return mixed
*/
public function transfer(Character $from, Character $to, string $currency, int $amount);
/**
* @return Transfer
*/
public function getTransferRecord(): ?Transfer;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.