Exemplo n.º 1
0
async def slimeball_tick(id_server):
    resp_cont = EwResponseContainer(id_server=id_server)

    for id_game in sb_games:
        game = sb_games.get(id_game)
        if game == None:
            continue
        if game.id_server == id_server:
            if len(game.players) > 0:
                for player in game.players:
                    resp_cont.add_response_container(player.move())

                resp_cont.add_response_container(game.move_ball())

            else:
                poi_data = poi_static.id_to_poi.get(game.poi)
                response = "Slimeball game ended with score purple {} : {} pink.".format(game.score_purple, game.score_pink)
                resp_cont.add_channel_response(poi_data.channel, response)

                game.kill()

    await resp_cont.post()
Exemplo n.º 2
0
async def print_grid_bubblebreaker(cmd):
    grid_str = ""
    user_data = EwUser(member=cmd.message.author)
    poi = user_data.poi
    channel = cmd.message.channel.name
    id_server = cmd.guild.id
    time_now = int(time.time())
    use_emotes = False
    if poi in mines_map:
        grid_map = mines_map.get(poi)
        if id_server not in grid_map:
            init_grid(poi, id_server)
        grid_cont = grid_map.get(id_server)

        grid = grid_cont.grid

        # grid_str += "   "
        for j in range(len(grid[0])):
            letter = ewcfg.alphabet[j]
            grid_str += "{} ".format(letter)
        grid_str += "\n"
        for i in range(len(grid)):
            row = grid[i]
            # if i+1 < 10:
            #	grid_str += " "

            # grid_str += "{} ".format(i+1)
            for j in range(len(row)):
                cell = row[j]
                cell_str = get_cell_symbol_bubblebreaker(cell)
                if use_emotes:
                    cell_str = ewcfg.number_emote_map.get(int(cell))
                grid_str += cell_str + " "
            # grid_str += "{}".format(i+1)
            grid_str += "\n"

        # grid_str += "   "
        for j in range(len(grid[0])):
            letter = ewcfg.alphabet[j]
            grid_str += "{} ".format(letter)

        grid_edit = "\n```\n{}\n```".format(grid_str)
        if use_emotes:
            grid_edit = "\n" + grid_str
        if time_now > grid_cont.time_last_posted + 10 or grid_cont.times_edited > 8 or grid_cont.message == "":
            grid_cont.message = await fe_utils.send_message(
                cmd.client, cmd.message.channel,
                fe_utils.formatMessage(cmd.message.author, grid_edit))
            grid_cont.time_last_posted = time_now
            grid_cont.times_edited = 0
        else:
            await fe_utils.edit_message(
                cmd.client, grid_cont.message,
                fe_utils.formatMessage(cmd.message.author, grid_edit))
            grid_cont.times_edited += 1

        if grid_cont.wall_message == "":
            wall_channel = ewcfg.mines_wall_map.get(poi)
            resp_cont = EwResponseContainer(id_server=id_server)
            resp_cont.add_channel_response(wall_channel, grid_edit)
            msg_handles = await resp_cont.post()
            grid_cont.wall_message = msg_handles[0]
        else:
            await fe_utils.edit_message(cmd.client, grid_cont.wall_message,
                                        grid_edit)
