Skip to content

Commit

Permalink
beaming impossible during ion storm
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Jan 22, 2025
1 parent 4136670 commit cc891d2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Lib/Interaction/InteractionCheckType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum InteractionCheckType
case EXPECT_TARGET_UNWARPED;
case EXPECT_TARGET_SAME_USER;
case EXPECT_TARGET_ALSO_IN_FINISHED_WEB;
case EXPECT_TARGET_DOCKED_OR_NO_ION_STORM;

public function getReason(string $placeholder = ''): string
{
Expand All @@ -37,9 +38,10 @@ public function getReason(string $placeholder = ''): string
self::EXPECT_TARGET_NOT_NPC => 'Aktion nicht möglich, der Spieler ist NPC!',
self::EXPECT_TARGET_UNSHIELDED => 'Das Ziel hat die Schilde aktiviert',
self::EXPECT_TARGET_UNWARPED => 'Das Ziel hat den Warpantrieb aktiviert',
self::EXPECT_TARGET_SAME_USER => throw new SanityCheckException('Tried to interact with entity of other user'),
self::EXPECT_TARGET_ALSO_IN_FINISHED_WEB => 'Das Ziel ist nicht mit im Energienetz gefangen',
self::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM => 'Beamen nicht möglich während eines Ionensturms',
self::EXPECT_SOURCE_TACHYON => throw new SanityCheckException('Tried to interact with cloaked entity without active tachyon'),
self::EXPECT_TARGET_SAME_USER => throw new SanityCheckException('Tried to interact with entity of other user'),
self::EXPECT_TARGET_UNCLOAKED => throw new SanityCheckException('Tried to interact with cloaked entity')
};
}
Expand Down
8 changes: 8 additions & 0 deletions src/Lib/Interaction/Member/ColonyMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Stu\Lib\Interaction\Member;

