Exemplo n.º 1
0
def post_injury(request, character_id, secret_key = None):
    if request.is_ajax and request.method == "POST":
        character = get_object_or_404(Character, id=character_id)
        form = InjuryForm(request.POST, prefix="injury")
        __check_edit_perms(request, character, secret_key)
        if form.is_valid():
            injury = Injury(description = form.cleaned_data['description'],
                            character=character,
                            severity = form.cleaned_data['severity'])
            with transaction.atomic():
                injury.save()
            ser_instance = serializers.serialize('json', [ injury, ])
            return JsonResponse({"instance": ser_instance, "id": injury.id, "severity": injury.severity}, status=200)
        else:
            return JsonResponse({"error": form.errors}, status=400)
    return JsonResponse({"error": ""}, status=400)
Exemplo n.º 2
0
def view_character(request, character_id, secret_key = None):
    character = get_object_or_404(Character, id=character_id)
    if character.player and secret_key:
        return HttpResponseRedirect(reverse('characters:characters_view', args=(character_id,)))
    if not character.player_can_view(request.user):
        raise PermissionDenied("You do not have permission to view this Character")
    if request.user.is_authenticated and not request.user.profile.confirmed_agreements:
            return HttpResponseRedirect(reverse('profiles:profiles_terms'))
    secret_key_valid = False
    if secret_key:
        secret_key_valid = character.is_editable_with_key(secret_key)
    else:
        secret_key = ""
    user_can_edit = (request.user.is_authenticated and character.player_can_edit(request.user)) or secret_key_valid
    if not character.stats_snapshot:
        context={"character": character,
                 "user_can_edit": user_can_edit}
        return render(request, 'characters/legacy_character.html', context)

    completed_games = [(x.relevant_game.end_time, "game", x) for x in character.completed_games()] # completed_games() does ordering
    character_edit_history = [(x.created_time, "edit", x) for x in
                              character.contractstats_set.filter(is_snapshot=False).order_by("created_time").all()[1:]]
    exp_rewards = [(x.created_time, "exp_reward", x) for x in character.experiencereward_set.order_by("created_time").all()]
    events_by_date = list(merge(completed_games, character_edit_history, exp_rewards))
    timeline = defaultdict(list)
    for event in events_by_date:
        timeline[event[0].strftime("%d %b %Y")].append((event[1], event[2]))

    char_ability_values = character.stats_snapshot.abilityvalue_set.order_by("relevant_ability__name").all()
    char_value_ids = [x.relevant_ability.id for x in char_ability_values]
    primary_zero_values = [(x.name, x, 0) for x in Ability.objects.filter(is_primary=True).order_by("name").all()
                 if x.id not in char_value_ids]
    all_ability_values =[(x.relevant_ability.name, x.relevant_ability, x.value) for x in char_ability_values]
    ability_value_by_name = list(merge(primary_zero_values, all_ability_values))
    unspent_experience = character.unspent_experience()
    exp_earned = character.exp_earned()
    exp_cost = character.exp_cost()

    equipment_form = EquipmentForm()
    context = {
        'character': character,
        'user_can_edit': user_can_edit,
        'health_display': character.get_health_display(),
        'ability_value_by_name': ability_value_by_name,
        'physical_attributes': character.get_attributes(is_physical=True),
        'mental_attributes': character.get_attributes(is_physical=False),
        'timeline': dict(timeline),
        'tutorial': get_object_or_404(CharacterTutorial),
        'battle_scar_form': BattleScarForm(),
        'trauma_form': TraumaForm(prefix="trauma"),
        'injury_form': InjuryForm(request.POST, prefix="injury"),
        'exp_cost': exp_cost,
        'exp_earned': exp_earned,
        'unspent_experience': unspent_experience,
        'equipment_form': equipment_form,
        'secret_key': secret_key,
        'secret_key_valid': secret_key_valid,
    }
    return render(request, 'characters/view_pages/view_character.html', context)
Exemplo n.º 3
0
def delete_injury(request, injury_id, secret_key=None):
    if request.is_ajax and request.method == "POST":
        injury = get_object_or_404(Injury, id=injury_id)
        form = InjuryForm(request.POST, prefix="injury")
        __check_edit_perms(request, injury.character, secret_key)
        with transaction.atomic():
            injury.delete()
        return JsonResponse({}, status=200)
    return JsonResponse({"error": ""}, status=400)
Exemplo n.º 4
0
def set_mind_damage(request, character_id, secret_key=None):
    if request.is_ajax and request.method == "POST":
        character = get_object_or_404(Character, id=character_id)
        form = InjuryForm(request.POST, prefix="mental-exertion")
        __check_edit_perms(request, character, secret_key)
        if form.is_valid():
            requested_damage = form.cleaned_data['severity']
            num_mind = character.num_mind_levels()
            if requested_damage > num_mind:
                character.mental_damage = num_mind
            elif requested_damage < 0:
                character.mental_damage = 0
            else:
                character.mental_damage = requested_damage
            with transaction.atomic():
                character.save()
            return JsonResponse({}, status=200)
        else:
            return JsonResponse({"error": form.errors}, status=400)
    return JsonResponse({"error": ""}, status=400)
