コード例 #1
0
def unwrap(id_user = None, id_server = None, item = None):
	response = "You eagerly rip open a pack of Secreatures™ trading cards!!"
	ewitem.item_delete(item.id_item)
	slimexodia = False

	slimexodia_chance = 1 / 1000

	if random.random() < slimexodia_chance:
		slimexodia = True

	if slimexodia == True:
		# If there are multiple possible products, randomly select one.
		slimexodia_item = random.choice(ewcfg.slimexodia_parts)

		response += " There’s a single holographic card poking out of the swathes of repeats and late edition cards..."
		response += " ***...What’s this?! It’s the legendary card {}!! If you’re able to collect the remaining pieces of Slimexodia, you might be able to smelt something incomprehensibly powerful!!***".format(slimexodia_item.str_name)

		item_props = ewitem.gen_item_props(slimexodia_item)

		ewitem.item_create(
			item_type = slimexodia_item.item_type,
			id_user = id_user.id,
			id_server = id_server.id,
			item_props = item_props
		)

	else:
		response += " But… it’s mostly just repeats and late edition cards. You toss them away."

	return response
コード例 #2
0
ファイル: ewsmelting.py プロジェクト: huckleton/endless-war
def popcapsule(id_user=None, id_server=None, item=None):
    rarity_roll = random.randrange(10)
    ewitem.item_delete(item.id_item)

    if rarity_roll > 3:
        prank_item = random.choice(ewcfg.prank_items_heinous)
    elif rarity_roll > 0:
        prank_item = random.choice(ewcfg.prank_items_scandalous)
    else:
        prank_item = random.choice(ewcfg.prank_items_forbidden)

    item_props = ewitem.gen_item_props(prank_item)

    prank_item_id = ewitem.item_create(item_type=prank_item.item_type,
                                       id_user=id_user.id,
                                       id_server=id_server.id,
                                       item_props=item_props)

    response = "You pop open the Prank Capsule to reveal a {}! Whoa, sick!!".format(
        prank_item.str_name)

    return response
