Ejemplo n.º 1
0
async def menu(cmd):
    user_data = EwUser(member=cmd.message.author, data_level=2)
    if user_data.life_state == ewcfg.life_state_shambler and user_data.poi != ewcfg.poi_id_nuclear_beach_edge:
        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=cmd.guild.id)
    # poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name)
    poi = poi_static.id_to_poi.get(user_data.poi)

    if user_data.poi == ewcfg.poi_id_clinicofslimoplasty:
        response = "Try {}browse. The menu is in the zines.".format(ewcfg.cmd_prefix)
    elif poi is None or len(poi.vendors) == 0 or ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
        # Only allowed in the food court.
        response = "There’s nothing to buy here. If you want to purchase some items, go to a sub-zone with a vendor in it, like the food court, the speakeasy, or the bazaar."
    else:
        poi = poi_static.id_to_poi.get(user_data.poi)

        mother_district_data = None
        for mother_poi in poi.mother_districts:

            mother_poi_data = poi_static.id_to_poi.get(mother_poi)

            if mother_poi_data.is_district:
                # One of the mother pois was a district, get its controlling faction
                mother_district_data = EwDistrict(district=mother_poi, id_server=user_data.id_server)
                break
            else:
                # One of the mother pois was a street, get the father district of that street and its controlling faction
                father_poi = mother_poi_data.father_district
                mother_district_data = EwDistrict(district=father_poi, id_server=user_data.id_server)
                break

        district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)
        # mother_district_data = EwDistrict(district = destination_poi.id_poi, id_server = user_data.id_server)

        shambler_multiplier = 1  # for speakeasy during shambler times

        if district_data.is_degraded() and poi.id_poi != ewcfg.poi_id_nuclear_beach_edge:
            if poi.id_poi == ewcfg.poi_id_speakeasy:
                shambler_multiplier = 4
            else:
                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))

        controlling_faction = poi_utils.get_subzone_controlling_faction(user_data.poi, user_data.id_server)

        response = "{} Menu:\n\n".format(poi.str_name)

        vendors_list = poi.vendors

        for vendor in vendors_list:
            if vendor == ewcfg.vendor_secretbodega:
                if user_data.freshness < ewcfg.freshnesslevel_4:
                    continue
                else:
                    response += '\nThe hipster behind the counter nearly falls out of his chair after laying eyes on the sheer, unadulterated freshness before him.\n"S-Sir! Your outfit... i-it is positively ***on fleek!!*** As I see you are a fashion enthusiast like myself, let me show you the good stuff…"\n'

            items = []
            # If the vendor is the bazaar get the current rotation of items from the market_data
            vendor_inv = vendors.vendor_inv[vendor] if vendor != ewcfg.vendor_bazaar else market_data.bazaar_wares.values()
            for item_name in vendor_inv:
                item_item = static_items.item_map.get(item_name)
                food_item = static_food.food_map.get(item_name)
                cosmetic_item = static_cosmetics.cosmetic_map.get(item_name)
                furniture_item = static_items.furniture_map.get(item_name)
                weapon_item = static_weapons.weapon_map.get(item_name)
                relic_item = static_relic.relic_map.get(item_name)

                if relic_item is not None:
                    if relic_utils.canCreateRelic(item_name, cmd.guild.id) == None:
                        continue

                # increase profits for the stock market
                stock_data = None
                if vendor in ewcfg.vendor_stock_map:
                    stock = ewcfg.vendor_stock_map.get(vendor)
                    stock_data = EwStock(id_server=user_data.id_server, stock=stock)

                value = 0

                if item_item:
                    value = item_item.price

                if food_item:
                    value = food_item.price

                if cosmetic_item:
                    value = cosmetic_item.price

                if furniture_item:
                    value = furniture_item.price

                if weapon_item:
                    value = weapon_item.price

                if relic_item:
                    value = relic_item.price

                if stock_data != None:
                    value *= (stock_data.exchange_rate / ewcfg.default_stock_exchange_rate) ** 0.2

                # multiply by 4 is speakeasy is shambled
                value *= shambler_multiplier

                if mother_district_data != None:
                    if controlling_faction != "":
                        # prices are halved for the controlling gang
                        if controlling_faction == user_data.faction:
                            value /= 2

                        # and 4 times as much for enemy gangsters
                        elif user_data.faction != "":
                            value *= 4

                if vendor == ewcfg.vendor_breakroom and user_data.faction == ewcfg.faction_slimecorp:
                    value = 0

                value = int(value)

                if value != 0:
                    items.append('{} ({:,})'.format(item_name, value))
                else:
                    items.append(item_name)

            response += "**{}**: *{}*\n".format(vendor, ewutils.formatNiceList(names=items))

            if vendor == ewcfg.vendor_bodega:
                if user_data.freshness < ewcfg.freshnesslevel_1:
                    response += "\nThe hipster behind the counter is utterly repulsed by the fashion disaster in front of him. Looks like you just aren’t fresh enough for him."
            if user_data.has_soul == 0:
                if vendor == ewcfg.vendor_dojo:
                    response += "\n\nThe Dojo master looks at your soulless form with pity."
                elif vendor == ewcfg.vendor_bar:
                    response += "\n\nThe bartender, sensing your misery, asks if you're okay."
                elif vendor == ewcfg.vendor_diner:
                    response += "\n\nThe cook gives you a concerned look as he throws down another helping of flapjacks."
                elif vendor == ewcfg.vendor_seafood:
                    response += "\n\nThe waiter sneers at how soulless and unkempt you look. You try to ignore him."
                elif vendor == ewcfg.vendor_bazaar:
                    response += "\n\nAll the shops seem so lively. You wish you had a soul so you could be like them."
                elif vendor == ewcfg.vendor_beachresort or vendor == ewcfg.vendor_countryclub:
                    response += "\n\nEverything looks so fancy here, but it doesn't really appeal to you since you don't have a soul."
                elif vendor == ewcfg.vendor_bodega:
                    if user_data.freshness < ewcfg.freshnesslevel_1:
                        response += ".. and you probably never will be."
                elif vendor == ewcfg.vendor_glocksburycomics:
                    response += "\n\nThe cashier here tries to start up a conversation about life being worth living. You're having none of it."
                elif vendor == ewcfg.vendor_basedhardware:
                    response += "\n\nSo many industrial metals here... You contemplate which you could use to kill yourself..."
                elif vendor == ewcfg.vendor_wafflehouse:
                    response += "\n\nNot even waffles could hope to make your emptiness go away."
                elif vendor == ewcfg.vendor_greencakecafe:
                    response += "\n\nThe barista behind the counter pauses to look at your soulless misery for a second, but decides you're not worth it and gets back to work."
                elif vendor == ewcfg.vendor_slimypersuits:
                    response += "\n\nYour mere presence in here ruins the cheery atmosphere."

    # Send the response to the player.
    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Ejemplo n.º 2
