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

don't reactivate achievement for demoted event achievement #3146

Merged
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
3 changes: 3 additions & 0 deletions app/Helpers/database/player-game.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ function reactivateUserEventAchievements(User $user, array $userUnlocks): array
// find any active event achievements for the set of achievements that the user has already unlocked
$activeEventAchievementMap = EventAchievement::active()
->whereIn('source_achievement_id', array_keys($userUnlocks))
->whereHas('achievement', function ($query) {
$query->where('Flags', AchievementFlag::OfficialCore->value);
})
->get(['source_achievement_id', 'achievement_id'])
->mapWithKeys(function ($eventAchievement, int $key) {
return [$eventAchievement->achievement_id => $eventAchievement->source_achievement_id];
Expand Down
45 changes: 44 additions & 1 deletion tests/Feature/Connect/StartSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Models\User;
use App\Platform\Actions\AssociateAchievementSetToGameAction;
use App\Platform\Actions\UpsertGameCoreAchievementSetFromLegacyFlagsAction;
use App\Platform\Enums\AchievementFlag;
use App\Platform\Enums\AchievementSetType;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -400,7 +401,7 @@ public function testStartSession(): void

// ----------------------------
// event achievement outside of active range is ignored
/** @var Achievement $eventAchievement2 */
/** @var Achievement $eventAchievement3 */
$eventAchievement3 = Achievement::factory()->published()->create(['GameID' => $eventGame->ID]);
EventAchievement::create([
'achievement_id' => $eventAchievement2->ID,
Expand All @@ -409,6 +410,48 @@ public function testStartSession(): void
'active_until' => $now->clone()->addDays(5),
]);

$this->withHeaders(['User-Agent' => $this->userAgentValid])
->get($this->apiUrl('startsession', ['g' => $game->ID, 'm' => $gameHash->md5]))
->assertExactJson([
'Success' => true,
'HardcoreUnlocks' => [
[
'ID' => $achievement1->ID,
'When' => $unlock1Date->timestamp,
],
[
'ID' => $achievement2->ID,
'When' => $unlock2Date->timestamp,
],
[
'ID' => $bonusAchievement1->ID,
'When' => $bonusUnlock1Date->timestamp,
],
],
'Unlocks' => [
[
'ID' => $achievement3->ID,
'When' => $unlock3Date->timestamp,
],
[
'ID' => $bonusAchievement2->ID,
'When' => $bonusUnlock2Date->timestamp,
],
],
'ServerNow' => Carbon::now()->timestamp,
]);

// ----------------------------
// demoted event achievement is ignored
/** @var Achievement $eventAchievement4 */
$eventAchievement4 = Achievement::factory()->published()->create(['GameID' => $eventGame->ID, 'Flags' => AchievementFlag::Unofficial->value]);
EventAchievement::create([
'achievement_id' => $eventAchievement4->ID,
'source_achievement_id' => $achievement1->ID,
'active_from' => $now->clone()->subDays(2),
'active_until' => $now->clone()->addDays(5),
]);

$this->withHeaders(['User-Agent' => $this->userAgentValid])
->get($this->apiUrl('startsession', ['g' => $game->ID, 'm' => $gameHash->md5]))
->assertExactJson([
Expand Down