コード例 #3
0
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))
コード例 #4
0
async def barter(cmd):
	user_data = EwUser(member = cmd.message.author)
	market_data = EwMarket(id_server = user_data.id_server)
	item_search = ewutils.flattenTokenListToString(cmd.tokens[1:])
	item_sought = ewitem.find_item(item_search = item_search, id_user = cmd.message.author.id, id_server = cmd.message.server.id if cmd.message.server is not None else None)

	# Checking availability of appraisal
	#if market_data.clock < 8 or market_data.clock > 17:
	#	response = "You ask the bartender if he knows someone who would want to trade you something for your recently caught fish. Apparently, at night, an old commodore by the name of Captain Albert Alexander comes to drown his sorrows at this very tavern. You guess you’ll just have to sit here and wait for him, then."

	if cmd.message.channel.name != ewcfg.channel_speakeasy:
		if cmd.message.channel.name in [ewcfg.channel_tt_pier, ewcfg.channel_jp_pier, ewcfg.channel_cl_pier, ewcfg.channel_afb_pier, ewcfg.channel_vc_pier, ewcfg.channel_se_pier, ewcfg.channel_ferry]:
			response = 'You ask a nearby fisherman if he wants to trade you anything for this fish you just caught. He tells you to f**k off, but also helpfully informs you that there’s an old sea captain that frequents the Speakeasy that might be able to help you. What an inexplicably helpful/grouchy fisherman!'
		else:
			response = 'What random passerby is going to give two shits about your fish? You’ll have to consult a fellow fisherman… perhaps you’ll find some on a pier?'

	elif item_sought:
		name = item_sought.get('name')
		fish = EwItem(id_item = item_sought.get('id_item'))
		id_fish = fish.id_item
		# str_fish = fish.item_props.get('str_name')
		item_props = fish.item_props
		acquisition = item_props.get('acquisition')
		response = "You approach a man of particularly swashbuckling appearance, adorned in an old sea captain's uniform and bicorne cap, and surrounded by empty glass steins. You ask him if he is Captain Albert Alexander and he replies that he hasn’t heard that name in a long time. You submit your {} for bartering".format(name)

		if acquisition != ewcfg.acquisition_fishing:
			response += '. \n"Have you lost yer mind, laddy? That’s not a fish!! Just what’re you trying to pull??"'

		else:
			value = int(item_props['value'])

			items = []

			# Filters out all non-generic items without the current fish as an ingredient.
			for result in ewcfg.appraise_results:
				if result.ingredients == fish.item_props.get('id_item') or result.ingredients == "generic" and result.acquisition == ewcfg.acquisition_bartering:  # Generic means that it can be made with any fish.
					items.append(result)
				else:
					pass

			# Filters out items of greater value than your fish.
			for value_filter in items:
				if value < value_filter.context:
					items.remove(value_filter)
				else:
					pass

			else:
				offer = EwOffer(
					id_server = cmd.message.server.id,
					id_user = cmd.message.author.id,
					offer_give = id_fish
				)

				cur_time_min = time.time() / 60
				time_offered = cur_time_min - offer.time_sinceoffer

				if offer.time_sinceoffer > 0 and time_offered < ewcfg.fish_offer_timeout:
					offer_receive = str(offer.offer_receive)

					if offer_receive.isdigit() == True:
						slime_gain = int(offer.offer_receive)

						response = '\n"Well, back again I see! My offer still stands, I’ll trade ya {} slime for your {}"'.format(slime_gain, name)

					else:
						for result in ewcfg.appraise_results:
							if hasattr(result, 'id_item'):
								if result.id_item != offer.offer_receive:
									pass
								else:
									item = result

							if hasattr(result, 'id_food'):
								if result.id_food != offer.offer_receive:
									pass
								else:
									item = result

							if hasattr(result, 'id_cosmetic'):
								if result.id_cosmetic != offer.offer_receive:
									pass
								else:
									item = result

						response = '\n"Well, back again I see! My offer still stands, I’ll trade ya a {} for your {}"'.format(item.str_name, name)

					response += "\n**!accept** or **!refuse** Captain Albert Alexander's deal."

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

				else:
					# Random choice between 0, 1, and 2
					offer_decision = random.randint(0, 2)

					if offer_decision != 2: # If Captain Albert Alexander wants to offer you slime for your fish. 66% chance.
						max_value = value * 6000 # 600,000 slime for a colossal promo fish, 120,000 for a miniscule common fish.
						min_value = max_value / 10 # 60,000 slime for a colossal promo fish, 12,000 for a miniscule common fish.

						slime_gain = round(random.triangular(min_value, max_value, min_value * 2))

						offer.offer_receive = slime_gain

						response = '"Hm, alright… for this {}... I’ll offer you {} slime! Trust me, you’re not going to get a better deal anywhere else, laddy."'.format(name, slime_gain)

					else: # If Captain Albert Alexander wants to offer you an item for your fish. 33% chance. Once there are more unique items, we'll make this 50%.
						item = random.choice(items)

						if hasattr(item, 'id_item'):
							offer.offer_receive = item.id_item

						if hasattr(item, 'id_food'):
							offer.offer_receive = item.id_food

						if hasattr(item, 'id_cosmetic'):
							offer.offer_receive = item.id_cosmetic

						response = '"Hm, alright… for this {}... I’ll offer you a {}! Trust me, you’re not going to get a better deal anywhere else, laddy."'.format(name, item.str_name)

					offer.time_sinceoffer = int(time.time() / 60)
					offer.persist()

					response += "\n**!accept** or **!refuse** Captain Albert Alexander's deal."

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

				# Wait for an answer
				accepted = False

				try:
					message = await cmd.client.wait_for_message(timeout = 20, author = cmd.message.author, check = ewutils.check_accept_or_refuse)

					if message != None:
						if message.content.lower() == "!accept":
							accepted = True
						if message.content.lower() == "!refuse":
							accepted = False
				except:
					accepted = False

				offer = EwOffer(
					id_server = cmd.message.server.id,
					id_user = cmd.message.author.id,
					offer_give = id_fish
				)

				user_data = EwUser(member = cmd.message.author)
				fish = EwItem(id_item = id_fish)

				# cancel deal if fish is no longer in user's inventory
				if fish.id_owner != user_data.id_user:
					accepted = False

				# cancel deal if the user has left the speakeasy
				if user_data.poi != ewcfg.poi_id_speakeasy:
					accepted = False

				# cancel deal if the offer has been deleted
				if offer.time_sinceoffer == 0:
					accepted = False


				if accepted == True:
					offer_receive = str(offer.offer_receive)

					response = ""

					if offer_receive.isdigit() == True:
						slime_gain = int(offer_receive)

						user_initial_level = user_data.slimelevel

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

						was_levelup = True if user_initial_level < user_data.slimelevel else False

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

					else:
						item_props = ewitem.gen_item_props(item)	

						ewitem.item_create(
							item_type = item.item_type,
							id_user = cmd.message.author.id,
							id_server = cmd.message.server.id,
							item_props = item_props
						)


					ewitem.item_delete(id_item = item_sought.get('id_item'))

					user_data.persist()

					offer.deal()

					response += '"Pleasure doing business with you, laddy!"'

				else:
					response = '"Ah, what a shame. Maybe you’ll change your mind in the future…?"'

	else:
		if item_search:  # If they didn't forget to specify an item and it just wasn't found.
			response = "You don't have one."
		else:
			response = "Offer Captain Albert Alexander which fish? (check **!inventory**)"

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #5
0
async def reel(cmd):
	user_data = EwUser(member = cmd.message.author)
	if cmd.message.author.id not in fishers.keys():
		fishers[cmd.message.author.id] = EwFisher()
	fisher = fishers[cmd.message.author.id]
	poi = ewcfg.id_to_poi.get(user_data.poi)

	# Ghosts cannot fish.
	if user_data.life_state == ewcfg.life_state_corpse:
		response = "You can't fish while you're dead. Try {}.".format(ewcfg.cmd_revive)

	elif cmd.message.channel.name in [ewcfg.channel_tt_pier, ewcfg.channel_jp_pier, ewcfg.channel_cl_pier, ewcfg.channel_afb_pier, ewcfg.channel_vc_pier, ewcfg.channel_se_pier, ewcfg.channel_ferry]:
		# Players who haven't cast a line cannot reel.
		if fisher.fishing == False:
			response = "You haven't cast your hook yet. Try !cast."

		# If a fish isn't biting, then a player reels in nothing.
		elif fisher.bite == False and fisher.fishing == True:
			fisher.current_fish = ""
			fisher.current_size = ""
			fisher.fishing = False
			fisher.pier = ""
			response = "You reeled in too early! Nothing was caught."

		# On successful reel.
		else:
			if fisher.current_fish == "item":
				
				slimesea_inventory = ewitem.inventory(id_server = cmd.message.server.id, id_user = ewcfg.poi_id_slimesea)
				
				pier_poi = ewcfg.id_to_poi.get(fisher.pier)				

				if pier_poi.pier_type != ewcfg.fish_slime_saltwater or len(slimesea_inventory) == 0 or random.random() < 0.5:

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

					item_props = ewitem.gen_item_props(item)

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

					response = "You reel in {} {}s! ".format(unearthed_item_amount, item.str_name)

				else:
					item = random.choice(slimesea_inventory)

					ewitem.give_item(id_item = item.get('id_item'), member = cmd.message.author)

					response = "You reel in a {}!".format(item.get('name'))

				fisher.fishing = False
				fisher.bite = False
				fisher.current_fish = ""
				fisher.current_size = ""
				fisher.pier = ""
				user_data.persist()

			else:
				user_initial_level = user_data.slimelevel

				gang_bonus = False

				has_fishingrod = False

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

				value = 0

				if fisher.current_size == ewcfg.fish_size_miniscule:
					slime_gain = ewcfg.fish_gain * 1
					value += 10

				elif fisher.current_size == ewcfg.fish_size_small:
					slime_gain = ewcfg.fish_gain * 2

					value += 20

				elif fisher.current_size == ewcfg.fish_size_average:
					slime_gain = ewcfg.fish_gain * 3
					value += 30

				elif fisher.current_size == ewcfg.fish_size_big:
					slime_gain = ewcfg.fish_gain * 4
					value += 40

				elif fisher.current_size == ewcfg.fish_size_huge:
					slime_gain = ewcfg.fish_gain * 5
					value += 50

				else:
					slime_gain = ewcfg.fish_gain * 6
					value += 60

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_common:
					value += 10

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_uncommon:
					value += 20

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_rare:
					value += 30

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_promo:
					value += 40

				if user_data.life_state == 2:
					if ewcfg.fish_map[fisher.current_fish].catch_time == ewcfg.fish_catchtime_day and user_data.faction == ewcfg.faction_rowdys:
						gang_bonus = True
						slime_gain = slime_gain * 1.5
						value += 20

					if ewcfg.fish_map[fisher.current_fish].catch_time == ewcfg.fish_catchtime_night and user_data.faction == ewcfg.faction_killers:
						gang_bonus = True
						slime_gain = slime_gain * 1.5
						value += 20

				if has_fishingrod == True:
					slime_gain = slime_gain * 2

				if fisher.current_fish == "plebefish":
					slime_gain = ewcfg.fish_gain * .5
					value = 10
				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 != "" and district_data.controlling_faction == user_data.faction:
					slime_gain *= 2

				ewitem.item_create(
					id_user = cmd.message.author.id,
					id_server = cmd.message.server.id,
					item_type = ewcfg.it_food,
					item_props = {
						'id_food': ewcfg.fish_map[fisher.current_fish].id_fish,
						'food_name': ewcfg.fish_map[fisher.current_fish].str_name,
						'food_desc': ewcfg.fish_map[fisher.current_fish].str_desc,
						'recover_hunger': 20,
						'str_eat': ewcfg.str_eat_raw_material.format(ewcfg.fish_map[fisher.current_fish].str_name),
						'rarity': ewcfg.fish_map[fisher.current_fish].rarity,
						'size': fisher.current_size,
						'time_expir': time.time() + ewcfg.std_food_expir,
						'time_fridged': 0,
						'acquisition': ewcfg.acquisition_fishing,
						'value': value
					}
				)

				response = "You reel in a {fish}! {flavor} You grab hold and wring {slime} slime from it. "\
					.format(fish = ewcfg.fish_map[fisher.current_fish].str_name, flavor = ewcfg.fish_map[fisher.current_fish].str_desc, slime = str(slime_gain))

				if gang_bonus == True:
					if user_data.faction == ewcfg.faction_rowdys:
						response += "The Rowdy-pride this fish is showing gave you more slime than usual. "
					elif user_data.faction == ewcfg.faction_killers:
						response += "The Killer-pride this fish is showing gave you more slime than usual. "

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

				was_levelup = True if user_initial_level < user_data.slimelevel else False

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

				market_data = EwMarket(id_server=user_data.id_server)
				if market_data.caught_fish == ewcfg.debugfish_goal and fisher.pier in ewcfg.debugpiers:
					
					item = ewcfg.debugitem
					
					ewitem.item_create(
						item_type=ewcfg.it_item,
						id_user=user_data.id_user,
						id_server=user_data.id_server,
						item_props={
							'id_item': item.id_item,
							'context': item.context,
							'item_name': item.str_name,
							'item_desc': item.str_desc,
						}
					),
					ewutils.logMsg('Created item: {}'.format(item.id_item))
					item = EwItem(id_item=item.id_item)
					item.persist()
					
					response += ewcfg.debugfish_response
					market_data.caught_fish += 1
					market_data.persist()
		
				elif market_data.caught_fish < ewcfg.debugfish_goal and fisher.pier in ewcfg.debugpiers:
					market_data.caught_fish += 1
					market_data.persist()

				fisher.fishing = False
				fisher.bite = False
				fisher.current_fish = ""
				fisher.current_size = ""
				fisher.pier = ""
				
				user_data.persist()
				
	else:
		response = "You cast your fishing rod unto a sidewalk. That is to say, you've accomplished nothing. Go to a pier if you want to fish."

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #6
0
async def mine(cmd):
    market_data = EwMarket(id_server=cmd.message.author.server.id)
    user_data = EwUser(member=cmd.message.author)
    mutations = user_data.get_mutations()
    time_now = int(time.time())

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

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

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

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

    # Mine only in the mines.
    if cmd.message.channel.name in [
            ewcfg.channel_mines, ewcfg.channel_cv_mines, ewcfg.channel_tt_mines
    ]:

        if user_data.hunger >= user_data.get_hunger_max():
            return await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(
                    cmd.message.author,
                    "You've exhausted yourself from mining. You'll need some refreshment before getting back to work."
                ))

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

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

            #minesweeper = False
            if cmd.tokens_count < 2:
                response = "Please specify which vein to mine."
                await ewutils.send_message(
                    cmd.client, cmd.message.channel,
                    ewutils.formatMessage(cmd.message.author, response))
                return await print_grid(cmd)

            else:
                #minesweeper = True
                #grid_multiplier = grid_cont.cells_mined ** 0.4
                #flag = False
                row = -1
                col = -1
                for token in cmd.tokens[1:]:

                    if token.lower() == "reset":
                        user_data.hunger += ewcfg.hunger_perminereset * int(
                            hunger_cost_mod)
                        if random.random() < extra:
                            user_data.hunger += ewcfg.hunger_perminereset
                        user_data.persist()
                        init_grid(user_data.poi, user_data.id_server)
                        return await print_grid(cmd)

                    if row < 1 or col < 1:
                        coords = token.lower()

                        for char in coords:
                            if char in ewcfg.alphabet:
                                col = ewcfg.alphabet.index(char)
                                coords = coords.replace(char, "")

                        try:
                            row = int(coords)
                        except:
                            row = -1

                row -= 1

                if row not in range(len(grid)) or col not in range(
                        len(grid[row])):
                    response = "Invalid vein."
                    await ewutils.send_message(
                        cmd.client, cmd.message.channel,
                        ewutils.formatMessage(cmd.message.author, response))
                    return await print_grid(cmd)

                mining_yield = 0
                mining_accident = False

                slimes_pertile = ewcfg.slimes_pertile
                for current_row in range(max(0, row - 1),
                                         min(row + 2, len(grid))):
                    for current_col in range(
                            max(0, col - 1),
                            min(col + 2, len(grid[current_row]))):
                        symbol_prev = get_cell_symbol(
                            grid[current_row][current_col])
                        slimes_fromtile = slimes_pertile
                        if current_row == row and current_col == col:
                            slimes_fromtile *= 2
                        mining_yield += max(
                            0,
                            min(slimes_fromtile,
                                grid[current_row][current_col]))
                        grid[current_row][current_col] -= slimes_fromtile
                        if grid[current_row][
                                current_col] < -60 * ewcfg.slimes_pertile:
                            mining_accident = True
                        if get_cell_symbol(
                                grid[current_row][current_col]) != symbol_prev:
                            printgrid = True

                if mining_accident:
                    user_data.change_slimes(n=-(user_data.slimes * 0.5))
                    user_data.persist()

                    init_grid(user_data.poi, user_data.id_server)
                    response = "You have lost an arm and a leg in a mining accident. Tis but a scratch."

                    await ewutils.send_message(
                        cmd.client, cmd.message.channel,
                        ewutils.formatMessage(cmd.message.author, response))
                    return await print_grid(cmd)

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

            has_pickaxe = False

            if user_data.weapon >= 0:
                weapon_item = EwItem(id_item=user_data.weapon)
                weapon = ewcfg.weapon_map.get(
                    weapon_item.item_props.get("weapon_type"))
                if weapon.id_weapon == ewcfg.weapon_id_pickaxe:
                    has_pickaxe = True

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

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

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

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

                item_props = ewitem.gen_item_props(item)

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

                if unearthed_item_amount == 1:
                    response = "You unearthed a {}! ".format(item.str_name)
                elif unearthed_item_amount == 2:
                    response = "You unearthed two (2) {}! ".format(
                        item.str_name)

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

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

            user_initial_level = user_data.slimelevel

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

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

            #mining_yield = min(mining_yield, alternate_yield)

            if has_pickaxe == True:
                mining_yield *= 2

            # Fatigue the miner.

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

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

            was_levelup = True if user_initial_level < user_data.slimelevel else False

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

            user_data.persist()

            if printgrid:
                await print_grid(cmd)

    else:
        response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!"

    if len(response) > 0:
        await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
