예제 #1
0
async def mine(cmd):
    roles_map_user = ewutils.getRoleMap(cmd.message.author.roles)
    time_now = int(time.time())

    if ewcfg.role_corpse in roles_map_user:
        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)))
    else:
        if (cmd.message.channel.name == ewcfg.channel_mines):
            user_data = EwUser(member=cmd.message.author)

            if user_data.stamina >= ewcfg.stamina_max:
                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'] >= 5:
                    # Death
                    last_mismined_times[cmd.message.author.id] = None
                    user_data.slimes = 0
                    user_data.persist()

                    await cmd.client.send_message(
                        cmd.message.channel,
                        ewutils.formatMessage(
                            cmd.message.author,
                            "You have died in a mining accident."))
                    await cmd.client.replace_roles(
                        cmd.message.author, cmd.roles_map[ewcfg.role_corpse])
                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
                poudrinchance = (random.randrange(3600) + 1)
                if poudrinchance == 3600:
                    poudrin = True
                    poudrinamount = (random.randrange(2) + 1)

                # Add mined slime to the user.
                user_data.slimes += (10 * (2**user_data.slimelevel))
                user_data.slimepoudrins += poudrinamount

                # Adjust slime level.
                was_levelup = False
                new_level = len(str(int(user_data.slimes)))
                if new_level > user_data.slimelevel:
                    was_levelup = True
                    user_data.slimelevel = new_level

                # Fatigue the miner.
                user_data.stamina += ewcfg.stamina_permine
                if random.randrange(10) > 6:
                    user_data.stamina += ewcfg.stamina_permine

                # Flag the user for PvP
                user_data.time_expirpvp = ewutils.calculatePvpTimer(
                    user_data.time_expirpvp,
                    (int(time.time()) + ewcfg.time_pvp_mine))
                user_data.persist()

                # Add the PvP flag role.
                await ewutils.add_pvp_role(cmd=cmd)

                # 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! "

                        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(
                            new_level)

                    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)
            resp = await ewcmd.start(cmd=cmd)

            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'] >= 3:
                # Death
                last_mismined_times[cmd.message.author.id] = None

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data = EwUser(member=cmd.message.author,
                                       conn=conn,
                                       cursor=cursor)
                    user_data.slimes = 0
                    user_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()

                await cmd.client.edit_message(
                    resp,
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You have died in a mining accident."))
                await cmd.client.replace_roles(
                    cmd.message.author, cmd.roles_map[ewcfg.role_corpse])
            else:
                await cmd.client.edit_message(
                    resp,
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You can't mine here. Try #{}.".format(
                            ewcfg.channel_mines)))
예제 #2
0
async def reap(cmd):
    user_data = EwUser(member=cmd.message.author)
    response = ""
    levelup_response = ""
    mutations = user_data.get_mutations()
    poi = ewcfg.id_to_poi.get(user_data.poi)

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

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

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

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

                    slime_gain = farm.slimes_onreap

                    if poi.is_subzone:
                        district_data = EwDistrict(
                            district=poi.mother_district,
                            id_server=cmd.message.server.id)
                    else:
                        district_data = EwDistrict(
                            district=poi.id_poi,
                            id_server=cmd.message.server.id)

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

                    if cmd.message.channel.name == ewcfg.channel_jr_farms:
                        slime_gain = int(slime_gain / 4)

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

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

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

                    if ewcfg.mutation_id_lucky in mutations:
                        unearthed_item_chance *= 1.33

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

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

                        item_props = ewitem.gen_item_props(item)

                        if item is not None:

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

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

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

                    item_props = ewitem.gen_item_props(vegetable)

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

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

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

                    was_levelup = True if user_initial_level < user_data.slimelevel else False

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

                    user_data.hunger += ewcfg.hunger_perfarm
                    # Flag the user for PvP
                    user_data.time_expirpvp = ewutils.calculatePvpTimer(
                        user_data.time_expirpvp,
                        (int(time.time()) + ewcfg.time_pvp_farm))

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

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

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
예제 #3
0
async def haunt(cmd):
    time_now = int(time.time())
    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.message.server.id)

    if cmd.mentions_count > 1:
        response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
    elif cmd.mentions_count == 1:
        # Get the user and target data from the database.
        user_data = EwUser(member=cmd.message.author)

        member = cmd.mentions[0]
        haunted_data = EwUser(member=member)
        market_data = EwMarket(id_server=cmd.message.server.id)
        target_isshambler = haunted_data.life_state == ewcfg.life_state_shambler

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

            #if -user_data.slimes < haunted_slimes:  # cap on for how much you can haunt
            #	haunted_slimes = -user_data.slimes

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

            user_data.time_expirpvp = ewutils.calculatePvpTimer(
                user_data.time_expirpvp,
                (int(time.time()) + ewcfg.time_pvp_attack))
            resp_cont.add_member_to_update(cmd.message.author)
            # Persist changes to the database.
            user_data.persist()
            haunted_data.persist()
            market_data.persist()

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

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

    # Send the response to the player.
    resp_cont.add_channel_response(cmd.message.channel.name, response)
    await resp_cont.post()
