|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Orm\Entity\ModuleInterface; |
|
8
|
|
|
use Stu\Orm\Entity\ShipRumpInterface; |
|
9
|
|
|
use Stu\Component\Ship\ShipModuleTypeEnum; |
|
10
|
|
|
|
|
11
|
|
|
final class ModuleValueCalculator implements ModuleValueCalculatorInterface |
|
12
|
|
|
{ |
|
13
|
|
|
public function calculateModuleValue( |
|
14
|
|
|
$rump, |
|
15
|
|
|
ModuleInterface $module, |
|
16
|
|
|
$callback = 'aggi', |
|
17
|
|
|
$value = false |
|
18
|
|
|
): int { |
|
19
|
|
|
if (!$value) { |
|
20
|
|
|
$value = $rump->$callback(); |
|
21
|
|
|
} |
|
22
|
|
|
if ($module->getType() === ShipModuleTypeEnum::MODULE_TYPE_SENSOR) { |
|
23
|
|
|
if ($rump->getModuleLevel() > $module->getLevel()) { |
|
24
|
|
|
return (int) round($value - $module->getDowngradeFactor()); |
|
25
|
|
|
} |
|
26
|
|
|
if ($rump->getModuleLevel() < $module->getLevel()) { |
|
27
|
|
|
return (int) round($value + $module->getUpgradeFactor()); |
|
28
|
|
|
} |
|
29
|
|
|
if ($rump->getModuleLevel() === $module->getLevel()) { |
|
30
|
|
|
return (int) round($value + $module->getDefaultFactor()); |
|
31
|
|
|
} |
|
32
|
|
|
} else { |
|
33
|
|
|
if ($rump->getModuleLevel() > $module->getLevel()) { |
|
34
|
|
|
return (int) round($value - $value / 100 * $module->getDowngradeFactor()); |
|
35
|
|
|
} |
|
36
|
|
|
if ($rump->getModuleLevel() < $module->getLevel()) { |
|
37
|
|
|
return (int) round($value + $value / 100 * $module->getUpgradeFactor()); |
|
38
|
|
|
} |
|
39
|
|
|
if ($rump->getModuleLevel() === $module->getLevel()) { |
|
40
|
|
|
return (int) round($value + $value / 100 * $module->getDefaultFactor()); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
return (int) $value; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function calculateDamageImpact(ShipRumpInterface $rump, ModuleInterface $module): string |
|
47
|
|
|
{ |
|
48
|
|
|
if ($rump->getModuleLevel() > $module->getLevel()) { |
|
49
|
|
|
return '-' . $module->getDowngradeFactor() . '%'; |
|
50
|
|
|
} |
|
51
|
|
|
if ($rump->getModuleLevel() < $module->getLevel()) { |
|
52
|
|
|
return '+' . $module->getUpgradeFactor() . '%'; |
|
53
|
|
|
} |
|
54
|
|
|
if ($rump->getModuleLevel() === $module->getLevel()) { |
|
55
|
|
|
return '+' . $module->getDefaultFactor() . '%'; |
|
56
|
|
|
} |
|
57
|
|
|
return _('Normal'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function calculateEvadeChance(ShipRumpInterface $rump, ModuleInterface $module): int |
|
61
|
|
|
{ |
|
62
|
|
|
$base = $rump->getEvadeChance(); |
|
63
|
|
|
if ($rump->getModuleLevel() > $module->getLevel()) { |
|
64
|
|
|
$value = (1 - $base / 100) * 1 / (1 - $module->getDowngradeFactor() / 100); |
|
65
|
|
|
} elseif ($rump->getModuleLevel() < $module->getLevel()) { |
|
66
|
|
|
$value = (1 - $base / 100) * 1 / (1 + $module->getUpgradeFactor() / 100); |
|
67
|
|
|
} elseif ($rump->getModuleLevel() === $module->getLevel()) { |
|
68
|
|
|
$value = (1 - $base / 100) * 1 / (1 + $module->getDefaultFactor() / 100); |
|
69
|
|
|
} else { |
|
70
|
|
|
return $base; |
|
71
|
|
|
} |
|
72
|
|
|
return (int) round((1 - $value) * 100); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|