|
23 | 23 | use Stu\Module\Control\TargetLink; |
24 | 24 | use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
25 | 25 | use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
| 26 | +use Stu\Orm\Entity\ColonyInterface; |
| 27 | +use Stu\Orm\Repository\NPCLogRepositoryInterface; |
| 28 | +use Stu\Orm\Repository\MapRepositoryInterface; |
| 29 | + |
26 | 30 |
|
27 | 31 | final class Transfer implements ActionControllerInterface |
28 | 32 | { |
29 | 33 | public const string ACTION_IDENTIFIER = 'B_TRANSFER'; |
30 | 34 |
|
| 35 | + public const int INACTIV_TIME = 60 * 60 * 48; // 48 hours |
| 36 | + |
31 | 37 | public function __construct( |
32 | 38 | private PrivateMessageSenderInterface $privateMessageSender, |
33 | 39 | private TransferInformationFactoryInterface $transferInformationFactory, |
34 | | - private InteractionCheckerBuilderFactoryInterface $interactionCheckerBuilderFactory |
| 40 | + private InteractionCheckerBuilderFactoryInterface $interactionCheckerBuilderFactory, |
| 41 | + private NPCLogRepositoryInterface $npcLogRepository, |
| 42 | + private MapRepositoryInterface $mapRepository |
35 | 43 | ) {} |
36 | 44 |
|
37 | 45 | #[Override] |
@@ -99,6 +107,31 @@ public function handle(GameControllerInterface $game): void |
99 | 107 | $informations |
100 | 108 | ); |
101 | 109 |
|
| 110 | + if ($transferInformation->getTargetType() === TransferEntityTypeEnum::COLONY && !$isUnload) { |
| 111 | + $targetEntity = $transferInformation->getTargetWrapper()->get(); |
| 112 | + if ($targetEntity instanceof ColonyInterface) { |
| 113 | + $targetUser = $target->getUser(); |
| 114 | + $sourceUser = $source->getUser(); |
| 115 | + if ($targetUser !== null && $sourceUser !== null && $this->mapRepository->isAdminRegionUserRegion($target->getLocation()->getId(), $targetUser->getFactionId())) { |
| 116 | + $userstring = $sourceUser->getName() . '(' . $sourceUser->getId() . ') -> ' . $targetUser->getName() . '(' . $targetUser->getId() . ')'; |
| 117 | + if ($targetUser->getLastaction() < time() - self::INACTIV_TIME) { |
| 118 | + $lastactivestring = ' | Lastaction: ' . date('d.m.Y H:i:s', $targetUser->getLastaction()); |
| 119 | + } else { |
| 120 | + $lastactivestring = ''; |
| 121 | + } |
| 122 | + $text = $informations->getInformationsAsString() . ' | ' . $userstring . ' | ' . $target->getLocation()->getSectorString() . $lastactivestring; |
| 123 | + |
| 124 | + $this->createEntry( |
| 125 | + $text, |
| 126 | + $sourceUser->getId(), |
| 127 | + $targetUser->getFactionId() |
| 128 | + ); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + |
| 134 | + |
102 | 135 | $this->privateMessageSender->send( |
103 | 136 | $transferInformation->getSourceWrapper()->getUser()->getId(), |
104 | 137 | $transferInformation->getTargetWrapper()->getUser()->getId(), |
@@ -164,6 +197,20 @@ private function getTransferStrategy(TransferTypeEnum $transferType): TransferSt |
164 | 197 | return $transferStrategy; |
165 | 198 | } |
166 | 199 |
|
| 200 | + private function createEntry( |
| 201 | + string $text, |
| 202 | + int $UserId, |
| 203 | + int $factionId |
| 204 | + ): void { |
| 205 | + $entry = $this->npcLogRepository->prototype(); |
| 206 | + $entry->setText($text); |
| 207 | + $entry->setSourceUserId($UserId); |
| 208 | + $entry->setDate(time()); |
| 209 | + $entry->setFactionId($factionId); |
| 210 | + |
| 211 | + $this->npcLogRepository->save($entry); |
| 212 | + } |
| 213 | + |
167 | 214 | #[Override] |
168 | 215 | public function performSessionCheck(): bool |
169 | 216 | { |
|
0 commit comments