|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Component\Colony\Trait; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Component\Game\TimeConstants; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
trait ColonyRotationTrait |
|
8
|
|
|
{ |
|
9
|
6 |
|
public function getTwilightZone(int $timestamp): int |
|
10
|
|
|
{ |
|
11
|
6 |
|
if (array_key_exists($timestamp, $this->twilightZones)) { |
|
12
|
6 |
|
return $this->twilightZones[$timestamp]; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
1 |
|
$twilightZone = 0; |
|
16
|
|
|
|
|
17
|
1 |
|
$width = $this->getSurfaceWidth(); |
|
|
|
|
|
|
18
|
1 |
|
$rotationTime = $this->getRotationTime(); |
|
19
|
1 |
|
$colonyTimeSeconds = $this->getColonyTimeSeconds($timestamp); |
|
20
|
|
|
|
|
21
|
1 |
|
if ($this->getDayTimePrefix($timestamp) == 1) { |
|
22
|
|
|
$scaled = floor((((100 / ($rotationTime * 0.125)) * ($colonyTimeSeconds - $rotationTime * 0.25)) / 100) * $width); |
|
23
|
|
|
if ($scaled == 0) { |
|
24
|
|
|
$twilightZone = - (($width) - 1); |
|
25
|
|
|
} elseif ((int) - (($width) - ceil($scaled)) == 0) { |
|
26
|
|
|
$twilightZone = -1; |
|
27
|
|
|
} else { |
|
28
|
|
|
$twilightZone = (int) - (($width) - $scaled); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
1 |
|
if ($this->getDayTimePrefix($timestamp) == 2) { |
|
32
|
1 |
|
$twilightZone = $width; |
|
33
|
|
|
} |
|
34
|
1 |
|
if ($this->getDayTimePrefix($timestamp) == 3) { |
|
35
|
|
|
$scaled = floor((((100 / ($rotationTime * 0.125)) * ($colonyTimeSeconds - $rotationTime * 0.75)) / 100) * $width); |
|
36
|
|
|
$twilightZone = (int) ($width - $scaled); |
|
37
|
|
|
} |
|
38
|
1 |
|
if ($this->getDayTimePrefix($timestamp) == 4) { |
|
39
|
|
|
$twilightZone = 0; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
$this->twilightZones[$timestamp] = $twilightZone; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
1 |
|
return $twilightZone; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
public function getRotationTime(): int |
|
48
|
|
|
{ |
|
49
|
4 |
|
return (int) (TimeConstants::ONE_DAY_IN_SECONDS * $this->getRotationFactor() / 100); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
public function getColonyTimeHour(int $timestamp): ?string |
|
53
|
|
|
{ |
|
54
|
4 |
|
$rotationTime = $this->getRotationTime(); |
|
55
|
|
|
|
|
56
|
4 |
|
return sprintf("%02d", (int) floor(($rotationTime / 3600) * ($this->getColonyTimeSeconds($timestamp) / $rotationTime))); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
4 |
|
public function getColonyTimeMinute(int $timestamp): ?string |
|
60
|
|
|
{ |
|
61
|
4 |
|
$rotationTime = $this->getRotationTime(); |
|
62
|
|
|
|
|
63
|
4 |
|
return sprintf("%02d", (int) floor(60 * (($rotationTime / 3600) * ($this->getColonyTimeSeconds($timestamp) / $rotationTime) - ((int) $this->getColonyTimeHour($timestamp))))); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
4 |
|
private function getColonyTimeSeconds(int $timestamp): int |
|
67
|
|
|
{ |
|
68
|
4 |
|
return $timestamp % $this->getRotationTime(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
4 |
|
public function getDayTimePrefix(int $timestamp): ?int |
|
72
|
|
|
{ |
|
73
|
4 |
|
$daytimeprefix = null; |
|
74
|
4 |
|
$daypercent = (int) (($this->getColonyTimeSeconds($timestamp) / $this->getRotationTime()) * 100); |
|
75
|
4 |
|
if ($daypercent > 25 && $daypercent <= 37.5) { |
|
76
|
|
|
$daytimeprefix = 1; //Sonnenaufgang |
|
77
|
|
|
} |
|
78
|
4 |
|
if ($daypercent > 37.5 && $daypercent <= 75) { |
|
79
|
4 |
|
$daytimeprefix = 2; //Tag |
|
80
|
|
|
} |
|
81
|
4 |
|
if ($daypercent > 75 && $daypercent <= 87.5) { |
|
82
|
|
|
$daytimeprefix = 3; //Sonnenuntergang |
|
83
|
|
|
} |
|
84
|
4 |
|
if ($daypercent > 87.5 || $daypercent <= 25) { |
|
85
|
|
|
$daytimeprefix = 4; //Nacht |
|
86
|
|
|
} |
|
87
|
4 |
|
return $daytimeprefix; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
4 |
|
public function getDayTimeName(int $timestamp): ?string |
|
91
|
|
|
{ |
|
92
|
4 |
|
$daytimename = null; |
|
93
|
4 |
|
if ($this->getDayTimePrefix($timestamp) == 1) { |
|
94
|
|
|
$daytimename = 'Morgen'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
4 |
|
if ($this->getDayTimePrefix($timestamp) == 2) { |
|
98
|
4 |
|
$daytimename = 'Tag'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
4 |
|
if ($this->getDayTimePrefix($timestamp) == 3) { |
|
102
|
|
|
$daytimename = 'Abend'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
4 |
|
if ($this->getDayTimePrefix($timestamp) == 4) { |
|
106
|
|
|
$daytimename = 'Nacht'; |
|
107
|
|
|
} |
|
108
|
4 |
|
return $daytimename; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths