Пример #1
0
 def test_getIntToken(self):
     self.assertEqual(ewutils.getIntToken([]), None)
     self.assertEqual(ewutils.getIntToken(['test']), None)
     self.assertEqual(ewutils.getIntToken(['1']), None)
     self.assertEqual(ewutils.getIntToken(['1', '2']), 2)
     self.assertEqual(ewutils.getIntToken(['2', '1,200']), 1200)
     self.assertEqual(ewutils.getIntToken(['1', 'test', '2']), 2)
     self.assertEqual(ewutils.getIntToken(['test', '-1']), None)
     self.assertEqual(
         ewutils.getIntToken(['test', 'all', '-1'], negate=True), 1)
     self.assertEqual(
         ewutils.getIntToken(['test', 'all', '2'], allow_all=True), -1)
     self.assertEqual(
         ewutils.getIntToken(['test', '2', 'all'], allow_all=True), 2)
Пример #2
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()
Пример #3
0
async def withdraw(cmd):
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    time_now = round(time.time())
    market_data = EwMarket(id_server=cmd.message.author.guild.id)

    if market_data.clock < 6 or market_data.clock >= 20:
        response = ewcfg.str_exchange_closed
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if cmd.message.channel.name != ewcfg.channel_stockexchange:  # or user_data.poi != ewcfg.poi_id_downtown:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin", action="withdraw")
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    poi = poi_static.id_to_poi.get(user_data.poi)
    district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

    if district_data.is_degraded():
        response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow withdraws from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    else:
        value = None
        stock = None

        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(cmd.tokens[1:], allow_all=True)

            for token in cmd.tokens[1:]:
                if token.lower() in ewcfg.stocks:
                    stock = token.lower()
                    break

        if stock != None:
            stock = EwStock(id_server=cmd.guild.id, stock=stock)

            total_shares = market_utils.getUserTotalShares(id_server=user_data.id_server, stock=stock.id_stock, id_user=user_data.id_user)

            if value != None:
                if value < 0:
                    value = total_shares
                if value <= 0:
                    value = None

            if value != None:

                if value <= total_shares:
                    exchange_rate = (stock.exchange_rate / 1000.0)

                    shares = value
                    slimecoin = round(value * exchange_rate)

                    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                        # Limit frequency of withdrawals
                        response = ewcfg.str_exchange_busy.format(action="withdraw")
                    else:
                        user_data.change_slimecoin(n=slimecoin, coinsource=ewcfg.coinsource_withdraw)
                        total_shares -= shares
                        user_data.time_lastinvest = time_now
                        stock.total_shares -= shares

                        response = "You exchange {shares:,} shares in {stock} for {coins:,} SlimeCoin.".format(coins=slimecoin, shares=shares, stock=ewcfg.stock_names.get(stock.id_stock))
                        user_data.persist()
                        stock.timestamp = round(time.time())
                        stock.persist()
                        market_utils.updateUserTotalShares(id_server=user_data.id_server, stock=stock.id_stock, id_user=user_data.id_user, shares=total_shares)
                else:
                    response = "You don't have that many shares in {stock} to exchange.".format(stock=ewcfg.stock_names.get(stock.id_stock))
            else:
                response = ewcfg.str_exchange_specify.format(currency="SlimeCoin", action="withdraw")
        else:
            response = "That's not a valid stock name, please use a proper one, you c**t: {}".format(ewutils.formatNiceList(names=ewcfg.stocks))

    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #4
