Ejemplo n.º 1
0
def player_race(request, race_id):
    race = get_object_or_404(Race, pk=race_id)

    top_users = race.player_set.order_by('-points')
    activity_qs = Activity.get_race_activity(race)
    paginator = Paginator(activity_qs, 20)
    activity = paginator.page(1)

    # get top position
    races = list(Race.objects.filter(can_play=True))
    races.sort(key=lambda a: a.points, reverse=True)
    if race in races:
        top_rank = races.index(race) + 1
    else:
        top_rank = '-'

    groups = NewHistory.get_children_top(race, PlayerGroup)

    # Get levels
    levels = []
    for i, limit in enumerate(God.get_level_limits()):
        level = God.get_race_level(level_no=i + 1, race=race)
        level.limit = limit
        levels.append(level)

    return render_to_response('profile/race.html', {
        'race': race,
        'children': groups,
        'top_users': top_users,
        'top_rank': top_rank,
        'top': ObjectHistory(),
        'activity': activity,
        'levels': levels
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check

        can_cast, error = God.can_cast(spell=spell,
                                       source=self.player,
                                       destination=player_dest)
        if not can_cast:
            return error
        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest,
                                                  source=self.player,
                                                  spell=spell,
                                                  due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            #extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest,
                                                      source=self.player,
                                                      spell=spell,
                                                      due=due)
            else:
                return None

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        return None
Ejemplo n.º 3
0
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            # extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        if psdue.source == psdue.player:
            signal_msg = _("cast a spell on himself/herself")
        else:
            signal_msg = _("cast a spell on {to} ")
        signals.addActivity.send(sender=None, user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 action='cast',
                                 game=None)

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        return None
Ejemplo n.º 4
0
    def cast_spell(self, spell, source, due):
        """ Cast a spell on this player.

        Returns: error message if the spell was not cast, or None
        """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return 'Spell unavailable'

        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell, source, self.player)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=self.player, source=source, spell=spell, due=due)
        except IntegrityError:
            return 'Cannot cast the same spell more than once'

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if not psamount.amount:
            psamount.delete()
        else:
            psamount.save()
        return None
Ejemplo n.º 5
0
    def cast_spell(self, spell, source, due):
        """ Curse self with given spell from source, for due time. """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return False

        # Pre-cat God actions: immunity and curse ar done by this
        # check
        if not God.can_cast(spell, source, self):
            return False

        try:
            psdue = PlayerSpellDue.objects.create(player=self, source=source, spell=spell, due=due)
        except Exception as e:
            logging.exception(e)
            return False
        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if psamount.amount == 0:
            psamount.delete()
        else:
            psamount.save()
        return True
Ejemplo n.º 6
0
def player_race(request, race_id):
    race = get_object_or_404(Race, pk=race_id)

    top_users = race.player_set.order_by('-points')
    activity_qs = Activity.get_race_activity(race)
    paginator = Paginator(activity_qs, 20)
    activity = paginator.page(1)

    # get top position
    races = list(Race.objects.filter(can_play=True))
    races.sort(key=lambda a: a.points, reverse=True)
    if race in races:
        top_rank = races.index(race) + 1
    else:
        top_rank = '-'

    groups = NewHistory.get_children_top(race, PlayerGroup)

    # Get levels
    levels = []
    for i, limit in enumerate(God.get_level_limits()):
        l = God.get_race_level(level_no=i + 1, race=race)
        l.limit = limit
        levels.append(l)

    return render_to_response('profile/race.html',
                            {'race': race,
                             'children': groups,
                             'top_users': top_users,
                             'top_rank': top_rank,
                             'top': ObjectHistory(),
                             'activity': activity,
                             'levels': levels},
                            context_instance=RequestContext(request)
    )
Ejemplo n.º 7
0
    def cast_spell(self, spell, source, due):
        """ Curse self with given spell from source, for due time. """
        try:
            psamount = PlayerSpellAmount.objects.get(player=source, spell=spell)
            assert psamount.amount > 0
        except (PlayerSpellAmount.DoesNotExist, AssertionError):
            return False

        # Pre-cat God actions: immunity and curse ar done by this
        # check
        if not God.can_cast(spell, source, self):
            return False

        try:
            psdue = PlayerSpellDue.objects.create(player=self, source=source, spell=spell, due=due)
        except Exception as e:
            logging.exception(e)
            return False
        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        psamount.amount -= 1
        if psamount.amount == 0:
            psamount.delete()
        else:
            psamount.save()
        return True
