Esempio n. 1
0
 def test_spy(self):
     menu.navigate_to_planet('Phoenix')
     while self._available_fleet_slots > 0:
         target_address = self.pick_next_target()[0]
         spy(
             target_address.split(':')[0],
             target_address.split(':')[1],
             target_address.split(':')[2], 1)
         self._available_fleet_slots -= 1
Esempio n. 2
0
def getNextTimeAvailability(planetName):
    menu.navigate_to_planet(planetName)
    menu.navigate_to_overview()

    try:
        timeLeft = driver().find_element_by_id('Countdown').get_attribute('innerHTML')
        return time.time() + formatted_time_to_seconds(timeLeft)
    except Exception as e:
        log.warn('Exception {} : {}. Discard if no construction in progress'.format(type(e).__name__, str(e)))
        return 0
Esempio n. 3
0
def extract_facilities_buildings_level(planetName):
    menu.navigate_to_planet(planetName)

    go_to_facilities()
    building_levels = {}
    for building in FACILITIES_BUILDINGS:
        building_levels[building] = _extract_level_building(building)

    log.debug('Facilities building levels extracted for {}'.format(planetName))
    return building_levels
Esempio n. 4
0
def extract_resources_buildings_level(planetName):
    menu.navigate_to_planet(planetName)

    go_to_resources()
    building_levels = {}
    for building in RESOURCES_BUILDINGS:
        building_levels[building] = _extract_level_building(building)

    log.debug('Resources building levels extracted for {}'.format(planetName))
    return building_levels
Esempio n. 5
0
 def update_planet_resources(self):
     menu.navigate_to_planet(self.name)
     self.resources[METAL] = int(driver().find_element_by_id(
         'resources_metal').get_attribute('innerHTML').replace('.', ''))
     self.resources[CRISTAL] = int(driver().find_element_by_id(
         'resources_crystal').get_attribute('innerHTML').replace('.', ''))
     self.resources[DEUTERIUM] = int(driver().find_element_by_id(
         'resources_deuterium').get_attribute('innerHTML').replace('.', ''))
     self.resources[ENERGY] = int(driver().find_element_by_id(
         'resources_energy').get_attribute('innerHTML').replace('.', ''))
Esempio n. 6
0
def clickTechElement(planetName, techName):
    global opened_tech
    menu.navigate_to_planet(planetName)
    go_to_research()

    if opened_tech == techName:
        # Already opened
        return

    driver().find_element_by_id(researchTranslation[techName]).click()
    opened_tech = techName
Esempio n. 7
0
def get_in_progress_building(planet_name):
    menu.navigate_to_planet(planet_name)
    menu.navigate_to_overview()

    try:
        building_overview = driver().find_elements_by_class_name('content-box-s')[0]
        in_progres = building_overview.find_element_by_class_name('first')
        cancel_link = in_progres.find_elements_by_tag_name('a')[0]
        cancel_action = cancel_link.get_attribute('onClick')
        log.debug(cancel_action)
        # 3 numbers after 'cancelProduction(' (17 letters)
        item_id = cancel_action[17:19].strip(',')

        x = - len(item_id)
        for building in buildingTranslation:
            (_, _, name) = buildingTranslation[building]
            if item_id in name[x:]:
                return building

        log.error('building not identified: {}'.format(item_id))
        return None
    except Exception as e:
        log.warn('Exception {} : {}. Discard if no construction in progress'.format(type(e).__name__, str(e)))
        return None
Esempio n. 8
0
def upgrade_building(planetName, buildingName):

    if buildingName not in buildingTranslation:
        return Event(Event.ERROR, 0, planetName, 'Building is not valid')

    menu.navigate_to_planet(planetName)
    go_to(buildingName)

    try:

        _clickBuildingElement(buildingName)
        time.sleep(3)
        cost = _get_current_building_cost()

        driver().find_element_by_class_name('build-it').click()
        #TODO: improve by using construction time extracted when building

        log.info('{} construction started for {} metal, {} cristal and {} deuterium'.format(buildingName,
                                                                        cost[METAL], cost[CRISTAL], cost[DEUTERIUM]))
        return Event(Event.BUILDING_IN_PROGRESS, getNextTimeAvailability(planetName) - time.time(), planetName, buildingName)
    except Exception as e:
        log.error('Impossible to upgrade this building {} on {}\n {} : {}'.format(buildingName, planetName, type(e).__name__, str(e)))
        menu.navigate_to_overview()
        return Event(Event.ERROR, 0, planetName, 'Impossible to upgrade this building, {}'.format(str(e)))
Esempio n. 9
0
def build_device(planet_name, deviceName, n):
    menu.navigate_to_planet(planet_name)
    go_to(deviceName)

    if deviceName not in deviceTranslation:
        return Event(Event.ERROR, 0, planet_name, 'Device is not valid')

    try:

        _click_device_element(deviceName)
        time.sleep(3)
        cost = getDeviceCost(deviceName, n)

        # Fill quantity
        driver().find_element_by_id('number').send_keys(str(n))
        # Start construction
        driver().find_element_by_class_name('build-it').click()

        log.info('Construction of {} {} started for {} metal, {} cristal and {} deuterium'.format(n, deviceName,
                                                        cost[METAL], cost[CRISTAL], cost[DEUTERIUM]))
        return Event(Event.SHIPYARD_CONSTRUCTION_IN_PROGRESS, getNextTimeAvailability() - time.time(), planet_name, deviceName)
    except Exception as e:
        log.error('Impossible to building {} {} on {}\n {} : {}'.format(n, deviceName,planet_name, type(e).__name__, str(e)))
        return Event(Event.ERROR, 0, planet_name, 'Impossible to build this device, {}'.format(str(e)))
Esempio n. 10
0
 def full_update(self):
     menu.navigate_to_planet(self.name)
     self.update_planet_resources()
     self.update_buildings_level()
     self.update_defense()