Skip to content

Commit

Permalink
Added playtest start/end dates to teams
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Feb 16, 2020
1 parent b26aef5 commit e576aa9
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
4 changes: 2 additions & 2 deletions huntserver/hunt_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def hunt(request, hunt_num):
if (hunt.is_public or request.user.is_staff):
puzzle_list = hunt.puzzle_set.all()

elif(team and team.is_playtester_team):
elif(team and team.is_playtester_team and team.playtest_started):
puzzle_list = team.unlocked.filter(hunt=hunt)

# Hunt has not yet started
Expand Down Expand Up @@ -297,7 +297,7 @@ def puzzle_hint(request, puzzle_id):

if request.method == 'POST':
# Can't request a hint if there aren't any left
if(team.num_available_hints == 0):
if(team.num_available_hints <= 0):
return HttpResponseForbidden()

form = HintRequestForm(request.POST)
Expand Down
56 changes: 34 additions & 22 deletions huntserver/management/commands/runupdates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,46 @@
from huntserver.models import Hunt, HintUnlockPlan


def check_hints(hunt):
num_min = (timezone.now() - hunt.start_date).seconds / 60
for hup in hunt.hintunlockplan_set.exclude(unlock_type=HintUnlockPlan.SOLVES_UNLOCK):
if((hup.unlock_type == hup.TIMED_UNLOCK and
hup.num_triggered < 1 and num_min > hup.unlock_parameter) or
(hup.unlock_type == hup.INTERVAL_UNLOCK and
num_min / hup.unlock_parameter < hup.num_triggered)):
hunt.team_set.all().update(num_available_hints=F('num_available_hints') + 1)
hup.num_triggered = hup.num_triggered + 1
hup.save()


def check_puzzles(hunt, new_points, teams):
teams.update(num_unlock_points=F('num_unlock_points') + new_points)
for team in teams:
team.unlock_puzzles()


class RunUpdates(BaseCommand):
help = 'Runs all time related updates for the huntserver app'

def handle(self, *args, **options):
curr_hunt = Hunt.objects.get(is_current_hunt=True)
if(not curr_hunt.is_open):
return
hunt = Hunt.objects.get(is_current_hunt=True)

last_update_time = curr_hunt.last_update_time.replace(second=0, microsecond=0)
curr_hunt.last_update_time = timezone.now()
curr_hunt.save()
last_update_time = hunt.last_update_time.replace(second=0, microsecond=0)
hunt.last_update_time = timezone.now()
hunt.save()
diff_time = timezone.now().replace(second=0, microsecond=0) - last_update_time
diff_minutes = diff_time.seconds / 60

# Check hints
num_min = (timezone.now() - curr_hunt.start_date).seconds / 60
for hup in curr_hunt.hintunlockplan_set.exclude(unlock_type=HintUnlockPlan.SOLVES_UNLOCK):
if((hup.unlock_type == hup.TIMED_UNLOCK and
hup.num_triggered < 1 and num_min > hup.unlock_parameter)
or (hup.unlock_type == hup.INTERVAL_UNLOCK and
num_min / hup.unlock_parameter < hup.num_triggered)):
curr_hunt.team_set.all().update(num_available_hints=F('num_available_hints') + 1)
hup.num_triggered = hup.num_triggered + 1
hup.save()

# Check puzzles
if(hunt.is_open):
check_hints

if(diff_minutes >= 1):
new_points = curr_hunt.points_per_minute * diff_minutes
curr_hunt.team_set.all().update(num_unlock_points=F('num_unlock_points') + new_points)
for team in curr_hunt.team_set.all():
team.unlock_puzzles()
new_points = hunt.points_per_minute * diff_minutes

if(hunt.is_open):
check_puzzles(hunt, new_points, hunt.team_set.all())
else:
playtesters = hunt.team_set.filter(playtester=True).all()
playtesters = [t for t in playtesters if t.playtest_happening]
if(len(playtesters) > 0):
check_puzzles(hunt, new_points, playtesters)
23 changes: 23 additions & 0 deletions huntserver/migrations/0049_auto_20200215_1930.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2 on 2020-02-16 00:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0048_auto_20200215_1743'),
]

operations = [
migrations.AddField(
model_name='team',
name='playtest_end_date',
field=models.DateTimeField(blank=True, help_text='The date/time at which a hunt will be archived and available to the public', null=True),
),
migrations.AddField(
model_name='team',
name='playtest_start_date',
field=models.DateTimeField(blank=True, help_text='The date/time at which a hunt will become visible to registered users', null=True),
),
]
27 changes: 27 additions & 0 deletions huntserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ class Team(models.Model):
playtester = models.BooleanField(
default=False,
help_text="A boolean to indicate if the team is a playtest team and will get early access")
playtest_start_date = models.DateTimeField(
null=True,
blank=True,
help_text="The date/time at which a hunt will become visible to registered users")
playtest_end_date = models.DateTimeField(
null=True,
blank=True,
help_text="The date/time at which a hunt will be archived and available to the public")
last_seen_message = models.IntegerField(
default=0)
last_received_message = models.IntegerField(
Expand All @@ -331,6 +339,25 @@ def is_playtester_team(self):
""" A boolean indicating whether or not the team is a playtesting team """
return self.playtester

@property
def playtest_started(self):
""" A boolean indicating whether or not the team is currently allowed to be playtesting """
if(self.playtest_start_date is None and self.playtest_end_date is None):
return False
return (timezone.now() >= self.playtest_start_date)

@property
def playtest_over(self):
""" A boolean indicating whether or not the team's playtest slot has passed """
if(self.playtest_start_date is None and self.playtest_end_date is None):
return False
return timezone.now() >= self.playtest_end_date

@property
def playtest_happening(self):
""" A boolean indicating whether or not the team's playtest slot has passed """
return self.playtest_started and not self.playtest_over

@property
def is_normal_team(self):
""" A boolean indicating whether or not the team is a normal (non-playtester) team """
Expand Down

0 comments on commit e576aa9

Please sign in to comment.