Exemplo n.º 1
0
async def cmd_howl(cmd):
    user_data = EwUser(member=cmd.message.author)
    slimeoid = EwSlimeoid(member=cmd.message.author)
    response = ewcfg.howls[random.randrange(len(ewcfg.howls))]

    if (slimeoid.life_state == ewcfg.slimeoid_state_active) and (
            user_data.life_state != ewcfg.life_state_corpse):
        response += "\n{} howls along with you! {}".format(
            str(slimeoid.name),
            ewcfg.howls[random.randrange(len(ewcfg.howls))])

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 2
0
async def accept(cmd):
    user = EwUser(member=cmd.message.author)
    if (user.rr_challenger != ""):
        challenger = EwUser(id_user=user.rr_challenger,
                            id_server=user.id_server)
        if (user.rr_challenger != user.id_user
                and challenger.rr_challenger != user.id_user):
            challenger.rr_challenger = user.id_user
            challenger.persist()
            slimeoid_data = EwSlimeoid(member=cmd.message.author)
            if cmd.message.channel.name == ewcfg.channel_arena and ewslimeoid.active_slimeoidbattles.get(
                    slimeoid_data.id_slimeoid):
                response = "You accept the challenge! Both of your Slimeoids ready themselves for combat!"
            elif cmd.message.channel.name == ewcfg.channel_casino:
                response = "You accept the challenge! Both of you head out back behind the casino and load a bullet into the gun."
            await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 3
0
def gen_data_text(id_user=None,
                  id_server=None,
                  display_name=None,
                  channel_name=None):
    resp_cont = ewutils.EwResponseContainer(id_server=id_server)
    response = ""
    user_data = EwUser(id_user=id_user, id_server=id_server)
    slimeoid = EwSlimeoid(id_user=id_user, id_server=id_server)

    mutations = user_data.get_mutations()

    cosmetics = ewitem.inventory(id_user=user_data.id_user,
                                 id_server=user_data.id_server,
                                 item_type_filter=ewcfg.it_cosmetic)
    adorned_cosmetics = []
    for cosmetic in cosmetics:
        cos = EwItem(id_item=cosmetic.get('id_item'))
        if cos.item_props['adorned'] == 'true':
            hue = ewcfg.hue_map.get(cos.item_props.get('hue'))
            adorned_cosmetics.append((hue.str_name +
                                      " " if hue != None else "") +
                                     cosmetic.get('name'))

    if user_data.life_state == ewcfg.life_state_grandfoe:
        poi = ewcfg.id_to_poi.get(user_data.poi)
        if poi != None:
            response = "{} is {} {}.".format(display_name, poi.str_in,
                                             poi.str_name)
        else:
            response = "You can't discern anything useful about {}.".format(
                display_name)

        resp_cont.add_channel_response(channel_name, response)
    else:

        # return somebody's score
        if user_data.life_state == ewcfg.life_state_corpse:
            response = "{} is a level {} deadboi.".format(
                display_name, user_data.slimelevel)
        else:
            response = "{} is a level {} slimeboi.".format(
                display_name, user_data.slimelevel)

        coinbounty = int(user_data.bounty / ewcfg.slimecoin_exchangerate)

        weapon_item = EwItem(id_item=user_data.weapon)
        weapon = ewcfg.weapon_map.get(
            weapon_item.item_props.get("weapon_type"))

        if weapon != None:
            response += " {} {}{}.".format(
                ewcfg.str_weapon_married if user_data.weaponmarried == True
                else ewcfg.str_weapon_wielding,
                ("" if len(weapon_item.item_props.get("weapon_name")) == 0 else
                 "{}, ".format(weapon_item.item_props.get("weapon_name"))),
                weapon.str_weapon)
            if user_data.weaponskill >= 5:
                response += " {}".format(
                    weapon.str_weaponmaster.format(
                        rank=(user_data.weaponskill - 4)))

        trauma = ewcfg.weapon_map.get(user_data.trauma)
        # if trauma is not gathered from weapon_map, get it from attack_type_map
        if trauma == None:
            trauma = ewcfg.attack_type_map.get(user_data.trauma)

        if trauma != None:
            response += " {}".format(trauma.str_trauma)

        response_block = ""
        for mutation in mutations:
            mutation_flavor = ewcfg.mutations_map[mutation]
            response_block += "{} ".format(mutation_flavor.str_describe_other)

        if len(response_block) > 0:
            response += "\n\n" + response_block

        resp_cont.add_channel_response(channel_name, response)

        response = ""
        response_block = ""

        user_kills = ewstats.get_stat(user=user_data, metric=ewcfg.stat_kills)

        enemy_kills = ewstats.get_stat(user=user_data,
                                       metric=ewcfg.stat_pve_kills)

        if user_kills > 0 and enemy_kills > 0:
            response_block += "They have {:,} confirmed kills, and {:,} confirmed hunts. ".format(
                user_kills, enemy_kills)
        elif user_kills > 0:
            response_block += "They have {:,} confirmed kills. ".format(
                user_kills)
        elif enemy_kills > 0:
            response_block += "They have {:,} confirmed hunts. ".format(
                enemy_kills)

        if coinbounty != 0:
            response_block += "SlimeCorp offers a bounty of {:,} SlimeCoin for their death. ".format(
                coinbounty)

        if len(adorned_cosmetics) > 0:
            response_block += "They have a {} adorned. ".format(
                ewutils.formatNiceList(adorned_cosmetics, 'and'))

        statuses = user_data.getStatusEffects()

        for status in statuses:
            status_effect = EwStatusEffect(id_status=status,
                                           user_data=user_data)
            if status_effect.time_expire > time.time(
            ) or status_effect.time_expire == -1:
                status_flavor = ewcfg.status_effects_def_map.get(status)
                if status_flavor is not None:
                    response_block += status_flavor.str_describe + " "

        if (slimeoid.life_state == ewcfg.slimeoid_state_active) and (
                user_data.life_state != ewcfg.life_state_corpse):
            response_block += "They are accompanied by {}, a {}-foot-tall Slimeoid.".format(
                slimeoid.name, str(slimeoid.level))
        if len(response_block) > 0:
            response += "\n" + response_block

        response += "\n\nhttps://ew.krakissi.net/stats/player.html?pl={}".format(
            id_user)

        resp_cont.add_channel_response(channel_name, response)

    return resp_cont