use Override;
use Stu\Component\Anomaly\Type\AnomalyTypeEnum;
use Stu\Lib\Interaction\InteractionCheckType;
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
use Stu\Orm\Entity\ColonyInterface;
Expand Down Expand Up @@ -38,6 +39,13 @@ public function canBeAccessedFrom(
callable $shouldCheck
): ?InteractionCheckType {

if (
$shouldCheck(InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM)
&& $this->colony->getLocation()->hasAnomaly(AnomalyTypeEnum::ION_STORM)
) {
return InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM;
}

if (
$shouldCheck(InteractionCheckType::EXPECT_TARGET_ALSO_IN_FINISHED_WEB)
&& $this->tholianWebUtil->isTargetOutsideFinishedTholianWeb($other->get(), $this->colony)
Expand Down
6 changes: 4 additions & 2 deletions src/Lib/Interaction/Member/InteractionMemberFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RuntimeException;
use Stu\Component\Spacecraft\Nbs\NbsUtilityInterface;
use Stu\Lib\Interaction\EntityWithInteractionCheckInterface;
use Stu\Lib\Transfer\CommodityTransferInterface;
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
use Stu\Orm\Entity\ColonyInterface;
use Stu\Orm\Entity\SpacecraftInterface;
Expand All @@ -14,7 +15,8 @@ class InteractionMemberFactory implements InteractionMemberFactoryInterface
{
public function __construct(
private NbsUtilityInterface $nbsUtility,
private TholianWebUtilInterface $tholianWebUtil
private TholianWebUtilInterface $tholianWebUtil,
private CommodityTransferInterface $commodityTransfer
) {}

public function createMember(EntityWithInteractionCheckInterface $entity): InteractionMemberInterface
Expand All @@ -23,7 +25,7 @@ public function createMember(EntityWithInteractionCheckInterface $entity): Inter
return new ColonyMember($this->tholianWebUtil, $entity);
}
if ($entity instanceof SpacecraftInterface) {
return new SpacecraftMember($this->nbsUtility, $this->tholianWebUtil, $entity);
return new SpacecraftMember($this->nbsUtility, $this->tholianWebUtil, $this->commodityTransfer, $entity);
}
if ($entity instanceof TrumfieldInterface) {
return new TrumfieldMember($entity);
Expand Down
13 changes: 13 additions & 0 deletions src/Lib/Interaction/Member/SpacecraftMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Stu\Lib\Interaction\Member;

use Override;
use Stu\Component\Anomaly\Type\AnomalyTypeEnum;
use Stu\Component\Spacecraft\Nbs\NbsUtilityInterface;
use Stu\Lib\Interaction\InteractionCheckType;
use Stu\Lib\Transfer\CommodityTransferInterface;
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
use Stu\Orm\Entity\MapInterface;
use Stu\Orm\Entity\SpacecraftInterface;
Expand All @@ -16,6 +18,7 @@ class SpacecraftMember implements InteractionMemberInterface
public function __construct(
private NbsUtilityInterface $nbsUtility,
private TholianWebUtilInterface $tholianWebUtil,
private CommodityTransferInterface $commodityTransfer,
private SpacecraftInterface $spacecraft
) {}

Expand Down Expand Up @@ -64,6 +67,16 @@ public function canBeAccessedFrom(
callable $shouldCheck
): ?InteractionCheckType {

$otherEntity = $other->get();
if (
$otherEntity instanceof SpacecraftInterface
&& $shouldCheck(InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM)
&& $this->spacecraft->getLocation()->hasAnomaly(AnomalyTypeEnum::ION_STORM)
&& !$this->commodityTransfer->isDockTransfer($this->spacecraft, $otherEntity)
) {
return InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM;
}

if (
$shouldCheck(InteractionCheckType::EXPECT_TARGET_SAME_USER)
&& $this->spacecraft->getUser() !== $other->getUser()
Expand Down
1 change: 1 addition & 0 deletions src/Module/Colony/Lib/Gui/ColonyScanPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected function loadLayers(): void
$panelLayerCreation = $this->panelLayerCreation
->addShipCountLayer($showCloaked, null, SpacecraftCountLayerTypeEnum::ALL, 0)
->addSystemLayer()
->addAnomalyLayer()
->addColonyShieldLayer();

if ($this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE)) {
Expand Down
1 change: 1 addition & 0 deletions src/Module/Game/Action/Transfer/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function handle(GameControllerInterface $game): void
InteractionCheckType::EXPECT_SOURCE_UNWARPED,
InteractionCheckType::EXPECT_SOURCE_UNSHIELDED,
InteractionCheckType::EXPECT_TARGET_NO_VACATION,
InteractionCheckType::EXPECT_TARGET_DOCKED_OR_NO_ION_STORM,
InteractionCheckType::EXPECT_TARGET_UNWARPED,
InteractionCheckType::EXPECT_TARGET_UNCLOAKED,
InteractionCheckType::EXPECT_TARGET_UNSHIELDED
Expand Down
2 changes: 2 additions & 0 deletions tests/StuMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Stu\Config\StuContainer;
use Stu\Lib\Component\ComponentEnumInterface;
use Stu\Lib\Component\ComponentLoaderInterface;
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerCreation;

class StuMocks
{
Expand Down Expand Up @@ -44,6 +45,7 @@ public function registerStubbedComponent(ComponentEnumInterface $componentEnum):
public function reset(): void
{
request::setMockVars(null);
PanelLayerCreation::$skippedLayers = [];
$this->getStuContainer()->clearAdditionalServices();
$this->getStuContainer()
->get(ComponentLoaderInterface::class)
Expand Down
4 changes: 4 additions & 0 deletions tests/inttest/html/AllViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use PHPUnit\Framework\Attributes\DataProvider;
use ReflectionClass;
use Stu\Config\Init;
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerCreation;
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerEnum;
use Stu\Module\Control\ViewControllerInterface;
use Stu\Module\Game\Component\GameComponentEnum;
use Stu\StuMocks;
Expand Down Expand Up @@ -96,6 +98,8 @@ public static function getAllViewControllerDataProvider(): array
#[DataProvider('getAllViewControllerDataProvider')]
public function testHandle(string $key): void
{
PanelLayerCreation::$skippedLayers[] = PanelLayerEnum::ANOMALIES->value;

$this->snapshotKey = $key;

$this->renderSnapshot(
Expand Down

0 comments on commit cc891d2

Please sign in to comment.