Exemplo n.º 1
0
	def decay_capture_points(self):
		resp_cont_decay = ewutils.EwResponseContainer(client = ewutils.get_client(), id_server = self.id_server)
		if self.capture_points > 0:
				#and self.time_unlock == 0:

			neighbors = ewcfg.poi_neighbors[self.name]
			all_neighbors_friendly = self.all_neighbors_friendly()

			decay = -math.ceil(ewcfg.limit_influence_a / (ewcfg.ticks_per_day * ewcfg.decay_modifier))
			#decay = -math.ceil(ewcfg.max_capture_points_a / (ewcfg.ticks_per_day * ewcfg.decay_modifier))

			slimeoids = ewutils.get_slimeoids_in_poi(poi = self.name, id_server = self.id_server, sltype = ewcfg.sltype_nega)
			
			nega_present = len(slimeoids) > 0

			poi = ewcfg.id_to_poi.get(self.name)
			father_poi = ewcfg.id_to_poi.get(poi.father_district)
			num_districts = len(ewutils.get_street_list(poi.father_district))

			if nega_present:
				decay *= 1.5
			if self.capture_points + (decay * 3) > (ewcfg.limit_influence[father_poi.property_class])/num_districts:
				decay *= 3

			if self.controlling_faction == "" or (not self.all_neighbors_friendly() and self.capture_points > ewcfg.limit_influence[father_poi.property_class]/num_districts) or nega_present:  # don't decay if the district is completely surrounded by districts controlled by the same faction
				# reduces the capture progress at a rate with which it arrives at 0 after 1 in-game day
				#if (self.capture_points + int(decay) < ewcfg.min_influence[self.property_class] and self.capture_points >= ewcfg.min_influence[self.property_class]) and not nega_present and self.controlling_faction != "":
				#	responses = self.change_capture_points(self.capture_points - ewcfg.min_influence[self.property_class], ewcfg.actor_decay)
				#else:
				responses = self.change_capture_points(int(decay), ewcfg.actor_decay)
				resp_cont_decay.add_response_container(responses)

		#if self.capture_points < 0:
		#	self.capture_points = 0

		if self.capture_points <= 0:
			if self.controlling_faction != "":  # if it was owned by a faction

				message = "The {faction} have lost control over {district} because of sheer negligence.".format(
					faction = self.controlling_faction,
					district = ewcfg.id_to_poi[self.name].str_name
				)
				channels = [ewcfg.id_to_poi[self.name].channel] + ewcfg.hideout_channels
				for ch in channels:
					resp_cont_decay.add_channel_response(channel = ch, response = message)
			responses = self.change_ownership("", ewcfg.actor_decay)
			resp_cont_decay.add_response_container(responses)
			self.capturing_faction = ""
		return resp_cont_decay
Exemplo n.º 2
0
    def decay_capture_points(self):
        resp_cont_decay = ewutils.EwResponseContainer(
            client=ewutils.get_client(), id_server=self.id_server)
        if self.capture_points > 0:

            neighbors = ewcfg.poi_neighbors[self.name]
            all_neighbors_friendly = self.all_neighbors_friendly()

            decay = -math.ceil(ewcfg.max_capture_points_a /
                               (ewcfg.ticks_per_day * ewcfg.decay_modifier))

            slimeoids = ewutils.get_slimeoids_in_poi(poi=self.name,
                                                     id_server=self.id_server,
                                                     sltype=ewcfg.sltype_nega)

            nega_present = len(slimeoids) > 0

            if nega_present:
                decay *= 1.5

            if self.controlling_faction == "" or not all_neighbors_friendly or nega_present:  # don't decay if the district is completely surrounded by districts controlled by the same faction
                # reduces the capture progress at a rate with which it arrives at 0 after 1 in-game day
                responses = self.change_capture_points(int(decay),
                                                       ewcfg.actor_decay)
                resp_cont_decay.add_response_container(responses)

        if self.capture_points < 0:
            self.capture_points = 0

        if self.capture_points == 0:
            if self.controlling_faction != "":  # if it was owned by a faction

                message = "The {faction} have lost control over {district} because of sheer negligence.".format(
                    faction=self.controlling_faction,
                    district=ewcfg.id_to_poi[self.name].str_name)
                channels = [ewcfg.id_to_poi[self.name].channel
                            ] + ewcfg.hideout_channels
                for ch in channels:
                    resp_cont_decay.add_channel_response(channel=ch,
                                                         response=message)
            responses = self.change_ownership("", ewcfg.actor_decay)
            resp_cont_decay.add_response_container(responses)
            self.capturing_faction = ""

        return resp_cont_decay