Exemplo n.º 5
0
def how_to_play(request):
    quickstart_info = QuickStartInfo.objects.first()
    character = quickstart_info.main_char
    attribute_val_by_id = character.get_attribute_values_by_id()
    actions = ExampleAction.objects.filter(is_first_roll=False).all()
    first_action = ExampleAction.objects.filter(is_first_roll=True).get()
    character_tutorial = get_object_or_404(CharacterTutorial)
    action_list = []
    physical_attributes = character.get_attributes(is_physical=True)
    mental_attributes = character.get_attributes(is_physical=False)
    char_ability_values = character.stats_snapshot.abilityvalue_set.order_by(
        "relevant_ability__name").all()
    ability_value_by_id = {}
    char_value_ids = [x.relevant_ability.id for x in char_ability_values]
    primary_zero_values = [(x.name, x, 0) for x in Ability.objects.filter(
        is_primary=True).order_by("name").all() if x.id not in char_value_ids]
    all_ability_values = []
    for x in char_ability_values:
        all_ability_values.append(
            (x.relevant_ability.name, x.relevant_ability, x.value))
        ability_value_by_id[x.relevant_ability.id] = x.value
    ability_value_by_name = list(merge(primary_zero_values,
                                       all_ability_values))
    for action in actions:
        action_list.append(action.json_serialize())

    expand_step = []
    expand_step.append(True)  # zero index fix
    expand_step.append(not request.user.is_authenticated)  #login
    expand_step.append(
        not request.user.is_authenticated
        or request.user.character_set.count() == 0)  # create contractor
    expand_step.append(
        not request.user.is_authenticated
        or request.user.cell_set.count() == 0)  # create / join Playgroup
    context = {
        "quickstart_info":
        quickstart_info,
        "character":
        character,
        'health_display':
        character.get_health_display(),
        'injury_form':
        InjuryForm(request.POST, prefix="injury"),
        "physical_attributes":
        physical_attributes,
        "mental_attributes":
        mental_attributes,
        "attribute_value_by_id":
        attribute_val_by_id,
        "ability_value_by_id":
        ability_value_by_id,
        "ability_value_by_name":
        ability_value_by_name,
        "action_list":
        action_list,
        "first_action":
        first_action.json_serialize(),
        "tutorial":
        character_tutorial,
        "expand_step":
        expand_step,
        'powers_modal_art_url':
        static('overrides/art/grace.png'),
        'sig_item_modal_art_url':
        static('overrides/art/lady_lake_sm.jpg'),
        'art_craft_modal_art_url':
        static('overrides/art/front-music.jpg'),
        'consumable_craft_modal_art_url':
        static('overrides/art/sushi.jpg'),
        'mod_power':
        get_object_or_404(Base_Power, slug='power'),
        'mod_sig_item':
        get_object_or_404(Base_Power, slug='signature-item-mod'),
        'mod_consumable':
        get_object_or_404(Base_Power, slug='craftable-consumable'),
        'mod_artifacts':
        get_object_or_404(Base_Power, slug='craftable-artifact'),
    }
    return render(request, 'info/new_player_guide/quickstart.html', context)
