Browse Source

add create character stuff

Gesche 10 months ago
parent
commit
5acbde1f07

+ 7
- 1
accounts/forms.py View File

@@ -1,7 +1,7 @@
1 1
 from django import forms
2 2
 
3 3
 from accounts.models import Accounts
4
-from accounts.utils import LoginHelper
4
+from accounts.utils import LoginHelper, VocationHelper
5 5
 
6 6
 
7 7
 class LoginForm(forms.Form):
@@ -18,3 +18,9 @@ class LoginForm(forms.Form):
18 18
             return True
19 19
         else:
20 20
             return False
21
+
22
+class CreateCharacterForm(forms.Form):
23
+    name = forms.CharField()
24
+    vocation = forms.ChoiceField(
25
+        choices=VocationHelper.get_base_vocation_choices())
26
+    sex = forms.ChoiceField(choices=((0, 'female'), (1, 'male')))

+ 17
- 0
accounts/migrations/0002_auto_20190123_1959.py View File

@@ -0,0 +1,17 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 19:59
2
+
3
+from django.db import migrations
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('accounts', '0001_initial'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterModelOptions(
14
+            name='accounts',
15
+            options={'managed': True},
16
+        ),
17
+    ]

+ 41
- 0
accounts/migrations/0003_auto_20190123_2000.py View File

