示例#1
0
def pumpkin_patch(hour):
    print "\nYou enter the pumpkin patch. The time is %d." % hour
    event = randint(1,6)
    
    if hour == 600 or hour == 1000 or hour == 1400:
        print "It's another pleasant day at the pumpkin patch!"
        if event in range(1,4):
            battle(Enemy(randint(3,4)))
                                    
        elif event == 4:
            print "\nThis is a placeholder! But here, have some money, XP, and Stiff Koushi Fluff."
            taken = randint(0,5) + 5
            print "\nYou found %d Shaymin Dollars!" % taken
            Player.ShayminDollars += taken
            item_add("Stiff Koushi Fluff")
            XP(5)
        hour += 400
        if hour == 2600:
            hour = 200
        return hour
    else:
        print "Night has fallen on the pumpkin patch. The place feels eerie when it's like this..."
        if event == 1:
            print "You have been discovered by a witch! She sends her familiar at you!"
            battle(Enemy(randint(0,2)))
            print "The witch appears surprised that you managed to defeat her familiar. Not like that'll stop her from attacking your directly!"
            battle(Enemy(5))
        if event in range(2,5):
            battle(Enemy(randint(6,7)))
        else:
            print "Gosh, it's so spooky here at night. You decide to leave before something finds you."
        hour += 400
        if hour == 2600:
            hour = 200
        return hour
示例#2
0
	def create(self):
		self.status_icon = gtk.StatusIcon()
		self.spring_logo_pixbuf = gtk.gdk.pixbuf_new_from_file(self.ini.get(self.profile, 'DOCKAPP', None))
		self.status_icon.set_from_file(self.ini.get(self.profile, 'DOCKAPP', None))
		self.status_icon.set_visible(True)


		self.map_index = index_map(self)
		self.map_index.check_if_update_needed()

		# Mod Index
		self.mod_index = index_mod(self)
		self.mod_index.check_if_update_needed()

		# Datadirs
		datadirs = self.unitsync_wrapper.datadirs_list()
		self.datadirs = []
		for i in range(0,len(datadirs)):
			if os.path.isdir(datadirs[i]) == True:
				self.datadirs.append(datadirs[i])

		# Classes
		self.battle = battle(self)
		self.lobby = gui_lobby(self)

		self.battle.IntegrateWithLobby(self)
		self.lobby.IntegrateWithBattle(self)

		self.lobby.Create()


		self.battle.Create()

		self.options = config(self)
		self.options.create()

		self.tooltip('Unity Lobby')
		self.blinking(True)
		self.status_icon.connect('activate', self.active)
		self.status_icon.connect('popup-menu', self.popup_menu)
