Skip to content

Commit

Permalink
During the beta, once a puzzle is solved, all other hints become free. (
Browse files Browse the repository at this point in the history
PuzzleServer#386)

* During the beta, once a puzzle is solved, all other hints become free.

* Use event name to determine if this is a beta or not for making hints free.
  • Loading branch information
bruceleban authored and tabascq committed Apr 10, 2019
1 parent 045abd3 commit df30f13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ServerCore/Pages/Teams/Hints.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,26 @@ public async Task<IActionResult> OnGetAsync(int puzzleId, int teamId)
return Page();
}

private async Task<IList<HintWithState>> GetAllHints(int puzzleId, int teamId)
private async Task<IList<HintWithState>> GetAllHints(int puzzleID, int teamID)
{
Hints = await (from Hint hint in _context.Hints
join HintStatePerTeam state in _context.HintStatePerTeam on hint.Id equals state.HintID
where state.TeamID == teamId && hint.Puzzle.ID == puzzleId
where state.TeamID == teamID && hint.Puzzle.ID == puzzleID
orderby hint.DisplayOrder, hint.Description
select new HintWithState { Hint = hint, IsUnlocked = state.IsUnlocked }).ToListAsync();
bool solved = await PuzzleStateHelper.IsPuzzleSolved(_context, puzzleID, teamID);

if (Hints.Count > 0)
{
int discount = Hints.Min(hws => (hws.IsUnlocked && hws.Hint.Cost < 0) ? hws.Hint.Cost : 0);
bool IsBeta = Event.Name.ToLower().Contains("beta");
if (solved && IsBeta)
{
// During a beta, once a puzzle is solved, all other hints become free.
// There's no IsBeta flag on an event, so check the name.
// We can change this in the unlikely event there's a beta-themed hunt.
discount = -999;
}
foreach (HintWithState hint in Hints)
{
hint.Discount = discount;
Expand Down
13 changes: 13 additions & 0 deletions ServerCore/PuzzleStateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ public static async Task SetLockoutExpiryTimeAsync(
await context.SaveChangesAsync();
}

/// <summary>
/// Get the solved status of a single puzzle.
/// Do not use if you want to get status of many puzzles as it will be very inefficient.
/// </summary>
/// <returns></returns>
public static async Task<bool> IsPuzzleSolved(PuzzleServerContext context, int puzzleID, int teamID)
{
DateTime? solved = await (from PuzzleStatePerTeam pspt in context.PuzzleStatePerTeam
where pspt.PuzzleID == puzzleID && pspt.TeamID == teamID
select pspt.SolvedTime).FirstOrDefaultAsync();
return solved != null;
}

private static DateTime LastGlobalExpiry;
private static Dictionary<int, DateTime> TimedUnlockExpiryCache = new Dictionary<int, DateTime>();
private static TimeSpan ClosestExpirySpacing = TimeSpan.FromSeconds(2);
Expand Down

0 comments on commit df30f13

Please sign in to comment.