Exemplo n.º 4
0
async def data(cmd):
    response = ""
    user_data = None
    member = None
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.message.server.id)

    if len(cmd.tokens) > 1 and cmd.mentions_count == 0:
        user_data = EwUser(member=cmd.message.author)

        soughtenemy = " ".join(cmd.tokens[1:]).lower()
        enemy = find_enemy(soughtenemy, user_data)
        if enemy != None:
            if enemy.attacktype != ewcfg.enemy_attacktype_unarmed:
                response = "{} is a level {} enemy. They have {} slime, and attack with their {}.".format(
                    enemy.display_name, enemy.level, enemy.slimes,
                    enemy.attacktype)
            else:
                response = "{} is a level {} enemy. They have {} slime.".format(
                    enemy.display_name, enemy.level, enemy.slimes)
        else:
            response = "ENDLESS WAR didn't understand that name."

        resp_cont.add_channel_response(cmd.message.channel.name, response)

    elif cmd.mentions_count == 0:

        user_data = EwUser(member=cmd.message.author)
        slimeoid = EwSlimeoid(member=cmd.message.author)
        mutations = user_data.get_mutations()

        cosmetics = ewitem.inventory(id_user=cmd.message.author.id,
                                     id_server=cmd.message.server.id,
                                     item_type_filter=ewcfg.it_cosmetic)
        adorned_cosmetics = []
        for cosmetic in cosmetics:
            cos = EwItem(id_item=cosmetic.get('id_item'))
            if cos.item_props['adorned'] == 'true':
                hue = ewcfg.hue_map.get(cos.item_props.get('hue'))
                adorned_cosmetics.append((hue.str_name +
                                          " " if hue != None else "") +
                                         cosmetic.get('name'))

        poi = ewcfg.id_to_poi.get(user_data.poi)
        if poi != None:
            response = "You find yourself {} {}. ".format(
                poi.str_in, poi.str_name)

        # return my data
        if user_data.life_state == ewcfg.life_state_corpse:
            response += "You are a level {} deadboi.".format(
                user_data.slimelevel)
        else:
            response += "You are a level {} slimeboi.".format(
                user_data.slimelevel)

        coinbounty = int(user_data.bounty / ewcfg.slimecoin_exchangerate)

        weapon_item = EwItem(id_item=user_data.weapon)
        weapon = ewcfg.weapon_map.get(
            weapon_item.item_props.get("weapon_type"))

        if weapon != None:
            response += " {} {}{}.".format(
                ewcfg.str_weapon_married_self if user_data.weaponmarried
                == True else ewcfg.str_weapon_wielding_self,
                ("" if len(weapon_item.item_props.get("weapon_name")) == 0 else
                 "{}, ".format(weapon_item.item_props.get("weapon_name"))),
                weapon.str_weapon)
            if user_data.weaponskill >= 5:
                response += " {}".format(
                    weapon.str_weaponmaster_self.format(
                        rank=(user_data.weaponskill - 4)))

        trauma = ewcfg.weapon_map.get(user_data.trauma)
        # if trauma is not gathered from weapon_map, get it from attack_type_map
        if trauma == None:
            trauma = ewcfg.attack_type_map.get(user_data.trauma)

        if trauma != None:
            response += " {}".format(trauma.str_trauma_self)

        response_block = ""
        for mutation in mutations:
            mutation_flavor = ewcfg.mutations_map[mutation]
            response_block += "{} ".format(mutation_flavor.str_describe_self)

        if len(response_block) > 0:
            response += "\n\n" + response_block

        resp_cont.add_channel_response(cmd.message.channel.name, response)

        response = ""
        response_block = ""

        user_kills = ewstats.get_stat(user=user_data, metric=ewcfg.stat_kills)
        enemy_kills = ewstats.get_stat(user=user_data,
                                       metric=ewcfg.stat_pve_kills)

        if user_kills > 0 and enemy_kills > 0:
            response_block += "You have {:,} confirmed kills, and {:,} confirmed hunts. ".format(
                user_kills, enemy_kills)
        elif user_kills > 0:
            response_block += "You have {:,} confirmed kills. ".format(
                user_kills)
        elif enemy_kills > 0:
            response_block += "You have {:,} confirmed hunts. ".format(
                enemy_kills)

        if coinbounty != 0:
            response_block += "SlimeCorp offers a bounty of {:,} SlimeCoin for your death. ".format(
                coinbounty)

        if len(adorned_cosmetics) > 0:
            response_block += "You have a {} adorned. ".format(
                ewutils.formatNiceList(adorned_cosmetics, 'and'))

        if user_data.hunger > 0:
            response_block += "You are {}% hungry. ".format(
                round(user_data.hunger * 100.0 / user_data.get_hunger_max(),
                      1))

        if user_data.busted and user_data.life_state == ewcfg.life_state_corpse:
            response_block += "You are busted and therefore cannot leave the sewers until your next !haunt. "

        statuses = user_data.getStatusEffects()

        for status in statuses:
            status_effect = EwStatusEffect(id_status=status,
                                           user_data=user_data)
            if status_effect.time_expire > time.time(
            ) or status_effect.time_expire == -1:
                status_flavor = ewcfg.status_effects_def_map.get(status)
                if status_flavor is not None:
                    response_block += status_flavor.str_describe_self + " "

        if (slimeoid.life_state == ewcfg.slimeoid_state_active) and (
                user_data.life_state != ewcfg.life_state_corpse):
            response_block += "You are accompanied by {}, a {}-foot-tall Slimeoid. ".format(
                slimeoid.name, str(slimeoid.level))

        if len(response_block) > 0:
            response += "\n" + response_block

        response += "\n\nhttps://ew.krakissi.net/stats/player.html?pl={}".format(
            user_data.id_user)

        resp_cont.add_channel_response(cmd.message.channel.name, response)
    else:
        member = cmd.mentions[0]
        resp_cont = gen_data_text(id_user=member.id,
                                  id_server=member.server.id,
                                  display_name=member.display_name,
                                  channel_name=cmd.message.channel.name)

    # Send the response to the player.
    resp_cont.format_channel_response(cmd.message.channel.name,
                                      cmd.message.author)
    await resp_cont.post()

    await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)
    if member != None:
        await ewrolemgr.updateRoles(client=cmd.client, member=member)