Ejemplo n.º 8
0
    def management_task(cls, datetime=lambda: datetime.now(), stdout=sys.stdout):
        spells = PlayerSpellDue.get_expired(datetime)

        stdout.write(" %d expired spells\n" % spells.count())
        for s in spells:
            SpellHistory.expired(s.player, s.spell)

            from wouso.core.god import God
            God.post_expire(psdue=s)
            s.delete()
Ejemplo n.º 9
0
    def management_task(cls,
                        datetime=lambda: datetime.now(),
                        stdout=sys.stdout):
        spells = PlayerSpellDue.get_expired(datetime)

        stdout.write(" %d expired spells\n" % spells.count())
        for s in spells:
            SpellHistory.expired(s.player, s.spell)

            from wouso.core.god import God
            God.post_expire(psdue=s)
            s.delete()
Ejemplo n.º 10
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)

    if level == player.level_no:
        return

	arguments = dict(level=level)
    if level < player.level_no:
        action_msg = 'level-downgrade'
        signal_msg = ugettext_noop("downgraded to level {level}")
		this_game = game
	else:
        action_msg = 'level-upgrade'
        # Check if the user has previously reached this level
        if level > player.max_level:
            # Update the maximum reached level
            player.max_level = level
            # Offer the corresponding amount of gold
            score(player, None, 'level-gold', external_id=level, level=level)

            signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
            amount = calculate('level-gold', level=level).get('gold', 0)
            arguments['amount'] = amount
        else:
            # The user should not receive additional gold
            signal_msg = ugettext_noop("upgraded back to level {level}")
		this_game = None

	signals.addActivity.send(sender=None, user_from=player,
                            user_to=player, message=signal_msg,
                            arguments=dict(level=level),
                            game=game, action=action_msg)
Ejemplo n.º 11
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            signal_msg = ugettext_noop("downgraded to level {level}")
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level),
                                     game=game)
        else:
            amount = calculate('level-gold', level=level)
            signal_msg = ugettext_noop(
                "upgraded to level {level} and received {amount} gold")
            score(player, None, 'level-gold', level=level)
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level,
                                                    amount=amount['gold']),
                                     game=None)
        player.level_no = level
        player.save()
Ejemplo n.º 12
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            amount = calculate('level-gold', level=player.level_no).get('gold', 0)
            action_msg = 'gold-lost'
            signal_msg = ugettext_noop("downgraded to level {level} and lost {amount} gold")
            rollback(player, None, 'level-gold', external_id=player.level_no)
            signals.addActivity.send(sender=None, user_from=player,
                                user_to=player, message=signal_msg,
                                arguments=dict(level=level, amount=amount),
                                game=game, action=action_msg)
        else:

            amount = calculate('level-gold', level=level)
            # Check if the user has previously reached this level
            if level > player.max_level:
                # Update the maximum reached level
                player.max_level = level
                # Offer the corresponding amount of gold
                score(player, None, 'level-gold', external_id=level, level=level)
            else:
                # The user should not receive additional gold
                amount['gold'] = 0
            signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
            action_msg = 'gold-won'
            signals.addActivity.send(sender=None, user_from=player,
                    user_to=player, message=signal_msg,
                                arguments=dict(level=level, amount=amount['gold']),
                                game=None, action=action_msg)
        player.level_no = level
        player.save()
Ejemplo n.º 13
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            amount = calculate('level-gold',
                               level=player.level_no).get('gold', 0)
            action_msg = 'gold-lost'
            signal_msg = ugettext_noop(
                "downgraded to level {level} and lost {amount} gold")
            rollback(player, None, 'level-gold', external_id=player.level_no)
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level,
                                                    amount=amount),
                                     game=game,
                                     action=action_msg)
        else:

            amount = calculate('level-gold', level=level)
            signal_msg = ugettext_noop(
                "upgraded to level {level} and received {amount} gold")
            action_msg = 'gold-won'
            score(player, None, 'level-gold', external_id=level, level=level)
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level,
                                                    amount=amount['gold']),
                                     game=None,
                                     action=action_msg)
        player.level_no = level
        player.save()
Ejemplo n.º 14
0
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check
        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error

        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            # extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        if psdue.source == psdue.player:
            signal_msg = _("cast a spell on himself/herself")
        else:
            signal_msg = _("cast a spell on {to} ")
        signals.addActivity.send(sender=None, user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 action='cast',
                                 game=None)

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        signals.postCast.send(sender=None, psdue=psdue)
        return None