@@ -0,0 +1,41 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 20:00
2
+
3
+from django.conf import settings
4
+from django.db import migrations, models
5
+import django.db.models.deletion
6
+
7
+
8
+class Migration(migrations.Migration):
9
+
10
+    dependencies = [
11
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12
+        ('accounts', '0002_auto_20190123_1959'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.AddField(
17
+            model_name='accounts',
18
+            name='linked_django_user',
19
+            field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
20
+        ),
21
+        migrations.AlterField(
22
+            model_name='accounts',
23
+            name='creation',
24
+            field=models.IntegerField(default=0),
25
+        ),
26
+        migrations.AlterField(
27
+            model_name='accounts',
28
+            name='lastday',
29
+            field=models.PositiveIntegerField(default=0),
30
+        ),
31
+        migrations.AlterField(
32
+            model_name='accounts',
33
+            name='premdays',
34
+            field=models.IntegerField(default=0),
35
+        ),
36
+        migrations.AlterField(
37
+            model_name='accounts',
38
+            name='type',
39
+            field=models.IntegerField(default=1),
40
+        ),
41
+    ]

+ 17
- 0
accounts/migrations/0004_auto_20190123_2214.py View File

@@ -0,0 +1,17 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 22:14
2
+
3
+from django.db import migrations
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('accounts', '0003_auto_20190123_2000'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterModelOptions(
14
+            name='players',
15
+            options={'managed': True},
16
+        ),
17
+    ]

+ 259
- 0
accounts/migrations/0005_auto_20190123_2225.py View File

@@ -0,0 +1,259 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 22:25
2
+
3
+from django.db import migrations, models
4
+import django.db.models.deletion
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('accounts', '0004_auto_20190123_2214'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='players',
16
+            name='account',
17
+            field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.DO_NOTHING, to='accounts.Accounts'),
18
+        ),
19
+        migrations.AlterField(
20
+            model_name='players',
21
+            name='balance',
22
+            field=models.BigIntegerField(default=0),
23
+        ),
24
+        migrations.AlterField(
25
+            model_name='players',
26
+            name='blessings',
27
+            field=models.IntegerField(default=0),
28
+        ),
29
+        migrations.AlterField(
30
+            model_name='players',
31
+            name='cap',
32
+            field=models.IntegerField(default=400),
33
+        ),
34
+        migrations.AlterField(
35
+            model_name='players',
36
+            name='conditions',
37
+            field=models.TextField(blank=True, null=True),
38
+        ),
39
+        migrations.AlterField(
40
+            model_name='players',
41
+            name='deletion',
42
+            field=models.BigIntegerField(default=0),
43
+        ),
44
+        migrations.AlterField(
45
+            model_name='players',
46
+            name='experience',
47
+            field=models.BigIntegerField(default=0),
48
+        ),
49
+        migrations.AlterField(
50
+            model_name='players',
51
+            name='group_id',
52
+            field=models.IntegerField(default=1),
53
+        ),
54
+        migrations.AlterField(
55
+            model_name='players',
56
+            name='health',
57
+            field=models.IntegerField(default=150),
58
+        ),
59
+        migrations.AlterField(
60
+            model_name='players',
61
+            name='healthmax',
62
+            field=models.IntegerField(default=150),
63
+        ),
64
+        migrations.AlterField(
65
+            model_name='players',
66
+            name='lastip',
67
+            field=models.PositiveIntegerField(default=0),
68
+        ),
69
+        migrations.AlterField(
70
+            model_name='players',
71
+            name='lastlogin',
72
+            field=models.BigIntegerField(default=0),
73
+        ),
74
+        migrations.AlterField(
75
+            model_name='players',
76
+            name='lastlogout',
77
+            field=models.BigIntegerField(default=0),
78
+        ),
79
+        migrations.AlterField(
80
+            model_name='players',
81
+            name='level',
82
+            field=models.IntegerField(default=1),
83
+        ),
84
+        migrations.AlterField(
85
+            model_name='players',
86
+            name='lookaddons',
87
+            field=models.IntegerField(default=0),
88
+        ),
89
+        migrations.AlterField(
90
+            model_name='players',
91
+            name='lookbody',
92
+            field=models.IntegerField(default=0),
93
+        ),
94
+        migrations.AlterField(
95
+            model_name='players',
96
+            name='lookfeet',
97
+            field=models.IntegerField(default=0),
98
+        ),
99
+        migrations.AlterField(
100
+            model_name='players',
101
+            name='lookhead',
102
+            field=models.IntegerField(default=0),
103
+        ),
104
+        migrations.AlterField(
105
+            model_name='players',
106
+            name='looklegs',
107
+            field=models.IntegerField(default=0),
108
+        ),
109
+        migrations.AlterField(
110
+            model_name='players',
111
+            name='looktype',
112
+            field=models.IntegerField(default=136),
113
+        ),
114
+        migrations.AlterField(
115
+            model_name='players',
116
+            name='maglevel',
117
+            field=models.IntegerField(default=1),
118
+        ),
119
+        migrations.AlterField(
120
+            model_name='players',
121
+            name='mana',
122
+            field=models.IntegerField(default=55),
123
+        ),
124
+        migrations.AlterField(
125
+            model_name='players',
126
+            name='manamax',
127
+            field=models.IntegerField(default=55),
128
+        ),
129
+        migrations.AlterField(
130
+            model_name='players',
131
+            name='manaspent',
132
+            field=models.PositiveIntegerField(default=0),
133
+        ),
134
+        migrations.AlterField(
135
+            model_name='players',
136
+            name='offlinetraining_skill',
137
+            field=models.IntegerField(default=-1),
138
+        ),
139
+        migrations.AlterField(
140
+            model_name='players',
141
+            name='offlinetraining_time',
142
+            field=models.PositiveSmallIntegerField(default=43200),
143
+        ),
144
+        migrations.AlterField(
145
+            model_name='players',
146
+            name='onlinetime',
147
+            field=models.IntegerField(default=0),
148
+        ),
149
+        migrations.AlterField(
150
+            model_name='players',
151
+            name='save',
152
+            field=models.IntegerField(default=1),
153
+        ),
154
+        migrations.AlterField(
155
+            model_name='players',
156
+            name='sex',
157
+            field=models.IntegerField(default=0),
158
+        ),
159
+        migrations.AlterField(
160
+            model_name='players',
161
+            name='skill_axe',
162
+            field=models.PositiveIntegerField(default=10),
163
+        ),
164
+        migrations.AlterField(
165
+            model_name='players',
166
+            name='skill_axe_tries',
167
+            field=models.BigIntegerField(default=0),
168
+        ),
169
+        migrations.AlterField(
170
+            model_name='players',
171
+            name='skill_club',
172
+            field=models.PositiveIntegerField(default=10),
173
+        ),
174
+        migrations.AlterField(
175
+            model_name='players',
176
+            name='skill_club_tries',
177
+            field=models.BigIntegerField(default=0),
178
+        ),
179
+        migrations.AlterField(
180
+            model_name='players',
181
+            name='skill_dist',
182
+            field=models.PositiveIntegerField(default=10),
183
+        ),
184
+        migrations.AlterField(
185
+            model_name='players',
186
+            name='skill_dist_tries',
187
+            field=models.BigIntegerField(default=0),
188
+        ),
189
+        migrations.AlterField(
190
+            model_name='players',
191
+            name='skill_fishing',
192
+            field=models.PositiveIntegerField(default=10),
193
+        ),
194
+        migrations.AlterField(
195
+            model_name='players',
196
+            name='skill_fishing_tries',
197
+            field=models.BigIntegerField(default=0),
198
+        ),
199
+        migrations.AlterField(
200
+            model_name='players',
201
+            name='skill_fist',
202
+            field=models.PositiveIntegerField(default=10),
203
+        ),
204
+        migrations.AlterField(
205
+            model_name='players',
206
+            name='skill_fist_tries',
207
+            field=models.BigIntegerField(default=0),
208
+        ),
209
+        migrations.AlterField(
210
+            model_name='players',
211
+            name='skill_shielding',
212
+            field=models.PositiveIntegerField(default=10),
213
+        ),
214
+        migrations.AlterField(
215
+            model_name='players',
216
+            name='skill_shielding_tries',
217
+            field=models.BigIntegerField(default=0),
218
+        ),
219
+        migrations.AlterField(
220
+            model_name='players',
221
+            name='skill_sword',
222
+            field=models.PositiveIntegerField(default=10),
223
+        ),
224
+        migrations.AlterField(
225
+            model_name='players',
226
+            name='skill_sword_tries',
227
+            field=models.BigIntegerField(default=0),
228
+        ),
229
+        migrations.AlterField(
230
+            model_name='players',
231
+            name='skull',
232
+            field=models.IntegerField(default=0),
233
+        ),
234
+        migrations.AlterField(
235
+            model_name='players',
236
+            name='skulltime',
237
+            field=models.IntegerField(default=0),
238
+        ),
239
+        migrations.AlterField(
240
+            model_name='players',
241
+            name='soul',
242
+            field=models.PositiveIntegerField(default=0),
243
+        ),
244
+        migrations.AlterField(
245
+            model_name='players',
246
+            name='stamina',
247
+            field=models.PositiveSmallIntegerField(default=2520),
248
+        ),
249
+        migrations.AlterField(
250
+            model_name='players',
251
+            name='town_id',
252
+            field=models.IntegerField(default=1),
253
+        ),
254
+        migrations.AlterField(
255
+            model_name='players',
256
+            name='vocation',
257
+            field=models.IntegerField(default=0),
258
+        ),
259
+    ]

