add create character stuff
This commit is contained in:
parent
f082f04d01
commit
5acbde1f07
|
@ -1,7 +1,7 @@
|
|||
from django import forms
|
||||
|
||||
from accounts.models import Accounts
|
||||
from accounts.utils import LoginHelper
|
||||
from accounts.utils import LoginHelper, VocationHelper
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
|
@ -18,3 +18,9 @@ class LoginForm(forms.Form):
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
class CreateCharacterForm(forms.Form):
|
||||
name = forms.CharField()
|
||||
vocation = forms.ChoiceField(
|
||||
choices=VocationHelper.get_base_vocation_choices())
|
||||
sex = forms.ChoiceField(choices=((0, 'female'), (1, 'male')))
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 19:59
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='accounts',
|
||||
options={'managed': True},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 20:00
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('accounts', '0002_auto_20190123_1959'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='accounts',
|
||||
name='linked_django_user',
|
||||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='accounts',
|
||||
name='creation',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='accounts',
|
||||
name='lastday',
|
||||
field=models.PositiveIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='accounts',
|
||||
name='premdays',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='accounts',
|
||||
name='type',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 22:14
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0003_auto_20190123_2000'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='players',
|
||||
options={'managed': True},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,259 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 22:25
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0004_auto_20190123_2214'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='players',
|
||||
name='account',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.DO_NOTHING, to='accounts.Accounts'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='balance',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='blessings',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='cap',
|
||||
field=models.IntegerField(default=400),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='conditions',
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='deletion',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='experience',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='group_id',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='health',
|
||||
field=models.IntegerField(default=150),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='healthmax',
|
||||
field=models.IntegerField(default=150),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lastip',
|
||||
field=models.PositiveIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lastlogin',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lastlogout',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='level',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lookaddons',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lookbody',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lookfeet',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='lookhead',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='looklegs',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='looktype',
|
||||
field=models.IntegerField(default=136),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='maglevel',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='mana',
|
||||
field=models.IntegerField(default=55),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='manamax',
|
||||
field=models.IntegerField(default=55),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='manaspent',
|
||||
field=models.PositiveIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='offlinetraining_skill',
|
||||
field=models.IntegerField(default=-1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='offlinetraining_time',
|
||||
field=models.PositiveSmallIntegerField(default=43200),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='onlinetime',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='save',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='sex',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_axe',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_axe_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_club',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_club_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_dist',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_dist_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_fishing',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_fishing_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_fist',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_fist_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_shielding',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_shielding_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_sword',
|
||||
field=models.PositiveIntegerField(default=10),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skill_sword_tries',
|
||||
field=models.BigIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skull',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='skulltime',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='soul',
|
||||
field=models.PositiveIntegerField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='stamina',
|
||||
field=models.PositiveSmallIntegerField(default=2520),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='town_id',
|
||||
field=models.IntegerField(default=1),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='vocation',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 22:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0005_auto_20190123_2225'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='id',
|
||||
field=models.AutoField(primary_key=True, serialize=False),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 22:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0006_auto_20190123_2232'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='players',
|
||||
old_name='save',
|
||||
new_name='tibia_save',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='tibia_save',
|
||||
field=models.IntegerField(db_column='save', default=1),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.5 on 2019-01-23 22:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0007_auto_20190123_2239'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='players',
|
||||
name='conditions',
|
||||
field=models.TextField(blank=True, default='', null=True),
|
||||
),
|
||||
]
|
|
@ -290,62 +290,63 @@ class PlayerStorage(models.Model):
|
|||
|
||||
|
||||
class Players(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(unique=True, max_length=255)
|
||||
group_id = models.IntegerField()
|
||||
account = models.ForeignKey(Accounts, models.DO_NOTHING)
|
||||
level = models.IntegerField()
|
||||
vocation = models.IntegerField()
|
||||
health = models.IntegerField()
|
||||
healthmax = models.IntegerField()
|
||||
experience = models.BigIntegerField()
|
||||
lookbody = models.IntegerField()
|
||||
lookfeet = models.IntegerField()
|
||||
lookhead = models.IntegerField()
|
||||
looklegs = models.IntegerField()
|
||||
looktype = models.IntegerField()
|
||||
lookaddons = models.IntegerField()
|
||||
maglevel = models.IntegerField()
|
||||
mana = models.IntegerField()
|
||||
manamax = models.IntegerField()
|
||||
manaspent = models.PositiveIntegerField()
|
||||
soul = models.PositiveIntegerField()
|
||||
town_id = models.IntegerField()
|
||||
group_id = models.IntegerField(default=1)
|
||||
account = models.ForeignKey(Accounts, models.DO_NOTHING, default=1)
|
||||
level = models.IntegerField(default=1)
|
||||
vocation = models.IntegerField(default=0)
|
||||
health = models.IntegerField(default=150)
|
||||
healthmax = models.IntegerField(default=150)
|
||||
experience = models.BigIntegerField(default=0)
|
||||
lookbody = models.IntegerField(default=0)
|
||||
lookfeet = models.IntegerField(default=0)
|
||||
lookhead = models.IntegerField(default=0)
|
||||
looklegs = models.IntegerField(default=0)
|
||||
looktype = models.IntegerField(default=136)
|
||||
lookaddons = models.IntegerField(default=0)
|
||||
maglevel = models.IntegerField(default=1)
|
||||
mana = models.IntegerField(default=55)
|
||||
manamax = models.IntegerField(default=55)
|
||||
manaspent = models.PositiveIntegerField(default=0)
|
||||
soul = models.PositiveIntegerField(default=0)
|
||||
town_id = models.IntegerField(default=1)
|
||||
posx = models.IntegerField()
|
||||
posy = models.IntegerField()
|
||||
posz = models.IntegerField()
|
||||
conditions = models.TextField()
|
||||
cap = models.IntegerField()
|
||||
sex = models.IntegerField()
|
||||
lastlogin = models.BigIntegerField()
|
||||
lastip = models.PositiveIntegerField()
|
||||
save = models.IntegerField()
|
||||
skull = models.IntegerField()
|
||||
skulltime = models.IntegerField()
|
||||
lastlogout = models.BigIntegerField()
|
||||
blessings = models.IntegerField()
|
||||
onlinetime = models.IntegerField()
|
||||
deletion = models.BigIntegerField()
|
||||
balance = models.BigIntegerField()
|
||||
offlinetraining_time = models.PositiveSmallIntegerField()
|
||||
offlinetraining_skill = models.IntegerField()
|
||||
stamina = models.PositiveSmallIntegerField()
|
||||
skill_fist = models.PositiveIntegerField()
|
||||
skill_fist_tries = models.BigIntegerField()
|
||||
skill_club = models.PositiveIntegerField()
|
||||
skill_club_tries = models.BigIntegerField()
|
||||
skill_sword = models.PositiveIntegerField()
|
||||
skill_sword_tries = models.BigIntegerField()
|
||||
skill_axe = models.PositiveIntegerField()
|
||||
skill_axe_tries = models.BigIntegerField()
|
||||
skill_dist = models.PositiveIntegerField()
|
||||
skill_dist_tries = models.BigIntegerField()
|
||||
skill_shielding = models.PositiveIntegerField()
|
||||
skill_shielding_tries = models.BigIntegerField()
|
||||
skill_fishing = models.PositiveIntegerField()
|
||||
skill_fishing_tries = models.BigIntegerField()
|
||||
conditions = models.TextField(blank=True, null=True, default='')
|
||||
cap = models.IntegerField(default=400)
|
||||
sex = models.IntegerField(default=0)
|
||||
lastlogin = models.BigIntegerField(default=0)
|
||||
lastip = models.PositiveIntegerField(default=0)
|
||||
tibia_save = models.IntegerField(default=1, db_column='save')
|
||||
skull = models.IntegerField(default=0)
|
||||
skulltime = models.IntegerField(default=0)
|
||||
lastlogout = models.BigIntegerField(default=0)
|
||||
blessings = models.IntegerField(default=0)
|
||||
onlinetime = models.IntegerField(default=0)
|
||||
deletion = models.BigIntegerField(default=0)
|
||||
balance = models.BigIntegerField(default=0)
|
||||
offlinetraining_time = models.PositiveSmallIntegerField(default=43200)
|
||||
offlinetraining_skill = models.IntegerField(default=-1)
|
||||
stamina = models.PositiveSmallIntegerField(default=2520)
|
||||
skill_fist = models.PositiveIntegerField(default=10)
|
||||
skill_fist_tries = models.BigIntegerField(default=0)
|
||||
skill_club = models.PositiveIntegerField(default=10)
|
||||
skill_club_tries = models.BigIntegerField(default=0)
|
||||
skill_sword = models.PositiveIntegerField(default=10)
|
||||
skill_sword_tries = models.BigIntegerField(default=0)
|
||||
skill_axe = models.PositiveIntegerField(default=10)
|
||||
skill_axe_tries = models.BigIntegerField(default=0)
|
||||
skill_dist = models.PositiveIntegerField(default=10)
|
||||
skill_dist_tries = models.BigIntegerField(default=0)
|
||||
skill_shielding = models.PositiveIntegerField(default=10)
|
||||
skill_shielding_tries = models.BigIntegerField(default=0)
|
||||
skill_fishing = models.PositiveIntegerField(default=10)
|
||||
skill_fishing_tries = models.BigIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
managed = True
|
||||
db_table = 'players'
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Add Character</h1>
|
||||
<form method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
|
@ -21,7 +21,9 @@
|
|||
<li><a href="{% url 'login'%}?next={{request.path}}">Login</a></li>
|
||||
{% endif %}
|
||||
<li><a href="{% url 'accounts:index' %}">Home</a></li>
|
||||
<li><a href="">Account</a></li>
|
||||
{% if user.is_authenticated %}
|
||||
<li><a href="{% url 'accounts:characters' %}">My characters</a></li>
|
||||
{% endif %}
|
||||
<li><a href="">All authors</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% if players %}
|
||||
<ul>
|
||||
{% for player in players %}
|
||||
<li>{{ player.name }} - Level {{ player.level }} - Vocation: {{ player.vocation }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
This account has no characters yet.
|
||||
{% endif %}
|
||||
|
||||
<a href="{% url 'accounts:create_char' %}">Create a new character</a>
|
||||
|
||||
{% endblock %}
|
|
@ -8,4 +8,6 @@ app_name = 'accounts'
|
|||
urlpatterns = [
|
||||
path('', views.IndexView.as_view(), name='index'),
|
||||
path('register/', views.RegisterAccountView.as_view(), name='register'),
|
||||
path('characters/', views.PlayerView.as_view(), name='characters'),
|
||||
path('create_character/', views.CreateCharView.as_view(), name='create_char'),
|
||||
]
|
|
@ -6,4 +6,25 @@ class LoginHelper(object):
|
|||
def hash_password(password):
|
||||
hashed_password = hashlib.sha1(password.encode('utf-8'))\
|
||||
.hexdigest()
|
||||
return hashed_password
|
||||
return hashed_password
|
||||
|
||||
class VocationHelper(object):
|
||||
mapper = {
|
||||
0: 'None',
|
||||
1: 'Sorcerer',
|
||||
2: 'Druid',
|
||||
3: 'Paladin',
|
||||
4: 'Knight',
|
||||
5: 'Master Sorcerer',
|
||||
6: 'Elder Druid',
|
||||
7: 'Royal Paladin',
|
||||
8: 'Elite Knight',
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def vocation_to_string(vocation_id):
|
||||
return VocationHelper.mapper[vocation_id]
|
||||
|
||||
@staticmethod
|
||||
def get_base_vocation_choices():
|
||||
return tuple([(k, v) for k, v, in VocationHelper.mapper.items() if k <= 4])
|
|
@ -1,11 +1,14 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.shortcuts import render, render_to_response
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.views import generic
|
||||
from django.views.generic.edit import CreateView, FormView
|
||||
# Create your views here.
|
||||
from accounts.forms import LoginForm
|
||||
from accounts.models import Accounts, Players
|
||||
from accounts.utils import LoginHelper
|
||||
from accounts.forms import CreateCharacterForm
|
||||
from accounts.models import Accounts, Players, Towns
|
||||
from accounts.utils import LoginHelper, VocationHelper
|
||||
|
||||
|
||||
class RegisterAccountView(CreateView):
|
||||
|
@ -36,4 +39,53 @@ class IndexView(generic.ListView):
|
|||
context_object_name = 'best_players'
|
||||
|
||||
def get_queryset(self):
|
||||
return Players.objects.filter(group_id=1).order_by('-level').values('name', 'level')[:10]
|
||||
return Players.objects.filter(group_id=1).order_by('-level').values('name', 'level')[:10]
|
||||
|
||||
class PlayerView(LoginRequiredMixin, generic.ListView):
|
||||
template_name = 'players.html'
|
||||
context_object_name = 'players'
|
||||
|
||||
def get_queryset(self):
|
||||
players = Players.objects.filter(account__linked_django_user=self.request.user)\
|
||||
.values('name', 'level', 'vocation')
|
||||
return players
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PlayerView, self).get_context_data(**kwargs)
|
||||
players = context['players']
|
||||
context['players'] = [{
|
||||
'name': p['name'],
|
||||
'level': p['level'],
|
||||
'vocation': VocationHelper.vocation_to_string(p['vocation'])}
|
||||
for p in players]
|
||||
return context
|
||||
|
||||
class CreateCharView(LoginRequiredMixin, FormView):
|
||||
form_class = CreateCharacterForm
|
||||
template_name = 'add_character.html'
|
||||
success_url = reverse_lazy('accounts:characters')
|
||||
|
||||
def form_valid(self, form):
|
||||
rookgaard = Towns.objects.get(name='Rookgaard')
|
||||
start_health = 150
|
||||
start_mana = 55
|
||||
start_cap = 400
|
||||
user = self.request.user
|
||||
account = Accounts.objects.get(linked_django_user=user)
|
||||
player = Players.objects.create(
|
||||
name=form.cleaned_data['name'],
|
||||
level=1,
|
||||
vocation=int(form.cleaned_data['vocation']),
|
||||
sex=int(form.cleaned_data['sex']),
|
||||
posx=rookgaard.posx,
|
||||
posy=rookgaard.posy,
|
||||
posz=rookgaard.posz,
|
||||
health=start_health,
|
||||
healthmax=start_health,
|
||||
mana=start_mana,
|
||||
manamax=start_mana,
|
||||
cap=start_cap,
|
||||
account_id=account.id,
|
||||
)
|
||||
return super(CreateCharView, self).form_valid(form)
|
||||
|
||||
|
|
Loading…
Reference in New Issue