0
async def invest(cmd):
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    time_now = round(time.time())
    market_data = EwMarket(id_server=cmd.message.author.guild.id)

    if cmd.message.channel.name != ewcfg.channel_stockexchange:  # or user_data.poi != ewcfg.poi_id_downtown:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin", action="invest")
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    poi = poi_static.id_to_poi.get(user_data.poi)
    district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

    if district_data.is_degraded():
        response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if market_data.clock < 6 or market_data.clock >= 20:
        response = ewcfg.str_exchange_closed
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
        # Limit frequency of investments.
        response = ewcfg.str_exchange_busy.format(action="invest")
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow invests from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_kingpin:
        # Disallow investments by RF and CK kingpins.
        response = "You need that money to buy more videogames."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    else:
        value = None
        stock = None

        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(cmd.tokens, allow_all=True)

            for token in cmd.tokens[1:]:
                if token.lower() in ewcfg.stocks:
                    stock = token.lower()
                    break

        if value != None:
            if value < 0:
                value = user_data.slimecoin
            if value <= 0:
                value = None

        if value != None:
            if stock != None:

                stock = EwStock(id_server=cmd.guild.id, stock=stock)
                # basic exchange rate / 1000 = 1 share
                exchange_rate = (stock.exchange_rate / 1000.0)

                cost_total = round(value * 1.05)

                # gets the highest value possible where the player can still pay the fee
                if value == user_data.slimecoin:
                    while cost_total > user_data.slimecoin:
                        value -= cost_total - value
                        cost_total = round(value * 1.05)

                # The user can only buy a whole number of shares, so adjust their cost based on the actual number of shares purchased.
                net_shares = round(value / exchange_rate)

                if user_data.slimecoin < cost_total:
                    response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(user_data.slimecoin, cost_total)

                elif value > user_data.slimecoin:
                    response = "You don't have that much SlimeCoin to invest."

                elif net_shares == 0:
                    response = "You don't have enough SlimeCoin to buy a share in {stock}".format(stock=ewcfg.stock_names.get(stock.id_stock))

                else:
                    user_data.change_slimecoin(n=-cost_total, coinsource=ewcfg.coinsource_invest)
                    shares = market_utils.getUserTotalShares(id_server=user_data.id_server, stock=stock.id_stock, id_user=user_data.id_user)
                    shares += net_shares
                    market_utils.updateUserTotalShares(id_server=user_data.id_server, stock=stock.id_stock, id_user=user_data.id_user, shares=shares)
                    user_data.time_lastinvest = time_now

                    stock.total_shares += net_shares
                    response = "You invest {coin:,} SlimeCoin and receive {shares:,} shares in {stock}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(coin=value, shares=net_shares, stock=ewcfg.stock_names.get(stock.id_stock), fee=(cost_total - value))

                    user_data.persist()
                    stock.timestamp = round(time.time())
                    stock.persist()

            else:
                response = "That's not a valid stock name, please use a proper one, you c**t: {}".format(ewutils.formatNiceList(names=ewcfg.stocks))

        else:
            response = ewcfg.str_exchange_specify.format(currency="SlimeCoin", action="invest")

    # Send the response to the player.
    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #5
0
async def xfer(cmd):
    time_now = round(time.time())
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin", action="transfer")
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    poi = poi_static.id_to_poi.get(user_data.poi)
    district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

    if district_data.is_degraded():
        response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if cmd.mentions_count != 1:
        # Must have exactly one target to send to.
        response = "Mention the player you want to send SlimeCoin to."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
        # Limit frequency of transfers
        response = ewcfg.str_exchange_busy.format(action="transfer slimecoin")
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow transfers from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    member = cmd.mentions[0]
    target_data = EwUser(member=member)

    if target_data.life_state == ewcfg.life_state_kingpin:
        # Disallow transfers to RF and CK kingpins.
        response = "You can't transfer SlimeCoin to a known criminal warlord."
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    market_data = EwMarket(id_server=cmd.message.author.guild.id)

    if cmd.message.author.id == member.id:
        slimes_total = user_data.slimes
        slimes_drained = int(slimes_total * 0.1)
        slimes_todistrict = slimes_total - slimes_drained

        sewer_data = EwDistrict(district=ewcfg.poi_id_thesewers, id_server=user_data.id_server)
        sewer_data.change_slimes(n=slimes_drained)
        sewer_data.persist()

        district_data = EwDistrict(district=user_data.poi, id_server=cmd.guild.id)
        district_data.change_slimes(n=slimes_todistrict, source=ewcfg.source_killing)
        district_data.persist()

        # Set the id_killer to the player himself, remove his slime and slime poudrins.
        user_data.id_killer = cmd.message.author.id
        user_data.visiting = ewcfg.location_id_empty
        user_data.trauma = ewcfg.trauma_id_environment

        user_data.die(cause=ewcfg.cause_suicide)
        user_data.persist()

        await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "Gaming the slimeconomy is punishable by death. SlimeCorp soldiers execute you immediately."))
        await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
        return

    # Parse the slime value to send.
    value = None
    if cmd.tokens_count > 1:
        value = ewutils.getIntToken(tokens=cmd.tokens)

    if value != None:
        if value < 0:
            value = user_data.slimes
        if value <= 0:
            value = None

    if value != None:
        # Cost including the transfer fee.
        cost_total = round(value * 1.1)

        if user_data.slimecoin < cost_total:
            response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(user_data.slimecoin, cost_total)
        else:
            # Do the transfer if the player can afford it.
            target_data.change_slimecoin(n=value, coinsource=ewcfg.coinsource_transfer)
            user_data.change_slimecoin(n=-cost_total, coinsource=ewcfg.coinsource_transfer)
            user_data.time_lastinvest = time_now

            # Persist changes
            response = "You transfer {slime:,} SlimeCoin to {target_name}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(slime=value, target_name=member.display_name, fee=(cost_total - value))

            target_data.persist()
            user_data.persist()
    else:
        response = ewcfg.str_exchange_specify.format(currency="SlimeCoin", action="transfer")

    # Send the response to the player.
    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #6
