|
|
@@ -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: |
|
|
|