Exemplo n.º 1
0
 def check_battles(self):
     session = self.session
     battles = session.query(Battle).all()
     for battle in battles:
         post = self.reddit.get_submission(comment_limit=None, submission_id=name_to_id(battle.submission_id))
         if post:
             self.process_post_for_battle(post, battle, session)
Exemplo n.º 2
0
 def check_battles(self):
     session = self.session
     battles = session.query(Battle).all()
     for battle in battles:
         post = self.reddit.get_submission(comment_limit=None,
                                           submission_id=name_to_id(
                                               battle.submission_id))
         if post:
             self.process_post_for_battle(post, battle, session)
Exemplo n.º 3
0
 def markdown(self, text="Disputed"):
     if self.submission_id:
         url = "/r/%s/comments/%s" % (self.region.srname,
                                      name_to_id(self.submission_id))
         return "[%s](%s)" % (text, url)
     return text
Exemplo n.º 4
0
def main():
    hero_class_mapping = utils.CLASS_MAPPING
    
    request = urllib.request.Request(
        url='https://api.hearthstonejson.com/v1/23966/enUS/cards.json',
        headers={'User-Agent': 'Mozilla/5.0'
                 })
    
    db = json.loads(urllib.request.urlopen(request).read())
    
    # Filter for only witchwood
    db = [x for x in db if 'set' in x and x['set'] == 'GILNEAS' and 'type' in x and x['type'] != 'ENCHANTMENT']
    
    for hs_card in db:
        card_dict = {}
        card_dict['set'] = 'WITCHWOOD'
        card_dict['name'] = hs_card['name']
        card_dict['description'] = '' if 'text' not in hs_card else hs_card['text']
        attributes = {}
        card_dict['attributes'] = attributes
        card_dict['baseManaCost'] = 0 if 'cost' not in hs_card else hs_card['cost']
        card_dict['rarity'] = 'FREE' if 'rarity' not in hs_card else hs_card['rarity']
        card_dict['type'] = hs_card['type']
        card_dict['heroClass'] = hero_class_mapping[hs_card['cardClass']]
        card_dict['collectible'] = False if 'collectible' not in hs_card else hs_card['collectible']
        lower = hs_card['type'].lower()
        if lower == 'minion' and not card_dict['collectible']:
            lower = 'token'
        filename = utils.name_to_id(name=hs_card['name'], card_type=lower)
        if hs_card['type'] == 'MINION':
            card_dict['baseAttack'] = hs_card['attack']
            card_dict['baseHp'] = hs_card['health']
            if 'race' in hs_card:
                card_dict['race'] = hs_card['race']
        if hs_card['type'] == 'SPELL' or hs_card['type'] == 'HERO_POWER':
            card_dict['spell'] = {'class': 'BuffSpell', 'target': 'SELF'}
            card_dict['targetSelection'] = 'NONE'
        
        if 'mechanics' in hs_card:
            mechanics = hs_card['mechanics']
            if 'BATTLECRY' in mechanics:
                card_dict['battlecry'] = {'spell': {'class': 'NullSpell'}, 'targetSelection': 'NONE'}
                attributes['BATTLECRY'] = True
            if 'AURA' in mechanics:
                card_dict['aura'] = {'class': 'BuffAura', 'target': 'FRIENDLY_MINIONS', 'hpBonus': 0, 'attackBonus': 0}
            if 'CANT_ATTACK' in mechanics:
                attributes['CANNOT_ATTACK'] = True
            if 'CHARGE' in mechanics:
                attributes['CHARGE'] = True
            if 'COMBO' in mechanics:
                attributes['COMBO'] = True
                card_dict['battlecry'] = {'spell': {'class': 'NullSpell'}, 'targetSelection': 'NONE'}
            if 'DEATHRATTLE' in mechanics:
                attributes['DEATHRATTLES'] = True
                card_dict['deathrattle'] = {'class': 'NullSpell'}
            if 'DIVINE_SHIELD' in mechanics:
                attributes['DIVINE_SHIELD'] = True
            if 'IMMUNE' in mechanics:
                attributes['IMMUNE'] = True
            if 'POISONOUS' in mechanics:
                attributes['POISONOUS'] = True
            if 'STEALTH' in mechanics:
                attributes['STEALTH'] = True
            if 'TAUNT' in mechanics:
                attributes['TAUNT'] = True
            if 'WINDFURY' in mechanics:
                attributes['WINDFURY'] = True
            if 'RUSH' in mechanics:
                attributes['RUSH'] = True
        
        card_dict['fileFormatVersion'] = 1
        stubs_ = 'src/main/resources/cards/hearthstone/witchwood/stubs/'
        if card_dict['collectible']:
            stubs_ = path.join(stubs_, 'collectible/')
        else:
            stubs_ = path.join(stubs_, 'uncollectible/')
        try:
            os.makedirs(stubs_)
        except:
            pass
        utils.write_card(fix_dict(card_dict), path.join(stubs_, filename + '.json'))
