Beispiel #1
0
    def change_capture_lock(self, progress):
        resp_cont = ewutils.EwResponseContainer(id_server=self.id_server)

        progress_before = self.time_unlock

        self.time_unlock += progress

        if self.time_unlock < 0:
            self.time_unlock == 0

        progress_after = self.time_unlock

        if (progress_after // ewcfg.capture_lock_milestone) != (
                progress_before // ewcfg.capture_lock_milestone):
            time_mins = ewutils.formatNiceTime(seconds=progress_after,
                                               round_to_minutes=True)
            if progress < 0:
                if progress_before >= 15 * 60 >= progress_after:
                    message = "{district} will unlock for capture in {time}.".format(
                        district=ewcfg.id_to_poi[self.name].str_name,
                        time=time_mins)
                    channels = ewcfg.hideout_channels

                    for ch in channels:
                        resp_cont.add_channel_response(channel=ch,
                                                       response=message)

                elif progress_before >= 5 * 60 >= progress_after:
                    message = "{district} will unlock for capture in {time}.".format(
                        district=ewcfg.id_to_poi[self.name].str_name,
                        time=time_mins)
                    channels = ewcfg.hideout_channels

                    for ch in channels:
                        resp_cont.add_channel_response(channel=ch,
                                                       response=message)

                message = "{district} will unlock for capture in {time}.".format(
                    district=ewcfg.id_to_poi[self.name].str_name,
                    time=time_mins)

                channels = [ewcfg.id_to_poi[self.name].channel]

                for ch in channels:
                    resp_cont.add_channel_response(channel=ch,
                                                   response=message)

        if self.time_unlock == 0 and progress < 0:
            chip_cont = self.change_capture_points(progress=-1,
                                                   actor=ewcfg.actor_decay)
            resp_cont.add_response_container(chip_cont)

        return resp_cont
Beispiel #2
0
async def capture_progress(cmd):
    user_data = EwUser(member=cmd.message.author)
    response = ""

    poi = ewcfg.id_to_poi.get(user_data.poi)
    response += "**{}**: ".format(poi.str_name)

    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.controlling_faction != "":
        response += "{} control this district. ".format(
            district_data.controlling_faction.capitalize())
    elif district_data.capturing_faction != "":
        response += "{} are capturing this district. ".format(
            district_data.capturing_faction.capitalize())
    else:
        response += "Nobody has staked a claim to this district yet. ".format(
            district_data.controlling_faction.capitalize())

    response += "Current capture progress: {:.3g}%".format(
        100 * district_data.capture_points / district_data.max_capture_points)

    if district_data.time_unlock > 0:

        response += "\nThis district cannot be captured currently. It will unlock 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))
Beispiel #3
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
Beispiel #4
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()