def recurse_prim(x): x = database.to_primitive(x) if isinstance(x, dict): return {k: recurse_prim(v) for k, v in x.items()} if isinstance(x, list): return [recurse_prim(y) for y in x] return x
def pullChar(banner_name): player = db['players'][current_user.id] #You don't a full roster if player['max_roster'] > len(player['roster']): new_char = pickChar(banner_name) db['players'][current_user.id]['roster'].append(new_char) #You do have a full roster else: new_char = pickChar(banner_name) db['players'][current_user.id]['pulled_character'] = new_char return render_template('pull/pulled.html', user=current_user, character=database.to_primitive( db['characters'][new_char]), chr_ind=new_char)
def character_page(chr_ind): if request.method == 'POST': #button = request.form.get('submit_button') if chr_ind in db['players'][current_user.id]['wishlist']: db['players'][current_user.id]['wishlist'].remove(chr_ind) flash('Removed character from wishlist.', category='success') else: db['players'][current_user.id]['wishlist'].append(chr_ind) flash('Added character to wishlist.', category='success') #Determines if a characer is owned owned = getOwnedChars() if chr_ind in owned: owner = owned[chr_ind] else: owner = None pulled = getPulledChars() if chr_ind in pulled: puller = pulled[chr_ind] else: puller = None character = database.to_primitive(db['characters'][chr_ind]) rarity = db['rarity_names'][str(character['rarity'])] rarity += " " + "☆" * character['rarity'] in_wishlist = chr_ind in db['players'][current_user.id]['wishlist'] players_wished = [ pname for pname, player in db['players'].items() if chr_ind in player['wishlist'] ] return render_template('characters/character_page.html', user=current_user, character=character, chr_ind=chr_ind, owner=owner, puller=puller, rarity=rarity, in_wishlist=in_wishlist, players_wished=players_wished)
def banners(): if request.method == 'POST': #Gets the info about the player and the button press player = db['players'][current_user.id] button = request.form.get('submit_button') #Checks if the button press was a pull if button.split('-')[0] == 'pull': banner_name = button.split('-')[1] cost = db['banners'][banner_name]['cost'] #Checks if the player has enough coins if player['coins'] - cost < 0: flash("You don't have enough coins.", category='error') else: #Deducting the cost of the banner db['players'][current_user.id]['coins'] -= cost #Returns a page to show the user thier pull return pullChar(banner_name) #Checks if the button was a character removal elif button == 'remove': #Gets the character that's being removed removing = request.form.get('characterRemoving') if removing is not None: removing = removing.split('-')[1] #If the character selected the one that was just pulled if removing == 'pulled': db['players'][current_user.id]['pulled_character'] = None #If the character selected was already in thier roster else: removing = int(removing) db['players'][current_user.id]['roster'].pop(removing) db['players'][current_user.id]['roster'].append( player['pulled_character']) db['players'][current_user.id]['pulled_character'] = None #End of POST request logic #Gets the current player player = db['players'][current_user.id] #Determines if the player is able to pull. #If the player already has a character in their "pulled" slot, #They must remove a character before they can pull again. can_pull = player['pulled_character'] is None if can_pull: #Gets the number of coins the player has coins = player['coins'] #Returns HTML template that displays the banners return render_template('pull/banners.html', user=current_user, coins=coins, banners=db['banners']) else: #Gets the roster of the current player char_ids = database.to_primitive(player['roster']) characters = [(str(ri), db['characters'][ci]) for ri, ci in enumerate(char_ids)] #Gets the character that was pulled by the player pulled_char = (player['pulled_character'], db['characters'][player['pulled_character']]) #Returns an HTML template that prompts the user to remove a character return render_template('pull/already_pulled.html', user=current_user, characters=characters, pulled_char=pulled_char)
def player_page(ply_ind): if request.method == 'POST': button = request.form.get('submit_button') #If a user is checking in to claim their coins if button == 'check-in': last_check_in = db['players'][current_user.id]['last_check_in'] now = int(time.time()) #Get's the previous check in time and the current time prev = datetime.datetime.utcfromtimestamp(last_check_in) prev = est.localize(prev) curr = datetime.datetime.utcfromtimestamp(now) curr = est.localize(curr) #Calculates the number of days since the last check in diff = (curr.date() - prev.date()).days #Adds the appropriate number of coins db['players'][current_user.id]['last_check_in'] = now db['players'][current_user.id]['coins'] += diff #Flashes success message to user flash(f'You have redeemed {diff} Koins.', category='success') #If a user is changing their NSFW status elif button.split('-')[0] == 'NSFW': toggle = button.split('-')[1] == 'on' db['players'][current_user.id]['NSFW_shown'] = toggle flash('Preferences updated. Please clear cache.', category='success') elif button == 'expand-roster': player = db['players'][ply_ind] roster_size = player['max_roster'] if roster_size >= len(db['expansion_costs']): flash("You already have the max roster size.", category='error') else: cost = db['expansion_costs'][roster_size] if cost > player['coins']: flash("You don't have enough coins.", category='error') else: #Deducting the cost of the banner and adding to their roster db['players'][current_user.id]['max_roster'] += 1 db['players'][current_user.id]['coins'] -= cost #Returns a page to show the user thier pull return pullChar(banner_name='base') if current_user.is_authenticated: player = db['players'][ply_ind] #Get a list of owned characters and wishlisted characters by the player owned_characters = [(char_id, db['characters'][char_id]) for char_id in player['roster']] wishlist_characters = [(char_id, db['characters'][char_id]) for char_id in player['wishlist']] #Gets the time that the player last checked in last_check_in = player['last_check_in'] check_in = datetime.datetime.utcfromtimestamp(last_check_in) check_in = est.localize(check_in) check_in_string = check_in.strftime("%a, %b %d, %Y %I:%M %Z%z") #Returns the HTML template return render_template( 'players/player_page.html', user=current_user, player=(ply_ind, database.to_primitive(db['players'][ply_ind])), owned_characters=owned_characters, wishlist_characters=wishlist_characters, check_in=check_in_string) #If the user is not logged in, redirect to the home page. else: return redirect(url_for('otherBP.home'))