Ejemplo n.º 15
0
    def give_modifier(self, modifier, amount=1):
        """ Add given amount to existing, or create new artifact amount
        for the current user.

        Return the PlayerArtifactAmount object after applying changes.
        """
        if amount <= 0:
            return

        # Check for existing artifact
        try:
            paamount = PlayerArtifactAmount.objects.get(
                player=self.player, artifact__name=modifier)
        except PlayerArtifactAmount.DoesNotExist:
            paamount = 0

        if not paamount:
            artifact = God.get_artifact_for_modifier(modifier, self.player)
            if not artifact:
                logging.debug('No such artifact: %s' % modifier)
                return None
            paamount = PlayerArtifactAmount.objects.create(player=self.player,
                                                           artifact=artifact,
                                                           amount=amount)
        else:
            paamount.amount += amount
            paamount.save()
        return paamount
Ejemplo n.º 16
0
 def get_context_data(self, **kwargs):
     context = super(ArtifactHomeView, self).get_context_data(**kwargs)
     modifiers = God.get_all_modifiers()
     groups = ArtifactGroup.objects.all()
     context.update(
         {'groups': groups, 'group': self.group, 'modifiers': modifiers})
     return context
Ejemplo n.º 17
0
    def give_modifier(self, modifier, amount=1):
        """ Add given amount to existing, or create new artifact amount
        for the current user.

        Return the PlayerArtifactAmount object after applying changes.
        """
        if amount <= 0:
            return

        # Check for existing artifact
        try:
            paamount = PlayerArtifactAmount.objects.get(player=self.player, artifact__name=modifier)
        except PlayerArtifactAmount.DoesNotExist:
            paamount = 0

        if not paamount:
            artifact = God.get_artifact_for_modifier(modifier, self.player)
            if not artifact:
                logging.debug('No such artifact: %s' % modifier)
                return None
            paamount = PlayerArtifactAmount.objects.create(player=self.player, artifact=artifact, amount=amount)
        else:
            paamount.amount += amount
            paamount.save()
        return paamount
Ejemplo n.º 18
0
Archivo: sm.py Proyecto: andreip/wouso
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            signal_msg = ugettext_noop("downgraded to level {level}")
            signals.addActivity.send(
                sender=None,
                user_from=player,
                user_to=player,
                message=signal_msg,
                arguments=dict(level=level),
                game=game,
            )
        else:
            amount = calculate("level-gold", level=level)
            signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
            score(player, None, "level-gold", level=level)
            signals.addActivity.send(
                sender=None,
                user_from=player,
                user_to=player,
                message=signal_msg,
                arguments=dict(level=level, amount=amount["gold"]),
                game=None,
            )
        player.level_no = level
        player.save()
Ejemplo n.º 19
0
    def read(self, request, player_id=None):
        if player_id:
            try:
                player = Player.objects.get(pk=player_id)
            except Player.DoesNotExist:
                return rc.NOT_FOUND
        else:
            try:
                player = request.user.get_profile()
            except Player.DoesNotExist:
                return rc.NOT_FOUND

        level = {
            'name': player.level.name,
            'title': player.level.title,
            'image': player.level.image,
            'id': player.level.id,
        } if player.level else {}

        group = player.group
        gold = player.coins['gold'] if 'gold' in player.coins.keys() else 0
        topuser = player.get_extension(TopUser)

        return {
            'username':
            player.user.username,
            'nickname':
            player.nickname,
            'first_name':
            player.user.first_name,
            'last_name':
            player.user.last_name,
            'email':
            player.user.email,
            'avatar':
            player_avatar(player),
            'points':
            player.points,
            'gold':
            gold,
            'race':
            player.race_name,
            'race_slug':
            player.race.name.lower()
            if player.race and player.race.name else '',
            'race_id':
            player.race.id if player.race else 0,
            'group':
            group,
            'level_no':
            player.level_no,
            'level':
            level,
            'level_progress':
            God.get_level_progress(player),
            'rank':
            topuser.position,
        }
Ejemplo n.º 20
0
 def can_challenge(self, user):
     """ Check if the target user is available.
     """
     user = user.get_extension(ChallengeUser)
     if self.user == user.user:
         # Cannot challenge myself
         return False
     if user.magic.has_modifier('challenge-cannot-be-challenged'):
         return False
     return God.user_can_interact_with(self, user, game=ChallengeGame)
Ejemplo n.º 21
0
def sync_user(player):
    """ Synchronise user points with database
    """
    coin = Coin.get('points')
    points = real_points(player) 
    if player.points != points and not player.magic.has_modifier('top-disguise'):
        logging.debug('%s had %d instead of %d points' % (player, player.points, points))
        player.points = points
        player.level_no = God.get_level_for_points(player.points)
        player.save()
Ejemplo n.º 22
0
 def can_challenge(self, user):
     """ Check if the target user is available.
     """
     user = user.get_extension(ChallengeUser)
     if self.user == user.user:
         # Cannot challenge myself
         return False
     if user.has_modifier('challenge-cannot-be-challenged'):
         return False
     return God.user_can_interact_with(self, user, game=ChallengeGame)