コード例 #7
0
async def mill(cmd):
    user_data = EwUser(member=cmd.message.author)
    market_data = EwMarket(id_server=user_data.id_server)
    item_search = ewutils.flattenTokenListToString(cmd.tokens[1:])
    item_sought = ewitem.find_item(item_search=item_search,
                                   id_user=cmd.message.author.id,
                                   id_server=cmd.message.server.id
                                   if cmd.message.server is not None else None)

    # Checking availability of milling
    if user_data.life_state != ewcfg.life_state_juvenile:
        response = "Only Juveniles of pure heart and with nothing better to do can mill their vegetables."
    elif user_data.poi not in [
            ewcfg.poi_id_jr_farms, ewcfg.poi_id_og_farms, ewcfg.poi_id_ab_farms
    ]:
        response = "Alas, there doesn’t seem to be an official SlimeCorp milling station anywhere around here. Probably because you’re in the middle of the f*****g city. Try looking where you reaped your vegetable in the first place, dumbass."

    elif user_data.slimes < ewcfg.slimes_permill:
        response = "It costs {} to !mill, and you only have {}.".format(
            ewcfg.slimes_permill, user_data.slimes)

    elif item_sought:
        items = []
        vegetable = EwItem(id_item=item_sought.get('id_item'))

        for result in ewcfg.mill_results:
            if result.ingredients != vegetable.item_props.get('id_food'):
                pass
            else:
                items.append(result)

        if len(items) > 0:
            item = random.choice(items)

            item_props = ewitem.gen_item_props(item)

            ewitem.item_create(item_type=item.item_type,
                               id_user=cmd.message.author.id,
                               id_server=cmd.message.server.id,
                               item_props=item_props)

            response = "You walk up to the official SlimeCorp Milling Station and shove your irradiated produce into the hand-crank. You painfully grip the needle-covered crank handle, dripping {} slime into a small compartment on the device’s side which supposedly fuels it. You begin slowly churning them into a glorious, pastry goo. As the goo tosses and turns inside the machine, it solidifies, and after a few moments a {} pops out!".format(
                ewcfg.slimes_permill, item.str_name)

            market_data.donated_slimes += ewcfg.slimes_permill
            market_data.persist()

            ewitem.item_delete(id_item=item_sought.get('id_item'))
            user_data.change_slimes(n=-ewcfg.slimes_permill,
                                    source=ewcfg.source_spending)
            user_data.slime_donations += ewcfg.slimes_permill
            user_data.persist()
        else:
            response = "You can only mill fresh vegetables! SlimeCorp obviously wants you to support local farmers."

    else:
        if item_search:  # if they didn't forget to specify an item and it just wasn't found
            response = "You don't have one."
        else:
            response = "Mill which item? (check **!inventory**)"

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
コード例 #8
0
async def reap(cmd):
    user_data = EwUser(member=cmd.message.author)
    response = ""
    levelup_response = ""
    mutations = user_data.get_mutations()
    poi = ewcfg.id_to_poi.get(user_data.poi)

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

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

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

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

                    slime_gain = farm.slimes_onreap

                    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 != "" and district_data.controlling_faction == user_data.faction:
                        slime_gain *= 2

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

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

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

                    if ewcfg.mutation_id_lucky in mutations:
                        unearthed_item_chance *= 1.33

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

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

                        item_props = ewitem.gen_item_props(item)

                        if item is not None:

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

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

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

                    item_props = ewitem.gen_item_props(vegetable)

                    #  Create and give a bushel of whatever crop was grown.
                    for vcreate in range(3):
                        ewitem.item_create(id_user=cmd.message.author.id,
                                           id_server=cmd.message.server.id,
                                           item_type=vegetable.item_type,
                                           item_props=item_props)

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

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

                    was_levelup = True if user_initial_level < user_data.slimelevel else False

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

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

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

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
コード例 #9
0
ファイル: ewfarm.py プロジェクト: teorec/endless-war
async def mill(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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	market_data = EwMarket(id_server = user_data.id_server)
	item_search = ewutils.flattenTokenListToString(cmd.tokens[1:])
	item_sought = ewitem.find_item(item_search = item_search, id_user = cmd.message.author.id, id_server = cmd.guild.id if cmd.guild is not None else None, item_type_filter=ewcfg.it_food)

	# Checking availability of milling
	if user_data.life_state != ewcfg.life_state_juvenile:
		response = "Only Juveniles of pure heart and with nothing better to do can mill their vegetables."
	elif cmd.message.channel.name not in [ewcfg.channel_jr_farms, ewcfg.channel_og_farms, ewcfg.channel_ab_farms]:
		response = "Alas, there doesn’t seem to be an official SlimeCorp milling station anywhere around here. Probably because you’re in the middle of the f*****g city. Try looking where you reaped your vegetable in the first place, dumbass."

	# elif user_data.slimes < ewcfg.slimes_permill:
	# 	response = "It costs {} to !mill, and you only have {}.".format(ewcfg.slimes_permill, user_data.slimes)

	elif item_sought:
		poi = ewcfg.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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
		items = []
		vegetable = EwItem(id_item = item_sought.get('id_item'))

		for result in ewcfg.mill_results:
			if type(result.ingredients) == str:
				if vegetable.item_props.get('id_food') != result.ingredients:
					pass
				else:
					items.append(result)
			elif type(result.ingredients) == list:
				if vegetable.item_props.get('id_food') not in result.ingredients:
					pass
				else:
					items.append(result)



		if len(items) > 0:
			item = random.choice(items)

			item_props = ewitem.gen_item_props(item)
			
			ewitem.item_create(
				item_type = item.item_type,
				id_user = cmd.message.author.id,
				id_server = cmd.guild.id,
				item_props = item_props
			)

			response = "You walk up to the official ~~SlimeCorp~~ Garden Gankers Milling Station and shove your irradiated produce into the hand-crank. You begin slowly churning them into a glorious, pastry goo. As the goo tosses and turns inside the machine, it solidifies, and after a few moments a {} pops out!".format(item.str_name)

			#market_data.donated_slimes += ewcfg.slimes_permill
			market_data.persist()

			ewitem.item_delete(id_item = item_sought.get('id_item'))
			#user_data.change_slimes(n = -ewcfg.slimes_permill, source = ewcfg.source_spending)
			#user_data.slime_donations += ewcfg.slimes_permill
			user_data.persist()
		else:
			response = "You can only mill fresh vegetables! SlimeCorp obviously wants you to support local farmers."

	else:
		if item_search:  # if they didn't forget to specify an item and it just wasn't found
			response = "You don't have one."
		else:
			response = "Mill which item? (check **!inventory**)"

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #10
0
ファイル: ewfarm.py プロジェクト: teorec/endless-war
async def reap(cmd):
	user_data = EwUser(member = cmd.message.author)
	if user_data.life_state == ewcfg.life_state_shambler:
		response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0])
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
	
	forcereap = False
	if cmd.tokens[0] == ewcfg.cmd_reap_alt:
		if cmd.message.author.guild_permissions.administrator:
			forcereap = True
		else:
			return
		

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

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

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

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

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

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

					slime_gain = farm.slimes_onreap

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

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

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

					if ewcfg.mutation_id_greenfingers in mutations:
						slime_gain *= 1.2

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

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

					slime_gain = max(0, round(slime_gain))

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

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

					unearthed_item_chance = 50 / ewcfg.unearthed_item_rarity  # 1 in 30 chance
					
					if ewcfg.mutation_id_lucky in mutations or ewcfg.cosmeticAbility_id_lucky in cosmetic_abilites:
						unearthed_item_chance *= 1.33

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

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

						item_props = ewitem.gen_item_props(item)

						if item is not None:

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

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

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

					item_props = ewitem.gen_item_props(vegetable)

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

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

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

						for vcreate in range(unearthed_vegetable_amount):
							ewitem.item_create(
								id_user = cmd.message.author.id,
								id_server = cmd.guild.id,
								item_type = vegetable.item_type,
								item_props = item_props
							)
	
						response += "and a bushel of {}!".format(vegetable.str_name)

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

					was_levelup = True if user_initial_level < user_data.slimelevel else False

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

					user_data.hunger += ewcfg.hunger_perfarm
					# Flag the user for PvP
					#enlisted = True if user_data.life_state == ewcfg.life_state_enlisted else False
					# user_data.time_expirpvp = ewutils.calculatePvpTimer(user_data.time_expirpvp, ewcfg.time_pvp_farm, enlisted)

					user_data.persist()

					farm.time_lastsow = 0  # 0 means no seeds are currently planted
					farm.persist()
					await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)


	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #11
