Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2016

Merged
merged 2 commits into from
Jan 24, 2025
Merged

Dev #2016

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ parameters:
count: 2
path: src/Component/Logging/services.php

-
message: '#^Call to deprecated method getSensorRange\(\) of interface Stu\\Orm\\Entity\\SpacecraftInterface\.$#'
identifier: method.deprecated
count: 1
path: src/Component/Refactor/RefactorRunner.php

-
message: '#^Call to deprecated method getShieldRegenerationTimer\(\) of interface Stu\\Orm\\Entity\\SpacecraftInterface\.$#'
identifier: method.deprecated
count: 1
path: src/Component/Refactor/RefactorRunner.php

-
message: '#^Cannot call method getEps\(\) on Stu\\Component\\Spacecraft\\System\\Data\\EpsSystemData\|null\.$#'
identifier: method.nonObject
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Refactor/RefactorRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public function refactor(): void
$shieldSystemData = $wrapper->getShieldSystemData();
if ($shieldSystemData !== null) {
$shieldSystemData
->setShieldRegenerationTimer($spacecraft->getShieldRegenerationTimer())
//->setShieldRegenerationTimer($spacecraft->getShieldRegenerationTimer())
->update();
}

$shieldSystemData = $wrapper->getLssSystemData();
if ($shieldSystemData !== null) {
$shieldSystemData
->setSensorRange($spacecraft->getSensorRange())
//->setSensorRange($spacecraft->getSensorRange())
->update();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250121154150 extends AbstractMigration
final class Version20250124215956 extends AbstractMigration
{
public function getDescription(): string
{
Expand Down Expand Up @@ -405,7 +405,7 @@ public function up(Schema $schema): void
$this->addSql('CREATE INDEX IDX_7C6FFB4221BDB235 ON stu_shipyard_shipqueue (station_id)');
$this->addSql('CREATE INDEX shipyard_shipqueue_user_idx ON stu_shipyard_shipqueue (user_id)');
$this->addSql('CREATE INDEX shipyard_shipqueue_finish_date_idx ON stu_shipyard_shipqueue (finish_date)');
$this->addSql('CREATE TABLE stu_spacecraft (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER NOT NULL, rump_id INTEGER NOT NULL, plan_id INTEGER DEFAULT NULL, direction SMALLINT DEFAULT NULL, name VARCHAR(255) NOT NULL, alvl SMALLINT NOT NULL, lss_mode SMALLINT NOT NULL, huelle INTEGER NOT NULL, max_huelle INTEGER NOT NULL, schilde INTEGER NOT NULL, max_schilde INTEGER NOT NULL, tractored_ship_id INTEGER DEFAULT NULL, holding_web_id INTEGER DEFAULT NULL, database_id INTEGER DEFAULT NULL, disabled BOOLEAN NOT NULL, hit_chance SMALLINT NOT NULL, evade_chance SMALLINT NOT NULL, base_damage SMALLINT NOT NULL, sensor_range SMALLINT NOT NULL, shield_regeneration_timer INTEGER NOT NULL, state SMALLINT NOT NULL, location_id INTEGER NOT NULL, in_emergency BOOLEAN NOT NULL, type VARCHAR(255) NOT NULL, CONSTRAINT FK_4BD20E2EEE54A42E FOREIGN KEY (tractored_ship_id) REFERENCES stu_ship (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E73D3801E FOREIGN KEY (holding_web_id) REFERENCES stu_tholian_web (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2EA76ED395 FOREIGN KEY (user_id) REFERENCES stu_user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E2EE98D4C FOREIGN KEY (rump_id) REFERENCES stu_rump (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2EE899029B FOREIGN KEY (plan_id) REFERENCES stu_buildplan (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E64D218E FOREIGN KEY (location_id) REFERENCES stu_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE TABLE stu_spacecraft (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER NOT NULL, rump_id INTEGER NOT NULL, plan_id INTEGER DEFAULT NULL, direction SMALLINT DEFAULT NULL, name VARCHAR(255) NOT NULL, alvl SMALLINT NOT NULL, lss_mode SMALLINT NOT NULL, huelle INTEGER NOT NULL, max_huelle INTEGER NOT NULL, schilde INTEGER NOT NULL, max_schilde INTEGER NOT NULL, tractored_ship_id INTEGER DEFAULT NULL, holding_web_id INTEGER DEFAULT NULL, database_id INTEGER DEFAULT NULL, disabled BOOLEAN NOT NULL, hit_chance SMALLINT NOT NULL, evade_chance SMALLINT NOT NULL, base_damage SMALLINT NOT NULL, state SMALLINT NOT NULL, location_id INTEGER NOT NULL, in_emergency BOOLEAN NOT NULL, type VARCHAR(255) NOT NULL, CONSTRAINT FK_4BD20E2EEE54A42E FOREIGN KEY (tractored_ship_id) REFERENCES stu_ship (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E73D3801E FOREIGN KEY (holding_web_id) REFERENCES stu_tholian_web (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2EA76ED395 FOREIGN KEY (user_id) REFERENCES stu_user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E2EE98D4C FOREIGN KEY (rump_id) REFERENCES stu_rump (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2EE899029B FOREIGN KEY (plan_id) REFERENCES stu_buildplan (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_4BD20E2E64D218E FOREIGN KEY (location_id) REFERENCES stu_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_4BD20E2EEE54A42E ON stu_spacecraft (tractored_ship_id)');
$this->addSql('CREATE INDEX IDX_4BD20E2E73D3801E ON stu_spacecraft (holding_web_id)');
$this->addSql('CREATE INDEX IDX_4BD20E2EA76ED395 ON stu_spacecraft (user_id)');
Expand Down
28 changes: 28 additions & 0 deletions src/Migrations/pgsql/Version20250124215954.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Stu\Migrations\Pgsql;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250124215954 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove obsolete attributes.';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE stu_spacecraft DROP sensor_range');
$this->addSql('ALTER TABLE stu_spacecraft DROP shield_regeneration_timer');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE stu_spacecraft ADD sensor_range SMALLINT NOT NULL');
$this->addSql('ALTER TABLE stu_spacecraft ADD shield_regeneration_timer INT NOT NULL');
}
}
9 changes: 5 additions & 4 deletions src/Module/Spacecraft/Lib/SpacecraftWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,14 @@ public function setAlertState(SpacecraftAlertStateEnum $alertState): ?string
public function getSensorRange(): int
{
$lssSystemData = $this->getLssSystemData();
if ($lssSystemData === null) {
return 0;
}

return $lssSystemData !== null
? $lssSystemData->getSensorRange()
: 0;
return (int) (ceil($lssSystemData->getSensorRange()
* $this->get()->getSpacecraftSystem(SpacecraftSystemTypeEnum::LSS)->getStatus() / 100));
}