Ejemplo n.º 23
0
Archivo: sm.py Proyecto: LucianU/wouso
def sync_user(player):
    """ Synchronise user points with database
    """
    coin = Coin.get('points')
    result = History.objects.filter(user=player.user,coin=coin).aggregate(total=models.Sum('amount'))
    points = result['total'] if result['total'] is not None else 0
    if player.points != points:
        logging.debug('%s had %d instead of %d points' % (player, player.points, points))
        player.points = points
        player.level_no = God.get_level_for_points(player.points)
        player.save()
Ejemplo n.º 24
0
Archivo: sm.py Proyecto: andreip/wouso
def sync_user(player):
    """ Synchronise user points with database
    """
    coin = Coin.get("points")
    result = History.objects.filter(user=player.user, coin=coin).aggregate(total=models.Sum("amount"))
    points = result["total"] if result["total"] is not None else 0
    if player.points != points and not player.magic.has_modifier("top-disguise"):
        logging.debug("%s had %d instead of %d points" % (player, player.points, points))
        player.points = points
        player.level_no = God.get_level_for_points(player.points)
        player.save()
Ejemplo n.º 25
0
 def can_challenge(self, user):
     """ Check if the target user is available.
     """
     user = user.get_extension(ChallengeUser)
     if self.user == user.user:
         # Cannot challenge myself
         logging.info("User cannot challenge because it is the same user.")
         return False
     if user.magic.has_modifier('challenge-cannot-be-challenged'):
         logging.info("User cannot challenge due to magic modifier.")
         return False
     return God.user_can_interact_with(self, user, game=ChallengeGame)
Ejemplo n.º 26
0
def sync_user(player):
    """ Synchronise user points with database
    """
    coin = Coin.get('points')
    result = History.objects.filter(
        user=player.user, coin=coin).aggregate(total=models.Sum('amount'))
    points = result['total'] if result['total'] is not None else 0
    if player.points != points:
        logging.debug('%s had %d instead of %d points' %
                      (player, player.points, points))
        player.points = points
        player.level_no = God.get_level_for_points(player.points)
        player.save()
Ejemplo n.º 27
0
Archivo: sm.py Proyecto: LucianU/wouso
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            signal_msg = ugettext_noop("downgraded to level {level}")
        else:
            signal_msg = ugettext_noop("upgraded to level {level}")

        signals.addActivity.send(sender=None, user_from=player,
                             user_to=player, message=signal_msg,
                             arguments=dict(level=level),
                             game=game)
        player.level_no = level
        player.save()
Ejemplo n.º 28
0
    def give_modifier(self, modifier, amount):
        """ Add given amount to existing, or creat new artifact amount
        for the current user.
        """
        if amount <= 0:
            return

        paamount = self.has_modifier(modifier)
        if not paamount:
            artifact = God.get_artifact_for_modifier(modifier, self)
            paamount = PlayerArtifactAmount.objects.create(player=self, artifact=artifact, amount=amount)
        else:
            paamount.amount += amount
            paamount.save()
        return paamount
Ejemplo n.º 29
0
    def basic_cast(self, player_dest, spell, due):
        # Pre-cast God actions: immunity and curse ar done by this
        # check

        can_cast, error = God.can_cast(spell=spell, source=self.player, destination=player_dest)
        if not can_cast:
            return error
        try:
            psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
        except IntegrityError:
            if not spell.mass:
                return 'Cannot cast the same spell more than once'
            #extend the affected time by spell
            psdue = PlayerSpellDue.objects.get(player=player_dest, spell=spell)
            if psdue.due < due:
                psdue.delete()
                psdue = PlayerSpellDue.objects.create(player=player_dest, source=self.player, spell=spell, due=due)
            else:
                return None

        # Post-cast God action (there are specific modifiers, such as clean-spells
        # that are implemented in God
        God.post_cast(psdue)
        return None
Ejemplo n.º 30
0
    def give_modifier(self, modifier, amount):
        """ Add given amount to existing, or creat new artifact amount
        for the current user.
        """
        if amount <= 0:
            return

        paamount = self.has_modifier(modifier)
        if not paamount:
            artifact = God.get_artifact_for_modifier(modifier, self)
            paamount = PlayerArtifactAmount.objects.create(player=self, artifact=artifact, amount=amount)
        else:
            paamount.amount += amount
            paamount.save()
        return paamount
