From 4f57df545f0a5996b5567abcc2ba0aa21bfc346a Mon Sep 17 00:00:00 2001 From: EmperorBale Date: Wed, 20 Jan 2021 23:58:37 -0700 Subject: [PATCH] Implement CJSnow handlers --- houdini.sql | 5 +++++ houdini/data/penguin.py | 3 +++ houdini/handlers/games/__init__.py | 4 ++++ houdini/handlers/games/ninja/snow.py | 17 +++++++++++++++++ houdini/handlers/play/ninja.py | 22 +++++++++++----------- houdini/handlers/play/room.py | 8 ++++++++ 6 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 houdini/handlers/games/ninja/snow.py diff --git a/houdini.sql b/houdini.sql index 68dbf18..918ee02 100644 --- a/houdini.sql +++ b/houdini.sql @@ -562,9 +562,14 @@ CREATE TABLE penguin ( fire_ninja_progress SMALLINT NOT NULL DEFAULT 0, water_ninja_rank SMALLINT NOT NULL DEFAULT 0, water_ninja_progress SMALLINT NOT NULL DEFAULT 0, + snow_ninja_rank SMALLINT NOT NULL DEFAULT 0, + snow_ninja_progress SMALLINT NOT NULL DEFAULT 0, ninja_matches_won INT NOT NULL DEFAULT 0, fire_matches_won INT NOT NULL DEFAULT 0, water_matches_won INT NOT NULL DEFAULT 0, + snow_progress_fire_wins INT NOT NULL DEFAULT 0, + snow_progress_water_wins INT NOT NULL DEFAULT 0, + snow_progress_snow_wins INT NOT NULL DEFAULT 0, rainbow_adoptability BOOLEAN NOT NULL DEFAULT FALSE, has_dug BOOLEAN NOT NULL DEFAULT FALSE, puffle_handler BOOLEAN NOT NULL DEFAULT FALSE, diff --git a/houdini/data/penguin.py b/houdini/data/penguin.py index 1765d3b..11e3df2 100644 --- a/houdini/data/penguin.py +++ b/houdini/data/penguin.py @@ -49,6 +49,8 @@ class Penguin(db.Model): fire_ninja_progress = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) water_ninja_rank = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) water_ninja_progress = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + snow_ninja_progress = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + snow_ninja_rank = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) ninja_matches_won = db.Column(db.Integer, nullable=False, server_default=db.text("0")) fire_matches_won = db.Column(db.Integer, nullable=False, server_default=db.text("0")) water_matches_won = db.Column(db.Integer, nullable=False, server_default=db.text("0")) @@ -80,6 +82,7 @@ class Penguin(db.Model): rejection_es = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) rejection_de = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) rejection_ru = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) + def __init__(self, *args, **kwargs): self.inventory = None diff --git a/houdini/handlers/games/__init__.py b/houdini/handlers/games/__init__.py index a4140f9..4b03d9b 100644 --- a/houdini/handlers/games/__init__.py +++ b/houdini/handlers/games/__init__.py @@ -72,6 +72,10 @@ async def handle_get_puck(p): @handlers.handler(XTPacket('zo', ext='z')) @handlers.cooldown(10, callback=game_over_cooling) async def handle_get_game_over(p, score: int): + # If the room is Card Jitsu Snow, it this should do nothing + if p.room.id == 996: + return + if p.room.game and not p.waddle and not p.table: coins_earned = determine_coins_earned(p, score) if await determine_coins_overdose(p, coins_earned): diff --git a/houdini/handlers/games/ninja/snow.py b/houdini/handlers/games/ninja/snow.py new file mode 100644 index 0000000..7d1efc2 --- /dev/null +++ b/houdini/handlers/games/ninja/snow.py @@ -0,0 +1,17 @@ +from houdini.handlers import XTPacket +from houdini import handlers +from houdini.data.item import PenguinItemCollection +from houdini.data.stamp import PenguinStampCollection +from houdini.handlers.play.stampbook import get_player_stamps_string + +@handlers.handler(XTPacket('i#ngi')) +@handlers.cooldown(5) +async def ninja_get_inventory(self, p): + p.inventory = await PenguinItemCollection.get_collection(p.id) + await p.send_xt('gi', *p.inventory.keys()) + +@handlers.handler(XTPacket('st#ngps')) +@handlers.cooldown(5) +async def ninja_get_penguin_stamps(self, p): + p.stamps = await PenguinStampCollection.get_collection(p.id) + await p.send_xt('gps', p.id, await get_player_stamps_string(p, p.id)) \ No newline at end of file diff --git a/houdini/handlers/play/ninja.py b/houdini/handlers/play/ninja.py index 2fddc71..8b7473e 100644 --- a/houdini/handlers/play/ninja.py +++ b/houdini/handlers/play/ninja.py @@ -4,17 +4,12 @@ from houdini.data.penguin import Penguin @handlers.handler(XTPacket('ni', 'gnr')) +@handlers.cooldown(2) async def handle_get_ninja_ranks(p, penguin_id: int): - if penguin_id in p.server.penguins_by_id: - penguin = p.server.penguins_by_id[penguin_id] - ninja_rank, fire_ninja_rank, water_ninja_rank = \ - penguin.ninja_rank, penguin.fire_ninja_rank, penguin.water_ninja_rank - else: - ninja_rank, fire_ninja_rank, water_ninja_rank = await Penguin.select( - 'ninja_rank', 'fire_ninja_rank', 'water_ninja_rank' - ).where(Penguin.id == penguin_id).gino.first() - await p.send_xt('gnr', p.id, ninja_rank, fire_ninja_rank, water_ninja_rank, 0) - + ninja_rank, fire_ninja_rank, water_ninja_rank, snow_ninja_rank = await Penguin.select( + 'ninja_rank', 'fire_ninja_rank', 'water_ninja_rank', 'snow_ninja_rank' + ).where(Penguin.id == penguin_id).gino.first() + await p.send_xt('gnr', p.id, ninja_rank, fire_ninja_rank, water_ninja_rank, snow_ninja_rank) @handlers.handler(XTPacket('ni', 'gnl')) async def handle_get_ninja_level(p): @@ -32,8 +27,13 @@ async def handle_get_water_level(p): @handlers.handler(XTPacket('ni', 'gsl')) +@handlers.cooldown(1) async def handle_get_snow_level(p): - await p.send_xt('gsl', 0, 0, 24) + # Snow ninja data should be taken from the database, not memory + snow_ninja_rank, snow_ninja_progress = await Penguin.select( + 'snow_ninja_rank', 'snow_ninja_progress' + ).where(Penguin.id == p.id).gino.first() + await p.send_xt('gsl', snow_ninja_rank, snow_ninja_progress, 24) @handlers.handler(XTPacket('ni', 'gcd')) diff --git a/houdini/handlers/play/room.py b/houdini/handlers/play/room.py index 2912eb8..cedc04f 100644 --- a/houdini/handlers/play/room.py +++ b/houdini/handlers/play/room.py @@ -12,3 +12,11 @@ async def handle_get_coin_reward(p): coins = random.choice([1, 2, 5, 10, 20, 50, 100]) await p.update(coins=Penguin.coins + coins).apply() await p.send_xt('cdu', coins, p.coins) + +@handlers.handler(XTPacket('r', 'gtc')) +@handlers.cooldown(1) +async def handle_get_coins(p): + # Fetch coins from the database + p.coins, = await Penguin.select('coins').where(Penguin.id == p.id).gino.first() + await p.send_xt("gtc", p.coins) +