Example #1
0
async def remove_user_overwrites(cmd):

    if not cmd.message.author.guild_permissions.administrator:
        return

    server = cmd.guild
    client = ewutils.get_client()

    for poi in ewcfg.poi_list:

        searched_channel = poi.channel

        channel = ewutils.get_channel(server, searched_channel)

        if channel == None:
            # Second try
            channel = ewutils.get_channel(server, searched_channel)
            if channel == None:
                continue

        # print('{} overwrites: {}'.format(poi.id_poi, channel.overwrites))
        for tuple in channel.overwrites:
            # print('tuplevar: {}'.format(tuple) + '\n\n')
            if tuple not in server.roles:
                member = tuple

                print('removed overwrite in {} for {}'.format(channel, member))

                for i in range(ewcfg.permissions_tries):
                    await channel.set_permissions(member, overwrite=None)

    response = "DEBUG: ALL USER OVERWRITES DELETED."
    return await ewutils.send_message(
        client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Example #2
0
async def shamble(cmd):

	user_data = EwUser(member = cmd.message.author)

	if user_data.life_state != ewcfg.life_state_shambler and user_data.poi != ewcfg.poi_id_assaultflatsbeach:
		response = "You have too many higher brain functions left to {}.".format(cmd.tokens[0])
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
	elif user_data.life_state in [ewcfg.life_state_juvenile, ewcfg.life_state_enlisted] and user_data.poi == ewcfg.poi_id_assaultflatsbeach:
		response = "You feel an overwhelming sympathy for the plight of the Shamblers and decide to join their ranks."
		await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

		await asyncio.sleep(5)
		
		user_data = EwUser(member=cmd.message.author)
		user_data.life_state = ewcfg.life_state_shambler
		user_data.degradation = 100

		ewutils.moves_active[user_data.id_user] = 0

		user_data.poi = ewcfg.poi_id_nuclear_beach_edge
		user_data.persist()
		
		member = cmd.message.author
		
		base_poi_channel = ewutils.get_channel(cmd.message.guild, 'nuclear-beach-edge')

		response = 'You arrive inside the facility and are injected with a unique strain of the Modelovirus. Not long after, a voice on the intercom chimes in.\n**"Welcome, {}. Welcome to Downpour Laboratories. It\'s safer here. Please treat all machines and facilities with respect, they are precious to our cause."**'.format(member.display_name)

		await ewrolemgr.updateRoles(client=cmd.client, member=member)
		return await ewutils.send_message(cmd.client, base_poi_channel, ewutils.formatMessage(cmd.message.author, response))
	
	else:
		pass
Example #3
0
async def rejuvenate(cmd):
	user_data = EwUser(member=cmd.message.author)

	if user_data.life_state == ewcfg.life_state_shambler and user_data.poi != ewcfg.poi_id_oozegardens:
		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))
	elif user_data.life_state == ewcfg.life_state_shambler and user_data.poi == ewcfg.poi_id_oozegardens:
		response = "You decide to change your ways and become one of the Garden Gankers in order to overthrow your old master."
		await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

		await asyncio.sleep(5)

		user_data = EwUser(member=cmd.message.author)
		user_data.life_state = ewcfg.life_state_juvenile
		user_data.degradation = 0
		#user_data.gvs_currency = 0

		ewutils.moves_active[user_data.id_user] = 0

		user_data.poi = ewcfg.poi_id_og_farms
		user_data.persist()

		client = ewutils.get_client()
		server = client.get_guild(user_data.id_server)
		member = server.get_member(user_data.id_user)
		
		base_poi_channel = ewutils.get_channel(cmd.message.guild, ewcfg.channel_og_farms)

		response = "You enter into Atomic Forest inside the farms of Ooze Gardens and are sterilized of the Modelovirus. Hortisolis gives you a big hug and says he's glad you've overcome your desire for vengeance in pursuit of deposing Downpour."

		await ewrolemgr.updateRoles(client=cmd.client, member=member)
		return await ewutils.send_message(cmd.client, base_poi_channel, ewutils.formatMessage(cmd.message.author, response))

	else:
		pass
async def post_leaderboards(client=None, server=None):
    leaderboard_channel = ewutils.get_channel(
        server=server, channel_name=ewcfg.channel_leaderboard)

    market = EwMarket(id_server=server.id)
    time = "day {}".format(market.day)

    await client.send_message(
        leaderboard_channel,
        "▓▓{} **STATE OF THE CITY:** {} {}▓▓".format(ewcfg.emote_theeye, time,
                                                     ewcfg.emote_theeye))

    kingpins = make_kingpin_board(server=server,
                                  title=ewcfg.leaderboard_kingpins)
    await client.send_message(leaderboard_channel, kingpins)
    topslimes = make_userdata_board(server=server,
                                    category=ewcfg.col_slimes,
                                    title=ewcfg.leaderboard_slimes)
    await client.send_message(leaderboard_channel, topslimes)
    topcoins = make_userdata_board(server=server,
                                   category=ewcfg.col_slimecredit,
                                   title=ewcfg.leaderboard_slimecredit)
    await client.send_message(leaderboard_channel, topcoins)
    topghosts = make_userdata_board(server=server,
                                    category=ewcfg.col_slimes,
                                    title=ewcfg.leaderboard_ghosts,
                                    lowscores=True,
                                    rows=3)
    await client.send_message(leaderboard_channel, topghosts)
    topbounty = make_userdata_board(server=server,
                                    category=ewcfg.col_bounty,
                                    title=ewcfg.leaderboard_bounty)
    await client.send_message(leaderboard_channel, topbounty)
Example #5
0
async def pa_command(cmd):
    user_data = EwUser(member=cmd.message.author)
    if not cmd.message.author.guild_permissions.administrator and user_data.life_state != ewcfg.life_state_executive:
        return await ewutils.fake_failed_command(cmd)
    else:
        if cmd.tokens_count >= 3:
            poi = ewutils.flattenTokenListToString(cmd.tokens[1])

            poi_obj = ewcfg.id_to_poi.get(poi)
            if poi == "auditorium":
                channel = "auditorium"
            else:
                channel = poi_obj.channel

            loc_channel = ewutils.get_channel(cmd.guild, channel)

            if poi is not None:
                patext = re.sub(
                    "<.+>", "",
                    cmd.message.content[(len(cmd.tokens[0]) +
                                         len(cmd.tokens[1]) + 1):]).strip()
                if len(patext) > 500:
                    patext = patext[:-500]
                return await ewutils.send_message(cmd.client, loc_channel,
                                                  patext)
Example #6
0
async def post_leaderboards(client = None, server = None):
	leaderboard_channel = ewutils.get_channel(server = server, channel_name = ewcfg.channel_leaderboard)

	market = EwMarket(id_server = server.id)
	time = "day {}".format(market.day) 

	await ewutils.send_message(client, leaderboard_channel, "▓▓{} **STATE OF THE CITY:** {} {}▓▓".format(ewcfg.emote_theeye, time, ewcfg.emote_theeye))

	kingpins = make_kingpin_board(server = server, title = ewcfg.leaderboard_kingpins)
	await ewutils.send_message(client, leaderboard_channel, kingpins)
	districts = make_district_control_board(id_server = server.id, title = ewcfg.leaderboard_districts)
	await ewutils.send_message(client, leaderboard_channel, districts)
	topslimes = make_userdata_board(server = server, category = ewcfg.col_slimes, title = ewcfg.leaderboard_slimes)
	await ewutils.send_message(client, leaderboard_channel, topslimes)
	topcoins = make_userdata_board(server = server, category = ewcfg.col_slimecoin, title = ewcfg.leaderboard_slimecoin)
	await ewutils.send_message(client, leaderboard_channel, topcoins)
	topghosts = make_userdata_board(server = server, category = ewcfg.col_slimes, title = ewcfg.leaderboard_ghosts, lowscores = True, rows = 3)
	await ewutils.send_message(client, leaderboard_channel, topghosts)
	topbounty = make_userdata_board(server = server, category = ewcfg.col_bounty, title = ewcfg.leaderboard_bounty, divide_by = ewcfg.slimecoin_exchangerate)
	await ewutils.send_message(client, leaderboard_channel, topbounty)
	topdonated = make_userdata_board(server = server, category = ewcfg.col_splattered_slimes, title = ewcfg.leaderboard_donated)
	await ewutils.send_message(client, leaderboard_channel, topdonated)
	topslimeoids = make_slimeoids_top_board(server = server)
	await ewutils.send_message(client, leaderboard_channel, topslimeoids)
	topfestivity = make_slimernalia_board(server = server, title = ewcfg.leaderboard_slimernalia)
	await ewutils.send_message(client, leaderboard_channel, topfestivity)
	topzines = make_zines_top_board(server=server)
	await ewutils.send_message(client, leaderboard_channel, topzines)