Ejemplo n.º 31
0
def artifact_home(request, group=None):
    if group is None:
        group = 'Default'

    group = get_object_or_404(ArtifactGroup, name=group)
    artifacts = group.artifact_set.all()
    modifiers = God.get_all_modifiers()

    return render_to_response('cpanel/artifact_home.html',
                              {'groups': ArtifactGroup.objects.all(),
                               'artifacts': artifacts,
                               'module': 'artifacts',
                               'group': group,
                               'modifiers': modifiers,
                               },
                              context_instance=RequestContext(request))
Ejemplo n.º 32
0
def artifact_home(request, group=None):
    if group is None:
        group = 'Default'

    group = get_object_or_404(ArtifactGroup, name=group)
    artifacts = group.artifact_set.all()
    modifiers = God.get_all_modifiers()

    return render_to_response('cpanel/artifact_home.html', {
        'groups': ArtifactGroup.objects.all(),
        'artifacts': artifacts,
        'module': 'artifacts',
        'group': group,
        'modifiers': modifiers,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 33
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            signal_msg = ugettext_noop("downgraded to level {level}")
        else:
            signal_msg = ugettext_noop("upgraded to level {level}")

        signals.addActivity.send(sender=None,
                                 user_from=player,
                                 user_to=player,
                                 message=signal_msg,
                                 arguments=dict(level=level),
                                 game=game)
        player.level_no = level
        player.save()
Ejemplo n.º 34
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            amount = calculate('level-gold',
                               level=player.level_no).get('gold', 0)
            action_msg = 'gold-lost'
            signal_msg = ugettext_noop(
                "downgraded to level {level} and lost {amount} gold")
            rollback(player, None, 'level-gold', external_id=player.level_no)
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level,
                                                    amount=amount),
                                     game=game,
                                     action=action_msg)
        else:

            amount = calculate('level-gold', level=level)
            # Check if the user has previously reached this level
            if level > player.max_level:
                # Update the maximum reached level
                player.max_level = level
                # Offer the corresponding amount of gold
                score(player,
                      None,
                      'level-gold',
                      external_id=level,
                      level=level)
            else:
                # The user should not receive additional gold
                amount['gold'] = 0
            signal_msg = ugettext_noop(
                "upgraded to level {level} and received {amount} gold")
            action_msg = 'gold-won'
            signals.addActivity.send(sender=None,
                                     user_from=player,
                                     user_to=player,
                                     message=signal_msg,
                                     arguments=dict(level=level,
                                                    amount=amount['gold']),
                                     game=None,
                                     action=action_msg)
        player.level_no = level
        player.save()
Ejemplo n.º 35
0
def setup():
    """ Prepare database for Scoring """
    for cc in CORE_POINTS:
        if not Coin.get(cc):
            Coin.add(cc, name=cc)
    # special case, gold is integer
    gold = Coin.get('gold')
    gold.integer = True
    gold.save()

    # iterate through games and register formulas
    for game in get_games():
        for formula in game.get_formulas():
            if not Formula.get(formula.id):
                Formula.add(formula)
    # add wouso formulas
    for formula in God.get_system_formulas():
        if not Formula.get(formula.id):
            Formula.add(formula)
Ejemplo n.º 36
0
Archivo: sm.py Proyecto: LucianU/wouso
def setup():
    """ Prepare database for Scoring """
    for cc in CORE_POINTS:
        if not Coin.get(cc):
            Coin.add(cc, name=cc)
    # special case, gold is integer
    gold = Coin.get('gold')
    gold.integer = True
    gold.save()

    # iterate through games and register formulas
    for game in get_games():
        for formula in game.get_formulas():
            if not Formula.get(formula.id):
                Formula.add(formula)
    # add wouso formulas
    for formula in God.get_system_formulas():
        if not Formula.get(formula.id):
            Formula.add(formula)
Ejemplo n.º 37
0
    def read(self, request, player_id=None):
        if player_id:
            try:
                player = Player.objects.get(pk=player_id)
            except Player.DoesNotExist:
                return rc.NOT_FOUND
        else:
            try:
                player = request.user.get_profile()
            except Player.DoesNotExist:
                return rc.NOT_FOUND

        level = {
            'name': player.level.name,
            'title': player.level.title,
            'image': player.level.image,
            'id': player.level.id,
            } if player.level else {}

        group = player.group
        gold = player.coins['gold'] if 'gold' in player.coins.keys() else 0
        topuser = player.get_extension(TopUser)

        return {'username': player.user.username,
                'nickname': player.nickname,
                'first_name': player.user.first_name,
                'last_name': player.user.last_name,
                'email': player.user.email,
                'avatar': player_avatar(player),
                'points': player.points,
                'gold': gold,
                'race': player.race_name,
                'race_slug': player.race.name.lower() if player.race and player.race.name else '',
                'race_id': player.race.id if player.race else 0,
                'group': group,
                'level_no': player.level_no,
                'level': level,
                'level_progress': God.get_level_progress(player),
                'rank': topuser.position,
                }