+ 18
- 0
accounts/migrations/0006_auto_20190123_2232.py View File

@@ -0,0 +1,18 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 22:32
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('accounts', '0005_auto_20190123_2225'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterField(
14
+            model_name='players',
15
+            name='id',
16
+            field=models.AutoField(primary_key=True, serialize=False),
17
+        ),
18
+    ]

+ 23
- 0
accounts/migrations/0007_auto_20190123_2239.py View File

@@ -0,0 +1,23 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 22:39
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('accounts', '0006_auto_20190123_2232'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.RenameField(
14
+            model_name='players',
15
+            old_name='save',
16
+            new_name='tibia_save',
17
+        ),
18
+        migrations.AlterField(
19
+            model_name='players',
20
+            name='tibia_save',
21
+            field=models.IntegerField(db_column='save', default=1),
22
+        ),
23
+    ]

+ 18
- 0
accounts/migrations/0008_auto_20190123_2240.py View File

@@ -0,0 +1,18 @@
1
+# Generated by Django 2.1.5 on 2019-01-23 22:40
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('accounts', '0007_auto_20190123_2239'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AlterField(
14
+            model_name='players',
15
+            name='conditions',
16
+            field=models.TextField(blank=True, default='', null=True),
17
+        ),
18
+    ]

+ 51
- 50
accounts/models.py View File

@@ -290,62 +290,63 @@ class PlayerStorage(models.Model):
290 290
 