Example #7
0
async def donate(cmd):
	time_now = int(time.time())

	if cmd.message.channel.name != ewcfg.channel_slimecorphq:
		# Only allowed in SlimeCorp HQ.
		response = "You must go to SlimeCorp HQ to donate slime."
		await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
		return

	user_data = EwUser(member = cmd.message.author)

	value = None
	if cmd.tokens_count > 1:
		value = ewutils.getIntToken(tokens = cmd.tokens, allow_all = True)

	if value != None:
		if value < 0:
			value = user_data.slimes
		if value <= 0:
			value = None

	if value != None and value < ewcfg.slimecoin_exchangerate:
		response = "You must volunteer to donate at least %d slime to receive compensation." % ewcfg.slimecoin_exchangerate

	elif value != None:
		# Amount of slime invested.
		cost_total = int(value)
		coin_total = int(value / ewcfg.slimecoin_exchangerate)

		if user_data.slimes < cost_total:
			response = "Acid-green flashes of light and bloodcurdling screams emanate from small window of SlimeCorp HQ. Unfortunately, you did not survive the procedure. Your body is dumped down a disposal chute to the sewers."
			user_data.die(cause = ewcfg.cause_donation)
			user_data.persist()
			# Assign the corpse role to the player. He dead.
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
			sewerchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_sewers)
			await cmd.client.send_message(sewerchannel, "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(cmd.message.author, "You have died in a medical mishap. {}".format(ewcfg.emote_slimeskull)))
		else:
			# Do the transfer if the player can afford it.
			user_data.change_slimes(n = -cost_total, source = ewcfg.source_spending)
			user_data.change_slimecredit(n = coin_total, coinsource = ewcfg.coinsource_donation)
			user_data.time_lastinvest = time_now

			# Persist changes
			user_data.persist()

			response = "You stumble out of a Slimecorp HQ vault room in a stupor. You don't remember what happened in there, but your body hurts and you've got {slimecoin:,} shiny new SlimeCoin in your pocket.".format(slimecoin = coin_total)

	else:
		response = ewcfg.str_exchange_specify.format(currency = "slime", action = "donate")

	# Send the response to the player.
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
async def tweet(cmd):

    user_data = EwUser(id_user=cmd.message.author.id, id_server=cmd.guild.id)

    if user_data.has_gellphone():

        if cmd.tokens_count < 2:
            response = "Tweet what?"
            return await ewutils.send_response(response, cmd)

        tweet_content = ' '.join(
            "`{}`".format(token) if token.startswith("#") else token
            for token in cmd.tokens[1:])
        # embed limits
        if len(tweet_content) > 280:
            response = "Alright there bud, slow down a bit. No one's gonna read all that ({}/280).".format(
                len(tweet_content))
            return await ewutils.send_response(response, cmd)

        tweet = ewutils.discord.Embed()

        tweet.set_thumbnail(url=cmd.message.author.avatar_url)
        # we use the description to set the author since members cannot be mentioned from the author field
        tweet.description = "<@!{}>".format(cmd.message.author.id)
        tweet.color = get_tweet_color(user_data)

        # \u200b is a whitespace character, since we cannot leave field names empty
        tweet.add_field(name='\u200b', value=tweet_content)

        # works as long as the first attachment is an image
        # other file types are ignored
        if len(cmd.message.attachments) > 0:
            tweet.set_image(url=cmd.message.attachments[0].url)

        channel = ewutils.get_channel(server=cmd.guild,
                                      channel_name=ewcfg.channel_slimetwitter)

        await ewutils.send_message(cmd.client, channel, embed=tweet)

    else:
        response = "You need to have a gellphone to !tweet."
        return await ewutils.send_response(response, cmd)
Example #9
0
async def begin_cataclysm(user_data):
	
	player_data = EwPlayer(user_data.id_user)
	player_name = player_data.display_name
	
	client = ewutils.get_client()
	server = client.get_guild(user_data.id_server)
	auditorium_channel = ewutils.get_channel(server, 'auditorium')

	responses = [
		"@everyone",
		"You point the sword towards the heavens, making your prescense known. ENDLESS WAR begins to shudder as he witnesses what's about to happen...",
		"Dark clouds begin to assemble in the skies above. Buildings around you begin to lose their color. The ground begins to shake, and a sense of dread envelops you as you grip the handle of the cold metal sword.",
		"All of the wicked things you've ever done have come back to haunt you. But you've made your bed, and now you have to lie in it.",
		"All of the sins and hatred you've brought forth will be spun into form. But you knew that, and you lept toward the darkness anyways.",
		"With blade in hand, you unleash an unparalleled wave of anguish and dread over the city of Neo Los Angeles City AKA Neo Milw-",
		"**The sword snaps in two.**",
		"Wow. Just wow. No seriously, what the f**k did you think was gonna happen? I swear, people get so hopped up when they hear about shit like the Negaslime, like the Endless Rock, that they delude themselves into thinking that everything in this game has to be some kind of history-altering cataclysm. Not this time, dumbass. You've endured countless acts of BDSM Sadomasochism, and for what? Well, I'll tell you plain and simple: It was all for f*****g **NOTHING**.",
		"Yeah yeah, you've been taken for a fool, everyone laugh at the dummy, and then we can all go home and pretend like this whole 'Swilldermuk' thing never happened, right? No, f**k you. You are gonna sit here and listen to me ramble off about how much of a f*****g retard you are. I swear to god, the nerve that some people have, to think that they can play this race to the bottom and intentionally let themselves get pranked, it's just absolutely *disgusting*. Tell me, {}, you've been pranked so much... Who exactly is it that you've pranked? Can you name even one person? I thought not.".format(player_name),
		"This whole event, it was all about NOT getting pranked, about one-upping your bros and seeing the stupid ass retarded look on their face when you blew a goddamn airhorn right in their eardrums. But you? You're just a pathetic whipping boy who turned this whole thing upside down. You probably think I'm being a bit mean here don't you? But let's be real, I'm just stating the God's honest truth when I say this: You enjoy pain. You enjoy being whipped and beaten. The way you get your rocks off is when someone deliberately humiliates you, all for their own personal gain. Consider all of this a wake up call.",
		"You thought that you could just get away with being a disgusting sexfiend in public. You thought that when all of this was over, you'd get a nice item for your uh, what were your efforts again? Oh that's right, standing around waiting for credence to build up and then opening your body to unspeakable acts of debauchery. No strategy. No brains. No soul. You're just as bad, if not worse than the people who cowardly stood inside their apartments, waiting for all this to blow over. And so here we are, at the end of the road, pontificating over how badly you f****d everything up. Where do we go from here?",
		"How are you gonna reconcile with the fact that all your scars were for naught? 'How am I supposed to COPE', you might be thinking? Well, for starters, stop being such a reprehensible freak. I'm dead serious. All those times you let people further and further drain your credence, it was just abysmal and agonizing to watch. You don't have to apologize to anyone, you don't have to be put in a cage or any of that shit, because God knows how much you'd f*****g *enjoy it*. Just remember this. On this day, April 7th, in the year of our lord, two thousand and twenty, you, {}, were f*****g cringey, embarassing, and above all retarded. Commit it to memory. Tell your grandkids about it one day, even. It'll be a story for the ages.".format(player_name),
		"Now, as for everyone else reading this: Do your part, do your DUTY, even, and !pointandlaugh at {}, while you still can. It's what they f*****g deserve.".format(player_name),
	]
	
	for i in range(len(responses)):
		response = responses[i]


		if response == responses[1]:
			await ewutils.send_message(client, auditorium_channel, ewutils.formatMessage(player_data, response))
		else:
			await ewutils.send_message(client, auditorium_channel, response)
			
		if i >= 7:
			await asyncio.sleep(20)
		else:
			await asyncio.sleep(10)
Example #10
0
async def attack(cmd):
    time_now = int(time.time())
    response = ""
    deathreport = ""
    coinbounty = 0

    user_data = EwUser(member=cmd.message.author)
    slimeoid = EwSlimeoid(member=cmd.message.author)
    weapon = ewcfg.weapon_map.get(user_data.weapon)

    if ewmap.channel_name_is_poi(cmd.message.channel.name) == False:
        response = "You can't commit violence from here."
    elif ewmap.poi_is_pvp(user_data.poi) == False:
        response = "You must go elsewhere to commit gang violence."
    elif cmd.mentions_count > 1:
        response = "One shot at a time!"
    elif cmd.mentions_count <= 0:
        response = "Your bloodlust is appreciated, but ENDLESS WAR didn't understand that name."
    elif user_data.hunger >= ewutils.hunger_max_bylevel(user_data.slimelevel):
        response = "You are too exhausted for gang violence right now. Go get some grub!"
    elif cmd.mentions_count == 1:
        # Get shooting player's info
        if user_data.slimelevel <= 0:
            user_data.slimelevel = 1
            user_data.persist()

        # Get target's info.
        member = cmd.mentions[0]
        shootee_data = EwUser(member=member)
        shootee_slimeoid = EwSlimeoid(member=member)

        miss = False
        crit = False
        strikes = 0

        slimes_spent = int(ewutils.slime_bylevel(user_data.slimelevel) / 20)
        slimes_damage = int(
            (slimes_spent * 4) * (100 + (user_data.weaponskill * 10)) / 100.0)

        if weapon is None:
            slimes_damage /= 2  # penalty for not using a weapon, otherwise fists would be on par with other weapons
        slimes_dropped = shootee_data.totaldamage + shootee_data.slimes

        #fumble_chance = (random.randrange(10) - 4)
        #if fumble_chance > user_data.weaponskill:
        #miss = True

        user_iskillers = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_killers
        user_isrowdys = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_rowdys

        if shootee_data.life_state == ewcfg.life_state_kingpin:
            # Disallow killing generals.
            response = "He is hiding in his ivory tower and playing video games like a retard."

        elif (slimes_spent > user_data.slimes):
            # Not enough slime to shoot.
            response = "You don't have enough slime to attack. ({:,}/{:,})".format(
                user_data.slimes, slimes_spent)

        elif (time_now - user_data.time_lastkill) < ewcfg.cd_kill:
            # disallow kill if the player has killed recently
            response = "Take a moment to appreciate your last slaughter."

        elif shootee_data.poi != user_data.poi:
            response = "You can't reach them from where you are."

        elif ewmap.poi_is_pvp(shootee_data.poi) == False:
            response = "{} is not mired in the ENDLESS WAR right now.".format(
                member.display_name)

        elif user_iskillers == False and user_isrowdys == False:
            # Only killers, rowdys, the cop killer, and rowdy f****r can shoot people.
            if user_data.life_state == ewcfg.life_state_juvenile:
                response = "Juveniles lack the moral fiber necessary for violence."
            else:
                response = "You lack the moral fiber necessary for violence."

        elif (time_now - shootee_data.time_lastrevive) < ewcfg.invuln_onrevive:
            # User is currently invulnerable.
            response = "{} has died too recently and is immune.".format(
                member.display_name)

        elif shootee_data.life_state == ewcfg.life_state_corpse and user_data.ghostbust == True:
            # Attack a ghostly target
            was_busted = False

            #hunger drain
            user_data.hunger += ewcfg.hunger_pershot * ewutils.hunger_cost_mod(
                user_data.slimelevel)

            # Weaponized flavor text.
            randombodypart = ewcfg.hitzone_list[random.randrange(
                len(ewcfg.hitzone_list))]

            # Weapon-specific adjustments
            if weapon != None and weapon.fn_effect != None:
                # Build effect container
                ctn = EwEffectContainer(miss=miss,
                                        crit=crit,
                                        slimes_damage=slimes_damage,
                                        slimes_spent=slimes_spent,
                                        user_data=user_data,
                                        shootee_data=shootee_data)

                # Make adjustments
                weapon.fn_effect(ctn)

                # Apply effects for non-reference values
                miss = ctn.miss
                crit = ctn.crit
                slimes_damage = ctn.slimes_damage
                slimes_spent = ctn.slimes_spent
                strikes = ctn.strikes
                # user_data and shootee_data should be passed by reference, so there's no need to assign them back from the effect container.

                if miss:
                    slimes_damage = 0

            # Remove !revive invulnerability.
            user_data.time_lastrevive = 0

            # Spend slimes, to a minimum of zero
            user_data.change_slimes(
                n=(-user_data.slimes
                   if slimes_spent >= user_data.slimes else -slimes_spent),
                source=ewcfg.source_spending)

            # Damage stats
            ewstats.track_maximum(user=user_data,
                                  metric=ewcfg.stat_max_hitdealt,
                                  value=slimes_damage)
            ewstats.change_stat(user=user_data,
                                metric=ewcfg.stat_lifetime_damagedealt,
                                n=slimes_damage)

            # Remove repeat killing protection if.
            if user_data.id_killer == shootee_data.id_user:
                user_data.id_killer = ""

            if slimes_damage >= -shootee_data.slimes:
                was_busted = True

            if was_busted:
                # Move around slime as a result of the shot.
                user_data.change_slimes(n=ewutils.slime_bylevel(
                    shootee_data.slimelevel),
                                        source=ewcfg.source_busting)
                coinbounty = int(shootee_data.bounty /
                                 ewcfg.slimecoin_exchangerate)
                user_data.change_slimecredit(
                    n=coinbounty, coinsource=ewcfg.coinsource_bounty)

                ewstats.track_maximum(user=user_data,
                                      metric=ewcfg.stat_biggest_bust_level,
                                      value=shootee_data.slimelevel)

                # Player was busted.
                shootee_data.die(cause=ewcfg.cause_busted)

                response = "{name_target}\'s ghost has been **BUSTED**!!".format(
                    name_target=member.display_name)

                deathreport = "Your ghost has been busted by {}. {}".format(
                    cmd.message.author.display_name, ewcfg.emote_bustin)
                deathreport = "{} ".format(
                    ewcfg.emote_bustin) + ewutils.formatMessage(
                        member, deathreport)

                if coinbounty > 0:
                    response += "\n\n SlimeCorp transfers {} SlimeCoin to {}\'s account.".format(
                        str(coinbounty), cmd.message.author.display_name)

                #adjust busts
                ewstats.increment_stat(user=user_data,
                                       metric=ewcfg.stat_ghostbusts)

            else:
                # A non-lethal blow!
                shootee_data.change_slimes(n=slimes_damage,
                                           source=ewcfg.source_busting)
                damage = str(slimes_damage)

                if weapon != None:
                    if miss:
                        response = "{}".format(
                            weapon.str_miss.format(
                                name_player=cmd.message.author.display_name,
                                name_target=member.display_name + "\'s ghost"))
                    else:
                        response = weapon.str_damage.format(
                            name_player=cmd.message.author.display_name,
                            name_target=member.display_name + "\'s ghost",
                            hitzone=randombodypart,
                            strikes=strikes)
                        if crit:
                            response += " {}".format(
                                weapon.str_crit.format(
                                    name_player=cmd.message.author.
                                    display_name,
                                    name_target=member.display_name +
                                    "\'s ghost"))
                        response += " {target_name} loses {damage} antislime!".format(
                            target_name=(member.display_name + "\'s ghost"),
                            damage=damage)
                else:
                    if miss:
                        response = "{}\'s ghost is unharmed.".format(
                            member.display_name)
                    else:
                        response = "{target_name} is hit!! {target_name} loses {damage} antislime!".format(
                            target_name=(member.display_name + "\'s ghost"),
                            damage=damage)

            # Persist every users' data.
            user_data.persist()
            shootee_data.persist()

            await ewrolemgr.updateRoles(client=cmd.client,
                                        member=cmd.message.server.get_member(
                                            shootee_data.id_user))

        elif shootee_data.life_state == ewcfg.life_state_corpse and shootee_data.busted == True:
            # Target is already dead and not a ghost.
            response = "{} is already dead.".format(member.display_name)

        elif shootee_data.life_state == ewcfg.life_state_corpse and user_data.ghostbust == False:
            # Target is a ghost but user is not able to bust
            response = "You don't know how to fight a ghost."

        else:
            # Slimes from this shot might be awarded to the boss.
            role_boss = (ewcfg.role_copkiller
                         if user_iskillers else ewcfg.role_rowdyfucker)
            boss_slimes = 0
            user_inital_level = user_data.slimelevel

            was_juvenile = False
            was_killed = False
            was_shot = False

            if (shootee_data.life_state == ewcfg.life_state_enlisted) or (
                    shootee_data.life_state == ewcfg.life_state_juvenile):
                # User can be shot.
                if shootee_data.life_state == ewcfg.life_state_juvenile:
                    was_juvenile = True

                was_shot = True

            if was_shot:
                #hunger drain
                user_data.hunger += ewcfg.hunger_pershot * ewutils.hunger_cost_mod(
                    user_data.slimelevel)

                # Weaponized flavor text.
                randombodypart = ewcfg.hitzone_list[random.randrange(
                    len(ewcfg.hitzone_list))]

                # Weapon-specific adjustments
                if weapon != None and weapon.fn_effect != None:
                    # Build effect container
                    ctn = EwEffectContainer(miss=miss,
                                            crit=crit,
                                            slimes_damage=slimes_damage,
                                            slimes_spent=slimes_spent,
                                            user_data=user_data,
                                            shootee_data=shootee_data)

                    # Make adjustments
                    weapon.fn_effect(ctn)

                    # Apply effects for non-reference values
                    miss = ctn.miss
                    crit = ctn.crit
                    slimes_damage = ctn.slimes_damage
                    slimes_spent = ctn.slimes_spent
                    strikes = ctn.strikes
                    # user_data and shootee_data should be passed by reference, so there's no need to assign them back from the effect container.

                    if miss:
                        slimes_damage = 0

                # Remove !revive invulnerability.
                user_data.time_lastrevive = 0

                # Spend slimes, to a minimum of zero
                user_data.change_slimes(
                    n=(-user_data.slimes
                       if slimes_spent >= user_data.slimes else -slimes_spent),
                    source=ewcfg.source_spending)

                # Damage stats
                ewstats.track_maximum(user=user_data,
                                      metric=ewcfg.stat_max_hitdealt,
                                      value=slimes_damage)
                ewstats.change_stat(user=user_data,
                                    metric=ewcfg.stat_lifetime_damagedealt,
                                    n=slimes_damage)

                # Remove repeat killing protection if.
                if user_data.id_killer == shootee_data.id_user:
                    user_data.id_killer = ""

                if slimes_damage >= shootee_data.slimes:
                    was_killed = True

                if was_killed:
                    #adjust statistics
                    ewstats.increment_stat(user=user_data,
                                           metric=ewcfg.stat_kills)
                    ewstats.track_maximum(user=user_data,
                                          metric=ewcfg.stat_biggest_kill,
                                          value=int(slimes_dropped))
                    if user_data.slimelevel > shootee_data.slimelevel:
                        ewstats.increment_stat(
                            user=user_data, metric=ewcfg.stat_lifetime_ganks)
                    elif user_data.slimelevel < shootee_data.slimelevel:
                        ewstats.increment_stat(
                            user=user_data,
                            metric=ewcfg.stat_lifetime_takedowns)

                    # Collect bounty
                    coinbounty = int(
                        shootee_data.bounty /
                        ewcfg.slimecoin_exchangerate)  # 100 slime per coin

                    # Move around slime as a result of the shot.
                    if shootee_data.slimes >= 0:
                        if was_juvenile:
                            user_data.change_slimes(
                                n=slimes_dropped, source=ewcfg.source_killing)
                        else:
                            user_data.change_slimecredit(
                                n=coinbounty,
                                coinsource=ewcfg.coinsource_bounty)
                            user_data.change_slimes(
                                n=slimes_dropped / 2,
                                source=ewcfg.source_killing)
                            boss_slimes += int(slimes_dropped / 2)

                    # Steal items
                    ewitem.item_loot(member=member,
                                     id_user_target=cmd.message.author.id)

                    #add bounty
                    user_data.add_bounty(n=(shootee_data.bounty / 2) +
                                         (slimes_dropped / 4))

                    # Give a bonus to the player's weapon skill for killing a stronger player.
                    if shootee_data.slimelevel >= user_data.slimelevel:
                        user_data.add_weaponskill(n=1)

                    # Player was killed.
                    shootee_data.id_killer = user_data.id_user
                    shootee_data.die(cause=ewcfg.cause_killing)
                    shootee_data.change_slimes(
                        n=-slimes_dropped / 10,
                        source=ewcfg.source_ghostification)

                    kill_descriptor = "beaten to death"
                    if weapon != None:
                        response = weapon.str_damage.format(
                            name_player=cmd.message.author.display_name,
                            name_target=member.display_name,
                            hitzone=randombodypart,
                            strikes=strikes)
                        kill_descriptor = weapon.str_killdescriptor
                        if crit:
                            response += " {}".format(
                                weapon.str_crit.format(
                                    name_player=cmd.message.author.
                                    display_name,
                                    name_target=member.display_name))

                        response += "\n\n{}".format(
                            weapon.str_kill.format(
                                name_player=cmd.message.author.display_name,
                                name_target=member.display_name,
                                emote_skull=ewcfg.emote_slimeskull))
                        shootee_data.trauma = weapon.id_weapon

                        if slimeoid.level == ewcfg.slimeoid_state_active:
                            brain = ewcfg.brain_map.get(slimeoid.ai)
                            response += "\n\n{}" + brain.str_kill.format(
                                slimeoid_name=shootee_slimeoid.name)

                        if shootee_slimeoid.level == ewcfg.slimeoid_state_active:
                            brain = ewcfg.brain_map.get(shootee_slimeoid.ai)
                            response += "\n\n{}" + brain.str_death.format(
                                slimeoid_name=shootee_slimeoid.name)

                    else:
                        response = "{name_target} is hit!!\n\n{name_target} has died.".format(
                            name_target=member.display_name)

                        shootee_data.trauma = ""

                        if slimeoid.life_state == ewcfg.slimeoid_state_active:
                            brain = ewcfg.brain_map.get(slimeoid.ai)
                            response += "\n\n" + brain.str_kill.format(
                                slimeoid_name=shootee_slimeoid.name)

                        if shootee_slimeoid.life_state == ewcfg.slimeoid_state_active:
                            brain = ewcfg.brain_map.get(shootee_slimeoid.ai)
                            response += "\n\n" + brain.str_death.format(
                                slimeoid_name=shootee_slimeoid.name)

                    deathreport = "You were {} by {}. {}".format(
                        kill_descriptor, cmd.message.author.display_name,
                        ewcfg.emote_slimeskull)
                    deathreport = "{} ".format(
                        ewcfg.emote_slimeskull) + ewutils.formatMessage(
                            member, deathreport)

                    if coinbounty > 0:
                        response += "\n\n SlimeCorp transfers {} SlimeCoin to {}\'s account.".format(
                            str(coinbounty), cmd.message.author.display_name)
                else:
                    # A non-lethal blow!
                    shootee_data.change_slimes(n=-slimes_damage,
                                               source=ewcfg.source_damage)
                    damage = str(slimes_damage)

                    if weapon != None:
                        if miss:
                            response = "{}".format(
                                weapon.str_miss.format(
                                    name_player=cmd.message.author.
                                    display_name,
                                    name_target=member.display_name))
                        else:
                            response = weapon.str_damage.format(
                                name_player=cmd.message.author.display_name,
                                name_target=member.display_name,
                                hitzone=randombodypart,
                                strikes=strikes)
                            if crit:
                                response += " {}".format(
                                    weapon.str_crit.format(
                                        name_player=cmd.message.author.
                                        display_name,
                                        name_target=member.display_name))
                            response += " {target_name} loses {damage} slime!".format(
                                target_name=member.display_name, damage=damage)
                    else:
                        # unarmed attacks have no miss or crit chance
                        response = "{target_name} is hit!! {target_name} loses {damage} slime!".format(
                            target_name=member.display_name, damage=damage)
            else:
                response = 'You are unable to attack {}.'.format(
                    member.display_name)

            # Add level up text to response if appropriate
            if user_inital_level < user_data.slimelevel:
                response += "\n\n{} has been empowered by slime and is now a level {} slimeboi!".format(
                    cmd.message.author.display_name, user_data.slimelevel)

            # # Give slimes to the boss if possible.
            # boss_member = None
            # if boss_slimes > 0:
            # 	for member_search in cmd.message.server.members:
            # 		if role_boss in ewutils.getRoleMap(member_search.roles):
            # 			boss_member = member_search
            # 			break

            # if boss_member != None:
            # 	boss_data = EwUser(member = boss_member)
            # 	boss_data.change_slimes(n = boss_slimes)
            # 	boss_data.persist()

            kingpin = ewutils.find_kingpin(id_server=cmd.message.server.id,
                                           kingpin_role=role_boss)

            if kingpin:
                kingpin.change_slimes(n=boss_slimes)
                kingpin.persist()

            # Persist every users' data.
            user_data.persist()
            shootee_data.persist()

            # Assign the corpse role to the newly dead player.
            if was_killed:
                await ewrolemgr.updateRoles(client=cmd.client, member=member)

    # Send the response to the player.
    await cmd.client.send_message(
        cmd.message.channel, ewutils.formatMessage(cmd.message.author,
                                                   response))
    if deathreport != "":
        sewerchannel = ewutils.get_channel(cmd.message.server,
                                           ewcfg.channel_sewers)
        await cmd.client.send_message(sewerchannel, deathreport)
Example #11
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))
Example #12
0
async def mine(cmd):
    market_data = EwMarket(id_server=cmd.message.author.server.id)
    user_data = EwUser(member=cmd.message.author)
    time_now = int(time.time())

    # 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 cmd.client.send_message(
            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 cmd.client.send_message(
                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 cmd.client.send_message(
                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 >= ewutils.hunger_max_bylevel(
                user_data.slimelevel):
            global last_mismined_times
            mismined = last_mismined_times.get(cmd.message.author.id)

            if mismined == None:
                mismined = {'time': time_now, 'count': 0}

            if time_now - mismined['time'] < 5:
                mismined['count'] += 1
            else:
                # Reset counter.
                mismined['time'] = time_now
                mismined['count'] = 1

            last_mismined_times[cmd.message.author.id] = mismined

            if mismined[
                    'count'] >= 7:  # up to 6 messages can be buffered by discord and people have been dying unfairly because of that
                # Death
                last_mismined_times[cmd.message.author.id] = None
                user_data.die(cause=ewcfg.cause_mining)
                user_data.persist()

                await cmd.client.send_message(
                    cmd.message.channel,
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You have died in a mining accident."))
                await ewrolemgr.updateRoles(client=cmd.client,
                                            member=cmd.message.author)
                sewerchannel = ewutils.get_channel(cmd.message.server,
                                                   ewcfg.channel_sewers)
                await cmd.client.send_message(
                    sewerchannel, "{} ".format(ewcfg.emote_slimeskull) +
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You have died in a mining accident. {}".format(
                            ewcfg.emote_slimeskull)))
            else:
                await cmd.client.send_message(
                    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:
            # Determine if a poudrin is found.
            poudrin = False
            poudrinamount = 0

            # juvies get poudrins 4 times as often as enlisted players
            poudrin_rarity = ewcfg.poudrin_rarity / (
                2 if user_data.life_state == ewcfg.life_state_juvenile else 1)
            poudrin_mined = random.randint(1, poudrin_rarity)

            if poudrin_mined == 1:
                poudrin = True
                poudrinamount = 1 if random.randint(
                    1, 3) != 1 else 2  # 33% chance of extra drop

            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)

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

            was_levelup = True if user_initial_level < user_data.slimelevel else False

            # Create and give slime poudrins
            for pdx in range(poudrinamount):
                item_id = ewitem.item_create(
                    item_type=ewcfg.it_slimepoudrin,
                    id_user=cmd.message.author.id,
                    id_server=cmd.message.server.id,
                )
                ewutils.logMsg(
                    'Created poudrin (item {}) for user (id {})'.format(
                        item_id, cmd.message.author.id))

            # Fatigue the miner.
            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

            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

            user_data.persist()

            # Tell the player their slime level increased and/or a poudrin was found.
            if was_levelup or poudrin:
                response = ""

                if poudrin:
                    if poudrinamount == 1:
                        response += "You unearthed a slime poudrin! "
                    elif poudrinamount == 2:
                        response += "You unearthed two slime poudrins! "

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

                    ewutils.logMsg('{} has found {} poudrin(s)!'.format(
                        cmd.message.author.display_name, poudrinamount))

                if was_levelup:
                    response += "You have been empowered by slime and are now a level {} slimeboi!".format(
                        user_data.slimelevel)

                await cmd.client.send_message(
                    cmd.message.channel,
                    ewutils.formatMessage(cmd.message.author, response))
    else:
        # Mismined. Potentially kill the player for spamming the wrong channel.
        mismined = last_mismined_times.get(cmd.message.author.id)

        if mismined == None:
            mismined = {'time': time_now, 'count': 0}

        if time_now - mismined['time'] < 5:
            mismined['count'] += 1
        else:
            # Reset counter.
            mismined['time'] = time_now
            mismined['count'] = 1

        last_mismined_times[cmd.message.author.id] = mismined

        if mismined['count'] >= 5:
            # Death
            last_mismined_times[cmd.message.author.id] = None

            user_data.die(cause=ewcfg.cause_mining)
            user_data.persist()

            await cmd.client.send_message(
                cmd.message.channel,
                ewutils.formatMessage(cmd.message.author,
                                      "You have died in a mining accident."))
            await ewrolemgr.updateRoles(client=cmd.client,
                                        member=cmd.message.author)
            sewerchannel = ewutils.get_channel(cmd.message.server,
                                               ewcfg.channel_sewers)
            await cmd.client.send_message(
                sewerchannel,
                "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(
                    cmd.message.author,
                    "You have died in a mining accident. {}".format(
                        ewcfg.emote_slimeskull)))
        else:
            await cmd.client.send_message(
                cmd.message.channel,
                ewutils.formatMessage(cmd.message.author,
                                      "You can't mine here. Go to the mines."))