예제 #4
0
async def reel(cmd):
	user_data = EwUser(member = cmd.message.author)
	if cmd.message.author.id not in fishers.keys():
		fishers[cmd.message.author.id] = EwFisher()
	fisher = fishers[cmd.message.author.id]
	poi = ewcfg.id_to_poi.get(user_data.poi)

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

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

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

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

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

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

					item_props = ewitem.gen_item_props(item)

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

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

				else:
					item = random.choice(slimesea_inventory)

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

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

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

			else:
				user_initial_level = user_data.slimelevel

				gang_bonus = False

				has_fishingrod = False

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

				value = 0

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

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

					value += 20

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

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

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

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

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

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

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

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

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

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

				if has_fishingrod == True:
					slime_gain = slime_gain * 2

				if fisher.current_fish == "plebefish":
					slime_gain = ewcfg.fish_gain * .5
					value = 10
				if poi.is_subzone:
					district_data = EwDistrict(district = poi.mother_district, id_server = cmd.message.server.id)
				else:
					district_data = EwDistrict(district = poi.id_poi, id_server = cmd.message.server.id)

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


				if cmd.message.channel.name == ewcfg.channel_jr_pier:
					slime_gain = int(slime_gain / 4)

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

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

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

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

				was_levelup = True if user_initial_level < user_data.slimelevel else False

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

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

				fisher.fishing = False
				fisher.bite = False
				fisher.current_fish = ""
				fisher.current_size = ""
				fisher.pier = ""

				# Flag the user for PvP
				user_data.time_expirpvp = ewutils.calculatePvpTimer(user_data.time_expirpvp, (int(time.time()) + ewcfg.time_pvp_fish))

				user_data.persist()
				await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
				
	else:
		response = "You cast your fishing rod unto a sidewalk. That is to say, you've accomplished nothing. Go to a pier if you want to fish."

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
예제 #5
0
async def annex(cmd):
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(
            cmd.tokens[0])
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.message.server.id)
    time_now = int(time.time())

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

    if user_data.life_state == ewcfg.life_state_corpse:
        response = "You ineffectively try shaking your can of spraypaint to whip up some sick graffiti. Alas, you’re all outta slime. " \
                         "They should really make these things compatible with ectoplasm."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if not (len(user_data.faction) > 0
            and user_data.life_state == ewcfg.life_state_enlisted):
        response = "Juveniles are too chickenshit to make graffiti and risk getting busted by the cops. F****n’ losers."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi in [
            ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_copkilltown
    ]:
        response = "There’s no point, the rest of your gang has already covered this place in spraypaint. Focus on exporting your graffiti instead."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi == ewcfg.poi_id_juviesrow:
        response = "Nah, the Rowdys and Killers have both agreed this is neutral ground. You don’t want to start a diplomatic crisis, " \
                         "just stick to spraying down sick graffiti and splattering your rival gang across the pavement in the other districts."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if not user_data.poi in ewcfg.capturable_districts:
        response = "This zone cannot be captured."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    district_data = EwDistrict(id_server=user_data.id_server,
                               district=user_data.poi)

    if district_data.is_degraded():
        response = "{} has been degraded by shamblers. You can't {} here anymore.".format(
            poi.str_name, cmd.tokens[0])
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
    if district_data.time_unlock > 0:
        response = "You can’t spray graffiti here yet, it’s too soon after your rival gang extended their own cultural dominance over it. Try again in {}.".format(
            ewutils.formatNiceTime(seconds=district_data.time_unlock,
                                   round_to_minutes=True))
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if district_data.all_neighbors_friendly():
        response = "What the hell are you doing, dude? You can’t put down any graffiti here, it’s been completely overrun by your rival gang. " \
                         "You can only spray districts that have at least one unfriendly neighbor, duh!"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    users_in_district = district_data.get_players_in_district(
        life_states=[ewcfg.life_state_enlisted],
        ignore_offline=True,
        pvp_only=True)

    allies_in_district = district_data.get_players_in_district(
        factions=[user_data.faction],
        life_states=[ewcfg.life_state_enlisted],
        ignore_offline=True,
        pvp_only=True)

    if len(users_in_district) > len(allies_in_district):
        response = "Holy shit, deal with your rival gangsters first! You can’t spray graffiti while they’re on the prowl!"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    mutations = user_data.get_mutations()

    slimes_spent = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)
    capture_discount = 1

    if ewcfg.mutation_id_lonewolf in mutations:
        if user_data.time_expirpvp > time_now:
            if len(users_in_district) == 1:
                capture_discount *= 0.8
        else:
            if len(users_in_district) == 0:
                capture_discount *= 0.8

    if ewcfg.mutation_id_patriot in mutations:
        capture_discount *= 0.8

    if slimes_spent == None:
        response = "How much slime do you want to spend on spraying graffiti in this district?"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if slimes_spent < 0:
        slimes_spent = user_data.slimes

    if slimes_spent > user_data.slimes:
        response = "You don't have that much slime, retard."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    num_lock = len(allies_in_district)
    if user_data.time_expirpvp < time_now:
        num_lock += 1

    if (district_data.controlling_faction not in [
            "", user_data.faction
    ]) or (district_data.capturing_faction not in ["", user_data.faction]):
        slimes_decap = min(district_data.capture_points,
                           int(slimes_spent / capture_discount))
        decap_resp = district_data.change_capture_points(
            progress=-slimes_decap, actor=user_data.faction, num_lock=num_lock)
        resp_cont.add_response_container(decap_resp)

        user_data.change_slimes(n=-slimes_decap * capture_discount,
                                source=ewcfg.source_spending)
        slimes_spent -= slimes_decap * capture_discount

    slimes_cap = min(
        district_data.max_capture_points - district_data.capture_points,
        int(slimes_spent / capture_discount))
    cap_resp = district_data.change_capture_points(progress=slimes_cap,
                                                   actor=user_data.faction,
                                                   num_lock=num_lock)
    resp_cont.add_response_container(cap_resp)

    user_data.change_slimes(n=-slimes_cap * capture_discount,
                            source=ewcfg.source_spending)

    # Flag the user for PvP
    user_data.time_expirpvp = ewutils.calculatePvpTimer(
        user_data.time_expirpvp, ewcfg.time_pvp_annex, True)

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

    return await resp_cont.post()
