Ejemplo n.º 1
0
    def get_race_level(self, level_no, race):
        if isinstance(race, unicode):
            group = ArtifactGroup.get(race)
        elif race:
            group = ArtifactGroup.get(race.name)
        else:
            group = None

        name = 'level-%d' % level_no
        full_name = '%s-%s-%s' % (group.name if group else 'default', name, 100)
        full_fallback = '%s-%s-%s' % ('default', name, 100)
        return Artifact.get(full_name) or Artifact.get(full_fallback) or NoArtifactLevel(level_no)
Ejemplo n.º 2
0
    def get_race_level(self, level_no, race):
        try:
            group = ArtifactGroup.objects.get(name=race.name)
        except (ArtifactGroup.DoesNotExist, AttributeError):
            group = Artifact.DEFAULT()

        name = 'level-%d' % level_no
        try:
            return Artifact.objects.get(name=name, group=group)
        except Artifact.DoesNotExist:
            try:
                return Artifact.objects.get(name=name,
                                            group=Artifact.DEFAULT())
            except Artifact.DoesNotExist:
                return NoArtifactLevel(level_no)
Ejemplo n.º 3
0
    def test_early_bird_not(self):
        player = self._get_player()
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-early-bird')
        for i in range(1, 2):
            Activity.objects.create(timestamp=datetime(2012, 9, 17, 6, 0, 0),
                                    user_from=player,
                                    user_to=player,
                                    action='seen',
                                    public=False)

        for i in range(1, 4):
            Activity.objects.create(timestamp=datetime(2012, 9, 17, 5, 0, 0),
                                    user_from=player,
                                    user_to=player,
                                    action='seen',
                                    public=False)

        signals.addActivity.send(sender=None,
                                 timestamp=datetime(2012, 9, 17, 5, 0, 0),
                                 user_from=player,
                                 user_to=player,
                                 action='seen',
                                 game=None)
        self.assertFalse(player.magic.has_modifier('ach-early-bird'))
Ejemplo n.º 4
0
    def test_challenges_played_today_activity(self):
        player = self._get_player()
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-chall-10-a-day')
        for i in range(1, 10):
            timestamp = datetime.now()
            if (i % 4) == 0:
                Activity.objects.create(timestamp=timestamp,
                                        user_from=player,
                                        user_to=player,
                                        action="chall-lost",
                                        public=True)
            else:
                Activity.objects.create(timestamp=timestamp,
                                        user_from=player,
                                        user_to=player,
                                        action="chall-won",
                                        public=True)

        signals.addActivity.send(sender=None,
                                 user_from=player,
                                 user_to=player,
                                 action='chall-won',
                                 game=ChallengeGame.get_instance())
        self.assertTrue(player.magic.has_modifier('ach-chall-10-a-day'))
Ejemplo n.º 5
0
 def test_this_is_sparta_activity_passed(self):
     Artifact.objects.create(group=Artifact.DEFAULT(),
                             name='ach-this-is-sparta')
     player1 = self._get_player()
     player2 = self._get_player(2)
     first_seen = datetime.now() + timedelta(days=-7)  #barely enough time
     Activity.objects.create(timestamp=first_seen,
                             user_from=player1,
                             user_to=player1,
                             action='seen',
                             public=False)
     for i in range(1, 5):
         timestamp = datetime.now() + timedelta(days=-i)
         a = Activity.objects.create(timestamp=timestamp,
                                     user_from=player1,
                                     user_to=player2,
                                     action='chall-lost',
                                     public=True)
     #send signal to enable achievement validation
     signals.addActivity.send(sender=None,
                              user_from=player1,
                              user_to=player2,
                              action='chall-won',
                              game=ChallengeGame.get_instance())
     #achievement condition earned
     self.assertTrue(player1.magic.has_modifier('ach-this-is-sparta'))
Ejemplo n.º 6
0
 def test_this_is_sparta_activity_not_given(self):
     Artifact.objects.create(group=Artifact.DEFAULT(),
                             name='ach-this-is-sparta')
     player1 = self._get_player()
     player2 = self._get_player(2)
     first_seen = datetime.now() + timedelta(
         days=-10)  #10 days since first login
     Activity.objects.create(timestamp=first_seen,
                             user_from=player1,
                             user_to=player1,
                             action='seen',
                             public=False)
     for i in range(1, 7):
         timestamp = datetime.now() + timedelta(days=-i)
         if (i % 4) == 0:
             a = Activity.objects.create(timestamp=timestamp,
                                         user_from=player1,
                                         user_to=player2,
                                         action='chall-refused',
                                         public=True)
         else:
             a = Activity.objects.create(timestamp=timestamp,
                                         user_from=player1,
                                         user_to=player2,
                                         action='chall-lost',
                                         public=True)
     #send signal to enable achievement validation
     signals.addActivity.send(sender=None,
                              user_from=player1,
                              user_to=player2,
                              action='chall-refused',
                              game=ChallengeGame.get_instance())
     #False due to refused challenge
     self.assertFalse(player1.magic.has_modifier('ach-this-is-sparta'))
