async def order(cmd): user_data = EwUser(member=cmd.message.author) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 = ewcfg.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 = ewcfg.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( ) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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(ewcfg.furniture_pony) item = ewcfg.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 = ewcfg.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 = ewcfg.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 = ewcfg.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 ewcfg.furniture_pony: item.vendors = [ewcfg.vendor_bazaar] if item == None: item = ewcfg.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_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 ewcfg.furniture_pony and "mylittleponyfigurine" in market_data.bazaar_wares.values( ): pass else: current_vendor = None if current_vendor == ewcfg.vendor_downpourlaboratory: currency_used = 'brainz' current_currency_amount = user_data.gvs_currency 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 = ewutils.get_subzone_controlling_faction( user_data.poi, user_data.id_server) if controlling_faction != "" and poi.id_poi != ewcfg.poi_id_nuclear_beach_edge: # 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: if item_type == ewcfg.it_food: food_ordered = True food_items = ewitem.inventory( id_user=cmd.message.author.id, id_server=cmd.guild.id, item_type_filter=ewcfg.it_food) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) if len(food_items) >= user_data.get_food_capacity( ) and target_data == None and togo: # user_data never got persisted so the player won't lose money unnecessarily response = "You can't carry any more food than that." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) elif item_type == ewcfg.it_weapon: weapons_held = ewitem.inventory( id_user=user_data.id_user, id_server=cmd.guild.id, item_type_filter=ewcfg.it_weapon) has_weapon = False # Thrown weapons are stackable if ewcfg.weapon_class_thrown in item.classes: # Check the player's inventory for the weapon and add amount to stack size. Create a new item the max stack size has been reached for wep in weapons_held: weapon = EwItem(id_item=wep.get("id_item")) if weapon.item_props.get( "weapon_type" ) == item.id_weapon and weapon.stack_size < weapon.stack_max: has_weapon = True weapon.stack_size += 1 weapon.persist() if value == 0: response = "You swipe a {} from the counter at {}.".format( item.str_weapon, current_vendor) else: response = "You slam {:,} slime down on the counter at {} for {}.".format( value, current_vendor, item.str_weapon) user_data.change_slimes( n=-value, source=ewcfg.source_spending) user_data.persist() return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) if has_weapon == False: if len(weapons_held ) >= user_data.get_weapon_capacity(): response = "You can't carry any more weapons." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) elif user_data.life_state == ewcfg.life_state_corpse: response = "Ghosts can't hold weapons." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) item_props = ewitem.gen_item_props(item) customtext = cmd.message.content[(len(cmd.tokens[0]) + len(cmd.tokens[1]) + 2):] if item.item_type == ewcfg.it_furniture and "custom" in item_props.get( 'id_furniture'): if customtext == "": response = "You need to specify the customization text before buying a custom item. Come on, isn't that self-evident?" return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) # 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) elif currency_used == 'brainz': user_data.gvs_currency -= value 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'): item_props['furniture_name'] = item_props[ 'furniture_name'].format(custom=customtext) item_props['furniture_desc'] = item_props[ 'furniture_desc'].format(custom=customtext) item_props['furniture_look_desc'] = item_props[ 'furniture_look_desc'].format( custom=customtext) item_props['furniture_place_desc'] = item_props[ 'furniture_place_desc'].format( custom=customtext) item.str_name = item.str_name.format( custom=customtext) id_item = ewitem.item_create( item_type=item_type, id_user=cmd.message.author.id, id_server=cmd.guild.id, stack_max=20 if item_type == ewcfg.it_weapon and ewcfg.weapon_class_thrown in item.classes else -1, stack_size=1 if item_type == ewcfg.it_weapon and ewcfg.weapon_class_thrown in item.classes else 0, item_props=item_props) if value == 0: response = "You swipe a {} from the counter at {}.".format( item.str_name, current_vendor) else: response = "You slam {:,} {} down on the counter at {} for {}.".format( value, currency_used, current_vendor, item.str_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( item.str_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, item.str_name, target_player_data.display_name) response += "\n\n*{}*: ".format( target_player_data.display_name ) + target_data.eat(item_data) target_data.persist() asyncio.ensure_future( ewutils.decrease_food_multiplier( user_data.id_user)) else: if value == 0: response = "You swipe a {} from the counter at {} and eat it right on the spot.".format( item.str_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, item.str_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() asyncio.ensure_future( ewutils.decrease_food_multiplier( user_data.id_user)) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) market_data = EwMarket(id_server=cmd.guild.id) #poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name) poi = ewcfg.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 = ewcfg.id_to_poi.get(user_data.poi) mother_district_data = None for mother_poi in poi.mother_districts: mother_poi_data = ewcfg.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) controlling_faction = ewutils.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 = ewcfg.vendor_inv[ vendor] if vendor != ewcfg.vendor_bazaar else market_data.bazaar_wares.values( ) for item_name in vendor_inv: item_item = ewcfg.item_map.get(item_name) food_item = ewcfg.food_map.get(item_name) cosmetic_item = ewcfg.cosmetic_map.get(item_name) furniture_item = ewcfg.furniture_map.get(item_name) weapon_item = ewcfg.weapon_map.get(item_name) # 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 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 mother_district_data.all_streets_taken( ) != "" and poi.id_poi != ewcfg.poi_id_nuclear_beach_edge: # prices are halved for the controlling gang if mother_district_data.all_streets_taken( ) == 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('{name} ({price})'.format(name=item_name, price=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_basedhardware: 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
async def menu(cmd): user_data = EwUser(member=cmd.message.author) market_data = EwMarket(id_server=cmd.message.server.id) poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name) if poi is None or len(poi.vendors) == 0: # 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: if poi.is_subzone: district_data = EwDistrict(district=poi.mother_district, id_server=cmd.message.server.id) else: district_data = EwDistrict(district=poi.id_poi, id_server=cmd.message.server.id) response = "{} Menu:\n\n".format(poi.str_name) for vendor in poi.vendors: items = [] # If the vendor is the bazaar get the current rotation of items from the market_data vendor_inv = ewcfg.vendor_inv[ vendor] if vendor != ewcfg.vendor_bazaar else market_data.bazaar_wares.values( ) for item_name in vendor_inv: item_item = ewcfg.item_map.get(item_name) food_item = ewcfg.food_map.get(item_name) cosmetic_item = ewcfg.cosmetic_map.get(item_name) furniture_item = ewcfg.furniture_map.get(item_name) weapon_item = ewcfg.weapon_map.get(item_name) # 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 stock_data != None: value *= (stock_data.exchange_rate / ewcfg.default_stock_exchange_rate)**0.2 if district_data.controlling_faction != "": # prices are halved for the controlling gang if district_data.controlling_faction == user_data.faction: value /= 2 # and 4 times as much for enemy gangsters elif user_data.faction != "": value *= 4 value = int(value) if value != 0: items.append('{name} ({price})'.format(name=item_name, price=value)) else: items.append(item_name) response += "**{}**: *{}*\n".format( vendor, ewutils.formatNiceList(names=items)) 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." # Send the response to the player. await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
async def order(cmd): user_data = EwUser(member=cmd.message.author) market_data = EwMarket(id_server=cmd.message.server.id) poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name) if poi is None or len(poi.vendors) == 0: # 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: value = ewutils.flattenTokenListToString(cmd.tokens[1:]) #if cmd.tokens_count > 1: # value = cmd.tokens[1] # value = value.lower() # Finds the item if it's an EwGeneralItem. item = ewcfg.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 = ewcfg.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 = ewcfg.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 = ewcfg.furniture_map.get(value) item_type = ewcfg.it_furniture if item != None: item_id = item.id_furniture name = item.str_name if item == None: item = ewcfg.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_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(): 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 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 if poi.is_subzone: district_data = EwDistrict(district=poi.mother_district, id_server=cmd.message.server.id) else: district_data = EwDistrict(district=poi.id_poi, id_server=cmd.message.server.id) if district_data.controlling_faction != "": # prices are halved for the controlling gang if district_data.controlling_faction == user_data.faction: value /= 2 # and 4 times as much for enemy gangsters elif user_data.faction != "": value *= 4 value = int(value) # 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 # Yo, Slimernalia! if item_type == ewcfg.it_food: value = 0 if value > user_data.slimes: # Not enough money. response = "A {} costs {:,} slime, and you only have {:,}.".format( name, value, user_data.slimes) else: if item_type == ewcfg.it_food: food_items = ewitem.inventory( id_user=cmd.message.author.id, id_server=cmd.message.server.id, item_type_filter=ewcfg.it_food) if len(food_items) >= user_data.get_food_capacity(): # user_data never got persisted so the player won't lose money unnecessarily response = "You can't carry any more food than that." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) elif item_type == ewcfg.it_weapon: weapons_held = ewitem.inventory( id_user=user_data.id_user, id_server=cmd.message.server.id, item_type_filter=ewcfg.it_weapon) has_weapon = False # Thrown weapons are stackable if ewcfg.weapon_class_thrown in item.classes: # Check the player's inventory for the weapon and add amount to stack size. Create a new item the max stack size has been reached for wep in weapons_held: weapon = EwItem(id_item=wep.get("id_item")) if weapon.item_props.get( "weapon_type" ) == item.id_weapon and weapon.stack_size < weapon.stack_max: has_weapon = True weapon.stack_size += 1 weapon.persist() response = "You slam {:,} slime down on the counter at {} for {}.".format( value, current_vendor, item.str_weapon) user_data.change_slimes( n=-value, source=ewcfg.source_spending) user_data.persist() return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) if has_weapon == False: if len(weapons_held ) >= user_data.get_weapon_capacity(): response = "You can't carry any more weapons." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) elif user_data.life_state == ewcfg.life_state_corpse: response = "Ghosts can't hold weapons." return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, response)) user_data.change_slimes(n=-value, source=ewcfg.source_spending) if company_data is not None: company_data.recent_profits += value company_data.persist() item_props = ewitem.gen_item_props(item) if item.str_name == "arcade cabinet": item_props['furniture_desc'] = random.choice( ewcfg.cabinets_list) ewitem.item_create( item_type=item_type, id_user=cmd.message.author.id, id_server=cmd.message.server.id, stack_max=20 if item_type == ewcfg.it_weapon and ewcfg.weapon_class_thrown in item.classes else -1, stack_size=1 if item_type == ewcfg.it_weapon and ewcfg.weapon_class_thrown in item.classes else 0, item_props=item_props) response = "You slam {:,} slime down on the counter at {} for {}.".format( value, current_vendor, item.str_name) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
async def on_ready(): global init_complete if init_complete: return init_complete = True ewcfg.set_client(client) ewutils.logMsg('Logged in as {} ({}).'.format(client.user.name, client.user.id)) ewutils.logMsg("Loaded NLACakaNM world map. ({}x{})".format(ewmap.map_width, ewmap.map_height)) ewmap.map_draw() # Flatten role names to all lowercase, no spaces. fake_observer = EwUser() fake_observer.life_state = ewcfg.life_state_observer for poi in ewcfg.poi_list: if poi.role != None: poi.role = ewutils.mapRoleName(poi.role) neighbors = [] neighbor_ids = [] if poi.coord != None: neighbors = ewmap.path_to(coord_start = poi.coord, user_data = fake_observer) #elif poi.id_poi == ewcfg.poi_id_thesewers: # neighbors = ewcfg.poi_list if neighbors != None: for neighbor in neighbors: neighbor_ids.append(neighbor.id_poi) ewcfg.poi_neighbors[poi.id_poi] = set(neighbor_ids) ewutils.logMsg("Found neighbors for poi {}: {}".format(poi.id_poi, ewcfg.poi_neighbors[poi.id_poi])) for id_poi in ewcfg.landmark_pois: ewutils.logMsg("beginning landmark precomputation for " + id_poi) poi = ewcfg.id_to_poi.get(id_poi) ewmap.landmarks[id_poi] = ewmap.score_map_from( coord_start = poi.coord, user_data = fake_observer, landmark_mode = True ) ewutils.logMsg("finished landmark precomputation") try: await client.change_presence(game = discord.Game(name = "EW " + ewcfg.version)) except: ewutils.logMsg("Failed to change_presence!") # Look for a Twitch client_id on disk. # FIXME debug - temporarily disable Twitch integration if False: twitch_client_id = ewutils.getTwitchClientId() # If no twitch client ID is available, twitch integration will be disabled. # FIXME debug - temporarily disable Twitch integration. if True: twitch_client_id = None ewutils.logMsg('Twitch integration disabled.') elif twitch_client_id == None or len(twitch_client_id) == 0: ewutils.logMsg('No twitch_client_id file found. Twitch integration disabled.') else: ewutils.logMsg("Enabled Twitch integration.") # Channels in the connected discord servers to announce to. channels_announcement = [] # Channels in the connected discord servers to send stock market updates to. Map of server ID to channel. channels_stockmarket = {} for server in client.servers: # Update server data in the database ewserver.server_update(server = server) # store the list of channels in an ewutils field ewcfg.update_server_list(server = server) # find roles and add them to the database ewrolemgr.setupRoles(client = client, id_server = server.id) # hides the names of poi roles await ewrolemgr.hideRoleNames(client = client, id_server = server.id) # Grep around for channels ewutils.logMsg("connected to server: {}".format(server.name)) for channel in server.channels: if(channel.type == discord.ChannelType.text): if(channel.name == ewcfg.channel_twitch_announcement): channels_announcement.append(channel) ewutils.logMsg("• found channel for announcements: {}".format(channel.name)) elif(channel.name == ewcfg.channel_stockexchange): channels_stockmarket[server.id] = channel ewutils.logMsg("• found channel for stock exchange: {}".format(channel.name)) # create all the districts in the database for poi_object in ewcfg.poi_list: poi = poi_object.id_poi # call the constructor to create an entry if it doesnt exist yet dist = EwDistrict(id_server = server.id, district = poi) # change the ownership to the faction that's already in control to initialize topic names try: # initialize gang bases if poi == ewcfg.poi_id_rowdyroughhouse: dist.controlling_faction = ewcfg.faction_rowdys elif poi == ewcfg.poi_id_copkilltown: dist.controlling_faction = ewcfg.faction_killers resp_cont = dist.change_ownership(new_owner = dist.controlling_faction, actor = "init", client = client) dist.persist() await resp_cont.post() except: ewutils.logMsg('Could not change ownership for {} to "{}".'.format(poi, dist.controlling_faction)) asyncio.ensure_future(ewdistrict.capture_tick_loop(id_server = server.id)) asyncio.ensure_future(ewutils.bleed_tick_loop(id_server = server.id)) asyncio.ensure_future(ewutils.enemy_action_tick_loop(id_server=server.id)) asyncio.ensure_future(ewutils.spawn_enemies_tick_loop(id_server = server.id)) asyncio.ensure_future(ewutils.burn_tick_loop(id_server = server.id)) asyncio.ensure_future(ewutils.remove_status_loop(id_server = server.id)) asyncio.ensure_future(ewworldevent.event_tick_loop(id_server = server.id)) asyncio.ensure_future(ewutils.sap_tick_loop(id_server = server.id)) if not debug: await ewtransport.init_transports(id_server = server.id) asyncio.ensure_future(ewweather.weather_tick_loop(id_server = server.id)) asyncio.ensure_future(ewslimeoid.slimeoid_tick_loop(id_server = server.id)) asyncio.ensure_future(ewfarm.farm_tick_loop(id_server = server.id)) try: ewutils.logMsg('Creating message queue directory.') os.mkdir(ewcfg.dir_msgqueue) except FileExistsError: ewutils.logMsg('Message queue directory already exists.') ewutils.logMsg('Ready.') """ Set up for infinite loop to perform periodic tasks. """ time_now = int(time.time()) time_last_pvp = time_now time_last_twitch = time_now time_twitch_downed = 0 # Every three hours we log a message saying the periodic task hook is still active. On startup, we want this to happen within about 60 seconds, and then on the normal 3 hour interval. time_last_logged = time_now - ewcfg.update_hookstillactive + 60 stream_live = None ewutils.logMsg('Beginning periodic hook loop.') while not ewutils.TERMINATE: time_now = int(time.time()) # Periodic message to log that this stuff is still running. if (time_now - time_last_logged) >= ewcfg.update_hookstillactive: time_last_logged = time_now ewutils.logMsg("Periodic hook still active.") # Check to see if a stream is live via the Twitch API. # FIXME disabled if False: #if twitch_client_id != None and (time_now - time_last_twitch) >= ewcfg.update_twitch: time_last_twitch = time_now try: # Twitch API call to see if there are any active streams. json_string = "" p = subprocess.Popen( "curl -H 'Client-ID: {}' -X GET 'https://api.twitch.tv/helix/streams?user_login = rowdyfrickerscopkillers' 2>/dev/null".format(twitch_client_id), shell = True, stdout = subprocess.PIPE ) for line in p.stdout.readlines(): json_string += line.decode('utf-8') json_parsed = json.loads(json_string) # When a stream is up, data is an array of stream information objects. data = json_parsed.get('data') if data != None: data_count = len(data) stream_was_live = stream_live stream_live = True if data_count > 0 else False if stream_was_live == True and stream_live == False: time_twitch_downed = time_now if stream_was_live == False and stream_live == True and (time_now - time_twitch_downed) > 600: ewutils.logMsg("The stream is now live.") # The stream has transitioned from offline to online. Make an announcement! for channel in channels_announcement: await ewutils.send_message( client, channel, "ATTENTION CITIZENS. THE **ROWDY F****R** AND THE **COP KILLER** ARE **STREAMING**. BEWARE OF INCREASED KILLER AND ROWDY ACTIVITY.\n\n@everyone\n{}".format( "https://www.twitch.tv/rowdyfrickerscopkillers" ) ) except: ewutils.logMsg('Twitch handler hit an exception (continuing): {}'.format(json_string)) traceback.print_exc(file = sys.stdout) # Clear PvP roles from players who are no longer flagged. if (time_now - time_last_pvp) >= ewcfg.update_pvp: time_last_pvp = time_now try: for server in client.servers: role_ids = [] for pvp_role in ewcfg.role_to_pvp_role.values(): role = ewrolemgr.EwRole(id_server = server.id, name = pvp_role) role_ids.append(role.id_role) # Monitor all user roles and update if a user is no longer flagged for PvP. for member in server.members: for role in member.roles: if role.id in role_ids: await ewrolemgr.updateRoles(client = client, member = member) break except: ewutils.logMsg('An error occurred in the scheduled role update task:') traceback.print_exc(file=sys.stdout) # Adjust the exchange rate of slime for the market. try: for server in client.servers: # Load market data from the database. market_data = EwMarket(id_server = server.id) if market_data.time_lasttick + ewcfg.update_market <= time_now: market_response = "" for stock in ewcfg.stocks: s = EwStock(server.id, stock) # we don't update stocks when they were just added if s.timestamp != 0: s.timestamp = time_now market_response = ewmarket.market_tick(s, server.id) await ewutils.send_message(client, channels_stockmarket.get(server.id), market_response) market_data = EwMarket(id_server = server.id) market_data.time_lasttick = time_now # Advance the time and potentially change weather. market_data.clock += 1 if market_data.clock >= 24 or market_data.clock < 0: market_data.clock = 0 market_data.day += 1 if market_data.clock == 6: # Update the list of available bazaar items by clearing the current list and adding the new items market_data.bazaar_wares.clear() bazaar_foods = [] bazaar_cosmetics = [] bazaar_general_items = [] bazaar_furniture = [] for item in ewcfg.vendor_inv.get(ewcfg.vendor_bazaar): if item in ewcfg.item_names: bazaar_general_items.append(item) elif item in ewcfg.food_names: bazaar_foods.append(item) elif item in ewcfg.cosmetic_names: bazaar_cosmetics.append(item) elif item in ewcfg.furniture_names: bazaar_furniture.append(item) market_data.bazaar_wares['slimecorp1'] = ewcfg.weapon_id_umbrella market_data.bazaar_wares['slimecorp2'] = ewcfg.cosmetic_id_raincoat market_data.bazaar_wares['generalitem'] = random.choice(bazaar_general_items) market_data.bazaar_wares['food1'] = random.choice(bazaar_foods) # Don't add repeated foods bw_food2 = None while bw_food2 is None or bw_food2 in market_data.bazaar_wares.values(): bw_food2 = random.choice(bazaar_foods) market_data.bazaar_wares['food2'] = bw_food2 market_data.bazaar_wares['cosmetic1'] = random.choice(bazaar_cosmetics) # Don't add repeated cosmetics bw_cosmetic2 = None while bw_cosmetic2 is None or bw_cosmetic2 in market_data.bazaar_wares.values(): bw_cosmetic2 = random.choice(bazaar_cosmetics) market_data.bazaar_wares['cosmetic2'] = bw_cosmetic2 bw_cosmetic3 = None while bw_cosmetic3 is None or bw_cosmetic3 in market_data.bazaar_wares.values(): bw_cosmetic3 = random.choice(bazaar_cosmetics) market_data.bazaar_wares['cosmetic3'] = bw_cosmetic3 bw_furniture2 = None while bw_furniture2 is None or bw_furniture2 in market_data.bazaar_wares.values(): bw_furniture2 = random.choice(bazaar_furniture) market_data.bazaar_wares['furniture2'] = bw_furniture2 bw_furniture3 = None while bw_furniture3 is None or bw_furniture3 in market_data.bazaar_wares.values(): bw_furniture3 = random.choice(bazaar_furniture) market_data.bazaar_wares['furniture3'] = bw_furniture3 if random.random() == 0.1: market_data.bazaar_wares['minigun'] = ewcfg.weapon_id_minigun market_data.persist() if not ewutils.check_fursuit_active(market_data.id_server): ewcosmeticitem.dedorn_all_costumes() if market_data.clock == 6 and market_data.day % 8 == 0: await ewapt.rent_time(id_server=server.id) market_data = EwMarket(id_server=server.id) market_data.persist() if market_data.clock == 6: response = ' The SlimeCorp Stock Exchange is now open for business.' await ewutils.send_message(client, channels_stockmarket.get(server.id), response) elif market_data.clock == 20: response = ' The SlimeCorp Stock Exchange has closed for the night.' await ewutils.send_message(client, channels_stockmarket.get(server.id), response) market_data = EwMarket(id_server = server.id) if random.randrange(3) == 0: pattern_count = len(ewcfg.weather_list) if pattern_count > 1: weather_old = market_data.weather if random.random() < 0.4: market_data.weather = ewcfg.weather_bicarbonaterain # Randomly select a new weather pattern. Try again if we get the same one we currently have. while market_data.weather == weather_old: pick = random.randrange(len(ewcfg.weather_list)) market_data.weather = ewcfg.weather_list[pick].name # Log message for statistics tracking. ewutils.logMsg("The weather changed. It's now {}.".format(market_data.weather)) # Persist new data. market_data.persist() # Decay slime totals ewutils.decaySlimes(id_server = server.id) # Increase hunger for all players below the max. #ewutils.pushupServerHunger(id_server = server.id) # Decrease inebriation for all players above min (0). ewutils.pushdownServerInebriation(id_server = server.id) # Remove fish offers which have timed out ewfish.kill_dead_offers(id_server = server.id) # kill advertisements that have timed out ewads.delete_expired_ads(id_server = server.id) await ewdistrict.give_kingpins_slime_and_decay_capture_points(id_server = server.id) await ewmap.kick(server.id) # Post leaderboards at 6am NLACakaNM time. if market_data.clock == 6: await ewleaderboard.post_leaderboards(client = client, server = server) except: ewutils.logMsg('An error occurred in the scheduled slime market update task:') traceback.print_exc(file = sys.stdout) # Parse files dumped into the msgqueue directory and send messages as needed. try: for msg_file in os.listdir(ewcfg.dir_msgqueue): fname = "{}/{}".format(ewcfg.dir_msgqueue, msg_file) msg = ewutils.readMessage(fname) os.remove(fname) msg_channel_names = [] msg_channel_names_reverb = [] if msg.channel != None: msg_channel_names.append(msg.channel) if msg.poi != None: poi = ewcfg.id_to_poi.get(msg.poi) if poi != None: if poi.channel != None and len(poi.channel) > 0: msg_channel_names.append(poi.channel) if msg.reverb == True: pois_adjacent = ewmap.path_to(poi_start = msg.poi) for poi_adjacent in pois_adjacent: if poi_adjacent.channel != None and len(poi_adjacent.channel) > 0: msg_channel_names_reverb.append(poi_adjacent.channel) if len(msg_channel_names) == 0: ewutils.logMsg('in file {} message for channel {} (reverb {})\n{}'.format(msg_file, msg.channel, msg.reverb, msg.message)) else: # Send messages to every connected server. for server in client.servers: for channel in server.channels: if channel.name in msg_channel_names: await ewutils.send_message(client, channel, "**{}**".format(msg.message)) elif channel.name in msg_channel_names_reverb: await ewutils.send_message(client, channel, "**Something is happening nearby...\n\n{}**".format(msg.message)) except: ewutils.logMsg('An error occurred while trying to process the message queue:') traceback.print_exc(file = sys.stdout) # Wait a while before running periodic tasks. await asyncio.sleep(15)
async def menu(cmd): user_data = EwUser(member=cmd.message.author, data_level=1) if user_data.life_state == ewcfg.life_state_shambler: response = "You lack the higher brain functions required to {}.".format( cmd.tokens[0]) return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) market_data = EwMarket(id_server=cmd.message.server.id) poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name) if poi is None or len(poi.vendors) == 0: # 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 = ewcfg.chname_to_poi.get(cmd.message.channel.name) district_data = EwDistrict(district=poi.id_poi, id_server=cmd.message.server.id) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) if poi.is_subzone: district_data = EwDistrict(district=poi.mother_district, id_server=cmd.message.server.id) else: district_data = EwDistrict(district=poi.id_poi, id_server=cmd.message.server.id) 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 < 5000: 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 = ewcfg.vendor_inv[ vendor] if vendor != ewcfg.vendor_bazaar else market_data.bazaar_wares.values( ) for item_name in vendor_inv: item_item = ewcfg.item_map.get(item_name) food_item = ewcfg.food_map.get(item_name) cosmetic_item = ewcfg.cosmetic_map.get(item_name) furniture_item = ewcfg.furniture_map.get(item_name) weapon_item = ewcfg.weapon_map.get(item_name) # 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 stock_data != None: value *= (stock_data.exchange_rate / ewcfg.default_stock_exchange_rate)**0.2 if district_data.controlling_faction != "": # prices are halved for the controlling gang if district_data.controlling_faction == user_data.faction: value /= 2 # and 4 times as much for enemy gangsters elif user_data.faction != "": value *= 4 value = int(value) if value != 0: items.append('{name} ({price})'.format(name=item_name, price=value)) else: items.append(item_name) response += "**{}**: *{}*\n".format( vendor, ewutils.formatNiceList(names=items)) if vendor == ewcfg.vendor_bodega: if user_data.freshness < 100: 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 < 100: response += ".. and you probably never will be." # Send the response to the player. await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))