Example #13
0
async def refresh_user_perms(client,
                             id_server,
                             used_member=None,
                             startup=False):

    server = client.get_guild(id_server)

    has_overrides = False

    user_data = EwUser(member=used_member)

    if not startup:
        for poi in ewcfg.poi_list:
            channel = ewutils.get_channel(server, poi.channel)
            if channel == None:
                #ewutils.logMsg('Error: In refresh_user_perms, could not get channel for {}'.format(poi.channel))
                # Second try
                channel = ewutils.get_channel(server, poi.channel)
                if channel == None:
                    continue

            #print('{} overwrites: {}'.format(poi.id_poi, channel.overwrites))
            if used_member in channel.overwrites and user_data.poi != poi.id_poi:
                # Incorrect overwrite found for user

                #time_now_start = int(time.time())

                try:
                    for i in range(ewcfg.permissions_tries):
                        await channel.set_permissions(used_member,
                                                      overwrite=None)

                    # Handle mine walls
                    if poi.id_poi in ewcfg.mines_wall_map:
                        wall_channel = ewutils.get_channel(
                            server, ewcfg.mines_wall_map[poi.id_poi])
                        if wall_channel is not None:
                            for i in range(ewcfg.permissions_tries):
                                await wall_channel.set_permissions(
                                    used_member, overwrite=None)
                except:
                    ewutils.logMsg(
                        "Failed to remove permissions for {} in channel {}.".
                        format(used_member.display_name, channel.name))

                #time_now_end = int(time.time())
                #print('took {} seconds to delete channel permissions'.format(time_now_end - time_now_start))
                #print('\ndeleted overwrite in {} for {}\n'.format(channel, member))

            elif used_member not in channel.overwrites and user_data.poi == poi.id_poi:

                correct_poi = ewcfg.id_to_poi.get(user_data.poi)

                if correct_poi == None:
                    print('User {} has invalid POI of {}'.format(
                        user_data.id_user, user_data.poi))
                    correct_poi = ewcfg.id_to_poi.get(ewcfg.poi_id_downtown)

                correct_channel = ewutils.get_channel(server,
                                                      correct_poi.channel)
                #correct_lan_channel = "{}-LAN-connection".format(correct_channel)

                if correct_channel == None:
                    ewutils.logMsg("Channel {} not found".format(
                        correct_poi.channel))
                    return

                permissions_dict = correct_poi.permissions
                overwrite = discord.PermissionOverwrite()
                overwrite.read_messages = True if ewcfg.permission_read_messages in permissions_dict[
                    user_data.poi] else False
                overwrite.send_messages = True if ewcfg.permission_send_messages in permissions_dict[
                    user_data.poi] else False

                #print(permissions_dict[user_data.poi])
                #time_now_start = int(time.time())
                try:
                    for i in range(ewcfg.permissions_tries):
                        await correct_channel.set_permissions(
                            used_member, overwrite=overwrite)

                    # Handle mine walls
                    if correct_poi.id_poi in ewcfg.mines_wall_map:
                        wall_channel = ewutils.get_channel(
                            server, ewcfg.mines_wall_map[correct_poi.id_poi])
                        if wall_channel is not None:
                            overwrite = discord.PermissionOverwrite()
                            overwrite.read_messages = True
                            for i in range(ewcfg.permissions_tries):
                                await wall_channel.set_permissions(
                                    used_member, overwrite=overwrite)
                except:
                    ewutils.logMsg(
                        "Failed to add permissions to {} in channel {}.".
                        format(used_member.display_name, channel.name))

                #time_now_end = int(time.time())
                #print('took {} seconds to update channel permissions'.format(time_now_end - time_now_start))
                #print('updated permissions for {} in {}'.format(member, user_data.poi))

                has_overrides = True

        if not has_overrides:
            # Member has no overwrites -- fix this:
            user_data = EwUser(member=used_member)

            # User might not have their poi set to downtown when they join the server.
            if user_data.poi == None:
                correct_poi = ewcfg.id_to_poi.get(ewcfg.poi_id_downtown)
            else:
                correct_poi = ewcfg.id_to_poi.get(user_data.poi)

            if correct_poi == None:
                print('User {} has invalid POI of {}'.format(
                    user_data.id_user, user_data.poi))
                correct_poi = ewcfg.id_to_poi.get(ewcfg.poi_id_downtown)

            #print(user_data.poi)

            correct_channel = ewutils.get_channel(server, correct_poi.channel)
            if correct_channel == None:
                ewutils.logMsg("Channel {} not found".format(
                    correct_poi.channel))
                return

            permissions_dict = correct_poi.permissions
            overwrite = discord.PermissionOverwrite()
            overwrite.read_messages = True if ewcfg.permission_read_messages in permissions_dict[
                user_data.poi] else False
            overwrite.send_messages = True if ewcfg.permission_send_messages in permissions_dict[
                user_data.poi] else False

            #time_now_start = int(time.time())

            try:
                for i in range(ewcfg.permissions_tries):
                    await correct_channel.set_permissions(used_member,
                                                          overwrite=overwrite)
            except Exception as e:
                ewutils.logMsg("Failed to fix permissions for {}:{}.".format(
                    used_member.display_name, str(e)))