示例#3
0
    def setup(self, progressbar):

        # Get Datadirs from unitsync
        datadir = self.ini.get(self.profile, "SPRING_DATADIR", None)
        if datadir != None:
            os.chdir(datadir)
        unitsync.Init(True, 1)
        self.datadirs = []
        datadirs = unitsync.GetDataDirectories(False)
        for i in range(0, len(datadirs)):
            if os.path.isdir(datadirs[i]) == True:
                self.datadirs.append(datadirs[i])

                # Map Index
        self.map_index = index_map(self.map_index_file, progressbar)
        if os.path.isfile(self.map_index_file) == False:
            self.map_index.create_index()
        self.map_index.check_if_update_needed()

        # Mod Index
        self.mod_index = index_mod(self.mod_index_file, progressbar)
        if os.path.isfile(self.mod_index_file) == False:
            self.mod_index.create_index()
        self.mod_index.check_if_update_needed()

        self.lobby_table = gtk.Table(rows=2, columns=2, homogeneous=False)
        self.gui_lobby = gui_lobby(self)
        self.config = config(self)
        self.battle = battle(self)

        # Main Window
        self.window.set_title("Unity Lobby")
        self.window.set_resizable(True)
        self.window.connect("delete-event", gtk.main_quit)
        self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # Vertical Box Part 1/2
        vbox = gtk.VBox(False, 0)
        vbox.show()
        self.window.add(vbox)

        # Menu Part 1/2
        menu_bar = gtk.MenuBar()
        menu_bar.show()

        # Battle Notebook
        self.battle_notebook = gtk.Notebook()
        self.battle_notebook.set_tab_pos(gtk.POS_LEFT)
        self.battle.create(self.battle_notebook)

        # Options Notebook
        self.options_notebook = gtk.Notebook()
        self.options_notebook.set_tab_pos(gtk.POS_LEFT)
        self.config.create(self.options_notebook)

        # Vertical Box Part 2/2
        vbox.pack_start(menu_bar, False, False, 2)
        vbox.pack_start(self.battle_notebook, True, True, 2)
        vbox.pack_start(self.options_notebook, True, True, 2)
        vbox.pack_start(self.lobby_table, True, True, 2)

        self.window.show()

        # Menu Part 2/2
        # Menu Items
        battle_item = gtk.MenuItem("Battle")
        lobby_item = gtk.MenuItem("Lobby")
        config_item = gtk.MenuItem("Options")
        self.start_item = gtk.MenuItem("Start")
        menu_bar.append(battle_item)
        menu_bar.append(lobby_item)
        menu_bar.append(config_item)
        menu_bar.append(self.start_item)

        battle_item.show()
        lobby_item.show()
        self.start_item.set_right_justified(1)
        config_item.show()

        # Menu-Connect
        battle_item.connect("button_press_event", self.battle_section)
        config_item.connect("button_press_event", self.config_section)
        self.start_item.connect("button_press_event", self.battle.script_create)
        lobby_item.connect("button_press_event", self.lobby_section)

        # Main Window destory event
        self.window.connect("delete-event", self.destroy)

        self.battle_section(None, None)
示例#4
0
    def setup(self, progressbar):

        # Get Datadirs from unitsync
        datadir = self.ini.get(self.profile, 'SPRING_DATADIR', None)
        if datadir != None:
            os.chdir(datadir)
        unitsync.Init(True, 1)
        self.datadirs = []
        datadirs = unitsync.GetDataDirectories(False)
        for i in range(0, len(datadirs)):
            if os.path.isdir(datadirs[i]) == True:
                self.datadirs.append(datadirs[i])

        # Map Index
        self.map_index = index_map(self.map_index_file, progressbar)
        if os.path.isfile(self.map_index_file) == False:
            self.map_index.create_index()
        self.map_index.check_if_update_needed()

        # Mod Index
        self.mod_index = index_mod(self.mod_index_file, progressbar)
        if os.path.isfile(self.mod_index_file) == False:
            self.mod_index.create_index()
        self.mod_index.check_if_update_needed()

        self.lobby_table = gtk.Table(rows=2, columns=2, homogeneous=False)
        self.gui_lobby = gui_lobby(self)
        self.config = config(self)
        self.battle = battle(self)

        # Main Window
        self.window.set_title("Unity Lobby")
        self.window.set_resizable(True)
        self.window.connect("delete-event", gtk.main_quit)
        self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)

        # Vertical Box Part 1/2
        vbox = gtk.VBox(False, 0)
        vbox.show()
        self.window.add(vbox)

        # Menu Part 1/2
        menu_bar = gtk.MenuBar()
        menu_bar.show()

        # Battle Notebook
        self.battle_notebook = gtk.Notebook()
        self.battle_notebook.set_tab_pos(gtk.POS_LEFT)
        self.battle.create(self.battle_notebook)

        # Options Notebook
        self.options_notebook = gtk.Notebook()
        self.options_notebook.set_tab_pos(gtk.POS_LEFT)
        self.config.create(self.options_notebook)

        #Vertical Box Part 2/2
        vbox.pack_start(menu_bar, False, False, 2)
        vbox.pack_start(self.battle_notebook, True, True, 2)
        vbox.pack_start(self.options_notebook, True, True, 2)
        vbox.pack_start(self.lobby_table, True, True, 2)

        self.window.show()

        # Menu Part 2/2
        #Menu Items
        battle_item = gtk.MenuItem("Battle")
        lobby_item = gtk.MenuItem("Lobby")
        config_item = gtk.MenuItem("Options")
        self.start_item = gtk.MenuItem("Start")
        menu_bar.append(battle_item)
        menu_bar.append(lobby_item)
        menu_bar.append(config_item)
        menu_bar.append(self.start_item)

        battle_item.show()
        lobby_item.show()
        self.start_item.set_right_justified(1)
        config_item.show()

        #Menu-Connect
        battle_item.connect("button_press_event", self.battle_section)
        config_item.connect("button_press_event", self.config_section)
        self.start_item.connect("button_press_event",
                                self.battle.script_create)
        lobby_item.connect("button_press_event", self.lobby_section)

        # Main Window destory event
        self.window.connect("delete-event", self.destroy)

        self.battle_section(None, None)
