Skip to content

Commit

Permalink
Merge pull request #2213 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v8.1 - Subcreation integration replaced with Archon.gg
  • Loading branch information
Wotuu authored Feb 23, 2024
2 parents 62fd6a9 + f5ffc4a commit 3bd7350
Show file tree
Hide file tree
Showing 63 changed files with 1,933 additions and 403 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/CombatLog/CreateMappingVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function createMappingVersionFromCombatLog(
'- %s mapping version %s (%s, %d, %d enemies)',
$hasMappingVersion ? 'Updated' : 'Created',
$mappingVersion->version,
__($mappingVersion->dungeon->name, [], 'en'),
__($mappingVersion->dungeon->name, [], 'en-US'),
$mappingVersion->id,
$mappingVersion->enemies()->count(),
)
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Dungeon/CreateMissing.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(): int
$expansion = $expansions->get($expansionKey);

$nameTranslationKey = sprintf('dungeons.%s.%s.name', $expansionKey, $dungeonKey);
$nameTranslated = __($nameTranslationKey, [], 'en');
$nameTranslated = __($nameTranslationKey, [], 'en-US');

Dungeon::create([
'expansion_id' => $expansion->id,
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/Dungeon/CreateMissingFloors.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function handle(): int
$dungeonTranslationKey = explode('.', $dungeon->name)[2];
$floorsTranslationKey = sprintf('dungeons.%s.%s.floors', $dungeon->expansion->shortname, $dungeonTranslationKey);

$translatedFloors = __($floorsTranslationKey, [], 'en');
$translatedFloors = __($floorsTranslationKey, [], 'en-US');

$this->info(sprintf('- %s', __($dungeon->name, [], 'en')));
$this->info(sprintf('- %s', __($dungeon->name, [], 'en-US')));
$index = 1;
foreach ($translatedFloors as $key => $value) {
$floorKey = sprintf('%s.%s', $floorsTranslationKey, $key);
Expand All @@ -65,7 +65,7 @@ public function handle(): int
'default' => $index === 1,
]);

$this->comment(sprintf('-- Added new floor %s', __($floorKey, [], 'en')));
$this->comment(sprintf('-- Added new floor %s', __($floorKey, [], 'en-US')));

$index++;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Environment/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function handle(): int
$this->call('supervisor:start');
}

// Refresh the subcreation ease tiers (for a first run to populate the data)
// Refresh the affix group ease tiers (for a first run to populate the data)
$this->call('affixgroupeasetiers:refresh');
// Dispatch the refreshing of the discovery cache - this can take up to 5 minutes and can be done in the background
RefreshDiscoverCache::dispatch();
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/Mapping/AssignMDTIDs.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function handle()
return $enemy->mdt_id > 0;
})->isNotEmpty()) {
$this->comment(
sprintf('- Skipping dungeon %s - already assigned has assigned MDT IDs', __($mappingVersion->dungeon->name, [], 'en'))
sprintf('- Skipping dungeon %s - already assigned has assigned MDT IDs', __($mappingVersion->dungeon->name, [], 'en-US'))
);
continue;
}

$this->info(sprintf('Assigning MDT IDs for dungeon %s', __($mappingVersion->dungeon->name, [], 'en')));
$this->info(sprintf('Assigning MDT IDs for dungeon %s', __($mappingVersion->dungeon->name, [], 'en-US')));