Example #14
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))
Example #15
0
    async def change_ownership(
            self,
            new_owner,
            actor,
            client=None):  # actor can either be a faction, "decay", or "init"
        factions = ["", ewcfg.faction_killers, ewcfg.faction_rowdys]

        if new_owner in factions:
            server = ewcfg.server_list[self.id_server]
            channel_str = ewcfg.id_to_poi[self.name].channel
            channel = ewutils.get_channel(server=server,
                                          channel_name=channel_str)

            if channel is not None and channel.topic:  # tests if the topic is neither None nor empty
                initialized = False

                # initialize channel topic control statuses
                for faction in factions:
                    if ewcfg.control_topics[faction] in channel.topic:
                        initialized = True

                if not initialized:
                    new_topic = channel.topic + " " + ewcfg.control_topics[
                        new_owner]

                # replace the the string of the previously controlling faction with that of the new one.
                else:
                    new_topic = channel.topic.replace(
                        ewcfg.control_topics[self.controlling_faction],
                        ewcfg.control_topics[new_owner])

                if client is None:
                    client = ewutils.get_client()

                if client is not None:
                    await client.edit_channel(channel=channel, topic=new_topic)

            if self.controlling_faction != new_owner:  # if the controlling faction actually changed
                if new_owner != "":  # if it was captured by a faction instead of being de-captured or decayed
                    await ewutils.post_in_channels(
                        id_server=self.id_server,
                        message="{faction} just captured {district}.".format(
                            faction=self.capturing_faction.capitalize(),
                            district=ewcfg.id_to_poi[self.name].str_name),
                        channels=[ewcfg.id_to_poi[self.name].channel] +
                        ewcfg.hideout_channels)
                else:  # successful de-capture or full decay
                    if actor != ewcfg.actor_decay:
                        await ewutils.post_in_channels(
                            id_server=self.id_server,
                            message=
                            "{faction} just wrested control over {district} from the {other_faction}."
                            .format(
                                faction=actor.capitalize(),
                                district=ewcfg.id_to_poi[self.name].str_name,
                                other_faction=self.
                                controlling_faction  # the faction that just lost control
                            ),
                            channels=[ewcfg.id_to_poi[self.name].channel] +
                            ewcfg.hideout_channels)

                self.controlling_faction = new_owner
                self.persist()