0
async def donate(cmd):
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    market_data = EwMarket(id_server=user_data.id_server)

    time_now = round(time.time())

    if user_data.poi == ewcfg.poi_id_slimecorphq:
        poi = poi_static.id_to_poi.get(user_data.poi)
        district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

        if district_data.is_degraded():
            response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimes
            if value <= 0:
                value = None

        if value != None and value < ewcfg.slimecoin_exchangerate:
            response = "You must volunteer to donate at least %d slime to receive compensation." % ewcfg.slimecoin_exchangerate

        elif value != None:
            # Amount of slime invested.
            cost_total = round(value)
            coin_total = round(value / ewcfg.slimecoin_exchangerate)

            if user_data.slimes < cost_total:
                response = "Acid-green flashes of light and bloodcurdling screams emanate from small window of SlimeCorp HQ. Unfortunately, you did not survive the procedure. Your body is dumped down a disposal chute to the sewers."
                market_data.donated_slimes += user_data.slimes
                market_data.persist()
                user_data.trauma = ewcfg.trauma_id_environment
                die_resp = user_data.die(cause=ewcfg.cause_donation)
                user_data.persist()
                # Assign the corpse role to the player. He dead.
                await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
                await die_resp.post()
            else:
                # Do the transfer if the player can afford it.
                market_data.donated_slimes += cost_total
                market_data.persist()
                user_data.change_slimes(n=-cost_total, source=ewcfg.source_spending)
                user_data.change_slimecoin(n=coin_total, coinsource=ewcfg.coinsource_donation)
                user_data.slime_donations += cost_total

                # Persist changes
                user_data.persist()

                response = "You stumble out of a Slimecorp HQ vault room in a stupor. You don't remember what happened in there, but your body hurts and you've got {slimecoin:,} shiny new SlimeCoin in your pocket.".format(slimecoin=coin_total)

        else:
            response = ewcfg.str_exchange_specify.format(currency="slime", action="donate")

    elif user_data.poi == ewcfg.poi_id_slimeoidlab:
        poi = poi_static.id_to_poi.get(user_data.poi)
        district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

        if district_data.is_degraded():
            response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

        poudrins = bknd_item.find_item(item_search="slimepoudrin", id_user=cmd.message.author.id, id_server=cmd.guild.id if cmd.guild is not None else None, item_type_filter=ewcfg.it_item)

        if poudrins == None:
            response = "You have to own a poudrin in order to donate a poudrin. Duh."

        else:
            bknd_item.item_delete(id_item=poudrins.get('id_item'))  # Remove Poudrins
            market_data.donated_poudrins += 1
            market_data.persist()
            user_data.poudrin_donations += 1
            user_data.persist()

            response = "You hand off one of your hard-earned poudrins to the front desk receptionist, who is all too happy to collect it. Pretty uneventful, but at the very least you’re glad donating isn’t physically painful anymore."

    else:
        response = "To donate slime, go to the SlimeCorp HQ in Downtown. To donate poudrins, go to the N.L.A.C.U. Lab in Brawlden."

    # Send the response to the player.
    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #7
