2022-11-24 20:35:08 +00:00
|
|
|
import asyncio
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from pyshock import PiShock
|
|
|
|
from datapuller import (
|
|
|
|
LiveData,
|
|
|
|
MapData,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
2022-11-24 23:07:25 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2022-11-24 20:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Events:
|
|
|
|
combo_A = 100
|
|
|
|
combo_B = 300
|
|
|
|
|
2022-11-24 23:07:25 +00:00
|
|
|
combo_A_break = ['vibrate', 0.5, 20]
|
|
|
|
combo_B_break = ['shock', 0.3, 5]
|
|
|
|
|
|
|
|
fail = ['shock', 1, 10]
|
2022-11-24 20:35:08 +00:00
|
|
|
|
2022-11-24 23:07:25 +00:00
|
|
|
playing = False
|
|
|
|
combo_level = None
|
|
|
|
map_failed = False
|
2022-11-24 20:35:08 +00:00
|
|
|
|
2022-11-24 23:07:25 +00:00
|
|
|
def __init__(self, config, shocker):
|
2022-11-24 20:35:08 +00:00
|
|
|
self.combo_A = config['comboA']
|
|
|
|
self.combo_B = config['comboB']
|
|
|
|
self.combo_A_break = config['comboABreak']
|
|
|
|
self.combo_B_break = config['comboBBreak']
|
|
|
|
self.fail = config['fail']
|
2022-11-24 23:07:25 +00:00
|
|
|
self.shocker = shocker
|
|
|
|
|
|
|
|
def update_combo(self, message):
|
|
|
|
combo = message['Combo']
|
|
|
|
health = message['PlayerHealth']
|
|
|
|
if not self.map_failed and health == 0:
|
|
|
|
logger.info('Failed the map!')
|
|
|
|
self.shocker.act(*self.fail)
|
|
|
|
self.map_failed = True
|
|
|
|
self.combo_level = None
|
|
|
|
if combo > self.combo_A:
|
|
|
|
self.combo_level = 'A'
|
|
|
|
if combo > self.combo_B:
|
|
|
|
self.combo_level = 'B'
|
|
|
|
|
|
|
|
def break_combo(self, message):
|
|
|
|
if self.combo_level == 'A':
|
|
|
|
logger.info('Broke combo A!')
|
|
|
|
self.shocker.act(*self.combo_A_break)
|
|
|
|
if self.combo_level == 'B':
|
|
|
|
logger.info('Broke combo B!')
|
|
|
|
self.shocker.act(*self.combo_B_break)
|
|
|
|
self.combo_level = None
|
|
|
|
|
|
|
|
def tick(self, message):
|
|
|
|
logger.info('Tick')
|
|
|
|
if self.playing and message['TimeElapsed'] == 0:
|
|
|
|
logger.info('Stopping map...')
|
|
|
|
self.map_failed = False
|
|
|
|
self.combo = 0
|
|
|
|
self.playing = False
|
|
|
|
elif not self.playing and message['TimeElapsed'] != 0:
|
|
|
|
logger.info('Starting map...')
|
|
|
|
self.playing = True
|
2022-11-24 20:35:08 +00:00
|
|
|
|
|
|
|
|
2022-11-24 23:07:25 +00:00
|
|
|
async def main(config):
|
|
|
|
logger.info('Initializing...')
|
|
|
|
shocker = PiShock(config['username'], config['apiKey'], config['code'], name='ZapSaber')
|
|
|
|
#shocker.beep()
|
|
|
|
events = Events(config, shocker)
|
2022-11-24 20:35:08 +00:00
|
|
|
|
|
|
|
livedata = LiveData()
|
|
|
|
|
2022-11-24 23:07:25 +00:00
|
|
|
livedata.on('ScoreChange', events.update_combo)
|
|
|
|
livedata.on('NoteMissed', events.break_combo)
|
|
|
|
livedata.on('TimerElapsed', events.tick)
|
2022-11-24 20:35:08 +00:00
|
|
|
|
|
|
|
await livedata.listen()
|
|
|
|
await mapdata.listen()
|
|
|
|
shocker.vibrate()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
with open('config.json') as config_file:
|
|
|
|
config = json.load(config_file)
|
2022-11-24 23:07:25 +00:00
|
|
|
asyncio.run(main(config))
|