async def update_initiative_turn(sid, data): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] location = sid_data["location"] if room.creator != user: logger.warning( f"{user.name} attempted to advance the initiative tracker") return location_data = InitiativeLocationData.get(location=location) with db.atomic(): location_data.turn = data location_data.save() effects = (InitiativeEffect.select().join(Initiative).where( Initiative.uuid == data)) for effect in effects: if effect.turns <= 0: effect.delete_instance() else: effect.turns -= 1 effect.save() await sio.emit( "Initiative.Turn.Update", data, room=location.get_path(), skip_sid=sid, namespace="/planarally", )
async def update_initiative_turn(sid: int, data: Dict[str, Any]): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning( f"{pr.player.name} attempted to advance the initiative tracker") return location_data = InitiativeLocationData.get(location=pr.active_location) with db.atomic(): location_data.turn = data location_data.save() effects = (InitiativeEffect.select().join(Initiative).where( Initiative.uuid == data)) for effect in effects: if effect.turns <= 0: effect.delete_instance() else: effect.turns -= 1 effect.save() await sio.emit( "Initiative.Turn.Update", data, room=pr.active_location.get_path(), skip_sid=sid, namespace=GAME_NS, )
async def update_initiative_turn(sid: str, data: str): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning( f"{pr.player.name} attempted to advance the initiative tracker") return location_data = InitiativeLocationData.get(location=pr.active_location) with db.atomic(): location_data.turn = data location_data.save() effects = (InitiativeEffect.select().join(Initiative).where( Initiative.uuid == data)) for effect in effects: try: turns = int(effect.turns) if turns <= 0: effect.delete_instance() else: effect.turns = str(turns - 1) except ValueError: # For non-number inputs do not update the effect pass effect.save() await sio.emit( "Initiative.Turn.Update", data, room=pr.active_location.get_path(), skip_sid=sid, namespace=GAME_NS, )