|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace eXpansion\Framework\GameCurrencyBundle\ChatCommand; |
|
5
|
|
|
|
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\ChatNotification; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\ChatCommand\AbstractChatCommand; |
|
8
|
|
|
use eXpansion\Framework\Core\Storage\GameDataStorage; |
|
9
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
10
|
|
|
use eXpansion\Framework\GameCurrencyBundle\Services\GameCurrencyService; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Donate |
|
17
|
|
|
* |
|
18
|
|
|
* @package eXpansion\Framework\GameCurrencyBundle\ChatCommand; |
|
19
|
|
|
* @author oliver de Cramer <[email protected]> |
|
20
|
|
|
* @author reaby |
|
21
|
|
|
*/ |
|
22
|
|
|
class Donate extends AbstractChatCommand |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var GameCurrencyService |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $currencyService; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var GameDataStorage |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $gameDataStorage; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ChatNotification |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $chatNotification; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var PlayerStorage |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $playerStorage; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* ScriptPanel constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param $command |
|
48
|
|
|
* @param array $aliases |
|
49
|
|
|
* @param GameCurrencyService $currencyService |
|
50
|
|
|
* @param GameDataStorage $gameDataStorage |
|
51
|
|
|
* @param ChatNotification $chatNotification |
|
52
|
|
|
* @param PlayerStorage $playerStorage |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct( |
|
55
|
|
|
$command, |
|
56
|
|
|
array $aliases = [], |
|
57
|
|
|
GameCurrencyService $currencyService, |
|
58
|
|
|
GameDataStorage $gameDataStorage, |
|
59
|
|
|
ChatNotification $chatNotification, |
|
60
|
|
|
PlayerStorage $playerStorage |
|
61
|
|
|
) { |
|
62
|
|
|
parent::__construct($command, $aliases); |
|
63
|
|
|
$this->currencyService = $currencyService; |
|
64
|
|
|
$this->gameDataStorage = $gameDataStorage; |
|
65
|
|
|
$this->chatNotification = $chatNotification; |
|
66
|
|
|
$this->playerStorage = $playerStorage; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritdoc |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function configure() |
|
73
|
|
|
{ |
|
74
|
|
|
parent::configure(); |
|
75
|
|
|
|
|
76
|
|
|
$this->inputDefinition->addArgument( |
|
77
|
|
|
new InputArgument('amount', InputArgument::REQUIRED, "Amount to donate") |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritdoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public function execute($login, InputInterface $input) |
|
85
|
|
|
{ |
|
86
|
|
|
$amount = $input->getArgument("amount"); |
|
87
|
|
|
$bill = $this->currencyService->createBill( |
|
88
|
|
|
$login, |
|
89
|
|
|
$amount, |
|
90
|
|
|
$this->gameDataStorage->getSystemInfo()->serverLogin, |
|
91
|
|
|
"" |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
if (!$bill) { |
|
95
|
|
|
$this->chatNotification->sendMessage( |
|
96
|
|
|
'expansion_game_currency.donate.error', |
|
97
|
|
|
$login, |
|
98
|
|
|
['error' => "Bill could't be created"] |
|
99
|
|
|
); |
|
100
|
|
|
return; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$this->currencyService->sendBill( |
|
104
|
|
|
$bill, |
|
105
|
|
|
function () use ($bill, $login) { |
|
106
|
|
|
$player = $this->playerStorage->getPlayerInfo($login); |
|
107
|
|
|
$amount = $bill->getAmount(); |
|
108
|
|
|
$this->chatNotification->sendMessage( |
|
109
|
|
|
'expansion_game_currency.donate.success', |
|
110
|
|
|
null, |
|
111
|
|
|
['amount' => $amount, 'nickname' => $player->getNickName()] |
|
112
|
|
|
); |
|
113
|
|
|
}, |
|
114
|
|
|
function ($error) use ($login) { |
|
115
|
|
|
$this->chatNotification->sendMessage( |
|
116
|
|
|
'expansion_game_currency.donate.error', |
|
117
|
|
|
$login, |
|
118
|
|
|
['error' => $error] |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
} |