Exemplo n.º 5
0
async def revive(cmd):
    time_now = int(time.time())
    response = ""

    if cmd.message.channel.name != ewcfg.channel_endlesswar and cmd.message.channel.name != ewcfg.channel_sewers:
        response = "Come to me. I hunger. #{}.".format(ewcfg.channel_sewers)
    else:
        player_data = EwUser(member=cmd.message.author)

        time_until_revive = (player_data.time_lastdeath +
                             player_data.degradation) - time_now
        if time_until_revive > 0:
            response = "ENDLESS WAR is not ready to {} you yet ({}s).".format(
                cmd.tokens[0], time_until_revive)
            return await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(cmd.message.author, response))

        slimeoid = EwSlimeoid(member=cmd.message.author)

        if player_data.life_state == ewcfg.life_state_corpse:
            market_data = EwMarket(id_server=cmd.message.server.id)

            # Endless War collects his fee.
            #fee = (player_data.slimecoin / 10)
            #player_data.change_slimecoin(n = -fee, coinsource = ewcfg.coinsource_revival)
            #market_data.slimes_revivefee += fee
            #player_data.busted = False

            # Preserve negaslime
            if player_data.slimes < 0:
                #market_data.negaslime += player_data.slimes
                player_data.change_slimes(n=-player_data.slimes)  # set to 0

            # reset slimelevel to zero
            player_data.slimelevel = 0

            # Set time of last revive. This used to provied spawn protection, but currently isn't used.
            player_data.time_lastrevive = time_now

            if player_data.degradation >= 100:
                player_data.life_state = ewcfg.life_state_shambler
                player_data.change_slimes(n=0.5 * ewcfg.slimes_shambler)
                player_data.trauma = ""
                poi_death = ewcfg.id_to_poi.get(player_data.poi_death)
                if ewmap.inaccessible(poi=poi_death, user_data=player_data):
                    player_data.poi = ewcfg.poi_id_downtown
                else:
                    player_data.poi = poi_death.id_poi
            else:
                # Set life state. This is what determines whether the player is actually alive.
                player_data.life_state = ewcfg.life_state_juvenile
                # Give player some initial slimes.
                player_data.change_slimes(n=ewcfg.slimes_onrevive)
                # Get the player out of the sewers.
                player_data.poi = ewcfg.poi_id_downtown

            player_data.persist()
            market_data.persist()

            # Shower every district in the city with slime from the sewers.
            sewer_data = EwDistrict(district=ewcfg.poi_id_thesewers,
                                    id_server=cmd.message.server.id)
            # the amount of slime showered is divided equally amongst the districts
            districts_amount = len(ewcfg.capturable_districts)
            geyser_amount = int(0.5 * sewer_data.slimes / districts_amount)
            # Get a list of all the districts
            for poi in ewcfg.capturable_districts:
                district_data = EwDistrict(district=poi,
                                           id_server=cmd.message.server.id)

                district_data.change_slimes(n=geyser_amount)
                sewer_data.change_slimes(n=-1 * geyser_amount)

                district_data.persist()
                sewer_data.persist()

            sewer_inv = ewitem.inventory(id_user=sewer_data.name,
                                         id_server=sewer_data.id_server)
            for item in sewer_inv:
                district = ewcfg.poi_id_slimesea
                if random.random() < 0.5:
                    district = random.choice(ewcfg.capturable_districts)
                ewitem.give_item(id_item=item.get("id_item"),
                                 id_user=district,
                                 id_server=sewer_data.id_server)

            await ewrolemgr.updateRoles(client=cmd.client,
                                        member=cmd.message.author)

            response = '{slime4} Geysers of fresh slime erupt from every manhole in the city, showering their surrounding districts. {slime4} {name} has been reborn in slime. {slime4}'.format(
                slime4=ewcfg.emote_slime4,
                name=cmd.message.author.display_name)
        else:
            response = 'You\'re not dead just yet.'

    #	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 slimeoid.life_state == ewcfg.slimeoid_state_active:
            reunite = ""
            brain = ewcfg.brain_map.get(slimeoid.ai)
            reunite += brain.str_revive.format(slimeoid_name=slimeoid.name)
            new_poi = ewcfg.id_to_poi.get(player_data.poi)
            revivechannel = ewutils.get_channel(cmd.message.server,
                                                new_poi.channel)
            reunite = ewutils.formatMessage(cmd.message.author, reunite)
            await ewutils.send_message(cmd.client, revivechannel, reunite)

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 6
0
async def summon_negaslimeoid(cmd):
    response = ""
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state != ewcfg.life_state_corpse:
        response = "Only the dead have the occult knowledge required to summon a cosmic horror."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi not in ewcfg.capturable_districts:
        response = "You can't conduct the ritual here."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    name = None
    if cmd.tokens_count > 1:
        #value = ewutils.getIntToken(tokens = cmd.tokens, allow_all = True, negate = True)
        slimeoid = EwSlimeoid(member=cmd.message.author,
                              sltype=ewcfg.sltype_nega)
        if slimeoid.life_state != ewcfg.slimeoid_state_none:
            response = "You already have an active negaslimeoid."
            return await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(cmd.message.author, response))
        negaslimeoid_name = cmd.message.content[(len(cmd.tokens[0])):].strip()

        if len(negaslimeoid_name) > 32:
            response = "That name is too long. ({:,}/32)".format(
                len(negaslimeoid_name))
            return await ewutils.send_message(
                cmd.client, cmd.message.channel,
                ewutils.formatMessage(cmd.message.author, response))
        market_data = EwMarket(id_server=cmd.message.author.server.id)

        if market_data.negaslime >= 0:
            response = "The dead haven't amassed any negaslime yet."
        else:
            max_level = min(
                len(str(user_data.slimes)) - 1,
                len(str(market_data.negaslime)) - 1)
            level = random.randint(1, max_level)
            value = 10**(level - 1)
            #user_data.change_slimes(n = int(value/10))
            market_data.negaslime += value
            slimeoid.sltype = ewcfg.sltype_nega
            slimeoid.life_state = ewcfg.slimeoid_state_active
            slimeoid.level = level
            slimeoid.id_user = user_data.id_user
            slimeoid.id_server = user_data.id_server
            slimeoid.poi = user_data.poi
            slimeoid.name = negaslimeoid_name
            slimeoid.body = random.choice(ewcfg.body_names)
            slimeoid.head = random.choice(ewcfg.head_names)
            slimeoid.legs = random.choice(ewcfg.mobility_names)
            slimeoid.armor = random.choice(ewcfg.defense_names)
            slimeoid.weapon = random.choice(ewcfg.offense_names)
            slimeoid.special = random.choice(ewcfg.special_names)
            slimeoid.ai = random.choice(ewcfg.brain_names)
            for i in range(level):
                rand = random.randrange(3)
                if rand == 0:
                    slimeoid.atk += 1
                elif rand == 1:
                    slimeoid.defense += 1
                else:
                    slimeoid.intel += 1

            user_data.persist()
            slimeoid.persist()
            market_data.persist()

            response = "You have summoned **{}**, a {}-foot-tall Negaslimeoid.".format(
                slimeoid.name, slimeoid.level)
            desc = ewslimeoid.slimeoid_describe(slimeoid)
            response += desc

    else:
        response = "To summon a negaslimeoid you must first know its name."
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 7
0
async def sow(cmd):
    user_data = EwUser(member=cmd.message.author)

    # Checking availability of sow action
    if user_data.life_state != ewcfg.life_state_juvenile:
        response = "Only Juveniles of pure heart and with nothing better to do can farm."

    elif user_data.poi not in [
            ewcfg.poi_id_jr_farms, ewcfg.poi_id_og_farms, ewcfg.poi_id_ab_farms
    ]:
        response = "The cracked, filthy concrete streets around you would be a pretty terrible place for a farm. Try again on more arable land."

    else:
        if user_data.poi == ewcfg.poi_id_jr_farms:
            farm_id = ewcfg.poi_id_jr_farms
        elif user_data.poi == ewcfg.poi_id_og_farms:
            farm_id = ewcfg.poi_id_og_farms
        else:  # if it's the farm in arsonbrook
            farm_id = ewcfg.poi_id_ab_farms

        farm = EwFarm(id_server=cmd.message.server.id,
                      id_user=cmd.message.author.id,
                      farm=farm_id)

        if farm.time_lastsow > 0:
            response = "You’ve already sown something here. Try planting in another farming location. If you’ve planted in all three farming locations, you’re shit out of luck. Just wait, asshole."
        else:
            if cmd.tokens_count > 1:
                item_search = ewutils.flattenTokenListToString(cmd.tokens[1:])
            else:
                item_search = "slimepoudrin"

            item_sought = ewitem.find_item(
                item_search=item_search,
                id_user=cmd.message.author.id,
                id_server=cmd.message.server.id
                if cmd.message.server is not None else None)

            if item_sought == None:
                response = "You don't have anything to plant! Try collecting a poudrin."
            else:
                slimes_onreap = ewcfg.reap_gain
                item_data = EwItem(id_item=item_sought.get("id_item"))
                if item_data.item_type == ewcfg.it_item:
                    if item_data.item_props.get(
                            "id_item") == ewcfg.item_id_slimepoudrin:
                        vegetable = random.choice(ewcfg.vegetable_list)
                        slimes_onreap *= 2
                    elif item_data.item_props.get(
                            "context") == ewcfg.context_slimeoidheart:
                        vegetable = random.choice(ewcfg.vegetable_list)
                        slimes_onreap *= 2

                        slimeoid_data = EwSlimeoid(
                            id_slimeoid=item_data.item_props.get("subcontext"))
                        slimeoid_data.delete()

                    else:
                        response = "The soil has enough toxins without you burying your trash here."
                        return await ewutils.send_message(
                            cmd.client, cmd.message.channel,
                            ewutils.formatMessage(cmd.message.author,
                                                  response))
                elif item_data.item_type == ewcfg.it_food:
                    food_id = item_data.item_props.get("id_food")
                    vegetable = ewcfg.food_map.get(food_id)
                    if ewcfg.vendor_farm not in vegetable.vendors:
                        response = "It sure would be nice if {}s grew on trees, but alas they do not. Idiot.".format(
                            item_sought.get("name"))
                        return await ewutils.send_message(
                            cmd.client, cmd.message.channel,
                            ewutils.formatMessage(cmd.message.author,
                                                  response))

                else:
                    response = "The soil has enough toxins without you burying your trash here."
                    return await ewutils.send_message(
                        cmd.client, cmd.message.channel,
                        ewutils.formatMessage(cmd.message.author, response))

                # Sowing
                response = "You sow a {} into the fertile soil beneath you. It will grow in about 3 hours.".format(
                    item_sought.get("name"))

                farm.time_lastsow = int(time.time() /
                                        60)  # Grow time is stored in minutes.
                farm.time_lastphase = int(time.time())
                farm.slimes_onreap = slimes_onreap
                farm.crop = vegetable.id_food
                farm.phase = ewcfg.farm_phase_sow
                farm.action_required = ewcfg.farm_action_none
                ewitem.item_delete(
                    id_item=item_sought.get('id_item'))  # Remove Poudrins

                farm.persist()

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
async def sow(cmd):
	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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

	# check if the user has a farming tool equipped
	weapon_item = EwItem(id_item=user_data.weapon)
	weapon = ewcfg.weapon_map.get(weapon_item.item_props.get("weapon_type"))
	has_tool = False
	if weapon is not None:
		if ewcfg.weapon_class_farming in weapon.classes:
			has_tool = True

	# Checking availability of sow action
	if user_data.life_state != ewcfg.life_state_juvenile and not has_tool:
		response = "Only Juveniles of pure heart and with nothing better to do can farm."

	elif cmd.message.channel.name not in [ewcfg.channel_jr_farms, ewcfg.channel_og_farms, ewcfg.channel_ab_farms]:
		response = "The cracked, filthy concrete streets around you would be a pretty terrible place for a farm. Try again on more arable land."

	else:
		poi = ewcfg.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 ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
		if user_data.poi == ewcfg.poi_id_jr_farms:
			farm_id = ewcfg.poi_id_jr_farms
		elif user_data.poi == ewcfg.poi_id_og_farms:
			farm_id = ewcfg.poi_id_og_farms
		else:  # if it's the farm in arsonbrook
			farm_id = ewcfg.poi_id_ab_farms

		farm = EwFarm(
			id_server = cmd.guild.id,
			id_user = cmd.message.author.id,
			farm = farm_id
		)

		if farm.time_lastsow > 0:
			response = "You’ve already sown something here. Try planting in another farming location. If you’ve planted in all three farming locations, you’re shit out of luck. Just wait, asshole."
		else:
			it_type_filter = None

			# gangsters can only plant poudrins
			if cmd.tokens_count > 1 and user_data.life_state == ewcfg.life_state_juvenile:
				item_search = ewutils.flattenTokenListToString(cmd.tokens[1:])
				
				# if the item selected was a vegetable, use a food only filter in find_item
				for v in ewcfg.vegetable_list:
					if item_search in v.id_food or item_search in v.str_name:
						it_type_filter = ewcfg.it_food
						break
			else:
				item_search = "slimepoudrin"

			item_sought = ewitem.find_item(item_search = item_search, id_user = cmd.message.author.id, id_server = cmd.guild.id if cmd.guild is not None else None, item_type_filter = it_type_filter)

			if item_sought == None:
				response = "You don't have anything to plant! Try collecting a poudrin."
			else:
				slimes_onreap = ewcfg.reap_gain
				item_data = EwItem(id_item = item_sought.get("id_item"))
				if item_data.item_type == ewcfg.it_item:
					if item_data.item_props.get("id_item") == ewcfg.item_id_slimepoudrin:
						vegetable = random.choice(ewcfg.vegetable_list)
						slimes_onreap *= 2
					elif item_data.item_props.get("context") == ewcfg.context_slimeoidheart:
						vegetable = random.choice(ewcfg.vegetable_list)
						slimes_onreap *= 2

						slimeoid_data = EwSlimeoid(id_slimeoid = item_data.item_props.get("subcontext"))
						slimeoid_data.delete()
						
					else:
						response = "The soil has enough toxins without you burying your trash here."
						return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
				elif item_data.item_type == ewcfg.it_food:
					food_id = item_data.item_props.get("id_food")
					vegetable = ewcfg.food_map.get(food_id)
					if ewcfg.vendor_farm not in vegetable.vendors:
						response = "It sure would be nice if {}s grew on trees, but alas they do not. Idiot.".format(item_sought.get("name"))
						return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
					elif user_data.life_state != ewcfg.life_state_juvenile:
						response = "You lack the knowledge required to grow {}.".format(item_sought.get("name"))
						return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

				else:
					response = "The soil has enough toxins without you burying your trash here."
					return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

				mutations = user_data.get_mutations()
				growth_time = ewcfg.crops_time_to_grow
				if user_data.life_state == ewcfg.life_state_juvenile:
					growth_time /= 2
				if ewcfg.mutation_id_greenfingers in mutations:
					growth_time /= 1.5
				
				hours = int(growth_time / 60)
				minutes = int(growth_time % 60)

				str_growth_time = "{} hour{}{}".format(hours, "s" if hours > 1 else "", " and {} minutes".format(minutes) if minutes > 0 else "")

				# Sowing
				response = "You sow a {} into the fertile soil beneath you. It will grow in about {}.".format(item_sought.get("name"), str_growth_time)

				farm.time_lastsow = int(time.time() / 60)  # Grow time is stored in minutes.
				farm.time_lastphase = int(time.time())
				farm.slimes_onreap = slimes_onreap
				farm.crop = vegetable.id_food
				farm.phase = ewcfg.farm_phase_sow
				farm.action_required = ewcfg.farm_action_none
				farm.sow_life_state = user_data.life_state
				ewitem.item_delete(id_item = item_sought.get('id_item'))  # Remove Poudrins

				farm.persist()

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 10
0
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))
Exemplo n.º 11
0
async def revive(cmd):
	time_now = int(time.time())
	response = ""

	if cmd.message.channel.name != ewcfg.channel_endlesswar and cmd.message.channel.name != ewcfg.channel_sewers:
		response = "Come to me. I hunger. #{}.".format(ewcfg.channel_sewers)
	else:
		player_data = EwUser(member = cmd.message.author)
		slimeoid = EwSlimeoid(member = cmd.message.author)

		if player_data.life_state == ewcfg.life_state_corpse:
			market_data = EwMarket(id_server = cmd.message.server.id)

			# Endless War collects his fee.
			fee = (player_data.slimecredit / 10)
			player_data.change_slimecredit(n = -fee, coinsource = ewcfg.coinsource_revival)
			market_data.slimes_revivefee += fee
			player_data.busted = False
			
			# Preserve negaslime
			if player_data.slimes < 0:
				market_data.negaslime += player_data.slimes
				player_data.change_slimes(n = -player_data.slimes) # set to 0

			# Give player some initial slimes.
			player_data.slimelevel = 0
			player_data.change_slimes(n = ewcfg.slimes_onrevive)

			# Set time of last revive. This used to provied spawn protection, but currently isn't used.
			player_data.time_lastrevive = time_now

			# Set life state. This is what determines whether the player is actually alive.
			player_data.life_state = ewcfg.life_state_juvenile

			# Get the player out of the sewers. Will be endless-war eventually.
			player_data.poi = ewcfg.poi_id_downtown

			player_data.persist()
			market_data.persist()

			# Give some slimes to every living player (currently online)
			for member in cmd.message.server.members:
				if member.id != cmd.message.author.id and member.id != cmd.client.user.id:
					member_data = EwUser(member = member)

					if member_data.life_state != ewcfg.life_state_corpse and member_data.life_state != ewcfg.life_state_grandfoe:
						member_data.change_slimes(n = ewcfg.slimes_onrevive_everyone)
						member_data.persist()

			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)

			response = '{slime4} A geyser of fresh slime erupts, showering Rowdy, Killer, and Juvenile alike. {slime4} {name} has been reborn in slime. {slime4}'.format(slime4 = ewcfg.emote_slime4, name = cmd.message.author.display_name)
		else:
			response = 'You\'re not dead just yet.'

	#	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 slimeoid.life_state == ewcfg.slimeoid_state_active:
			reunite = ""
			brain = ewcfg.brain_map.get(slimeoid.ai)
			reunite += brain.str_revive.format(
			slimeoid_name = slimeoid.name
			)
			downtownchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_downtown)
			reunite = ewutils.formatMessage(cmd.message.author, reunite)
			await cmd.client.send_message(downtownchannel, reunite)

	# Send the response to the player.
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))