0
async def exalt(cmd):
	author = cmd.message.author
	user_data = EwUser(member=author)

	if not author.guild_permissions.administrator and user_data.life_state != ewcfg.life_state_kingpin:
		response = "You do not have the power within you worthy of !exalting another player."
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	if cmd.mentions_count > 0:
		recipient = cmd.mentions[0]
	else:
		response = 'You need to specify a recipient. Usage: !exalt @[recipient].'
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	recipient_data = EwUser(member=recipient)

# 	DOUBLE HALLOWEEN
# 
# 	# Gather the Medallion
	medallion_results = []
	for m in ewcfg.cosmetic_items_list:
		if m.ingredients == 'HorsemanSoul':
			medallion_results.append(m)
		else:
			pass
 
	medallion = medallion_results[0]
	medallion_props = ewitem.gen_item_props(medallion)

	medallion_id = ewitem.item_create(
		item_type=medallion.item_type,
		id_user=recipient.id,
		id_server=cmd.guild.id,
		item_props=medallion_props
	)
 
 	# Soulbind the medallion. A player can get at most twice, but later on a new command could be added to destroy them/trade them in.
 	# I imagine this would be something similar to how players can destroy Australium Wrenches in TF2, which broadcasts a message to everyone in the game, or something.
	ewitem.soulbind(medallion_id)

	response = "**{} has been gifted the Double Halloween Medallion!!**\n".format(recipient.display_name)