예제 #6
0
async def spar(cmd):
    resp = await ewcmd.start(cmd)
    time_now = int(time.time())
    response = ""

    if cmd.message.channel.name != ewcfg.channel_dojo:
        response = "You must go to the #{} to spar.".format(ewcfg.channel_dojo)

    elif cmd.mentions_count > 1:
        response = "One sparring partner at a time!"

    elif cmd.mentions_count == 1:
        member = cmd.mentions[0]

        if (member.id == cmd.message.author.id):
            response = "How do you expect to spar with yourself?"
        else:
            # The roles assigned to the author of this message.
            roles_map_user = ewutils.getRoleMap(cmd.message.author.roles)

            try:
                conn = ewutils.databaseConnect()
                cursor = conn.cursor()

                # Get killing player's info.
                user_data = EwUser(member=cmd.message.author,
                                   conn=conn,
                                   cursor=cursor)

                # Get target's info.
                sparred_data = EwUser(member=member, conn=conn, cursor=cursor)

                conn.commit()
            finally:
                cursor.close()
                conn.close()

            user_iskillers = ewcfg.role_copkillers in roles_map_user or ewcfg.role_copkiller in roles_map_user
            user_isrowdys = ewcfg.role_rowdyfuckers in roles_map_user or ewcfg.role_rowdyfucker in roles_map_user
            user_isdead = ewcfg.role_corpse in roles_map_user

            if user_data.stamina >= ewcfg.stamina_max:
                response = "You are too exhausted to train right now. Go get some grub!"
            elif sparred_data.stamina >= ewcfg.stamina_max:
                response = "{} is too exhausted to train right now. They need a snack!".format(
                    member.display_name)
            elif user_isdead == True:
                response = "The dead think they're too cool for conventional combat. Pricks."
            elif user_iskillers == False and user_isrowdys == False:
                # Only killers, rowdys, the cop killer, and the rowdy f****r can spar
                response = "Juveniles lack the backbone necessary for combat."
            else:
                was_juvenile = False
                was_sparred = False
                was_dead = False
                was_player_tired = False
                was_target_tired = False
                was_enemy = False
                duel = False

                roles_map_target = ewutils.getRoleMap(member.roles)

                #Determine if the !spar is a duel:
                weapon = None
                if user_data.weapon != None and user_data.weapon != "" and user_data.weapon == sparred_data.weapon:
                    weapon = ewcfg.weapon_map.get(user_data.weapon)
                    duel = True

                if ewcfg.role_corpse in roles_map_target:
                    # Target is already dead.
                    was_dead = True
                elif (user_data.time_lastspar + ewcfg.cd_spar) > time_now:
                    # player sparred too recently
                    was_player_tired = True
                elif (sparred_data.time_lastspar + ewcfg.cd_spar) > time_now:
                    # taret sparred too recently
                    was_target_tired = True
                elif ewcfg.role_juvenile in roles_map_target:
                    # Target is a juvenile.
                    was_juvenile = True

                elif (user_iskillers and
                      (ewcfg.role_copkillers in roles_map_target)) or (
                          user_isrowdys and
                          (ewcfg.role_rowdyfuckers in roles_map_target)):
                    # User can be sparred.
                    was_sparred = True
                elif (user_iskillers and
                      (ewcfg.role_rowdyfuckers in roles_map_target)) or (
                          user_isrowdys and
                          (ewcfg.role_copkillers in roles_map_target)):
                    # Target is a member of the opposing faction.
                    was_enemy = True

                #if the duel is successful
                if was_sparred:
                    weaker_player = sparred_data if sparred_data.slimes < user_data.slimes else user_data
                    stronger_player = sparred_data if user_data is weaker_player else user_data

                    # Flag the player for PvP
                    user_data.time_expirpvp = ewutils.calculatePvpTimer(
                        user_data.time_expirpvp,
                        (time_now + ewcfg.time_pvp_kill))

                    # Weaker player gains slime based on the slime of the stronger player.
                    possiblegain = (ewcfg.slimes_perspar_base *
                                    (2**weaker_player.slimelevel))
                    slimegain = possiblegain if (stronger_player.slimes /
                                                 10) > possiblegain else (
                                                     stronger_player.slimes /
                                                     10)
                    weaker_player.slimes += slimegain

                    #stamina drain for both players
                    user_data.stamina += ewcfg.stamina_perspar
                    sparred_data.stamina += ewcfg.stamina_perspar

                    # Bonus 50% slime to both players in a duel.
                    if duel:
                        weaker_player.slimes += int(slimegain / 2)
                        stronger_player.slimes += int(slimegain / 2)

                        if weaker_player.weaponskill < 5:
                            weaker_player.weaponskill += 1
                        elif (weaker_player.weaponskill +
                              1) < stronger_player.weaponskill:
                            weaker_player.weaponskill += 1

                        if stronger_player.weaponskill < 5:
                            stronger_player.weaponskill += 1

                    weaker_player.time_lastspar = time_now

                    try:
                        conn = ewutils.databaseConnect()
                        cursor = conn.cursor()

                        user_data.persist(conn=conn, cursor=cursor)
                        sparred_data.persist(conn=conn, cursor=cursor)

                        conn.commit()
                    finally:
                        cursor.close()
                        conn.close()

                    # Add the PvP flag role.
                    await ewutils.add_pvp_role(cmd=cmd)

                    # player was sparred with
                    if duel and weapon != None:
                        response = weapon.str_duel.format(
                            name_player=cmd.message.author.display_name,
                            name_target=member.display_name)
                    else:
                        response = '{} parries the attack. :knife: {}'.format(
                            member.display_name, ewcfg.emote_slime5)

                    #Notify if max skill is reached
                    if weapon != None:
                        if user_data.weaponskill == 5:
                            response += ' {} is a master of the {}.'.format(
                                cmd.message.author.display_name,
                                weapon.id_weapon)
                        if sparred_data.weaponskill == 5:
                            response += ' {} is a master of the {}.'.format(
                                member.display_name, weapon.id_weapon)

                else:
                    if was_dead:
                        # target is already dead
                        response = '{} is already dead.'.format(
                            member.display_name)
                    elif was_target_tired:
                        # target has sparred too recently
                        response = '{} is too tired to spar right now.'.format(
                            member.display_name)
                    elif was_player_tired:
                        # player has sparred too recently
                        response = 'You are too tired to spar right now.'
                    elif was_enemy:
                        # target and player are different factions
                        response = "You cannot spar with your enemies."
                    else:
                        #otherwise unkillable
                        response = '{} cannot spar now.'.format(
                            member.display_name)
    else:
        response = 'Your fighting spirit is appreciated, but ENDLESS WAR didn\'t understand that name.'

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
예제 #7
0
async def attack(cmd):
    resp = await ewcmd.start(cmd)
    time_now = int(time.time())
    response = ""

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

    if cmd.message.channel.name != ewcfg.channel_combatzone:
        response = "You must go to the #{} to commit gang violence.".format(
            ewcfg.channel_combatzone)
    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.stamina >= ewcfg.stamina_max:
        response = "You are too exhausted for gang violence right now. Go get some grub!"
    elif cmd.mentions_count == 1:
        # The roles assigned to the author of this message.
        roles_map_user = ewutils.getRoleMap(cmd.message.author.roles)

        # Get shooting player's info
        try:
            conn = ewutils.databaseConnect()
            cursor = conn.cursor()

            if user_data.slimelevel <= 0:
                user_data.slimelevel = 1

            # Flag the shooter for PvP no matter what happens next.
            user_data.time_expirpvp = ewutils.calculatePvpTimer(
                user_data.time_expirpvp, (time_now + ewcfg.time_pvp_kill))
            user_data.persist(conn=conn, cursor=cursor)

            # Get target's info.
            member = cmd.mentions[0]
            shootee_data = EwUser(member=member, conn=conn, cursor=cursor)

            conn.commit()
        finally:
            cursor.close()
            conn.close()

        miss = False
        crit = False
        strikes = 0

        # Shot player's assigned Discord roles.
        roles_map_target = ewutils.getRoleMap(member.roles)

        # Slime level data. Levels are in powers of 10.
        slimes_bylevel = int((10**user_data.slimelevel) / 10)
        slimes_spent = int(slimes_bylevel / 10)
        slimes_damage = int((slimes_bylevel / 5.0) *
                            (100 + (user_data.weaponskill * 5)) / 100.0)
        slimes_dropped = shootee_data.totaldamage

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

        user_iskillers = ewcfg.role_copkillers in roles_map_user or ewcfg.role_copkillers in roles_map_user
        user_isrowdys = ewcfg.role_rowdyfuckers in roles_map_user or ewcfg.role_rowdyfucker in roles_map_user

        # Add the PvP flag role.
        await ewutils.add_pvp_role(cmd=cmd)

        if ewcfg.role_copkiller in roles_map_target or ewcfg.role_rowdyfucker in roles_map_target:
            # 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.id_killer == user_data.id_user:
            # Don't allow the shootee to be shot by the same player twice.
            response = "You have already proven your superiority over {}.".format(
                member.display_name)

        elif time_now > shootee_data.time_expirpvp:
            # Target is not flagged for PvP.
            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 ewcfg.role_juvenile in roles_map_user:
                response = "Juveniles lack the moral fiber necessary for violence."
            else:
                response = "You lack the moral fiber necessary for violence."

        elif ewcfg.role_corpse in roles_map_target:
            # Target is already dead.
            response = "{} is already dead.".format(member.display_name)

        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)

        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

            role_corpse = cmd.roles_map[ewcfg.role_corpse]

            was_juvenile = False
            was_killed = False
            was_shot = False

            if (user_iskillers and
                (ewcfg.role_rowdyfuckers in roles_map_target)) or (
                    user_isrowdys and
                    (ewcfg.role_copkillers in roles_map_target)) or (
                        ewcfg.role_juvenile in roles_map_target):
                # User can be shot.
                if ewcfg.role_juvenile in roles_map_target:
                    was_juvenile = True

                was_shot = True

            if was_shot:
                #stamina drain
                user_data.stamina += ewcfg.stamina_pershot

                # Weaponized flavor text.
                weapon = ewcfg.weapon_map.get(user_data.weapon)
                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
                user_data.slimes -= slimes_spent

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

                # Don't allow attacking to cause you to go negative.
                if user_data.slimes < 0:
                    user_data.slimes = 0

                if slimes_damage >= shootee_data.slimes:
                    was_killed = True

                if was_killed:
                    # Move around slime as a result of the shot.
                    if shootee_data.slimes > 0:
                        if was_juvenile:
                            user_data.slimes += (slimes_dropped +
                                                 shootee_data.slimes)
                            user_data.slimepoudrins += shootee_data.slimepoudrins
                        else:
                            market_data = EwMarket(
                                id_server=cmd.message.server.id)
                            coinbounty = int(
                                shootee_data.bounty /
                                (market_data.rate_exchange / 1000000.0))
                            user_data.slimecredit += coinbounty
                            user_data.slimes += int(slimes_dropped / 2)
                            user_data.slimepoudrins += shootee_data.slimepoudrins
                            boss_slimes += int(slimes_dropped / 2)

                    # Player was killed.
                    shootee_data.totaldamage += shootee_data.slimes
                    shootee_data.slimes = 0
                    shootee_data.slimepoudrins = 0
                    shootee_data.id_killer = user_data.id_user
                    shootee_data.bounty = 0

                    if weapon != None:
                        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 += "\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
                    else:
                        response = "{name_target} is hit!!\n\n{name_target} has died.".format(
                            name_target=member.display_name)
                        shootee_data.trauma = ""

                    #adjust kills bounty
                    user_data.kills += 1
                    user_data.bounty += int((shootee_data.bounty / 2) +
                                            (shootee_data.totaldamage / 4))

                    # Give a bonus to the player's weapon skill for killing a stronger player.
                    if shootee_data.slimelevel > user_data.slimelevel:
                        user_data.weaponskill += 1

                else:
                    # A non-lethal blow!
                    shootee_data.slimes -= slimes_damage
                    shootee_data.totaldamage += 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))
                    else:
                        if miss:
                            response = "{} is unharmed.".format(
                                member.display_name)
                        else:
                            response = "{} is hit!!".format(
                                member.display_name)
            else:
                response = 'ENDLESS WAR finds this betrayal stinky. He will not allow you to slaughter {}.'.format(
                    member.display_name)

            # Level up the player if appropriate.
            new_level = len(str(int(user_data.slimes)))
            if new_level > user_data.slimelevel:
                response += "\n\n{} has been empowered by slime and is now a level {} slimeboi!".format(
                    cmd.message.author.display_name, new_level)
                user_data.slimelevel = new_level

            # 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

            # Persist every users' data.
            try:
                conn = ewutils.databaseConnect()
                cursor = conn.cursor()

                user_data.persist(conn=conn, cursor=cursor)
                shootee_data.persist(conn=conn, cursor=cursor)

                if boss_member != None:
                    boss_data = EwUser(member=boss_member,
                                       conn=conn,
                                       cursor=cursor)
                    boss_data.slimes += boss_slimes
                    boss_data.persist(conn=conn, cursor=cursor)

                conn.commit()
            finally:
                cursor.close()
                conn.close()

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

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
예제 #8
0
async def haunt(cmd):
    time_now = int(time.time())
    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.guild.id)

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

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

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

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

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

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

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

                if time_now - haunted_data.time_lastkill < (60 * 15):
                    haunt_power_multiplier *= 1.5  # wet hands

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

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

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

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

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

                user_data.time_lasthaunt = time_now
                user_data.busted = False

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

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

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

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

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

    # Send the response to the player.
    resp_cont.add_channel_response(cmd.message.channel.name, response)
    await resp_cont.post()