Example #16
0
	def change_ownership(self, new_owner, actor, client = None):  # actor can either be a faction, "decay", or "init"
		resp_cont_owner = ewutils.EwResponseContainer(client = ewutils.get_client(), id_server = self.id_server)

		factions = ["", ewcfg.faction_killers, ewcfg.faction_rowdys]

		if new_owner in factions:
			server = ewcfg.server_list[self.id_server]
			channel_str = ewcfg.id_to_poi[self.name].channel
			channel = ewutils.get_channel(server = server, channel_name = channel_str)

			if channel is not None and channel.topic:  # tests if the topic is neither None nor empty
				initialized = False

				# initialize channel topic control statuses
				for faction in factions:
					if ewcfg.control_topics[faction] in channel.topic:
						initialized = True

				if not initialized:
					new_topic = channel.topic + " " + ewcfg.control_topics[new_owner]

				# replace the the string of the previously controlling faction with that of the new one.
				else:
					new_topic = channel.topic.replace(ewcfg.control_topics[self.controlling_faction], ewcfg.control_topics[new_owner])

				if client is None:
					client = ewutils.get_client()


				if client is not None:
					resp_cont_owner.add_channel_topic(channel = channel_str, topic = new_topic)

			if self.controlling_faction != new_owner:  # if the controlling faction actually changed
				if new_owner != "":  # if it was captured by a faction instead of being de-captured or decayed
					countdown_message = ""
					if self.time_unlock > 0:
						countdown_message = "It will unlock for capture again in {}.".format(ewutils.formatNiceTime(seconds = self.time_unlock, round_to_minutes = True))
					message = "{faction} just captured {district}. {countdown}".format(
						faction = self.capturing_faction.capitalize(),
						district = ewcfg.id_to_poi[self.name].str_name,
						countdown = countdown_message
					)
					channels = [ewcfg.id_to_poi[self.name].channel] + ewcfg.hideout_channels
					
					for ch in channels:
						resp_cont_owner.add_channel_response(channel = ch, response = message)
				else:  # successful de-capture or full decay
					if actor != ewcfg.actor_decay:
						message = "{faction} just wrested control over {district} from the {other_faction}.".format(
							faction = actor.capitalize(),
							district = ewcfg.id_to_poi[self.name].str_name,
							other_faction = self.controlling_faction  # the faction that just lost control
						)
						channels = [ewcfg.id_to_poi[self.name].channel] + ewcfg.hideout_channels
						
						for ch in channels:
							resp_cont_owner.add_channel_response(channel = ch, response = message)

				self.controlling_faction = new_owner

		return resp_cont_owner