Ejemplo n.º 38
0
def update_points(player, game):
    level = God.get_level_for_points(player.points)
    if level != player.level_no:
        if level < player.level_no:
            amount = calculate('level-gold', level=player.level_no).get('gold', 0)
            action_msg = 'gold-lost'
            signal_msg = ugettext_noop("downgraded to level {level} and lost {amount} gold")
            rollback(player, None, 'level-gold', external_id=player.level_no)
            signals.addActivity.send(sender=None, user_from=player,
                                user_to=player, message=signal_msg,
                                arguments=dict(level=level, amount=amount),
                                game=game, action=action_msg)
        else:

            amount = calculate('level-gold', level=level)
            signal_msg = ugettext_noop("upgraded to level {level} and received {amount} gold")
            action_msg = 'gold-won'
            score(player, None, 'level-gold', external_id=level, level=level)
            signals.addActivity.send(sender=None, user_from=player,
                    user_to=player, message=signal_msg,
                                arguments=dict(level=level, amount=amount['gold']),
                                game=None, action=action_msg)
        player.level_no = level
        player.save()
Ejemplo n.º 39
0
    def activity_handler(cls, sender, **kwargs):
        action = kwargs.get('action', None)
        player = kwargs.get('user_from', None)

        if player:
            player = player.get_extension(Player)

        if not action:
            return

        if 'qotd' in action:
            # Check 10 qotd in a row
            if consecutive_qotd_correct(player) >= 10:
                if not player.magic.has_modifier('ach-qotd-10'):
                    cls.earn_achievement(player, 'ach-qotd-10')

        if 'chall' in action:
            # Check if number of challenge games is >= 100
            games_played = challenge_count(player)
            if games_played >= 100:
                if not player.magic.has_modifier('ach-chall-100'):
                    cls.earn_achievement(player, 'ach-chall-100')

            # Check if the number of refused challenges in the past week is 0
            # also check for minimum number of challenges played = 5
            if not player.magic.has_modifier('ach-this-is-sparta'):
                if refused_challenges(player) == 0 and \
                                challenge_count(player, days=7) >= 5 and \
                                first_seen(player) >= 7:
                    cls.earn_achievement(player, 'ach-this-is-sparta')

            # Check if player played 10 challenges in a day"
            if not player.magic.has_modifier('ach-chall-10-a-day'):
                if challenges_played_today(player) >= 10:
                    cls.earn_achievement(player, 'ach-chall-10-a-day')

        if action == 'chall-won':
            # Check for flawless victory
            if get_chall_score(kwargs.get("arguments")) == 500:
                if not player.magic.has_modifier('ach-flawless-victory'):
                    cls.earn_achievement(player, 'ach-flawless-victory')
            # Check 10 won challenge games in a row
            if not player.magic.has_modifier('ach-chall-won-10'):
                if consecutive_chall_won(player) >= 10:
                    cls.earn_achievement(player, 'ach-chall-won-10')

            # Check if player defeated 2 levels or more bigger opponent
            if not player.magic.has_modifier('ach-chall-def-big'):
                if (kwargs.get('user_to').level_no - player.level_no) >= 2:
                    Activity.objects.create(timestamp=datetime.now(),
                                            user_from=player,
                                            user_to=player,
                                            action='defeat-better-player')
                    victories = Activity.objects.filter(
                        user_to=player, action='defeat-better-player')
                    if victories.count() >= 5:
                        cls.earn_achievement(player, 'ach-chall-def-big')
                        victories.delete()

            # Check if the player finished the challenge in less than 1 minute
            if not player.magic.has_modifier('ach-win-fast'):
                seconds_no = get_challenge_time(kwargs.get("arguments"))
                if seconds_no > 0 and seconds_no <= 60:
                    cls.earn_achievement(player, 'ach-win-fast')

        if action == 'message':
            # Check the number of unique users who send pm to player in the last m minutes
            if unique_users_pm(kwargs.get('user_to'), 15) >= 5:
                if not kwargs.get('user_to').magic.has_modifier(
                        'ach-popularity'):
                    cls.earn_achievement(kwargs.get('user_to'),
                                         'ach-popularity')

        if action in ("login", "seen"):
            # Check login between 2-4 am
            if login_between_count(player, 3, 5) > 2:
                if not player.magic.has_modifier('ach-night-owl'):
                    cls.earn_achievement(player, 'ach-night-owl')
            if login_between_count(player, 6, 8) > 2:
                if not player.magic.has_modifier('ach-early-bird'):
                    cls.earn_achievement(player, 'ach-early-bird')

            if not player.magic.has_modifier('ach-god-mode-on'):
                if check_for_god_mode(player, 5, 5):
                    cls.earn_achievement(player, 'ach-god-mode-on')
            # Check previous 10 seens
            if consecutive_days_seen(player, datetime.now()) >= 14:
                if not player.magic.has_modifier('ach-login-10'):
                    cls.earn_achievement(player, 'ach-login-10')

        if action == 'cast':
            # Check if player is affected by 5 or more spells
            if not player.magic.has_modifier('ach-spell-5'):
                if spell_count(player) >= 5:
                    cls.earn_achievement(player, 'ach-spell-5')

            # Check if player used all non-mass spells
            if not player.magic.has_modifier('ach-use-all-spells'):
                if used_all_spells(player, False):
                    cls.earn_achievement(player, 'ach-use-all-spells')

            # Check if player used all mass spells
            if not player.magic.has_modifier('ach-use-all-mass'):
                if used_all_spells(player, True):
                    cls.earn_achievement(player, 'ach-use-all-mass')

        if 'buy' in action:
            # Check if player spent 500 gold on spells
            if not player.magic.has_modifier('ach-spent-gold'):
                if spent_gold(player) >= 500:
                    cls.earn_achievement(player, 'ach-spent-gold')

        if action == 'gold-won':
            # Check if player reached level 5
            if not player.magic.has_modifier('ach-level-5'):
                if player.level_no >= 5:
                    cls.earn_achievement(player, 'ach-level-5')
            # Check if player reached level 10
            if not player.magic.has_modifier('ach-level-10'):
                if player.level_no >= 10:
                    cls.earn_achievement(player, 'ach-level-10')

        if 'gold' in action:
            # Check if player has 300 gold
            if not player.magic.has_modifier('ach-gold-300'):
                if gold_amount(player) >= 300:
                    cls.earn_achievement(player, 'ach-gold-300')

        if 'login' in action:
            # Check if player got a head start login
            if not player.magic.has_modifier('ach-head-start'):
                # (player, start_hour, start_day, start_month, hour_offset)
                # server start date: hour, day, month
                # hour_offset = offset from start date when player will be rewarded
                head_start_date = God.get_head_start_date()
                if login_at_start(player,
                                  start_day=head_start_date.day,
                                  start_month=head_start_date.month):
                    cls.earn_achievement(player, 'ach-head-start')
