Toy book handlers

Experimental: players who open newspapers will persist after changing rooms.
This commit is contained in:
Ben 2019-08-19 02:28:42 +01:00
parent a6e1d05a52
commit 337c2048cd
4 changed files with 34 additions and 1 deletions

View File

@ -38,6 +38,8 @@ class Room(db.Model):
self.penguins.remove(p) self.penguins.remove(p)
p.room = None p.room = None
p.frame = 1
p.toy = None
async def get_string(self): async def get_string(self):
return '%'.join([await p.string for p in self.penguins]) return '%'.join([await p.string for p in self.penguins])

View File

@ -102,6 +102,7 @@ async def handle_pbsm_finish(p):
async def handle_set_player_position(p, x: int, y: int): async def handle_set_player_position(p, x: int, y: int):
p.x, p.y = x, y p.x, p.y = x, y
p.frame = 1 p.frame = 1
p.toy = None
await p.room.send_xt('sp', p.data.id, x, y) await p.room.send_xt('sp', p.data.id, x, y)

View File

@ -0,0 +1,29 @@
from houdini import handlers, ClientType
from houdini.handlers import XTPacket
@handlers.handler(XTPacket('t', 'at'))
async def handle_open_book(p, toy_id: int):
p.toy = toy_id
await p.room.send_xt('at', p.data.id, toy_id)
@handlers.handler(XTPacket('t', 'rt'))
async def handle_close_book(p):
p.toy = None
await p.room.send_xt('rt', p.data.id)
@handlers.handler(XTPacket('j', 'jr'), client=ClientType.Legacy)
async def handle_join_room_toy(p):
for penguin in p.room.penguins:
if penguin.toy is not None:
await p.send_xt('at', penguin.data.id, penguin.toy)
@handlers.handler(XTPacket('j', 'crl'), client=ClientType.Vanilla)
@handlers.depends_on_packet(XTPacket('j', 'jr'))
async def handle_client_room_loaded_toy(p):
for penguin in p.room.penguins:
if penguin.toy is not None:
await p.send_xt('at', penguin.data.id, penguin.toy)

View File

@ -5,7 +5,7 @@ from houdini.spheniscidae import Spheniscidae
class Penguin(Spheniscidae): class Penguin(Spheniscidae):
__slots__ = ['x', 'y', 'frame', 'room', 'waddle', 'table', 'data', 'muted', __slots__ = ['x', 'y', 'frame', 'toy', 'room', 'waddle', 'table',
'login_key', 'member', 'membership_days', 'avatar', 'login_key', 'member', 'membership_days', 'avatar',
'walking_puffle', 'permissions', 'active_quests'] 'walking_puffle', 'permissions', 'active_quests']
@ -14,6 +14,7 @@ class Penguin(Spheniscidae):
self.x, self.y = (0, 0) self.x, self.y = (0, 0)
self.frame = 1 self.frame = 1
self.toy = None
self.room = None self.room = None
self.waddle = None self.waddle = None
self.table = None self.table = None