Exemplo n.º 1
0
    async def do_work(self) -> int:
        await self.click(Work.selector(), 3)
        await self.browser.wait_for(".imp.yellow.tip")

        soup = await self.get_soup()
        energy, energy_cooldown_time = Status.check_energy(soup)
        gold = Work.check_region_gold(soup)

        if not Work.can_work(soup):
            LOG.info("Working is not possible")
            return 600

        if gold > 0 and energy >= 10:
            try:
                await self.click(Work.work_selector(), 3)
                await self.click(utils.close_selector(), 3)
                LOG.info("Work is completed {} energys use to work".format(energy))
            except Exception as err:
                LOG.debug(err)
                LOG.error("Can not work, maybe the factory owner doesn't have enough money?")
                return 600
        elif gold > 0 and energy_cooldown_time == 0 and int(self.perks['END'][0]) >= 50:
            await self.click(Status.energy_bar_selector(), 3)
        else:
            if int(self.perks['END'][0]) < 50:
                return 600
            elif gold == 0:
                LOG.info("Region lack of gold")
                return 600
            elif energy >= 10 or energy_cooldown_time == 0:
                LOG.error("Some error occurred in work")
                return 600
            return energy_cooldown_time

        return await self.do_work()
Exemplo n.º 2
0
    async def idle(self):
        # work cooldown time
        work_c = 600

        war_c, is_traveling, _ = await self.check_overview()

        await self.do_perks_upgrade()

        if is_traveling:
            await self.sleep(600)
            return

        await self.do_storage_supply()

        if war_c == 0:
            await self.do_military_training()

        work_c = await self.do_work()

        war_c, _, _ = await self.check_overview()
        perk_c = await self.calculate_perks_time()

        gold, money = Status.check_str_money(await self.get_soup())
        LOG.info(f"Your property: {money} $   {gold} G")
        await self.sleep(min(perk_c, war_c, work_c))
Exemplo n.º 3
0
 async def check_overview(self) -> (int, bool, (int, int)):
     """
     Return
         (
             wars_cooldown_time,
             is_traveling,
             (energy, energy_cooldown_time)
         )
     """
     await self.click(Overview.selector(),
                      wait_for='#chat input[name=name]')
     soup = await self.get_soup()
     return (Overview.check_war(soup), Overview.check_travel(soup),
             Status.check_energy(soup))
Exemplo n.º 4
0
    async def idle(self):
        await self.refresh()
        await self.check_login()

        await self.do_perks_upgrade()
        await self.do_storage_supply()

        _, _, (energy, energy_cooldown_time) = await self.check_overview()

        if (energy >= 20) and energy_cooldown_time == 0:
            LOG.warn(
                "There is no gold in your area or automatic working expires")

        time = await self.calculate_perks_time()
        if time:
            gold, money = Status.check_str_money(await self.get_soup())
            LOG.info(f"Your property: {money} $   {gold} G")
            await self.sleep(3600 if time >= 3600 else time)
Exemplo n.º 5
0
    async def upgrade(self, perk):
        selector = None

        gold, _ = Status.check_money(await self.get_soup())

        minimal_strategy = [
            i for i, v in enumerate(self.upgrade_strategy)
            if v == min(self.upgrade_strategy)
        ]

        if len(minimal_strategy) == 3:
            minimal_strategy = []

        if self.upgrade_strategy == 'RRCash' or gold <= 4320:
            upgrade_selector = "#perk_target_4 > div[url='1'] > div > div"
        elif self.use_to_upgrade == "GOLD" or (self.use_to_upgrade == "GOLD1"
                                               and perk.value
                                               not in minimal_strategy):
            upgrade_selector = "#perk_target_4 > div[url='2'] > div > div"
        else:
            upgrade_selector = "#perk_target_4 > div[url='1'] > div > div"

        if perk == Perks.STR:
            selector = ".perk_item[perk='1']"
        elif perk == Perks.EDU:
            selector = ".perk_item[perk='2']"
        elif perk == Perks.END:
            selector = ".perk_item[perk='3']"
        else:
            raise Exception("Perk not found")

        await self.click(selector, 3)
        await self.click(upgrade_selector, 3)

        LOG.info("Upgrading {}: {} -> {}".format(perk.name,
                                                 self.perks[perk.name][0],
                                                 self.perks[perk.name][0] + 1))
Exemplo n.º 6
0
    async def do_storage_supply(self):
        LOG.debug("Do storage supply")
        await self.click(Storage.selector(),
                         wait_for="span[action='leader/storage']")

        soup = BeautifulSoup((await self.browser.content()), "html5lib")

        # Produce energy drink
        if int(
                soup.find("span", {
                    "urlbar": str(Storage.Energydrink.value)
                }).text.replace('.', '')) <= 3600:
            await self.click(Storage.selector(Storage.Energydrink.value), 3)
            gold, _ = Status.check_money(await self.get_soup())

            # 6 hours ~ 24 hours
            amount = random.randrange(10800, 43200, 1000)
            if gold < amount / 10:
                amount = gold * 10

            if amount > 300:
                await self.type('.storage_produce_ammount', str(amount))
                await self.click('.storage_produce_button', 3)
                LOG.info('Produced: energy drink {} pcs.'.format(amount))

        need_products = [(Storage.Bombers, 10000), (Storage.Moontanks, 10000),
                         (Storage.Spacestations, 1280)]

        # Buy products
        for pair in need_products:
            product, number = pair
            if int(
                    soup.find("span", {
                        "urlbar": str(product.value)
                    }).text.replace('.', '')) < number:
                await self.buy_product(product, number)
Exemplo n.º 7
0
    async def buy_product(self, product, amount):
        """
        Must be #storage page

        : product (Storage):   Storage.Bombers、.....
        : amount (int)
        """
        await self.click(Storage.selector(product.value), 3)
        price, num = Storage.check_product_price(await self.get_soup())
        _, money = Status.check_money(await self.get_soup())
        # Reserve 1 billion(1kkk) for upgrade perk
        money -= 1000000000

        if money < price:
            return

        amount = amount if num >= amount else num
        if price * amount > money:
            amount = money // price

        await self.type('.storage_buy_input', str(amount))
        await self.click('.storage_buy_button', 3)
        LOG.info("Market purchase: {}, {} pcs, total {}.".format(
            product.name, amount, price * amount))