Exemplo n.º 3
0
async def capture_tick(id_server):
	# the variables might apparently be accessed before assignment if i didn't declare them here
	cursor = None
	conn_info = None

	resp_cont_capture_tick = ewutils.EwResponseContainer(client = ewutils.get_client(), id_server = id_server)

	all_districts = ewcfg.capturable_districts


	if len(all_districts) > 0:  # if all_districts isn't empty
		server = ewcfg.server_list[id_server]
		time_old = time.time()

		for district in all_districts:
			district_name = district
			dist = EwDistrict(id_server = id_server, district = district_name)

			if dist.time_unlock > 0 and not dist.all_neighbors_friendly():
				responses = dist.change_capture_lock(progress = -ewcfg.capture_tick_length)
				resp_cont_capture_tick.add_response_container(responses)
				dist.persist()

			if dist.time_unlock > 0:
				continue

			# no more automatic capping
			continue

			controlling_faction = dist.controlling_faction

			gangsters_in_district = dist.get_players_in_district(min_slimes = ewcfg.min_slime_to_cap, life_states = [ewcfg.life_state_enlisted], ignore_offline = True)
					

			slimeoids = ewutils.get_slimeoids_in_poi(poi = district_name, id_server = id_server, sltype = ewcfg.sltype_nega)
			
			nega_present = len(slimeoids) > 0
#			if nega_present:
#				continue

			# the faction that's actively capturing the district this tick
			# if no players are present, it's None, if only players of one faction (ignoring juvies and ghosts) are,
			# it's the faction's name, i.e. 'rowdys' or 'killers', and if both are present, it's 'both'
			faction_capture = None

			# how much progress will be made. is higher the more people of one faction are in a district, and is 0 if both teams are present
			capture_speed = 0

			# number of players actively capturing
			num_capturers = 0

			dc_stat_increase_list = []

			# checks if any players are in the district and if there are only players of the same faction, i.e. progress can happen
			for player in gangsters_in_district:
				player_id = player
				user_data = EwUser(id_user = player_id, id_server = id_server)
				player_faction = user_data.faction

				mutations = user_data.get_mutations()

				try:
					player_online = server.get_member(player_id).status != discord.Status.offline
				except:
					player_online = False

				#ewutils.logMsg("Online status checked. Time elapsed: %f" % (time.time() - time_old) + " Server: %s" % id_server + " Player: %s" % player_id + " Status: %s" % ("online" if player_online else "offline"))

				if player_online:
					if faction_capture not in [None, player_faction]:  # if someone of the opposite faction is in the district
						faction_capture = 'both'  # standstill, gang violence has to happen
						capture_speed = 0
						num_capturers = 0
						dc_stat_increase_list.clear()

					else:  # if the district isn't already controlled by the player's faction and the capture isn't halted by an enemy
						faction_capture = player_faction
						player_capture_speed = 1
						if ewcfg.mutation_id_lonewolf in mutations and len(gangsters_in_district) == 1:
							player_capture_speed *= 2
						if ewcfg.mutation_id_patriot in mutations:
							player_capture_speed *= 2
							

						capture_speed += player_capture_speed
						num_capturers += 1
						dc_stat_increase_list.append(player_id)


			if faction_capture not in ['both', None]:  # if only members of one faction is present
				if district_name in ewcfg.capturable_districts:
					friendly_neighbors = dist.get_number_of_friendly_neighbors()
					if dist.all_neighbors_friendly():
						capture_speed = 0
					elif dist.controlling_faction == faction_capture:
						capture_speed *= 1 + 0.1 * friendly_neighbors
					else:
						capture_speed /= 1 + 0.1 * friendly_neighbors

					capture_progress = dist.capture_points

					if faction_capture != dist.capturing_faction:
						capture_progress *= -1

					capture_speed *= ewcfg.baseline_capture_speed


					if dist.capture_points < dist.max_capture_points:
						for stat_recipient in dc_stat_increase_list:
							ewstats.change_stat(
								id_server = id_server,
								id_user = stat_recipient,
								metric = ewcfg.stat_capture_points_contributed,
								n = ewcfg.capture_tick_length * capture_speed
							)

					if faction_capture == dist.capturing_faction:  # if the faction is already in the process of capturing, continue
						responses = dist.change_capture_points(ewcfg.capture_tick_length * capture_speed, faction_capture, num_capturers)
						resp_cont_capture_tick.add_response_container(responses)

					elif dist.capture_points == 0 and dist.controlling_faction == "":  # if it's neutral, start the capture
						responses =  dist.change_capture_points(ewcfg.capture_tick_length * capture_speed, faction_capture, num_capturers)
						resp_cont_capture_tick.add_response_container(responses)

						dist.capturing_faction = faction_capture

					# lower the enemy faction's progress to revert it to neutral (or potentially get it onto your side without becoming neutral first)
					else:  # if the (de-)capturing faction is not in control
						responses =  dist.change_capture_points(-(ewcfg.capture_tick_length * capture_speed * ewcfg.decapture_speed_multiplier), faction_capture)
						resp_cont_capture_tick.add_response_container(responses)

					dist.persist()