$previousNpcId = 0;
foreach ($enemies as $enemy) {
Expand Down
148 changes: 16 additions & 132 deletions app/Console/Commands/Scheduler/RefreshAffixGroupEaseTiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

namespace App\Console\Commands\Scheduler;

use App\Models\Affix;
use App\Models\AffixGroup\AffixGroupEaseTier;
use App\Models\Dungeon;
use App\Models\SubcreationEaseTierPull;
use App\Service\Season\SeasonServiceInterface;
use App\Service\Subcreation\Exceptions\InvalidResponseException;
use App\Service\Subcreation\SubcreationApiServiceInterface;
use Carbon\Carbon;
use DateTimeZone;
use Exception;
use App\Models\AffixGroup\AffixGroupEaseTierPull;
use App\Service\AffixGroup\AffixGroupEaseTierServiceInterface;
use App\Service\AffixGroup\ArchonApiServiceInterface;
use App\Service\AffixGroup\Exceptions\InvalidResponseException;
use Illuminate\Console\Command;

class RefreshAffixGroupEaseTiers extends Command
{
private const DUNGEON_NAME_MAPPING = [
'Dawn of the Infinite: Galakrond\'s Fall' => 'DOTI: Galakrond\'s Fall',
'Dawn of the Infinite: Murozond\'s Rise' => 'DOTI: Murozond\'s Rise',
];

/**
* The name and signature of the console command.
Expand All @@ -33,7 +24,7 @@ class RefreshAffixGroupEaseTiers extends Command
*
* @var string
*/
protected $description = 'Refreshes the affix group ease tiers from Subcreation.net';
protected $description = 'Refreshes the affix group ease tiers from Archon.gg';

/**
* Create a new command instance.
Expand All @@ -48,141 +39,34 @@ public function __construct()
/**
* Execute the console command.
*
* @param SubcreationApiServiceInterface $subcreationApiService
* @param SeasonServiceInterface $seasonService
* @param ArchonApiServiceInterface $archonApiService
* @param AffixGroupEaseTierServiceInterface $affixGroupEaseTierService
* @return int
* @throws Exception
*/
public function handle(SubcreationApiServiceInterface $subcreationApiService, SeasonServiceInterface $seasonService)
{
public function handle(
ArchonApiServiceInterface $archonApiService,
AffixGroupEaseTierServiceInterface $affixGroupEaseTierService
): int {
try {
$tierLists = $subcreationApiService->getDungeonEaseTierListOverall();
$tierLists = $archonApiService->getDungeonEaseTierListOverall();
} catch (InvalidResponseException $exception) {
$this->error(sprintf('Invalid response: %s', $exception->getMessage()));

// @TODO fix when reimplementing Subcreation but as Archon instead.
return 0;
return -1;
}

if (!isset($tierLists['last_updated']) || !isset($tierLists['current_affixes']) || !isset($tierLists['source_url']) || !isset($tierLists['tier_lists'])) {
if (!isset($tierLists['encounterTierList'])) {
$this->error(sprintf('Invalid response: %s', json_encode($tierLists)));

return -1;
}

$lastUpdatedAt = Carbon::createFromFormat('Y-m-d G:i:s.uP', $tierLists['last_updated']);
$lastEaseTierPull = SubcreationEaseTierPull::latest()->first();

if ($lastEaseTierPull === null || $lastUpdatedAt->isAfter($lastEaseTierPull->last_updated_at)) {
$subcreationEaseTierPull = SubcreationEaseTierPull::create([
'current_affixes' => $tierLists['current_affixes'],
'source_url' => $tierLists['source_url'],
'last_updated_at' => $lastUpdatedAt->setTimezone(new DateTimeZone(config('app.timezone')))->toDateTimeString(),
]);

$dungeonList = Dungeon::active()->get();
$totalSaved = 0;

foreach ($tierLists['tier_lists'] as $affixString => $tierList) {
$this->info(sprintf('- Parsing %s', $affixString));

$affixGroupId = $this->getAffixGroupByString($seasonService, $affixString);

// Only if we actually found an affix..
if ($affixGroupId !== null) {
$this->info(sprintf('-- Parsing for AffixGroup %s (%s)', $affixString, $affixGroupId));
$saved = 0;

foreach ($tierList as $tier => $dungeons) {
foreach ($dungeons as $dungeonName) {
// If found
$dungeon = $dungeonList->first(function (Dungeon $dungeon) use ($dungeonName) {
// Translate the name of the dungeon to English (from a key), and then match it
$ksgDungeonName = __($dungeon->name, [], 'en-US');

return (self::DUNGEON_NAME_MAPPING[$ksgDungeonName] ?? $ksgDungeonName) === $dungeonName;
});

if ($dungeon instanceof Dungeon) {
(new AffixGroupEaseTier([
'subcreation_ease_tier_pull_id' => $subcreationEaseTierPull->id,
'affix_group_id' => $affixGroupId,
'dungeon_id' => $dungeon->id,
'tier' => $tier,
]))->save();

$saved++;
$totalSaved++;
$this->info(sprintf('--- Saved dungeon %s (%s)', $dungeonName, $dungeon->id));
} else {
$this->error(sprintf('--- Unknown dungeon %s', $dungeonName));
}
}
}

$this->info(sprintf('-- Saved %s ease tiers', $saved));
} else {
$this->error(sprintf('-- Unable to find AffixGroup for affixes %s', $affixString));
}
}
} else {
$this->warn('Cannot update the Subcreation ease tier tiers - the data has not updated yet');
}
$affixGroupEaseTierService->parseTierList($tierLists);

// Clear model cache so that it will be refreshed upon next request
$this->call('modelCache:clear', ['--model' => AffixGroupEaseTier::class]);
$this->call('modelCache:clear', ['--model' => SubcreationEaseTierPull::class]);
$this->call('modelCache:clear', ['--model' => AffixGroupEaseTierPull::class]);

return 0;
}

/**
* @param SeasonServiceInterface $seasonService
* @param string $affixString
* @return int|null
*/
private function getAffixGroupByString(SeasonServiceInterface $seasonService, string $affixString): ?int
{
$affixGroupId = null;

$affixList = Affix::all();
$currentSeason = $seasonService->getCurrentSeason();
$currentSeasonAffixGroups = $currentSeason->affixgroups;

$affixes = collect(explode(', ', $affixString));

// Filter out properties that don't have the correct amount of affixes
if ($affixes->count() === 3 + (int)($currentSeason->seasonal_affix_id !== null)) {
// Check if there's any affixes in the list that we cannot find in our own database
$invalidAffixes = $affixes->filter(function (string $affixName) use ($affixList) {
// Find the affix in the list and match by translated name - must be found to continue
return $affixList->filter(function (Affix $affix) use ($affixName) {
return __($affix->name, [], 'en-US') === $affixName;
})->isEmpty();
});

// Non invalid affixes found, great!
if ($invalidAffixes->isNotEmpty()) {
$this->error(sprintf('Unable to find Affix(es) %s', $invalidAffixes->join(', ')));
} // Cannot find an affix in this list - perhaps it's new?
else {
// Now we must find affixgroups that correspond to the affix list
foreach ($currentSeasonAffixGroups as $affixGroup) {

// Loop over the affixes of the affix group and empty the list
$notFoundAffixes = $affixGroup->affixes->filter(function (Affix $affix) use ($affixes) {
return $affixes->search($affix->key) === false;
});

// If we have found the match, we're done
if ($notFoundAffixes->isEmpty()) {
$affixGroupId = $affixGroup->id;
break;
}
}
}
}

return $affixGroupId;
}
}
4 changes: 2 additions & 2 deletions app/Http/Resources/Affix/AffixResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function toArray($request)
{
return [
'id' => $this->affix_id,
'name' => __($this->name, [], 'en')
'name' => __($this->name, [], 'en-US')
];
}
}
}
4 changes: 2 additions & 2 deletions app/Http/Resources/Dungeon/DungeonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function toArray($request)
return [
'id' => $this->id,
'expansion_id' => $this->expansion_id,
'name' => __($this->name, [], 'en'),
'name' => __($this->name, [], 'en-US'),
'slug' => $this->slug,
'key' => $this->key,
'speedrun_enabled' => $this->speedrun_enabled,
];
}
}
}
8 changes: 8 additions & 0 deletions app/Jobs/RefreshDiscoverCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class RefreshDiscoverCache implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public int $timeout = 1800;

public function __construct()
{
$this->queue = sprintf('%s-%s-long-running', config('app.type'), config('app.env'));
}


/**
* @throws Exception
*/
Expand Down
Loading

0 comments on commit 3bd7350

Please sign in to comment.