0
async def incubate_slimeoid(cmd):
    user_data = EwUser(member=cmd.message.author)
    slimeoid_data = EwSlimeoid(member=cmd.message.author)

    if cmd.message.channel.name != ewcfg.channel_slimeoidlab:
        response = "You must go to the NLACU Laboratories in Brawlden to create a Slimeoid."
        # Go to final response

    elif user_data.life_state == ewcfg.life_state_corpse:
        response = "Ghosts cannot interact with the NLACU Lab apparati."
        # Go to final response

    #TODO: change this because player can have more than one slimeoid now
    # this is f*****g brutal. poor slimeoid
    elif slimeoid_data.life_state == ewcfg.slimeoid_state_active:
        response = "You have already created a Slimeoid. Bottle or dissolve your current slimeoid before incubating a new one."
        # Go to final response

    elif slimeoid_data.life_state == ewcfg.slimeoid_state_forming:
        response = "You are already in the process of incubating a Slimeoid."
        # Go to final response

    else:

        #Check if player has too many slimeoids
        slimeoid_count = get_slimeoid_count(user_id=cmd.message.author.id,
                                            server_id=cmd.guild.id)

        if slimeoid_count >= 3:
            response = "You have too many slimeoids."
            # Go to final response

        else:
            #Check if player has a poudrin
            poudrin = bknd_item.find_item(
                item_search=ewcfg.item_id_slimepoudrin,
                id_user=cmd.message.author.id,
                id_server=cmd.guild.id if cmd.guild is not None else None,
                item_type_filter=ewcfg.it_item)
            if poudrin is None:
                response = "You need a slime poudrin."
                # Go to final response

            else:
                # Get arguement for how big the slimeoid should be made
                injected_slime = None
                if cmd.tokens_count > 1:
                    injected_slime = ewutils.getIntToken(tokens=cmd.tokens,
                                                         allow_all=True)
                    # -1 from getIntToken() means use all slime
                    if injected_slime == -1:
                        injected_slime = user_data.slimes

                if injected_slime == None:
                    response = "You must contribute some of your own slime to create a Slimeoid. Specify how much slime you will sacrifice."
                    # Go to final response

                elif injected_slime > user_data.slimes:
                    response = "You do not have that much slime to sacrifice."
                    # Go to final response

                else:
                    # delete a slime poudrin from the player's inventory
                    bknd_item.item_delete(id_item=poudrin.get('id_item'))

                    # Remove slime
                    user_data.change_slimes(n=-injected_slime)

                    # Setup gestating slimeoid
                    level = len(str(injected_slime))
                    slimeoid_data.life_state = ewcfg.slimeoid_state_forming
                    slimeoid_data.level = level
                    slimeoid_data.id_user = str(user_data.id_user)
                    slimeoid_data.id_server = user_data.id_server

                    # Save changes
                    slimeoid_data.persist()
                    user_data.persist()

                    response = "You place a poudrin into a small opening on the console. As you do, a needle shoots up and pricks your finger, intravenously extracting {injected_slime:,} slime from your body. The poudrin is then dropped into the gestation tank. Looking through the observation window, you see what was once your slime begin to seep into the tank and accrete around the poudrin. The incubation of a new Slimeoid has begun! {slime_emote}".format(
                        injected_slime=injected_slime,
                        slime_emote=ewcfg.emote_slime2)
                    # Go to final response

    # Final response
    await send_response(response, cmd)
