Browse Source

Fix to fear phase logic; add event phase support; add revert phase button.

feature/js
Daniel Perelman 2 years ago
parent
commit
b92159d4de
3 changed files with 57 additions and 7 deletions
  1. +49
    -5
      fear_tracker/models.py
  2. +1
    -0
      fear_tracker/templates/game.html
  3. +7
    -2
      fear_tracker/views.py

+ 49
- 5
fear_tracker/models.py View File

@@ -22,8 +22,13 @@ class Game(models.Model):
GAME_PHASE_GROWTH_SPIRIT = 3
GAME_PHASE_FAST = 4
GAME_PHASE_BLIGHTED_ISLAND = 5
GAME_PHASE_FEAR = 6
GAME_PHASE_FEAR_CARDS = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
GAME_PHASE_EVENT_MAIN = 6
GAME_PHASE_EVENT_TOKEN = 7
GAME_PHASE_EVENT_DAHAN = 8
GAME_PHASE_EVENT_COMBINED = 9
GAME_PHASE_FEAR = 50
GAME_PHASE_FEAR_CARDS = [51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65]
GAME_PHASE_ENGLAND_BUILD = 100
GAME_PHASE_RAVAGE = 101
GAME_PHASE_BUILD = 102
@@ -33,8 +38,10 @@ class Game(models.Model):
game_phase = models.IntegerField(default=GAME_PHASE_LOBBY)
created = models.DateTimeField()
ended = models.DateTimeField(null=True, default=None)
combined_growth_spirit = models.BooleanField(default=False)
combined_growth_spirit = models.BooleanField(default=True)
england_build = models.BooleanField(default=False)
enable_events = models.BooleanField(default=False)
combined_event = models.BooleanField(default=False)
fear_per_card = models.IntegerField()

# from http://stackoverflow.com/a/11821832
@@ -62,16 +69,25 @@ class Game(models.Model):
def next_phase():
if self.game_phase == Game.GAME_PHASE_SPIRIT:
return Game.GAME_PHASE_FAST
elif self.game_phase == Game.GAME_PHASE_BLIGHTED_ISLAND:
elif self.game_phase == Game.GAME_PHASE_BLIGHTED_ISLAND\
and not self.enable_events\
or self.game_phase in [Game.GAME_PHASE_EVENT_DAHAN,
Game.GAME_PHASE_EVENT_COMBINED]:
if self.num_available_fear_cards() == 0:
return Game.GAME_PHASE_FEAR
else:
return Game.GAME_PHASE_FEAR_CARDS[0]
elif self.game_phase == Game.GAME_PHASE_BLIGHTED_ISLAND\
and self.enable_events:
if self.combined_event:
return Game.GAME_PHASE_EVENT_COMBINED
else:
return Game.GAME_PHASE_EVENT_MAIN
elif self.game_phase == Game.GAME_PHASE_FEAR or\
self.game_phase in Game.GAME_PHASE_FEAR_CARDS:
num_fear = self.fear_cards_in_current_fear_phase()
fear_so_far = self.game_phase - Game.GAME_PHASE_FEAR
if num_fear < fear_so_far:
if num_fear > fear_so_far:
return self.game_phase + 1
else:
if self.england_build:
@@ -161,6 +177,26 @@ class Game(models.Model):
self.player_set.update(ready=False)
return next_phase

def revert_phase(self):
previous_phase =\
self.phase_set.filter(game_turn=self.game_turn,
game_phase__lt=self.game_phase)\
.order_by('game_phase').last()
if not previous_phase:
previous_phase = self.phase_set\
.filter(game_turn=self.game_turn-1)\
.order_by('game_phase')\
.last()
if not previous_phase:
return
previous_phase.ended = None
previous_phase.save()
self.game_turn = previous_phase.game_turn
self.game_phase = previous_phase.game_phase
self.save()
self.player_set.update(ready=True)
return previous_phase

@staticmethod
def get_name_for_phase_id(phase):
if phase == Game.GAME_PHASE_LOBBY:
@@ -175,6 +211,14 @@ class Game(models.Model):
return "Fast Actions"
elif phase == Game.GAME_PHASE_BLIGHTED_ISLAND:
return "Blighted Island"
elif phase == Game.GAME_PHASE_EVENT_MAIN:
return "Event (main/top)"
elif phase == Game.GAME_PHASE_EVENT_TOKEN:
return "Event (token/middle)"
elif phase == Game.GAME_PHASE_EVENT_DAHAN:
return "Event (dahan/bottom)"
elif phase == Game.GAME_PHASE_EVENT_COMBINED:
return "Event"
elif phase == Game.GAME_PHASE_FEAR:
return "Fear (no fear cards)"
elif phase in Game.GAME_PHASE_FEAR_CARDS:


+ 1
- 0
fear_tracker/templates/game.html View File

@@ -94,5 +94,6 @@
{% if all_ready %}
<input type="submit" name="advance" value="Advance to next phase">
{% endif %}
<input type="submit" name="revert" value="Revert to previous phase">
</form>
{% endblock %}

+ 7
- 2
fear_tracker/views.py View File

@@ -112,10 +112,11 @@ def game(request, game):
current_phase.game_turn == int(request.POST['game_turn'])\
and current_phase.game_phase == int(request.POST['game_phase'])
advance_phase = 'advance' in request.POST
revert_phase = 'revert' in request.POST
for key, value in request.POST.items():
sections = key.split('-')
if key in ['csrfmiddlewaretoken',
'update', 'advance',
'update', 'advance', 'revert',
'game_turn', 'game_phase', 'phase_name']\
or sections[-1] == 'orig':
pass
@@ -155,7 +156,7 @@ def game(request, game):
f"{player.name} " +
f"({player.get_spirit_name()})'s " +
f"#{effect_num} {effect_kind} " +
"could not be change from " +
"could not be changed from " +
f"{orig} to {amount} " +
f"because {old_phase} has already ended.")
else:
@@ -192,6 +193,10 @@ def game(request, game):
current_phase = game.advance_phase()
for player in players.values():
player.ready = False
elif revert_phase:
current_phase = game.revert_phase()
for player in players.values():
player.ready = True

for fear in current_phase.fear_set.order_by('effect').all():
players[fear.player.order].fear[fear.effect] = {


Loading…
Cancel
Save