Exemple #1
0
    def attack(self, vid, troops=None):
        url = "game.php?village=%s&screen=place&target=%s" % (self.village_id,
                                                              vid)
        pre_attack = self.wrapper.get_url(url)
        pre_data = {}
        for u in Extractor.attack_form(pre_attack):
            k, v = u
            pre_data[k] = v
        if troops:
            pre_data.update(troops)
        else:
            pre_data.update(self.troopmanager.troops)

        if vid not in self.map.map_pos:
            return False

        x, y = self.map.map_pos[vid]
        post_data = {
            'x': x,
            'y': y,
            'target_type': 'coord',
            'attack': 'Aanvallen'
        }
        pre_data.update(post_data)

        confirm_url = "game.php?village=%s&screen=place&try=confirm" % self.village_id
        conf = self.wrapper.post_url(url=confirm_url, data=pre_data)
        if '<div class="error_box">' in conf.text:
            return False
        duration = Extractor.attack_duration(conf)
        self.logger.info("[Attack] %s -> %s duration %f.1 h" %
                         (self.village_id, vid, duration / 3600))

        confirm_data = {}
        for u in Extractor.attack_form(conf):
            k, v = u
            if k == "support":
                continue
            confirm_data[k] = v
        new_data = {
            'building': 'main',
            'h': self.wrapper.last_h,
        }
        confirm_data.update(new_data)
        result = self.wrapper.get_api_action(village_id=self.village_id,
                                             action="popup_command",
                                             params={"screen": "place"},
                                             data=confirm_data)

        return result
Exemple #2
0
    def attack(self, source, vid, troops=None):
        url = "game.php?village=%s&screen=place&target=%s" % (source, vid)
        pre_attack = self.wrapper.get_url(url)
        pre_data = {}
        for u in Extractor.attack_form(pre_attack):
            k, v = u
            pre_data[k] = v
        if troops:
            pre_data.update(troops)

        if vid not in self.game_map.map_pos:
            return False

        x, y = self.game_map.map_pos[vid]
        post_data = {
            'x': x,
            'y': y,
            'target_type': 'coord',
            'attack': 'Aanvallen'
        }
        pre_data.update(post_data)

        confirm_url = "game.php?village=%s&screen=place&try=confirm" % self.village_id
        conf = self.wrapper.post_url(url=confirm_url, data=pre_data)
        if '<div class="error_box">' in conf.text:
            return False
        duration = Extractor.attack_duration(conf)
        confirm_data = {}
        for u in Extractor.attack_form(conf):
            k, v = u
            if k == "support":
                continue
            confirm_data[k] = v
        new_data = {
            'building': 'main',
            'h': self.wrapper.last_h,
        }
        confirm_data.update(new_data)

        return confirm_data, duration