async def mine(cmd): market_data = EwMarket(id_server=cmd.message.author.guild.id) 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 fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) mutations = user_data.get_mutations() cosmetic_abilites = itm_utils.get_cosmetic_abilities(id_user=cmd.message.author.id, id_server=cmd.guild.id) time_now = int(time.time()) poi = poi_static.id_to_poi.get(user_data.poi) response = "" # Kingpins can't mine. if user_data.life_state == ewcfg.life_state_kingpin or user_data.life_state == ewcfg.life_state_grandfoe: return # ghosts cant mine (anymore) if user_data.life_state == ewcfg.life_state_corpse: return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You can't mine while you're dead. Try {}.".format(ewcfg.cmd_revive))) # Enlisted players only mine at certain times. if user_data.life_state == ewcfg.life_state_enlisted: if user_data.faction == ewcfg.faction_rowdys and (market_data.clock < 8 or market_data.clock > 17): return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "Rowdies only mine in the daytime. Wait for full daylight at 8am.".format(ewcfg.cmd_revive))) if user_data.faction == ewcfg.faction_killers and (market_data.clock < 20 and market_data.clock > 5): return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "Killers only mine under cover of darkness. Wait for nightfall at 8pm.".format(ewcfg.cmd_revive))) # Mine only in the mines. if cmd.message.channel.name in ewcfg.mining_channels: poi = poi_static.id_to_poi.get(user_data.poi) district_data = EwDistrict(district=poi.id_poi, id_server=user_data.id_server) 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 fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) if user_data.hunger >= user_data.get_hunger_max(): return await mismine(cmd, user_data, "exhaustion") # return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, "You've exhausted yourself from mining. You'll need some refreshment before getting back to work.")) else: printgrid = True hunger_cost_mod = ewutils.hunger_cost_mod(user_data.slimelevel) extra = hunger_cost_mod - int(hunger_cost_mod) # extra is the fractional part of hunger_cost_mod world_events = bknd_worldevent.get_world_events(id_server=cmd.guild.id) mining_type = ewcfg.mines_mining_type_map.get(user_data.poi) for id_event in world_events: if world_events.get(id_event) == ewcfg.event_type_minecollapse: event_data = EwWorldEvent(id_event=id_event) if int(event_data.event_props.get('id_user')) == user_data.id_user and event_data.event_props.get('poi') == user_data.poi: captcha = event_data.event_props.get('captcha').lower() tokens_lower = [] for token in cmd.tokens[1:]: tokens_lower.append(token.lower()) if captcha in tokens_lower: bknd_worldevent.delete_world_event(id_event=id_event) response = "You escape from the collapsing mineshaft." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) elif ewcfg.mutation_id_lightminer in mutations: bknd_worldevent.delete_world_event(id_event=id_event) response = "You nimbly step outside the collapse without even thinking about it." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) else: return await mismine(cmd, user_data, ewcfg.event_type_minecollapse) if user_data.poi not in juviecmdutils.mines_map: response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!" return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) elif user_data.id_server not in juviecmdutils.mines_map.get(user_data.poi): init_grid(user_data.poi, user_data.id_server) printgrid = True grid_cont = juviecmdutils.mines_map.get(user_data.poi).get(user_data.id_server) grid = grid_cont.grid grid_type = ewcfg.grid_type_by_mining_type.get(mining_type) if grid_type != grid_cont.grid_type: init_grid(user_data.poi, user_data.id_server) printgrid = True grid_cont = juviecmdutils.mines_map.get(user_data.poi).get(user_data.id_server) grid = grid_cont.grid # minesweeper = True # grid_multiplier = grid_cont.cells_mined ** 0.4 # flag = False mining_yield = get_mining_yield_by_grid_type(cmd, grid_cont) if type(mining_yield) == type(""): response = mining_yield if len(response) > 0: await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) if time_now > grid_cont.time_last_posted + 10: await print_grid(cmd) return if mining_yield == 0: user_data.hunger += ewcfg.hunger_permine * int(hunger_cost_mod) user_data.persist() # response = "This vein has already been mined dry." # await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) if printgrid: return await print_grid(cmd) else: return has_pickaxe = False if user_data.weapon >= 0: weapon_item = EwItem(id_item=user_data.weapon) weapon = static_weapons.weapon_map.get(weapon_item.item_props.get("weapon_type")) if (weapon.id_weapon == ewcfg.weapon_id_pickaxe or weapon.id_weapon == ewcfg.weapon_id_diamondpickaxe) and user_data.life_state != ewcfg.life_state_juvenile: has_pickaxe = True # if user_data.sidearm >= 0: # sidearm_item = EwItem(id_item=user_data.sidearm) # sidearm = static_weapons.weapon_map.get(sidearm_item.item_props.get("weapon_type")) # if sidearm.id_weapon == ewcfg.weapon_id_pickaxe: # has_pickaxe = True # Determine if an item is found. unearthed_item = False unearthed_item_amount = (random.randrange(3) + 5) # anywhere from 5-7 drops # juvies get items 4 times as often as enlisted players unearthed_item_chance = 1 / ewcfg.unearthed_item_rarity if user_data.life_state == ewcfg.life_state_juvenile: unearthed_item_chance *= 2 if has_pickaxe == True: unearthed_item_chance *= 1.5 if ewcfg.mutation_id_lucky in mutations: unearthed_item_chance *= 1.33 if ewcfg.cosmeticAbility_id_lucky in cosmetic_abilites: unearthed_item_chance *= 1.33 # event bonus for id_event in world_events: if world_events.get(id_event) == ewcfg.event_type_slimefrenzy: event_data = EwWorldEvent(id_event=id_event) if event_data.event_props.get('poi') == user_data.poi and int(event_data.event_props.get('id_user')) == user_data.id_user: mining_yield *= 2 if world_events.get(id_event) == ewcfg.event_type_poudrinfrenzy: event_data = EwWorldEvent(id_event=id_event) if event_data.event_props.get('poi') == user_data.poi and int(event_data.event_props.get('id_user')) == user_data.id_user: unearthed_item_chance = 1 unearthed_item_amount = 1 if random.random() < 0.05: id_event = create_mining_event(cmd) event_data = EwWorldEvent(id_event=id_event) if event_data.id_event == -1: return ewutils.logMsg("Error couldn't find world event with id {}".format(id_event)) if event_data.event_type == ewcfg.event_type_slimeglob: mining_yield *= 4 bknd_worldevent.delete_world_event(id_event=id_event) if event_data.time_activate <= time.time(): event_def = poi_static.event_type_to_def.get(event_data.event_type) if event_def == None: return ewutils.logMsg("Error, couldn't find event def for event type {}".format(event_data.event_type)) str_event_start = event_def.str_event_start if event_data.event_type == ewcfg.event_type_minecollapse: str_event_start = str_event_start.format(cmd=ewcfg.cmd_mine, captcha=ewutils.text_to_regional_indicator(event_data.event_props.get('captcha'))) await fe_utils.send_response(str_event_start, cmd) event_data.time_expir = time_now + 60 event_data.persist() str_event_start = "" if str_event_start != "": response += str_event_start + "\n" if random.random() < unearthed_item_chance: unearthed_item = True if unearthed_item == True: # If there are multiple possible products, randomly select one. item = random.choice(vendors.mine_results) if bknd_item.check_inv_capacity(user_data=user_data, item_type=item.item_type): item_props = itm_utils.gen_item_props(item) for creation in range(unearthed_item_amount): bknd_item.item_create( item_type=item.item_type, id_user=cmd.message.author.id, id_server=cmd.guild.id, item_props=item_props ) if unearthed_item_amount == 1: response += "You unearthed a {}! ".format(item.str_name) else: response += "You unearthed {} {}s! ".format(unearthed_item_amount, item.str_name) ewstats.change_stat(user=user_data, metric=ewcfg.stat_lifetime_poudrins, n=unearthed_item_amount) # ewutils.logMsg('{} has found {} {}(s)!'.format(cmd.message.author.display_name, item.str_name, unearthed_item_amount)) user_initial_level = user_data.slimelevel # Add mined slime to the user. slime_bylevel = ewutils.slime_bylevel(user_data.slimelevel) # mining_yield = math.floor((slime_bylevel / 10) + 1) # alternate_yield = math.floor(200 + slime_bylevel ** (1 / math.e)) # mining_yield = min(mining_yield, alternate_yield) controlling_faction = poi_utils.get_subzone_controlling_faction(user_data.poi, user_data.id_server) if controlling_faction != "" and controlling_faction == user_data.faction: mining_yield *= 2 if has_pickaxe == True: mining_yield *= 2 if user_data.life_state == ewcfg.life_state_juvenile: mining_yield *= 2 # trauma = se_static.trauma_map.get(user_data.trauma) # if trauma != None and trauma.trauma_class == ewcfg.trauma_class_slimegain: # mining_yield *= (1 - 0.5 * user_data.degradation / 100) mining_yield = max(0, round(mining_yield)) # Fatigue the miner. user_data.hunger += ewcfg.hunger_permine * int(hunger_cost_mod) if extra > 0: # if hunger_cost_mod is not an integer # there's an x% chance that an extra stamina is deducted, where x is the fractional part of hunger_cost_mod in percent (times 100) if random.randint(1, 100) <= extra * 100: user_data.hunger += ewcfg.hunger_permine levelup_response = user_data.change_slimes(n=mining_yield, source=ewcfg.source_mining) was_levelup = True if user_initial_level < user_data.slimelevel else False # Tell the player their slime level increased and/or they unearthed an item. if was_levelup: response += levelup_response user_data.persist() if printgrid: await print_grid(cmd) # gangsters don't need their roles updated if user_data.life_state == ewcfg.life_state_juvenile: await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author) else: return await mismine(cmd, user_data, "channel") # response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!" if len(response) > 0: await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def mismine(cmd, user_data, cause): time_now = int(time.time()) global last_mismined_times mismined = last_mismined_times.get(cmd.message.author.id) if mismined is None: mismined = {'time': time_now, 'count': 0} if time_now - mismined['time'] < 20: mismined['count'] += 1 else: # Reset counter. mismined['time'] = time_now mismined['count'] = 1 last_mismined_times[cmd.message.author.id] = mismined world_events = bknd_worldevent.get_world_events(id_server=cmd.guild.id) event_data = None captcha = None for id_event in world_events: if world_events.get(id_event) == ewcfg.event_type_minecollapse: event_data = EwWorldEvent(id_event=id_event) if int(event_data.event_props.get('id_user')) == user_data.id_user: mine_collapse = True captcha = event_data.event_props.get('captcha') if mismined[ 'count'] >= 11: # up to 6 messages can be buffered by discord and people have been dying unfairly because of that if cause == ewcfg.event_type_minecollapse: if event_data != None: bknd_worldevent.delete_world_event( id_event=event_data.id_event) else: return # Lose some slime last_mismined_times[cmd.message.author.id] = None # user_data.die(cause = ewcfg.cause_mining) accident_response = "You have lost an arm and a leg in a mining accident. Tis but a scratch." if random.randrange(4) == 0: accident_response = "Big John arrives just in time to save you from your mining accident!\nhttps://cdn.discordapp.com/attachments/431275470902788107/743629505876197416/mine2.jpg" else: mutations = user_data.get_mutations() 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." else: user_data.change_slimes(n=-(user_data.slimes * 0.5)) user_data.persist() await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, accident_response)) # await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author) # sewerchannel = fe_utils.get_channel(cmd.guild, ewcfg.channel_sewers) # await fe_utils.send_message(cmd.client, sewerchannel, "{} ".format(ewcfg.emote_slimeskull) + fe_utils.formatMessage(cmd.message.author, "You have died in a mining accident. {}".format(ewcfg.emote_slimeskull))) else: if cause == "exhaustion": response = "You've exhausted yourself from mining. You'll need some refreshment before getting back to work." elif cause == ewcfg.event_type_minecollapse: if captcha != None: response = "The mineshaft is collapsing around you!\nGet out of there! ({cmd} {captcha})".format( cmd=ewcfg.cmd_mine, captcha=ewutils.text_to_regional_indicator(captcha)) else: return else: response = "You can't mine in this channel. Go elsewhere." await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def handle_hourly_events(id_server=None): if id_server != None: client = ewutils.get_client() server = client.get_guild(id_server) time_current = EwMarket(id_server=id_server).clock events = bknd_event.get_world_events(id_server, True) for we_id, we_type in events.items(): if we_type in ewcfg.hourly_events: we = EwWorldEvent(id_event=we_id) if we.event_props.get("time") == str(time_current): # Handle brickshitting code if we_type == ewcfg.event_type_brickshit: brick_obj = EwItem( id_item=we.event_props.get("brick_id")) id_user = brick_obj.id_owner.replace("stomach", "") brick_user = EwUser(id_server=id_server, id_user=id_user) brick_member = server.get_member(user_id=int(id_user)) poi = poi_static.id_to_poi.get(brick_user.poi) channel_brick = fe_utils.get_channel( server, poi.channel) if brick_member: try: await fe_utils.send_message( client, channel_brick, fe_utils.formatMessage( brick_member, "UUUUUUUUUUGGGGGGGGGGGGHHHHHHHHHHH... OOOOOOOOOOOOOOOOOAAAAAAAAAAAAAAAHHHHH th-tunk. You just shit a brick. Congratulations?" )) brick_obj.id_owner = poi.id_poi brick_obj.item_props[ 'furniture_name'] = 'brick' brick_obj.persist() except: ewutils.logMsg( "failed to shit brick on user {}".format( brick_member.id)) else: bknd_event.delete_world_event(we_id) # Handle alarm clock code elif we_type == ewcfg.event_type_alarmclock: clock_obj = EwItem( id_item=we.event_props.get("clock_id")) if "decorate" in clock_obj.id_owner: isFurnished = True clock_user = clock_obj.id_owner.replace("decorate", "") clock_member = server.get_member(user_id=clock_user) if clock_member != None: clock_player = EwUser(member=clock_member) if (isFurnished == False or ("apt" in clock_player.poi and clock_player.visiting == "empty")) and clock_member: try: await fe_utils.send_message( client, clock_member, fe_utils.formatMessage( clock_member, "BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP BLAAAP" )) except: ewutils.logMsg( "failed to send alarm to user {}". format(clock_member.id))