Esempio n. 1
0
async def possess_weapon(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""
	if user_data.life_state != ewcfg.life_state_corpse:
		response = "You have no idea what you're doing."
	elif not user_data.get_inhabitee():
		response = "You're not **{}**ing anyone right now.".format(ewcfg.cmd_inhabit)
	elif user_data.slimes >= ewcfg.slimes_to_possess_weapon:
		response = "You'll have to become stronger before you can perform occult arts of this level."
	else:
		server = cmd.guild
		inhabitee_id = user_data.get_inhabitee()
		inhabitee_data = EwUser(id_user = inhabitee_id, id_server = user_data.id_server)
		inhabitee_member = server.get_member(inhabitee_id)
		inhabitee_name = inhabitee_member.display_name
		if inhabitee_data.weapon < 0:
			response = "{} is not wielding a weapon right now.".format(inhabitee_name)
		elif inhabitee_data.get_possession():
			response = "{} is already being possessed.".format(inhabitee_name)
		else:
			proposal_response = "You propose a trade to {}.\n" \
				"You will possess their weapon to empower it, and in return they'll sacrifice a fifth of their slime to your name upon their next kill.\n" \
				"Will they **{}** this exchange, or **{}** it?".format(inhabitee_name, ewcfg.cmd_accept, ewcfg.cmd_refuse)
			await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, proposal_response))
    
			accepted = False
			try:
				msg = await cmd.client.wait_for('message', timeout = 30, check=lambda message: message.author == inhabitee_member and 
														message.content.lower() in [ewcfg.cmd_accept, ewcfg.cmd_refuse])
				if msg != None:
					if msg.content.lower() == ewcfg.cmd_accept:
						accepted = True
					elif msg.content.lower() == ewcfg.cmd_refuse:
						accepted = False
			except:
				accepted = False

			if accepted:
				ewutils.execute_sql_query(
				"UPDATE inhabitations SET {empowered} = %s WHERE {id_fleshling} = %s AND {id_ghost} = %s".format(
					empowered = ewcfg.col_empowered,
					id_fleshling = ewcfg.col_id_fleshling,
					id_ghost = ewcfg.col_id_ghost,
				), (
					'weapon',
					inhabitee_id,
					user_data.id_user,
				))
				user_data.change_slimes(n = -ewcfg.slimes_to_possess_weapon, source = ewcfg.source_ghost_contract)
				user_data.persist()
				accepted_response = "You feel a metallic taste in your mouth as you sign {}'s spectral contract. You see them bind themselves to your weapon, which now bears their mark. It feels cold to the touch.".format(cmd.message.author.display_name)
				await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(inhabitee_member, accepted_response))
			else:
				response = "You should've known better, why would anyone ever trust you?"
	
	if response:
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Esempio n. 2
0
async def possess_fishing_rod(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""
	if user_data.life_state != ewcfg.life_state_corpse:
		response = "You have no idea what you're doing."
	elif not user_data.get_inhabitee():
		response = "You're not **{}**ing anyone right now.".format(ewcfg.cmd_inhabit)
	elif user_data.slimes >= ewcfg.slimes_to_possess_fishing_rod:
		response = "You'll have to become stronger before you can perform occult arts of this level."
	else:
		server = cmd.guild
		inhabitee_id = user_data.get_inhabitee()
		inhabitee_data = EwUser(id_user = inhabitee_id, id_server = user_data.id_server)
		inhabitee_member = server.get_member(inhabitee_id)
		inhabitee_name = inhabitee_member.display_name
		if inhabitee_data.get_possession():
			response = "{} is already being possessed.".format(inhabitee_name)
		else:
			proposal_response = "You propose a trade to {}.\n" \
				"You will possess their fishing rod to enhance it, making it more attractive to fish. In exchange, you will corrupt away all of the fish's slime, and absorb it as antislime.\n" \
				"Both of you will need to reel the fish in together, and failing to do so will nullify this contract.\nWill they **{}** this exchange, or **{}** it?".format(inhabitee_name, ewcfg.cmd_accept, ewcfg.cmd_refuse)
			await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, proposal_response))
    
			accepted = False
			try:
				msg = await cmd.client.wait_for('message', timeout = 30, check=lambda message: message.author == inhabitee_member and 
														message.content.lower() in [ewcfg.cmd_accept, ewcfg.cmd_refuse])
				if msg != None:
					if msg.content.lower() == ewcfg.cmd_accept:
						accepted = True
					elif msg.content.lower() == ewcfg.cmd_refuse:
						accepted = False
			except:
				accepted = False

			if accepted:
				ewutils.execute_sql_query(
				"UPDATE inhabitations SET {empowered} = %s WHERE {id_fleshling} = %s AND {id_ghost} = %s".format(
					empowered = ewcfg.col_empowered,
					id_fleshling = ewcfg.col_id_fleshling,
					id_ghost = ewcfg.col_id_ghost,
				), (
					'rod',
					inhabitee_id,
					user_data.id_user,
				))
				user_data.change_slimes(n = -ewcfg.slimes_to_possess_fishing_rod, source = ewcfg.source_ghost_contract)
				user_data.persist()
				accepted_response = "You feel a metallic taste in your mouth as you sign {}'s spectral contract. Their ghastly arms superpose yours, enhancing your grip and causing shadowy tendrils to appear near your rod's hook.".format(cmd.message.author.display_name)
				await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(inhabitee_member, accepted_response))
			else:
				response = "You should've known better, why would anyone ever trust you?"
	
	if response:
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Esempio n. 3
0
async def let_go(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""

	if user_data.life_state != ewcfg.life_state_corpse:
		# Only ghosts can inhabit other players
		response = "You feel a bit more at peace with the world."
	elif not user_data.get_inhabitee():
		response = "You're not **{}**ing anyone right now.".format(ewcfg.cmd_inhabit)
	else:
		user_data.remove_inhabitation()
		response = "You let go of the soul you've been tormenting."

	return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Esempio n. 4
0
async def haunt(cmd):
	time_now = int(time.time())
	response = ""
	resp_cont = ewutils.EwResponseContainer(id_server = cmd.guild.id)

	if cmd.mentions_count > 1:
		response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
	else: 
		haunted_data = None
		member = None
		if cmd.mentions_count == 0 and cmd.tokens_count > 1:
			server = cmd.guild
			member = server.get_member(ewutils.getIntToken(cmd.tokens))
			haunted_data = EwUser(member = member)
		elif cmd.mentions_count == 1:
			member = cmd.mentions[0]
			haunted_data = EwUser(member = member)
		
		if member:
			# Get the user and target data from the database.
			user_data = EwUser(member = cmd.message.author)
			market_data = EwMarket(id_server = cmd.guild.id)
			target_mutations = haunted_data.get_mutations()
			target_poi = ewcfg.id_to_poi.get(haunted_data.poi)
			target_is_shambler = haunted_data.life_state == ewcfg.life_state_shambler
			target_is_inhabitted = haunted_data.id_user == user_data.get_inhabitee()


			if user_data.life_state != ewcfg.life_state_corpse:
				# Only dead players can haunt.
				response = "You can't haunt now. Try {}.".format(ewcfg.cmd_suicide)
			elif haunted_data.life_state == ewcfg.life_state_kingpin:
				# Disallow haunting of generals.
				response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
			elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
				# Disallow haunting if the user has haunted too recently.
				response = "You're being a little TOO spooky lately, don't you think? Try again in {} seconds.".format(int(ewcfg.cd_haunt-(time_now-user_data.time_lasthaunt)))
			elif ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
				response = "You can't commit violence from here."
			elif target_poi.pvp == False:
			#Require the target to be in a PvP area, and flagged if it's a remote haunt
				response = "{} is not mired in the ENDLESS WAR right now.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_corpse:
				# Dead players can't be haunted.
				response = "{} is already dead.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_grandfoe:
				# Grand foes can't be haunted.
				response = "{} is invulnerable to ghosts.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_enlisted or haunted_data.life_state == ewcfg.life_state_juvenile or haunted_data.life_state == ewcfg.life_state_shambler:
				haunt_power_multiplier = 1

				# power to the ancients
				ghost_age = time_now - user_data.time_lastdeath
				if ghost_age > 60 * 60 * 24 * 7: # dead for longer than
					if ghost_age > 60 * 60 * 24 * 365: # one friggin year
						haunt_power_multiplier *= 2.5
					if ghost_age > 60 * 60 * 24 * 90: # three months
						haunt_power_multiplier *= 2
					elif ghost_age > 60 * 60 * 24 * 30: # one month
						haunt_power_multiplier *= 1.5
					else: # one week
						haunt_power_multiplier *= 1.25

				# vitriol as virtue
				list_ids = []
				for quadrant in ewcfg.quadrant_ids:
					quadrant_data = ewquadrants.EwQuadrant(id_server=cmd.guild.id, id_user=cmd.message.author.id, quadrant=quadrant)
					if quadrant_data.id_target != -1 and quadrant_data.check_if_onesided() is False:
						list_ids.append(quadrant_data.id_target)
					if quadrant_data.id_target2 != -1 and quadrant_data.check_if_onesided() is False:
						list_ids.append(quadrant_data.id_target2)
				if haunted_data.id_user in list_ids: # any mutual quadrants
					haunt_power_multiplier *= 1.2
				if haunted_data.faction and ((not user_data.faction) or (user_data.faction != haunted_data.faction)): # opposite faction (or no faction at all)
					haunt_power_multiplier *= 1.2
				if user_data.id_killer == haunted_data.id_user: # haunting your murderer/buster
					haunt_power_multiplier *= 1.2

				# places of power.
				if haunted_data.poi in [ewcfg.poi_id_thevoid, ewcfg.poi_id_wafflehouse, ewcfg.poi_id_blackpond]:
					haunt_power_multiplier *= 2
				elif haunted_data.poi in ewmap.get_void_connection_pois(cmd.guild.id):
					haunt_power_multiplier *= 1.25

				# glory to the vanquished
				target_kills = ewstats.get_stat(user = haunted_data, metric = ewcfg.stat_kills)
				if target_kills > 5:
					haunt_power_multiplier *= 1.25 + ((target_kills - 5) / 100) # 1% per kill after 5
				else:
					haunt_power_multiplier *= 1 + (target_kills * 5 / 100) # 5% per kill
					
				if time_now - haunted_data.time_lastkill < (60 * 15):
					haunt_power_multiplier *= 1.5 # wet hands

				# misc
				if ewcfg.weather_map.get(market_data.weather) == ewcfg.weather_foggy:
					haunt_power_multiplier *= 1.1
				if not haunted_data.has_soul:
					haunt_power_multiplier *= 1.2
				# uncomment this after moon mechanics update
				# if (market_data.day % 31 == 15 and market_data.clock >= 20) or (market_data.day % 31 == 16 and market_data.clock <= 6):
				# 	haunt_power_multiplier *= 2

				# divide haunt power by 2 if not in same area
				if user_data.poi != haunted_data.poi:
					haunt_power_multiplier /= 2

				# Double Halloween
				#haunt_power_multiplier *= 4

				haunted_slimes = int((haunted_data.slimes / ewcfg.slimes_hauntratio) * haunt_power_multiplier)
				slimes_lost = int(haunted_slimes / 5) # hauntee only loses 1/5th of what the ghost gets as antislime

				if ewcfg.mutation_id_coleblooded in target_mutations:
					haunted_slimes = -10000
					if user_data.slimes > haunted_slimes:
						haunted_slimes = user_data.slimes

				haunted_data.change_slimes(n = -slimes_lost, source = ewcfg.source_haunted)
				user_data.change_slimes(n = -haunted_slimes, source = ewcfg.source_haunter)
				market_data.negaslime -= haunted_slimes

				user_data.time_lasthaunt = time_now
				user_data.busted = False
				
				resp_cont.add_member_to_update(cmd.message.author)
				# Persist changes to the database.
				user_data.persist()
				haunted_data.persist()
				market_data.persist()

				response = "{} has been haunted by the ghost of {}! Slime has been lost! {} antislime congeals within you.".format(member.display_name, cmd.message.author.display_name, haunted_slimes)
				if ewcfg.mutation_id_coleblooded in target_mutations:
					response = "{} has been haunted by the ghost of {}! Their exorcising coleslaw blood purges {} antislime from your being! Better not do that again.".format(member.display_name, cmd.message.author.display_name, -haunted_slimes)

				haunted_channel = ewcfg.id_to_poi.get(haunted_data.poi).channel
				haunt_message = "You feel a cold shiver run down your spine"
				if cmd.tokens_count > 2:
					haunt_message_content = re.sub("<.+>" if cmd.mentions_count == 1 else "\d{17,}", "", cmd.message.content[(len(cmd.tokens[0])):]).strip()
					# Cut down really big messages so discord doesn't crash
					if len(haunt_message_content) > 500:
						haunt_message_content = haunt_message_content[:-500]
					haunt_message += " and faintly hear the words \"{}\"".format(haunt_message_content)
				haunt_message += ". {} slime evaporates from your body.".format(slimes_lost)
				if ewcfg.mutation_id_coleblooded in target_mutations:
					haunt_message += " The ghost that did it wails in agony as their ectoplasm boils in your coleslaw blood!"

				haunt_message = ewutils.formatMessage(member, haunt_message)
				resp_cont.add_channel_response(haunted_channel, haunt_message)
		else:
			# No mentions, or mentions we didn't understand.
			response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

	# Send the response to the player.
	resp_cont.add_channel_response(cmd.message.channel.name, response)
	await resp_cont.post()
Esempio n. 5
0
async def disembark(cmd):
	# can only use movement commands in location channels
	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])))
	user_data = EwUser(member = cmd.message.author)
	response = ""
	resp_cont = ewutils.EwResponseContainer(client = cmd.client, id_server = user_data.id_server)

	# prevent ghosts currently inhabiting other players from moving on their own
	if user_data.get_inhabitee():
		response = "You might want to **{}** of the poor soul you've been tormenting first.".format(ewcfg.cmd_letgo)
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	# can only disembark when you're on a transport vehicle
	elif user_data.poi in ewcfg.transports:
		transport_data = EwTransport(id_server = user_data.id_server, poi = user_data.poi)
		response = "{}ing.".format(cmd.tokens[0][1:].lower()).capitalize()

		stop_poi = ewcfg.id_to_poi.get(transport_data.current_stop)
		# if stop_poi.is_subzone:
		# 	stop_poi = ewcfg.id_to_poi.get(stop_poi.mother_district)

		if ewmap.inaccessible(user_data = user_data, poi = stop_poi):
			return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, "You're not allowed to go there (bitch)."))

		# schedule tasks for concurrent execution
		message_task = asyncio.ensure_future(ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)))
		wait_task = asyncio.ensure_future(asyncio.sleep(5))

		# Take control of the move for this player.
		ewmap.move_counter += 1
		move_current = ewutils.moves_active[cmd.message.author.id] = ewmap.move_counter
		await message_task
		await wait_task


		# check if the user entered another movement command while waiting for the current one to be completed
		if move_current != ewutils.moves_active[cmd.message.author.id]:
			return

		user_data = EwUser(member = cmd.message.author)
		transport_data = EwTransport(id_server = user_data.id_server, poi = transport_data.poi)

		# cancel move, if the user has left the transport while waiting for movement to be completed (e.g. by dying)
		if user_data.poi != transport_data.poi:
			return

		stop_poi = ewcfg.id_to_poi.get(transport_data.current_stop)

		# juvies can't swim
		if transport_data.current_stop == ewcfg.poi_id_slimesea and user_data.life_state != ewcfg.life_state_corpse:
			if user_data.life_state == ewcfg.life_state_kingpin:
				response = "You try to heave yourself over the railing as you're hit by a sudden case of sea sickness. You puke into the sea and sink back on deck."
				response = ewutils.formatMessage(cmd.message.author, response)
				return await ewutils.send_message(cmd.client, cmd.message.channel, response)
			user_data.poi = ewcfg.poi_id_slimesea
			user_data.trauma = ewcfg.trauma_id_environment
			die_resp = user_data.die(cause = ewcfg.cause_drowning)
			user_data.persist()
			resp_cont.add_response_container(die_resp)

			response = "{} jumps over the railing of the ferry and promptly drowns in the slime sea.".format(cmd.message.author.display_name)
			resp_cont.add_channel_response(channel = ewcfg.channel_slimesea, response = response)
			resp_cont.add_channel_response(channel = ewcfg.channel_ferry, response = response)
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
		# they also can't fly
                
		elif transport_data.transport_type == ewcfg.transport_type_blimp and not stop_poi.is_transport_stop and user_data.life_state != ewcfg.life_state_corpse:
			user_mutations = user_data.get_mutations()
			if user_data.life_state == ewcfg.life_state_kingpin:
				response = "Your life flashes before your eyes, as you plummet towards your certain death. A lifetime spent being a piece of shit and playing videogames all day. You close your eyes and... BOING! You open your eyes again to see a crew of workers transporting the trampoline that broke your fall. You get up and dust yourself off, sighing heavily."
				response = ewutils.formatMessage(cmd.message.author, response)
				resp_cont.add_channel_response(channel = stop_poi.channel, response = response)
				user_data.poi = stop_poi.id_poi
				user_data.persist()
				await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
				return await resp_cont.post()
			
			elif ewcfg.mutation_id_lightasafeather in user_mutations:
				response = "With a running jump you launch yourself out of the blimp and begin falling to your soon-to-be demise... but then a strong updraft breaks your fall and you land unscathed. "
				response = ewutils.formatMessage(cmd.message.author, response)
				resp_cont.add_channel_response(channel = stop_poi.channel, response = response)
				user_data.poi = stop_poi.id_poi
				user_data.persist()
				await user_data.move_inhabitants(id_poi = stop_poi.id_poi)
				await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
				return await resp_cont.post()
			district_data = EwDistrict(id_server = user_data.id_server, district = stop_poi.id_poi)
			district_data.change_slimes(n = user_data.slimes)
			district_data.persist()
			user_data.poi = stop_poi.id_poi
			user_data.trauma = ewcfg.trauma_id_environment
			die_resp = user_data.die(cause = ewcfg.cause_falling)
			user_data.persist()
			resp_cont.add_response_container(die_resp)
			response = "SPLAT! A body collides with the asphalt with such force, that it is utterly annihilated, covering bystanders in blood and slime and guts."
			resp_cont.add_channel_response(channel = stop_poi.channel, response = response)
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)

		# update user location, if move successful
		else:
			# if stop_poi.is_subzone:
			# 	stop_poi = ewcfg.id_to_poi.get(stop_poi.mother_district)

			if ewmap.inaccessible(user_data = user_data, poi = stop_poi):
				return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, "You're not allowed to go there (bitch)."))

			user_data.poi = stop_poi.id_poi
			user_data.persist()
			await user_data.move_inhabitants(id_poi = stop_poi.id_poi)
			response = "You enter {}".format(stop_poi.str_name)
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
			await ewutils.send_message(cmd.client, ewutils.get_channel(cmd.guild, stop_poi.channel), ewutils.formatMessage(cmd.message.author, response))

			# SWILLDERMUK
			await ewutils.activate_trap_items(stop_poi.id_poi, user_data.id_server, user_data.id_user)
			
			return
		return await resp_cont.post()
	else:
		response = "You are not currently riding any transport."
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Esempio n. 6
0
async def embark(cmd):
	# can only use movement commands in location channels
	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])))

	user_data = EwUser(member = cmd.message.author)
	poi = ewcfg.id_to_poi.get(user_data.poi)
	district_data = EwDistrict(district = poi.id_poi, id_server = cmd.guild.id)

	if district_data.is_degraded():
		response = "{} has been degraded by shamblers. You can't {} here anymore.".format(poi.str_name, cmd.tokens[0])
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	response = ""

	if ewutils.active_restrictions.get(user_data.id_user) != None and ewutils.active_restrictions.get(user_data.id_user) > 0:
		response = "You can't do that right now."
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	if user_data.get_inhabitee():
		# prevent ghosts currently inhabiting other players from moving on their own
		response = "You might want to **{}** of the poor soul you've been tormenting first.".format(ewcfg.cmd_letgo)
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	#poi = ewmap.fetch_poi_if_coordless(cmd.message.channel.name)

	# must be at a transport stop to enter a transport
	if poi != None and poi.id_poi in ewcfg.transport_stops:
		transport_ids = get_transports_at_stop(id_server = user_data.id_server, stop = poi.id_poi)

		# can't embark, when there's no vehicles to embark on
		if len(transport_ids) == 0:
			response = "There are currently no transport vehicles to embark on here."
			return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

		# automatically embark on the only transport at the station, if no arguments were provided
		elif len(transport_ids) == 1 and cmd.tokens_count < 2:
			transport_data = EwTransport(id_server = user_data.id_server, poi = transport_ids[0])
			target_name = transport_data.current_line

		# get target name from command arguments
		else:
			target_name = ewutils.flattenTokenListToString(cmd.tokens[1:])

		# report failure, if the vehicle to be boarded couldn't be ascertained
		if target_name == None or len(target_name) == 0:
			return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, "Which transport line?"))

		transport_line = ewcfg.id_to_transport_line.get(target_name)

		# report failure, if an invalid argument was given
		if transport_line == None:
			return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, "Never heard of it."))

		for transport_id in transport_ids:
			transport_data = EwTransport(id_server = user_data.id_server, poi = transport_id)

			# check if one of the vehicles at the stop matches up with the line, the user wants to board
			if transport_data.current_line == transport_line.id_line:
				last_stop_poi = ewcfg.id_to_poi.get(transport_line.last_stop)
				response = "Embarking on {}.".format(transport_line.str_name)
				# schedule tasks for concurrent execution
				message_task = asyncio.ensure_future(ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)))
				wait_task = asyncio.ensure_future(asyncio.sleep(5))

				# Take control of the move for this player.
				ewmap.move_counter += 1
				move_current = ewutils.moves_active[cmd.message.author.id] = ewmap.move_counter
				await message_task
				await wait_task

				# check if the user entered another movement command while waiting for the current one to be completed
				if move_current == ewutils.moves_active[cmd.message.author.id]:
					user_data = EwUser(member = cmd.message.author)

					transport_data = EwTransport(id_server = user_data.id_server, poi = transport_id)

					# check if the transport is still at the same stop
					if transport_data.current_stop == poi.id_poi:
						user_data.poi = transport_data.poi
						user_data.persist()

						transport_poi = ewcfg.id_to_poi.get(transport_data.poi)

						response = "You enter the {}.".format(transport_data.transport_type)
						await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
						await user_data.move_inhabitants(id_poi = transport_data.poi)
						return await ewutils.send_message(cmd.client, ewutils.get_channel(cmd.guild, transport_poi.channel), ewutils.formatMessage(cmd.message.author, response))
					else:
						response = "The {} starts moving just as you try to get on.".format(transport_data.transport_type)
						return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

		response = "There is currently no vehicle following that line here."
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))


	else:
		response = "No transport vehicles stop here. Try going to a subway station or a ferry port."
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Esempio n. 7
0
async def haunt(cmd):
    time_now = int(time.time())
    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.guild.id)

    if cmd.mentions_count > 1:
        response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
    else:
        haunted_data = None
        member = None
        if cmd.mentions_count == 0 and cmd.tokens_count > 1:
            server = cmd.guild
            member = server.get_member(ewutils.getIntToken(cmd.tokens))
            haunted_data = EwUser(member=member)
        elif cmd.mentions_count == 1:
            member = cmd.mentions[0]
            haunted_data = EwUser(member=member)

        if member:
            # Get the user and target data from the database.
            user_data = EwUser(member=cmd.message.author)
            market_data = EwMarket(id_server=cmd.guild.id)
            target_is_shambler = haunted_data.life_state == ewcfg.life_state_shambler
            target_is_inhabitted = haunted_data.id_user == user_data.get_inhabitee(
            )

            if user_data.life_state != ewcfg.life_state_corpse:
                # Only dead players can haunt.
                response = "You can't haunt now. Try {}.".format(
                    ewcfg.cmd_suicide)
            elif haunted_data.life_state == ewcfg.life_state_kingpin:
                # Disallow haunting of generals.
                response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
            elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
                # Disallow haunting if the user has haunted too recently.
                response = "You're being a little TOO spooky lately, don't you think? Try again in {} seconds.".format(
                    int(ewcfg.cd_haunt -
                        (time_now - user_data.time_lasthaunt)))
            elif ewutils.channel_name_is_poi(
                    cmd.message.channel.name) == False:
                response = "You can't commit violence from here."
            elif time_now > haunted_data.time_expirpvp and not (
                    target_is_shambler or target_is_inhabitted):
                # Require the target to be flagged for PvP
                response = "{} is not mired in the ENDLESS WAR right now.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_corpse:
                # Dead players can't be haunted.
                response = "{} is already dead.".format(member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_grandfoe:
                # Grand foes can't be haunted.
                response = "{} is invulnerable to ghosts.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_enlisted or haunted_data.life_state == ewcfg.life_state_juvenile or haunted_data.life_state == ewcfg.life_state_shambler:
                # Target can be haunted by the player.
                haunt_power_multiplier = 1
                if user_data.poi == haunted_data.poi:
                    if user_data.poi == ewcfg.poi_id_thevoid:
                        # haunting is empowered by the void
                        haunt_power_multiplier *= 5
                    else:
                        # when haunting someone face to face, you get double the amount
                        haunt_power_multiplier *= 2
                haunted_slimes = int(
                    haunted_data.slimes /
                    ewcfg.slimes_hauntratio) * haunt_power_multiplier

                haunted_data.change_slimes(n=-haunted_slimes,
                                           source=ewcfg.source_haunted)
                user_data.change_slimes(
                    n=-min(haunted_slimes, ewcfg.slimes_hauntmax),
                    source=ewcfg.source_haunter)
                market_data.negaslime -= haunted_slimes
                user_data.time_lasthaunt = time_now
                user_data.busted = False

                user_poi = ewcfg.id_to_poi.get(user_data.poi)
                user_data.time_expirpvp = ewutils.calculatePvpTimer(
                    user_data.time_expirpvp, ewcfg.time_pvp_attack)

                resp_cont.add_member_to_update(cmd.message.author)
                # Persist changes to the database.
                user_data.persist()
                haunted_data.persist()
                market_data.persist()

                response = "{} has been haunted by the ghost of {}! Slime has been lost!".format(
                    member.display_name, cmd.message.author.display_name)

                haunted_channel = ewcfg.id_to_poi.get(haunted_data.poi).channel
                haunt_message = "You feel a cold shiver run down your spine"
                if cmd.tokens_count > 2:
                    haunt_message_content = re.sub(
                        "<.+>" if cmd.mentions_count == 1 else "\d{17,}", "",
                        cmd.message.content[(len(cmd.tokens[0])):]).strip()
                    # Cut down really big messages so discord doesn't crash
                    if len(haunt_message_content) > 500:
                        haunt_message_content = haunt_message_content[:-500]
                    haunt_message += " and faintly hear the words \"{}\"".format(
                        haunt_message_content)
                haunt_message += "."
                haunt_message = ewutils.formatMessage(member, haunt_message)
                resp_cont.add_channel_response(haunted_channel, haunt_message)
        else:
            # No mentions, or mentions we didn't understand.
            response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

    # Send the response to the player.
    resp_cont.add_channel_response(cmd.message.channel.name, response)
    await resp_cont.post()