Create death events function.

This commit is contained in:
luxick
2018-03-14 14:47:04 +01:00
parent ac01a4441b
commit 48ed0d830f
7 changed files with 38 additions and 7 deletions

View File

@@ -6,6 +6,8 @@ from sql import Episode
query = Episode.select().where(Episode.name == 'MyName')
"""
import sys
import datetime
try:
from peewee import *
except ImportError:
@@ -70,6 +72,7 @@ class Enemy(Model):
class Death(Model):
id = AutoField()
info = CharField(null=True)
time = TimeField(default=datetime.time(0, 0))
player = ForeignKeyField(Player)
enemy = ForeignKeyField(Enemy)
episode = ForeignKeyField(Episode, backref='deaths')

View File

@@ -32,6 +32,16 @@ class WriteFunctions:
sql.Drink.vol: drink.vol})
.execute())
@staticmethod
def save_death(death: 'models.Death'):
with sql.db.atomic():
created_id = (sql.Death
.insert(info=death.info, player=death.player, enemy=death.enemy, episode=death.episode,
time=death.time)
.execute())
for penalty in death.penalties:
sql.Penalty.create(death=created_id, size=penalty.size, drink=penalty.drink, player=penalty.player)
@staticmethod
def update_season(season: 'models.Season', *_):
(sql.Season