async def eat_item(cmd): user_data = EwUser(member=cmd.message.author) mutations = user_data.get_mutations() item_search = ewutils.flattenTokenListToString(cmd.tokens[1:]) food_item = None # look for a food item if a name was given if item_search: item_sought = bknd_item.find_item(item_search=item_search, id_user=user_data.id_user, id_server=user_data.id_server, item_type_filter=ewcfg.it_food) if item_sought: food_item = EwItem(id_item=item_sought.get('id_item')) else: item_sought = bknd_item.find_item(item_search=item_search, id_user=user_data.id_user, id_server=user_data.id_server) if item_sought and ewcfg.mutation_id_trashmouth in mutations: return await devour(cmd=cmd) # otherwise find the first useable food else: food_inv = bknd_item.inventory(id_user=user_data.id_user, id_server=user_data.id_server, item_type_filter=ewcfg.it_food) for food in food_inv: food_item = EwItem(id_item=food.get('id_item')) # check if the user can eat this item if float(getattr(food_item, "time_expir", 0)) > time.time() or \ food_item.item_props.get('perishable') not in ['true', '1'] or \ ewcfg.mutation_id_spoiledappetite in user_data.get_mutations(): break if food_item != None: response = user_data.eat(food_item) user_data.persist() else: if item_search: response = "Are you sure you have that item?" else: response = "You don't have anything to eat." await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
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))
async def devour(cmd): user_data = EwUser(member=cmd.message.author) item_search = ewutils.flattenTokenListToString(cmd.tokens[1:]) item_sought = bknd_item.find_item(id_server=cmd.message.guild.id, id_user=cmd.message.author.id, item_search=item_search) mutations = user_data.get_mutations() is_brick = 0 time_now = int(time.time()) mutation_data = EwMutation(id_user=user_data.id_user, id_server=user_data.id_server, id_mutation=ewcfg.mutation_id_trashmouth) if len(mutation_data.data) > 0: time_lastuse = int(mutation_data.data) else: time_lastuse = 0 if ewcfg.mutation_id_trashmouth not in mutations: response = "Wait, what? Quit trying to put everything in your mouth." elif item_sought: item_obj = EwItem(id_item=item_sought.get('id_item')) if time_lastuse + 60 > time_now: response = "You're still picking stuff out of your teeth from the last weird shit you ate. Try again in {} seconds.".format(time_lastuse + 60 - time_now) elif (item_obj.item_type not in [ewcfg.it_cosmetic, ewcfg.it_furniture, ewcfg.it_food] and item_obj.item_props.get('id_item') != 'slimepoudrin') or item_obj.item_props.get('id_cosmetic') == 'soul': response = "You swallow the {} whole, but after realizing this might be a mistake, you cough it back up.".format(item_sought.get('name')) elif item_obj.soulbound == True: response = "You attempt to consume the {}, but you realize it's soulbound and that you were about to eat your own existnece. Your life flashes before your eyes, so you decide to stop.".format(item_sought.get('name')) else: str_eat = "You unhinge your gaping maw and shove the {} right down, no chewing or anything. It's about as nutritious as you'd expect.".format(item_sought.get('name')) if item_obj.item_type == ewcfg.it_cosmetic: recover_hunger = 100 elif item_obj.item_type == ewcfg.it_furniture: furn = static_items.furniture_map.get(item_obj.item_props.get('id_furniture')) acquisition = None if furn is not None: acquisition = furn.acquisition if furn.id_furniture == 'brick': brickeat(item_obj=item_obj) is_brick = 1 recover_hunger = 50 response = str_eat elif acquisition != ewcfg.acquisition_bazaar: recover_hunger = 100 elif furn.price < 500: recover_hunger = 0 elif furn.price < 5000: recover_hunger = 50 elif furn.price < 1000000: recover_hunger = 320 else: recover_hunger = 16000 else: # This only happens in the case of propstanded items, so we just set it to the lowest possible recover_hunger = 50 elif item_obj.item_type == ewcfg.it_food: if item_obj.item_props.get('perishable') != None: perishable_status = item_obj.item_props.get('perishable') if perishable_status == 'true' or perishable_status == '1': item_is_non_perishable = False else: item_is_non_perishable = True else: item_is_non_perishable = False user_has_spoiled_appetite = ewcfg.mutation_id_spoiledappetite in mutations item_has_expired = float(getattr(item_obj, "time_expir", 0)) < time.time() if item_has_expired and not (user_has_spoiled_appetite or item_is_non_perishable): response = "You realize that the {} you were trying to eat is already spoiled. Ugh, not eating that.".format(item_sought.get('name')) return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) # ewitem.item_drop(food_item.id_item) recover_hunger = item_obj.item_props.get('recover_hunger') else: recover_hunger = 100 item_obj.item_props = { 'id_food': "convertedfood", 'food_name': "", 'food_desc': "", 'recover_hunger': recover_hunger, 'inebriation': 0, 'str_eat': str_eat, 'time_expir': time.time() + ewcfg.std_food_expir, 'time_fridged': 0, 'perishable': True, } if item_obj.item_type != ewcfg.it_food: mutation_data.data = '{}'.format(time_now) if is_brick == 0: response = user_data.eat(item_obj) user_data.persist() elif item_search == "": response = "Devour what?" else: response = "Are you sure you have that item?" return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))