Exemplo n.º 1
0
def bazaar_buy(request, spell):
    spell = get_object_or_404(Spell, pk=spell)

    player = request.user.get_profile()
    error, message = '',''
    if spell.price > player.coins.get('gold', 0):
        error = _("Insufficient gold amount")
    else:
        player.add_spell(spell)
        scoring.score(player, None, 'buy-spell', external_id=spell.id,
                      price=spell.price)
        SpellHistory.bought(player, spell)
        message = _("Successfully aquired")

    return bazaar(request, message=message, error=error)
    # TODO: use django-flash
    """
Exemplo n.º 2
0
    def post_cast(self, psdue):
        """ Execute action after a spell is cast. This is used to implement specific spells
        such as 'clean any existing spell' cast.

        Returns True if action has been taken, False if not.
        """
        # Always executed, so log
        from wouso.core.user.models import SpellHistory
        SpellHistory.used(psdue.source, psdue.spell, psdue.player)
        # Also trigger anonymous activiy
        from wouso.interface.activity import signals
        if psdue.source == psdue.player:
            signal_msg = 'a facut o vraja asupra sa.'
        else:
            signal_msg = 'a facut o vraja asupra {to}.'
        signals.addActivity.send(sender=None,
                                 user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 game=None)

        if psdue.spell.name == 'dispell':
            for psd in psdue.player.spells:
                psd.delete()
            return True
        if psdue.spell.name == 'cure':
            for psd in psdue.player.spells.filter(spell__type='n'):
                psd.delete()
            # also delete itself
            psdue.delete()
            return True
        if psdue.spell.name == 'steal':
            psdue.player.steal_points(psdue.source, psdue.spell.percents)
            psdue.delete()
            return True
        return False
Exemplo n.º 3
0
Arquivo: god.py Projeto: LucianU/wouso
    def post_cast(self, psdue):
        """ Execute action after a spell is cast. This is used to implement specific spells
        such as 'clean any existing spell' cast.

        Returns True if action has been taken, False if not.
        """
        # Always executed, so log
        from wouso.core.user.models import SpellHistory
        SpellHistory.used(psdue.source, psdue.spell, psdue.player)
        # Also trigger anonymous activiy
        from wouso.interface.activity import signals
        if psdue.source == psdue.player:
            signal_msg = 'a facut o vraja asupra sa.'
        else:
            signal_msg = 'a facut o vraja asupra {to}.'
        signals.addActivity.send(sender=None, user_from=psdue.source,
                                 user_to=psdue.player,
                                 message=signal_msg,
                                 arguments=dict(to=psdue.player),
                                 game=None)

        if psdue.spell.name == 'dispell':
            for psd in psdue.player.spells:
                psd.delete()
            return True
        if psdue.spell.name == 'cure':
            for psd in psdue.player.spells.filter(spell__type='n'):
                psd.delete()
            # also delete itself
            psdue.delete()
            return True
        if psdue.spell.name == 'steal':
            psdue.player.steal_points(psdue.source, psdue.spell.percents)
            psdue.delete()
            return True
        return False
Exemplo n.º 4
0
def main(args):
    try:
        init()
    except:
        print "No wouso/settings.py file. Maybe you can symlink the example file?"
        sys.exit(1)

    from wouso.core.user.models import Player, PlayerGroup
    from wouso.interface.top.models import TopUser, History

    today = date.today()
    print 'Updating users with date: ', today
    for i, u in enumerate(Player.objects.all().order_by('-points')):
        topuser = u.get_extension(TopUser)
        position = i + 1
        hs, new = History.objects.get_or_create(user=topuser,
                                                date=today,
                                                relative_to=None)
        hs.position, hs.points = position, u.points
        hs.save()

    print 'Updating group history: '
    for p in PlayerGroup.objects.all():
        p.points = p.live_points
        p.save()
    # get position on distinct classes
    for cls in PlayerGroup.objects.values_list('gclass').distinct():
        cls = cls[0]
        for i, p in enumerate(
                PlayerGroup.objects.filter(gclass=cls).order_by('-points')):
            position = i + 1
            hs, new = History.objects.get_or_create(group=p,
                                                    date=today,
                                                    relative_to=None)
            hs.position, hs.points = position, p.points
            hs.save()
    print 'Updating user relative to group position: '
    for g in PlayerGroup.objects.all():
        for i, u in enumerate(g.player_set.order_by('-points')):
            topuser = u.get_extension(TopUser)
            position = i + 1
            hs, new = History.objects.get_or_create(user=topuser,
                                                    date=today,
                                                    relative_to=g)
            hs.position, hs.points = position, p.points
            hs.save()
    print 'Updating group relative to parent group position: '
    for g in PlayerGroup.objects.all():
        if g.children:
            for i, c in enumerate(g.children.order_by('-points')):
                position = i + 1
                hs, new = History.objects.get_or_create(group=c,
                                                        date=today,
                                                        relative_to=g)
                hs.position, hs.points = position, p.points
                hs.save()

    from wouso.games.challenge.models import Challenge

    challenges = Challenge.get_expired(today)
    print 'Updating expired challenges ', len(challenges)
    for c in challenges:
        if c.is_launched():
            # launched before yesterday, automatically refuse
            c.refuse(auto=True)
        else:
            # launched and accepted before yesterday, but not played by both
            c.set_expired()

    from wouso.core.user.models import PlayerSpellDue, SpellHistory
    spells = PlayerSpellDue.get_expired(today)
    print 'Updating expired spells (%d)' % spells.count()
    for s in spells:
        SpellHistory.expired(s.player, s.spell)
        s.delete()

    print 'Done.'
Exemplo n.º 5
0
def main(args):
    try:
        init()
    except:
        print "No wouso/settings.py file. Maybe you can symlink the example file?"
        sys.exit(1)

    from wouso.core.user.models import Player, PlayerGroup
    from wouso.interface.top.models import TopUser, History

    today = date.today()
    print 'Updating users with date: ', today
    for i,u in enumerate(Player.objects.all().order_by('-points')):
        topuser = u.get_extension(TopUser)
        position = i + 1
        hs, new = History.objects.get_or_create(user=topuser, date=today, relative_to=None)
        hs.position, hs.points = position, u.points
        hs.save()

    print 'Updating group history: '
    for p in PlayerGroup.objects.all():
        p.points = p.live_points
        p.save()
    # get position on distinct classes
    for cls in PlayerGroup.objects.values_list('gclass').distinct():
        cls = cls[0]
        for i,p in enumerate(PlayerGroup.objects.filter(gclass=cls).order_by('-points')):
            position = i + 1
            hs, new = History.objects.get_or_create(group=p, date=today, relative_to=None)
            hs.position, hs.points = position, p.points
            hs.save()
    print 'Updating user relative to group position: '
    for g in PlayerGroup.objects.all():
        for i,u in enumerate(g.player_set.order_by('-points')):
            topuser = u.get_extension(TopUser)
            position = i + 1
            hs, new = History.objects.get_or_create(user=topuser, date=today, relative_to=g)
            hs.position, hs.points = position, p.points
            hs.save()
    print 'Updating group relative to parent group position: '
    for g in PlayerGroup.objects.all():
        if g.children:
            for i,c in enumerate(g.children.order_by('-points')):
                position = i + 1
                hs, new = History.objects.get_or_create(group=c, date=today, relative_to=g)
                hs.position, hs.points = position, p.points
                hs.save()

    from wouso.games.challenge.models import Challenge
    
    challenges = Challenge.get_expired(today)
    print 'Updating expired challenges ', len(challenges)
    for c in challenges:
        if c.is_launched():
            # launched before yesterday, automatically refuse
            c.refuse(auto=True)
        else:
            # launched and accepted before yesterday, but not played by both
            c.set_expired()

    from wouso.core.user.models import PlayerSpellDue, SpellHistory
    spells = PlayerSpellDue.get_expired(today)
    print 'Updating expired spells (%d)' % spells.count()
    for s in spells:
        SpellHistory.expired(s.player, s.spell)
        s.delete()

    print 'Done.'