Example #17
0
async def writhe(cmd):
    resp = await ewcmd.start(cmd=cmd)
    response = ""
    user_data = EwUser(member=cmd.message.author)

    if user_data.life_state != ewcfg.life_state_grandfoe:
        response = "Only the NEGASLIME {} can do that.".format(
            ewcfg.emote_negaslime)
        await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
    else:
        # play animation
        he = ewcfg.emote_he
        s_ = ewcfg.emote_s_
        ve = ewcfg.emote_ve
        vt = ewcfg.emote_vt
        v_ = ewcfg.emote_v_
        h_ = ewcfg.emote_h_
        va = ewcfg.emote_va
        ht = ewcfg.emote_ht
        hs = ewcfg.emote_hs
        blank = ewcfg.emote_blank

        writhing1 = he
        writhing2 = s_ + he + "\n" + ve
        writhing3 = s_ + h_ + he + "\n" + vt + he
        writhing4 = s_ + h_ + ht + "\n" + vt + he + ve
        writhing5 = s_ + h_ + ht + "\n" + va + he + vt + he + "\n" + ve
        writhing6 = s_ + h_ + ht + "\n" + va + ht + va + ht + "\n" + v_ + ve + ve + ve + "\n" + ve
        writhing7 = s_ + h_ + ht + "\n" + va + ht + va + hs + he + "\n" + v_ + ve + v_ + vt + he + "\n" + ve + blank + ve
        writhing8 = s_ + h_ + ht + "\n" + va + ht + va + hs + he + "\n" + v_ + ve + v_ + vt + h_ + he + "\n" + vt + he + vt + he
        writhing9 = s_ + h_ + ht + "\n" + va + ht + va + hs + h_ + he + "\n" + v_ + ve + v_ + vt + h_ + ht + "\n" + vt + ht + vt + ht + blank + ve + "\n" + blank + ve + blank + ve
        writhing10 = s_ + h_ + ht + "\n" + va + ht + va + hs + h_ + he + "\n" + v_ + ve + v_ + vt + h_ + ht + "\n" + vt + ht + vt + ht + blank + vt + he + "\n" + blank + ve + blank + vt + he

        writhings = [
            writhing1, writhing2, writhing3, writhing4, writhing5, writhing6,
            writhing7, writhing8, writhing9, writhing10
        ]

        for writhing in writhings:
            cur_time = time.time()
            await ewutils.edit_message(cmd.client, resp, writhing)
            elapsed = time.time() - cur_time
            await asyncio.sleep(2.0 - elapsed)

        id_server = cmd.message.server.id
        targets = []

        # search for players in the negaslime's location in database and put them in a list
        if id_server != None:
            try:
                conn_info = ewutils.databaseConnect()
                conn = conn_info.get('conn')
                cursor = conn.cursor()

                cursor.execute(
                    "SELECT id_user FROM users WHERE id_server = %s AND poi = '{}' AND life_state IN (1, 2);"
                    .format(user_data.poi), (id_server, ))

                # convert pulled IDs into member objects
                target_ids = cursor.fetchall()
                for target_id in target_ids:
                    target = cmd.message.server.get_member(target_id[0])
                    targets.append(target)

                conn.commit()
            finally:
                # Clean up the database handles.
                cursor.close()
                ewutils.databaseClose(conn_info)

        victim_list = []

        # kill everyone in the negaslime's poi and remember their names
        for target in targets:
            if target != None:
                user_data_target = EwUser(member=target)

                user_data_target.id_killer = cmd.message.author.id
                user_data_target.die(cause=ewcfg.cause_grandfoe)
                user_data_target.persist()
                await ewrolemgr.updateRoles(client=cmd.client, member=target)
                sewerchannel = ewutils.get_channel(cmd.message.server,
                                                   ewcfg.channel_sewers)
                await ewutils.send_message(
                    cmd.client, sewerchannel,
                    "{} ".format(ewcfg.emote_slimeskull) +
                    ewutils.formatMessage(
                        target, "You have been crushed by tendrils. {}".format(
                            ewcfg.emote_slimeskull)))

                victim_list.append(target)

        # display result of the writhing
        if len(victim_list) > 0:
            victims_string = ewutils.userListToNameString(victim_list)
            response = "Your tendrils have successfully killed {}.".format(
                victims_string)
        else:
            response = "Your tendrils didn't kill anyone :("

        await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
