Automatic party handlers

This commit is contained in:
Ben 2019-06-21 23:11:00 +01:00
parent 114a110d39
commit 5f20d30ada

View File

@ -0,0 +1,66 @@
from houdini import handlers
from houdini.handlers import XTPacket
import ujson
DefaultPartyCookie = {
'msgViewedArray': [0] * 10,
'communicatorMsgArray': [0] * 5,
'questTaskStatus': [0] * 10
}
@handlers.handler(XTPacket('party', 'partycookie'))
@handlers.allow_once
async def handle_party_cookie(p):
cookie = await p.server.redis.hget('partycookie', p.data.id)
if cookie is None:
cookie = ujson.dumps(DefaultPartyCookie)
await p.server.redis.hset('partycookie', p.data.id, cookie)
else:
cookie = cookie.decode('utf-8')
await p.send_xt('partycookie', cookie)
@handlers.handler(XTPacket('party', 'msgviewed'))
@handlers.depends_on_packet(XTPacket('party', 'partycookie'))
async def handle_party_message_viewed(p, message_index: int):
cookie = await p.server.redis.hget('partycookie', p.data.id)
cookie = ujson.loads(cookie)
cookie['msgViewedArray'][message_index] = 1
await p.server.redis.hset('partycookie', p.data.id, ujson.dumps(cookie))
@handlers.handler(XTPacket('party', 'qcmsgviewed'))
@handlers.depends_on_packet(XTPacket('party', 'partycookie'))
async def handle_party_communicator_message_viewed(p, message_index: int):
cookie = await p.server.redis.hget('partycookie', p.data.id)
cookie = ujson.loads(cookie)
cookie['communicatorMsgArray'][message_index] = 1
await p.server.redis.hset('partycookie', p.data.id, ujson.dumps(cookie))
@handlers.handler(XTPacket('party', 'qtaskcomplete'))
@handlers.depends_on_packet(XTPacket('party', 'partycookie'))
async def handle_party_task_complete(p, task_index: int):
cookie = await p.server.redis.hget('partycookie', p.data.id)
cookie = ujson.loads(cookie)
cookie['questTaskStatus'][task_index] = 1
await p.server.redis.hset('partycookie', p.data.id, ujson.dumps(cookie))
@handlers.handler(XTPacket('party', 'qtupdate'))
@handlers.depends_on_packet(XTPacket('party', 'partycookie'))
@handlers.cooldown(5)
async def handle_party_task_update(p, coins: int):
coins = min(coins, 10)
await p.data.update(coins=p.data.coins + coins).apply()
await p.send_xt('qtupdate', p.data.coins)