Пример #8
0
async def incubate_negaslimeoid(cmd):
    user_data = EwUser(member=cmd.message.author)
    slimeoid_data = EwSlimeoid(member=cmd.message.author)

    # Check for if the player is a corpse
    if user_data.life_state != ewcfg.life_state_corpse:
        if cmd.message.channel.name == ewcfg.channel_wafflehouse:
            response = "You feel as though there is some ancient power here, but the slime coursing through your veins prevents you from using it."
        else:
            response = "Huh? What'd you say?"

    # Check for if the player is at Waffle House
    elif cmd.message.channel.name != ewcfg.channel_wafflehouse:
        response = "You can't exactly summon anything in {}. Go to Waffle House first.".format(
            cmd.message.channel.name)

    # Check if the player already has a Slimeoid or a Negaslimeoid.
    elif slimeoid_data.life_state == ewcfg.slimeoid_state_active:
        if slimeoid_data.sltype == ewcfg.sltype_nega:
            response = "You already have a Negaslimeoid by your side. Destroy your current Negaslimeoid before you commune with the Ancient Ones yet again."
        else:
            response = "You wish to summon a Negaslimeoid, yet you have a Slimeoid that still calls you its master. !destroyslimeoid if you wish to commune with the Ancient Ones properly."

    # Check if the player is already incubating a Slimeoid or Negaslimeoid
    elif slimeoid_data.life_state == ewcfg.slimeoid_state_forming:
        if slimeoid_data.sltype == ewcfg.sltype_nega:
            response = "You are already in the process of conjuring a Negaslimeoid."
        else:
            response = "You wish to summon a Negaslimeoid, yet you have a Slimeoid that is still yet to call you its master. !destroyslimeoid if you wish to commune with the Ancient Ones properly."

    else:

        #Check if player has too many slimeoids
        slimeoid_count = get_slimeoid_count(user_id=cmd.message.author.id,
                                            server_id=cmd.guild.id)

        if slimeoid_count >= 3:
            response = "You have too many slimeoids."
            # Go to final response

        else:
            #Check if player has a negapoudrin
            negapoudrin = bknd_item.find_item(
                item_search=ewcfg.item_id_negapoudrin,
                id_user=cmd.message.author.id,
                id_server=cmd.guild.id if cmd.guild is not None else None,
                item_type_filter=ewcfg.it_item)
            if negapoudrin is None:
                response = "You need a negapoudrin to bind a Negaslimeoid to your command."
                # Go to final response

            else:
                # Get argument for how big the negaslimeoid should be made
                sacrificed_negaslime = None
                if cmd.tokens_count > 1:
                    # -1 from getIntToken() could possibly be gotten from player input, so do a check here.
                    if cmd.tokens[1] == "all":
                        if user_data.slimes < 0:
                            sacrificed_negaslime = -user_data.slimes

                    else:
                        print(cmd.tokens[0])
                        sacrificed_negaslime = ewutils.getIntToken(
                            tokens=cmd.tokens)
                        if sacrificed_negaslime < 0:
                            sacrificed_negaslime = -sacrificed_negaslime

                # Check if player sacrificed any negaslime or if they have enough to sacrifice.
                if sacrificed_negaslime == None:
                    response = "You must sacrifice your own negaslime to conjure a Negaslimeoid. Specify how much negaslime you will sacrifice."
                    # Go to final response

                elif -sacrificed_negaslime < user_data.slimes:
                    response = "You do not have that much negaslime to sacrifice."
                    # Go to final response

                else:
                    # delete a negapoudrin from the player's inventory
                    bknd_item.item_delete(id_item=negapoudrin.get('id_item'))

                    # Remove negaslime
                    user_data.change_slimes(n=+sacrificed_negaslime)

                    # Establish these stats for conjuring the negaslimeoid
                    level = len(str(sacrificed_negaslime))
                    slimeoid_data.life_state = ewcfg.slimeoid_state_forming
                    slimeoid_data.level = level
                    slimeoid_data.sltype = ewcfg.sltype_nega
                    slimeoid_data.hue = ewcfg.hue_id_negative
                    slimeoid_data.id_user = str(user_data.id_user)
                    slimeoid_data.id_server = user_data.id_server

                    # Save changes
                    slimeoid_data.persist()
                    user_data.persist()

                    response = "Floating in front of the Ouija® Board, you place both of your ghastly appendages on the planchette. {sacrificed_negaslime:,} negaslime rises from your body, flowing towards your negapoudrin. The negapoudrin appears to lift into the air, held up by a pool of rising negaslime. Whispers awake around you, indiscernible and unknowable. It feels as though the planchette beneath your ghastly fingers has more than one set of hands on it. \n\nThe conjuration of a Negaslimeoid has begun! {negaslime_emote}".format(
                        sacrificed_negaslime=sacrificed_negaslime,
                        negaslime_emote=ewcfg.emote_negaslime)
                    # Go to final response

    # Final response
    await send_response(response, cmd)
