|
19 | 19 | use Doctrine\ORM\Mapping\Table; |
20 | 20 | use Override; |
21 | 21 | use Stu\Component\Colony\ColonyMenuEnum; |
| 22 | +use Stu\Component\Colony\Trait\ColonyRotationTrait; |
22 | 23 | use Stu\Component\Game\ModuleEnum; |
23 | | -use Stu\Component\Game\TimeConstants; |
24 | 24 | use Stu\Lib\Colony\PlanetFieldHostTypeEnum; |
25 | 25 | use Stu\Lib\Transfer\CommodityTransfer; |
26 | 26 | use Stu\Lib\Transfer\TransferEntityTypeEnum; |
|
35 | 35 | #[Entity(repositoryClass: ColonyRepository::class)] |
36 | 36 | class Colony implements ColonyInterface |
37 | 37 | { |
| 38 | + use ColonyRotationTrait; |
| 39 | + |
38 | 40 | #[Id] |
39 | 41 | #[Column(type: 'integer')] |
40 | 42 | #[GeneratedValue(strategy: 'IDENTITY')] |
@@ -380,45 +382,6 @@ public function setShields(?int $shields): ColonyInterface |
380 | 382 | return $this; |
381 | 383 | } |
382 | 384 |
|
383 | | - #[Override] |
384 | | - public function getTwilightZone(int $timestamp): int |
385 | | - { |
386 | | - if (array_key_exists($timestamp, $this->twilightZones)) { |
387 | | - return $this->twilightZones[$timestamp]; |
388 | | - } |
389 | | - |
390 | | - $twilightZone = 0; |
391 | | - |
392 | | - $width = $this->getSurfaceWidth(); |
393 | | - $rotationTime = $this->getRotationTime(); |
394 | | - $colonyTimeSeconds = $this->getColonyTimeSeconds($timestamp); |
395 | | - |
396 | | - if ($this->getDayTimePrefix($timestamp) == 1) { |
397 | | - $scaled = floor((((100 / ($rotationTime * 0.125)) * ($colonyTimeSeconds - $rotationTime * 0.25)) / 100) * $width); |
398 | | - if ($scaled == 0) { |
399 | | - $twilightZone = - (($width) - 1); |
400 | | - } elseif ((int) - (($width) - ceil($scaled)) == 0) { |
401 | | - $twilightZone = -1; |
402 | | - } else { |
403 | | - $twilightZone = (int) - (($width) - $scaled); |
404 | | - } |
405 | | - } |
406 | | - if ($this->getDayTimePrefix($timestamp) == 2) { |
407 | | - $twilightZone = $width; |
408 | | - } |
409 | | - if ($this->getDayTimePrefix($timestamp) == 3) { |
410 | | - $scaled = floor((((100 / ($rotationTime * 0.125)) * ($colonyTimeSeconds - $rotationTime * 0.75)) / 100) * $width); |
411 | | - $twilightZone = (int) ($width - $scaled); |
412 | | - } |
413 | | - if ($this->getDayTimePrefix($timestamp) == 4) { |
414 | | - $twilightZone = 0; |
415 | | - } |
416 | | - |
417 | | - $this->twilightZones[$timestamp] = $twilightZone; |
418 | | - |
419 | | - return $twilightZone; |
420 | | - } |
421 | | - |
422 | 385 | #[Override] |
423 | 386 | public function getShieldFrequency(): ?int |
424 | 387 | { |
@@ -459,75 +422,6 @@ public function setRotationFactor(int $rotationFactor): ColonyInterface |
459 | 422 | return $this; |
460 | 423 | } |
461 | 424 |
|
462 | | - #[Override] |
463 | | - public function getRotationTime(): int |
464 | | - { |
465 | | - return (int) (TimeConstants::ONE_DAY_IN_SECONDS * $this->getRotationFactor() / 100); |
466 | | - } |
467 | | - |
468 | | - public function getColonyTimeSeconds(int $timestamp): int |
469 | | - { |
470 | | - return $timestamp % $this->getRotationTime(); |
471 | | - } |
472 | | - |
473 | | - #[Override] |
474 | | - public function getColonyTimeHour(int $timestamp): ?string |
475 | | - { |
476 | | - $rotationTime = $this->getRotationTime(); |
477 | | - |
478 | | - return sprintf("%02d", (int) floor(($rotationTime / 3600) * ($this->getColonyTimeSeconds($timestamp) / $rotationTime))); |
479 | | - } |
480 | | - |
481 | | - #[Override] |
482 | | - public function getColonyTimeMinute(int $timestamp): ?string |
483 | | - { |
484 | | - $rotationTime = $this->getRotationTime(); |
485 | | - |
486 | | - return sprintf("%02d", (int) floor(60 * (($rotationTime / 3600) * ($this->getColonyTimeSeconds($timestamp) / $rotationTime) - ((int) $this->getColonyTimeHour($timestamp))))); |
487 | | - } |
488 | | - |
489 | | - #[Override] |
490 | | - public function getDayTimePrefix(int $timestamp): ?int |
491 | | - { |
492 | | - $daytimeprefix = null; |
493 | | - $daypercent = (int) (($this->getColonyTimeSeconds($timestamp) / $this->getRotationTime()) * 100); |
494 | | - if ($daypercent > 25 && $daypercent <= 37.5) { |
495 | | - $daytimeprefix = 1; //Sonnenaufgang |
496 | | - } |
497 | | - if ($daypercent > 37.5 && $daypercent <= 75) { |
498 | | - $daytimeprefix = 2; //Tag |
499 | | - } |
500 | | - if ($daypercent > 75 && $daypercent <= 87.5) { |
501 | | - $daytimeprefix = 3; //Sonnenuntergang |
502 | | - } |
503 | | - if ($daypercent > 87.5 || $daypercent <= 25) { |
504 | | - $daytimeprefix = 4; //Nacht |
505 | | - } |
506 | | - return $daytimeprefix; |
507 | | - } |
508 | | - |
509 | | - #[Override] |
510 | | - public function getDayTimeName(int $timestamp): ?string |
511 | | - { |
512 | | - $daytimename = null; |
513 | | - if ($this->getDayTimePrefix($timestamp) == 1) { |
514 | | - $daytimename = 'Morgen'; |
515 | | - } |
516 | | - |
517 | | - if ($this->getDayTimePrefix($timestamp) == 2) { |
518 | | - $daytimename = 'Tag'; |
519 | | - } |
520 | | - |
521 | | - if ($this->getDayTimePrefix($timestamp) == 3) { |
522 | | - $daytimename = 'Abend'; |
523 | | - } |
524 | | - |
525 | | - if ($this->getDayTimePrefix($timestamp) == 4) { |
526 | | - $daytimename = 'Nacht'; |
527 | | - } |
528 | | - return $daytimename; |
529 | | - } |
530 | | - |
531 | 425 | #[Override] |
532 | 426 | public function getSurfaceWidth(): int |
533 | 427 | { |
|
0 commit comments