291 291
 
292 292
 class Players(models.Model):
293
+    id = models.AutoField(primary_key=True)
293 294
     name = models.CharField(unique=True, max_length=255)
294
-    group_id = models.IntegerField()
295
-    account = models.ForeignKey(Accounts, models.DO_NOTHING)
296
-    level = models.IntegerField()
297
-    vocation = models.IntegerField()
298
-    health = models.IntegerField()
299
-    healthmax = models.IntegerField()
300
-    experience = models.BigIntegerField()
301
-    lookbody = models.IntegerField()
302
-    lookfeet = models.IntegerField()
303
-    lookhead = models.IntegerField()
304
-    looklegs = models.IntegerField()
305
-    looktype = models.IntegerField()
306
-    lookaddons = models.IntegerField()
307
-    maglevel = models.IntegerField()
308
-    mana = models.IntegerField()
309
-    manamax = models.IntegerField()
310
-    manaspent = models.PositiveIntegerField()
311
-    soul = models.PositiveIntegerField()
312
-    town_id = models.IntegerField()
295
+    group_id = models.IntegerField(default=1)
296
+    account = models.ForeignKey(Accounts, models.DO_NOTHING, default=1)
297
+    level = models.IntegerField(default=1)
298
+    vocation = models.IntegerField(default=0)
299
+    health = models.IntegerField(default=150)
300
+    healthmax = models.IntegerField(default=150)
301
+    experience = models.BigIntegerField(default=0)
302
+    lookbody = models.IntegerField(default=0)
303
+    lookfeet = models.IntegerField(default=0)
304
+    lookhead = models.IntegerField(default=0)
305
+    looklegs = models.IntegerField(default=0)
306
+    looktype = models.IntegerField(default=136)
307
+    lookaddons = models.IntegerField(default=0)
308
+    maglevel = models.IntegerField(default=1)
309
+    mana = models.IntegerField(default=55)
310
+    manamax = models.IntegerField(default=55)
311
+    manaspent = models.PositiveIntegerField(default=0)
312
+    soul = models.PositiveIntegerField(default=0)
313
+    town_id = models.IntegerField(default=1)
313 314
     posx = models.IntegerField()
314 315
     posy = models.IntegerField()
315 316
     posz = models.IntegerField()
316
-    conditions = models.TextField()
317
-    cap = models.IntegerField()
318
-    sex = models.IntegerField()
319
-    lastlogin = models.BigIntegerField()
320
-    lastip = models.PositiveIntegerField()
321
-    save = models.IntegerField()
322
-    skull = models.IntegerField()
323
-    skulltime = models.IntegerField()
324
-    lastlogout = models.BigIntegerField()
325
-    blessings = models.IntegerField()
326
-    onlinetime = models.IntegerField()
327
-    deletion = models.BigIntegerField()
328
-    balance = models.BigIntegerField()
329
-    offlinetraining_time = models.PositiveSmallIntegerField()
330
-    offlinetraining_skill = models.IntegerField()
331
-    stamina = models.PositiveSmallIntegerField()
332
-    skill_fist = models.PositiveIntegerField()
333
-    skill_fist_tries = models.BigIntegerField()
334
-    skill_club = models.PositiveIntegerField()
335
-    skill_club_tries = models.BigIntegerField()
336
-    skill_sword = models.PositiveIntegerField()
337
-    skill_sword_tries = models.BigIntegerField()
338
-    skill_axe = models.PositiveIntegerField()
339
-    skill_axe_tries = models.BigIntegerField()
340
-    skill_dist = models.PositiveIntegerField()
341
-    skill_dist_tries = models.BigIntegerField()
342
-    skill_shielding = models.PositiveIntegerField()
343
-    skill_shielding_tries = models.BigIntegerField()
344
-    skill_fishing = models.PositiveIntegerField()
345
-    skill_fishing_tries = models.BigIntegerField()
317
+    conditions = models.TextField(blank=True, null=True, default='')
318
+    cap = models.IntegerField(default=400)
319
+    sex = models.IntegerField(default=0)
320
+    lastlogin = models.BigIntegerField(default=0)
321
+    lastip = models.PositiveIntegerField(default=0)
322
+    tibia_save = models.IntegerField(default=1, db_column='save')
323
+    skull = models.IntegerField(default=0)
324
+    skulltime = models.IntegerField(default=0)
325
+    lastlogout = models.BigIntegerField(default=0)
326
+    blessings = models.IntegerField(default=0)
327
+    onlinetime = models.IntegerField(default=0)
328
+    deletion = models.BigIntegerField(default=0)
329
+    balance = models.BigIntegerField(default=0)
330
+    offlinetraining_time = models.PositiveSmallIntegerField(default=43200)
331
+    offlinetraining_skill = models.IntegerField(default=-1)
332
+    stamina = models.PositiveSmallIntegerField(default=2520)
333
+    skill_fist = models.PositiveIntegerField(default=10)
334
+    skill_fist_tries = models.BigIntegerField(default=0)
335
+    skill_club = models.PositiveIntegerField(default=10)
336
+    skill_club_tries = models.BigIntegerField(default=0)
337
+    skill_sword = models.PositiveIntegerField(default=10)
338
+    skill_sword_tries = models.BigIntegerField(default=0)
339
+    skill_axe = models.PositiveIntegerField(default=10)
340
+    skill_axe_tries = models.BigIntegerField(default=0)
341
+    skill_dist = models.PositiveIntegerField(default=10)
342
+    skill_dist_tries = models.BigIntegerField(default=0)
343
+    skill_shielding = models.PositiveIntegerField(default=10)
344
+    skill_shielding_tries = models.BigIntegerField(default=0)
345
+    skill_fishing = models.PositiveIntegerField(default=10)
346
+    skill_fishing_tries = models.BigIntegerField(default=0)
346 347
 
