def _sync_consumable(self, counter, used): """Syncs a consumable's uses with dicecloud.""" def update_callback(error, data): if error: log.warning(error) if error.get('error') == 403: # character no longer shared self.character[ 'live'] = False # this'll be committed since we're modifying something to sync self.live = False else: log.debug(data) try: if counter['live'] in CLASS_RESOURCES: DicecloudClient.getInstance().meteor_client.update( 'characters', {'_id': self.id[10:]}, {'$set': { f"{counter['live']}.adjustment": -used }}, callback=update_callback) else: DicecloudClient.getInstance().meteor_client.update( 'features', {'_id': counter['live']}, {'$set': { "used": used }}, callback=update_callback) except MeteorClient.MeteorClientException: pass
def sync_slots(self): spell_dict = {} for lvl in range(1, 10): spell_dict[f'level{lvl}SpellSlots.adjustment'] = \ self.character.spellbook.get_slots(lvl) - self.character.spellbook.get_max_slots(lvl) try: DicecloudClient.getInstance().meteor_client.update( 'characters', {'_id': self.character.upstream[10:]}, {'$set': spell_dict}, callback=update_callback) except MeteorClient.MeteorClientException: pass
def sync_hp(self): try: DicecloudClient.getInstance().meteor_client.update( 'characters', {'_id': self.character.upstream[10:]}, { '$set': { "hitPoints.adjustment": self.character.hp - self.character.max_hp } }, callback=update_callback) except MeteorClient.MeteorClientException: pass
async def _do_sync_death_saves(self): try: DicecloudClient.getInstance().meteor_client.update( 'characters', {'_id': self.character.upstream_id}, { '$set': { "deathSave.pass": self.character.death_saves.successes, "deathSave.fail": self.character.death_saves.fails } }, callback=update_callback) except MeteorClient.MeteorClientException: pass
def sync_consumable(self, consumable): used = consumable.get_max() - consumable.value try: if consumable.live_id in CLASS_RESOURCES: DicecloudClient.getInstance().meteor_client.update( 'characters', {'_id': self.character.upstream[10:]}, {'$set': { f"{consumable.live_id}.adjustment": -used }}, callback=update_callback) else: DicecloudClient.getInstance().meteor_client.update( 'features', {'_id': consumable.live_id}, {'$set': { "used": used }}, callback=update_callback) except MeteorClient.MeteorClientException: pass
def _sync_slots(self): def update_callback(error, data): if error: log.warning(error) if error.get('error') == 403: # character no longer shared self.character['live'] = False self.live = False else: log.debug(data) spell_dict = {} for lvl in range(1, 10): spell_dict[f'level{lvl}SpellSlots.adjustment'] = self.get_remaining_slots(lvl) - self.get_max_spellslots( lvl) try: DicecloudClient.getInstance().meteor_client.update('characters', {'_id': self.id[10:]}, {'$set': spell_dict}, callback=update_callback) except MeteorClient.MeteorClientException: pass
def _sync_hp(self): def update_callback(error, data): if error: log.warning(error) if error.get('error') == 403: # character no longer shared self.character['live'] = False self.live = False else: log.debug(data) try: DicecloudClient.getInstance().meteor_client.update('characters', {'_id': self.id[10:]}, {'$set': { "hitPoints.adjustment": (self.get_current_hp() - self.get_max_hp()) - self.get_temp_hp()} }, callback=update_callback) except MeteorClient.MeteorClientException: pass
def is_live(self): dicecloud_client = DicecloudClient.getInstance() if dicecloud_client.user_id in self.character_data['characters'][0]['writers'] \ or dicecloud_client.user_id == self.character_data['characters'][0]['owner']: return 'dicecloud' return None