示例#5
0
def killing_fields():                                                                                             
    print "\nYou wander out into the killing fields."
    sleep(1)
    
    # Generate one of the 7 random killing fields events.
    event = randint(1,7)
    if event in range(1,4):
        battle(Enemy(randint(0,2)))

    elif event == 4:
        print "\nYou spot a Koushi in the middle of the field. He's already dead!"
        taken = randint(0,5) + 5
        print "\nYou found %d Shaymin Dollars!" % taken
        Player.ShayminDollars += taken
        item_add("Stiff Koushi Fluff")
        XP(5)
        press_enter()

    elif event == 5:
        print "\nYou happen upon an Experience Point spring!"
        XP(20)
        press_enter()
        
    # Bubba event. You find a drunk man in the woods. You can give him 5 Shaymin Dollars for food, but there's a 1/4 chance that he'll fill your backpack with 2x4s.
    elif event == 6:
        print "\nYou happen upon a drunk-looking man sitting near a tree. He looks hungry. \nDo you offer him 5 Shaymin Dollars for a meal?"
        print " 1. Yes\n 2. No"
        command = raw_input()
        chance = randint(0,3)
        if command == "1" and chance == 0:
            print "\nYou push the brush aside to approach him, but he doesn't seem to be there anymore."
            sleep(1)
            print "You can't seem to find him, but your backpack feels a lot heavier. (20/20 Items)"
            for _ in range(20-len(Player.Backpack)):   # Fills your backpack with 2x4s.
                Player.Backpack.append("2x4")
                press_enter()
        elif command == "1" and chance != 0:
            print "\nYou hand him 5 Shaymin Dollars. He mutters to you in appreciation, and falls back asleep."
            Player.ShayminDollars -= 5
            press_enter()
            wipe()
        elif command == "2":
            print "\nYou decide he isn't worth your time, and walk away."
            press_enter()
            wipe()
            
    # Treasure chest in clearing event. Chest is guarded by a random set of enemies. You can choose to attack now, or wait until conditions become more favorable.
    elif event == 7:
        eventwon = False      # Tracks whether the player has cleared the field of enemies
        waiting = True        # Keeps the player in the event loop.
        chestopen = False     # Is the chest open?
        print "\nYou walk through the thick brush and see a clearing ahead. In the middle is a treasure chest."
        sleep(.5)
        while waiting == True:
            chance = randint(1,5) # Rolls which enemies are guarding the chest.
            if chance   == 1:
                enemies = "two Khyhywhaohws"
            elif chance == 2:
                enemies = "three Khyhywhaohws"
            elif chance == 3:
                enemies = "Shoola and a Khyhywhaohw"
            elif chance == 4:
                enemies = "two Shoolas"
            elif chance == 5:
                enemies = "three unpettables"
            print "The chest is guarded by %s." % enemies
            print "You can:\n 1. Attack them head on.\n 2. Wait and see what happens.\n 3. Flee while you can."
            command = raw_input()
            if command == "1":
                print "You leap out from the brush, ready to strike!"
                sleep(.5)
                if chance == 1:
                    print "The first Khyhywhaohw looks straight at you, bug-eyed."
                    if battle(Enemy(0)) == False:
                        break
                    print "You then pounce on the second Khyhywhaohw!"
                    if battle(Enemy(0)) == False:
                        break
                if chance == 2:
                    print "The first Khyhywhaohw looks straight at you, bug-eyed."
                    if battle(Enemy(0)) == False:
                        break
                    print "You then pounce on the second Khyhywhaohw!"
                    if battle(Enemy(0)) == False:
                        break
                    print "You turn to fight the third Khyhywhaohw, who has flopped as a defensive measure!"
                    if battle(Enemy(0)) == False:
                        break
                elif chance == 3:
                    print "Realizing the bigger theat, you stare down the Shoola."
                    if battle(Enemy(2)) == False:
                        break
                    print "You then take the opportunity to strike the Khyhywhaohw"
                    if battle(Enemy(0)) == False:
                        break
                elif chance == 4:
                    print "You approach the first Shoola, careful not to draw the attention of the other."
                    if battle(Enemy(2)) == False:
                        break
                    print "You then round yourself to face the second Shoola."
                    if battle(Enemy(2)) == False:
                        break
                elif chance == 5:
                    print "You leap out of the bushes, ready to give some pettinz. The unpettables scatter!"
                eventwon = True
                    
            elif command == "2":   
                if randint(1,4) == 1:   # 1/4 chance of being ambushed by a Shoola.
                    print "While waiting, another Shoola approaches you from behind and attacks!"
                    if battle(Enemy(2), True) == False:
                        break
                    print "The %s realize what's going on and also attack!" % enemies
                    if chance == 1:
                        if battle(Enemy(0)) == False:
                            break
                        if battle(Enemy(0)) == False:
                            break
                    if chance == 2:
                        if battle(Enemy(0)) == False:
                            break
                        if battle(Enemy(0)) == False:
                            break
                        if battle(Enemy(0)) == False:
                            break
                    if chance == 3:
                        if battle(Enemy(2)) == False:
                            break
                        if battle(Enemy(0)) == False:
                            break
                    if chance == 4:
                        if battle(Enemy(2)) == False:
                            break
                        if battle(Enemy(2)) == False:
                            break
                    eventwon = True
                else:
                    print "You wait around until a change of guard happens."
                sleep(.5)
            
            elif command == "3":
                print "The chest isn't worth the work. You leave."
                waiting = False
                wipe()
                
            if eventwon == True:
                print "With the clearing finally clear, you approach the chest."
                sleep(.5)
                chance = randint(1,2)   # 1/2 chance of the chest being locked.
                if chance == 1:
                    print "The chest is unlocked. Nice!"
                    chestopen = True
                elif chance == 2:
                    print "The chest has a slot on the front. 'Insert 50 Shaymin Dollars to proceed.' Are you f*****g serious? (%d $D)" % Player.ShayminDollars
                    print "Do you pay?"
                    print " 1. Yes\n 2. No"
                    command = raw_input()
                    if command == "1" and Player.ShayminDollars >= 50:
                        print "You pay 50 Shaymin Dollars. You hear a click from within the chest."
                        Player.ShayminDollars -= 50
                        chestopen = True
                    elif command == "1":
                        print "You don't have enough money. You sigh and leave the chest where it is."
                        break
                    if command == "2":
                        print "You decide not to open the chest. Bummer."
                        break
                
            if chestopen == True:
                print "You open the chest!"
                sleep(.5)
                chance = randint(1,50) + 50
                print "You find %d Shaymin Dollars inside!" % chance
                Player.ShayminDollars += chance
                sleep(.5)
                print "You rummage around and find some other items inside!"
                items = 0
                while items <= 3:         # Produces a distribution of items, between 4 and 9.
                    if randint(1,4) > 1: # 3/4 chance
                        item_add("Tarnished Coin")
                        item_add("Tarnished Coin")
                        items += 2
                    if randint(1,4) > 2: # 1/2 chance
                        item_add("Emerald Dust")
                        items += 1
                    if randint(1,4) > 2: # 1/2 chance
                        item_add("Faded Seal")
                        items += 1
                    if randint(1,4) > 3: # 1/4 chance
                        item_add("Phial of Ether")
                        items += 1
                waiting = False
                press_enter()

    # Backup event in case something happens. The player should never see this.
    else:
        print "\nYou spot an unpettable. It runs off into the distance."
        press_enter()
