示例#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 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))