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
def all_streets_taken(self): street_name_list = ewutils.get_street_list(self.name) if self.name == ewcfg.poi_id_rowdyroughhouse: return ewcfg.faction_rowdys elif self.name == ewcfg.poi_id_copkilltown: return ewcfg.faction_killers faction_list = [] for name in street_name_list: district_data = EwDistrict(id_server=self.id_server, district=name) faction_list.append(district_data.controlling_faction) if len(faction_list) > 0 and all(faction == faction_list[0] for faction in faction_list): return faction_list[0] else: return ""
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." if poi.is_district == True: response += " To take this district, you need to enter into the streets." district_data = EwDistrict(district=user_data.poi, id_server=user_data.id_server) if district_data.all_streets_taken() != "": response += " {} have a stranglehold over this entire district.".format(district_data.all_streets_taken().capitalize()) 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=poi.father_district) street_data = EwDistrict(id_server=user_data.id_server, district=user_data.poi) if street_data.controlling_faction != "": response += "{} control this street. ".format(street_data.controlling_faction.capitalize()) elif street_data.capturing_faction != "" and street_data.cap_side != street_data.capturing_faction: response += "{} are de-capturing this street. ".format(street_data.capturing_faction.capitalize()) elif street_data.capturing_faction != "": response += "{} are capturing this street. ".format(street_data.capturing_faction.capitalize()) else: response += "Nobody has staked a claim to this street yet. ".format(street_data.controlling_faction.capitalize()) num_streets = len(ewutils.get_street_list(poi.father_district)) response += "\n\n**Current influence: {:,}**\nMinimum influence: {:,}\nMaximum influence: {:,}\nPercentage to maximum influence: {:,}%".format(abs(street_data.capture_points), int(ewcfg.min_influence[district_data.property_class]/num_streets), int(ewcfg.limit_influence[district_data.property_class]/num_streets), round((abs(street_data.capture_points) * 100/(ewcfg.limit_influence[district_data.property_class]/num_streets)), 1)) if district_data.all_streets_taken() != "": response += "\n{} have a stranglehold over this entire district.".format( district_data.all_streets_taken().capitalize()) #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))
async def give_kingpins_slime_and_decay_capture_points(id_server): resp_cont_decay_loop = ewutils.EwResponseContainer(client = ewutils.get_client(), id_server = id_server) for kingpin_role in [ewcfg.role_rowdyfucker, ewcfg.role_copkiller]: kingpin = ewutils.find_kingpin(id_server = id_server, kingpin_role = kingpin_role) if kingpin is not None: total_slimegain = 0 for id_district in ewcfg.capturable_districts: district = EwDistrict(id_server = id_server, district = id_district) # if the kingpin is controlling this district give the kingpin slime based on the district's property class if district.controlling_faction == (ewcfg.faction_killers if kingpin.faction == ewcfg.faction_killers else ewcfg.faction_rowdys): poi = ewcfg.id_to_poi.get(id_district) num_streets = len(ewutils.get_street_list(poi.father_district)) father_district = EwDistrict(district=poi.father_district) slimegain = ewcfg.district_control_slime_yields[district.property_class]/num_streets # increase slimeyields by 10 percent per friendly neighbor friendly_mod = 1 + 0.1 * district.get_number_of_friendly_neighbors() total_slimegain += slimegain * friendly_mod kingpin.change_slimes(n = total_slimegain) kingpin.persist() ewutils.logMsg(kingpin_role + " just received %d" % total_slimegain + " slime for their captured districts.") # Decay capture points. for id_district in ewcfg.capturable_districts: district = EwDistrict(id_server = id_server, district = id_district) responses = district.decay_capture_points() resp_cont_decay_loop.add_response_container(responses) district.persist()
def change_capture_points(self, progress, actor, num_lock = 0): # actor can either be a faction or "decay" street_poi = ewcfg.id_to_poi.get(self.name) district_poi = ewcfg.id_to_poi.get(street_poi.father_district) num_districts = len(ewutils.get_street_list(street_poi.father_district)) max_capture = ewcfg.limit_influence[district_poi.property_class]/num_districts progress_percent_before = int(self.capture_points / max_capture * 100) self.capture_points += progress resp_cont_change_cp = ewutils.EwResponseContainer(client = ewutils.get_client(), id_server = self.id_server) # ensures that the value doesn't exceed the bounds if self.capture_points < 0: self.capture_points = 0 if self.cap_side == "" and actor != ewcfg.actor_decay: self.cap_side = actor if self.capture_points <= 0: self.cap_side = "" self.controlling_faction = "" #elif self.capture_points > self.max_capture_points: # self.capture_points = self.max_capture_points #where we're going we don't need roads progress_percent_after = int(self.capture_points / max_capture * 100) #if num_lock > 0 \ #and self.capture_points == max_capture \ #and progress > 0 \ #and self.property_class in ewcfg.capture_locks \ #and self.time_unlock == 0: # base_time_unlock = ewcfg.capture_locks.get(self.property_class) # responses = self.change_capture_lock(base_time_unlock + (num_lock - 1) * ewcfg.capture_lock_per_gangster) # resp_cont_change_cp.add_response_container(responses) if actor != ewcfg.actor_decay: self.capturing_faction = actor if self.controlling_faction == "" and progress > 0 and self.cap_side == actor and self.capture_points + progress > (ewcfg.min_influence[district_poi.property_class]/num_districts): self.controlling_faction = actor # display a message if it's reached a certain amount if (progress_percent_after // ewcfg.capture_milestone) != (progress_percent_before // ewcfg.capture_milestone): # if a progress milestone was reached if progress > 0: # if it was a positive change if ewcfg.capture_milestone <= progress_percent_after < ewcfg.capture_milestone * 2: # if its the first milestone message = "{faction} have started capturing {district}. Current progress: {progress}%".format( faction = self.capturing_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = [ewcfg.id_to_poi[self.name].channel] for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) else: # alert both factions of significant capture progress if progress_percent_after >= 30 > progress_percent_before: # if the milestone of 30% was just reached message = "{faction} are capturing {district}.".format( faction = self.capturing_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) if self.controlling_faction == ewcfg.faction_rowdys: channels = [ewcfg.channel_rowdyroughhouse] elif self.controlling_faction == ewcfg.faction_killers: channels = [ewcfg.channel_copkilltown] else: channels = ewcfg.hideout_channels for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) if self.controlling_faction != actor: # if it's not already owned by that faction message = "{faction} continue to capture {district}. Current progress: {progress}%".format( faction = self.capturing_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = [ewcfg.id_to_poi[self.name].channel] for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) else: message = "{faction} are renewing their grasp on {district}. Current control level: {progress}%".format( faction = self.capturing_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = [ewcfg.id_to_poi[self.name].channel] for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) else: # if it was a negative change if self.controlling_faction != "": # if the district is owned by a faction if progress_percent_after < 50 <= progress_percent_before: message = "{faction}' control of {district} is slipping.".format( faction = self.controlling_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = ewcfg.hideout_channels for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) elif progress_percent_after < 75 <= progress_percent_before and actor != ewcfg.actor_decay: message = "{faction} are de-capturing {district}.".format( faction = actor.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = ewcfg.hideout_channels for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) message = "{faction}' control of {district} has decreased. Remaining control level: {progress}%".format( faction = self.controlling_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = [ewcfg.id_to_poi[self.name].channel] for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) else: # if it's an uncontrolled district message = "{faction}' capture progress of {district} has decreased. Remaining progress: {progress}%".format( faction = self.capturing_faction.capitalize(), district = ewcfg.id_to_poi[self.name].str_name, progress = progress_percent_after ) channels = [ewcfg.id_to_poi[self.name].channel] for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = message) if progress < 0 and self.capture_points == 0: self.capturing_faction = "" # if capture_points is at its maximum value (or above), assign the district to the capturing faction #if self.capture_points > max_capture: # responses = self.change_ownership(self.capturing_faction, actor) # resp_cont_change_cp.add_response_container(responses) # if the district has decayed or been de-captured and it wasn't neutral anyway, make it neutral #elif self.capture_points == 0 and self.controlling_faction != "": # responses = self.change_ownership("", actor) # resp_cont_change_cp.add_response_container(responses) #return return resp_cont_change_cp