0
async def order(cmd):
    user_data = EwUser(member=cmd.message.author)
    mutations = user_data.get_mutations()
    if user_data.life_state == ewcfg.life_state_shambler and user_data.poi != ewcfg.poi_id_nuclear_beach_edge:
        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=cmd.guild.id)
    currency_used = 'slime'
    current_currency_amount = user_data.slimes
    # poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name)
    poi = poi_static.id_to_poi.get(user_data.poi)
    if poi is None or len(poi.vendors) == 0 or ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
        # Only allowed in the food court.
        response = "There’s nothing to buy here. If you want to purchase some items, go to a sub-zone with a vendor in it, like the food court, the speakeasy, or the bazaar."
    else:
        poi = poi_static.id_to_poi.get(user_data.poi)
        district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server)

        shambler_multiplier = 1  # for speakeasy during shambler times

        if district_data.is_degraded():
            if poi.id_poi == ewcfg.poi_id_speakeasy:
                shambler_multiplier = 4
            else:
                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 = ewutils.flattenTokenListToString(cmd.tokens[1:2])

        # if cmd.tokens_count > 1:
        #	value = cmd.tokens[1]
        #	value = value.lower()

        value = None

        togo = False
        if cmd.tokens_count > 1:
            for token in cmd.tokens[1:]:
                if token.startswith('<@') == False and token.lower() not in "togo":  # togo can be spelled together or separate
                    value = token
                    break

            for token in cmd.tokens[1:]:
                if token.lower() in "togo":  # lets people get away with just typing only to or only go (or only t etc.) but whatever
                    togo = True
                    break

        # Finds the item if it's an EwGeneralItem.

        if value == "mylittleponyfigurine":
            value = random.choice(static_items.furniture_pony)

        item = static_items.item_map.get(value)

        item_type = ewcfg.it_item
        if item != None:
            item_id = item.id_item
            name = item.str_name

        # Finds the item if it's an EwFood item.
        if item == None:
            item = static_food.food_map.get(value)
            item_type = ewcfg.it_food
            if item != None:
                item_id = item.id_food
                name = item.str_name

        # Finds the item if it's an EwCosmeticItem.
        if item == None:
            item = static_cosmetics.cosmetic_map.get(value)
            item_type = ewcfg.it_cosmetic
            if item != None:
                item_id = item.id_cosmetic
                name = item.str_name

        if item == None:
            item = static_items.furniture_map.get(value)
            item_type = ewcfg.it_furniture
            if item != None:
                item_id = item.id_furniture
                name = item.str_name
                if item_id in static_items.furniture_pony:
                    item.vendors = [ewcfg.vendor_bazaar]

        if item == None:
            item = static_weapons.weapon_map.get(value)
            item_type = ewcfg.it_weapon
            if item != None:
                item_id = item.id_weapon
                name = item.str_weapon

        if item == None:
            item = static_relic.relic_map.get(value)
            item_type = ewcfg.it_relic
            if item != None and relic_utils.canCreateRelic(item.id_relic, cmd.guild.id):
                item_id = item.id_relic
                name = item.str_name
            elif item != None:
                item = None


        if item != None:
            item_type = item.item_type
            # Gets a vendor that the item is available and the player currently located in
            try:
                current_vendor = (set(item.vendors).intersection(set(poi.vendors))).pop()
            except:
                current_vendor = None

            # Check if the item is available in the current bazaar item rotation
            if current_vendor == ewcfg.vendor_bazaar:
                if item_id not in market_data.bazaar_wares.values():
                    if item_id in static_items.furniture_pony and "mylittleponyfigurine" in market_data.bazaar_wares.values():
                        pass
                    else:
                        current_vendor = None


            if current_vendor is None or len(current_vendor) < 1:
                response = "Check the {} for a list of items you can {}.".format(ewcfg.cmd_menu, ewcfg.cmd_order)

            else:
                response = ""

                value = item.price

                premium_purchase = True if item_id in ewcfg.premium_items else False
                if premium_purchase:
                    togo = True  # Just in case they order a premium food item, don't make them eat it right then and there.

                    if ewcfg.cd_premium_purchase > (int(time.time()) - user_data.time_lastpremiumpurchase):
                        response = "That item is in very limited stock! The vendor asks that you refrain from purchasing it for a day or two."
                        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                    elif ewcfg.cd_new_player > (int(time.time()) - user_data.time_joined):
                        response = "You've only been in the city for a few days. The vendor doesn't trust you with that item very much..."
                        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                stock_data = None
                company_data = None
                # factor in the current stocks
                for vendor in item.vendors:
                    if vendor in ewcfg.vendor_stock_map:
                        stock = ewcfg.vendor_stock_map.get(vendor)
                        company_data = EwCompany(id_server=user_data.id_server, stock=stock)
                        stock_data = EwStock(id_server=user_data.id_server, stock=stock)

                if stock_data is not None:
                    value *= (stock_data.exchange_rate / ewcfg.default_stock_exchange_rate) ** 0.2

                controlling_faction = poi_utils.get_subzone_controlling_faction(user_data.poi, user_data.id_server)

                if controlling_faction != "":
                    # prices are halved for the controlling gang
                    if controlling_faction == user_data.faction:
                        value /= 2

                    # and 4 times as much for enemy gangsters
                    elif user_data.faction != "":
                        value *= 4

                # raise shambled speakeasy price 4 times
                value *= shambler_multiplier

                # Raise the price for togo ordering. This gets lowered back down later if someone does togo ordering on a non-food item by mistake.
                if togo:
                    value *= 1.5

                if current_vendor == ewcfg.vendor_breakroom and user_data.faction == ewcfg.faction_slimecorp:
                    value = 0

                value = int(value)

                food_ordered = False
                target_data = None

                # Kingpins eat free.
                if (user_data.life_state == ewcfg.life_state_kingpin or user_data.life_state == ewcfg.life_state_grandfoe) and item_type == ewcfg.it_food:
                    value = 0

                if value > current_currency_amount:
                    # Not enough money.
                    response = "A {} costs {:,} {}, and you only have {:,}.".format(name, value, currency_used, current_currency_amount)
                else:
                    mutations = user_data.get_mutations()
                    if random.randrange(5) == 0 and ewcfg.mutation_id_stickyfingers in mutations:
                        value = 0
                        user_data.change_crime(n=ewcfg.cr_larceny_points)

                    inv_response = bknd_item.check_inv_capacity(user_data=user_data, item_type=item_type, return_strings=True, pronoun="You")
                    if inv_response != "" and (item_type != ewcfg.it_food or togo):
                        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, inv_response))

                    if item_type == ewcfg.it_food:
                        food_ordered = True

                        target = None
                        target_data = None
                        if not togo:  # cant order togo for someone else, you can just give it to them in person
                            if cmd.mentions_count == 1:
                                target = cmd.mentions[0]
                                if target.id == cmd.message.author.id:
                                    target = None

                        if target != None:
                            target_data = EwUser(member=target)
                            if target_data.life_state == ewcfg.life_state_corpse and target_data.get_possession():
                                response = "How are you planning to feed them while they're possessing you?"
                                return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                            elif target_data.poi != user_data.poi:
                                response = "You can't order anything for them because they aren't here!"
                                return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                    elif item_type == ewcfg.it_weapon:

                        if user_data.life_state == ewcfg.life_state_corpse:
                            response = "Ghosts can't hold weapons."
                            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                    item_props = itm_utils.gen_item_props(item)

                    # Only food should have the value multiplied. If someone togo orders a non-food item by mistake, lower it back down.
                    if not food_ordered and togo:
                        value = int(value / 1.5)

                    if currency_used == 'slime':
                        user_data.change_slimes(n=-value, source=ewcfg.source_spending)

                    if company_data is not None:
                        company_data.recent_profits += value
                        company_data.persist()

                    if item.str_name == "arcade cabinet":
                        item_props['furniture_desc'] = random.choice(ewcfg.cabinets_list)
                    elif item.item_type == ewcfg.it_furniture:
                        if "custom" in item_props.get('id_furniture'):
                            if cmd.tokens_count < 4 or cmd.tokens[2] == "" or cmd.tokens[3] == "":
                                response = "You need to specify the customization text before buying a custom item. Come on, isn't that self-evident? (!order [custom item] \"custom name\" \"custom description\")"
                                return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                            else:
                                customname = cmd.tokens[2]

                                if len(customname) > 32:
                                    response = "That name is too long. ({:,}/32)".format(len(customname))
                                    return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                                customdesc = cmd.tokens[3]

                                if len(customdesc) > 500:
                                    response = "That description is too long. ({:,}/500)".format(len(customdesc))
                                    return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))

                                name = item_props['furniture_name'] = item_props['furniture_name'].format(custom=customname)
                                item_props['furniture_desc'] = customdesc
                                item_props['furniture_look_desc'] = item_props['furniture_look_desc'].format(custom=customname)
                                item_props['furniture_place_desc'] = item_props['furniture_place_desc'].format(custom=customname)

                    id_item = bknd_item.item_create(
                        item_type=item_type,
                        id_user=cmd.message.author.id,
                        id_server=cmd.guild.id,
                        stack_max=-1,
                        stack_size=0,
                        item_props=item_props
                    )

                    if value == 0:
                        response = "You swipe a {} from the counter at {}.".format(name, current_vendor)
                    else:
                        response = "You slam {:,} {} down on the counter at {} for {}.".format(value, currency_used, current_vendor, name)

                    if food_ordered and not togo:
                        item_data = EwItem(id_item=id_item)

                        # Eat food on the spot!
                        if target_data != None:

                            target_player_data = EwPlayer(id_user=target_data.id_user)

                            if value == 0:
                                response = "You swipe a {} from the counter at {} and give it to {}.".format(name, current_vendor, target_player_data.display_name)
                            else:
                                response = "You slam {:,} slime down on the counter at {} for {} and give it to {}.".format(value, current_vendor, name, target_player_data.display_name)

                            response += "\n\n*{}*: ".format(target_player_data.display_name) + target_data.eat(item_data)
                            target_data.persist()
                            
                        else:

                            if value == 0:
                                response = "You swipe a {} from the counter at {} and eat it right on the spot.".format(name, current_vendor)
                            else:
                                response = "You slam {:,} slime down on the counter at {} for {} and eat it right on the spot.".format(value, current_vendor, name)

                            user_player_data = EwPlayer(id_user=user_data.id_user)

                            response += "\n\n*{}*: ".format(user_player_data.display_name) + user_data.eat(item_data)
                            user_data.persist()

                    if premium_purchase:
                        user_data.time_lastpremiumpurchase = int(time.time())

                    user_data.persist()

        else:
            response = "Check the {} for a list of items you can {}.".format(ewcfg.cmd_menu, ewcfg.cmd_order)

    # Send the response to the player.
    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
