def consortium_context(request): """ Get important Consortium variables into the request :param request: request object :return: none """ from messaging.models import Mailbox mboxes = [] try: char = Character.objects.get(user=request.user) mboxes = Mailbox.objects.filter(Q(character=char) | Q(line__lineorder__order=1, line__lineorder__character=char)) except Character.DoesNotExist: char = None except AttributeError: char = None except TypeError: char = None game_day = GameDay.get_day() has_lines = LineOrder.objects.filter(character=char).exists() has_wargame = Line.objects.filter(lineorder__character=char).exclude(faction=None).exists() if request.user.is_superuser: mboxes = Mailbox.objects.filter(name__contains='GM') unread = sum(map(lambda x: len(x.unread_mail()), mboxes)) return {'char': char, 'game_day': game_day, 'has_lines': has_lines, 'has_wargame': has_wargame, 'gm': request.user.is_superuser, 'unread': unread, 'mboxes': mboxes}
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})
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)
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)
def events(request, template="node/events.html"): """ View events that you saw. """ char = gtc(request) days = range(GameDay.get_day() - 1) events = [] for day in days: day_events = [] for watch in CharNodeWatch.objects.filter(char=char, day=day): watch_events = NodeEvent.objects.filter( where=watch.node, day=day ) day_events.append(watch_events) events.append(day_events) return render(request, template, {"events": events})
def consortium_context(request): """ Get important Consortium variables into the request :param request: request object :return: none """ from messaging.models import Mailbox mboxes = [] try: char = Character.objects.get(user=request.user) mboxes = Mailbox.objects.filter( Q(character=char) | Q(line__lineorder__order=1, line__lineorder__character=char)) except Character.DoesNotExist: char = None except AttributeError: char = None except TypeError: char = None game_day = GameDay.get_day() has_lines = LineOrder.objects.filter(character=char).exists() has_wargame = Line.objects.filter(lineorder__character=char).exclude( faction=None).exists() if request.user.is_superuser: mboxes = Mailbox.objects.filter(name__contains='GM') unread = sum(map(lambda x: len(x.unread_mail()), mboxes)) return { 'char': char, 'game_day': game_day, 'has_lines': has_lines, 'has_wargame': has_wargame, 'gm': request.user.is_superuser, 'unread': unread, 'mboxes': mboxes }
def market_tick(): # if now().time().hour < 5 or now().time().hour > 6: return "Wrongly fired" msg = GameDay.tick() send_mail("[Consortium] Tick!", "Tick successful at %s" % datetime.now(), '*****@*****.**', ['*****@*****.**'], fail_silently=True)