From f088b9e850ff76b387a3eb1a26fcff6abbe52298 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 28 May 2012 02:18:46 -0400 Subject: [PATCH] title_at_stake change --- fowl/game/models.py | 92 ++++++++++++++++++-------------- fowl/game/templates/stables.html | 4 +- fowl/game/tests.py | 14 ++--- setup_league.py | 13 ++--- 4 files changed, 69 insertions(+), 54 deletions(-) diff --git a/fowl/game/models.py b/fowl/game/models.py index 200758e..de94a47 100644 --- a/fowl/game/models.py +++ b/fowl/game/models.py @@ -4,14 +4,13 @@ from django.contrib.auth.models import User # these things are independent of the game -OUTCOMES = ( - ('no contest', 'no contest'), - ('normal', 'normal'), - ('DQ', 'DQ'), - ('submission', 'submission'), - ('appearance', 'appearance'), - ('brawl', 'brawl'), - ) +OUTCOMES = (('no contest', 'no contest'), + ('normal', 'normal'), + ('DQ', 'DQ'), + ('submission', 'submission'), + ('appearance', 'appearance'), + ('brawl', 'brawl'), + ) TITLES = (('wwe', 'WWE'), ('heavyweight', 'Heavyweight'), @@ -53,7 +52,7 @@ class Event(models.Model): def add_match(self, *teams, **kwargs): winner = kwargs.get('winner', None) outcome = kwargs.get('outcome', '') - title_at_stake = kwargs.get('title_at_stake', False) + title_at_stake = kwargs.get('title_at_stake', None) notes = kwargs.get('notes', '') match = Match.objects.create(event=self, @@ -89,7 +88,7 @@ class Match(models.Model): event = models.ForeignKey(Event, related_name='matches') winner = models.ForeignKey(Star, null=True) outcome = models.CharField(max_length=10, choices=OUTCOMES) - title_at_stake = models.BooleanField(default=False) + title_at_stake = models.CharField(max_length=50, choices=TITLES, null=True) notes = models.TextField(blank=True, default='') def record_win(self, star, outcome): @@ -100,6 +99,16 @@ class Match(models.Model): self.outcome = outcome self.save() + def do_title_change(self): + if self.title_at_stake: + victors = list(self.teams.get(victorious=True).members.all()) + if len(victors) == 1: + victor[0].win_title(self.title_at_stake) + elif len(victors) == 2 and self.title_at_stake == 'tag': + victor[0].win_title(self.title_at_stake, victor[1]) + else: + raise ValueError('invalid number of victors for title change') + def points(self): points = {} winners = None @@ -147,39 +156,41 @@ class Match(models.Model): for w in winners.members.all(): points[w.id] = base_points - # if multiple people in this match and this person was credited - # w/ win, give them the bonus points - if allies and w.id == self.winner_id: - points[w.id] += 1 - if w.id == self.winner_id and self.outcome == 'submission': - points[w.id] += 1 - - # look over all titles in this match - for title, title_team in title_teams.iteritems(): - # title defense - if winners.title == title and self.title_at_stake: - if title in ('heavyweight', 'wwe'): + if self.title_at_stake: + if winners.title == self.title_at_stake: + # title defense + if winners.title in ('heavyweight', 'wwe'): points[w.id] += 5 else: points[w.id] += 3 - # beat someone w/ title - elif winners.title != title: - # title win - if self.title_at_stake and self.outcome != 'DQ': - if title in ('heavyweight', 'wwe'): - points[w.id] += 20 - else: - points[w.id] += 10 - # title team gets a point if they defend title by DQ - elif self.title_at_stake and self.outcome == 'DQ': - for star in title_team.members.all(): - points[star.id] += 1 - # beat tag champs in tag match w/o tag belt on line - elif title == 'tag' and all(c == 2 for c in losers): - points[w.id] += 2 - # beat champ in non-handicap match w/o belt on line - elif all(c == 1 for c in losers): - points[w.id] += 2 + elif self.outcome in ('normal', 'submission'): + # title win! + if self.title_at_stake in ('heavyweight', 'wwe'): + points[w.id] += 20 + else: + points[w.id] += 10 + else: + # defense by DQ + for star in title_teams[self.title_at_stake].members.all(): + points[star.id] += 1 + else: + # look over titles in match, to score a title-nondefense + for title, title_team in title_teams.iteritems(): + # beat someone w/ title in a non-defense + if winners.title != title: + # beat tag champs in tag match w/o tag belt on line + if title == 'tag' and all(c == 2 for c in losers): + points[w.id] += 2 + # beat champ in non-handicap match w/o belt on line + elif all(c == 1 for c in losers): + points[w.id] += 2 + + # if multiple people in this match and this person was credited + # w/ win, give them the bonus points + if allies: + points[self.winner_id] += 1 + if self.outcome == 'submission': + points[self.winner_id] += 1 return points def __unicode__(self): @@ -208,6 +219,7 @@ class MatchTeam(models.Model): class League(models.Model): name = models.CharField(max_length=100) + active = models.BooleanField(default=True) raw_picks = models.IntegerField(default=3) smackdown_picks = models.IntegerField(default=3) diva_picks = models.IntegerField(default=2) diff --git a/fowl/game/templates/stables.html b/fowl/game/templates/stables.html index 5bebcd1..46566ee 100644 --- a/fowl/game/templates/stables.html +++ b/fowl/game/templates/stables.html @@ -17,7 +17,9 @@ - + diff --git a/fowl/game/tests.py b/fowl/game/tests.py index 6d3d190..d392dc2 100644 --- a/fowl/game/tests.py +++ b/fowl/game/tests.py @@ -170,31 +170,31 @@ class MatchTest(TestCase): # defending wwe belt is worth +5 match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk', - outcome='normal', title_at_stake=True) + outcome='normal', title_at_stake='wwe') self.assertEqual(match.points(), {'cmpunk': 7, 'reymysterio': 0}) # winning wwe belt match = self.event.add_match('cmpunk', 'reymysterio', winner='reymysterio', outcome='normal', - title_at_stake=True) + title_at_stake='wwe') self.assertEqual(match.points(), {'reymysterio': 22, 'cmpunk': 0}) # defending other belt is worth +3 match = self.event.add_match('christian', 'codyrhodes', winner='christian', outcome='normal', - title_at_stake=True) + title_at_stake='ic') self.assertEqual(match.points(), {'christian': 5, 'codyrhodes': 0}) # winning other belt is worth +10 match = self.event.add_match('christian', 'codyrhodes', winner='codyrhodes', outcome='normal', - title_at_stake=True) + title_at_stake='ic') self.assertEqual(match.points(), {'codyrhodes': 12, 'christian': 0}) # title non-defense (DQ/countout) match = self.event.add_match('christian', 'codyrhodes', winner='codyrhodes', outcome='DQ', - title_at_stake=True) + title_at_stake='ic') self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1}) # no bonus in a tag match @@ -215,7 +215,7 @@ class MatchTest(TestCase): match = self.event.add_match(['kofikingston', 'rtruth'], ['reymysterio', 'sin-cara'], winner='reymysterio', outcome='normal', - title_at_stake=True) + title_at_stake='tag') self.assertEqual(match.points(), {'sin-cara': 12, 'reymysterio': 13, 'kofikingston': 0, 'rtruth': 0}) @@ -253,7 +253,7 @@ class LeagueTest(TestCase): match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'], winner='mickfoley', outcome='normal') _give_belt('codyrhodes', 'ic') - match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True, + match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake='ic', winner='sin-cara', outcome='normal') self.league.score_event(event) diff --git a/setup_league.py b/setup_league.py index 6b45548..ab3f5e1 100644 --- a/setup_league.py +++ b/setup_league.py @@ -84,17 +84,18 @@ event.add_match('alexriley', 'christian', 'curthawkins', 'darrenyoung', 'tylerreks', 'tysonkidd', 'williamregal', 'yoshitatsu', winner='christian', outcome='normal') event.add_match(['kofikingston', 'rtruth'], ['dolphziggler', 'jackswagger'], - winner='kofikingston', outcome='normal', title_at_stake=True) + winner='kofikingston', outcome='normal', title_at_stake='tag') event.add_match('layla', 'bethphoenix', winner='layla', - outcome='normal', title_at_stake=True) + outcome='normal', title_at_stake='divas') event.add_match('sheamus', 'randyorton', 'chrisjericho', 'albertodelrio', - winner='sheamus', outcome='normal', title_at_stake=True) + winner='sheamus', outcome='normal', + title_at_stake='heavyweight') event.add_match('brodusclay', 'themiz', winner='brodusclay', outcome='normal') -event.add_match('christian', 'codyrhodes', winner='christian', outcome='normal', - title_at_stake=True) +event.add_match('christian', 'codyrhodes', winner='christian', + outcome='normal', title_at_stake='ic') _give_belt('christian', 'ic') event.add_match('cmpunk', 'danielbryan', winner='cmpunk', outcome='normal', - title_at_stake=True) + title_at_stake='wwe') event.add_match('ryback', 'camacho', winner='ryback', outcome='normal') event.add_match('john-laurinaitis', 'johncena', 'bigshow', winner='john-laurinaitis',
+ +