Ejemplo n.º 3
0
async def award_fish(fisher, cmd, user_data):
    response = ""

    actual_fisherman = None
    actual_fisherman_data = user_data
    if fisher.inhabitant_id:
        actual_fisherman = user_data.get_possession()[1]
        actual_fisherman_data = EwUser(id_user=actual_fisherman,
                                       id_server=cmd.guild.id)

    if fisher.current_fish in ["item", "seaitem"]:
        slimesea_inventory = bknd_item.inventory(id_server=cmd.guild.id,
                                                 id_user=ewcfg.poi_id_slimesea)

        if (fisher.pier.pier_type != ewcfg.fish_slime_saltwater
                or len(slimesea_inventory) == 0
                or random.random() < 0.2) and fisher.current_fish == "item":

            item = random.choice(vendors.mine_results)

            unearthed_item_amount = (random.randrange(5) + 8
                                     )  # anywhere from 8-12 drops

            item_props = itm_utils.gen_item_props(item)

            # Ensure item limits are enforced, including food since this isn't the fish section
            if bknd_item.check_inv_capacity(user_data=actual_fisherman_data,
                                            item_type=item.item_type):
                for creation in range(unearthed_item_amount):
                    bknd_item.item_create(item_type=item.item_type,
                                          id_user=actual_fisherman
                                          or cmd.message.author.id,
                                          id_server=cmd.guild.id,
                                          item_props=item_props)

                response = "You reel in {} {}s! ".format(
                    unearthed_item_amount, item.str_name)
            else:
                response = "You woulda reeled in some {}s, but your back gave out under the weight of the rest of your {}s.".format(
                    item.str_name, item.item_type)

        else:
            item = random.choice(slimesea_inventory)

            if bknd_item.give_item(id_item=item.get('id_item'),
                                   member=cmd.message.author):
                response = "You reel in a {}!".format(item.get('name'))
            else:
                response = "You woulda reeled in a {}, but your back gave out under the weight of the rest of your {}s.".format(
                    item.str_name, item.item_type)

        fisher.stop()
        user_data.persist()

    else:
        user_initial_level = user_data.slimelevel

        gang_bonus = False

        has_fishingrod = False

        if user_data.weapon >= 0:
            weapon_item = EwItem(id_item=user_data.weapon)
            weapon = static_weapons.weapon_map.get(
                weapon_item.item_props.get("weapon_type"))
            if weapon.id_weapon == "fishingrod":
                has_fishingrod = True

        value = 0

        # Rewards from the fish's size
        slime_gain = ewcfg.fish_gain * static_fish.size_to_reward[
            fisher.current_size]
        value += 10 * static_fish.size_to_reward[fisher.current_size]

        # Rewards from the fish's rarity
        value += 10 * static_fish.rarity_to_reward[static_fish.fish_map[
            fisher.current_fish].rarity]

        if user_data.life_state == 2:
            if fisher.current_fish in static_fish.day_fish and user_data.faction == ewcfg.faction_rowdys:
                gang_bonus = True
                slime_gain = slime_gain * 1.5
                value += 20

            if fisher.current_fish in static_fish.night_fish and user_data.faction == ewcfg.faction_killers:
                gang_bonus = True
                slime_gain = slime_gain * 1.5
                value += 20

        # Disabled while I try out the new mastery fishing
        #if has_fishingrod == True:
        #    slime_gain = slime_gain * 2

        # trauma = se_static.trauma_map.get(user_data.trauma)
        # if trauma != None and trauma.trauma_class == ewcfg.trauma_class_slimegain:
        #	slime_gain *= (1 - 0.5 * user_data.degradation / 100)

        if fisher.pier.pier_type == ewcfg.fish_slime_void:
            slime_gain = slime_gain * 1.5
            value += 30

        if fisher.current_fish == "plebefish":
            slime_gain = ewcfg.fish_gain * .5
            value = 10

        controlling_faction = poi_utils.get_subzone_controlling_faction(
            user_data.poi, user_data.id_server)

        if controlling_faction != "" and controlling_faction == user_data.faction:
            slime_gain *= 2

        if user_data.poi == ewcfg.poi_id_juviesrow_pier:
            slime_gain = int(slime_gain / 4)

        #trauma = se_static.trauma_map.get(user_data.trauma)
        #if trauma != None and trauma.trauma_class == ewcfg.trauma_class_slimegain and False:
        #slime_gain *= (1 - 0.5 * user_data.degradation / 100)

        slime_gain = max(0, round(slime_gain))

        bknd_item.item_create(
            id_user=actual_fisherman or cmd.message.author.id,
            id_server=cmd.guild.id,
            item_type=ewcfg.it_food,
            item_props={
                'id_food':
                static_fish.fish_map[fisher.current_fish].id_fish,
                'food_name':
                static_fish.fish_map[fisher.current_fish].str_name,
                'food_desc':
                "{}\nIt's {} inches long.".format(
                    static_fish.fish_map[fisher.current_fish].str_desc,
                    fisher.length),
                'recover_hunger':
                20,
                'str_eat':
                ewcfg.str_eat_raw_material.format(
                    static_fish.fish_map[fisher.current_fish].str_name),
                'rarity':
                static_fish.fish_map[fisher.current_fish].rarity,
                'size':
                fisher.current_size,
                'time_expir':
                time.time() + ewcfg.std_food_expir,
                'time_fridged':
                0,
                'acquisition':
                ewcfg.acquisition_fishing,
                'value':
                value,
                'noslime':
                'false',
                'length':
                fisher.length
            })

        if fisher.inhabitant_id:
            server = cmd.guild
            inhabitant_member = server.get_member(fisher.inhabitant_id)
            inhabitant_name = inhabitant_member.display_name
            inhabitant_data = EwUser(id_user=fisher.inhabitant_id,
                                     id_server=user_data.id_server)
            inhabitee_name = server.get_member(actual_fisherman).display_name

            slime_gain = int(0.25 * slime_gain)

            response = "The two of you together manage to reel in a {fish}! {flavor} {ghost} haunts {slime:,} slime away from the fish before placing it on {fleshling}'s hands." \
                .format(
                fish=static_fish.fish_map[fisher.current_fish].str_name,
                flavor=static_fish.fish_map[fisher.current_fish].str_desc,
                ghost=inhabitant_name,
                fleshling=inhabitee_name,
                slime=slime_gain,
            )

            inhabitant_data.change_slimes(n=-slime_gain)
            inhabitant_data.persist()
            fisher.stop()
        else:
            response = "You reel in a {fish}! {flavor} You grab hold and wring {slime:,} slime from it. " \
                .format(fish=static_fish.fish_map[fisher.current_fish].str_name, flavor=static_fish.fish_map[fisher.current_fish].str_desc, slime=slime_gain)
            if gang_bonus == True:
                if user_data.faction == ewcfg.faction_rowdys:
                    response += "The Rowdy-pride this fish is showing gave you more slime than usual. "
                elif user_data.faction == ewcfg.faction_killers:
                    response += "The Killer-pride this fish is showing gave you more slime than usual. "

            levelup_response = user_data.change_slimes(
                n=slime_gain, source=ewcfg.source_fishing)
            was_levelup = True if user_initial_level < user_data.slimelevel else False
            # Tell the player their slime level increased.
            if was_levelup:
                response += levelup_response

        fisher.stop()

        user_data.persist()
    return response
