Skip to content

Commit ea44d68

Browse files
Amends to the top 3 badge awarding
1 parent ae49580 commit ea44d68

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

php/badges.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function hh_badge_definitions(): array
1717
'CR' => ['token' => 'CR', 'image' => 'img/badges/crowd-rebel.png', 'title' => 'Crowd Rebel', 'description' => 'Beat the crowd with a different scoreline and still score 3+ points.'],
1818
'HS' => ['token' => 'HS', 'image' => 'img/badges/hot-streak.png', 'title' => 'Hot Streak', 'description' => 'Score points in three consecutive recorded fixtures.'],
1919
'AC' => ['token' => 'AC', 'image' => 'img/badges/avid-climber.png', 'title' => 'Avid Climber', 'description' => 'Climb 5 or more places in a single results update.'],
20-
'DH' => ['token' => 'DH', 'image' => 'img/badges/dizzy-heights.png', 'title' => 'Dizzy Heights', 'description' => 'Break into the top three of the rankings.'],
20+
'DH' => ['token' => 'DH', 'image' => 'img/badges/dizzy-heights.png', 'title' => 'Dizzy Heights', 'description' => 'Reach the top three once the knockout rounds begin.'],
2121
'TFT' => ['token' => 'TFT', 'image' => 'img/badges/top-form-turkey.png', 'title' => 'Top Form Turkey', 'description' => 'Hit three straight 7-pointers in consecutive scored fixtures.'],
2222
'TH' => ['token' => 'TH', 'image' => 'img/badges/thread-starter.png', 'title' => 'Thread Starter', 'description' => 'Start a message thread in the Fan Zone.'],
2323
'RP' => ['token' => 'RP', 'image' => 'img/badges/in-the-replies.png', 'title' => 'In The Replies', 'description' => 'Reply to a thread in the Fan Zone.'],
@@ -267,10 +267,7 @@ function hh_badge_stats_for_user(mysqli $con, int $userId): array
267267
$perfectStreak = 0;
268268
$lastPosition = (int) ($identity['lastpos'] ?? 0);
269269
$currentPosition = (int) ($identity['currpos'] ?? 0);
270-
271-
if ($currentPosition > 0 && $currentPosition <= 3 && (int) ($stats['points_total'] ?? 0) > 0) {
272-
$stats['dizzy_heights'] = true;
273-
}
270+
$knockoutsStarted = false;
274271

275272
foreach ($stageDefinitions as $stageKey => $definition) {
276273
$tableName = (string) ($definition['table'] ?? '');
@@ -292,6 +289,14 @@ function hh_badge_stats_for_user(mysqli $con, int $userId): array
292289
$startIndex = (int) ($definition['start'] ?? 0);
293290
$endIndex = (int) ($definition['end'] ?? -1);
294291
for ($homeIndex = $startIndex, $awayIndex = $startIndex + 1; $homeIndex <= $endIndex && $awayIndex <= $endIndex; $homeIndex += 2, $awayIndex += 2) {
292+
if ($stageKey === 'ro32' && !$knockoutsStarted) {
293+
$actualHome = $latestResults['score' . $homeIndex . '_r'] ?? null;
294+
$actualAway = $latestResults['score' . $awayIndex . '_r'] ?? null;
295+
if (is_numeric($actualHome) && is_numeric($actualAway)) {
296+
$knockoutsStarted = true;
297+
}
298+
}
299+
295300
if (hh_badge_is_exact_prediction($predictionRow, $latestResults, $homeIndex, $awayIndex)) {
296301
$stats['perfect_predictions']++;
297302
}
@@ -349,6 +354,10 @@ function hh_badge_stats_for_user(mysqli $con, int $userId): array
349354
$stats['avid_climber'] = true;
350355
}
351356

357+
if ($knockoutsStarted && $currentPosition > 0 && $currentPosition <= 3) {
358+
$stats['dizzy_heights'] = true;
359+
}
360+
352361
$username = trim((string) ($identity['username'] ?? ''));
353362
if ($username !== '' && hh_badge_table_exists_for_name($con, 'live_fanzone_posts')) {
354363
$statement = mysqli_prepare(

0 commit comments

Comments
 (0)