Exemplo n.º 6
0
def view_character(request, character_id, secret_key=None):
    character = get_object_or_404(Character, id=character_id)
    if character.player and secret_key:
        return HttpResponseRedirect(
            reverse('characters:characters_view', args=(character_id, )))
    if not character.player_can_view(request.user):
        raise PermissionDenied(
            "You do not have permission to view this Character")
    if request.user.is_authenticated and not request.user.profile.confirmed_agreements:
        return HttpResponseRedirect(reverse('profiles:profiles_terms'))
    secret_key_valid = False
    if secret_key:
        secret_key_valid = character.is_editable_with_key(secret_key)
    else:
        secret_key = ""
    user_can_edit = (request.user.is_authenticated
                     and character.player_can_edit(
                         request.user)) or secret_key_valid
    if not character.stats_snapshot:
        context = {"character": character, "user_can_edit": user_can_edit}
        return render(request, 'characters/legacy_character.html', context)

    completed_games = [(x.relevant_game.end_time, "game", x)
                       for x in character.completed_games()
                       ]  # completed_games() does ordering
    character_edit_history = [
        (x.created_time, "edit", x)
        for x in character.contractstats_set.filter(
            is_snapshot=False).order_by("created_time").all()[1:]
    ]
    exp_rewards = [(x.created_time, "exp_reward", x)
                   for x in character.experiencereward_set.filter(
                       is_void=False).order_by("created_time").all()]
    events_by_date = list(
        merge(completed_games, character_edit_history, exp_rewards))
    timeline = defaultdict(list)
    for event in events_by_date:
        if event[1] == "edit":
            phrases = event[2].get_change_phrases()
            if len(phrases):
                timeline[event[0].strftime("%d %b %Y")].append(
                    (event[1], phrases))
        else:
            timeline[event[0].strftime("%d %b %Y")].append(
                (event[1], event[2]))

    char_ability_values = character.stats_snapshot.abilityvalue_set.order_by(
        "relevant_ability__name").all()
    ability_value_by_id = {}
    char_value_ids = [x.relevant_ability.id for x in char_ability_values]
    primary_zero_values = [(x.name, x, 0) for x in Ability.objects.filter(
        is_primary=True).order_by("name").all() if x.id not in char_value_ids]
    all_ability_values = []
    for x in char_ability_values:
        all_ability_values.append(
            (x.relevant_ability.name, x.relevant_ability, x.value))
        ability_value_by_id[x.relevant_ability.id] = x.value
    ability_value_by_name = list(merge(primary_zero_values,
                                       all_ability_values))
    unspent_experience = character.unspent_experience()
    exp_earned = character.exp_earned()
    exp_cost = character.exp_cost()

    equipment_form = EquipmentForm()
    bio_form = BioForm()

    num_journal_entries = character.num_journals if character.num_journals else 0
    latest_journals = []
    if num_journal_entries > 0:
        journal_query = Journal.objects.filter(
            game_attendance__attending_character=character.id).order_by(
                '-created_date')
        if request.user.is_anonymous or not request.user.profile.view_adult_content:
            journal_query = journal_query.exclude(is_nsfw=True)
        journals = journal_query.all()
        for journal in journals:
            if len(latest_journals) > 2:
                break
            if journal.player_can_view(request.user):
                latest_journals.append(journal)

    journal_cover = get_object_or_none(JournalCover, character=character.id)
    next_entry = get_characters_next_journal_credit(
        character) if user_can_edit else None

    show_more_home_games_warning = character.number_completed_games() > 3 \
                                   and (character.number_completed_games_in_home_cell() < character.number_completed_games_out_of_home_cell())
    available_gift = character.unspent_rewards().count() > 0
    circumstance_form = None
    condition_form = None
    artifact_form = None
    world_element_initial_cell = character.world_element_initial_cell()
    world_element_cell_choices = None
    if user_can_edit:
        # We only need these choices if the user can edit, both for forms and for char sheet.
        world_element_cell_choices = character.world_element_cell_choices()
        circumstance_form = make_world_element_form(
            world_element_cell_choices, world_element_initial_cell)
        condition_form = make_world_element_form(world_element_cell_choices,
                                                 world_element_initial_cell)
        artifact_form = make_world_element_form(world_element_cell_choices,
                                                world_element_initial_cell)

    artifacts = get_world_element_default_dict(world_element_cell_choices)
    for artifact in character.artifact_set.all():
        artifacts[artifact.cell].append(artifact)
    artifacts = dict(artifacts)

    circumstances = get_world_element_default_dict(world_element_cell_choices)
    for circumstance in character.circumstance_set.all():
        circumstances[circumstance.cell].append(circumstance)
    circumstances = dict(circumstances)

    conditions = get_world_element_default_dict(world_element_cell_choices)
    for condition in character.condition_set.all():
        conditions[condition.cell].append(condition)
    conditions = dict(conditions)

    assets = character.stats_snapshot.assetdetails_set.all()
    liabilities = character.stats_snapshot.liabilitydetails_set.all()
    physical_attributes = character.get_attributes(is_physical=True)
    mental_attributes = character.get_attributes(is_physical=False)
    attribute_value_by_id = {}
    for attr in physical_attributes:
        attribute_value_by_id[
            attr.relevant_attribute.id] = attr.val_with_bonuses()
    for attr in mental_attributes:
        attribute_value_by_id[
            attr.relevant_attribute.id] = attr.val_with_bonuses()
    context = {
        'character': character,
        'user_can_edit': user_can_edit,
        'health_display': character.get_health_display(),
        'ability_value_by_name': ability_value_by_name,
        'ability_value_by_id': ability_value_by_id,
        'physical_attributes': physical_attributes,
        'mental_attributes': mental_attributes,
        'attribute_value_by_id': attribute_value_by_id,
        'timeline': dict(timeline),
        'tutorial': get_object_or_404(CharacterTutorial),
        'battle_scar_form': BattleScarForm(),
        'trauma_form': TraumaForm(prefix="trauma"),
        'injury_form': InjuryForm(request.POST, prefix="injury"),
        'exp_cost': exp_cost,
        'exp_earned': exp_earned,
        'unspent_experience': unspent_experience,
        'equipment_form': equipment_form,
        'bio_form': bio_form,
        'secret_key': secret_key,
        'secret_key_valid': secret_key_valid,
        'num_journal_entries': num_journal_entries,
        'journal_cover': journal_cover,
        'next_entry': next_entry,
        'latest_journals': latest_journals,
        'show_more_home_games_warning': show_more_home_games_warning,
        'available_gift': available_gift,
        'circumstance_form': circumstance_form,
        'condition_form': condition_form,
        'artifact_form': artifact_form,
        'artifacts_by_cell': artifacts,
        'conditions_by_cell': conditions,
        'circumstances_by_cell': circumstances,
        'initial_cell': world_element_initial_cell,
        'assets': assets,
        'liabilities': liabilities,
    }
    return render(request, 'characters/view_pages/view_character.html',
                  context)