예제 #9
0
async def withdraw(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="withdraw")
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    try:
        conn = ewutils.databaseConnect()
        cursor = conn.cursor()

        user_data = EwUser(member=cmd.message.author, conn=conn, cursor=cursor)
        market_data = EwMarket(id_server=cmd.message.author.server.id,
                               conn=conn,
                               cursor=cursor)
    finally:
        cursor.close()
        conn.close()

    if market_data.clock >= 18 or market_data.clock < 6:
        response = ewcfg.str_exchange_closed
    else:
        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.slimecredit
            if value <= 0:
                value = None

        if value != None:

            rate_exchange = (market_data.rate_exchange / 1000000.0)

            credits = value
            slimes = int(value * rate_exchange)

            if value > user_data.slimecredit:
                response = "You don't have that many SlimeCoin to exchange."
            elif user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                # Limit frequency of withdrawals
                response = ewcfg.str_exchange_busy.format(action="withdraw")
            else:
                user_data.slimes += slimes
                user_data.slimecredit -= credits
                user_data.time_lastinvest = time_now
                market_data.slimes_casino -= slimes

                # Flag the user for PvP
                user_data.time_expirpvp = ewutils.calculatePvpTimer(
                    user_data.time_expirpvp,
                    (int(time.time()) + ewcfg.time_pvp_invest_withdraw))

                response = "You exchange {credits:,} SlimeCoin for {slimes:,} slime.".format(
                    credits=credits, slimes=slimes)

                # Level up the player if appropriate.
                new_level = len(str(int(user_data.slimes)))
                if new_level > user_data.slimelevel:
                    response += "\n\n{} has been empowered by slime and is now a level {} slimeboi!".format(
                        cmd.message.author.display_name, new_level)
                    user_data.slimelevel = new_level

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data.persist(conn=conn, cursor=cursor)
                    market_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()

                # Add the visible PvP flag role.
                await ewutils.add_pvp_role(cmd=cmd)

        else:
            response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                         action="withdraw")

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
예제 #10
0
async def haunt(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())
    response = ""

    if cmd.mentions_count > 1:
        response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
    elif cmd.mentions_count == 1:
        # A map of role names to Roles assigned to the current user.
        roles_map_user = ewutils.getRoleMap(cmd.message.author.roles)

        # Get the user and target data from the database.
        try:
            conn = ewutils.databaseConnect()
            cursor = conn.cursor()

            user_data = EwUser(member=cmd.message.author,
                               conn=conn,
                               cursor=cursor)

            member = cmd.mentions[0]
            haunted_data = EwUser(member=member, conn=conn, cursor=cursor)
        finally:
            cursor.close()
            conn.close()

        # A map of role names to Roles assigned to the targeted user.
        roles_map_target = ewutils.getRoleMap(member.roles)

        if ewcfg.role_corpse not in roles_map_user:
            # Only dead players can haunt.
            response = "You can't haunt now. Try {}.".format(ewcfg.cmd_suicide)
        elif cmd.message.channel.name != ewcfg.channel_sewers:
            # Allowed only from the-sewers.
            response = "You must haunt from #{}.".format(ewcfg.channel_sewers)
        elif ewcfg.role_copkiller in roles_map_target or ewcfg.role_rowdyfucker in roles_map_target:
            # Disallow haunting of generals.
            response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
        elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
            # Disallow haunting if the user has haunted too recently.
            response = "You're being a little TOO spooky lately, don't you think?"
        elif time_now > haunted_data.time_expirpvp:
            # Require the target to be flagged for PvP
            response = "{} is not mired in the ENDLESS WAR right now.".format(
                member.display_name)
        elif ewcfg.role_corpse in roles_map_target:
            # Dead players can't be haunted.
            response = "{} is already dead.".format(member.display_name)
        elif ewcfg.role_rowdyfuckers in roles_map_target or ewcfg.role_copkillers in roles_map_target or ewcfg.role_juvenile in roles_map_target:
            # Target can be haunted by the player.
            haunted_slimes = int(haunted_data.slimes / ewcfg.slimes_hauntratio)
            if haunted_slimes > ewcfg.slimes_hauntmax:
                haunted_slimes = ewcfg.slimes_hauntmax

            haunted_data.slimes -= haunted_slimes
            user_data.slimes -= haunted_slimes
            user_data.time_expirpvp = ewutils.calculatePvpTimer(
                user_data.time_expirpvp, (time_now + ewcfg.time_pvp_haunt))
            user_data.time_lasthaunt = time_now

            # Persist changes to the database.
            try:
                conn = ewutils.databaseConnect()
                cursor = conn.cursor()

                user_data.persist(conn=conn, cursor=cursor)
                haunted_data.persist(conn=conn, cursor=cursor)

                conn.commit()
            finally:
                cursor.close()
                conn.close()

            response = "{} has been haunted by a discontent corpse! Slime has been lost!".format(
                member.display_name)
        else:
            # Some condition we didn't think of.
            response = "You cannot haunt {}.".format(member.display_name)
    else:
        # No mentions, or mentions we didn't understand.
        response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

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