Exemplo n.º 5
0
    def update_game(self):
        session = self.session
        MarchingOrder.update_all(session, self.config)

        results = Region.update_all(session, self.config)
        to_add = []
        for newternal in results['new_eternal']:
            title = "The Eternal Battle Rages On"
            post = InvadeCommand.post_invasion(title, newternal, self.reddit)
            if post:
                newternal.submission_id = post.name
                to_add.append(newternal)
            else:
                logging.warn("Couldn't submit eternal battle thread")
                session.rollback()
        if to_add:
            session.add_all(to_add)
            session.commit()

        results = Battle.update_all(session, self.config)

        for ready in results['begin']:
            ready.display_ends = (ready.begins +
                self.config["game"]["battle_time"])

            # Actual ending is within battle_lockout of the end
            chooserange = self.config["game"]["battle_lockout"]
            chosen = random.randint(0, chooserange)
            ready.ends = ready.display_ends - (chooserange / 2) + chosen

            text = ("War is now at your doorstep!  Mobilize your armies! "
                    "The battle has begun now, and will end at %s.\n\n"
                    "> Enter your commands in this thread, prefixed with "
                    "'>'") % ready.ends_str()
            post = self.reddit.get_submission(
                submission_id=name_to_id(ready.submission_id))
            post.edit(text)
            session.commit()

        self.update_skirmish_summaries(results['skirmish_ended'])

        for done in results['ended']:
            report = ["The battle is complete...\n"]
            report += done.report(self.config)

            report.append("")

            if done.old_buffs:
                report.append("Buffs in effect for Team %s\n" %
                              num_to_team(done.old_owner, self.config))
                for buff in done.old_buffs:
                    report.append("  * %s" % buff.name)
                report.append("")

            team0_name = num_to_team(0, self.config)
            team1_name = num_to_team(1, self.config)

            # Homeland buffs?
            if done.homeland_buffs:
                report.append("Homeland buffs in effect:")
                for team in range(0, 2):
                    name = num_to_team(team, self.config)
                    report.append("%s: %d%%" %
                                  (name, done.homeland_buffs[team]))

            report.append(("## Final Score:  Team %s: %d "
                           "Team %s: %d") % (team0_name, done.score0,
                                             team1_name, done.score1))
            if done.victor is not None:
                report.append("\n# The Victor:  Team %s" %
                              num_to_team(done.victor, self.config))
            else:
                report.append("# TIE")

            text = "\n".join(report)
            post = self.reddit.get_submission(
                submission_id=name_to_id(done.submission_id))
            post.edit(text)

            # Update all the skirmish summaries
            self.update_skirmish_summaries(done.toplevel_skirmishes())

            session.delete(done)
            session.commit()
        db.Buff.update_all(session)
Exemplo n.º 6
0
 def markdown(self, text="Disputed"):
     if self.submission_id:
         url = "/r/%s/comments/%s" % (self.region.srname,
                                      name_to_id(self.submission_id))
         return "[%s](%s)" % (text, url)
     return text
Exemplo n.º 7
0
    def update_game(self):
        session = self.session
        MarchingOrder.update_all(session, self.config)

        results = Region.update_all(session, self.config)
        to_add = []
        for newternal in results['new_eternal']:
            title = "The Eternal Battle Rages On"
            post = InvadeCommand.post_invasion(title, newternal, self.reddit)
            if post:
                newternal.submission_id = post.name
                to_add.append(newternal)
            else:
                logging.warn("Couldn't submit eternal battle thread")
                session.rollback()
        if to_add:
            session.add_all(to_add)
            session.commit()

        results = Battle.update_all(session, self.config)

        for ready in results['begin']:
            ready.display_ends = (ready.begins +
                                  self.config["game"]["battle_time"])

            # Actual ending is within battle_lockout of the end
            chooserange = self.config["game"]["battle_lockout"]
            chosen = random.randint(0, chooserange)
            ready.ends = ready.display_ends - (chooserange / 2) + chosen

            text = ("War is now at your doorstep!  Mobilize your armies! "
                    "The battle has begun now, and will end at %s.\n\n"
                    "> Enter your commands in this thread, prefixed with "
                    "'>'") % ready.ends_str()
            post = self.reddit.get_submission(
                submission_id=name_to_id(ready.submission_id))
            post.edit(text)
            session.commit()

        self.update_skirmish_summaries(results['skirmish_ended'])

        for done in results['ended']:
            report = ["The battle is complete...\n"]
            report += done.report(self.config)

            report.append("")

            if done.old_buffs:
                report.append("Buffs in effect for Team %s\n" %
                              num_to_team(done.old_owner, self.config))
                for buff in done.old_buffs:
                    report.append("  * %s" % buff.name)
                report.append("")

            team0_name = num_to_team(0, self.config)
            team1_name = num_to_team(1, self.config)

            # Homeland buffs?
            if done.homeland_buffs:
                report.append("Homeland buffs in effect:")
                for team in range(0, 2):
                    name = num_to_team(team, self.config)
                    report.append("%s: %d%%" %
                                  (name, done.homeland_buffs[team]))

            report.append(("## Final Score:  Team %s: %d "
                           "Team %s: %d") %
                          (team0_name, done.score0, team1_name, done.score1))
            if done.victor is not None:
                report.append("\n# The Victor:  Team %s" %
                              num_to_team(done.victor, self.config))
            else:
                report.append("# TIE")

            text = "\n".join(report)
            post = self.reddit.get_submission(
                submission_id=name_to_id(done.submission_id))
            post.edit(text)

            # Update all the skirmish summaries
            self.update_skirmish_summaries(done.toplevel_skirmishes())

            session.delete(done)
            session.commit()
        db.Buff.update_all(session)