def export_cards(cls): cards = [] for coach in Coach.query.options(joinedload('cards').joinedload('coach')).all(): for card in coach.cards: cards.append(CardService.turn_Card_to_card(card)) ImperiumSheet.store_cards(cards)
def update(cls): for card in ImperiumSheet.cards(True): c_dict = cls.init_dict_from_card(card) cards = Card.query.filter_by(name=c_dict['name']).all() for scard in cards: scard.update(**c_dict) db.session.commit()
def generate(cls, ptype="booster_budget", team=None, first=False): if ptype not in cls.PACK_PRICES: raise InvalidPackType(ptype) if team is not None and team not in cls.team_codes(): raise InvalidTeam(team) if ptype in ["player", "positional"]: if not team: raise ValueError(f"Missing team value for {ptype} pack") elif team.lower() not in cls.team_codes(): raise ValueError(f"Team {team} unknown") else: team = team.lower() price = cls.PACK_PRICES[ptype] pack = Pack(price=price, pack_type=ptype, team=team) cards = [] if ptype == "starter": cards.extend(ImperiumSheet.starter_cards()) else: if ptype in ["player", "positional"]: combos = cls.PLAYER_COMBOS if first: combos = cls.PLAYER_FIRST_COMBOS elif ptype in ["training", "special"]: combos = cls.TRAINING_COMBOS elif ptype == "coaching": combos = cls.COACHING_COMBOS elif ptype == "skill": combos = cls.SKILL_COMBOS elif ptype == "booster_premium": combos = cls.PREMIUM_COMBOS else: combos = cls.BUDGET_COMBOS roll = random.random() rarities = [combo for combo in combos if combo['roll'] >= roll][0]['rarities'] for rarity in rarities: if ptype in ["player", "positional"]: races = cls.team_by_code(team)["races"] subtype = "Positional" if ptype == "positional" else None fcards = cls.filter_cards(rarity, "Player", races, subtype) elif ptype in ["training", "skill", "coaching"]: fcards = cls.filter_cards(rarity, "Training") elif ptype == "special": fcards = cls.filter_cards(rarity, "Special Play") else: fcards = cls.filter_cards(rarity) cards.append(random.choice(fcards)) for card in cards: pack.cards.append(CardService.init_Card_from_card(card)) return pack
def filter_cards(cls, rarity, ctype=None, races=None, subtype=None): if subtype is not None: return [ card for card in ImperiumSheet.cards() if card["Rarity"] == rarity and card["Type"] == ctype and card["Race"] in races and card["Subtype"] == subtype ] if races is not None: return [ card for card in ImperiumSheet.cards() if card["Rarity"] == rarity and card["Type"] == ctype and card["Race"] in races ] if ctype is not None: return [ card for card in ImperiumSheet.cards() if card["Rarity"] == rarity and card["Type"] == ctype ] return [ card for card in ImperiumSheet.cards() if card["Rarity"] == rarity ]
def update(cls): for tournament in ImperiumSheet.tournaments(): t_dict = cls.init_dict_from_tournament(tournament) t = Tournament.query.filter_by(tournament_id = t_dict['tournament_id']).all() if len(t)==0: T = Tournament() db.session.add(T) else: T = t[0] T.update(**t_dict) db.session.commit()
async def __run_genpack(self): if self.__class__.check_gen_command(self.cmd): ptype = self.args[1] if ptype == "player": team = self.args[2] pack = Pack(ptype, team=team) pack.generate() elif ptype == "training": pack = Pack(ptype) pack.generate() elif ptype == "booster": ptype = "booster_budget" if len( self.args) < 3 else f"booster_{self.args[2]}" pack = Pack(ptype) pack.generate() # add error handling eventually coach = Coach.load_coach(str(self.message.author)) t = Transaction(pack, pack.price) try: coach.make_transaction(t) except TransactionError as e: await self.transaction_error(e) return else: # transaction is ok and coach is saved msg = LongMessage(self.client, self.message.channel) msg.add( f"**{pack.description()}** for **{self.message.author}** - **{pack.price}** coins:\n" ) msg.add(f"{self.__class__.format_pack(pack.cards)}\n") msg.add(f"**Bank:** {coach.account.cash} coins") await msg.send() # export ImperiumSheet.store_all_cards() else: await self.client.send_message(self.message.channel, self.__class__.gen_help())
def check_gen_command(cls, command): args = command.split() length = len(args) if length not in [2, 3]: return False if args[1] not in GEN_PACKS: return False # training/booster without quality if length == 2 and args[1] not in ["training", "booster"]: return False # training takes not other parameter if length > 2 and args[1] == "training": return False # booster with allowed quality if length == 3 and args[1] == "booster" and args[2] not in GEN_QUALITY: return False # player with teams if length == 3 and args[1] == "player" and args[ 2] not in ImperiumSheet.team_codes(): return False return True
def get_card_from_sheet(cls, name): name_low = name.lower() for card in ImperiumSheet.cards(): if name_low == str(card["Card Name"]).lower(): return card return None