示例#6
0
def main(save_editor_path, game_install_location, profile_number, battle_speed='safe',
         debug=False, test_lootscreen=False):
    global provisions_bought
    c = Controller(debug)

    # Import Settings if Applicable
    filepath = Path(f'{os.getcwd()}/settings.json')
    if os.path.exists(filepath):
        f = open(filepath)
        settings = json.load(f)['settings']
        save_editor_path = settings['save_editor_path']
        game_install_location = settings['game_install_location']
        profile_number = settings['save_profile_number']
        battle_speed = settings['battle_speed']
        f.close()

    # Initialize Save File Reader
    sfr = SaveFileReader(save_editor_path, game_install_location, profile_number)

    if not debug:
        # Make Darkest Dungeon the active window
        dd_window = win32gui.FindWindowEx(0, 0, 0, "Darkest Dungeon")
        win32gui.SetForegroundWindow(dd_window)
        pydirectinput.doubleClick(x=1050, y=500)
        pydirectinput.doubleClick(x=1050, y=500)

    while True:
        print('Beginning main loop ...')
        sfr.decrypt_save_info('persist.game.json')
        f = open(Path(f'{sfr.SaveEditorPath}/persist.game.json'))
        info = json.load(f)['base_root']
        f.close()

        # In Dungeon
        if info['inraid']:
            # if ModsCheck is False:
            #     ModsCheck = True
            #     if 'applied_ugcs_1_0' in info:
            #         installed_mods = info['applied_ugcs_1_0']
            #         battle_speed = 'fast' \
            #             if any(mod['name'] == '885957080' for mod in installed_mods.values()) else 'safe'

            sfr.decrypt_save_info('persist.raid.json')
            f = open(Path(f'{sfr.SaveEditorPath}/persist.raid.json'))
            raid_info = json.load(f)['base_root']
            f.close()
            inventory = Inventory(raid_info)

            # Get party info
            sfr.decrypt_save_info('persist.roster.json')
            f = open(Path(f'{sfr.save_editor_path()}/persist.roster.json'))
            roster_info = json.load(f)['base_root']
            f.close()
            party_order = raid_info['party']['heroes']  # [front - back]
            party_info = Party(roster_info, party_order)

            # Separate utility for testing pattern recognition with saved lootscreen images
            # - problem with screen grab where it doesn't capture all windows including the loot window. Need to
            #   deselect and reselect darkest dungeon window in order to capture curio/loot window if not already
            #   open when starting the program (see activate_curio())
            # - second problem with pattern recognition accuracy not being good enough to classify items
            #  (not even close, see loot_treasure() for more details)
            if test_lootscreen:
                print('Testing loot screen capture!')
                search_region = rf'{sfr.save_editor_path()}\search_region.png'
                loot_img = rf'{sfr.game_install_location()}\scrolls\byhand.png'
                # use_item_img = rf'{sfr.game_install_location()}\scrolls\use_inventory.png'

                if not debug:
                    # Make Darkest Dungeon the active window
                    dd_window = win32gui.FindWindowEx(0, 0, 0, "Darkest Dungeon")
                    win32gui.SetForegroundWindow(dd_window)
                    pydirectinput.doubleClick(x=1050, y=500)
                    pydirectinput.doubleClick(x=1050, y=500)

                    if os.path.exists(search_region):
                        os.remove(search_region)
                    # pyautogui.screenshot(search_region, region=(1300, 425, 100, 150))
                    pyautogui.screenshot(search_region, region=(1060, 400, 585, 215))
                # found = list(pyautogui.locateAll(use_item_img, search_region, confidence=.8))
                found = list(pyautogui.locateAll(loot_img, search_region, confidence=.45))
                loot_screen_found = True if len(found) > 0 else False
                print(f'Found loot screen = {loot_screen_found}')

                if loot_screen_found:
                    dungeon_name = raid_info['raid_instance']['dungeon']
                    loot = identify_lootscreen_items(search_region, dungeon_name, party=party_info.heroes)
                    for item in loot:
                        print(f'item: {item.name}, quantity: {item.quantity}, slot: {item.item_slot}')
                return

            # Take action in Dungeon
            if raid_info['inbattle']:
                battle(inventory, battle_speed, debug)
            else:
                # Determine Dungeon location
                map_file = 'persist.map.json'
                sfr.decrypt_save_info(map_file)
                # map_file = 'map.json'  # can provide an alternate map file for debugging DungeonPath
                f = open(Path(f'{sfr.save_editor_path()}/{map_file}'))
                map_info = json.load(f)['base_root']
                f.close()
                areas = map_info['map']['static_dynamic']['areas']
                static_areas = map_info['map']['static_dynamic']['static_save']['base_root']['areas']
                location_number = raid_info['in_area']  # 1111584611
                location = next(index for index, area in areas.items() if static_areas[index]['id'] == location_number)

                # Used to debug droppable_items
                # dungeon_name = raid_info['raid_instance']['dungeon']
                # droppable_items = get_droppable_items(raid_info, areas, inventory, dungeon_name, party_info.heroes)
                # return

                # Check for loot screen
                queued_loot = raid_info['loot']['queue_items']['items']
                battle_reward = raid_info['loot']['result']['inventory_system']['items'] \
                    if 'result' in raid_info['loot'] else []
                if len(queued_loot) > 0 or len(battle_reward) > 0:
                    areas = map_info['map']['static_dynamic']['areas']
                    if location.startswith('co'):
                        static_tiles = static_areas[location]['tiles']
                        hallway_length = len(static_tiles) - 1
                        last_room_number = raid_info['last_room_id']  # 1111584611
                        reverse = last_room_number != static_tiles['tile0']['door_to']['area_to']
                        party_tile = get_party_tile(raid_info, hallway_length, reverse)
                    else:
                        party_tile = 0
                    dungeon_path, _ = get_dungeon_path(raid_info, static_areas, location)
                    loot_treasure(raid_info, inventory, areas, location, party_info.heroes,
                                  tile_number=party_tile, dungeon_path=dungeon_path, debug=debug)
                    sfr.decrypt_save_info('persist.raid.json')
                    f = open(Path(f'{sfr.SaveEditorPath}/persist.raid.json'))
                    raid_info = json.load(f)['base_root']
                    f.close()
                    inventory = Inventory(raid_info)  # important, need to check inventory again after looting

                time.sleep(.5)  # give enough time for loot/curio screen to close and mission complete to open
                c.write(c.b, 4)  # close out of menu (e.g. mission complete)
                time.sleep(.2)  # give enough time for mission complete screen to close

                navigate_dungeon(raid_info, areas, static_areas, inventory, party_info, location, debug)

        # In Town
        elif not info['inraid'] and not provisions_bought:
            # buy_provisions(dungeon_name, length, difficulty, debug)
            # provisions_bought = True

            # elif not info['inraid'] and provisions_bought:
            break
    print('DD bot finished!')