# 	
# 	SWILLDERMUK
# 	
# 	if recipient_data.gambit > 0:
# 		# Give the user the Janus Mask
# 
# 		mask_results = []
# 		for m in ewcfg.cosmetic_items_list:
# 			if m.ingredients == 'SwilldermukFinalGambit':
# 				mask_results.append(m)
# 			else:
# 				pass
# 
# 		mask = mask_results[0]
# 		mask_props = ewitem.gen_item_props(mask)
# 
# 		mask_id = ewitem.item_create(
# 			item_type=mask.item_type,
# 			id_user=recipient.id,
# 			id_server=cmd.guild.id,
# 			item_props=mask_props
# 		)
# 
# 		ewitem.soulbind(mask_id)
# 
# 		response = "In light of their supreme reign over Swilldermuk, and in honor of their pranking prowess, {} recieves the Janus Mask!".format(recipient.display_name)
# 
# 	else:
# 		# Give the user the Sword of Seething
# 		sword_results = []
# 		for s in ewcfg.item_list:
# 			if s.context == 'swordofseething':
# 				sword_results.append(s)
# 			else:
# 				pass
# 
# 		sword = sword_results[0]
# 		sword_props = ewitem.gen_item_props(sword)
# 
# 		sword_id = ewitem.item_create(
# 			item_type=sword.item_type,
# 			id_user=recipient.id,
# 			id_server=cmd.guild.id,
# 			item_props=sword_props
# 		)
# 
# 		ewitem.soulbind(sword_id)
# 
# 		response = "In response to their unparalleled ability to let everything go to shit and be the laughingstock of all of NLACakaNM, {} recieves the SWORD OF SEETHING! God help us all...".format(recipient.display_name)
# 
	return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #12