347 348
     class Meta:
348
-        managed = False
349
+        managed = True
349 350
         db_table = 'players'
350 351
 
351 352
 

+ 10
- 0
accounts/templates/add_character.html View File

@@ -0,0 +1,10 @@
1
+{% extends "base_generic.html" %}
2
+
3
+{% block content %}
4
+<h1>Add Character</h1>
5
+    <form method="post">{% csrf_token %}
6
+    {{ form.as_p }}
7
+    <input type="submit" value="Save">
8
+</form>
9
+
10
+{% endblock %}

+ 3
- 1
accounts/templates/base_generic.html View File

@@ -21,7 +21,9 @@
21 21
           <li><a href="{% url 'login'%}?next={{request.path}}">Login</a></li>
22 22
         {% endif %}
23 23
           <li><a href="{% url 'accounts:index' %}">Home</a></li>
24
-          <li><a href="">Account</a></li>
24
+        {% if user.is_authenticated %}
25
+          <li><a href="{% url 'accounts:characters' %}">My characters</a></li>
26
+        {% endif %}
25 27
           <li><a href="">All authors</a></li>
26 28
         </ul>
27 29
      {% endblock %}

+ 16
- 0
accounts/templates/players.html View File

@@ -0,0 +1,16 @@
1
+{% extends "base_generic.html" %}
2
+
3
+{% block content %}
4
+    {%  if players %}
5
+    <ul>
6
+        {% for player in players %}
7
+            <li>{{ player.name }} - Level {{ player.level }} - Vocation: {{ player.vocation }}</li>
8
+        {% endfor %}
9
+    </ul>
10
+    {% else %}
11
+        This account has no characters yet.
12
+    {% endif %}
13
+
14
+    <a href="{% url 'accounts:create_char' %}">Create a new character</a>
15
+
16
+{% endblock %}

+ 2
- 0
accounts/urls.py View File

@@ -8,4 +8,6 @@ app_name = 'accounts'
8 8
 urlpatterns = [
9 9
     path('', views.IndexView.as_view(), name='index'),
10 10
     path('register/', views.RegisterAccountView.as_view(), name='register'),
11
+    path('characters/', views.PlayerView.as_view(), name='characters'),
12
+    path('create_character/', views.CreateCharView.as_view(), name='create_char'),
11 13
 ]

+ 22
- 1
accounts/utils.py View File

@@ -6,4 +6,25 @@ class LoginHelper(object):
6 6
     def hash_password(password):