Exemplo n.º 3
0
async def print_grid_minesweeper(cmd):
    grid_str = ""
    user_data = EwUser(member=cmd.message.author)
    poi = user_data.poi
    channel = cmd.message.channel.name
    id_server = cmd.guild.id
    time_now = int(time.time())
    if poi in mines_map:
        grid_map = mines_map.get(poi)
        if id_server not in grid_map:
            init_grid_minesweeper(poi, id_server)
        grid_cont = grid_map.get(id_server)

        grid = grid_cont.grid

        grid_str += "   "
        for j in range(len(grid[0])):
            letter = ewcfg.alphabet[j]
            grid_str += "{} ".format(letter)
        grid_str += "\n"
        for i in range(len(grid)):
            row = grid[i]
            if i + 1 < 10:
                grid_str += " "

            grid_str += "{} ".format(i + 1)
            for j in range(len(row)):
                cell = row[j]
                cell_str = ""
                if cell == ewcfg.cell_empty_open:
                    neighbor_mines = 0
                    for ci in range(max(0, i - 1), min(len(grid), i + 2)):
                        for cj in range(max(0, j - 1), min(len(row), j + 2)):
                            if grid[ci][cj] > 0:
                                neighbor_mines += 1
                    cell_str = str(neighbor_mines)

                else:
                    cell_str = ewcfg.symbol_map_ms.get(cell)
                grid_str += cell_str + " "

            grid_str += "{}".format(i + 1)
            grid_str += "\n"

        grid_str += "   "
        for j in range(len(grid[0])):
            letter = ewcfg.alphabet[j]
            grid_str += "{} ".format(letter)

        grid_edit = "\n```\n{}\n```".format(grid_str)

        if time_now > grid_cont.time_last_posted + 10 or grid_cont.times_edited > 3 or grid_cont.message == "":
            grid_cont.message = await fe_utils.send_message(
                cmd.client, cmd.message.channel,
                fe_utils.formatMessage(cmd.message.author, grid_edit))
            grid_cont.time_last_posted = time_now
            grid_cont.times_edited = 0
        else:
            await fe_utils.edit_message(
                cmd.client, grid_cont.message,
                fe_utils.formatMessage(cmd.message.author, grid_edit))
            grid_cont.times_edited += 1

        if grid_cont.wall_message == "":
            wall_channel = ewcfg.mines_wall_map.get(poi)
            resp_cont = EwResponseContainer(id_server=id_server)
            resp_cont.add_channel_response(wall_channel, grid_edit)
            msg_handles = await resp_cont.post()
            grid_cont.wall_message = msg_handles[0]
        else:
            await fe_utils.edit_message(cmd.client, grid_cont.wall_message,
                                        grid_edit)
