def create_character(request): if not can_create_character(request.user): raise Http404() context = {'worlds': World.objects.all()} return render(request, 'world/create_character_step1.html', context=context)
def get(self, request, *args, **kwargs): if not can_create_character(request.user): raise Http404() return render(request, self.template_name, { 'world': get_object_or_404(World, id=kwargs['world_id']), 'names': get_names(limit=100), 'surnames': get_surnames(limit=100), })
def home(request): context = { 'server_messages': ServerMOTD.objects.all() if request.user.is_staff else ServerMOTD.objects.filter(draft=False), 'can_create_character': can_create_character(request.user) } return render(request, 'account/home.html', context=context)
def post(self, request, *args, **kwargs): if not can_create_character(request.user): raise Http404() try: world_id = kwargs['world_id'] world = World.objects.get(id=world_id) except World.DoesNotExist: messages.add_message(request, request.ERROR, "Invalid World") return redirect('world:create_character') try: state_id = request.POST.get('state_id') state = Organization.objects.get(id=state_id) except Organization.DoesNotExist: return self.fail_post_with_error( request, world_id, "Select a valid state" ) name = request.POST.get('name') surname = request.POST.get('surname') if name not in get_names() or surname not in get_surnames(): return self.fail_post_with_error( request, world_id, "Select a valid name/surname" ) profile = request.POST.get('profile') if profile not in (choice[0] for choice in Character.PROFILE_CHOICES): return self.fail_post_with_error( request, world_id, "Select a valid profile" ) character = Character.objects.create( name=name + ' ' + surname, world=world, location=random.choice( Settlement.objects.filter( tile__in=state.get_all_controlled_tiles() ) ), oath_sworn_to=state if state.leader is None else state.leader, owner_user=request.user, cash=100, profile=profile ) if character.profile == Character.TRADER: InventoryItem.objects.create( type=InventoryItem.CART, quantity=5, owner_character=character, ) character.add_notification( 'welcome', '<h4>Welcome, {char_name}!</h4>' '<p>You are starting as a member of {state_link}, a realm in ' '<a href="{world_url}">{world_name}</a>.</p>' '<p>A good way to start your journey is to write a message ' 'to the other members of {state_link} asking for orders ' 'or guidance on how you can be useful.</p>' ''.format( char_name=character.name, state_link=state.get_html_link(), world_url=world.get_absolute_url(), world_name=world.name ), safe=True ) state.character_members.add(character) return redirect(character.activation_url)
def post(self, request, *args, **kwargs): if not can_create_character(request.user): raise Http404() try: world_id = kwargs['world_id'] world = World.objects.get(id=world_id) except World.DoesNotExist: messages.add_message(request, request.ERROR, "Invalid World") return redirect('character:create') try: state_id = request.POST.get('state_id') state = Organization.objects.get(id=state_id) except Organization.DoesNotExist: return self.fail_post_with_error(request, world_id, "Select a valid Realm") name = request.POST.get('name') surname = request.POST.get('surname') if name not in get_names() or surname not in get_surnames(): return self.fail_post_with_error(request, world_id, "Select a valid name/surname") profile = request.POST.get('profile') if profile not in (choice[0] for choice in Character.PROFILE_CHOICES): return self.fail_post_with_error(request, world_id, "Select a valid profile") character = Character.objects.create( name=name + ' ' + surname, world=world, location=random.choice( Settlement.objects.filter( tile__in=state.get_all_controlled_tiles())), oath_sworn_to=state if state.leader is None else state.leader, owner_user=request.user, cash=100, profile=profile) if character.profile == Character.TRADER: InventoryItem.objects.create( type=InventoryItem.CART, quantity=5, owner_character=character, ) character.add_notification('messaging/messages/welcome.html', 'Welcome, {}'.format(character), { 'state': state, 'character': character }) if not state.barbaric: message = shortcuts.create_message( 'messaging/messages/new_character.html', world, "New member", { 'character': character, 'organization': state }, link=character.get_absolute_url()) shortcuts.add_organization_recipient(message, state) state.character_members.add(character) return redirect(character.activation_url)
def post(self, request, *args, **kwargs): if not can_create_character(request.user): raise Http404() try: world_id = kwargs['world_id'] world = World.objects.get(id=world_id) except World.DoesNotExist: messages.add_message(request, request.ERROR, "Invalid World") return redirect('world:create_character') try: state_id = request.POST.get('state_id') state = Organization.objects.get(id=state_id) except Organization.DoesNotExist: return self.fail_post_with_error(request, world_id, "Select a valid Realm") name = request.POST.get('name') surname = request.POST.get('surname') if name not in get_names() or surname not in get_surnames(): return self.fail_post_with_error(request, world_id, "Select a valid name/surname") profile = request.POST.get('profile') if profile not in (choice[0] for choice in Character.PROFILE_CHOICES): return self.fail_post_with_error(request, world_id, "Select a valid profile") character = Character.objects.create( name=name + ' ' + surname, world=world, location=random.choice( Settlement.objects.filter( tile__in=state.get_all_controlled_tiles())), oath_sworn_to=state if state.leader is None else state.leader, owner_user=request.user, cash=100, profile=profile) if character.profile == Character.TRADER: InventoryItem.objects.create( type=InventoryItem.CART, quantity=5, owner_character=character, ) character.add_notification( 'welcome', '<h4>Welcome, {char_name}!</h4>' '<p>' 'You are starting as a member of {state_link}, a realm in ' '<a href="{world_url}">{world_name}</a>.' '</p>' '<p>' 'A good way to start your journey is to write a message ' 'to the other members of {state_link} asking for orders ' 'or guidance on how you can be useful.' '</p>' '<p>' 'It is encouraged that you role play your character. This ' 'means that you should try to write in the voice of your ' 'character, {char_name}, an inhabitant of {world_name}, instead ' 'of your own, a person playing a computer game. You may want to ' 'come up with a simple past history of your ' 'character and presenting yourself to your realm. ' 'If you need to say something that your character would not say, ' 'you should prepend the letters OOC, meaning "out of character".' '</p>' ''.format(char_name=character.name, state_link=state.get_html_link(), world_url=world.get_absolute_url(), world_name=world.name), safe=True) message = shortcuts.create_message( "{} just joined {}. Let's give a warm welcome!".format( character, state), world, "newcomer", link=character.get_absolute_url()) shortcuts.add_organization_recipient(message, state) state.character_members.add(character) return redirect(character.activation_url)