def format_tutorial_response(scene): response = scene.text if scene.dungeon_state: response += "\n\nWhat do you do?\n\n**>options: " options = [] for path in scene.options.keys(): options.append("{}{}".format(ewcfg.cmd_prefix, path)) response += ewutils.formatNiceList(names=options, conjunction="or") response += "**" return response
def get_general_collection(id_item, id_server): item = EwItem(id_item=id_item) if 'decorate' not in str(item.id_owner): return "It's a multi-item display case. Best viewed when placed." id_item_col = "{}collection".format(id_item) item_inv = bknd_item.inventory(id_server=id_server, id_user=id_item_col) if len(item_inv) == 0: return "There's nothing in here at the moment." response = "You examine your preserved collection. Inside is " item_arr = [] for gen_item in item_inv: item_arr.append("a {} ({})".format(gen_item.get('name'), gen_item.get('id_item'))) response += "{}{}".format(ewutils.formatNiceList(names=item_arr), ".") return response
def get_fish_collection(id_item, id_server): item = EwItem(id_item=id_item) if 'decorate' not in str(item.id_owner): return 'It\'s a large aquarium, built for whole schools of fish. You can\'t see what\'s inside because you\'re nearly killing yourself carrying it.' id_item_col = "{}collection".format(id_item) fish_inv = bknd_item.inventory(id_server=id_server, id_user=id_item_col) response = "" if len(fish_inv) == 0: return "Look at all these- wait, you don't have any fish in here." elif len(fish_inv) == 1: response += "There's just one fish in here. It's feeling very loved." elif len(fish_inv) < 6: response += "It's pretty spacious in here!" elif len(fish_inv) < 43: response += "Look at all these fish!" else: response += "This thing is packed!" response += " There's " fish_arr = [] for fish in fish_inv: fish_item = EwItem(fish.get('id_item')) length = fish_item.item_props.get('length') if length is None: length = float( (ewcfg.fish_size_range.get(fish_item.item_props.get('size'))[0] + ewcfg.fish_size_range.get( fish_item.item_props.get('size'))[1]) / 2) fish_item.item_props['length'] = length fish_item.persist() fish_arr.append("a {} ({} in)".format(fish.get('name'), length)) response += "{}{}".format(ewutils.formatNiceList(names=fish_arr), ".") return response
async def stocks(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)) if cmd.message.channel.name != ewcfg.channel_stockexchange: # Only allowed in the stock exchange. response = "You must go to the Slime Stock Exchange to check the currently available stocks." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) 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)) response = "Here are the currently available stocks: {}".format(ewutils.formatNiceList(ewcfg.stocks)) # 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 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))
async def find_recipes_by_item(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)) used_recipe = None # if the player specifies an item name if cmd.tokens_count > 1: sought_item = ewutils.flattenTokenListToString(cmd.tokens[1:]) # Allow for the use of recipe aliases found_recipe = smelting.smelting_recipe_map.get(sought_item) if found_recipe != None: used_recipe = found_recipe.id_recipe # item_sought_in_inventory = bknd_item.find_item(item_search=sought_item, id_user=cmd.message.author.id, id_server=cmd.guild.id if cmd.guild is not None else None) makes_sought_item = [] uses_sought_item = [] # if the item name is an item in the player's inventory, we're assuming that the player is looking up information about this item specifically. # if item_sought_in_inventory is not None: # sought_item = item_sought_in_inventory.id_item # print(item_sought_in_inventory['item_def']) # man i could NOT get this to work . maybe another day # finds the recipes in questions that applys for name in smelting.recipe_names: # find recipes that this item is used as an ingredient in if smelting.smelting_recipe_map[name].ingredients.get(sought_item) is not None: uses_sought_item.append(name) # find recipes used to create this item elif sought_item in smelting.smelting_recipe_map[name].products: makes_sought_item.append(smelting.smelting_recipe_map[name]) # finds recipes based on possible recipe aliases elif used_recipe in smelting.smelting_recipe_map[name].products: makes_sought_item.append(smelting.smelting_recipe_map[name]) # zero matches in either of the above: if len(makes_sought_item) < 1 and len(uses_sought_item) < 1: response = "No recipes found for *{}*.".format(sought_item) # adds the recipe list to a response else: response = "\n" number_recipe = 1 list_length = len(makes_sought_item) for item in makes_sought_item: if (item.id_recipe == "toughcosmetic" and cosmetics.cosmetic_map[sought_item].style != ewcfg.style_tough or item.id_recipe == "smartcosmetic" and cosmetics.cosmetic_map[sought_item].style != ewcfg.style_smart or item.id_recipe == "beautifulcosmetic" and cosmetics.cosmetic_map[sought_item].style != ewcfg.style_beautiful or item.id_recipe == "cutecosmetic" and cosmetics.cosmetic_map[sought_item].style != ewcfg.style_cute or item.id_recipe == "coolcosmetic" and cosmetics.cosmetic_map[sought_item].style != ewcfg.style_cool): list_length -= 1 continue else: # formats items in form "# item" (like "1 poudrin" or whatever) ingredients_list = [] ingredient_strings = [] for ingredient in item.ingredients: ingredient_strings.append("{} {}".format(item.ingredients.get(ingredient), ingredient)) if number_recipe == 1: response += "To smelt this item, you'll need *{}*. ({})\n".format(ewutils.formatNiceList(names=ingredient_strings, conjunction="and"), item.id_recipe) else: response += "Alternatively, to smelt this item, you'll need *{}*. ({})\n".format(ewutils.formatNiceList(names=ingredient_strings, conjunction="and"), item.id_recipe) number_recipe += 1 if len(uses_sought_item) > 0: response += "This item can be used to smelt *{}*.".format(ewutils.formatNiceList(names=uses_sought_item, conjunction="and")) # if the player doesnt specify a 2nd argument else: response = "Please specify an item you would like to look up usage for." # send response to player await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def smelt(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)) # Find sought recipe. if cmd.tokens_count > 1: sought_result = ewutils.flattenTokenListToString(cmd.tokens[1:]) found_recipe = smelting.smelting_recipe_map.get(sought_result) if found_recipe != None: if 'soul' in found_recipe.products: return await smeltsoul(cmd=cmd) # Checks what ingredients are needed to smelt the recipe. necessary_ingredients = found_recipe.ingredients necessary_ingredients_list = [] owned_ingredients = [] # Seeks out the necessary ingredients in your inventory. missing_ingredients = [] for matched_item in necessary_ingredients: necessary_items = necessary_ingredients.get(matched_item) necessary_str = "{} {}".format(necessary_items, matched_item) if necessary_items > 1: necessary_str += "s" necessary_ingredients_list.append(necessary_str) sought_items = itm_utils.find_item_all(item_search=matched_item, id_user=user_data.id_user, id_server=user_data.id_server) missing_items = necessary_items - len(sought_items) if missing_items > 0: missing_str = "{} {}".format(missing_items, matched_item) if missing_items > 1: missing_str += "s" missing_ingredients.append(missing_str) else: for i in range(necessary_ingredients.get(matched_item)): sought_item = sought_items.pop() owned_ingredients.append(sought_item.get('id_item')) # If you don't have all the necessary ingredients. if len(missing_ingredients) > 0: response = "You've never done this before, have you? To smelt {}, you’ll need to combine *{}*.".format(found_recipe.str_name, ewutils.formatNiceList(names=necessary_ingredients_list, conjunction="and")) response += " You are missing *{}*.".format(ewutils.formatNiceList(names=missing_ingredients, conjunction="and")) else: # If you try to smelt a random cosmetic, use old smelting code to calculate what your result will be. if found_recipe.id_recipe == "coolcosmetic" or found_recipe.id_recipe == "toughcosmetic" or found_recipe.id_recipe == "smartcosmetic" or found_recipe.id_recipe == "beautifulcosmetic" or found_recipe.id_recipe == "cutecosmetic": if not bknd_item.check_inv_capacity(user_data=user_data, item_type=ewcfg.it_cosmetic): response = "You can't carry anymore cosmetic items." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) patrician_rarity = 100 patrician_smelted = random.randint(1, patrician_rarity) patrician = False if patrician_smelted <= 5: patrician = True cosmetics_list = [] if found_recipe.id_recipe == "toughcosmetic": style = ewcfg.style_tough elif found_recipe.id_recipe == "smartcosmetic": style = ewcfg.style_smart elif found_recipe.id_recipe == "beautifulcosmetic": style = ewcfg.style_beautiful elif found_recipe.id_recipe == "cutecosmetic": style = ewcfg.style_cute else: style = ewcfg.style_cool for result in static_cosmetics.cosmetic_items_list: if result.style == style and result.acquisition == ewcfg.acquisition_smelting: cosmetics_list.append(result) else: pass items = [] for cosmetic in cosmetics_list: if patrician and cosmetic.rarity == ewcfg.rarity_patrician: items.append(cosmetic) elif not patrician and cosmetic.rarity == ewcfg.rarity_plebeian: items.append(cosmetic) item = items[random.randint(0, len(items) - 1)] item_props = itm_utils.gen_item_props(item) 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 you're trying to smelt a specific item. else: possible_results = [] # Matches the recipe's listed products to actual items. for result in vendors.smelt_results: if hasattr(result, 'id_item'): if result.id_item not in found_recipe.products: pass else: possible_results.append(result) if hasattr(result, 'id_food'): if result.id_food not in found_recipe.products: pass else: possible_results.append(result) if hasattr(result, 'id_cosmetic'): if result.id_cosmetic not in found_recipe.products: pass else: possible_results.append(result) if hasattr(result, 'id_weapon'): if result.id_weapon not in found_recipe.products: pass else: possible_results.append(result) if hasattr(result, 'id_furniture'): if result.id_furniture not in found_recipe.products: pass else: possible_results.append(result) # If there are multiple possible products, randomly select one. item = random.choice(possible_results) if not bknd_item.check_inv_capacity(user_data=user_data, item_type=item.item_type): response = "You can't carry any more {}s.".format(item.item_type) 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) newitem_id = bknd_item.item_create( item_type=item.item_type, id_user=cmd.message.author.id, id_server=cmd.guild.id, item_props=item_props ) for id_item in owned_ingredients: item_check = EwItem(id_item=id_item) if item_check.item_props.get('id_cosmetic') != 'soul': bknd_item.item_delete(id_item=id_item) else: newitem = EwItem(id_item=newitem_id) newitem.item_props['target'] = id_item newitem.persist() bknd_item.give_item(id_item=id_item, id_user='******', id_server=cmd.guild.id) name = "" if hasattr(item, 'str_name'): name = item.str_name elif hasattr(item, 'id_weapon'): name = item.id_weapon response = "You sacrifice your {} to smelt a {}!!".format(ewutils.formatNiceList(names=necessary_ingredients_list, conjunction="and"), name) user_data.persist() else: response = "There is no recipe by the name." else: response = "Please specify a desired smelt result." # Send response await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def rate(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)) response = "" if cmd.message.channel.name != ewcfg.channel_stockexchange: # Only allowed in the stock exchange. response = "You must go to the Slime Stock Exchange to check the current stock exchange rates ." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) 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)) stock = "" if cmd.tokens_count > 0: stock = ewutils.flattenTokenListToString(cmd.tokens[1:]) if stock in ewcfg.stocks: stock = EwStock(id_server=cmd.guild.id, stock=stock) response = "The current value of {stock} stocks is {cred:,} SlimeCoin per 1000 Shares.".format(stock=ewcfg.stock_names.get(stock.id_stock), cred=stock.exchange_rate) elif stock == "": for stock in ewcfg.stocks: stock = EwStock(id_server=cmd.guild.id, stock=stock) response += "\nThe current value of {stock} stocks is {cred:,} SlimeCoin per 1000 Shares.".format(stock=ewcfg.stock_names.get(stock.id_stock), cred=stock.exchange_rate) else: response = "That's not a valid stock name, please use a proper one, you c**t: {}".format(ewutils.formatNiceList(ewcfg.stocks)) # 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 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))
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))
async def advertise(cmd): time_now = int(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 user_data.poi != ewcfg.poi_id_slimecorphq: response = "To buy ad space, you'll need to go SlimeCorp HQ." 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)) cost = ewcfg.slimecoin_toadvertise if user_data.slimecoin < cost: response = "Your don't have enough slimecoin to advertise. ({:,}/{:,})".format( user_data.slimecoin, cost) return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) ads = bknd_ads.get_ads(cmd.guild.id) if len(ads) >= ewcfg.max_concurrent_ads: first_ad = EwAd(id_ad=ads[0]) first_expire = first_ad.time_expir secs_to_expire = int(first_expire - time_now) mins_to_expire = int(secs_to_expire / 60) hours_to_expire = int(mins_to_expire / 60) days_to_expire = int(hours_to_expire / 24) expire_list = [] if hours_to_expire > 0: expire_list.append("{} days".format(days_to_expire)) if hours_to_expire > 0: expire_list.append("{} hours".format(hours_to_expire % 24)) if mins_to_expire > 0: expire_list.append("{} minutes".format(mins_to_expire % 60)) else: expire_list.append("{} seconds".format(secs_to_expire % 60)) time_to_expire = ewutils.formatNiceList(names=expire_list, conjunction="and") response = "Sorry, but all of our ad space is currently in use. The next vacancy will be in {}.".format( time_to_expire) return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) if cmd.tokens_count < 2: response = "Please specify the content of your ad." return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) content = cmd.message.content[len(cmd.tokens[0]):].strip() if len(content) > ewcfg.max_length_ads: response = "Your ad is too long, we can't fit that on a billboard. ({:,}/{:,})".format( len(content), ewcfg.max_length_ads) return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) sponsor_disclaimer = "Paid for by {}".format( cmd.message.author.display_name) response = "This is what your ad is going to look like." await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) response = "{}\n\n*{}*".format(content, sponsor_disclaimer) await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) response = "It will cost {:,} slimecoin to stay up for 4 weeks. Is this fine? {} or {}".format( cost, ewcfg.cmd_confirm, ewcfg.cmd_cancel) await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) accepted = False try: msg = await cmd.client.wait_for( 'message', timeout=30, check=lambda message: message.author == cmd.message.author and message.content.lower() in [ewcfg.cmd_confirm, ewcfg.cmd_cancel]) if msg != None: if msg.content.lower() == ewcfg.cmd_confirm: accepted = True except: accepted = False if accepted: bknd_ads.create_ad( id_server=cmd.guild.id, id_sponsor=cmd.message.author.id, content=content, time_expir=time_now + ewcfg.uptime_ads, ) user_data.change_slimecoin(n=-cost, coinsource=ewcfg.coinsource_spending) user_data.persist() response = "Your ad will be put up immediately. Thank you for your business." return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) else: response = "Good luck raising awareness by word of mouth." return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
def gen_data_text(id_user=None, id_server=None, display_name=None, channel_name=None): user_data = EwUser(id_user=id_user, id_server=id_server, data_level=2) slimeoid = EwSlimeoid(id_user=id_user, id_server=id_server) cosmetics = bknd_item.inventory(id_user=user_data.id_user, id_server=user_data.id_server, item_type_filter=ewcfg.it_cosmetic) adorned_cosmetics = [] for cosmetic in cosmetics: cos = EwItem(id_item=cosmetic.get('id_item')) if cos.item_props['adorned'] == 'true': hue = hue_static.hue_map.get(cos.item_props.get('hue')) adorned_cosmetics.append((hue.str_name + " " if hue != None else "") + cosmetic.get('name')) if user_data.life_state == ewcfg.life_state_grandfoe: poi = poi_static.id_to_poi.get(user_data.poi) if poi != None: response = "{} is {} {}.".format(display_name, poi.str_in, poi.str_name) else: response = "You can't discern anything useful about {}.".format( display_name) else: # return somebody's score # get race flavor text player_race = ewcfg.defined_races.get(user_data.race) if player_race != None: race_prefix = player_race.get("race_prefix", "") race_suffix = player_race.get("race_suffix", "") else: race_prefix = "" race_suffix = "" if user_data.life_state == ewcfg.life_state_corpse: response = "{} is a {}level {} {}dead{}.".format( display_name, race_prefix, user_data.slimelevel, race_suffix, user_data.gender) elif user_data.life_state == ewcfg.life_state_shambler: response = "{} is a {}level {} {}shambler.".format( display_name, race_prefix, user_data.slimelevel, race_suffix) else: response = "{} is a {}level {} {}slime{}.".format( display_name, race_prefix, user_data.slimelevel, race_suffix, user_data.gender) """if user_data.degradation < 20: pass elif user_data.degradation < 40: response += " Their bodily integrity is starting to slip." elif user_data.degradation < 60: response += " Their face seems to be melting and they periodically have to put it back in place." elif user_data.degradation < 80: response += " They are walking a bit funny, because their legs are getting mushy." elif user_data.degradation < 100: response += " Their limbs keep falling off. It's really annoying." else: response += " They almost look like a shambler already.""" coinbounty = int(user_data.bounty / ewcfg.slimecoin_exchangerate) weapon_item = EwItem(id_item=user_data.weapon) weapon = static_weapons.weapon_map.get( weapon_item.item_props.get("weapon_type")) if weapon != None: response += " {} {}{}.".format( ewcfg.str_weapon_married if user_data.weaponmarried == True else ewcfg.str_weapon_wielding, ("" if len(weapon_item.item_props.get("weapon_name")) == 0 else "{}, ".format(weapon_item.item_props.get("weapon_name"))), weapon.str_weapon) if user_data.weaponskill >= 5: response += " {}".format( weapon.str_weaponmaster.format( rank=(user_data.weaponskill - 4), title="master")) else: response += " {}".format( weapon.str_weaponmaster.format(rank=user_data.weaponskill, title="rookie")) sidearm_item = EwItem(id_item=user_data.sidearm) sidearm = static_weapons.weapon_map.get( sidearm_item.item_props.get("weapon_type")) if sidearm != None: response += " They have sidearmed {}{}.".format( ("" if len(sidearm_item.item_props.get("weapon_name")) == 0 else "{}, ".format( sidearm_item.item_props.get("weapon_name"))), sidearm.str_weapon) trauma = se_static.trauma_map.get(user_data.trauma) if trauma != None: response += " {}".format(trauma.str_trauma) response_block = "" user_kills = ewstats.get_stat(user=user_data, metric=ewcfg.stat_kills) enemy_kills = ewstats.get_stat(user=user_data, metric=ewcfg.stat_pve_kills) response_block += "{}{}".format( get_crime_level(num=user_data.crime, forYou=0), " ") if user_kills > 0 and enemy_kills > 0: response_block += "They have {:,} confirmed kills, and {:,} confirmed hunts. ".format( user_kills, enemy_kills) elif user_kills > 0: response_block += "They have {:,} confirmed kills. ".format( user_kills) elif enemy_kills > 0: response_block += "They have {:,} confirmed hunts. ".format( enemy_kills) if coinbounty != 0: response_block += "SlimeCorp offers a bounty of {:,} SlimeCoin for their death. ".format( coinbounty) if len(adorned_cosmetics) > 0: response_block += "They have a {} adorned. ".format( ewutils.formatNiceList(adorned_cosmetics, 'and')) if user_data.freshness < ewcfg.freshnesslevel_1: response_block += "Their outfit is starting to look pretty fresh, but They’ve got a long way to go if they wanna be NLACakaNM’s next top model. " elif user_data.freshness < ewcfg.freshnesslevel_2: response_block += "Their outfit is low-key on point, not gonna lie. They’re goin’ places, kid. " elif user_data.freshness < ewcfg.freshnesslevel_3: response_block += "Their outfit is lookin’ fresh as hell, goddamn! They shop so much they can probably speak Italian. " elif user_data.freshness < ewcfg.freshnesslevel_4: response_block += "Their outfit is straight up **GOALS!** Like, honestly. I’m being, like, totally sincere right now. Their Instragrime has attracted a small following. " else: response_block += "Holy shit! Their outfit is downright, positively, without a doubt, 100% **ON FLEEK!!** They’ve blown up on Instragrime, and they’ve got modeling gigs with fashion labels all across the city. " statuses = user_data.getStatusEffects() for status in statuses: status_effect = EwStatusEffect(id_status=status, user_data=user_data) if status_effect.time_expire > time.time( ) or status_effect.time_expire == -1: status_flavor = se_static.status_effects_def_map.get(status) severity = "" try: value_int = int(status_effect.value) if value_int < 3: severity = "lightly injured." elif value_int < 7: severity = "battered and bruised." elif value_int < 11: severity = "severely damaged." else: severity = "completely f****d up, holy shit!" except: pass format_status = {'severity': severity} if status_flavor is not None: response_block += status_flavor.str_describe.format_map( format_status) + " " if (slimeoid.life_state == ewcfg.slimeoid_state_active): # If the user isn't a corpse if user_data.life_state != ewcfg.life_state_corpse: response_block += "They are accompanied by {}, a {}-foot-tall Slimeoid. ".format( slimeoid.name, str(slimeoid.level)) # If the user is a corpse, but has a negaslimeoid elif slimeoid.sltype == ewcfg.sltype_nega: response_block += "They are accompanied by {}, a {}-foot-tall Negaslimeoid. ".format( slimeoid.name, str(slimeoid.level)) # if user_data.swear_jar >= 500: # response_block += "They're going to The Underworld for the things they've said." # elif user_data.swear_jar >= 100: # response_block += "They swear like a sailor!" # elif user_data.swear_jar >= 50: # response_block += "They have quite a profane vocabulary." # elif user_data.swear_jar >= 10: # response_block += "They've said some naughty things in the past." # elif user_data.swear_jar >= 5: # response_block += "They've cussed a handful of times here and there." # elif user_data.swear_jar > 0: # response_block += "They've sworn only a few times." # else: # response_block += "Their mouth is clean as a whistle." if len(response_block) > 0: response += "\n" + response_block return response
def test_formatNiceList(self): self.assertEqual(ewutils.formatNiceList(['a', 'b', 'c']), 'a, b, and c') self.assertEqual(ewutils.formatNiceList(['a', 'b'], 'or'), 'a or b')
async def publish_manuscript(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) poi = poi_static.id_to_poi.get(user_data.poi) if not poi.write_manuscript: response = "You'd love to work on your zine, however your current location doesn't strike you as a particularly good place to write. Try heading over the the Cafe, the Comic Shop, or one of the colleges (NLACU/NMS)." elif user_data.manuscript == -1: response = "You have yet to create a manuscript. Try !createmanuscript" else: book = EwBook(member=cmd.message.author, book_state=0) # check if zine is unreasonably short length = 0 for page in book.book_pages.keys(): length += len(book.book_pages[page]) if book.genre == -1: response = "Before you publish your zine, you must first set a genre with !setgenre. The genre choices are {}.".format(ewutils.formatNiceList(ewcfg.book_genres)) elif len(book.book_pages.keys()) < 3 or length < 10: response = "Who are you trying to fool? This zine is obviously too short!" else: accepted = False response = "Are you sure you want to publish your manuscript? This cannot be undone. **!accept** or **!refuse**" 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 not accepted: response = "The manuscript was not published." else: book.book_state = 1 book.date_published = market_data.day length = 0 for page in range(1, book.pages + 1): length += len(book.book_pages.get(page, "")) book.length = length user_data.manuscript = -1 user_data.persist() book.persist() bknd_item.item_create( item_type=ewcfg.it_book, id_user=user_data.id_user, id_server=book.id_server, item_props={ "title": book.title, "author": book.author, "date_published": book.date_published, "id_book": book.id_book, "book_desc": "A zine by {}, published on {}. It's the author's copy.".format(book.author, book.date_published) }) book_sale = EwBookSale(id_book=book.id_book, member=cmd.message.author) book_sale.bought = 1 book_sale.persist() response = "You've published your manuscript! Anybody can now buy your creation and you'll get royalties!" await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def set_genre(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)) genre = cmd.message.content[(len(cmd.tokens[0])):].strip() poi = poi_static.id_to_poi.get(user_data.poi) if not poi.write_manuscript: response = "You'd love to work on your zine, however your current location doesn't strike you as a particularly good place to write. Try heading over the the Cafe, the Comic Shop, or one of the colleges (NLACU/NMS)." elif user_data.hunger >= user_data.get_hunger_max() and user_data.life_state != ewcfg.life_state_corpse: response = "You are just too hungry to alter the title of your masterpiece!" elif user_data.manuscript == -1: response = "You have yet to create a manuscript. Try !createmanuscript" elif genre not in ewcfg.book_genres: response = "Please specify the genre you want to change it to. You can choose from {}.".format(ewutils.formatNiceList(ewcfg.book_genres)) else: for i in [i for i, x in enumerate(ewcfg.book_genres) if x == genre]: id_genre = i book = EwBook(member=cmd.message.author, book_state=0) if id_genre == 10 and not cmd.message.author.guild_permissions.administrator: response = "You're not a doctor. The publishing company's gonna skin your ass, so you better not." else: book.genre = id_genre book.persist() response = "You scribble {} onto the back cover.".format(genre) await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def set_length(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)) poi = poi_static.id_to_poi.get(user_data.poi) if not poi.write_manuscript: response = "You'd love to work on your zine, however your current location doesn't strike you as a particularly good place to write. Try heading over the the Cafe, the Comic Shop, or one of the colleges (NLACU/NMS)." elif user_data.hunger >= user_data.get_hunger_max() and user_data.life_state != ewcfg.life_state_corpse: response = "You are just too hungry to alter the length of your masterpiece!" elif user_data.manuscript == -1: response = "You have yet to create a manuscript. Try !createmanuscript" elif len(cmd.tokens) == 1: response = "Specify how many pages you want it to be ({} and {} pages).".format(ewcfg.minimum_pages, ewcfg.maximum_pages) else: length = cmd.tokens[1] if not length.isdigit(): response = "Your manuscript can be between {} and {} pages".format(ewcfg.minimum_pages, ewcfg.maximum_pages) else: book = EwBook(member=cmd.message.author, book_state=0) length = int(length) if book.pages == length: response = "Your manuscript is already {} pages long.".format(length) elif length > ewcfg.maximum_pages or length < ewcfg.minimum_pages: response = "Your manuscript can be between {} and {} pages".format(ewcfg.minimum_pages, ewcfg.maximum_pages) else: pages_with_content = [] for page in book.book_pages.keys(): if book.book_pages.get(page) is not None: if page > length: pages_with_content.append(page) accepted = True if len(pages_with_content) != 0: accepted = False page_list = ewutils.formatNiceList(pages_with_content) response = "There is writing on these pages: {}. If you change the number of pages to {}, you will cut these pages out. Will you still do it? **!accept** or **!refuse**".format(page_list, length) 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 not accepted: response = "The pages remain unchanged." else: if length > book.pages: response = "You haphazardly slap on a few extra pages at the end of your manuscript so you can write more bullshit." else: response = "You violently tear some pages out of your manuscript." book.pages = length if len(pages_with_content) != 0: for page in pages_with_content: del book.book_pages[page] book.persist() await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))