예제 #1
0
def current_player_pod(context):

	return {
		'ic': context['player'].get_influence(turn=context['turn']).level,
		'money': get_current_money(context['player'], context['turn']),
		'display_turn': context['turn'],
	}
예제 #2
0
def player(request, player, game, player_id, turn):
	"""
	Player data
	"""

	# Set the game_id in session to always display all tabs
	request.session['gameid'] = game.pk

	player_profile = Player.objects.get(pk=player_id, game_id=game.pk)
	corporations = Corporation.objects.filter(game=player.game, share__player=player_profile).annotate(qty_share=Count('share')).order_by('-qty_share')

	rp, _ = parse_markdown(player_profile.rp)
	rp = mark_safe(rp)

	events = Log.objects.for_player(player=player_profile, asking_player=player, turn=turn)

	if player == player_profile:
		money = unicode(get_current_money(player_profile, turn)) + u" k"
		help_text_money = u"Argent disponible"
	else:
		# The money is supposed to be a personal information.
		# If you have used a information  operation to get the money next turn on a player you are supposed to see it
		# But only the money at start of the turn, not the money left on player right now
		help_text_money = u"Argent disponible pour le tour"
		# We have to find a log that is linked to both players
		concernedPlayer = ConcernedPlayer.objects.filter(log__event_type=game.MONEY_NEXT_TURN, log__game=game, log__turn=turn - 1).order_by('log')
		is_target = False
		is_spy = False
		last_log = None
		for m2m in concernedPlayer:
			if last_log != m2m.log:
				is_target = False
				is_spy = False
				last_log = m2m.log
			if m2m.player == player:
				is_spy = True
			if m2m.player == player_profile and m2m.personal:
				is_target = True
			if is_target and is_spy:
				break

		if is_target and is_spy:
			data = Log.objects.filter(event_type=game.MONEY_NEXT_TURN, game=game, turn=turn - 1, concernedplayer__player=player_profile, concernedplayer__personal=True)[0].data
			context = json.loads(data)
			money = unicode(context['money']) + u" k"
		else:
			money = '?'

	# We do not display the background as long as the viewer doesn't used an information opération to see it
	# The targeted player is saved in database as a string in the data field which is a json serialized
	# We will rebuild the piece of string we need and find if it exists in the string stored in database
	piece_of_string = u'"player_id": ' + unicode(player_profile.id)
	if player == player_profile or Log.objects.filter(event_type=game.BACKGROUND, game=game, data__contains=piece_of_string, concernedplayer__player=player).count() > 0:
		background = player_profile.background
	else:
		background = u"Vous devez lancer une opération d'information contre ce joueur pour connaitre son background"

	return {
		"player_profile": player_profile,
		"money": money,
		"rp": rp,
		"corporations": corporations,
		"qty_shares": sum([corporation.qty_share for corporation in corporations]),
		"events": events,
		"request": request,
		"citizenship": player_profile.citizenship.corporation,
		"pods": ['d_inc', 'current_player', 'players', ],
		"turn": game.current_turn,
		"background": background,
		"help_text_money": help_text_money,
	}