Ejemplo n.º 4
0
async def reap(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))

    forcereap = False
    if cmd.tokens[0] == ewcfg.cmd_reap_alt:
        if cmd.message.author.guild_permissions.administrator:
            forcereap = True
        else:
            return

    response = ""
    levelup_response = ""
    mutations = user_data.get_mutations()
    cosmetic_abilites = itm_utils.get_cosmetic_abilities(
        id_user=cmd.message.author.id, id_server=cmd.guild.id)
    poi = poi_static.id_to_poi.get(user_data.poi)

    # check if the user has a farming tool equipped
    weapon_item = EwItem(id_item=user_data.weapon)
    weapon = static_weapons.weapon_map.get(
        weapon_item.item_props.get("weapon_type"))
    has_tool = False
    if weapon is not None:
        if ewcfg.weapon_class_farming in weapon.classes:
            has_tool = True

    # Checking availability of reap action
    if user_data.life_state != ewcfg.life_state_juvenile:
        response = "Only Juveniles of pure heart and with nothing better to do can farm."
    elif cmd.message.channel.name not in [
            ewcfg.channel_jr_farms, ewcfg.channel_og_farms,
            ewcfg.channel_ab_farms
    ]:
        response = "Do you remember planting anything here in this barren wasteland? No, you don’t. Idiot."
    else:
        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.poi == ewcfg.poi_id_jr_farms:
            farm_id = ewcfg.poi_id_jr_farms
        elif user_data.poi == ewcfg.poi_id_og_farms:
            farm_id = ewcfg.poi_id_og_farms
        else:  # if it's the farm in arsonbrook
            farm_id = ewcfg.poi_id_ab_farms

        farm = EwFarm(id_server=cmd.guild.id,
                      id_user=cmd.message.author.id,
                      farm=farm_id)

        if farm.time_lastsow == 0:
            response = "You missed a step, you haven’t planted anything here yet."
        else:
            cur_time_min = time.time() / 60
            time_grown = cur_time_min - farm.time_lastsow

            if farm.phase != ewcfg.farm_phase_reap and not forcereap:
                response = "Patience is a virtue and you are morally bankrupt. Just wait, asshole."
            else:  # Reaping
                if (time_grown > ewcfg.crops_time_to_grow *
                        16) and not forcereap:  # about 2 days
                    response = "You eagerly cultivate your crop, but what’s this? It’s dead and wilted! It seems as though you’ve let it lay fallow for far too long. Pay better attention to your farm next time. You gain no slime."
                    farm.time_lastsow = 0  # 0 means no seeds are currently planted
                    farm.persist()
                else:
                    user_initial_level = user_data.slimelevel

                    slime_gain = farm.slimes_onreap

                    controlling_faction = poi_utils.get_subzone_controlling_faction(
                        user_data.poi, user_data.id_server)

                    if controlling_faction != "" and controlling_faction == user_data.faction:
                        slime_gain *= 2

                    if has_tool and weapon.id_weapon == ewcfg.weapon_id_hoe:
                        slime_gain *= 1.5

                    if ewcfg.mutation_id_greenfingers in mutations:
                        slime_gain *= 1.2

                    if user_data.poi == ewcfg.poi_id_jr_farms:
                        slime_gain = int(slime_gain / 4)

                    # trauma = se_static.trauma_map.get(user_data.trauma)
                    # if trauma != None and trauma.trauma_class == ewcfg.trauma_class_slimegain:
                    #	slime_gain *= (1 - 0.5 * user_data.degradation / 100)

                    slime_gain = max(0, round(slime_gain))

                    response = "You reap what you’ve sown. Your investment has yielded {:,} slime, ".format(
                        slime_gain)

                    # Determine if an item is found.
                    unearthed_item = False
                    unearthed_item_amount = 0

                    unearthed_item_chance = 50 / ewcfg.unearthed_item_rarity  # 1 in 30 chance

                    if ewcfg.mutation_id_lucky in mutations:
                        unearthed_item_chance *= 1.33  # 1 in 22.5 chance

                    if ewcfg.cosmeticAbility_id_lucky in cosmetic_abilites:
                        unearthed_item_chance *= 1.33  # 1 in ~17 chance with both

                    if has_tool and weapon.id_weapon == ewcfg.weapon_id_shovel:  # 1 in 6 chance
                        unearthed_item_chance *= 5

                    if random.random() < unearthed_item_chance:
                        unearthed_item = True
                        unearthed_item_amount = 1 if random.randint(
                            1, 3) != 1 else 2  # 33% chance of extra drop

                    if unearthed_item == True:
                        # If there are multiple possible products, randomly select one.
                        item = random.choice(vendors.mine_results)

                        item_props = itm_utils.gen_item_props(item)

                        if item is not None:

                            for creation in range(unearthed_item_amount):
                                bknd_item.item_create(
                                    item_type=item.item_type,
                                    id_user=cmd.message.author.id,
                                    id_server=cmd.guild.id,
                                    item_props=item_props)

                        if unearthed_item_amount == 1:
                            response += "a {}, ".format(item.str_name)
                        elif unearthed_item_amount == 2:
                            response += "two {}s, ".format(item.str_name)

                    #  Determine what crop is grown.
                    vegetable = static_food.food_map.get(farm.crop)
                    if vegetable is None:
                        vegetable = random.choice(static_food.vegetable_list)

                    item_props = itm_utils.gen_item_props(vegetable)

                    #  Create and give a bushel of whatever crop was grown, unless it's a metal crop.
                    if item_props.get('id_food') in [
                            ewcfg.item_id_metallicaps,
                            ewcfg.item_id_steelbeans, ewcfg.item_id_aushucks
                    ]:
                        metallic_crop_ammount = 1
                        if random.randrange(10) == 0:
                            metallic_crop_ammount = 5 if random.randrange(
                                2) == 0 else 6

                        if has_tool and weapon.id_weapon == ewcfg.weapon_id_pitchfork:
                            metallic_crop_ammount *= 2

                        for vcreate in range(metallic_crop_ammount):
                            bknd_item.item_create(
                                id_user=cmd.message.author.id,
                                id_server=cmd.guild.id,
                                item_type=vegetable.item_type,
                                item_props=item_props)

                        if metallic_crop_ammount == 1:
                            response += "and a single {}!".format(
                                vegetable.str_name)
                        else:
                            response += "and a bushel or two of {}!".format(
                                vegetable.str_name)
                    # if random.randrange(10) == 0:
                    # 	for vcreate in range(6):
                    # 		bknd_item.item_create(
                    # 			id_user=cmd.message.author.id,
                    # 			id_server=cmd.guild.id,
                    # 			item_type=vegetable.item_type,
                    # 			item_props=item_props
                    # 		)
                    #
                    # 	response += "and a bushel of {}!".format(vegetable.str_name)
                    # else:
                    # 	response += "and a bushel of... hey, what the hell! You didn't reap anything! Must've been some odd seeds..."
                    else:
                        unearthed_vegetable_amount = 3
                        if has_tool and weapon.id_weapon == ewcfg.weapon_id_pitchfork:
                            unearthed_vegetable_amount *= 2

                        for vcreate in range(unearthed_vegetable_amount):
                            bknd_item.item_create(
                                id_user=cmd.message.author.id,
                                id_server=cmd.guild.id,
                                item_type=vegetable.item_type,
                                item_props=item_props)

                        response += "and a bushel of {}!".format(
                            vegetable.str_name)

                    levelup_response = user_data.change_slimes(
                        n=slime_gain, source=ewcfg.source_farming)

                    was_levelup = True if user_initial_level < user_data.slimelevel else False

                    # Tell the player their slime level increased.
                    if was_levelup:
                        response += "\n\n" + levelup_response

                    user_data.hunger += ewcfg.hunger_perfarm
                    user_data.persist()

                    farm.time_lastsow = 0  # 0 means no seeds are currently planted
                    farm.persist()

                    # gangsters don't need their roles updated
                    if user_data.life_state == ewcfg.life_state_juvenile:
                        await ewrolemgr.updateRoles(client=cmd.client,
                                                    member=cmd.message.author)

    await fe_utils.send_message(
        cmd.client, cmd.message.channel,
        fe_utils.formatMessage(cmd.message.author, response))