Ejemplo n.º 7
0
    def test_this_is_sparta_activity(self):
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-this-is-sparta')
        player1 = self._get_player()
        player2 = self._get_player(2)
        for i in range(1, 7):
            timestamp = datetime.now() + timedelta(days=-i)
            if (i % 4) == 0:
                a = Activity.objects.create(timestamp=timestamp,
                                            user_from=player1,
                                            user_to=player2,
                                            action='chall-refused',
                                            public=True)
            else:
                a = Activity.objects.create(timestamp=timestamp,
                                            user_from=player1,
                                            user_to=player2,
                                            action='chall-lost',
                                            public=True)

        signals.addActivity.send(sender=None,
                                 user_from=player1,
                                 user_to=player2,
                                 action='chall-refused',
                                 game=ChallengeGame.get_instance())
        self.assertTrue(player1.magic.has_modifier('ach-this-is-sparta'))
Ejemplo n.º 8
0
 def test_bad_start_3(self):
     Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-bad-start')
     player = self._get_player()
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              action='qotd-wrong',
                              game=QotdGame.get_instance())
     self.assertTrue(player.magic.has_modifier('ach-bad-start'))
Ejemplo n.º 9
0
 def test_night_owl_set(self):
     player = self._get_player()
     Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-night-owl')
     signals.addActivity.send(sender=None,
                              timestamp=datetime(2012, 9, 17, 3, 0, 0),
                              user_from=player,
                              user_to=player,
                              action='login',
                              game=None)
     self.assertTrue(player.magic.has_modifier('ach-night-owl'))
Ejemplo n.º 10
0
 def test_early_bird_not(self):
     player = self._get_player()
     Artifact.objects.create(group=Artifact.DEFAULT(),
                             name='ach-early-bird')
     signals.addActivity.send(sender=None,
                              timestamp=datetime(2012, 9, 17, 5, 0, 0),
                              user_from=player,
                              user_to=player,
                              action='login',
                              game=None)
     self.assertTrue(not player.magic.has_modifier('ach-early-bird'))
Ejemplo n.º 11
0
    def get_user_level(self, level_no, player):
        """
        Return the artifact object for the given level_no.
        If there is a group for player series, use it.
        """
        try:
            group = Group.objects.get(name=player.series.name)
        except (Group.DoesNotExist, AttributeError):
            group = Artifact.DEFAULT()

        name = 'level-%d' % level_no
        try:
            artifact = Artifact.objects.get(name=name, group=group)
        except Artifact.DoesNotExist:
            artifact = Artifact.objects.get(name=name,
                                            group=Artifact.DEFAULT())
        except Artifact.DoesNotExist:
            return None

        return artifact
Ejemplo n.º 12
0
    def test_login_10_activity(self):
        Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-login-10')
        player = self._get_player()
        for i in range(1, 10):
            timestamp = datetime.now() + timedelta(days=-i)
            a = Activity.objects.create(timestamp=timestamp,
                                        user_from=player,
                                        action='seen',
                                        public=False)

        self.client.login(username=player.user.username, password='******')
        self.client.get('/hub/')

        self.assertTrue(player.magic.has_modifier('ach-login-10'))
Ejemplo n.º 13
0
    def test_defeated_better_player_activity(self):
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-chall-def-big')
        player1 = self._get_player()
        player2 = self._get_player(2)
        player2.level_no = 4
        player2.save()

        signals.addActivity.send(sender=None,
                                 user_from=player1,
                                 user_to=player2,
                                 action='chall-won',
                                 game=ChallengeGame.get_instance())
        self.assertTrue(player1.magic.has_modifier('ach-chall-def-big'))
Ejemplo n.º 14
0
 def test_ach(self):
     Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-win-fast')
     player = self._get_player()
     self.chall.user_from.seconds_took = 30
     self.chall.user_from.score = 400
     self.chall.user_from.save()
     self.chall.user_to.seconds_took = 80
     self.chall.user_to.score = 300
     self.chall.user_to.save()
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              arguments=dict(id=self.chall.id),
                              action="chall-won",
                              game=ChallengeGame.get_instance())
     self.assertTrue(player.magic.has_modifier('ach-win-fast'))
Ejemplo n.º 15
0
    def testModifierPercents(self):
        artif = Artifact.objects.create(name='test', group=Artifact.DEFAULT(), percents=50)
        user = User.objects.create(username='******')
        player = user.get_profile()

        player.give_modifier('test', 1)
        self.assertEqual(player.modifier_percents('test'), 150)

        player.give_modifier('test', 1)
        self.assertEqual(player.modifier_percents('test'), 200)

        artif.percents = -50
        artif.save()
        self.assertEqual(player.modifier_percents('test'), 0)

        user.delete()
        artif.delete()