Ejemplo n.º 40
0
    def activity_handler(cls, sender, **kwargs):
        action = kwargs.get('action', None)
        player = kwargs.get('user_from', None)

        if player:
            player = player.get_extension(Player)

        if not action:
            return

        if 'qotd' in action:
            # Check 10 qotd in a row
            if consecutive_qotd_correct(player) >= 10:
                if not player.magic.has_modifier('ach-qotd-10'):
                    cls.earn_achievement(player, 'ach-qotd-10')

        if 'chall' in action:
            # Check if number of challenge games is >= 100
            games_played = challenge_count(player)
            if games_played >= 100:
                if not player.magic.has_modifier('ach-chall-100'):
                    cls.earn_achievement(player, 'ach-chall-100')

            # Check if the number of refused challenges in the past week is 0
            # also check for minimum number of challenges played = 5
            if not player.magic.has_modifier('ach-this-is-sparta'):
                if refused_challenges(player) == 0 and \
                                challenge_count(player, days=7) >= 5 and \
                                first_seen(player) >= 7:
                    cls.earn_achievement(player, 'ach-this-is-sparta')

            # Check if player played 10 challenges in a day"
            if not player.magic.has_modifier('ach-chall-10-a-day'):
                if challenges_played_today(player) >= 10:
                    cls.earn_achievement(player, 'ach-chall-10-a-day')

        if action == 'chall-won':
            # Check for flawless victory
            if get_chall_score(kwargs.get("arguments")) == 500:
                if not player.magic.has_modifier('ach-flawless-victory'):
                    cls.earn_achievement(player, 'ach-flawless-victory')
            # Check 10 won challenge games in a row
            if not player.magic.has_modifier('ach-chall-won-10'):
                if consecutive_chall_won(player) >= 10:
                    cls.earn_achievement(player, 'ach-chall-won-10')

            # Check if player defeated 2 levels or more bigger opponent
            if not player.magic.has_modifier('ach-chall-def-big'):
                if (kwargs.get('user_to').level_no - player.level_no) >= 2:
                    Activity.objects.create(timestamp=datetime.now(),
                                            user_from=player, user_to=player,
                                            action='defeat-better-player')
                    victories = Activity.objects.filter(user_to=player,
                                                        action='defeat-better-player')
                    if victories.count() >= 5:
                        cls.earn_achievement(player, 'ach-chall-def-big')
                        victories.delete()

            # Check if the player finished the challenge in less than 1 minute
            if not player.magic.has_modifier('ach-win-fast'):
                seconds_no = get_challenge_time(kwargs.get("arguments"))
                if seconds_no > 0 and seconds_no <= 60:
                    cls.earn_achievement(player, 'ach-win-fast')

        if action == 'message':
            # Check the number of unique users who send pm to player in the last m minutes
            if unique_users_pm(kwargs.get('user_to'), 15) >= 5:
                if not kwargs.get('user_to').magic.has_modifier('ach-popularity'):
                    cls.earn_achievement(kwargs.get('user_to'), 'ach-popularity')

        if action in ("login", "seen"):
            # Check login between 2-4 am
            if login_between_count(player, 3, 5) > 2:
                if not player.magic.has_modifier('ach-night-owl'):
                    cls.earn_achievement(player, 'ach-night-owl')
            if login_between_count(player, 6, 8) > 2:
                if not player.magic.has_modifier('ach-early-bird'):
                    cls.earn_achievement(player, 'ach-early-bird')

            if not player.magic.has_modifier('ach-god-mode-on'):
                if check_for_god_mode(player, 5, 5):
                    cls.earn_achievement(player, 'ach-god-mode-on')
            # Check previous 10 seens
            if consecutive_days_seen(player, datetime.now()) >= 14:
                if not player.magic.has_modifier('ach-login-10'):
                    cls.earn_achievement(player, 'ach-login-10')

        if action == 'cast':
            # Check if player is affected by 5 or more spells
            if not player.magic.has_modifier('ach-spell-5'):
                if spell_count(player) >= 5:
                    cls.earn_achievement(player, 'ach-spell-5')

            # Check if player used all non-mass spells
            if not player.magic.has_modifier('ach-use-all-spells'):
                if used_all_spells(player, False):
                    cls.earn_achievement(player, 'ach-use-all-spells')

            # Check if player used all mass spells
            if not player.magic.has_modifier('ach-use-all-mass'):
                if used_all_spells(player, True):
                    cls.earn_achievement(player, 'ach-use-all-mass')

        if 'buy' in action:
            # Check if player spent 500 gold on spells
            if not player.magic.has_modifier('ach-spent-gold'):
                if spent_gold(player) >= 500:
                    cls.earn_achievement(player, 'ach-spent-gold')

        if action == 'gold-won':
            # Check if player reached level 5
            if not player.magic.has_modifier('ach-level-5'):
                if player.level_no >= 5:
                    cls.earn_achievement(player, 'ach-level-5')
            # Check if player reached level 10
            if not player.magic.has_modifier('ach-level-10'):
                if player.level_no >= 10:
                    cls.earn_achievement(player, 'ach-level-10')

        if 'gold' in action:
            # Check if player has 300 gold
            if not player.magic.has_modifier('ach-gold-300'):
                if gold_amount(player) >= 300:
                    cls.earn_achievement(player, 'ach-gold-300')

        if 'login' in action:
            # Check if player got a head start login
            if not player.magic.has_modifier('ach-head-start'):
                # (player, start_hour, start_day, start_month, hour_offset)
                # server start date: hour, day, month
                # hour_offset = offset from start date when player will be rewarded
                head_start_date = God.get_head_start_date()
                if login_at_start(player, start_day=head_start_date.day, start_month=head_start_date.month):
                    cls.earn_achievement(player, 'ach-head-start')
Ejemplo n.º 41
0
 def is_eligible(self):
     return God.user_is_eligible(self, ChallengeGame)
Ejemplo n.º 42
0
 def level(self):
     """ Return an artifact object for the current level_no.
     Ask God about the right artifact object, given the player instance.
     In the future, God may check players race and give specific artifacts.
     """
     return God.get_user_level(self.level_no, player=self)
Ejemplo n.º 43
0
 def level_progress(self):
     """ Return a dictionary with: points_gained, points_left, next_level """
     return God.get_level_progress(self)
Ejemplo n.º 44
0
 def is_eligible(self):
     return God.user_is_eligible(self, ChallengeGame)
Ejemplo n.º 45
0
 def level_progress(self):
     """ Return a dictionary with: points_gained, points_left, next_level """
     return God.get_level_progress(self)
Ejemplo n.º 46
0
 def level(self):
     """ Return an artifact object for the current level_no.
     Ask God about the right artifact object, given the player instance.
     In the future, God may check players race and give specific artifacts.
     """
     return God.get_user_level(self.level_no, player=self)