Minigame save state handlers

This commit is contained in:
Ben 2019-12-04 01:31:55 +00:00
parent 23a8147762
commit 27cdb1e569
3 changed files with 39 additions and 11 deletions

View File

@ -99,17 +99,6 @@ class PenguinPuffleItem(db.Model):
quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("1"))
class PenguinLaunchGame(db.Model):
__tablename__ = 'penguin_launch_game'
penguin_id = db.Column(db.ForeignKey('penguin.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True,
nullable=False)
level = db.Column(db.SmallInteger, primary_key=True, nullable=False, server_default=db.text("0"))
puffle_os = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))
best_time = db.Column(db.SmallInteger, nullable=False, server_default=db.text("600"))
turbo = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
class PuffleCollection(AbstractDataCollection):
__model__ = Puffle
__indexby__ = 'id'

View File

@ -1,8 +1,13 @@
from houdini import handlers
from houdini.handlers import XTPacket
from houdini.converters import OptionalConverter
from houdini.constants import ClientType
from houdini.handlers.play.navigation import handle_join_room
from houdini.handlers.play.moderation import cheat_ban
from houdini.data.room import Room
from houdini.data.game import PenguinGameData
from sqlalchemy.dialects.postgresql import insert
import time
@ -91,3 +96,27 @@ async def handle_get_game_over(p, score: int):
total_collected_stamps,
total_game_stamps,
total_stamps)
@handlers.handler(XTPacket('ggd', ext='z'), client=ClientType.Vanilla)
async def handle_get_game_data(p, index: int = None):
game_data = await PenguinGameData.select('data').where((PenguinGameData.penguin_id == p.id) &
(PenguinGameData.room_id == p.room.id) &
(PenguinGameData.index == index)).gino.scalar()
await p.send_xt('ggd', game_data or '')
@handlers.handler(XTPacket('sgd', ext='z'), client=ClientType.Vanilla)
@handlers.cooldown(5)
async def handle_set_game_data(p, index: OptionalConverter(int) = None, *, game_data: str):
if p.room.game:
data_insert = insert(PenguinGameData).values(penguin_id=p.id, room_id=p.room.id, index=index, data=game_data)
data_insert = data_insert.on_conflict_do_update(
constraint='penguin_game_data_pkey',
set_=dict(data=game_data),
where=((PenguinGameData.penguin_id == p.id)
& (PenguinGameData.room_id == p.room.id)
& (PenguinGameData.index == index))
)
await data_insert.gino.scalar()

View File

@ -16,6 +16,7 @@ from houdini.data.igloo import IglooFurniture, IglooLike, Igloo, Furniture, Floo
PenguinIglooCollection, PenguinFurnitureCollection, \
PenguinFlooringCollection, PenguinLocationCollection
from houdini.data.room import PenguinIglooRoomCollection
from houdini.data.game import PenguinGameData
from sqlalchemy.dialects.postgresql import insert
@ -521,3 +522,12 @@ async def handle_get_furniture_inventory(p):
locations = ','.join(f'{location_id}|0000000000' for location_id in p.locations.keys())
await p.send_xt('gii', furniture, flooring, igloos, locations)
@handlers.handler(XTPacket('g', 'ggd'), client=ClientType.Vanilla)
async def handle_get_dj3k_track(p, penguin_id: int, game_index: str):
room_id, index = game_index.split('|')
game_data = await PenguinGameData.select('data').where((PenguinGameData.penguin_id == penguin_id) &
(PenguinGameData.room_id == int(room_id)) &
(PenguinGameData.index == int(index))).gino.scalar()
await p.send_xt('ggd', game_data or '')