Ejemplo n.º 16
0
 def test_10_qotd_get_ach(self):
     Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-qotd-10')
     player = self._get_player()
     for i in range(10):
         timestamp = datetime.now() + timedelta(days=-i)
         a = Activity.objects.create(timestamp=timestamp,
                                     user_from=player,
                                     user_to=player,
                                     action='qotd-correct',
                                     message_string=str(i),
                                     public=True)
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              action='qotd-correct',
                              game=QotdGame.get_instance())
     self.assertTrue(player.magic.has_modifier('ach-qotd-10'))
Ejemplo n.º 17
0
 def test_spell_count_activity(self):
     Artifact.objects.create(group=Artifact.DEFAULT(), name='ach-spell-5')
     player = self._get_player()
     for i in range(1, 6):
         name = "test" + str(i)
         spell = Spell.objects.create(name=name,
                                      title="",
                                      description="",
                                      image=None,
                                      percents=100)
         player.magic.add_spell(spell)
         player.magic.cast_spell(spell, player,
                                 datetime.now() + timedelta(days=i))
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              action="cast",
                              game=None)
     self.assertTrue(player.magic.has_modifier('ach-spell-5'))
Ejemplo n.º 18
0
    def test_chall_10_won_activity(self):
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-chall-won-10')
        player = self._get_player()
        for i in range(1, 10):
            timestamp = datetime.now() + timedelta(days=-i)
            a = Activity.objects.create(timestamp=timestamp,
                                        user_from=player,
                                        user_to=player,
                                        action='chall-won',
                                        public=True)

        self.assertFalse(player.magic.has_modifier('ach-chall-won-10'))
        signals.addActivity.send(sender=None,
                                 user_from=player,
                                 user_to=player,
                                 action='chall-won',
                                 game=ChallengeGame.get_instance())
        self.assertTrue(player.magic.has_modifier('ach-chall-won-10'))
Ejemplo n.º 19
0
    def test_check_for_god_mode3(self):
        player = self._get_player()
        player2 = self._get_player(1)
        timestamp = datetime.now()
        for i in range(5):
            timestamp -= timedelta(days=1)
            Activity.objects.create(timestamp=timestamp,
                                    user_from=player,
                                    user_to=player2,
                                    action='chall-won')
            Activity.objects.create(timestamp=timestamp,
                                    user_from=player,
                                    user_to=player,
                                    action='qotd-correct')
        self.assertTrue(check_for_god_mode(player, 5, 5))

        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-god-mode-on')
        signals.addActivity.send(sender=None,
                                 user_from=player,
                                 user_to=player,
                                 action='seen',
                                 game=None)
        self.assertTrue(player.magic.has_modifier('ach-god-mode-on'))
Ejemplo n.º 20
0
 def test_ach(self):
     Artifact.objects.create(group=Artifact.DEFAULT(),
                             name='ach-flawless-victory')
     player = self._get_player()
     self.chall.user_from.score = 100
     self.chall.user_from.save()
     self.chall.user_to.score = 200
     self.chall.user_to.save()
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              arguments=dict(id=self.chall.id),
                              action="chall-won",
                              game=None)
     self.assertTrue(not player.magic.has_modifier('ach-flawless-victory'))
     self.chall.user_from.score = 500
     self.chall.user_from.save()
     signals.addActivity.send(sender=None,
                              user_from=player,
                              user_to=player,
                              arguments=dict(id=self.chall.id),
                              action="chall-won",
                              game=None)
     self.assertTrue(player.magic.has_modifier('ach-flawless-victory'))
Ejemplo n.º 21
0
    def test_popularity_5_pm_3(self):
        Artifact.objects.create(group=Artifact.DEFAULT(),
                                name='ach-popularity')
        user_to = self._get_player(100).get_extension(MessagingUser)
        for i in range(10):
            player = self._get_player(i).get_extension(MessagingUser)
            if i <= 3:
                timestamp = datetime.now() + timedelta(minutes=-1)
                a = Message.objects.create(timestamp=timestamp,
                                           sender=player,
                                           receiver=user_to,
                                           subject="a",
                                           text="b")
            else:
                timestamp = datetime.now() + timedelta(minutes=-35)
                a = Message.objects.create(timestamp=timestamp,
                                           sender=player,
                                           receiver=user_to,
                                           subject="a",
                                           text="b")
        Message.send(sender=player, receiver=user_to, subject="a", text="b")

        self.assertEqual(unique_users_pm(user_to, 30), 5)
        self.assertTrue(user_to.magic.has_modifier('ach-popularity'))
Ejemplo n.º 22
0
 def test_ach_notification(self):
     player = self._get_player()
     Artifact.objects.create(group=Artifact.DEFAULT(),
                             name='ach-notfication')
     Achievements.earn_achievement(player, 'ach-notfication')
     self.assertEqual(len(Message.objects.all()), 1)