0
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))
コード例 #13
0
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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))



	# Find sought recipe.
	if cmd.tokens_count > 1:
		sought_result = ewutils.flattenTokenListToString(cmd.tokens[1:])
		found_recipe = ewcfg.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 = ewitem.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 == "cosmetic":
					patrician_rarity = 20
					patrician_smelted = random.randint(1, patrician_rarity)
					patrician = False

					if patrician_smelted == 1:
						patrician = True

					cosmetics_list = []

					for result in ewcfg.cosmetic_items_list:
						if 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)]

					ewitem.item_create(
						item_type = ewcfg.it_cosmetic,
						id_user = cmd.message.author.id,
						id_server = cmd.message.server.id,
						item_props = {
							'id_cosmetic': item.id_cosmetic,
							'cosmetic_name': item.str_name,
							'cosmetic_desc': item.str_desc,
							'rarity': item.rarity,
							'adorned': 'false'
						}
					)

				# If you're trying to smelt a specific item.
				else:
					possible_results = []

					# Matches the recipe's listed products to actual items.
					for result in ewcfg.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)

					item_props = ewitem.gen_item_props(item)

					newitem_id = ewitem.item_create(
						item_type = item.item_type,
						id_user = cmd.message.author.id,
						id_server = cmd.message.server.id,
						item_props = item_props
					)


				for id_item in owned_ingredients:
					item_check = ewitem.EwItem(id_item=id_item)
					if item_check.item_props.get('id_cosmetic') != 'soul':
						ewitem.item_delete(id_item = id_item)
					else:
						newitem = ewitem.EwItem(id_item=newitem_id)
						newitem.item_props['target'] = id_item
						newitem.persist()
						ewitem.give_item(id_item=id_item, id_user='******', id_server=cmd.message.server.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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
コード例 #14
0
async def reel(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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	if ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, "You must {} in a zone's channel.".format(cmd.tokens[0])))

	if cmd.message.author.id not in fishers.keys():
		fishers[cmd.message.author.id] = EwFisher()
	fisher = fishers[cmd.message.author.id]
	poi = ewcfg.id_to_poi.get(user_data.poi)

	# Ghosts cannot fish.
	if user_data.life_state == ewcfg.life_state_corpse:
		response = "You can't fish while you're dead. Try {}.".format(ewcfg.cmd_revive)

	elif user_data.poi in ewcfg.piers:
		poi = ewcfg.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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
		# Players who haven't cast a line cannot reel.
		if fisher.fishing == False:
			response = "You haven't cast your hook yet. Try !cast."

		# If a fish isn't biting, then a player reels in nothing.
		elif fisher.bite == False:
			fisher.stop()
			response = "You reeled in too early! Nothing was caught."

		# On successful reel.
		else:
			if fisher.current_fish == "item":
				
				slimesea_inventory = ewitem.inventory(id_server = cmd.guild.id, id_user = ewcfg.poi_id_slimesea)			

				if fisher.pier.pier_type != ewcfg.fish_slime_saltwater or len(slimesea_inventory) == 0 or random.random() < 0.5:

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

					item_props = ewitem.gen_item_props(item)

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

					response = "You reel in {} {}s! ".format(unearthed_item_amount, item.str_name)

				else:
					item = random.choice(slimesea_inventory)

					ewitem.give_item(id_item = item.get('id_item'), member = cmd.message.author)

					response = "You reel in a {}!".format(item.get('name'))

				fisher.stop()
				user_data.persist()

			else:
				user_initial_level = user_data.slimelevel

				gang_bonus = False

				has_fishingrod = False

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

				#if user_data.sidearm >= 0:
				#	sidearm_item = EwItem(id_item=user_data.sidearm)
				#	sidearm = ewcfg.weapon_map.get(sidearm_item.item_props.get("weapon_type"))
				#	if sidearm.id_weapon == "fishingrod":
				#		has_fishingrod = True

				value = 0

				if fisher.current_size == ewcfg.fish_size_miniscule:
					slime_gain = ewcfg.fish_gain * 1
					value += 10

				elif fisher.current_size == ewcfg.fish_size_small:
					slime_gain = ewcfg.fish_gain * 2

					value += 20

				elif fisher.current_size == ewcfg.fish_size_average:
					slime_gain = ewcfg.fish_gain * 3
					value += 30

				elif fisher.current_size == ewcfg.fish_size_big:
					slime_gain = ewcfg.fish_gain * 4
					value += 40

				elif fisher.current_size == ewcfg.fish_size_huge:
					slime_gain = ewcfg.fish_gain * 5
					value += 50

				else:
					slime_gain = ewcfg.fish_gain * 6
					value += 60

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_common:
					value += 10

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_uncommon:
					value += 20

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_rare:
					value += 30

				if ewcfg.fish_map[fisher.current_fish].rarity == ewcfg.fish_rarity_promo:
					value += 40

				if user_data.life_state == 2:
					if ewcfg.fish_map[fisher.current_fish].catch_time == ewcfg.fish_catchtime_day and user_data.faction == ewcfg.faction_boober:
						gang_bonus = True
						slime_gain = slime_gain * 1.5
						value += 20

					if ewcfg.fish_map[fisher.current_fish].catch_time == ewcfg.fish_catchtime_night and user_data.faction == ewcfg.faction_milkers:
						gang_bonus = True
						slime_gain = slime_gain * 1.5
						value += 20

				if has_fishingrod == True:
					slime_gain = slime_gain * 2

				if fisher.current_fish == "plebefish":
					slime_gain = ewcfg.fish_gain * .5
					value = 10
					
				controlling_faction = ewutils.get_subzone_controlling_faction(user_data.poi, user_data.id_server)

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


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

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

				slime_gain = max(0, round(slime_gain))

				ewitem.item_create(
					id_user = cmd.message.author.id,
					id_server = cmd.guild.id,
					item_type = ewcfg.it_food,
					item_props = {
						'id_food': ewcfg.fish_map[fisher.current_fish].id_fish,
						'food_name': ewcfg.fish_map[fisher.current_fish].str_name,
						'food_desc': ewcfg.fish_map[fisher.current_fish].str_desc,
						'recover_hunger': 20,
						'str_eat': ewcfg.str_eat_raw_material.format(ewcfg.fish_map[fisher.current_fish].str_name),
						'rarity': ewcfg.fish_map[fisher.current_fish].rarity,
						'size': fisher.current_size,
						'time_expir': time.time() + ewcfg.std_food_expir,
						'time_fridged': 0,
						'acquisition': ewcfg.acquisition_fishing,
						'value': value
					}
				)

				response = "You reel in a {fish}! {flavor} You grab hold and wring {slime:,} slime from it. "\
					.format(fish = ewcfg.fish_map[fisher.current_fish].str_name, flavor = ewcfg.fish_map[fisher.current_fish].str_desc, slime = slime_gain)

				if gang_bonus == True:
					if user_data.faction == ewcfg.faction_boober:
						response += "The Rowdy-pride this fish is showing gave you more slime than usual. "
					elif user_data.faction == ewcfg.faction_milkers:
						response += "The Killer-pride this fish is showing gave you more slime than usual. "

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

				was_levelup = True if user_initial_level < user_data.slimelevel else False

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

				market_data = EwMarket(id_server=user_data.id_server)
				# if market_data.caught_fish == ewcfg.debugfish_goal and fisher.pier.id_poi in ewcfg.debugpiers:
				# 	
				# 	item = ewcfg.debugitem
				# 	
				# 	ewitem.item_create(
				# 		item_type=ewcfg.it_item,
				# 		id_user=user_data.id_user,
				# 		id_server=user_data.id_server,
				# 		item_props={
				# 			'id_item': item.id_item,
				# 			'context': item.context,
				# 			'item_name': item.str_name,
				# 			'item_desc': item.str_desc,
				# 		}
				# 	),
				# 	ewutils.logMsg('Created item: {}'.format(item.id_item))
				# 	item = EwItem(id_item=item.id_item)
				# 	item.persist()
				# 	
				# 	response += ewcfg.debugfish_response
				# 	market_data.caught_fish += 1
				# 	market_data.persist()
				# 
				# elif market_data.caught_fish < ewcfg.debugfish_goal and fisher.pier.id_poi in ewcfg.debugpiers:
				# 	market_data.caught_fish += 1
				# 	market_data.persist()

				fisher.stop()

				# Flag the user for PvP
				enlisted = True if user_data.life_state == ewcfg.life_state_enlisted else False
				# user_data.time_expirpvp = ewutils.calculatePvpTimer(user_data.time_expirpvp, ewcfg.time_pvp_fish, enlisted)
				# 
				user_data.persist()
				# await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
				
	else:
		response = "You cast your fishing rod unto a sidewalk. That is to say, you've accomplished nothing. Go to a pier if you want to fish."

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