#[Override]
public function getShieldRegenerationRate(): int
{
Expand Down
20 changes: 13 additions & 7 deletions src/Module/Tick/Process/ShieldRegeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ public function __construct(
public function work(): void
{
$time = time();
$result = $this->spacecraftRepository->getSuitableForShieldRegeneration($time - self::SHIELD_REGENERATION_TIME);
$regenerationThreshold = $time - self::SHIELD_REGENERATION_TIME;
$processedCount = 0;
foreach ($result as $spacecraft) {
$processedCount++;
foreach ($this->spacecraftRepository->getSuitableForShieldRegeneration() as $spacecraft) {

//AND CAST(ss.data::jsonb->>\'shieldRegenerationTimer\' AS INTEGER) <= :regenerationThreshold
$wrapper = $this->spacecraftWrapperFactory->wrapSpacecraft($spacecraft);
$shieldSystemData = $wrapper->getShieldSystemData();
if ($shieldSystemData === null) {
throw new RuntimeException('this should hot happen');
}

if ($shieldSystemData->shieldRegenerationTimer > $regenerationThreshold) {
continue;
}

$processedCount++;
$rate = $wrapper->getShieldRegenerationRate();
if ($spacecraft->getShield() + $rate > $spacecraft->getMaxShield()) {
$rate = $spacecraft->getMaxShield() - $spacecraft->getShield();
}
$spacecraft->setShield($spacecraft->getShield() + $rate);

$shieldSystemData = $wrapper->getShieldSystemData();
if ($shieldSystemData === null) {
throw new RuntimeException('this should hot happen');
}
$shieldSystemData->setShieldRegenerationTimer($time)->update();

$this->spacecraftRepository->save($spacecraft);
Expand Down
26 changes: 0 additions & 26 deletions src/Orm/Entity/Spacecraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ abstract class Spacecraft implements SpacecraftInterface
#[Column(type: 'smallint', length: 4)]
private int $base_damage = 0;

#[Column(type: 'smallint', length: 3)]
private int $sensor_range = 0;

#[Column(type: 'integer')]
private int $shield_regeneration_timer = 0;

#[Column(type: 'smallint', enumType: SpacecraftStateEnum::class)]
private SpacecraftStateEnum $state = SpacecraftStateEnum::SHIP_STATE_NONE;

Expand Down Expand Up @@ -589,20 +583,6 @@ public function setBaseDamage(int $baseDamage): SpacecraftInterface
return $this;
}

/**
* proportional to sensor system status
*/
#[Override]
public function getSensorRange(): int
{
if (!$this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::LSS)) {
return $this->sensor_range;
}

return (int) (ceil($this->sensor_range
* $this->getSpacecraftSystem(SpacecraftSystemTypeEnum::LSS)->getStatus() / 100));
}

/**
* proportional to tractor beam system status
*/
Expand All @@ -617,12 +597,6 @@ public function getTractorPayload(): int
* $this->getSpacecraftSystem(SpacecraftSystemTypeEnum::TRACTOR_BEAM)->getStatus() / 100));
}

