1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
class SmrMines extends AbstractSmrCombatWeapon { |
4
|
|
|
|
5
|
|
|
use Traits\CombatWeaponForce; |
6
|
|
|
|
7
|
|
|
protected const TOTAL_ENEMY_MINES_MODIFIER = 25; |
8
|
|
|
protected const FED_SHIP_DAMAGE_MODIFIER = .5; |
9
|
|
|
protected const DCS_DAMAGE_MODIFIER = .75; |
10
|
|
|
|
11
|
|
|
public function __construct(int $numberOfMines) { |
12
|
|
|
$this->amount = $numberOfMines; |
13
|
|
|
$this->name = 'Mines'; |
14
|
|
|
$this->shieldDamage = 20; |
15
|
|
|
$this->armourDamage = 20; |
16
|
|
|
$this->accuracy = 100; |
17
|
|
|
$this->damageRollover = false; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getModifiedAccuracy(): float { |
21
|
|
|
return $this->getBaseAccuracy(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getModifiedForceAccuracyAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer, bool $minesAreAttacker): float { |
25
|
|
|
return $this->getModifiedForceAccuracyAgainstPlayerUsingRandom($forces, $targetPlayer, rand(1, 7) * rand(1, 7), $minesAreAttacker); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function getModifiedForceAccuracyAgainstPlayerUsingRandom(SmrForce $forces, AbstractSmrPlayer $targetPlayer, int $random, bool $minesAreAttacker): float { |
29
|
|
|
$modifiedAccuracy = $this->getModifiedAccuracy(); |
30
|
|
|
$modifiedAccuracy -= $targetPlayer->getLevelID() + $random; |
31
|
|
|
if ($minesAreAttacker) { |
32
|
|
|
$modifiedAccuracy /= pow(SmrSector::getSector($forces->getGameID(), $forces->getSectorID())->getNumberOfConnections(), 0.6); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (self::TOTAL_ENEMY_MINES_MODIFIER > 0) { |
36
|
|
|
$enemyMines = 0; |
37
|
|
|
$enemyForces = $forces->getSector()->getEnemyForces($targetPlayer); |
38
|
|
|
foreach ($enemyForces as $enemyForce) { |
39
|
|
|
$enemyMines += $enemyForce->getMines(); |
40
|
|
|
} |
41
|
|
|
$modifiedAccuracy += $enemyMines / self::TOTAL_ENEMY_MINES_MODIFIER; |
42
|
|
|
} |
43
|
|
|
return max(0, min(100, $modifiedAccuracy)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getModifiedDamageAgainstForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces): never { |
47
|
|
|
throw new Exception('This weapon should not be used in this context'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getModifiedDamageAgainstPort(AbstractSmrPlayer $weaponPlayer, SmrPort $port): never { |
51
|
|
|
throw new Exception('This weapon should not be used in this context'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getModifiedDamageAgainstPlanet(AbstractSmrPlayer $weaponPlayer, SmrPlanet $planet): never { |
55
|
|
|
throw new Exception('This weapon should not be used in this context'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getModifiedDamageAgainstPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer): never { |
59
|
|
|
throw new Exception('This weapon should not be used in this context'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getModifiedPortDamageAgainstPlayer(AbstractSmrPort $port, AbstractSmrPlayer $targetPlayer): never { |
63
|
|
|
throw new Exception('This weapon should not be used in this context'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getModifiedPlanetDamageAgainstPlayer(SmrPlanet $planet, AbstractSmrPlayer $targetPlayer): never { |
67
|
|
|
throw new Exception('This weapon should not be used in this context'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getModifiedForceDamageAgainstPlayer(SmrForce $forces, AbstractSmrPlayer $targetPlayer, bool $minesAreAttacker = false): array { |
71
|
|
|
if (!$this->canShootTraders()) { // If we can't shoot traders then just return a damageless array and don't waste resources calculated any damage mods. |
72
|
|
|
return ['Shield' => 0, 'Armour' => 0, 'Rollover' => $this->isDamageRollover()]; |
73
|
|
|
} |
74
|
|
|
$damage = $this->getDamage(); |
75
|
|
|
if ($targetPlayer->getShip()->isFederal()) { // do less damage to fed ships |
76
|
|
|
$damage['Shield'] = IRound($damage['Shield'] * self::FED_SHIP_DAMAGE_MODIFIER); |
|
|
|
|
77
|
|
|
$damage['Armour'] = IRound($damage['Armour'] * self::FED_SHIP_DAMAGE_MODIFIER); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($targetPlayer->getShip()->hasDCS()) { // do less damage to DCS (Drone Scrambler) |
81
|
|
|
$damage['Shield'] = IRound($damage['Shield'] * self::DCS_DAMAGE_MODIFIER); |
82
|
|
|
$damage['Armour'] = IRound($damage['Armour'] * self::DCS_DAMAGE_MODIFIER); |
83
|
|
|
} |
84
|
|
|
$damage['Launched'] = ICeil($this->getAmount() * $this->getModifiedForceAccuracyAgainstPlayer($forces, $targetPlayer, $minesAreAttacker) / 100); |
|
|
|
|
85
|
|
|
$damage['Shield'] = ICeil($damage['Launched'] * $damage['Shield']); |
86
|
|
|
$damage['Armour'] = ICeil($damage['Launched'] * $damage['Armour']); |
87
|
|
|
return $damage; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function shootForces(AbstractSmrPlayer $weaponPlayer, SmrForce $forces): never { |
91
|
|
|
throw new Exception('This weapon should not be used in this context'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function shootPlayer(AbstractSmrPlayer $weaponPlayer, AbstractSmrPlayer $targetPlayer): never { |
95
|
|
|
throw new Exception('This weapon should not be used in this context'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function shootPlayerAsForce(SmrForce $forces, AbstractSmrPlayer $targetPlayer, bool $minesAreAttacker = false): array { |
99
|
|
|
$return = ['Weapon' => $this, 'TargetPlayer' => $targetPlayer, 'Hit' => true]; |
100
|
|
|
$return = $this->doForceDamageToPlayer($return, $forces, $targetPlayer, $minesAreAttacker); |
101
|
|
|
$this->amount -= $return['ActualDamage']['Launched']; // kamikaze |
102
|
|
|
return $return; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
protected function doForceDamageToPlayer(array $return, SmrForce $forces, AbstractSmrPlayer $targetPlayer, bool $minesAreAttacker = false): array { |
106
|
|
|
$return['WeaponDamage'] = $this->getModifiedForceDamageAgainstPlayer($forces, $targetPlayer, $minesAreAttacker); |
107
|
|
|
$return['ActualDamage'] = $targetPlayer->getShip()->takeDamageFromMines($return['WeaponDamage']); |
108
|
|
|
|
109
|
|
|
// Update the number of mines launched so that we don't detonate more than needed |
110
|
|
|
if (!isset($return['WeaponDamage']['Launched'])) { |
111
|
|
|
throw new Exception('Mines must report the number launched'); |
112
|
|
|
} |
113
|
|
|
$return['ActualDamage']['Launched'] = ICeil($return['WeaponDamage']['Launched'] * $return['ActualDamage']['TotalDamage'] / $return['WeaponDamage']['Shield']); // assumes mines do the same shield/armour damage |
|
|
|
|
114
|
|
|
|
115
|
|
|
if ($return['ActualDamage']['KillingShot']) { |
116
|
|
|
$return['KillResults'] = $targetPlayer->killPlayerByForces($forces); |
117
|
|
|
} |
118
|
|
|
return $return; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|