async def remove_user_overwrites(cmd): if not cmd.message.author.guild_permissions.administrator: return server = cmd.guild client = ewutils.get_client() for poi in ewcfg.poi_list: searched_channel = poi.channel channel = ewutils.get_channel(server, searched_channel) if channel == None: # Second try channel = ewutils.get_channel(server, searched_channel) if channel == None: continue # print('{} overwrites: {}'.format(poi.id_poi, channel.overwrites)) for tuple in channel.overwrites: # print('tuplevar: {}'.format(tuple) + '\n\n') if tuple not in server.roles: member = tuple print('removed overwrite in {} for {}'.format(channel, member)) for i in range(ewcfg.permissions_tries): await channel.set_permissions(member, overwrite=None) response = "DEBUG: ALL USER OVERWRITES DELETED." return await ewutils.send_message( client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
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) slimegain = ewcfg.district_control_slime_yields[poi.property_class] # 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()
async def rejuvenate(cmd): user_data = EwUser(member=cmd.message.author) if user_data.life_state == ewcfg.life_state_shambler and user_data.poi != ewcfg.poi_id_oozegardens: response = "You lack the higher brain functions required to {}.".format(cmd.tokens[0]) return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) elif user_data.life_state == ewcfg.life_state_shambler and user_data.poi == ewcfg.poi_id_oozegardens: response = "You decide to change your ways and become one of the Garden Gankers in order to overthrow your old master." await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) await asyncio.sleep(5) user_data = EwUser(member=cmd.message.author) user_data.life_state = ewcfg.life_state_juvenile user_data.degradation = 0 #user_data.gvs_currency = 0 ewutils.moves_active[user_data.id_user] = 0 user_data.poi = ewcfg.poi_id_og_farms user_data.persist() client = ewutils.get_client() server = client.get_guild(user_data.id_server) member = server.get_member(user_data.id_user) base_poi_channel = ewutils.get_channel(cmd.message.guild, ewcfg.channel_og_farms) response = "You enter into Atomic Forest inside the farms of Ooze Gardens and are sterilized of the Modelovirus. Hortisolis gives you a big hug and says he's glad you've overcome your desire for vengeance in pursuit of deposing Downpour." await ewrolemgr.updateRoles(client=cmd.client, member=member) return await ewutils.send_message(cmd.client, base_poi_channel, ewutils.formatMessage(cmd.message.author, response)) else: pass
def get_players_in_district(self, min_level=0, max_level=math.inf, life_states=[], factions=[], min_slimes=-math.inf, max_slimes=math.inf): client = ewutils.get_client() server = client.get_server(self.id_server) if server == None: ewutils.logMsg("error: couldn't find server with id {}".format( self.id_server)) return [] players = ewutils.execute_sql_query( "SELECT {id_user} FROM users WHERE id_server = %s AND {poi} = %s". format(id_user=ewcfg.col_id_user, poi=ewcfg.col_poi), (self.id_server, self.name)) filtered_players = [] for player in players: if server.get_member(player[0]) != None: user_data = EwUser(id_user=player[0], id_server=self.id_server) if max_level >= user_data.slimelevel >= min_level \ and max_slimes >= user_data.slimes >= min_slimes \ and (len(life_states) == 0 or user_data.life_state in life_states) \ and (len(factions) == 0 or user_data.faction in factions): filtered_players.append(user_data.id_user) return filtered_players
async def hideRoleNames(cmd): id_server = cmd.guild.id client = ewutils.get_client() server = client.get_guild(id_server) roles_map = ewutils.getRoleMap(server.roles) role_counter = 0 ewutils.logMsg('Attempting to hide all role names...') for poi in ewcfg.poi_list: if poi.is_street: pass elif poi.is_district: pass elif poi.id_poi in [ ewcfg.poi_id_mine, ewcfg.poi_id_cv_mines, ewcfg.poi_id_tt_mines ]: pass else: continue # Slow down just a bit every 20 Role change attempts if role_counter >= 20: role_counter = 0 await asyncio.sleep(5) try: if poi.role in roles_map: role = roles_map[poi.role] if role.name != ewcfg.generic_role_name: role_counter += 1 await role.edit(name=ewcfg.generic_role_name) except: ewutils.logMsg('Failed to hide role name for {}'.format(poi.role)) try: if poi.major_role in roles_map: major_role = roles_map[poi.major_role] if major_role.name != ewcfg.generic_role_name: role_counter += 1 await major_role.edit(name=ewcfg.generic_role_name) except: ewutils.logMsg('Failed to hide role name for {}'.format( poi.major_role)) try: if poi.minor_role in roles_map: minor_role = roles_map[poi.minor_role] if minor_role.name != ewcfg.generic_role_name: role_counter += 1 await minor_role.edit(name=ewcfg.generic_role_name) except: ewutils.logMsg('Failed to hide role name for {}'.format( poi.minor_role)) ewutils.logMsg('Finished hiding roles!')
async def possess_weapon(cmd): user_data = EwUser(member = cmd.message.author) response = "" if user_data.life_state != ewcfg.life_state_corpse: response = "You have no idea what you're doing." elif not user_data.get_inhabitee(): response = "You're not inhabitting anyone right now." elif user_data.slimes >= (ewcfg.slimes_tomanifest + ewcfg.slimes_to_possess_weapon): # prevent ghosts from using so much antislime they can't manifest afterwards response = "You'll have to become stronger before you can perform occult arts of this level." else: server = ewutils.get_client().get_server(user_data.id_server) inhabitee_id = user_data.get_inhabitee() inhabitee_data = EwUser(id_user = inhabitee_id, id_server = user_data.id_server) inhabitee_member = server.get_member(inhabitee_id) inhabitee_name = inhabitee_member.display_name if inhabitee_data.weapon < 0: response = "{} is not wielding a weapon right now.".format(inhabitee_name) elif inhabitee_data.get_weapon_possession(): response = "{}'s weapon is already being possessed.".format(inhabitee_name) else: proposal_response = "You propose a trade to {}. " \ "You will possess their weapon to empower it, and in return they'll sacrifice half their slime to your name upon their next kill. " \ "Will they **{}** this exchange, or **{}** it?".format(inhabitee_name, ewcfg.cmd_accept, ewcfg.cmd_refuse) await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, proposal_response)) accepted = False try: msg = await cmd.client.wait_for_message(timeout = 30, author = inhabitee_member, check = ewutils.check_accept_or_refuse) if msg != None: if msg.content.lower() == ewcfg.cmd_accept: accepted = True elif message.content.lower() == ewcfg.cmd_refuse: accepted = False except: accepted = False if accepted: ewutils.execute_sql_query( "UPDATE inhabitations SET {empowered} = %s WHERE {id_fleshling} = %s AND {id_ghost} = %s".format( empowered = ewcfg.col_empowered, id_fleshling = ewcfg.col_id_fleshling, id_ghost = ewcfg.col_id_ghost, ), ( True, inhabitee_id, user_data.id_user, )) user_data.change_slimes(n = -ewcfg.slimes_to_possess_weapon, source = ewcfg.source_ghost_contract) user_data.persist() accepted_response = "You feel a metallic taste in your mouth as you sign {}'s spectral contract. You see them bind themselves to your weapon, which now bears their mark. It feels cold to the touch.".format(cmd.message.author.display_name) await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(inhabitee_member, accepted_response)) else: response = "You should've known better, why would anyone ever trust you?" if response: return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
async def move_inhabitants(self, id_poi = None): client = ewutils.get_client() inhabitants = self.get_inhabitants() if inhabitants: server = client.get_server(self.id_server) for ghost in inhabitants: ghost_data = EwUser(id_user = ghost, id_server = self.id_server) ghost_data.poi = id_poi ghost_data.time_lastenter = int(time.time()) ghost_data.persist() ghost_member = server.get_member(ghost) await ewrolemgr.updateRoles(client = client, member = ghost_member)
def get_players_in_district(self, min_level = 0, max_level = math.inf, life_states = [], factions = [], min_slimes = -math.inf, max_slimes = math.inf, ignore_offline = False, pvp_only = False ): client = ewutils.get_client() server = client.get_guild(self.id_server) if server == None: ewutils.logMsg("error: couldn't find server with id {}".format(self.id_server)) return [] time_now = int(time.time()) players = ewutils.execute_sql_query("SELECT {id_user}, {slimes}, {slimelevel}, {faction}, {life_state}, {time_expirpvp} FROM users WHERE id_server = %s AND {poi} = %s".format( id_user = ewcfg.col_id_user, slimes = ewcfg.col_slimes, slimelevel = ewcfg.col_slimelevel, faction = ewcfg.col_faction, life_state = ewcfg.col_life_state, poi = ewcfg.col_poi, time_expirpvp = ewcfg.col_time_expirpvp ),( self.id_server, self.name )) filtered_players = [] for player in players: id_user = player[0] slimes = player[1] slimelevel = player[2] faction = player[3] life_state = player[4] time_expirpvp = player[5] member = server.get_member(id_user) if member != None: if max_level >= slimelevel >= min_level \ and max_slimes >= slimes >= min_slimes \ and (len(life_states) == 0 or life_state in life_states) \ and (len(factions) == 0 or faction in factions) \ and not (ignore_offline and member.status == discord.Status.offline) \ and not (pvp_only and time_expirpvp < time_now and life_state != ewcfg.life_state_shambler): filtered_players.append(id_user) return filtered_players
def get_enemies_in_district(self, min_level = 0, max_level = math.inf, min_slimes = -math.inf, max_slimes = math.inf, scout_used = False, classes = None, ): client = ewutils.get_client() server = client.get_guild(self.id_server) if server == None: ewutils.logMsg("error: couldn't find server with id {}".format(self.id_server)) return [] enemies = ewutils.execute_sql_query("SELECT {id_enemy}, {slimes}, {level}, {enemytype}, {enemyclass} FROM enemies WHERE id_server = %s AND {poi} = %s AND {life_state} = 1".format( id_enemy = ewcfg.col_id_enemy, slimes = ewcfg.col_enemy_slimes, level = ewcfg.col_enemy_level, enemytype = ewcfg.col_enemy_type, enemyclass = ewcfg.col_enemy_class, poi = ewcfg.col_enemy_poi, life_state = ewcfg.col_enemy_life_state ),( self.id_server, self.name )) filtered_enemies = [] for enemy_data_column in enemies: fetched_id_enemy = enemy_data_column[0] # data from id_enemy column in enemies table fetched_slimes = enemy_data_column[1] # data from slimes column in enemies table fetched_level = enemy_data_column[2] # data from level column in enemies table fetched_type = enemy_data_column[3] # data from enemytype column in enemies table fetched_class = enemy_data_column[4] # data from enemyclass column in enemies table # Append the enemy to the list if it meets the requirements if max_level >= fetched_level >= min_level \ and max_slimes >= fetched_slimes >= min_slimes: if classes != None: if fetched_class in classes: filtered_enemies.append(fetched_id_enemy) else: filtered_enemies.append(fetched_id_enemy) # Don't show sandbags on !scout if scout_used and fetched_type == ewcfg.enemy_type_sandbag: filtered_enemies.remove(fetched_id_enemy) return filtered_enemies
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 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
async def begin_tutorial(member): user_data = EwUser(member = member) user_to_tutorial_state[user_data.id_user] = 0 scene = ewcfg.dungeon_tutorial[0] if scene.poi != None: user_data.poi = scene.poi if scene.life_state != None: user_data.life_state = scene.life_state user_data.persist() await ewrolemgr.updateRoles(client = ewutils.get_client(), member = member) response = format_tutorial_response(scene) poi_def = ewcfg.id_to_poi.get(user_data.poi) channels = [poi_def.channel] return await ewutils.post_in_channels(member.guild.id, ewutils.formatMessage(member, response), channels)
async def begin_cataclysm(user_data): player_data = EwPlayer(user_data.id_user) player_name = player_data.display_name client = ewutils.get_client() server = client.get_guild(user_data.id_server) auditorium_channel = ewutils.get_channel(server, 'auditorium') responses = [ "@everyone", "You point the sword towards the heavens, making your prescense known. ENDLESS WAR begins to shudder as he witnesses what's about to happen...", "Dark clouds begin to assemble in the skies above. Buildings around you begin to lose their color. The ground begins to shake, and a sense of dread envelops you as you grip the handle of the cold metal sword.", "All of the wicked things you've ever done have come back to haunt you. But you've made your bed, and now you have to lie in it.", "All of the sins and hatred you've brought forth will be spun into form. But you knew that, and you lept toward the darkness anyways.", "With blade in hand, you unleash an unparalleled wave of anguish and dread over the city of Neo Los Angeles City AKA Neo Milw-", "**The sword snaps in two.**", "Wow. Just wow. No seriously, what the f**k did you think was gonna happen? I swear, people get so hopped up when they hear about shit like the Negaslime, like the Endless Rock, that they delude themselves into thinking that everything in this game has to be some kind of history-altering cataclysm. Not this time, dumbass. You've endured countless acts of BDSM Sadomasochism, and for what? Well, I'll tell you plain and simple: It was all for f*****g **NOTHING**.", "Yeah yeah, you've been taken for a fool, everyone laugh at the dummy, and then we can all go home and pretend like this whole 'Swilldermuk' thing never happened, right? No, f**k you. You are gonna sit here and listen to me ramble off about how much of a f*****g retard you are. I swear to god, the nerve that some people have, to think that they can play this race to the bottom and intentionally let themselves get pranked, it's just absolutely *disgusting*. Tell me, {}, you've been pranked so much... Who exactly is it that you've pranked? Can you name even one person? I thought not.".format(player_name), "This whole event, it was all about NOT getting pranked, about one-upping your bros and seeing the stupid ass retarded look on their face when you blew a goddamn airhorn right in their eardrums. But you? You're just a pathetic whipping boy who turned this whole thing upside down. You probably think I'm being a bit mean here don't you? But let's be real, I'm just stating the God's honest truth when I say this: You enjoy pain. You enjoy being whipped and beaten. The way you get your rocks off is when someone deliberately humiliates you, all for their own personal gain. Consider all of this a wake up call.", "You thought that you could just get away with being a disgusting sexfiend in public. You thought that when all of this was over, you'd get a nice item for your uh, what were your efforts again? Oh that's right, standing around waiting for credence to build up and then opening your body to unspeakable acts of debauchery. No strategy. No brains. No soul. You're just as bad, if not worse than the people who cowardly stood inside their apartments, waiting for all this to blow over. And so here we are, at the end of the road, pontificating over how badly you f****d everything up. Where do we go from here?", "How are you gonna reconcile with the fact that all your scars were for naught? 'How am I supposed to COPE', you might be thinking? Well, for starters, stop being such a reprehensible freak. I'm dead serious. All those times you let people further and further drain your credence, it was just abysmal and agonizing to watch. You don't have to apologize to anyone, you don't have to be put in a cage or any of that shit, because God knows how much you'd f*****g *enjoy it*. Just remember this. On this day, April 7th, in the year of our lord, two thousand and twenty, you, {}, were f*****g cringey, embarassing, and above all retarded. Commit it to memory. Tell your grandkids about it one day, even. It'll be a story for the ages.".format(player_name), "Now, as for everyone else reading this: Do your part, do your DUTY, even, and !pointandlaugh at {}, while you still can. It's what they f*****g deserve.".format(player_name), ] for i in range(len(responses)): response = responses[i] if response == responses[1]: await ewutils.send_message(client, auditorium_channel, ewutils.formatMessage(player_data, response)) else: await ewutils.send_message(client, auditorium_channel, response) if i >= 7: await asyncio.sleep(20) else: await asyncio.sleep(10)
def get_enemies_in_district(self, min_level=0, max_level=math.inf, min_slimes=-math.inf, max_slimes=math.inf): client = ewutils.get_client() server = client.get_server(self.id_server) if server == None: ewutils.logMsg("error: couldn't find server with id {}".format( self.id_server)) return [] enemies = ewutils.execute_sql_query( "SELECT {id_enemy}, {slimes}, {level} FROM enemies WHERE id_server = %s AND {poi} = %s AND {life_state} = 1" .format(id_enemy=ewcfg.col_id_enemy, slimes=ewcfg.col_enemy_slimes, level=ewcfg.col_enemy_level, poi=ewcfg.col_enemy_poi, life_state=ewcfg.col_enemy_life_state), (self.id_server, self.name)) filtered_enemies = [] for enemy_data_column in enemies: fetched_id_enemy = enemy_data_column[ 0] # data from id_enemy column in enemies table fetched_slimes = enemy_data_column[ 1] # data from slimes column in enemies table fetched_level = enemy_data_column[ 2] # data from level column in enemies table # Append the enemy to the list if it meets the requirements if max_level >= fetched_level >= min_level \ and max_slimes >= fetched_slimes >= min_slimes: filtered_enemies.append(fetched_id_enemy) return filtered_enemies
async def event_tick(id_server): time_now = int(time.time()) resp_cont = ewutils.EwResponseContainer(id_server=id_server) try: data = ewutils.execute_sql_query( "SELECT {id_event} FROM world_events WHERE {time_expir} <= %s AND {time_expir} > 0 AND id_server = %s" .format( id_event=ewcfg.col_id_event, time_expir=ewcfg.col_time_expir, ), ( time_now, id_server, )) for row in data: try: event_data = EwWorldEvent(id_event=row[0]) event_def = ewcfg.event_type_to_def.get(event_data.event_type) response = event_def.str_event_end if event_def else "" if event_data.event_type == ewcfg.event_type_minecollapse: user_data = EwUser( id_user=event_data.event_props.get('id_user'), id_server=id_server) mutations = user_data.get_mutations() if user_data.poi == event_data.event_props.get('poi'): player_data = EwPlayer(id_user=user_data.id_user) response = "*{}*: You have lost an arm and a leg in a mining accident. Tis but a scratch.".format( player_data.display_name) if random.randrange(4) == 0: response = "*{}*: Big John arrives just in time to save you from your mining accident!\nhttps://cdn.discordapp.com/attachments/431275470902788107/743629505876197416/mine2.jpg".format( player_data.display_name) else: if ewcfg.mutation_id_lightminer in mutations: response = "*{}*: You instinctively jump out of the way of the collapsing shaft, not a scratch on you. Whew, really gets your blood pumping.".format( player_data.display_name) else: user_data.change_slimes( n=-(user_data.slimes * 0.5)) user_data.persist() # check if any void connections have expired, if so pop it and create a new one elif event_data.event_type == ewcfg.event_type_voidconnection: void_poi = ewcfg.id_to_poi.get(ewcfg.poi_id_thevoid) void_poi.neighbors.pop(event_data.event_props.get('poi'), "") create_void_connection(id_server) if len(response) > 0: poi = event_data.event_props.get('poi') channel = event_data.event_props.get('channel') if channel != None: # in shambaquarium the event happens in the user's DMs if event_data.event_type == ewcfg.event_type_shambaquarium: client = ewutils.get_client() channel = client.get_guild(id_server).get_member( int(channel)) resp_cont.add_channel_response(channel, response) elif poi != None: poi_def = ewcfg.id_to_poi.get(poi) if poi_def != None: resp_cont.add_channel_response( poi_def.channel, response) else: for ch in ewcfg.hideout_channels: resp_cont.add_channel_response(ch, response) delete_world_event(event_data.id_event) except: ewutils.logMsg( "Error in event tick for server {}".format(id_server)) await resp_cont.post() except: ewutils.logMsg("Error in event tick for server {}".format(id_server))
async def move_loop(self): response = "" poi_data = ewcfg.id_to_poi.get(self.poi) last_messages = [] while not ewutils.TERMINATE: district_data = EwDistrict(district = self.poi, id_server = self.id_server) if district_data.is_degraded(): return transport_line = ewcfg.id_to_transport_line[self.current_line] client = ewutils.get_client() resp_cont = ewutils.EwResponseContainer(client = client, id_server = self.id_server) if self.current_stop == transport_line.last_stop: self.current_line = transport_line.next_line self.persist() else: schedule = transport_line.schedule[self.current_stop] await asyncio.sleep(schedule[0]) for message in last_messages: try: await message.delete() pass except: ewutils.logMsg("Failed to delete message while moving transport {}.".format(transport_line.str_name)) self.current_stop = schedule[1] self.persist() stop_data = ewcfg.id_to_poi.get(self.current_stop) # announce new stop inside the transport # if stop_data.is_subzone: # stop_mother = ewcfg.id_to_poi.get(stop_data.mother_district) # response = "We have reached {}.".format(stop_mother.str_name) # else: response = "We have reached {}.".format(stop_data.str_name) next_line = transport_line if stop_data.is_transport_stop: response += " You may exit now." if stop_data.id_poi == transport_line.last_stop: next_line = ewcfg.id_to_transport_line[transport_line.next_line] response += " This {} will proceed on {}.".format(self.transport_type, next_line.str_name.replace("The", "the")) else: next_stop = ewcfg.id_to_poi.get(transport_line.schedule.get(stop_data.id_poi)[1]) if next_stop.is_transport_stop: # if next_stop.is_subzone: # stop_mother = ewcfg.id_to_poi.get(next_stop.mother_district) # response += " The next stop is {}.".format(stop_mother.str_name) # else: response += " The next stop is {}.".format(next_stop.str_name) resp_cont.add_channel_response(poi_data.channel, response) # announce transport has arrived at the stop if stop_data.is_transport_stop: response = "{} has arrived. You may board now.".format(next_line.str_name) resp_cont.add_channel_response(stop_data.channel, response) elif self.transport_type == ewcfg.transport_type_ferry: response = "{} sails by.".format(next_line.str_name) resp_cont.add_channel_response(stop_data.channel, response) elif self.transport_type == ewcfg.transport_type_blimp: response = "{} flies overhead.".format(next_line.str_name) resp_cont.add_channel_response(stop_data.channel, response) last_messages = await resp_cont.post()
async def weather_tick(id_server=None): if id_server != None: try: market_data = EwMarket(id_server=id_server) if market_data.weather == ewcfg.weather_sunny: exposed_pois = [] exposed_pois.extend(ewcfg.capturable_districts) exposed_pois.extend(ewcfg.outskirts) exposed_pois = tuple(exposed_pois) users = ewutils.execute_sql_query( "SELECT id_user FROM users WHERE id_server = %s AND {poi} IN %s AND {life_state} > 0" .format(poi=ewcfg.col_poi, life_state=ewcfg.col_life_state), (id_server, exposed_pois)) for user in users: try: user_data = EwUser(id_user=user[0], id_server=id_server) if user_data.life_state == ewcfg.life_state_kingpin: continue else: mutations = user_data.get_mutations() if ewcfg.mutation_id_airlock in mutations: user_data.hunger -= min(user_data.hunger, 5) except: ewutils.logMsg( "Error occurred in weather tick for server {}". format(id_server)) if market_data.weather != ewcfg.weather_bicarbonaterain: return exposed_pois = [] exposed_pois.extend(ewcfg.capturable_districts) exposed_pois.extend(ewcfg.outskirts) exposed_pois = tuple(exposed_pois) client = ewutils.get_client() server = client.get_guild(id_server) users = ewutils.execute_sql_query( "SELECT id_user FROM users WHERE id_server = %s AND {poi} IN %s AND {life_state} > 0" .format(poi=ewcfg.col_poi, life_state=ewcfg.col_life_state), (id_server, exposed_pois)) deathreport = "" resp_cont = ewutils.EwResponseContainer(id_server=id_server) for user in users: user_data = EwUser(id_user=user[0], id_server=id_server) if user_data.life_state == ewcfg.life_state_kingpin: continue user_poi = ewcfg.id_to_poi.get(user_data.poi) player_data = EwPlayer(id_server=user_data.id_server, id_user=user_data.id_user) protected = False slimeoid_protected = False if user_data.weapon >= 0: weapon_item = EwItem(id_item=user_data.weapon) if weapon_item.item_props.get( 'weapon_type') in ewcfg.rain_protection: protected = True cosmetics = ewitem.inventory( id_user=user_data.id_user, id_server=id_server, item_type_filter=ewcfg.it_cosmetic) for cosmetic in cosmetics: cosmetic_data = EwItem(id_item=cosmetic.get('id_item')) if cosmetic_data.item_props.get( 'id_cosmetic') in ewcfg.rain_protection: if cosmetic_data.item_props.get('adorned') == 'true': protected = True elif cosmetic_data.item_props.get( 'slimeoid') == 'true': slimeoid_protected = True if not protected: if user_data.life_state == ewcfg.life_state_shambler: slime_gain = (ewcfg.slimes_shambler - user_data.slimes) / 10 slime_gain = max(0, int(slime_gain)) user_data.change_slimes(n=slime_gain, source=ewcfg.source_weather) else: if random.random() < 0.01: user_data.degradation += 1 user_data.persist() if not slimeoid_protected: slimeoid_data = EwSlimeoid(id_user=user_data.id_user, id_server=id_server) if slimeoid_data.life_state != ewcfg.slimeoid_state_active: continue slimeoid_response = "" if random.randrange(10) < slimeoid_data.level: slimeoid_response = "*{uname}*: {slname} cries out in pain, as it's hit by the bicarbonate rain.".format( uname=player_data.display_name, slname=slimeoid_data.name) else: item_props = { 'context': ewcfg.context_slimeoidheart, 'subcontext': slimeoid_data.id_slimeoid, 'item_name': "Heart of {}".format(slimeoid_data.name), 'item_desc': "A poudrin-like crystal. If you listen carefully you can hear something that sounds like a faint heartbeat." } ewitem.item_create(id_user=str(user_data.id_user), id_server=id_server, item_type=ewcfg.it_item, item_props=item_props) slimeoid_data.die() slimeoid_data.persist() slimeoid_response = "*{uname}*: {slname} lets out a final whimper as it's dissolved by the bicarbonate rain. {skull} You quickly pocket its heart.".format( uname=player_data.display_name, slname=slimeoid_data.name, skull=ewcfg.emote_slimeskull) resp_cont.add_channel_response(user_poi.channel, slimeoid_response) for poi in exposed_pois: district_data = EwDistrict(district=poi, id_server=id_server) slimes_to_erase = district_data.slimes * 0.01 * ewcfg.weather_tick_length slimes_to_erase = max(slimes_to_erase, ewcfg.weather_tick_length * 1000) slimes_to_erase = min(district_data.slimes, slimes_to_erase) #round up or down, randomly weighted remainder = slimes_to_erase - int(slimes_to_erase) if random.random() < remainder: slimes_to_erase += 1 slimes_to_erase = int(slimes_to_erase) district_data.change_slimes(n=-slimes_to_erase, source=ewcfg.source_weather) district_data.persist() enemies = ewutils.execute_sql_query( "SELECT id_enemy FROM enemies WHERE id_server = %s AND {poi} IN %s AND {life_state} = %s AND {weathertype} != %s" .format(poi=ewcfg.col_enemy_poi, life_state=ewcfg.col_enemy_life_state, weathertype=ewcfg.col_enemy_weathertype), (id_server, exposed_pois, ewcfg.enemy_lifestate_alive, ewcfg.enemy_weathertype_rainresist)) for enemy in enemies: enemy_data = EwEnemy(id_enemy=enemy[0]) enemy_poi = ewcfg.id_to_poi.get(enemy_data.poi) slimes_to_erase = enemy_data.slimes * 0.01 * ewcfg.weather_tick_length slimes_to_erase = max(slimes_to_erase, ewcfg.weather_tick_length * 1000) slimes_to_erase = min(enemy_data.slimes, slimes_to_erase) #round up or down, randomly weighted remainder = slimes_to_erase - int(slimes_to_erase) if random.random() < remainder: slimes_to_erase += 1 slimes_to_erase = int(slimes_to_erase) enemy_data.change_slimes(n=-slimes_to_erase, source=ewcfg.source_weather) enemy_data.persist() response = "{name} takes {slimeloss:,} damage from the bicarbonate rain.".format( name=enemy_data.display_name, slimeloss=slimes_to_erase) resp_cont.add_channel_response(enemy_poi.channel, response) if enemy_data.slimes <= 0: ewhunting.delete_enemy(enemy_data) deathreport = "{skull} {name} is dissolved by the bicarbonate rain. {skull}".format( skull=ewcfg.emote_slimeskull, name=enemy_data.display_name) resp_cont.add_channel_response(enemy_poi.channel, deathreport) await resp_cont.post() except: ewutils.logMsg( "Error occurred in weather tick for server {}".format( id_server))
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()
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
def change_capture_points(self, progress, actor, num_lock = 0): # actor can either be a faction or "decay" district_poi = ewcfg.id_to_poi.get(self.name) invasion_response = "" max_capture = ewcfg.limit_influence[district_poi.property_class] progress_percent_before = int(self.capture_points / max_capture * 100) if actor == 'slimecorp': progress /= 3 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]): self.controlling_faction = actor invasion_response = "{} just captured {}.".format(self.capturing_faction.capitalize(), district_poi.str_name) # 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 = district_poi.str_name, progress = progress_percent_after ) channels = [district_poi.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 = district_poi.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 = [district_poi.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 = district_poi.str_name, progress = progress_percent_after ) channels = [district_poi.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 = district_poi.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 = district_poi.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 = district_poi.str_name, progress = progress_percent_after ) channels = [district_poi.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 = district_poi.str_name, progress = progress_percent_after ) channels = [district_poi.channel] if invasion_response != "": for ch in channels: resp_cont_change_cp.add_channel_response(channel = ch, response = invasion_response) 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
async def change_ownership( self, new_owner, actor, client=None): # actor can either be a faction, "decay", or "init" factions = ["", ewcfg.faction_killers, ewcfg.faction_rowdys] if new_owner in factions: server = ewcfg.server_list[self.id_server] channel_str = ewcfg.id_to_poi[self.name].channel channel = ewutils.get_channel(server=server, channel_name=channel_str) if channel is not None and channel.topic: # tests if the topic is neither None nor empty initialized = False # initialize channel topic control statuses for faction in factions: if ewcfg.control_topics[faction] in channel.topic: initialized = True if not initialized: new_topic = channel.topic + " " + ewcfg.control_topics[ new_owner] # replace the the string of the previously controlling faction with that of the new one. else: new_topic = channel.topic.replace( ewcfg.control_topics[self.controlling_faction], ewcfg.control_topics[new_owner]) if client is None: client = ewutils.get_client() if client is not None: await client.edit_channel(channel=channel, topic=new_topic) if self.controlling_faction != new_owner: # if the controlling faction actually changed if new_owner != "": # if it was captured by a faction instead of being de-captured or decayed await ewutils.post_in_channels( id_server=self.id_server, message="{faction} just captured {district}.".format( faction=self.capturing_faction.capitalize(), district=ewcfg.id_to_poi[self.name].str_name), channels=[ewcfg.id_to_poi[self.name].channel] + ewcfg.hideout_channels) else: # successful de-capture or full decay if actor != ewcfg.actor_decay: await ewutils.post_in_channels( id_server=self.id_server, message= "{faction} just wrested control over {district} from the {other_faction}." .format( faction=actor.capitalize(), district=ewcfg.id_to_poi[self.name].str_name, other_faction=self. controlling_faction # the faction that just lost control ), channels=[ewcfg.id_to_poi[self.name].channel] + ewcfg.hideout_channels) self.controlling_faction = new_owner self.persist()
def change_capture_points( self, progress, actor): # actor can either be a faction or "decay" progress_percent_before = int(self.capture_points / self.max_capture_points * 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 elif self.capture_points > self.max_capture_points: self.capture_points = self.max_capture_points progress_percent_after = int(self.capture_points / self.max_capture_points * 100) # 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 < 20 <= 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 < 50 <= 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.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'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 capture_points is at its maximum value (or above), assign the district to the capturing faction if self.capture_points == self.max_capture_points and self.controlling_faction != actor: 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 resp_cont_change_cp
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?" else: haunted_data = None member = None if cmd.mentions_count == 0: haunted_data = EwUser(id_user = cmd.tokens[1], id_server = cmd.message.server.id) server = ewutils.get_client().get_server(cmd.message.server.id) member = server.get_member(cmd.tokens[1]) 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.message.server.id) 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 time_now > haunted_data.time_expirpvp and not (target_is_shambler or target_is_inhabitted): # 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, 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("<.+>" 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 += "." 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()