7 7
         hashed_password = hashlib.sha1(password.encode('utf-8'))\
8 8
             .hexdigest()
9
-        return hashed_password
9
+        return hashed_password
10
+
11
+class VocationHelper(object):
12
+    mapper = {
13
+        0: 'None',
14
+        1: 'Sorcerer',
15
+        2: 'Druid',
16
+        3: 'Paladin',
17
+        4: 'Knight',
18
+        5: 'Master Sorcerer',
19
+        6: 'Elder Druid',
20
+        7: 'Royal Paladin',
21
+        8: 'Elite Knight',
22
+    }
23
+
24
+    @staticmethod
25
+    def vocation_to_string(vocation_id):
26
+        return VocationHelper.mapper[vocation_id]
27
+
28
+    @staticmethod
29
+    def get_base_vocation_choices():
30
+        return tuple([(k, v) for k, v, in VocationHelper.mapper.items() if k <= 4])

+ 56
- 4
accounts/views.py View File

@@ -1,11 +1,14 @@
1
+from django import forms
2
+from django.contrib.auth.mixins import LoginRequiredMixin
1 3
 from django.contrib.auth.models import User
2 4
 from django.shortcuts import render, render_to_response
5
+from django.urls import reverse, reverse_lazy
3 6
 from django.views import generic
4 7
 from django.views.generic.edit import CreateView, FormView
5 8
 # Create your views here.
6
-from accounts.forms import LoginForm
7
-from accounts.models import Accounts, Players
8
-from accounts.utils import LoginHelper
9
+from accounts.forms import CreateCharacterForm
10
+from accounts.models import Accounts, Players, Towns
11
+from accounts.utils import LoginHelper, VocationHelper
9 12
 
10 13
 
11 14
 class RegisterAccountView(CreateView):
@@ -36,4 +39,53 @@ class IndexView(generic.ListView):
36 39
     context_object_name = 'best_players'
37 40
 
38 41
     def get_queryset(self):
39
-        return Players.objects.filter(group_id=1).order_by('-level').values('name', 'level')[:10]
42
+        return Players.objects.filter(group_id=1).order_by('-level').values('name', 'level')[:10]
43
+
44
+class PlayerView(LoginRequiredMixin, generic.ListView):
45
+    template_name = 'players.html'
46
+    context_object_name = 'players'
47
+
48
+    def get_queryset(self):
49
+        players = Players.objects.filter(account__linked_django_user=self.request.user)\
50
+            .values('name', 'level', 'vocation')
51
+        return players
52
+
53
+    def get_context_data(self, **kwargs):
54
+        context = super(PlayerView, self).get_context_data(**kwargs)
55
+        players = context['players']
56
+        context['players'] = [{
57
+            'name': p['name'],
58
+            'level': p['level'],
59
+            'vocation': VocationHelper.vocation_to_string(p['vocation'])}
60
+            for p in players]
61
+        return context
62
+
63
+class CreateCharView(LoginRequiredMixin, FormView):
64
+    form_class = CreateCharacterForm
65
+    template_name = 'add_character.html'
66
+    success_url = reverse_lazy('accounts:characters')
67
+
68
+    def form_valid(self, form):
69
+        rookgaard = Towns.objects.get(name='Rookgaard')
70
+        start_health = 150
71
+        start_mana = 55
72
+        start_cap = 400
73
+        user = self.request.user
74
+        account = Accounts.objects.get(linked_django_user=user)
75
+        player = Players.objects.create(
76
+            name=form.cleaned_data['name'],
77
+            level=1,
78
+            vocation=int(form.cleaned_data['vocation']),
79
+            sex=int(form.cleaned_data['sex']),
80
+            posx=rookgaard.posx,
81
+            posy=rookgaard.posy,
82
+            posz=rookgaard.posz,
83
+            health=start_health,
84
+            healthmax=start_health,
85
+            mana=start_mana,
86
+            manamax=start_mana,
87
+            cap=start_cap,
88
+            account_id=account.id,
89
+        )
90
+        return super(CreateCharView, self).form_valid(form)
91
+

Loading…
Cancel
Save