예제 #1
0
def watch(request, hex_id):
    """
    Put a "watcher" on a node that looks for what happens nearby.
    """
    char = gtc(request)
    watch_node = Node.by_hex(hex_id)

    if CharNodeWatch.objects.filter(char=char).count() >= char.market_stat():
        messages.error(request, _("All your agents are placed; remove one first."))
        return node(request, hex_id)

    if not char.has_node(watch_node):
        messages.error(request, _("You haven't unlocked that node."))
        return node(request, hex_id)

    if char.watching_node(watch_node):
        messages.warning(request, _("You're already watching that node."))
        return node(request, hex_id)

    char.watch_node_final(watch_node)

    messages.success(request,
        _("You put a watcher near %(node_name)s." %
        {"node_name": watch_node.name}))

    char.revert_disguise(request)

    return redirect(node, hex_id)
예제 #2
0
def buy(request, node_hex, item_id, template="node/buy.html"):
    """
    Buy an item.
    """
    node = Node.by_hex(node_hex)
    char = gtc(request)
    item = get_object_or_404(Item, id=item_id)

    result_str = _n(
        "Congratulations! You bought %(item)s for %(price)d %(currency_singular)s.",
        "Congratulations! You bought %(item)s for %(price)d %(currency_plural)s.",
        item.price)

    result_str = result_str % {"item": item.name,
                               "price": item.price,
                               "currency_singular": CURRENCY_SINGULAR,
                               "currency_plural": CURRENCY_PLURAL}

    event = NodeEvent.objects.create(
         where=node,
         who=char,
         day=GameDay.get_day(),
         who_disguised=char.is_disguised,
         type=EVENT_BUY
     )

    char.revert_disguise(request)

    return render(request, template, {"result_str": result_str, "item": item, "node": node})
예제 #3
0
def node_password(request, from_hex, template="node/secret.html"):
    from_node = Node.by_hex(from_hex)
    password = request.GET.get("password", None)
    if Secret.objects.filter(node=from_node, password__iexact=password.strip()):
        s = Secret.objects.get(node=from_node, password__iexact=password.strip())
    else:
        s = None
    return render(request, template, {'node': from_node, 'secret': s})
예제 #4
0
def unlock(request, from_hex, to_hex):
    """
    Unlock a node.  Does error checking.
    """
    char = gtc(request)
    from_node = Node.by_hex(from_hex)
    to_node = Node.by_hex(to_hex)
    print from_hex, HOME_NODE
    if not (char.has_node(from_node) or int(from_hex) == HOME_NODE):
        messages.error(request,
            _("You didn't have node %s unlocked...?") % from_hex)
        return home(request)

    if char.has_node(to_node):
        messages.warning(request,
            _("You already had node %s unlocked!") % to_hex)
        return redirect(node, to_hex)

    if char.points < 1:
        messages.error(request, _("You don't have any Market points!"))
        return redirect(node, from_hex)

    # Error checking done

    char.points -= 1
    char.save()

    char.unlock_node_final(to_node)
    event = NodeEvent.objects.create(
        where=from_node,
        who=char,
        day=GameDay.get_day(),
        who_disguised=char.is_disguised,
        type=EVENT_UNLOCK_2
    )

    char.revert_disguise(request)
    check_inspiration(request)

    messages.success(request,
        _("%(from_node_name)s introduces you to %(to_node_name)s." %
        {"from_node_name": from_node.name,
         "to_node_name": to_node.name}))

    return redirect(node, to_hex)
예제 #5
0
def unwatch(request, from_hex, hex_id):
    """
    Remove a watcher from a node.
    """
    char = gtc(request)
    watch_node = Node.by_hex(hex_id)

    if not char.watching_node(watch_node):
        messages.error(request, _("You're not watching that node."))
        return node(request, hex_id)

    char.unwatch_node_final(watch_node)

    messages.success(request,
        _("You removed a watcher from %(node_name)s." %
        {"node_name": watch_node.name}))

    return redirect(node, from_hex) if from_hex else redirect(node, HOME_NODE)
예제 #6
0
def node(request, hex_id, template="node/node.html"):
    """
    Main view of a node.
    """
    char = gtc(request)
    hex_node = Node.by_hex(hex_id)
    items = Item.objects.filter(sold_by=hex_node, valid=True)
    bids = {}
    for i in items:
        if i.rarity_class == RARITY_AUCTION:
            if ItemBid.objects.filter(character=char, item=i):
                bids[i] = ItemBid.objects.get(character=char, item=i).amount
    context = {
        'node': hex_node,
        'items': Item.objects.filter(sold_by=hex_node, valid=True),
        'bids': bids,
        'char': gtc(request),
        'game_day': GameDay.get_day(),
    }
    return render(request, template, context)