예제 #1
0
class Scores(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(25), unique=True)
    user_id = db.Column(db.Integer, unique=True)
    score_all = db.Column(db.Integer)
    score_game = db.Column(db.Integer)
    score_week = db.Column(db.Integer)
    created_at = db.Column(db.Date())
    updated_at = db.Column(db.Date())

    def __init__(
            self, username, user_id
    ):  #Wird nur einemal ausgefuehrt, wenn Spieler registriert wird
        self.username = username
        self.user_id = user_id
        self.score_all = 0
        self.score_game = 0
        self.score_week = 0
        self.created_at = datetime.now()
        self.updated_at = datetime.now()

    def init_score_game(self):  #Zum reseten des currentGame Scores
        self.score_game = 0

    def init_score_week(self):  #Zum resetten der temporaeren Scores
        self.score_week = 0

    def update(self, score):
        self.score_all += score
        self.score_game += score
        self.score_week += score
        self.updated_at = datetime.now()

    def __repr__(self):
        '<Score %r>' % (self.username)
예제 #2
0
class ScheduleSpMotw(db.Model):
    week_id = db.Column(db.Integer, primary_key=True, unique=True)
    object_type = db.Column(
        db.String(25))  # save as string for better reproducability
    time_start = db.Column(db.Date())
    time_end = db.Column(db.Date())
    area = db.Column(
        db.String(25))  # store as string => world/<country>/<region>

    def __init__(self, object_type, time_start, time_end, area):
        self.object_type = object_type
        self.time_start = time_start
        self.time_end = time_end
        self.area = area

    def __repr__(self):
        '<Schedule MOTW %r>' % (self.time_start)
예제 #3
0
class Game(db.Model):
    id = db.Column(db.Integer, primary_key=True, unique=True)
    player_id = db.Column(db.Integer)
    region = db.Column(db.String(25))
    game_type = db.Column(db.Integer)  #1=Singleplayer/2=Multiplayer
    game_mode = db.Column(db.String(25))  #FFA/MapperOfTheWeek/...
    object_restaurant = db.Column(db.Boolean)
    object_bar = db.Column(db.Boolean)
    object_bank = db.Column(db.Boolean)
    radius = db.Column(db.Integer)
    session_start = db.Column(db.Date())
    session_end = db.Column(db.Date())
    session_status = db.Column(db.String(20))
    is_active = db.Column(db.Boolean)
    gamempffa_id = db.Column(db.Integer, db.ForeignKey('game_mp_ffa.id'))
    gamempffa = db.relationship('Game_mp_ffa',
                                backref=db.backref('games', lazy='dynamic'))

    def __init__(self, player_id, region, game_type, game_mode):
        self.player_id = player_id
        self.region = region
        self.game_type = game_type
        self.game_mode = game_mode
        self.session_start = datetime.now()
        self.session_status = 'started'
        self.is_active = True

    def set_objecttypes(self, restaurant, bar, bank):
        self.object_restaurant = restaurant
        self.object_bar = bar
        self.object_bank = bank

    def set_radius(self, radius):
        self.radius = radius

    def close_game(self):
        self.session_status = 'game closed'
        self.is_active = False

    def __repr__(self):
        '<Game %r>' % (self.player_id)
예제 #4
0
class History(db.Model):
    id = db.Column(db.Integer, primary_key=True, unique=True)
    game_id = db.Column(db.Integer, db.ForeignKey('game.id'))
    player_id = db.Column(db.Integer)
    score = db.Column(db.Integer)
    event_type = db.Column(db.String(15))  # badge, osm, social
    timestamp = db.Column(db.Date())

    def __init__(self, game_id, player_id, event_type):
        self.score = 1  # set dynamically
        self.game_id = game_id
        self.player_id = player_id
        self.event_type = event_type
        self.timestamp = datetime.now()
예제 #5
0
class Player(db.Model):
    id = db.Column(db.Integer, primary_key=True, unique=True)
    username = db.Column(db.String(25), unique=True)
    email = db.Column(db.String(120), unique=True)
    description = db.Column(db.String(250))
    pw_hash = db.Column(db.String(160))
    created_at = db.Column(db.Date())
    last_login = db.Column(db.Date())
    lang_short = db.Column(db.String(10))
    avatar = db.Column(db.String(30))
    color = db.Column(db.String(10))
    home_region = db.Column(db.String(80))
    #actual_region = db.Column(db.String(80))
    is_ready = db.Column(db.Boolean)
    lat = db.Column(db.Float)
    lng = db.Column(db.Float)
    country = db.Column(db.String(80))
    osm_login = db.Column(db.String(50), unique=True)
    osm_hash = db.Column(db.String(160))
    latlng = db.Column(db.String(36), unique=False)  #aktuelle koordinaten
    game_id = db.Column(db.Integer, db.ForeignKey('game.id'))
    game = db.relationship('Game',
                           backref=db.backref('players', lazy='dynamic'))
    score_id = db.Column(db.Integer, db.ForeignKey('scores.id'))
    score = db.relationship('Scores',
                            backref=db.backref('players', lazy='dynamic'))
    theme = db.Column(db.String(15))
    team_id = db.Column(db.Integer, db.ForeignKey('team.id'))
    team = db.relationship('Team',
                           backref=db.backref('players', lazy='dynamic'))

    def __init__(self, username, email, password):
        self.username = username
        self.email = email
        self.pw_hash = self.get_hash(password)
        self.created_at = datetime.now()
        self.last_login = datetime.now()
        self.score = Scores(self.username, self.id)
        self.is_ready = False

    def get_hash(self, password):
        return generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.pw_hash, password)

    def set_avatar(self, avatar='default'):
        self.avatar = avatar

    def set_description(self, description):
        self.description = description

    def set_color(self, color):
        self.color = color

    def set_position(self, lat, lng):
        self.lat = lat
        self.lng = lng

    def set_actual_region(self, actual_region):
        self.actual_region = actual_region

    def set_home_region(self, home_region):
        self.home_region = home_region

    def get_country(self, region):
        self.country = Regions.query.filter_by(regionname=region).first()

    def connect_osm(self, login, password):
        self.osm_login = login
        self.osm_hash = hash_password(password)

    def set_language(self, lang_short):
        self.lang_short = lang_short

    def set_username(self, username):
        self.username = username

    def set_email(self, email):
        self.email = email

    def set_last_login(self):
        self.last_login = datetime.now()

    def set_ready(self):
        self.is_ready = True

    def __repr__(self):
        '<Player %r>' % (self.username)