Пример #9
0
async def rate_zine(cmd):
    if len(cmd.tokens) < 2:
        response = "What zine do you want to rate?"

    else:
        if len(cmd.tokens) >= 3:
            rating = ewutils.getIntToken(cmd.tokens)
            book_title = ewutils.flattenTokenListToString(cmd.tokens[1:len(cmd.tokens) - 1])

            if rating == None:
                response = "How many f***s do you want to give the zine? (1-5)"

            elif rating not in range(1, 6):
                response = "Easy now, keep your f***s between 1 and 5."

            else:
                book_sought = bknd_item.find_item(item_search=book_title, id_user=cmd.message.author.id, id_server=cmd.guild.id if cmd.guild is not None else None)

                if book_sought:
                    book_item = EwItem(id_item=book_sought.get('id_item'))
                    id_book = book_item.item_props.get("id_book")
                    book = EwBook(id_book=id_book)
                    sale = EwBookSale(id_book=id_book, member=cmd.message.author)

                    if sale.bought == 1:
                        if sale.rating == 0:
                            book.rates += 1
                        sale.rating = rating
                        sale.persist()
                        try:
                            conn_info = bknd_core.databaseConnect()
                            conn = conn_info.get('conn')
                            cursor = conn.cursor()

                            cursor.execute((
                                "SELECT {} FROM book_sales WHERE {} = %s AND {} = %s AND {} != 0".format(
                                    ewcfg.col_rating,
                                    ewcfg.col_id_server,
                                    ewcfg.col_id_user,
                                    ewcfg.col_rating,
                                )
                            ), (
                                cmd.guild.id,
                                cmd.message.author.id,
                            ))

                            data = cursor.fetchall()
                            ratings = []
                            total_rating = 0

                            if data != None:
                                for row in data:
                                    ratings.append(row)
                                    total_rating += row[0]

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

                        book.rating = str(total_rating / len(ratings))[:4]

                        # zine is excluded from normal browsing
                        if book.book_state == 1:
                            if book.rates >= 10 and float(book.rating) <= 2.0:
                                book.book_state = 2
                            elif book.rates >= 4 and float(book.rating) <= 1.5:
                                book.book_state = 2

                        # zine is included back into normal browsing
                        elif book.book_state == 2:
                            if float(book.rating) > 2.0 and book.rates > 10:
                                book.book_state = 1
                            elif float(book.rating) > 1.5 and book.rates > 5:
                                book.book_state = 1

                        book.persist()

                        response = "{}, you carve a {} into the back of the zine in order to indicate how many f***s you give about it.".format(ewcfg.rating_flavor[rating], rating)

                    else:
                        response = "You've never bought this book."

                else:
                    response = "You don't have that zine on you."
        else:
            response = "How many f***s do you want to give the zine? (1-5)"

    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Пример #10
0
async def read_book(cmd):
    dm = cmd.message.guild is None

    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

    if not dm:
        response = "ENDLESS WAR politely asks that you !read in his DMs."

    elif len(cmd.tokens) < 2:
        response = "What zine do you want to read?"

    else:
        if len(cmd.tokens) < 3:
            book_title = ewutils.flattenTokenListToString(cmd.tokens)
            page_number = 0
        else:
            book_title = ewutils.flattenTokenListToString(cmd.tokens[1:len(cmd.tokens) - 1])
            page_number = ewutils.getIntToken(cmd.tokens)

        book_sought = bknd_item.find_item(item_search=book_title, id_user=cmd.message.author.id, id_server=cmd.guild.id if cmd.guild is not None else None, item_type_filter=ewcfg.it_book)

        if book_sought:
            book = EwItem(id_item=book_sought.get('id_item'))
            id_book = book.item_props.get("id_book")
            book = EwBook(id_book=id_book)

            if page_number not in range(0, book.pages + 1):
                page_number = 0

            accepted = True
            if book.genre == 3:

                accepted = False
                response = "ENDLESS WAR sees you about to open up a p**n zine and wants to make sure you're 18 years or older. Use **!accept** to open or **!refuse** to abstain."

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

                try:
                    message = await cmd.client.wait_for('message', timeout=20, check=lambda message: message.author == cmd.message.author and
                                                                                                     message.content.lower() in [ewcfg.cmd_accept, ewcfg.cmd_refuse])

                    if message != None:
                        if message.content.lower() == ewcfg.cmd_accept:
                            accepted = True
                        if message.content.lower() == ewcfg.cmd_refuse:
                            accepted = False
                except:
                    accepted = False

            if book.book_state < 0:
                response = "You simply can't make out the letters on the page. Maybe it's better this way."

            elif accepted:
                page_contents = get_page(id_book, page_number)

                if page_number == 0 and page_contents == "":
                    page_contents = get_page(id_book, 1)

                page_text = "turn to page {}".format(page_number)

                if page_number == 0:
                    page_text = "look at the cover"

                response = "You {} and begin to read.\n\n\"{} \"".format(page_text, page_contents)
                readers[user_data.id_user] = (id_book, page_number)

                if page_contents == "":
                    response = "You open up to page {} only to find that it's blank!".format(page_number)

                if page_number != 0:
                    response += "\n\nUse **!previouspage** to go back one page."

                if page_number != book.pages:
                    response += "\n\nUse **!nextpage** to go forward one page."

            else:
                response = "You decide not to indulge yourself."

        else:
            response = "You don't have that zine. Make sure you use **!read [zine title] [page]**"

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