Example #18
0
async def russian_roulette(cmd):
	time_now = int(time.time())

	if cmd.message.channel.name != ewcfg.channel_casino:
		#Only at the casino
		response = "You can only play russian roulette at the casino."
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	if cmd.mentions_count != 1:
		#Must mention only one player
		response = "Mention the player you want to challenge."
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	author = cmd.message.author
	member = cmd.mentions[0]

	global last_russianrouletted_times
	last_used_author = last_russianrouletted_times.get(author.id)
	last_used_member = last_russianrouletted_times.get(member.id)

	if last_used_author == None:
		last_used_author = 0
	if last_used_member == None:
		last_used_member = 0

	if last_used_author + ewcfg.cd_rr > time_now or last_used_member + ewcfg.cd_rr > time_now:
		response = "**ENOUGH**"
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	if author.id == member.id:
		response = "You might be looking for !suicide."
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

	challenger = EwUser(member = author)
	challengee = EwUser(member = member)

	#Players have been challenged
	if challenger.rr_challenger != "":
		response = "You are already in the middle of a challenge."
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

	if challengee.rr_challenger != "":
		response = "{} is already in the middle of a challenge.".format(member.display_name).replace("@", "\{at\}")
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

	if challenger.poi != challengee.poi:
		#Challangee must be in the casino
		response = "Both players must be in the casino."
		return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

	#Players have to be enlisted
	if challenger.life_state != ewcfg.life_state_enlisted or challengee.life_state != ewcfg.life_state_enlisted:
		if challenger.life_state == ewcfg.life_state_corpse:
			response = "You try to grab the gun, but it falls through your hands. Ghosts can't hold weapons.".format(author.display_name).replace("@", "\{at\}")
			return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

		elif challengee.life_state == ewcfg.life_state_corpse:
			response = "{} tries to grab the gun, but it falls through their hands. Ghosts can't hold weapons.".format(member.display_name).replace("@", "\{at\}")
			return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

		else:
			response = "Juveniles are too cowardly to gamble their lives."
			return await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))

	#Assign a challenger so players can't be challenged
	challenger.rr_challenger = challenger.id_user
	challengee.rr_challenger = challenger.id_user

	challenger.persist()
	challengee.persist()

	response = "You have been challenged by {} to a game of russian roulette. Do you !accept or !refuse?".format(author.display_name).replace("@", "\{at\}")
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(member, response))

	#Wait for an answer
	accepted = 0
	msg = await cmd.client.wait_for_message(timeout = 10, author = member, check = check)
	if msg != None:
		if msg.content == "!accept":
			accepted = 1

	#Start game
	if accepted == 1:

		for spin in range(1, 7):
			challenger = EwUser(member = author)
			challengee = EwUser(member = member)
			
			#In case any of the players suicide mid-game
			if challenger.life_state == ewcfg.life_state_corpse:
				response = "{} couldn't handle the pressure and killed themselves.".format(author.display_name).replace("@", "\{at\}")
				await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(member, response))
				break
				
			if challengee.life_state == ewcfg.life_state_corpse:
				response = "{} couldn't handle the pressure and killed themselves.".format(member.display_name).replace("@", "\{at\}")
				await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))
				break
				
			#Challenger goes second
			if spin % 2 == 0:
				player = author
			else:
				player = member

			response = "You put the gun to your head and pull the trigger..."
			res = await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(player, response))
			await asyncio.sleep(1)

			#Player dies
			if random.randint(1, (7 - spin)) == 1:
				await cmd.client.edit_message(res, ewutils.formatMessage(player, (response + " **BANG**")))
				response = "You return to the Casino with {}'s slime.".format(player.display_name).replace("@", "\{at\}")
				was_suicide = False
				#Challenger dies
				if spin % 2 == 0:
					winner = member

					challenger = EwUser(member = author)
					challengee = EwUser(member = member)
					
					if challengee.life_state != ewcfg.life_state_corpse:
						challengee.change_slimes(n = challenger.slimes, source = ewcfg.source_killing)
						ewitem.item_loot(member = author, id_user_target = member.id)
						
						challenger.id_killer = challenger.id_user
						challenger.die(cause = ewcfg.cause_suicide)
					#In case the other player killed themselves
					else:
						was_suicide = True
						winner = author
						response = "You shoot {}'s corpse, adding insult to injury.".format(member.display_name).replace("@", "\{at\}")

				#Challangee dies
				else:
					winner = author

					challenger = EwUser(member = author)
					challengee = EwUser(member = member)

					if challenger.life_state != ewcfg.life_state_corpse:					
						challenger.change_slimes(n = challengee.slimes, source = ewcfg.source_killing)
						ewitem.item_loot(member = member, id_user_target = author.id)

						challengee.id_killer = challengee.id_user
						challengee.die(cause = ewcfg.cause_suicide)
					#In case the other player killed themselves
					else:
						was_suicide = True
						winner = member
						response = "You shoot {}'s corpse, adding insult to injury.".format(author.display_name).replace("@", "\{at\}")
					
				challenger.rr_challenger = ""
				challengee.rr_challenger = ""

				challenger.persist()
				challengee.persist()

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

				await ewrolemgr.updateRoles(client = cmd.client, member = author)
				await ewrolemgr.updateRoles(client = cmd.client, member = member)

				if was_suicide == False:
					deathreport = "You arrive among the dead by your own volition. {}".format(ewcfg.emote_slimeskull)
					deathreport = "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(player, deathreport)

					sewerchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_sewers)
					await cmd.client.send_message(sewerchannel, deathreport)

				break

			#Or survives
			else:
				await cmd.client.edit_message(res, ewutils.formatMessage(player, (response + " but it's empty")))
				await asyncio.sleep(1)
				#track spins?

	#Or cancel the challenge
	else:
		response = "{} was too cowardly to accept your challenge.".format(member.display_name).replace("@", "\{at\}")
		await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(author, response))
		last_russianrouletted_times[author.id] = time_now - 540
		last_russianrouletted_times[member.id] = time_now - 540


	challenger = EwUser(member = author)
	challengee = EwUser(member = member)

	challenger.rr_challenger = ""
	challengee.rr_challenger = ""

	challenger.persist()
	challengee.persist()

	return
Example #19
0
async def suicide(cmd):
    response = ""
    deathreport = ""

    # Only allowed in the combat zone.
    if ewmap.channel_name_is_poi(cmd.message.channel.name) == False:
        response = "You must go into the city to commit suicide."
    else:
        # Get the user data.
        user_data = EwUser(member=cmd.message.author)

        user_iskillers = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_killers
        user_isrowdys = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_rowdys
        user_isgeneral = user_data.life_state == ewcfg.life_state_kingpin
        user_isjuvenile = user_data.life_state == ewcfg.life_state_juvenile
        user_isdead = user_data.life_state == ewcfg.life_state_corpse

        if user_isdead:
            response = "Too late for that."
        elif user_isjuvenile:
            response = "Juveniles are too cowardly for suicide."
        elif user_isgeneral:
            response = "\*click* Alas, your gun has jammed."
        elif user_iskillers or user_isrowdys:
            #Give slime to challenger if player suicides mid russian roulette
            if user_data.rr_challenger != "":
                challenger = EwUser(id_user=user_data.rr_challenger,
                                    id_server=user_data.id_server)
                challenger.change_slimes(n=user_data.slimes,
                                         source=ewcfg.source_killing)
                ewitem.item_loot(member=cmd.message.author,
                                 id_user_target=user_data.rr_challenger)
                challenger.persist()

            # Set the id_killer to the player himself, remove his slime and slime poudrins.
            user_data.id_killer = cmd.message.author.id
            user_data.die(cause=ewcfg.cause_suicide)
            user_data.persist()

            # Assign the corpse role to the player. He dead.
            await ewrolemgr.updateRoles(client=cmd.client,
                                        member=cmd.message.author)

            response = '{} has willingly returned to the slime. {}'.format(
                cmd.message.author.display_name, ewcfg.emote_slimeskull)
            deathreport = "You arrive among the dead by your own volition. {}".format(
                ewcfg.emote_slimeskull)
            deathreport = "{} ".format(
                ewcfg.emote_slimeskull) + ewutils.formatMessage(
                    cmd.message.author, deathreport)
        else:
            # This should never happen. We handled all the role cases. Just in case.
            response = "\*click* Alas, your gun has jammed."

    # Send the response to the player.
    await cmd.client.send_message(
        cmd.message.channel, ewutils.formatMessage(cmd.message.author,
                                                   response))
    if deathreport != "":
        sewerchannel = ewutils.get_channel(cmd.message.server,
                                           ewcfg.channel_sewers)
        await cmd.client.send_message(sewerchannel, deathreport)
