Skip to content

Commit

Permalink
fix shield regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot authored and Huxinator committed Jan 24, 2025
1 parent 9467f77 commit 8eb724e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
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
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

0 comments on commit 8eb724e

Please sign in to comment.