#[Override]
public function getShieldRegenerationTimer(): int
{
return $this->shield_regeneration_timer;
}

#[Override]
public function getState(): SpacecraftStateEnum
{
Expand Down
6 changes: 0 additions & 6 deletions src/Orm/Entity/SpacecraftInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,8 @@ public function getBaseDamage(): int;

public function setBaseDamage(int $baseDamage): SpacecraftInterface;

/** @deprecated */
public function getSensorRange(): int;

public function getTractorPayload(): int;

/** @deprecated */
public function getShieldRegenerationTimer(): int;

public function getState(): SpacecraftStateEnum;

public function setState(SpacecraftStateEnum $state): SpacecraftInterface;
Expand Down
4 changes: 1 addition & 3 deletions src/Orm/Repository/SpacecraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getByUser(UserInterface $user): array
}

#[Override]
public function getSuitableForShieldRegeneration(int $regenerationThreshold): array
public function getSuitableForShieldRegeneration(): array
{
return $this->getEntityManager()->createQuery(
sprintf(
Expand All @@ -105,7 +105,6 @@ public function getSuitableForShieldRegeneration(int $regenerationThreshold): ar
WHERE ss.system_type = :shieldType
AND ss.mode < :modeOn
AND s.schilde < s.max_schilde
AND CAST(ss.data::jsonb->>\'shieldRegenerationTimer\' AS INTEGER) <= :regenerationThreshold
AND (SELECT count(sc.id) FROM %s sc WHERE s.id = sc.spacecraft_id) >= bp.crew
AND NOT EXISTS (SELECT a FROM %s a
WHERE a.location_id = s.location_id
Expand All @@ -120,7 +119,6 @@ public function getSuitableForShieldRegeneration(int $regenerationThreshold): ar
)->setParameters([
'shieldType' => SpacecraftSystemTypeEnum::SHIELDS->value,
'modeOn' => SpacecraftSystemModeEnum::MODE_ON->value,
'regenerationThreshold' => $regenerationThreshold,
'anomalyTypes' => [AnomalyTypeEnum::SUBSPACE_ELLIPSE, AnomalyTypeEnum::ION_STORM]
])->getResult();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Orm/Repository/SpacecraftRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getByUser(UserInterface $user): array;
/**
* @return array<SpacecraftInterface>
*/
public function getSuitableForShieldRegeneration(int $regenerationThreshold): array;
public function getSuitableForShieldRegeneration(): array;

/**
* @return array<SpacecraftInterface>
Expand Down
14 changes: 7 additions & 7 deletions testdata/Migrations/VersionTestSpacecraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$this->addSql('INSERT INTO stu_spacecraft (id, user_id, rump_id, plan_id, direction, name, alvl, huelle, max_huelle, schilde, max_schilde, database_id, disabled, hit_chance, evade_chance, base_damage, sensor_range, shield_regeneration_timer, state, tractored_ship_id, lss_mode, holding_web_id, type, in_emergency, location_id)
VALUES (42, 101, 6501, 2324, NULL, \'Aerie\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'SHIP\', 0, 15247),
(77, 101, 6501, 2324, NULL, \'Aerie Zwo\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'SHIP\', 0, 204359),
(78, 101, 6501, 2324, NULL, \'Aerie Three\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'SHIP\', 0, 204359),
(43, 101, 10053, 689, NULL, \'Mighty AP\', 1, 20000, 21000, 24000, 25000, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'STATION\', 0, 15247),
(1021, 102, 6501, 2324, NULL, \'Aerie 102\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'SHIP\', 0, 204143),
(1022, 102, 10053, 689, NULL, \'AP 102\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 2, 0, 0, NULL, 1, NULL, \'STATION\', 0, 204143);
$this->addSql('INSERT INTO stu_spacecraft (id, user_id, rump_id, plan_id, direction, name, alvl, huelle, max_huelle, schilde, max_schilde, database_id, disabled, hit_chance, evade_chance, base_damage, state, tractored_ship_id, lss_mode, holding_web_id, type, in_emergency, location_id)
VALUES (42, 101, 6501, 2324, NULL, \'Aerie\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'SHIP\', 0, 15247),
(77, 101, 6501, 2324, NULL, \'Aerie Zwo\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'SHIP\', 0, 204359),
(78, 101, 6501, 2324, NULL, \'Aerie Three\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'SHIP\', 0, 204359),
(43, 101, 10053, 689, NULL, \'Mighty AP\', 1, 20000, 21000, 24000, 25000, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'STATION\', 0, 15247),
(1021, 102, 6501, 2324, NULL, \'Aerie 102\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'SHIP\', 0, 204143),
(1022, 102, 10053, 689, NULL, \'AP 102\', 1, 819, 819, 819, 819, NULL, 0, 68, 0, 43, 0, NULL, 1, NULL, \'STATION\', 0, 204143);
');
}
}
Loading