Ejemplo n.º 5
0
async def mine(cmd):
    market_data = EwMarket(id_server=cmd.message.author.guild.id)
    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))

    mutations = user_data.get_mutations()
    cosmetic_abilites = itm_utils.get_cosmetic_abilities(id_user=cmd.message.author.id, id_server=cmd.guild.id)
    time_now = int(time.time())
    poi = poi_static.id_to_poi.get(user_data.poi)

    response = ""
    # Kingpins can't mine.
    if user_data.life_state == ewcfg.life_state_kingpin or user_data.life_state == ewcfg.life_state_grandfoe:
        return

    # ghosts cant mine (anymore)
    if user_data.life_state == ewcfg.life_state_corpse:
        return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You can't mine while you're dead. Try {}.".format(ewcfg.cmd_revive)))

    # Enlisted players only mine at certain times.
    if user_data.life_state == ewcfg.life_state_enlisted:
        if user_data.faction == ewcfg.faction_rowdys and (market_data.clock < 8 or market_data.clock > 17):
            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "Rowdies only mine in the daytime. Wait for full daylight at 8am.".format(ewcfg.cmd_revive)))

        if user_data.faction == ewcfg.faction_killers and (market_data.clock < 20 and market_data.clock > 5):
            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "Killers only mine under cover of darkness. Wait for nightfall at 8pm.".format(ewcfg.cmd_revive)))

    # Mine only in the mines.
    if cmd.message.channel.name in ewcfg.mining_channels:
        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.hunger >= user_data.get_hunger_max():
            return await mismine(cmd, user_data, "exhaustion")
        # return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You've exhausted yourself from mining. You'll need some refreshment before getting back to work."))

        else:
            printgrid = True
            hunger_cost_mod = ewutils.hunger_cost_mod(user_data.slimelevel)
            extra = hunger_cost_mod - int(hunger_cost_mod)  # extra is the fractional part of hunger_cost_mod

            world_events = bknd_worldevent.get_world_events(id_server=cmd.guild.id)
            mining_type = ewcfg.mines_mining_type_map.get(user_data.poi)
            for id_event in world_events:

                if world_events.get(id_event) == ewcfg.event_type_minecollapse:
                    event_data = EwWorldEvent(id_event=id_event)
                    if int(event_data.event_props.get('id_user')) == user_data.id_user and event_data.event_props.get('poi') == user_data.poi:
                        captcha = event_data.event_props.get('captcha').lower()
                        tokens_lower = []
                        for token in cmd.tokens[1:]:
                            tokens_lower.append(token.lower())

                        if captcha in tokens_lower:
                            bknd_worldevent.delete_world_event(id_event=id_event)
                            response = "You escape from the collapsing mineshaft."
                            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                        elif ewcfg.mutation_id_lightminer in mutations:
                            bknd_worldevent.delete_world_event(id_event=id_event)
                            response = "You nimbly step outside the collapse without even thinking about it."
                            return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                        else:
                            return await mismine(cmd, user_data, ewcfg.event_type_minecollapse)

            if user_data.poi not in juviecmdutils.mines_map:
                response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!"
                return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
            elif user_data.id_server not in juviecmdutils.mines_map.get(user_data.poi):
                init_grid(user_data.poi, user_data.id_server)
                printgrid = True

            grid_cont = juviecmdutils.mines_map.get(user_data.poi).get(user_data.id_server)
            grid = grid_cont.grid

            grid_type = ewcfg.grid_type_by_mining_type.get(mining_type)
            if grid_type != grid_cont.grid_type:
                init_grid(user_data.poi, user_data.id_server)
                printgrid = True
                grid_cont = juviecmdutils.mines_map.get(user_data.poi).get(user_data.id_server)
                grid = grid_cont.grid

            # minesweeper = True
            # grid_multiplier = grid_cont.cells_mined ** 0.4
            # flag = False
            mining_yield = get_mining_yield_by_grid_type(cmd, grid_cont)

            if type(mining_yield) == type(""):
                response = mining_yield
                if len(response) > 0:
                    await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                if time_now > grid_cont.time_last_posted + 10:
                    await print_grid(cmd)
                return

            if mining_yield == 0:
                user_data.hunger += ewcfg.hunger_permine * int(hunger_cost_mod)
                user_data.persist()
                # response = "This vein has already been mined dry."
                # await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
                if printgrid:
                    return await print_grid(cmd)
                else:
                    return

            has_pickaxe = False

            if user_data.weapon >= 0:
                weapon_item = EwItem(id_item=user_data.weapon)
                weapon = static_weapons.weapon_map.get(weapon_item.item_props.get("weapon_type"))
                if (weapon.id_weapon == ewcfg.weapon_id_pickaxe or weapon.id_weapon == ewcfg.weapon_id_diamondpickaxe)  and user_data.life_state != ewcfg.life_state_juvenile:
                    has_pickaxe = True
            # if user_data.sidearm >= 0:
            #	sidearm_item = EwItem(id_item=user_data.sidearm)
            #	sidearm = static_weapons.weapon_map.get(sidearm_item.item_props.get("weapon_type"))
            #	if sidearm.id_weapon == ewcfg.weapon_id_pickaxe:
            #		has_pickaxe = True

            # Determine if an item is found.
            unearthed_item = False
            unearthed_item_amount = (random.randrange(3) + 5)  # anywhere from 5-7 drops

            # juvies get items 4 times as often as enlisted players
            unearthed_item_chance = 1 / ewcfg.unearthed_item_rarity
            if user_data.life_state == ewcfg.life_state_juvenile:
                unearthed_item_chance *= 2
            if has_pickaxe == True:
                unearthed_item_chance *= 1.5
            if ewcfg.mutation_id_lucky in mutations:
                unearthed_item_chance *= 1.33
            if ewcfg.cosmeticAbility_id_lucky in cosmetic_abilites:
                unearthed_item_chance *= 1.33

            # event bonus
            for id_event in world_events:

                if world_events.get(id_event) == ewcfg.event_type_slimefrenzy:
                    event_data = EwWorldEvent(id_event=id_event)
                    if event_data.event_props.get('poi') == user_data.poi and int(event_data.event_props.get('id_user')) == user_data.id_user:
                        mining_yield *= 2

                if world_events.get(id_event) == ewcfg.event_type_poudrinfrenzy:
                    event_data = EwWorldEvent(id_event=id_event)
                    if event_data.event_props.get('poi') == user_data.poi and int(event_data.event_props.get('id_user')) == user_data.id_user:
                        unearthed_item_chance = 1
                        unearthed_item_amount = 1

            if random.random() < 0.05:
                id_event = create_mining_event(cmd)
                event_data = EwWorldEvent(id_event=id_event)

                if event_data.id_event == -1:
                    return ewutils.logMsg("Error couldn't find world event with id {}".format(id_event))

                if event_data.event_type == ewcfg.event_type_slimeglob:
                    mining_yield *= 4
                    bknd_worldevent.delete_world_event(id_event=id_event)

                if event_data.time_activate <= time.time():

                    event_def = poi_static.event_type_to_def.get(event_data.event_type)
                    if event_def == None:
                        return ewutils.logMsg("Error, couldn't find event def for event type {}".format(event_data.event_type))
                    str_event_start = event_def.str_event_start

                    if event_data.event_type == ewcfg.event_type_minecollapse:
                        str_event_start = str_event_start.format(cmd=ewcfg.cmd_mine, captcha=ewutils.text_to_regional_indicator(event_data.event_props.get('captcha')))
                        await fe_utils.send_response(str_event_start, cmd)
                        event_data.time_expir = time_now + 60
                        event_data.persist()
                        str_event_start = ""

                    if str_event_start != "":
                        response += str_event_start + "\n"

            if random.random() < unearthed_item_chance:
                unearthed_item = True

            if unearthed_item == True:
                # If there are multiple possible products, randomly select one.
                item = random.choice(vendors.mine_results)

                if bknd_item.check_inv_capacity(user_data=user_data, item_type=item.item_type):

                    item_props = itm_utils.gen_item_props(item)

                    for creation in range(unearthed_item_amount):
                        bknd_item.item_create(
                            item_type=item.item_type,
                            id_user=cmd.message.author.id,
                            id_server=cmd.guild.id,
                            item_props=item_props
                        )

                    if unearthed_item_amount == 1:
                        response += "You unearthed a {}! ".format(item.str_name)
                    else:
                        response += "You unearthed {} {}s! ".format(unearthed_item_amount, item.str_name)

                    ewstats.change_stat(user=user_data, metric=ewcfg.stat_lifetime_poudrins, n=unearthed_item_amount)

            # ewutils.logMsg('{} has found {} {}(s)!'.format(cmd.message.author.display_name, item.str_name, unearthed_item_amount))

            user_initial_level = user_data.slimelevel

            # Add mined slime to the user.
            slime_bylevel = ewutils.slime_bylevel(user_data.slimelevel)

            # mining_yield = math.floor((slime_bylevel / 10) + 1)
            # alternate_yield = math.floor(200 + slime_bylevel ** (1 / math.e))

            # mining_yield = min(mining_yield, alternate_yield)

            controlling_faction = poi_utils.get_subzone_controlling_faction(user_data.poi, user_data.id_server)

            if controlling_faction != "" and controlling_faction == user_data.faction:
                mining_yield *= 2

            if has_pickaxe == True:
                mining_yield *= 2
            if user_data.life_state == ewcfg.life_state_juvenile:
                mining_yield *= 2

            # trauma = se_static.trauma_map.get(user_data.trauma)
            # if trauma != None and trauma.trauma_class == ewcfg.trauma_class_slimegain:
            #	mining_yield *= (1 - 0.5 * user_data.degradation / 100)

            mining_yield = max(0, round(mining_yield))

            # Fatigue the miner.

            user_data.hunger += ewcfg.hunger_permine * int(hunger_cost_mod)
            if extra > 0:  # if hunger_cost_mod is not an integer
                # there's an x% chance that an extra stamina is deducted, where x is the fractional part of hunger_cost_mod in percent (times 100)
                if random.randint(1, 100) <= extra * 100:
                    user_data.hunger += ewcfg.hunger_permine

            levelup_response = user_data.change_slimes(n=mining_yield, source=ewcfg.source_mining)

            was_levelup = True if user_initial_level < user_data.slimelevel else False

            # Tell the player their slime level increased and/or they unearthed an item.
            if was_levelup:
                response += levelup_response

            user_data.persist()

            if printgrid:
                await print_grid(cmd)

            # gangsters don't need their roles updated
            if user_data.life_state == ewcfg.life_state_juvenile:
                await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)

    else:
        return await mismine(cmd, user_data, "channel")
    # response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!"

    if len(response) > 0:
        await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))