Example #20
0
async def revive(cmd):
    time_now = int(time.time())
    response = ""

    if cmd.message.channel.name != ewcfg.channel_endlesswar and cmd.message.channel.name != ewcfg.channel_sewers:
        response = "Come to me. I hunger. #{}.".format(ewcfg.channel_sewers)
    else:
        player_data = EwUser(member=cmd.message.author)

        time_until_revive = (player_data.time_lastdeath +
                             player_data.degradation) - time_now
        if time_until_revive > 0:
            response = "ENDLESS WAR is not ready to {} you yet ({}s).".format(
                cmd.tokens[0], time_until_revive)
            return await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(cmd.message.author, response))

        slimeoid = EwSlimeoid(member=cmd.message.author)

        if player_data.life_state == ewcfg.life_state_corpse:
            market_data = EwMarket(id_server=cmd.message.server.id)

            # Endless War collects his fee.
            #fee = (player_data.slimecoin / 10)
            #player_data.change_slimecoin(n = -fee, coinsource = ewcfg.coinsource_revival)
            #market_data.slimes_revivefee += fee
            #player_data.busted = False

            # Preserve negaslime
            if player_data.slimes < 0:
                #market_data.negaslime += player_data.slimes
                player_data.change_slimes(n=-player_data.slimes)  # set to 0

            # reset slimelevel to zero
            player_data.slimelevel = 0

            # Set time of last revive. This used to provied spawn protection, but currently isn't used.
            player_data.time_lastrevive = time_now

            if player_data.degradation >= 100:
                player_data.life_state = ewcfg.life_state_shambler
                player_data.change_slimes(n=0.5 * ewcfg.slimes_shambler)
                player_data.trauma = ""
                poi_death = ewcfg.id_to_poi.get(player_data.poi_death)
                if ewmap.inaccessible(poi=poi_death, user_data=player_data):
                    player_data.poi = ewcfg.poi_id_downtown
                else:
                    player_data.poi = poi_death.id_poi
            else:
                # Set life state. This is what determines whether the player is actually alive.
                player_data.life_state = ewcfg.life_state_juvenile
                # Give player some initial slimes.
                player_data.change_slimes(n=ewcfg.slimes_onrevive)
                # Get the player out of the sewers.
                player_data.poi = ewcfg.poi_id_downtown

            player_data.persist()
            market_data.persist()

            # Shower every district in the city with slime from the sewers.
            sewer_data = EwDistrict(district=ewcfg.poi_id_thesewers,
                                    id_server=cmd.message.server.id)
            # the amount of slime showered is divided equally amongst the districts
            districts_amount = len(ewcfg.capturable_districts)
            geyser_amount = int(0.5 * sewer_data.slimes / districts_amount)
            # Get a list of all the districts
            for poi in ewcfg.capturable_districts:
                district_data = EwDistrict(district=poi,
                                           id_server=cmd.message.server.id)

                district_data.change_slimes(n=geyser_amount)
                sewer_data.change_slimes(n=-1 * geyser_amount)

                district_data.persist()
                sewer_data.persist()

            sewer_inv = ewitem.inventory(id_user=sewer_data.name,
                                         id_server=sewer_data.id_server)
            for item in sewer_inv:
                district = ewcfg.poi_id_slimesea
                if random.random() < 0.5:
                    district = random.choice(ewcfg.capturable_districts)
                ewitem.give_item(id_item=item.get("id_item"),
                                 id_user=district,
                                 id_server=sewer_data.id_server)

            await ewrolemgr.updateRoles(client=cmd.client,
                                        member=cmd.message.author)

            response = '{slime4} Geysers of fresh slime erupt from every manhole in the city, showering their surrounding districts. {slime4} {name} has been reborn in slime. {slime4}'.format(
                slime4=ewcfg.emote_slime4,
                name=cmd.message.author.display_name)
        else:
            response = 'You\'re not dead just yet.'

    #	deathreport = "You were {} by {}. {}".format(kill_descriptor, cmd.message.author.display_name, ewcfg.emote_slimeskull)
    #	deathreport = "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(member, deathreport)

        if slimeoid.life_state == ewcfg.slimeoid_state_active:
            reunite = ""
            brain = ewcfg.brain_map.get(slimeoid.ai)
            reunite += brain.str_revive.format(slimeoid_name=slimeoid.name)
            new_poi = ewcfg.id_to_poi.get(player_data.poi)
            revivechannel = ewutils.get_channel(cmd.message.server,
                                                new_poi.channel)
            reunite = ewutils.formatMessage(cmd.message.author, reunite)
            await ewutils.send_message(cmd.client, revivechannel, reunite)

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Example #21
0
async def disembark(cmd):
	# can only use movement commands in location channels
	if ewmap.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)

	# can only disembark when you're on a transport vehicle
	if 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()

		# 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
			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:
			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
				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
			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:
			user_data.poi = transport_data.current_stop
			user_data.persist()
			response = "You enter {}".format(stop_poi.str_name)
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
			return await ewutils.send_message(cmd.client, ewutils.get_channel(cmd.message.server, stop_poi.channel), ewutils.formatMessage(cmd.message.author, response))
		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))
Example #22
0
async def revive(cmd):
	time_now = int(time.time())
	response = ""

	if cmd.message.channel.name != ewcfg.channel_endlesswar and cmd.message.channel.name != ewcfg.channel_sewers:
		response = "Come to me. I hunger. #{}.".format(ewcfg.channel_sewers)
	else:
		player_data = EwUser(member = cmd.message.author)
		slimeoid = EwSlimeoid(member = cmd.message.author)

		if player_data.life_state == ewcfg.life_state_corpse:
			market_data = EwMarket(id_server = cmd.message.server.id)

			# Endless War collects his fee.
			fee = (player_data.slimecredit / 10)
			player_data.change_slimecredit(n = -fee, coinsource = ewcfg.coinsource_revival)
			market_data.slimes_revivefee += fee
			player_data.busted = False
			
			# Preserve negaslime
			if player_data.slimes < 0:
				market_data.negaslime += player_data.slimes
				player_data.change_slimes(n = -player_data.slimes) # set to 0

			# Give player some initial slimes.
			player_data.slimelevel = 0
			player_data.change_slimes(n = ewcfg.slimes_onrevive)

			# Set time of last revive. This used to provied spawn protection, but currently isn't used.
			player_data.time_lastrevive = time_now

			# Set life state. This is what determines whether the player is actually alive.
			player_data.life_state = ewcfg.life_state_juvenile

			# Get the player out of the sewers. Will be endless-war eventually.
			player_data.poi = ewcfg.poi_id_downtown

			player_data.persist()
			market_data.persist()

			# Give some slimes to every living player (currently online)
			for member in cmd.message.server.members:
				if member.id != cmd.message.author.id and member.id != cmd.client.user.id:
					member_data = EwUser(member = member)

					if member_data.life_state != ewcfg.life_state_corpse and member_data.life_state != ewcfg.life_state_grandfoe:
						member_data.change_slimes(n = ewcfg.slimes_onrevive_everyone)
						member_data.persist()

			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)

			response = '{slime4} A geyser of fresh slime erupts, showering Rowdy, Killer, and Juvenile alike. {slime4} {name} has been reborn in slime. {slime4}'.format(slime4 = ewcfg.emote_slime4, name = cmd.message.author.display_name)
		else:
			response = 'You\'re not dead just yet.'

	#	deathreport = "You were {} by {}. {}".format(kill_descriptor, cmd.message.author.display_name, ewcfg.emote_slimeskull)
	#	deathreport = "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(member, deathreport)

		if slimeoid.life_state == ewcfg.slimeoid_state_active:
			reunite = ""
			brain = ewcfg.brain_map.get(slimeoid.ai)
			reunite += brain.str_revive.format(
			slimeoid_name = slimeoid.name
			)
			downtownchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_downtown)
			reunite = ewutils.formatMessage(cmd.message.author, reunite)
			await cmd.client.send_message(downtownchannel, reunite)

	# Send the response to the player.
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Example #23
0
async def donate(cmd):
    user_data = EwUser(member=cmd.message.author)
    market_data = EwMarket(id_server=user_data.id_server)

    time_now = round(time.time())

    if user_data.poi == ewcfg.poi_id_slimecorphq:
        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimes
            if value <= 0:
                value = None

        if value != None and value < ewcfg.slimecoin_exchangerate:
            response = "You must volunteer to donate at least %d slime to receive compensation." % ewcfg.slimecoin_exchangerate

        elif value != None:
            # Amount of slime invested.
            cost_total = round(value)
            coin_total = round(value / ewcfg.slimecoin_exchangerate)

            if user_data.slimes < cost_total:
                response = "Acid-green flashes of light and bloodcurdling screams emanate from small window of SlimeCorp HQ. Unfortunately, you did not survive the procedure. Your body is dumped down a disposal chute to the sewers."
                market_data.donated_slimes += user_data.slimes
                market_data.persist()
                user_data.die(cause=ewcfg.cause_donation)
                user_data.persist()
                # Assign the corpse role to the player. He dead.
                await ewrolemgr.updateRoles(client=cmd.client,
                                            member=cmd.message.author)
                sewerchannel = ewutils.get_channel(cmd.message.server,
                                                   ewcfg.channel_sewers)
                await ewutils.send_message(
                    cmd.client, sewerchannel,
                    "{} ".format(ewcfg.emote_slimeskull) +
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You have died in a medical mishap. {}".format(
                            ewcfg.emote_slimeskull)))
            else:
                # Do the transfer if the player can afford it.
                market_data.donated_slimes += cost_total
                market_data.persist()
                user_data.change_slimes(n=-cost_total,
                                        source=ewcfg.source_spending)
                user_data.change_slimecoin(
                    n=coin_total, coinsource=ewcfg.coinsource_donation)
                user_data.slime_donations += cost_total

                # Persist changes
                user_data.persist()

                response = "You stumble out of a Slimecorp HQ vault room in a stupor. You don't remember what happened in there, but your body hurts and you've got {slimecoin:,} shiny new SlimeCoin in your pocket.".format(
                    slimecoin=coin_total)

        else:
            response = ewcfg.str_exchange_specify.format(currency="slime",
                                                         action="donate")

    elif user_data.poi == ewcfg.poi_id_slimeoidlab:
        poudrins = ewitem.find_item(item_search="slimepoudrin",
                                    id_user=cmd.message.author.id,
                                    id_server=cmd.message.server.id if
                                    cmd.message.server is not None else None)

        if poudrins == None:
            response = "You have to own a poudrin in order to donate a poudrin. Duh."

        else:
            ewitem.item_delete(
                id_item=poudrins.get('id_item'))  # Remove Poudrins
            market_data.donated_poudrins += 1
            market_data.persist()
            user_data.poudrin_donations += 1
            user_data.persist()

            response = "You hand off one of your hard-earned poudrins to the front desk receptionist, who is all too happy to collect it. Pretty uneventful, but at the very least you’re glad donating isn’t physically painful anymore."

    else:
        response = "To donate slime, go to the SlimeCorp HQ in Downtown. To donate poudrins, go to the SlimeCorp Lab in Brawlden."

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))