def treasure_check(room, player, db, db_id): print(f"Examining room for treasure and picking it up if I can") if len(room['items']) > 0: # get the latest player status status = get_status() print(f"Player status: {status}") time.sleep(status['cooldown']) player.update_player(status) # see if player have enough capacity to pick it up player_capacity = player['strength'] - \ player['encumbrance'] if player_capacity > 1: for item in room['items']: if item != 'tiny treasure' and item != 'small treasure' and item != 'shiny treasure' and item != 'great treasure': if player_capacity >= 3: # pick it up res = player.take_item(item) print(f'*** Picked up an item: {res} ***') # wait for cooldown before moving on time.sleep(res['cooldown']) # get the latest player status status = get_status() print(f"Player status: {status}") time.sleep(status['cooldown']) player.update_player(status) # see if player have enough capacity to pick it up player_capacity = player['strength'] - \ player['encumbrance'] else: print( f"There was an item '{item}', which I could not pick up") # if the player is carrying over 80% of his strength, go to Shop if player['encumbrance'] >= 0.8*player['strength']: # traverse there shortest_path = find_nearest_shop(room, db, db_id) traverse_path(shortest_path, player, db, db_id) # get shop room shop_room = db.get_room_by_id(1) # sell items shop_check(shop_room, player, db, db_id) # get path back => reversed shortest_path shortest_path.reverse() # traverse back to current room traverse_path(shortest_path, player, db, db_id) else: print('Nothing to pick up here')
def enqueue(request, username, tracks, atTop): logger.debug("enqueue: %s", tracks) for t in tracks: q = QueueItem(who = username, what = MusicFile.objects.get(url=t['url'])) cached(q.what) try: if atTop: items = QueueItem.objects.all().order_by("index") if len(items)> 1: q.index = (items[0].index+items[1].index)/2 else: q.index = items[0].index + 1 # only current item in queue else: q.index = QueueItem.objects.order_by("-index")[0].index + 1 # only current item in queue except IndexError: # nothing else in queue q.index = 0 q.save() # Newly queued items get automagically played if the player is idle. This is only needed if they're already cached if is_cached(QueueItem.current().what) and get_status() == Status.idle: play_current(player) return status_info(request)
def now_playing(self): obj = {'player_status': player.get_status()} if player.now_playing: obj['media'] = player.now_playing.dictify() return obj
def player_status(): return jsonify(player.get_status())
def player_check(): res = get_status() return f"{res}"
import os from flask import Flask, Response, request from flask_cors import CORS from threading import Thread from mongo import Database from player import Player, get_status from settings import DB, DB_NAME, PROD_DB from algo import explore, traverse_player_to_target app = Flask(__name__) CORS(app) p = Player(get_status()) db = Database(DB, DB_NAME) db_id = db.get_id() atlas_db = Database(PROD_DB, DB_NAME) atlas_id = atlas_db.get_id() # MANUAL COMMANDS. ONLY RUN ONE AT A TIME # print(p.dash('w', '7', '327,256,243,178,90,86,80')) # print(f"{p.move('w')}") # print(f"{p.wise_explore('s', 22)}") # print(p.sell_item('nice jacket')) # print(p.examine_item('amazing treasure')) # print(p.examine_player('shiny treasure')) # print(f"{p.take_item('shiny treasure')}") # print(f"{p.drop_item('small treasure')}") # print(p.pray()) # print(p.fly('s'))