示例#1
0
文件: views.py 项目: cvicentiu/wouso
def magic_cast(request, destination=None, spell=None):
    player = request.user.get_profile()
    destination = get_object_or_404(Player, pk=destination)

    error = ''

    if Bazaar.disabled():
        error = _("Magic is disabled")
    elif request.method == 'POST':
        spell = get_object_or_404(Spell, pk=request.POST.get('spell', 0))
        try:
            days = int(request.POST.get('days', 0))
        except ValueError:
            pass
        else:
            if (days > spell.due_days) or ((spell.due_days > 0) and (days < 1)):
                error = _('Invalid number of days')
            else:
                due = datetime.now() + timedelta(days=days)
                if not spell.mass:
                    error = destination.magic.cast_spell(spell=spell, source=player, due=due)
                else:
                    players = destination.get_neighbours_from_top(2, player.race, spell.type)
                    players = player.magic.filter_players_by_spell(players, spell)
                    error = player.magic.mass_cast(spell=spell, destination=players, due=due)

                if not error:
                    return HttpResponseRedirect(reverse('wouso.interface.profile.views.user_profile', args=(destination.id,)))

                error = _('Cast failed:') + ' ' + error

    return render_to_response('profile/cast.html',
                              {'destination': destination, 'error': error},
                              context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: cvicentiu/wouso
def bazaar_buy(request, spell):
    spell = get_object_or_404(Spell, pk=spell)

    player = request.user.get_profile()
    error, message = '',''

    if Bazaar.disabled():
        error = _("Magic is disabled")
    elif spell.price > player.coins.get('gold', 0):
        error = _("Insufficient gold amount")
    elif spell.available == False:
        error = _("Spell is not available")
    elif spell.level_required > player.level_no:
        error = _("Level {level} is required to buy this spell").format(level=spell.level_required)
    else:
        player.magic.add_spell(spell)
        scoring.score(player, None, 'buy-spell', external_id=spell.id,
                      price=spell.price)
        signal_msg = ugettext_noop('bought a spell')
        action_msg = 'spell-buy'
        signals.addActivity.send(sender=None, user_from=player,
                        user_to=player,
                        message=signal_msg,
                        game=None,
                        action=action_msg,
                        public=False)
        SpellHistory.bought(player, spell)
        message = _("Successfully aquired")

    return bazaar(request, message=message, error=error)
示例#3
0
def bazaar_buy(request, spell):
    spell = get_object_or_404(Spell, pk=spell)

    player = request.user.get_profile()
    error, message = '',''

    if Bazaar.disabled():
        error = _("Magic is disabled")
    elif spell.price > player.coins.get('gold', 0):
        error = _("Insufficient gold amount")
    elif spell.available == False:
        error = _("Spell is not available")
    elif spell.level_required > player.level_no:
        error = _("Level {level} is required to buy this spell").format(level=spell.level_required)
    else:
        player.magic.add_spell(spell)
        scoring.score(player, None, 'buy-spell', external_id=spell.id,
                      price=spell.price)
        signal_msg = ugettext_noop('bought a spell')
        action_msg = 'spell-buy'
        signals.addActivity.send(sender=None, user_from=player,
                        user_to=player,
                        message=signal_msg,
                        game=None,
                        action=action_msg,
                        public=False)
        SpellHistory.bought(player, spell)
        message = _("Successfully acquired")

    if error:
        messages.error(request, error)
    if message:
        messages.success(request, message)

    return redirect('bazaar_home')
示例#4
0
def header_footer(request):
    """ Generate header and footer bar contents.
    """
    try:
        reverse('homepage')
    except NoReverseMatch:
        return {}
    #TODO ordering, using config

    header = []
    try:
        for game in get_games():
            h = game.get_header_link(request)
            if h:
                header.append((h, game.get_instance().name))
    except Exception as e:
        logging.exception(e)

    # add also messages and magic link
    try:
        h = Message.get_header_link(request)
        if h:
            header.append((h, 'Message'))

        h = Bazaar.get_header_link(request)
        if h:
            header.append((h, 'Magic'))

        h = Chat.get_header_link(request)
        if h:
            header.append((h, 'Chat'))
    except Exception as e:
        logging.exception(e)

    footer = []
    try:
        for game in get_games():
            f = game.get_footer_link(request)
            if f:
                footer.append(f)
    except: pass

    # also add static pages
    footer.extend(get_static_pages())

    for a in get_apps():
        f = a.get_footer_link(request)
        if f:
            footer.append(a.get_footer_link(request))

    # format header
    hids = lambda p: '<span id="head-%s"><a href="%s">%s</a>%s</span>' % (p[1].lower(), \
                        p[0]['link'], p[0]['text'], \
                        '<sup class="unread-count">%d</sup>' % p[0]['count'] if p[0].get('count', False) else '')

    header_html = " ".join(map(hids, header))
    footer = " | ".join(footer)

    return {'header': header_html, 'heads': header, 'footer': footer}
示例#5
0
def magic_cast(request, destination=None, spell=None):
    player = request.user.get_profile()
    destination = get_object_or_404(Player, pk=destination)

    error = ''

    if Bazaar.disabled(
    ) or BoolSetting.get('setting-magic').get_value() is False:
        error = _("Magic is disabled")
    elif request.method == 'POST':
        spell = get_object_or_404(Spell, pk=request.POST.get('spell', 0))
        try:
            days = int(request.POST.get('days', 0))
        except ValueError:
            pass
        else:
            if (days > spell.due_days) or ((spell.due_days > 0) and
                                           (days < 1)):
                error = _('Invalid number of days')
            else:
                due = datetime.now() + timedelta(days=days)
                if not spell.mass:
                    error = destination.magic.cast_spell(spell=spell,
                                                         source=player,
                                                         due=due)
                else:
                    players = destination.get_neighbours_from_top(
                        2, player.race, spell.type)
                    players = player.magic.filter_players_by_spell(
                        players, spell)
                    error = player.magic.mass_cast(spell=spell,
                                                   destination=players,
                                                   due=due)

                if not error:
                    return HttpResponseRedirect(
                        reverse('wouso.interface.profile.views.user_profile',
                                args=(destination.id, )))

                error = _('Cast failed:') + ' ' + error

    if error:
        messages.error(request, error)

    return render_to_response('profile/cast.html',
                              {'destination': destination},
                              context_instance=RequestContext(request))
示例#6
0
def header_footer(request):
    """ Generate header and footer bar contents.
    """
    #TODO ordering, using config

    header = []
    try:
        for game in get_games():
            h = game.get_header_link(request)
            if h:
                header.append((h, game.get_instance().name))
    except Exception as e:
        logging.exception(e)

    # add also messages and magic link
    try:
        h = Message.get_header_link(request)
        if h:
            header.append((h, 'Message'))

        h = Bazaar.get_header_link(request)
        if h:
            header.append((h, 'Magic'))

        h = Chat.get_header_link(request)
        if h:
            header.append((h, 'Chat'))

    except Exception as e:
        logging.exception(e)

    footer = []
    try:
        for game in get_games():
            f = game.get_footer_link(request)
            if f:
                footer.append(f)
    except:
        pass

    # also add stats link
    try:
        f = stats_link(request)
        if f:
            footer.append(f)
    except:
        pass

    # also add static pages
    for sp in get_static_pages():
        footer.append(sp.html_link())

    # qporposal
    if not Qproposal.disabled():
        footer.append(Qproposal.get_footer_link(request))

    # format header
    hids = lambda p: '<span id="head-%s"><a href="%s">%s</a>%s</span>' % (p[1].lower(), \
                        p[0]['link'], p[0]['text'], \
                        '<sup class="unread-count">%d</sup>' % p[0]['count'] if p[0].get('count', False) else '')

    header_html = " ".join(map(hids, header))
    footer = " | ".join(footer)

    return {'header': header_html, 'heads': header, 'footer': footer}