|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Smr\Pages\Player; |
|
4
|
|
|
|
|
5
|
|
|
use AbstractSmrPlayer; |
|
6
|
|
|
use Globals; |
|
7
|
|
|
use Plotter; |
|
8
|
|
|
use Smr\Page\PlayerPageProcessor; |
|
9
|
|
|
use Smr\Request; |
|
10
|
|
|
use Smr\TransactionType; |
|
11
|
|
|
use SmrPort; |
|
12
|
|
|
|
|
13
|
|
|
class CargoDumpProcessor extends PlayerPageProcessor { |
|
14
|
|
|
|
|
15
|
|
|
public function __construct( |
|
16
|
|
|
private readonly int $goodID, |
|
17
|
|
|
private readonly ?int $goodAmount = null |
|
18
|
|
|
) {} |
|
19
|
|
|
|
|
20
|
|
|
public function build(AbstractSmrPlayer $player): never { |
|
21
|
|
|
$ship = $player->getShip(); |
|
22
|
|
|
$sector = $player->getSector(); |
|
23
|
|
|
|
|
24
|
|
|
$good_id = $this->goodID; |
|
25
|
|
|
$good_name = Globals::getGoodName($good_id); |
|
26
|
|
|
$amount = $this->goodAmount ?? Request::getInt('amount'); |
|
27
|
|
|
|
|
28
|
|
|
if ($amount <= 0) { |
|
29
|
|
|
create_error('You must actually enter an amount > 0!'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ($player->isLandedOnPlanet()) { |
|
33
|
|
|
create_error('You can\'t dump cargo while on a planet!'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ($player->getTurns() < TURNS_TO_DUMP_CARGO) { |
|
37
|
|
|
create_error('You do not have enough turns to dump cargo!'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
//lets make sure there is actually that much on the ship |
|
41
|
|
|
if ($amount > $ship->getCargo($good_id)) { |
|
42
|
|
|
create_error('You can\'t dump more than you have.'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if ($sector->offersFederalProtection()) { |
|
46
|
|
|
create_error('You can\'t dump cargo in a Federal Sector!'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$msg = 'You have jettisoned <span class="yellow">' . $amount . '</span> ' . pluralise($amount, 'unit', false) . ' of ' . $good_name; |
|
50
|
|
|
|
|
51
|
|
|
if ($player->getExperience() > 0) { |
|
52
|
|
|
// If they have any experience left, lose exp |
|
53
|
|
|
|
|
54
|
|
|
// get the distance |
|
55
|
|
|
$x = Globals::getGood($good_id); |
|
56
|
|
|
$x['TransactionType'] = TransactionType::Sell; |
|
57
|
|
|
$good_distance = Plotter::findDistanceToX($x, $sector, true); |
|
58
|
|
|
if (is_object($good_distance)) { |
|
|
|
|
|
|
59
|
|
|
$good_distance = $good_distance->getDistance(); |
|
60
|
|
|
} |
|
61
|
|
|
$good_distance = max(1, $good_distance); |
|
62
|
|
|
|
|
63
|
|
|
// Don't lose more exp than you have |
|
64
|
|
|
$lost_xp = min( |
|
65
|
|
|
$player->getExperience(), |
|
66
|
|
|
IRound(SmrPort::getBaseExperience($amount, $good_distance)) |
|
|
|
|
|
|
67
|
|
|
); |
|
68
|
|
|
$player->decreaseExperience($lost_xp); |
|
69
|
|
|
$player->increaseHOF($lost_xp, ['Trade', 'Experience', 'Jettisoned'], HOF_PUBLIC); |
|
70
|
|
|
|
|
71
|
|
|
$msg .= ' and have lost <span class="exp">' . $lost_xp . '</span> experience.'; |
|
72
|
|
|
// log action |
|
73
|
|
|
$player->log(LOG_TYPE_TRADING, 'Dumps ' . $amount . ' of ' . $good_name . ' and loses ' . $lost_xp . ' experience'); |
|
74
|
|
|
} else { |
|
75
|
|
|
// No experience to lose, so damage the ship |
|
76
|
|
|
$damage = ICeil($amount / 5); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
// Don't allow ship to be destroyed dumping cargo |
|
79
|
|
|
if ($ship->getArmour() <= $damage) { |
|
80
|
|
|
create_error('Your ship is too damaged to risk dumping cargo!'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$ship->decreaseArmour($damage); |
|
84
|
|
|
|
|
85
|
|
|
$msg .= '. Due to your lack of piloting experience, the cargo pierces the hull of your ship as you clumsily try to jettison the goods through the bay doors, destroying <span class="red">' . $damage . '</span> ' . pluralise($damage, 'plate', false) . ' of armour!'; |
|
86
|
|
|
// log action |
|
87
|
|
|
$player->log(LOG_TYPE_TRADING, 'Dumps ' . $amount . ' of ' . $good_name . ' and takes ' . $damage . ' armour damage'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// take turn |
|
91
|
|
|
$player->takeTurns(TURNS_TO_DUMP_CARGO, TURNS_TO_DUMP_CARGO); |
|
92
|
|
|
|
|
93
|
|
|
$ship->decreaseCargo($good_id, $amount); |
|
94
|
|
|
$player->increaseHOF($amount, ['Trade', 'Goods', 'Jettisoned'], HOF_ALLIANCE); |
|
95
|
|
|
|
|
96
|
|
|
$container = new CurrentSector(message: $msg); |
|
97
|
|
|
$container->go(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|