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 give_kingpins_slime_and_decay_capture_points(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: 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 if district.controlling_faction == ( ewcfg.faction_killers if kingpin.faction == ewcfg.faction_killers else ewcfg.faction_rowdys): # give the kingpin slime based on the district's property class slimegain += ewcfg.district_control_slime_yields[ district.property_class] await district.decay_capture_points() kingpin.change_slimes(n=slimegain) kingpin.persist() ewutils.logMsg(kingpin_role + " just received %d" % slimegain + " slime for their captured districts.")
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)