Exemplo n.º 4
0
async def haunt(cmd):
    time_now = int(time.time())
    response = ""
    resp_cont = EwResponseContainer(id_server=cmd.guild.id)

    if cmd.mentions_count > 1:
        response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
    else:
        haunted_data = None
        member = None
        if cmd.mentions_count == 0 and cmd.tokens_count > 1:
            server = cmd.guild
            member = server.get_member(ewutils.getIntToken(cmd.tokens))
            haunted_data = EwUser(member=member)
        elif cmd.mentions_count == 1:
            member = cmd.mentions[0]
            haunted_data = EwUser(member=member)

        if member:
            # Get the user and target data from the database.
            user_data = EwUser(member=cmd.message.author)
            market_data = EwMarket(id_server=cmd.guild.id)
            target_mutations = haunted_data.get_mutations()
            target_poi = poi_static.id_to_poi.get(haunted_data.poi)
            target_is_shambler = haunted_data.life_state == ewcfg.life_state_shambler
            target_is_inhabitted = haunted_data.id_user == user_data.get_inhabitee(
            )

            if user_data.life_state != ewcfg.life_state_corpse:
                # Only dead players can haunt.
                response = "You can't haunt now. Try {}.".format(
                    ewcfg.cmd_suicide)
            elif haunted_data.life_state == ewcfg.life_state_kingpin:
                # Disallow haunting of generals.
                response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
            elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
                # Disallow haunting if the user has haunted too recently.
                response = "You're being a little TOO spooky lately, don't you think? Try again in {} seconds.".format(
                    int(ewcfg.cd_haunt -
                        (time_now - user_data.time_lasthaunt)))
            elif ewutils.channel_name_is_poi(
                    cmd.message.channel.name) == False:
                response = "You can't commit violence from here."
            elif target_poi.pvp == False:
                # Require the target to be in a PvP area, and flagged if it's a remote haunt
                response = "{} is not mired in the ENDLESS WAR right now.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_corpse:
                # Dead players can't be haunted.
                response = "{} is already dead.".format(member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_grandfoe:
                # Grand foes can't be haunted.
                response = "{} is invulnerable to ghosts.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_enlisted or haunted_data.life_state == ewcfg.life_state_juvenile or haunted_data.life_state == ewcfg.life_state_shambler:
                haunt_power_multiplier = 1

                # power to the ancients
                ghost_age = time_now - user_data.time_lastdeath
                if ghost_age > 60 * 60 * 24 * 7:  # dead for longer than
                    if ghost_age > 60 * 60 * 24 * 365:  # one friggin year
                        haunt_power_multiplier *= 2.5
                    if ghost_age > 60 * 60 * 24 * 90:  # three months
                        haunt_power_multiplier *= 2
                    elif ghost_age > 60 * 60 * 24 * 30:  # one month
                        haunt_power_multiplier *= 1.5
                    else:  # one week
                        haunt_power_multiplier *= 1.25

                # vitriol as virtue
                list_ids = []
                for quadrant in ewcfg.quadrant_ids:
                    quadrant_data = EwQuadrant(id_server=cmd.guild.id,
                                               id_user=cmd.message.author.id,
                                               quadrant=quadrant)
                    if quadrant_data.id_target != -1 and quadrant_data.check_if_onesided(
                    ) is False:
                        list_ids.append(quadrant_data.id_target)
                    if quadrant_data.id_target2 != -1 and quadrant_data.check_if_onesided(
                    ) is False:
                        list_ids.append(quadrant_data.id_target2)
                if haunted_data.id_user in list_ids:  # any mutual quadrants
                    haunt_power_multiplier *= 1.2
                if haunted_data.faction and (
                    (not user_data.faction) or
                    (user_data.faction != haunted_data.faction)
                ):  # opposite faction (or no faction at all)
                    haunt_power_multiplier *= 1.2
                if user_data.id_killer == haunted_data.id_user:  # haunting your murderer/buster
                    haunt_power_multiplier *= 1.2

                # places of power.
                if haunted_data.poi in [
                        ewcfg.poi_id_thevoid, ewcfg.poi_id_wafflehouse,
                        ewcfg.poi_id_blackpond
                ]:
                    haunt_power_multiplier *= 2
                elif haunted_data.poi in get_void_connection_pois(
                        cmd.guild.id):
                    haunt_power_multiplier *= 1.25

                # glory to the vanquished
                target_kills = ewstats.get_stat(user=haunted_data,
                                                metric=ewcfg.stat_kills)
                if target_kills > 5:
                    haunt_power_multiplier *= 1.25 + (
                        (target_kills - 5) / 100)  # 1% per kill after 5
                else:
                    haunt_power_multiplier *= 1 + (target_kills * 5 / 100
                                                   )  # 5% per kill

                if time_now - haunted_data.time_lastkill < (60 * 15):
                    haunt_power_multiplier *= 1.5  #  wet hands

                # misc
                if weather_static.weather_map.get(
                        market_data.weather) == ewcfg.weather_foggy:
                    haunt_power_multiplier *= 1.1
                if not haunted_data.has_soul:
                    haunt_power_multiplier *= 1.2
                # uncomment this after moon mechanics update
                # if (market_data.day % 31 == 15 and market_data.clock >= 20) or (market_data.day % 31 == 16 and market_data.clock <= 6):
                # 	haunt_power_multiplier *= 2

                # divide haunt power by 2 if not in same area
                if user_data.poi != haunted_data.poi:
                    haunt_power_multiplier /= 2

                # Double Halloween
                if ewcfg.dh_active:
                    haunt_power_multiplier *= 4

                haunted_slimes = int(
                    (haunted_data.slimes / ewcfg.slimes_hauntratio) *
                    haunt_power_multiplier)
                slimes_lost = int(
                    haunted_slimes / 5
                )  # hauntee only loses 1/5th of what the ghost gets as antislime

                if ewcfg.mutation_id_coleblooded in target_mutations:
                    haunted_slimes = -10000
                    if user_data.slimes > haunted_slimes:
                        haunted_slimes = user_data.slimes

                haunted_data.change_slimes(n=-slimes_lost,
                                           source=ewcfg.source_haunted)
                user_data.change_slimes(n=-haunted_slimes,
                                        source=ewcfg.source_haunter)
                market_data.negaslime -= haunted_slimes

                user_data.time_lasthaunt = time_now
                user_data.clear_status(id_status=ewcfg.status_busted_id)

                resp_cont.add_member_to_update(cmd.message.author)
                # Persist changes to the database.
                user_data.persist()
                haunted_data.persist()
                market_data.persist()

                response = "{} has been haunted by the ghost of {}! Slime has been lost! {} antislime congeals within you.".format(
                    member.display_name, cmd.message.author.display_name,
                    haunted_slimes)
                if ewcfg.mutation_id_coleblooded in target_mutations:
                    response = "{} has been haunted by the ghost of {}! Their exorcising coleslaw blood purges {} antislime from your being! Better not do that again.".format(
                        member.display_name, cmd.message.author.display_name,
                        -haunted_slimes)

                haunted_channel = poi_static.id_to_poi.get(
                    haunted_data.poi).channel
                haunt_message = "You feel a cold shiver run down your spine"
                if cmd.tokens_count > 2:
                    haunt_message_content = re.sub(
                        "<.+>" if cmd.mentions_count == 1 else "\d{17,}", "",
                        cmd.message.content[(len(cmd.tokens[0])):]).strip()
                    # Cut down really big messages so discord doesn't crash
                    if len(haunt_message_content) > 500:
                        haunt_message_content = haunt_message_content[:-500]
                    haunt_message += " and faintly hear the words \"{}\"".format(
                        haunt_message_content)
                haunt_message += ". {} slime evaporates from your body.".format(
                    slimes_lost)
                if ewcfg.mutation_id_coleblooded in target_mutations:
                    haunt_message += " The ghost that did it wails in agony as their ectoplasm boils in your coleslaw blood!"

                haunt_message = fe_utils.formatMessage(member, haunt_message)
                resp_cont.add_channel_response(haunted_channel, haunt_message)
        else:
            # No mentions, or mentions we didn't understand.
            response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

    # Send the response to the player.
    resp_cont.add_channel_response(cmd.message.channel.name, response)
    await resp_cont.post()
Exemplo n.º 5
0
    def move(self):
        resp_cont = EwResponseContainer(id_server=self.id_server)
        abs_x = abs(self.velocity[0])
        abs_y = abs(self.velocity[1])
        abs_sum = abs_x + abs_y
        if abs_sum == 0:
            return resp_cont

        if random.random() * abs_sum < abs_x:
            move = [self.velocity[0] / abs_x, 0]
        else:
            move = [0, self.velocity[1] / abs_y]

        move_vector = ewutils.EwVector2D(move)
        position_vector = ewutils.EwVector2D(self.coords)

        destination_vector = position_vector.add(move_vector)

        # global sb_games
        game_data = sports_utils.sb_games.get(self.id_game)

        player_data = EwPlayer(id_user=self.id_user)
        response = ""
        ball_contact = False
        for i in range(-1, 2):
            for j in range(-1, 2):
                neighbor_direction = [i, j]
                neighbor_vector = ewutils.EwVector2D(neighbor_direction)
                if move_vector.scalar_product(neighbor_vector) > 0:
                    neighbor_position = position_vector.add(neighbor_vector)
                    if neighbor_position.vector == game_data.ball_coords:
                        ball_contact = True
                        break

        if ball_contact:
            game_data.ball_velocity = [
                round(5 * self.velocity[0]),
                round(5 * self.velocity[1])
            ]
            game_data.last_contact = self.id_player
            self.velocity = [0, 0]
            response = "{} has kicked the ball in direction {}!".format(
                player_data.display_name, game_data.ball_velocity)

        elif game_data.coords_free(destination_vector.vector):
            self.coords = destination_vector.vector

        elif game_data.out_of_bounds(destination_vector.vector):
            self.velocity = [0, 0]
            response = "{} has walked against the outer bounds and stopped at {}.".format(
                player_data.display_name, self.coords)
        else:
            vel = self.velocity

            for p in game_data.players:
                if p.coords == destination_vector.vector:
                    self.velocity = p.velocity
                    p.velocity = vel
                    other_player_data = EwPlayer(id_user=p.id_user)
                    response = "{} has collided with {}.".format(
                        player_data.display_name,
                        other_player_data.display_name)
                    break

        if len(response) > 0:
            poi_data = poi_static.id_to_poi.get(game_data.poi)
            resp_cont.add_channel_response(poi_data.channel, response)

        return resp_cont
Exemplo n.º 6
0
    def move_ball(self):
        resp_cont = EwResponseContainer(id_server=self.id_server)
        abs_x = abs(self.ball_velocity[0])
        abs_y = abs(self.ball_velocity[1])
        abs_sum = abs_x + abs_y
        if abs_sum == 0:
            return resp_cont

        move = [self.ball_velocity[0], self.ball_velocity[1]]
        whole_move_vector = ewutils.EwVector2D(move)

        response = ""
        while abs_sum != 0:
            if random.random() * abs_sum < abs_x:
                part_move = [move[0] / abs_x, 0]
            else:
                part_move = [0, move[1] / abs_y]

            move_vector = ewutils.EwVector2D(part_move)
            position_vector = ewutils.EwVector2D(self.ball_coords)

            destination_vector = position_vector.add(move_vector)

            player_contact = False
            for i in range(-1, 2):
                for j in range(-1, 2):
                    neighbor_direction = [i, j]
                    neighbor_vector = ewutils.EwVector2D(neighbor_direction)
                    if move_vector.scalar_product(neighbor_vector) > 0:
                        neighbor_position = position_vector.add(
                            neighbor_vector)
                        player = self.player_at_coords(
                            neighbor_position.vector)
                        if player != -1:
                            self.ball_velocity = [0, 0]
                            self.last_contact = player
                            player_contact = True
                            break

            if player_contact:
                break

            elif self.coords_free(destination_vector.vector):
                self.ball_coords = destination_vector.vector
            elif self.out_of_bounds(destination_vector.vector):
                for i in range(2):
                    if part_move[i] != 0:
                        whole_move_vector.vector[i] *= -1
                        self.ball_velocity[i] *= -1

            if self.is_goal():

                global sb_slimeballerid_to_player

                scoring_player = sb_slimeballerid_to_player.get(
                    self.last_contact)
                if scoring_player != None:
                    player_data = EwPlayer(id_user=scoring_player.id_user)
                else:
                    player_data = None

                if self.is_goal_purple():

                    if player_data != None:
                        response = "{} scored a goal for the pink team!".format(
                            player_data.display_name)
                    else:
                        response = "The pink team scored a goal!"
                    self.score_pink += 1
                elif self.is_goal_pink():

                    if player_data != None:
                        response = "{} scored a goal for the purple team!".format(
                            player_data.display_name)
                    else:
                        response = "The purple team scored a goal!"
                    self.score_purple += 1

                self.ball_velocity = [0, 0]
                self.ball_coords = get_starting_position("")
                self.last_contact = -1
                break

            else:
                whole_move_vector = whole_move_vector.subtract(move_vector)
                abs_x = abs(whole_move_vector.vector[0])
                abs_y = abs(whole_move_vector.vector[1])
                abs_sum = abs_x + abs_y
                move = whole_move_vector.vector

        for i in range(2):
            if self.ball_velocity[i] > 0:
                self.ball_velocity[i] -= 1
            elif self.ball_velocity[i] < 0:
                self.ball_velocity[i] += 1

        if len(response) > 0:
            poi_data = poi_static.id_to_poi.get(self.poi)
            resp_cont.add_channel_response(poi_data.channel, response)

        return resp_cont
Exemplo n.º 7
0
async def browse_zines(cmd):
    if len(cmd.tokens) > 1:
        sort_token = cmd.tokens[1].replace("_", "")

    else:
        sort_token = "null"

    user_data = EwUser(member=cmd.message.author)
    poi = poi_static.id_to_poi.get(user_data.poi)

    if poi.is_apartment:
        return await apt_cmds.browse(cmd)

    if not poi.write_manuscript:
        response = "You can't browse for zines here! Try going to the cafe. If you're looking for educational zines, try the colleges. If you can't read, then you might want to try the comic shop."

        await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    else:
        if not sort_token.isdigit():
            book_list = []
            resp_cont = EwResponseContainer(id_server=cmd.guild.id)
            query_suffix = ""
            query_sort = "id_book"
            more_selects = ""
            quality = "= 1"

            if user_data.poi in ["nlac-university", "neo-milwaukee-state"]:
                query_suffix = "AND b.genre = 1 "

            elif user_data.poi in ["glocksbury-comics"]:
                query_suffix = "AND b.genre = 2 "

            elif user_data.poi in [ewcfg.poi_id_clinicofslimoplasty]:
                query_suffix = "AND b.genre = 10 "

            if sort_token in ("bookname", "name", "title", "booktitle", "zinename", "zinetitle"):
                query_sort = "title"

            elif sort_token in ("author", "authorname", "artist", "artistname", "illustrator"):
                query_sort = "author"

            elif sort_token in ("date", "datepublished", "day", "time", "published", "publish", "publishdate"):
                query_sort = "date_published"
                more_selects = ", b.date_published"

            elif sort_token in ewcfg.book_genres:
                genre = ""

                for i in [i for i, x in enumerate(ewcfg.book_genres) if x == sort_token]:
                    genre = i

                query_suffix = "AND b.genre = {} ".format(genre)

            elif sort_token in ('reverse', 'inverse', 'descend', 'desc', 'descending', 'backwards'):
                query_sort += " DESC"

            elif sort_token in ('length', 'len', 'pages', 'long', 'longest'):
                query_sort = "length DESC"
                more_selects = ", b.length"

            elif sort_token in ('sales', 'sale', 'sell', 'bestsellers', 'topsellers', 'bestselling'):
                query_sort = "sales DESC"
                more_selects = ", b.sales"

            elif sort_token in ('rating', 'quality', 'ratings', 'rate', 'f***s', 'rate', 'f**k', 'toprated', 'best', 'highestrated'):
                query_sort = "rating DESC, rates DESC"
                more_selects = ", b.rating, b.rates"

            elif sort_token in ('bad', 'terrible', 'shit', 'shitty', 'worst', 'worstrated', 'bottom'):
                quality = "= 2"

            elif sort_token in ('all', 'every'):
                quality = "> 0"
                query_suffix = ""
                query_sort = "id_book"
                more_selects = ""

            if len(cmd.tokens) > 2:
                if cmd.tokens[2] in ('reverse', 'inverse', 'descend', 'desc', 'descending', 'backwards'):
                    if not query_sort.endswith(" DESC"):
                        query_sort += " DESC"

                    else:
                        query_sort = query_sort[:len(query_sort) - 5] + " ASC"
            try:
                conn_info = bknd_core.databaseConnect()
                conn = conn_info.get('conn')
                cursor = conn.cursor()

                cursor.execute((
                        "SELECT b.id_book, b.title, b.author{} ".format(more_selects) +
                        "FROM books AS b " +
                        "WHERE b.id_server = %s AND b.book_state {} {}".format(quality, query_suffix) +
                        "ORDER BY b.{}".format(query_sort)
                ), (
                    cmd.guild.id,
                ))

                data = cursor.fetchall()
                if data != None:
                    for row in data:
                        more_info = ""

                        if query_sort.startswith("date_published"):
                            more_info = " (Published on day {})".format(row[3])

                        elif query_sort.startswith("length"):
                            more_info = " (Length: {} characters)".format(row[3])

                        elif query_sort.startswith("sales"):
                            more_info = " (Sales: {} copies)".format(row[3])

                        elif query_sort.startswith("rating"):
                            if row[3] == '0' and row[4] == 0:
                                more_info = " (Rating: No f***s given yet)"

                            else:
                                more_info = " (Rating: {} f***s across {} ratings)".format(row[3], row[4])

                        book_list.append("\n{}: {} by {}{}".format(
                            row[0],
                            row[1].replace("`", "").replace("\n", ""),
                            row[2].replace("`", "").replace("\n", ""),
                            more_info,
                        ))

            finally:
                # Clean up the database handles.
                cursor.close()
                bknd_core.databaseClose(conn_info)

            if len(book_list) != 0:
                resp_num = 0
                resp_count = 0
                resp_list = []

                # weird looking loop (i assure you it works tho)
                for book in book_list:
                    resp_count += 1

                    if len(resp_list) != resp_num + 1:
                        resp_list.append("")
                    resp_list[resp_num] += book

                    if resp_count == 10:
                        resp_count = 0
                        resp_num += 1

                for resp_block in resp_list:
                    resp_cont.add_channel_response(cmd.message.channel.name, resp_block)

                # Send the response to the player.
                resp_cont.format_channel_response(cmd.message.channel.name, cmd.message.author)

                await resp_cont.post(channel=cmd.message.channel)
            else:
                response = "There aren't any zines in circulation at the moment."

                await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
        else:
            id_book = int(sort_token)

            if int_is_zine(id_book, cmd.guild.id):
                book = EwBook(id_book=id_book)
                title = book.title
                author = book.author
                genre = ewcfg.book_genres[book.genre]

                response = "\n{} is a {} zine by {}.\n".format(title, genre, author)

                cover = book.book_pages.get(0, "")
                pages = book.pages
                length = book.length
                date = book.date_published

                response += "It is {} pages and {:,} characters long and was published on Day {}. ".format(pages, length, date)

                sales = book.sales
                rating = book.rating
                rates = book.rates

                if sales == 0:
                    response += "It has not yet been bought by anyone.\n"

                else:
                    response += "It has sold {:,} copies.\n".format(sales)

                if rates == 0:
                    response += "Nobody has given it any f***s.\n"

                else:
                    response += "It has received {} ratings with an average of {} f***s given out of 5.\n".format(rates, rating)

                if cover != "":
                    if genre == "p**n":
                        response += "The cover looks like this: ||{}||".format(cover)
                    else:
                        response += "The cover looks like this: {}".format(cover)

            else:
                response = "That's not a valid zine ID."

            await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Exemplo n.º 8
0
async def disembark(cmd):
    # can only use movement commands in location channels
    if ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You must {} in a zone's channel.".format(cmd.tokens[0])))
    user_data = EwUser(member=cmd.message.author)
    response = ""
    resp_cont = EwResponseContainer(client=cmd.client, id_server=user_data.id_server)

    # prevent ghosts currently inhabiting other players from moving on their own
    if user_data.get_inhabitee():
        response = "You might want to **{}** of the poor soul you've been tormenting first.".format(ewcfg.cmd_letgo)
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    # can only disembark when you're on a transport vehicle
    elif user_data.poi in poi_static.transports:
        transport_data = EwTransport(id_server=user_data.id_server, poi=user_data.poi)
        response = "{}ing.".format(cmd.tokens[0][1:].lower()).capitalize()

        stop_poi = poi_static.id_to_poi.get(transport_data.current_stop)
        # if stop_poi.is_subzone:
        # 	stop_poi = poi_static.id_to_poi.get(stop_poi.mother_district)

        if move_utils.inaccessible(user_data=user_data, poi=stop_poi):
            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You're not allowed to go there (bitch)."))

        # schedule tasks for concurrent execution
        message_task = asyncio.ensure_future(fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)))
        wait_task = asyncio.ensure_future(asyncio.sleep(ewcfg.time_embark))

        # Take control of the move for this player.
        move_utils.move_counter += 1
        move_current = ewutils.moves_active[cmd.message.author.id] = move_utils.move_counter
        await message_task
        await wait_task

        # check if the user entered another movement command while waiting for the current one to be completed
        if move_current != ewutils.moves_active[cmd.message.author.id]:
            return

        user_data = EwUser(member=cmd.message.author)
        transport_data = EwTransport(id_server=user_data.id_server, poi=transport_data.poi)

        # cancel move, if the user has left the transport while waiting for movement to be completed (e.g. by dying)
        if user_data.poi != transport_data.poi:
            return

        stop_poi = poi_static.id_to_poi.get(transport_data.current_stop)

        # juvies can't swim
        if transport_data.current_stop == ewcfg.poi_id_slimesea and user_data.life_state != ewcfg.life_state_corpse:
            if user_data.life_state == ewcfg.life_state_kingpin:
                response = "You try to heave yourself over the railing as you're hit by a sudden case of sea sickness. You puke into the sea and sink back on deck."
                response = fe_utils.formatMessage(cmd.message.author, response)
                return await fe_utils.send_message(cmd.client, cmd.message.channel, response)
            user_data.poi = ewcfg.poi_id_slimesea
            user_data.trauma = ewcfg.trauma_id_environment
            die_resp = user_data.die(cause=ewcfg.cause_drowning)
            user_data.persist()
            resp_cont.add_response_container(die_resp)

            response = "{} jumps over the railing of the ferry and promptly drowns in the slime sea.".format(cmd.message.author.display_name)
            resp_cont.add_channel_response(channel=ewcfg.channel_slimesea, response=response)
            resp_cont.add_channel_response(channel=ewcfg.channel_ferry, response=response)
            await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
        # they also can't fly

        elif transport_data.transport_type == ewcfg.transport_type_blimp and not stop_poi.is_transport_stop and user_data.life_state != ewcfg.life_state_corpse:
            user_mutations = user_data.get_mutations()
            if user_data.life_state == ewcfg.life_state_kingpin:
                response = "Your life flashes before your eyes, as you plummet towards your certain death. A lifetime spent being a piece of shit and playing videogames all day. You close your eyes and... BOING! You open your eyes again to see a crew of workers transporting the trampoline that broke your fall. You get up and dust yourself off, sighing heavily."
                response = fe_utils.formatMessage(cmd.message.author, response)
                resp_cont.add_channel_response(channel=stop_poi.channel, response=response)
                user_data.poi = stop_poi.id_poi
                user_data.persist()
                await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
                return await resp_cont.post()

            elif ewcfg.mutation_id_lightasafeather in user_mutations or ewcfg.mutation_id_airlock in user_mutations:
                response = "With a running jump you launch yourself out of the blimp and begin falling to your soon-to-be demise... but then a strong updraft breaks your fall and you land unscathed. "
                response = fe_utils.formatMessage(cmd.message.author, response)
                resp_cont.add_channel_response(channel=stop_poi.channel, response=response)
                user_data.poi = stop_poi.id_poi
                user_data.persist()
                await user_data.move_inhabitants(id_poi=stop_poi.id_poi)
                await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
                return await resp_cont.post()
            district_data = EwDistrict(id_server=user_data.id_server, district=stop_poi.id_poi)
            district_data.change_slimes(n=user_data.slimes)
            district_data.persist()
            user_data.poi = stop_poi.id_poi
            user_data.trauma = ewcfg.trauma_id_environment
            die_resp = user_data.die(cause=ewcfg.cause_falling)
            user_data.persist()
            resp_cont.add_response_container(die_resp)
            response = "SPLAT! A body collides with the asphalt with such force, that it is utterly annihilated, covering bystanders in blood and slime and guts."
            resp_cont.add_channel_response(channel=stop_poi.channel, response=response)
            await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)

        # update user location, if move successful
        else:
            # if stop_poi.is_subzone:
            # 	stop_poi = poi_static.id_to_poi.get(stop_poi.mother_district)

            if move_utils.inaccessible(user_data=user_data, poi=stop_poi):
                return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You're not allowed to go there (bitch)."))

            user_data.poi = stop_poi.id_poi
            user_data.persist()
            await user_data.move_inhabitants(id_poi=stop_poi.id_poi)
            response = "You enter {}".format(stop_poi.str_name)
            await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
            await fe_utils.send_message(cmd.client, fe_utils.get_channel(cmd.guild, stop_poi.channel), fe_utils.formatMessage(cmd.message.author, response))

            # SWILLDERMUK
            await prank_utils.activate_trap_items(stop_poi.id_poi, user_data.id_server, user_data.id_user)

            return
        return await resp_cont.post()
    else:
        response = "You are not currently riding any transport."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))