async def mine(cmd): market_data = EwMarket(id_server=cmd.message.author.server.id) user_data = EwUser(member=cmd.message.author) # 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 cmd.client.send_message( cmd.message.channel, ewutils.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 cmd.client.send_message( cmd.message.channel, ewutils.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 cmd.client.send_message( cmd.message.channel, ewutils.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.channel_mines, ewcfg.channel_cv_mines, ewcfg.channel_tt_mines ]: if user_data.hunger >= ewutils.hunger_max_bylevel( user_data.slimelevel): return await cmd.client.send_message( cmd.message.channel, ewutils.formatMessage( cmd.message.author, "You've exhausted yourself from mining. You'll need some refreshment before getting back to work." )) else: # Determine if a poudrin is found. poudrin = False poudrinamount = 0 # juvies get poudrins 4 times as often as enlisted players poudrin_rarity = ewcfg.poudrin_rarity / ( 2 if user_data.life_state == ewcfg.life_state_juvenile else 1) poudrin_mined = random.randint(1, poudrin_rarity) if poudrin_mined == 1: poudrin = True poudrinamount = 1 if random.randint( 1, 3) != 1 else 2 # 33% chance of extra drop 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) user_data.change_slimes(n=mining_yield, source=ewcfg.source_mining) was_levelup = True if user_initial_level < user_data.slimelevel else False # Create and give slime poudrins for pdx in range(poudrinamount): item_id = ewitem.item_create( item_type=ewcfg.it_slimepoudrin, id_user=cmd.message.author.id, id_server=cmd.message.server.id, ) ewutils.logMsg( 'Created poudrin (item {}) for user (id {})'.format( item_id, cmd.message.author.id)) # Fatigue the miner. 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 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 user_data.persist() # Tell the player their slime level increased and/or a poudrin was found. if was_levelup or poudrin: response = "" if poudrin: if poudrinamount == 1: response += "You unearthed a slime poudrin! " elif poudrinamount == 2: response += "You unearthed two slime poudrins! " ewstats.change_stat(user=user_data, metric=ewcfg.stat_lifetime_poudrins, n=poudrinamount) ewutils.logMsg('{} has found {} poudrin(s)!'.format( cmd.message.author.display_name, poudrinamount)) if was_levelup: response += "You have been empowered by slime and are now a level {} slimeboi!".format( user_data.slimelevel) await cmd.client.send_message( cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) else: return await cmd.client.send_message( cmd.message.channel, ewutils.formatMessage(cmd.message.author, "You can't mine here. Go to the mines."))
async def attack(cmd): time_now = int(time.time()) response = "" deathreport = "" coinbounty = 0 user_data = EwUser(member=cmd.message.author) slimeoid = EwSlimeoid(member=cmd.message.author) weapon = ewcfg.weapon_map.get(user_data.weapon) if ewmap.channel_name_is_poi(cmd.message.channel.name) == False: response = "You can't commit violence from here." elif ewmap.poi_is_pvp(user_data.poi) == False: response = "You must go elsewhere to commit gang violence." elif cmd.mentions_count > 1: response = "One shot at a time!" elif cmd.mentions_count <= 0: response = "Your bloodlust is appreciated, but ENDLESS WAR didn't understand that name." elif user_data.hunger >= ewutils.hunger_max_bylevel(user_data.slimelevel): response = "You are too exhausted for gang violence right now. Go get some grub!" elif cmd.mentions_count == 1: # Get shooting player's info if user_data.slimelevel <= 0: user_data.slimelevel = 1 user_data.persist() # Get target's info. member = cmd.mentions[0] shootee_data = EwUser(member=member) shootee_slimeoid = EwSlimeoid(member=member) miss = False crit = False strikes = 0 slimes_spent = int(ewutils.slime_bylevel(user_data.slimelevel) / 20) slimes_damage = int( (slimes_spent * 4) * (100 + (user_data.weaponskill * 10)) / 100.0) if weapon is None: slimes_damage /= 2 # penalty for not using a weapon, otherwise fists would be on par with other weapons slimes_dropped = shootee_data.totaldamage + shootee_data.slimes #fumble_chance = (random.randrange(10) - 4) #if fumble_chance > user_data.weaponskill: #miss = True user_iskillers = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_killers user_isrowdys = user_data.life_state == ewcfg.life_state_enlisted and user_data.faction == ewcfg.faction_rowdys if shootee_data.life_state == ewcfg.life_state_kingpin: # Disallow killing generals. response = "He is hiding in his ivory tower and playing video games like a retard." elif (slimes_spent > user_data.slimes): # Not enough slime to shoot. response = "You don't have enough slime to attack. ({:,}/{:,})".format( user_data.slimes, slimes_spent) elif (time_now - user_data.time_lastkill) < ewcfg.cd_kill: # disallow kill if the player has killed recently response = "Take a moment to appreciate your last slaughter." elif shootee_data.poi != user_data.poi: response = "You can't reach them from where you are." elif ewmap.poi_is_pvp(shootee_data.poi) == False: response = "{} is not mired in the ENDLESS WAR right now.".format( member.display_name) elif user_iskillers == False and user_isrowdys == False: # Only killers, rowdys, the cop killer, and rowdy f****r can shoot people. if user_data.life_state == ewcfg.life_state_juvenile: response = "Juveniles lack the moral fiber necessary for violence." else: response = "You lack the moral fiber necessary for violence." elif (time_now - shootee_data.time_lastrevive) < ewcfg.invuln_onrevive: # User is currently invulnerable. response = "{} has died too recently and is immune.".format( member.display_name) elif shootee_data.life_state == ewcfg.life_state_corpse and user_data.ghostbust == True: # Attack a ghostly target was_busted = False #hunger drain user_data.hunger += ewcfg.hunger_pershot * ewutils.hunger_cost_mod( user_data.slimelevel) # Weaponized flavor text. randombodypart = ewcfg.hitzone_list[random.randrange( len(ewcfg.hitzone_list))] # Weapon-specific adjustments if weapon != None and weapon.fn_effect != None: # Build effect container ctn = EwEffectContainer(miss=miss, crit=crit, slimes_damage=slimes_damage, slimes_spent=slimes_spent, user_data=user_data, shootee_data=shootee_data) # Make adjustments weapon.fn_effect(ctn) # Apply effects for non-reference values miss = ctn.miss crit = ctn.crit slimes_damage = ctn.slimes_damage slimes_spent = ctn.slimes_spent strikes = ctn.strikes # user_data and shootee_data should be passed by reference, so there's no need to assign them back from the effect container. if miss: slimes_damage = 0 # Remove !revive invulnerability. user_data.time_lastrevive = 0 # Spend slimes, to a minimum of zero user_data.change_slimes( n=(-user_data.slimes if slimes_spent >= user_data.slimes else -slimes_spent), source=ewcfg.source_spending) # Damage stats ewstats.track_maximum(user=user_data, metric=ewcfg.stat_max_hitdealt, value=slimes_damage) ewstats.change_stat(user=user_data, metric=ewcfg.stat_lifetime_damagedealt, n=slimes_damage) # Remove repeat killing protection if. if user_data.id_killer == shootee_data.id_user: user_data.id_killer = "" if slimes_damage >= -shootee_data.slimes: was_busted = True if was_busted: # Move around slime as a result of the shot. user_data.change_slimes(n=ewutils.slime_bylevel( shootee_data.slimelevel), source=ewcfg.source_busting) coinbounty = int(shootee_data.bounty / ewcfg.slimecoin_exchangerate) user_data.change_slimecredit( n=coinbounty, coinsource=ewcfg.coinsource_bounty) ewstats.track_maximum(user=user_data, metric=ewcfg.stat_biggest_bust_level, value=shootee_data.slimelevel) # Player was busted. shootee_data.die(cause=ewcfg.cause_busted) response = "{name_target}\'s ghost has been **BUSTED**!!".format( name_target=member.display_name) deathreport = "Your ghost has been busted by {}. {}".format( cmd.message.author.display_name, ewcfg.emote_bustin) deathreport = "{} ".format( ewcfg.emote_bustin) + ewutils.formatMessage( member, deathreport) if coinbounty > 0: response += "\n\n SlimeCorp transfers {} SlimeCoin to {}\'s account.".format( str(coinbounty), cmd.message.author.display_name) #adjust busts ewstats.increment_stat(user=user_data, metric=ewcfg.stat_ghostbusts) else: # A non-lethal blow! shootee_data.change_slimes(n=slimes_damage, source=ewcfg.source_busting) damage = str(slimes_damage) if weapon != None: if miss: response = "{}".format( weapon.str_miss.format( name_player=cmd.message.author.display_name, name_target=member.display_name + "\'s ghost")) else: response = weapon.str_damage.format( name_player=cmd.message.author.display_name, name_target=member.display_name + "\'s ghost", hitzone=randombodypart, strikes=strikes) if crit: response += " {}".format( weapon.str_crit.format( name_player=cmd.message.author. display_name, name_target=member.display_name + "\'s ghost")) response += " {target_name} loses {damage} antislime!".format( target_name=(member.display_name + "\'s ghost"), damage=damage) else: if miss: response = "{}\'s ghost is unharmed.".format( member.display_name) else: response = "{target_name} is hit!! {target_name} loses {damage} antislime!".format( target_name=(member.display_name + "\'s ghost"), damage=damage) # Persist every users' data. user_data.persist() shootee_data.persist() await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.server.get_member( shootee_data.id_user)) elif shootee_data.life_state == ewcfg.life_state_corpse and shootee_data.busted == True: # Target is already dead and not a ghost. response = "{} is already dead.".format(member.display_name) elif shootee_data.life_state == ewcfg.life_state_corpse and user_data.ghostbust == False: # Target is a ghost but user is not able to bust response = "You don't know how to fight a ghost." else: # Slimes from this shot might be awarded to the boss. role_boss = (ewcfg.role_copkiller if user_iskillers else ewcfg.role_rowdyfucker) boss_slimes = 0 user_inital_level = user_data.slimelevel was_juvenile = False was_killed = False was_shot = False if (shootee_data.life_state == ewcfg.life_state_enlisted) or ( shootee_data.life_state == ewcfg.life_state_juvenile): # User can be shot. if shootee_data.life_state == ewcfg.life_state_juvenile: was_juvenile = True was_shot = True if was_shot: #hunger drain user_data.hunger += ewcfg.hunger_pershot * ewutils.hunger_cost_mod( user_data.slimelevel) # Weaponized flavor text. randombodypart = ewcfg.hitzone_list[random.randrange( len(ewcfg.hitzone_list))] # Weapon-specific adjustments if weapon != None and weapon.fn_effect != None: # Build effect container ctn = EwEffectContainer(miss=miss, crit=crit, slimes_damage=slimes_damage, slimes_spent=slimes_spent, user_data=user_data, shootee_data=shootee_data) # Make adjustments weapon.fn_effect(ctn) # Apply effects for non-reference values miss = ctn.miss crit = ctn.crit slimes_damage = ctn.slimes_damage slimes_spent = ctn.slimes_spent strikes = ctn.strikes # user_data and shootee_data should be passed by reference, so there's no need to assign them back from the effect container. if miss: slimes_damage = 0 # Remove !revive invulnerability. user_data.time_lastrevive = 0 # Spend slimes, to a minimum of zero user_data.change_slimes( n=(-user_data.slimes if slimes_spent >= user_data.slimes else -slimes_spent), source=ewcfg.source_spending) # Damage stats ewstats.track_maximum(user=user_data, metric=ewcfg.stat_max_hitdealt, value=slimes_damage) ewstats.change_stat(user=user_data, metric=ewcfg.stat_lifetime_damagedealt, n=slimes_damage) # Remove repeat killing protection if. if user_data.id_killer == shootee_data.id_user: user_data.id_killer = "" if slimes_damage >= shootee_data.slimes: was_killed = True if was_killed: #adjust statistics ewstats.increment_stat(user=user_data, metric=ewcfg.stat_kills) ewstats.track_maximum(user=user_data, metric=ewcfg.stat_biggest_kill, value=int(slimes_dropped)) if user_data.slimelevel > shootee_data.slimelevel: ewstats.increment_stat( user=user_data, metric=ewcfg.stat_lifetime_ganks) elif user_data.slimelevel < shootee_data.slimelevel: ewstats.increment_stat( user=user_data, metric=ewcfg.stat_lifetime_takedowns) # Collect bounty coinbounty = int( shootee_data.bounty / ewcfg.slimecoin_exchangerate) # 100 slime per coin # Move around slime as a result of the shot. if shootee_data.slimes >= 0: if was_juvenile: user_data.change_slimes( n=slimes_dropped, source=ewcfg.source_killing) else: user_data.change_slimecredit( n=coinbounty, coinsource=ewcfg.coinsource_bounty) user_data.change_slimes( n=slimes_dropped / 2, source=ewcfg.source_killing) boss_slimes += int(slimes_dropped / 2) # Steal items ewitem.item_loot(member=member, id_user_target=cmd.message.author.id) #add bounty user_data.add_bounty(n=(shootee_data.bounty / 2) + (slimes_dropped / 4)) # Give a bonus to the player's weapon skill for killing a stronger player. if shootee_data.slimelevel >= user_data.slimelevel: user_data.add_weaponskill(n=1) # Player was killed. shootee_data.id_killer = user_data.id_user shootee_data.die(cause=ewcfg.cause_killing) shootee_data.change_slimes( n=-slimes_dropped / 10, source=ewcfg.source_ghostification) kill_descriptor = "beaten to death" if weapon != None: response = weapon.str_damage.format( name_player=cmd.message.author.display_name, name_target=member.display_name, hitzone=randombodypart, strikes=strikes) kill_descriptor = weapon.str_killdescriptor if crit: response += " {}".format( weapon.str_crit.format( name_player=cmd.message.author. display_name, name_target=member.display_name)) response += "\n\n{}".format( weapon.str_kill.format( name_player=cmd.message.author.display_name, name_target=member.display_name, emote_skull=ewcfg.emote_slimeskull)) shootee_data.trauma = weapon.id_weapon if slimeoid.level == ewcfg.slimeoid_state_active: brain = ewcfg.brain_map.get(slimeoid.ai) response += "\n\n{}" + brain.str_kill.format( slimeoid_name=shootee_slimeoid.name) if shootee_slimeoid.level == ewcfg.slimeoid_state_active: brain = ewcfg.brain_map.get(shootee_slimeoid.ai) response += "\n\n{}" + brain.str_death.format( slimeoid_name=shootee_slimeoid.name) else: response = "{name_target} is hit!!\n\n{name_target} has died.".format( name_target=member.display_name) shootee_data.trauma = "" if slimeoid.life_state == ewcfg.slimeoid_state_active: brain = ewcfg.brain_map.get(slimeoid.ai) response += "\n\n" + brain.str_kill.format( slimeoid_name=shootee_slimeoid.name) if shootee_slimeoid.life_state == ewcfg.slimeoid_state_active: brain = ewcfg.brain_map.get(shootee_slimeoid.ai) response += "\n\n" + brain.str_death.format( slimeoid_name=shootee_slimeoid.name) deathreport = "You were {} by {}. {}".format( kill_descriptor, cmd.message.author.display_name, ewcfg.emote_slimeskull) deathreport = "{} ".format( ewcfg.emote_slimeskull) + ewutils.formatMessage( member, deathreport) if coinbounty > 0: response += "\n\n SlimeCorp transfers {} SlimeCoin to {}\'s account.".format( str(coinbounty), cmd.message.author.display_name) else: # A non-lethal blow! shootee_data.change_slimes(n=-slimes_damage, source=ewcfg.source_damage) damage = str(slimes_damage) if weapon != None: if miss: response = "{}".format( weapon.str_miss.format( name_player=cmd.message.author. display_name, name_target=member.display_name)) else: response = weapon.str_damage.format( name_player=cmd.message.author.display_name, name_target=member.display_name, hitzone=randombodypart, strikes=strikes) if crit: response += " {}".format( weapon.str_crit.format( name_player=cmd.message.author. display_name, name_target=member.display_name)) response += " {target_name} loses {damage} slime!".format( target_name=member.display_name, damage=damage) else: # unarmed attacks have no miss or crit chance response = "{target_name} is hit!! {target_name} loses {damage} slime!".format( target_name=member.display_name, damage=damage) else: response = 'You are unable to attack {}.'.format( member.display_name) # Add level up text to response if appropriate if user_inital_level < user_data.slimelevel: response += "\n\n{} has been empowered by slime and is now a level {} slimeboi!".format( cmd.message.author.display_name, user_data.slimelevel) # # Give slimes to the boss if possible. # boss_member = None # if boss_slimes > 0: # for member_search in cmd.message.server.members: # if role_boss in ewutils.getRoleMap(member_search.roles): # boss_member = member_search # break # if boss_member != None: # boss_data = EwUser(member = boss_member) # boss_data.change_slimes(n = boss_slimes) # boss_data.persist() kingpin = ewutils.find_kingpin(id_server=cmd.message.server.id, kingpin_role=role_boss) if kingpin: kingpin.change_slimes(n=boss_slimes) kingpin.persist() # Persist every users' data. user_data.persist() shootee_data.persist() # Assign the corpse role to the newly dead player. if was_killed: await ewrolemgr.updateRoles(client=cmd.client, member=member) # Send the response to the player. await cmd.client.send_message( cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) if deathreport != "": sewerchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_sewers) await cmd.client.send_message(sewerchannel, deathreport)
async def mine(cmd): market_data = EwMarket(id_server=cmd.message.author.server.id) user_data = EwUser(member=cmd.message.author) mutations = user_data.get_mutations() time_now = int(time.time()) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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.channel_mines, ewcfg.channel_cv_mines, ewcfg.channel_tt_mines ]: if user_data.hunger >= user_data.get_hunger_max(): return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage( cmd.message.author, "You've exhausted yourself from mining. You'll need some refreshment before getting back to work." )) else: printgrid = False 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 if user_data.poi not in mines_map: response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!" return await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) elif user_data.id_server not in mines_map.get(user_data.poi): init_grid(user_data.poi, user_data.id_server) printgrid = True grid_cont = mines_map.get(user_data.poi).get(user_data.id_server) grid = grid_cont.grid #minesweeper = False if cmd.tokens_count < 2: response = "Please specify which vein to mine." await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) return await print_grid(cmd) else: #minesweeper = True #grid_multiplier = grid_cont.cells_mined ** 0.4 #flag = False row = -1 col = -1 for token in cmd.tokens[1:]: if token.lower() == "reset": user_data.hunger += ewcfg.hunger_perminereset * int( hunger_cost_mod) if random.random() < extra: user_data.hunger += ewcfg.hunger_perminereset user_data.persist() init_grid(user_data.poi, user_data.id_server) return await print_grid(cmd) if row < 1 or col < 1: coords = token.lower() for char in coords: if char in ewcfg.alphabet: col = ewcfg.alphabet.index(char) coords = coords.replace(char, "") try: row = int(coords) except: row = -1 row -= 1 if row not in range(len(grid)) or col not in range( len(grid[row])): response = "Invalid vein." await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) return await print_grid(cmd) mining_yield = 0 mining_accident = False slimes_pertile = ewcfg.slimes_pertile for current_row in range(max(0, row - 1), min(row + 2, len(grid))): for current_col in range( max(0, col - 1), min(col + 2, len(grid[current_row]))): symbol_prev = get_cell_symbol( grid[current_row][current_col]) slimes_fromtile = slimes_pertile if current_row == row and current_col == col: slimes_fromtile *= 2 mining_yield += max( 0, min(slimes_fromtile, grid[current_row][current_col])) grid[current_row][current_col] -= slimes_fromtile if grid[current_row][ current_col] < -60 * ewcfg.slimes_pertile: mining_accident = True if get_cell_symbol( grid[current_row][current_col]) != symbol_prev: printgrid = True if mining_accident: user_data.change_slimes(n=-(user_data.slimes * 0.5)) user_data.persist() init_grid(user_data.poi, user_data.id_server) response = "You have lost an arm and a leg in a mining accident. Tis but a scratch." await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response)) return await print_grid(cmd) 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 ewutils.send_message( cmd.client, cmd.message.channel, ewutils.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 = ewcfg.weapon_map.get( weapon_item.item_props.get("weapon_type")) if weapon.id_weapon == ewcfg.weapon_id_pickaxe: has_pickaxe = True # Determine if an item is found. unearthed_item = False unearthed_item_amount = 0 # 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 random.random() < unearthed_item_chance: unearthed_item = True unearthed_item_amount = 1 if random.randint( 1, 3) != 1 else 2 # 33% chance of extra drop if unearthed_item == True: # If there are multiple possible products, randomly select one. item = random.choice(ewcfg.mine_results) item_props = ewitem.gen_item_props(item) for creation in range(unearthed_item_amount): ewitem.item_create(item_type=item.item_type, id_user=cmd.message.author.id, id_server=cmd.message.server.id, item_props=item_props) if unearthed_item_amount == 1: response = "You unearthed a {}! ".format(item.str_name) elif unearthed_item_amount == 2: response = "You unearthed two (2) {}! ".format( 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) if has_pickaxe == True: mining_yield *= 2 # 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) else: response = "You can't mine here! Go to the mines in Juvie's Row, Toxington, or Cratersville!" if len(response) > 0: await ewutils.send_message( cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
def die(self, cause = None): time_now = int(time.time()) ewutils.end_trade(self.id_user) resp_cont = ewutils.EwResponseContainer(id_server = self.id_server) client = ewcfg.get_client() server = client.get_server(self.id_server) deathreport = '' # remove ghosts inhabiting player self.remove_inhabitation() # Make The death report deathreport = ewutils.create_death_report(cause = cause, user_data = self) resp_cont.add_channel_response(ewcfg.channel_sewers, deathreport) poi = ewcfg.id_to_poi.get(self.poi) if cause == ewcfg.cause_weather: resp_cont.add_channel_response(poi.channel, deathreport) # Grab necessary data for spontaneous combustion before stat reset explosion_block_list = [ewcfg.cause_leftserver, ewcfg.cause_cliff] user_hasCombustion = False if (cause not in explosion_block_list) and (poi.pvp): if ewcfg.mutation_id_spontaneouscombustion in self.get_mutations(): user_hasCombustion = True explode_damage = ewutils.slime_bylevel(self.slimelevel) / 5 explode_district = ewdistrict.EwDistrict(district = self.poi, id_server = self.id_server) explode_poi_channel = ewcfg.id_to_poi.get(self.poi).channel if cause == ewcfg.cause_busted: self.busted = True self.poi = ewcfg.poi_id_thesewers #self.slimes = int(self.slimes * 0.9) else: self.busted = False # reset busted state on normal death; potentially move this to ewspooky.revive self.slimes = 0 self.slimelevel = 1 self.clear_mutations() self.clear_allstatuses() self.totaldamage = 0 self.bleed_storage = 0 self.hunger = 0 self.inebriation = 0 self.bounty = 0 self.time_lastdeath = time_now # if self.life_state == ewcfg.life_state_shambler: # self.degradation += 1 # else: # self.degradation += 5 ewstats.increment_stat(user = self, metric = ewcfg.stat_lifetime_deaths) ewstats.change_stat(user = self, metric = ewcfg.stat_lifetime_slimeloss, n = self.slimes) if cause == ewcfg.cause_cliff: pass else: if self.life_state == ewcfg.life_state_juvenile: # If you were a Juvenile. item_fraction = 4 food_fraction = 4 cosmetic_fraction = 4 else: # If you were a Gangster. item_fraction = 2 food_fraction = 2 cosmetic_fraction = 2 self.slimecoin = int(self.slimecoin) - (int(self.slimecoin) / 10) ewitem.item_dropsome(id_server = self.id_server, id_user = self.id_user, item_type_filter = ewcfg.it_item, fraction = item_fraction) # Drop a random fraction of your items on the ground. ewitem.item_dropsome(id_server = self.id_server, id_user = self.id_user, item_type_filter = ewcfg.it_food, fraction = food_fraction) # Drop a random fraction of your food on the ground. ewitem.item_dropsome(id_server = self.id_server, id_user = self.id_user, item_type_filter = ewcfg.it_cosmetic, fraction = cosmetic_fraction) # Drop a random fraction of your unadorned cosmetics on the ground. ewitem.item_dedorn_cosmetics(id_server = self.id_server, id_user = self.id_user) # Unadorn all of your adorned hats. self.freshness = 0 ewitem.item_dropsome(id_server = self.id_server, id_user = self.id_user, item_type_filter = ewcfg.it_weapon, fraction = 1) # Drop random fraction of your unequipped weapons on the ground. ewutils.weaponskills_clear(id_server = self.id_server, id_user = self.id_user, weaponskill = ewcfg.weaponskill_max_onrevive) self.life_state = ewcfg.life_state_corpse self.poi_death = self.poi self.poi = ewcfg.poi_id_thesewers self.weapon = -1 self.time_expirpvp = 0 if cause == ewcfg.cause_killing_enemy: # If your killer was an Enemy. Duh. ewstats.increment_stat(user = self, metric = ewcfg.stat_lifetime_pve_deaths) if cause == ewcfg.cause_leftserver: ewitem.item_dropall(id_server=self.id_server, id_user=self.id_user) self.sap = 0 self.hardened_sap = 0 self.attack = 0 self.defense = 0 self.speed = 0 ewutils.moves_active[self.id_user] = 0 ewutils.active_target_map[self.id_user] = "" ewutils.active_restrictions[self.id_user] = 0 ewstats.clear_on_death(id_server = self.id_server, id_user = self.id_user) self.persist() if cause not in explosion_block_list: # Run explosion after location/stat reset, to prevent looping onto self if user_hasCombustion: explode_resp = "\n{} spontaneously combusts, horribly dying in a fiery explosion of slime and shrapnel!! Oh, the humanity!\n".format(server.get_member(self.id_user).display_name) ewutils.logMsg("") resp_cont.add_channel_response(explode_poi_channel, explode_resp) explosion = ewutils.explode(damage = explode_damage, district_data = explode_district) resp_cont.add_response_container(explosion) #ewitem.item_destroyall(id_server = self.id_server, id_user = self.id_user) ewutils.logMsg('server {}: {} was killed by {} - cause was {}'.format(self.id_server, self.id_user, self.id_killer, cause)) return(resp_cont)