Example #1
0
def pick_special(player, item):
    if item.special == SpecialType.injure_immunity:
        player.injure_immunity = True
    if item.special == SpecialType.monster_immunity:
        player.monster_immunity = True
    if item.special == SpecialType.infection_immunity:
        player.infection_immunity = True
    if item.special == SpecialType.movement_boost:
        player.movement_boost = True

    if config.general.match_type == MatchType.districts:
        others_in_district = [x for x in get_alive_players() if
                              x.district.name == player.district.name and x.get_name() != player.get_name()]
        if len(others_in_district) > 0:
            for i, pl in enumerate(others_in_district):
                if item.special == SpecialType.injure_immunity:
                    pl.injure_immunity = player.injure_immunity
                if item.special == SpecialType.monster_immunity:
                    pl.monster_immunity = player.monster_immunity
                if item.special == SpecialType.infection_immunity:
                    pl.infection_immunity = player.infection_immunity
                if item.special == SpecialType.movement_boost:
                    pl.movement_boost = player.movement_boost

    player.location.items.pop(player.location.items.index(item))
    tweet = Tweet()
    tweet.type = TweetType.somebody_got_special
    tweet.place = player.location
    tweet.item = item
    tweet.player = player
    if config.general.match_type == MatchType.districts and len(others_in_district) > 0:
        tweet.player_list = others_in_district
    write_tweet(tweet)
    return True
Example #2
0
def trap():
    list = []
    for i, p in enumerate(place_list):
        if p.trap_by is None and len(p.players) > 0:
            any_alive = False
            for j, q in enumerate(p.players):
                if q.is_alive:
                    any_alive = True
            if any_alive:
                list.append(p)

    if len(list) > 0:
        candidates_list = []
        while len(candidates_list) == 0:
            place = random.choice(list)
            for i, p in enumerate(place.players):
                if p.is_alive:
                    candidates_list.append(p)

        player = random.choice(candidates_list)

        place.trap_by = player
        tweet = Tweet()
        tweet.type = TweetType.trap
        tweet.place = place
        tweet.player = player
        write_tweet(tweet)
        return True
    else:
        return False
Example #3
0
def pick_weapon(player, weapon):
    if len(player.item_list) <= 1:
        player.item_list.append(weapon)
        player.location.items.pop(player.location.items.index(weapon))
        tweet = Tweet()
        tweet.type = TweetType.somebody_found_item
        tweet.player = player
        tweet.place = player.location
        tweet.item = weapon
        write_tweet(tweet)
    else:
        if player.item_list[0].power >= player.item_list[1].power:
            worst_item = player.item_list[1]
            best_item = player.item_list[0]
        else:
            worst_item = player.item_list[0]
            best_item = player.item_list[1]

        if weapon.power > worst_item.power:
            player.item_list = [weapon, best_item]
            player.location.items.pop(player.location.items.index(weapon))
            tweet = Tweet()
            tweet.type = TweetType.somebody_replaced_item
            tweet.place = player.location
            tweet.item = weapon
            tweet.old_item = worst_item
            tweet.player = player
            write_tweet(tweet)
        else:
            return False
    return True
Example #4
0
def revive():
    dead_players = get_dead_players()
    if len(dead_players) > 0:
        player = random.choice(dead_players)
        player.is_alive = True
        rebuild_district = config.general.match_type == MatchType.districts and player.district.destroyed

        if rebuild_district:
            place = player.district
            place.destroyed = False
        else:
            place = player.location
            while place.destroyed:
                place = random.choice(place_list)

        tweet = Tweet()
        player.location = place
        for i, pl in enumerate(place.players):
            if pl.infected:
                player.infected = True
                tweet.there_was_infection = True
        place.players.append(player)
        tweet.type = TweetType.somebody_revived
        tweet.place = player.location
        tweet.player = player
        tweet.double = rebuild_district

        write_tweet(tweet)

        return True
    else:
        suicide()
Example #5
0
def suicide():
    alive_players = get_alive_players()
    if len(alive_players) < 5:
        return False
    player = random.choice(alive_players)
    kill_player(player)
    tweet = Tweet()
    tweet.type = TweetType.somebody_suicided
    tweet.place = player.location
    tweet.player = player
    write_tweet(tweet)
    if config.general.match_type == MatchType.districts:
        destroy_tweet = destroy_district_if_needed(player.district)
        if destroy_tweet is not None:
            write_tweet(destroy_tweet)
    return True
Example #6
0
def next_entrance():
    alive_players = get_alive_players()
    players_in_place = [x for x in alive_players if x.location is not None]
    players_out = [x for x in alive_players if x.location is None]
    if len(players_out) == 0:
        return False
    candidate = random.choice(players_out)
    move_player(candidate, place_list[0])

    tweet = Tweet()
    tweet.type = TweetType.next_entrance
    tweet.place = candidate.location
    tweet.player = candidate
    tweet.player_list = players_in_place
    write_tweet(tweet)

    return True
Example #7
0
def infect():
    any_infection = any(x for x in player_list if x.infected)
    alive_players = get_alive_players()
    infected_players = []
    healthy_players = []
    for i, p in enumerate(alive_players):
        if p.infected:
            infected_players.append(p)
        elif not p.infection_immunity:
            healthy_players.append(p)

    if not any_infection and len(healthy_players) > 0:
        player = random.choice(healthy_players)
        if not player.infection_immunity:
            player.infected = True
        affected = [x for x in player.location.players if x.get_name() != player.get_name()]
        for i, p in enumerate(affected):
            if not p.infection_immunity:
                p.infected = True

        tweet = Tweet()
        tweet.type = TweetType.somebody_was_infected
        tweet.place = player.location
        tweet.player = player
        tweet.player_list = affected
        write_tweet(tweet)
    elif len(infected_players) > 0:
        player = random.choice(infected_players)
        action_number = random.randint(1, 100)
        if action_number > config.general.infection_die_threshold:
            player.infected = False
            player.infection_immunity = True
            tweet = Tweet()
            tweet.type = TweetType.somebody_got_cured
            tweet.place = player.location
            tweet.player = player
            write_tweet(tweet)
        elif len(alive_players) > 5:
            kill_player(player)
            tweet = Tweet()
            tweet.type = TweetType.somebody_died_of_infection
            tweet.place = player.location
            tweet.player = player
            write_tweet(tweet)
            if config.general.match_type == MatchType.districts:
                destroy_tweet = destroy_district_if_needed(player.district)
                if destroy_tweet is not None:
                    write_tweet(destroy_tweet)
    else:
        return False
    return True
Example #8
0
def tie(player_1, player_2, factor, action_number):
    if not are_friends(player_1, player_2):
        befriend(player_1, player_2)
        tweet = Tweet()
        tweet.type = TweetType.somebody_tied_and_became_friend
        tweet.place = player_1.location
        tweet.player = player_1
        tweet.player_2 = player_2
        tweet.factor = factor
        tweet.action_number = action_number
        write_tweet(tweet)
    else:
        tweet = Tweet()
        tweet.type = TweetType.somebody_tied_and_was_friend
        tweet.place = player_1.location
        tweet.player = player_1
        tweet.player_2 = player_2
        tweet.factor = factor
        tweet.action_number = action_number
        write_tweet(tweet)
    return True
Example #9
0
def monster():
    place = [x for x in place_list if x.monster]

    if len(place) > 0:
        place = place[0]
        action_number = random.randint(1, 100)
        people_list = [
            x for x in place.players if x.is_alive and not x.monster_immunity
        ]

        if action_number < 50 and len(people_list) > 0:
            player = random.choice(people_list)
            kill_player(player)
            tweet = Tweet()
            tweet.type = TweetType.monster_killed
            tweet.place = player.location
            tweet.player = player
            write_tweet(tweet)
            if config.general.match_type == MatchType.districts:
                destroy_tweet = destroy_district_if_needed(player.district)
                if destroy_tweet is not None:
                    write_tweet(destroy_tweet)
        else:
            place.monster = False
            loc_candidates = [
                x for x in place.connection_list if not x.destroyed
            ]

            if len(loc_candidates) > 0 and action_number < 75:
                new_place = random.choice(loc_candidates)
                new_place.monster = True
                tweet = Tweet()
                tweet.type = TweetType.monster_moved
                tweet.place = new_place
                tweet.place_2 = place
                write_tweet(tweet)
            else:
                return False
    else:
        loc_candidates = [x for x in place_list if not x.destroyed]

        new_place = random.choice(loc_candidates)
        new_place.monster = True
        tweet = Tweet()
        tweet.type = TweetType.monster_appeared
        tweet.place = new_place
        write_tweet(tweet)
    return True
Example #10
0
def run_away(player_1, player_2, factor, action_number, inverse):
    tweet = Tweet()

    candidates = [x for x in player_1.location.connection_list if not x.destroyed]

    if len(candidates) == 0:
        return False

    new_location = random.choice(candidates)

    if inverse:
        there_was_infection, infected_or_was_infected_by = who_infected_who(player_1, new_location.players)
        move_player(player_1, new_location)
        tweet.place = player_2.location
        tweet.place_2 = player_1.location
    else:
        there_was_infection, infected_or_was_infected_by = who_infected_who(player_1, new_location.players)
        move_player(player_2, new_location)
        tweet.place = player_1.location
        tweet.place_2 = player_2.location

    tweet.type = TweetType.somebody_escaped
    tweet.player = player_1
    tweet.player_2 = player_2
    tweet.factor = factor
    tweet.action_number = action_number
    tweet.inverse = inverse
    if there_was_infection:
        tweet.there_was_infection = True
    tweet.infected_or_was_infected_by = infected_or_was_infected_by

    if are_friends(player_1, player_2):
        unfriend(player_1, player_2)
        tweet.unfriend = True

    write_tweet(tweet)
    return True
Example #11
0
def steal():
    player_1, player_2, place = get_two_players_in_random_place()

    if (player_1, player_2) == (None, None) or are_friends(player_1, player_2):
        return False

    if len(player_1.item_list) > 0:
        robbed = player_1
        robber = player_2
    elif len(player_2.item_list) > 0:
        robbed = player_2
        robber = player_1
    else:
        return False

    item = random.choice(robbed.item_list)
    index = robbed.item_list.index(item)
    robbed.item_list.pop(index)

    if len(robber.item_list) <= 1:
        robber.item_list.append(item)
        tweet = Tweet()
        tweet.type = TweetType.somebody_stole
        tweet.place = robber.location
        tweet.player = robber
        tweet.player_2 = robbed
        tweet.item = item
        write_tweet(tweet)
    else:
        if robber.item_list[0].power >= robber.item_list[1].power:
            worst_item = robber.item_list[1]
            best_item = robber.item_list[0]
        else:
            worst_item = robber.item_list[0]
            best_item = robber.item_list[1]

        if item.power > worst_item.power:
            robber.item_list = [item, best_item]
            tweet = Tweet()
            tweet.type = TweetType.somebody_stole_and_replaced
            tweet.place = robber.location
            tweet.player = robber
            tweet.player_2 = robbed
            tweet.item = item
            tweet.old_item = worst_item
            write_tweet(tweet)
        else:
            tweet = Tweet()
            tweet.type = TweetType.somebody_stole_and_threw
            tweet.place = robber.location
            tweet.player = robber
            tweet.player_2 = robbed
            tweet.item = item
            write_tweet(tweet)
    return True
Example #12
0
def kill(player_1, player_2, place, factor, action_number, inverse):
    killer = player_1
    killed = player_2
    if inverse:
        killer = player_2
        killed = player_1

    killer.kills = killer.kills + 1
    best_killer_item = killer.get_best_item()
    best_killed_item = killed.get_best_item()

    tweet = Tweet()
    tweet.type = TweetType.somebody_killed
    tweet.place = place
    tweet.player = player_1
    tweet.player_2 = player_2
    tweet.factor = factor
    tweet.action_number = action_number
    tweet.inverse = inverse
    tweet.item = killer.get_best_item()

    if best_killed_item is not None and len(killer.item_list) == 2 and (
            best_killer_item.power < best_killed_item.power):
        # Steal item and throw away
        killer.previous_power = killer.get_power()
        killed.previous_power = killed.get_power()
        killer.item_list = [best_killer_item, best_killed_item]
        killed.item_list.pop(killed.item_list.index(best_killed_item))

        old_item = killer.get_worst_item()
        killer.location.items.append(old_item)
        old_item.thrown_away_by = killer
        tweet.old_item = old_item
        tweet.new_item = best_killed_item
    elif best_killed_item is not None and len(killer.item_list) < 2:
        # Steal item
        killer.previous_power = killer.get_power()
        killed.previous_power = killed.get_power()
        if best_killer_item is not None:
            killer.item_list = [best_killer_item, best_killed_item]
        else:
            killer.item_list = [best_killed_item]
        killed.item_list.pop(killed.item_list.index(best_killed_item))

        tweet.new_item = best_killed_item

    place = killed.location
    place.players.pop(place.players.index(killed))
    killed.is_alive = False

    write_tweet(tweet)
    kill_player(killed)

    killer.previous_power = None
    killed.previous_power = None

    if config.general.match_type == MatchType.districts:
        destroy_tweet = destroy_district_if_needed(killed.district)
        if destroy_tweet is not None:
            write_tweet(destroy_tweet)
    return True
Example #13
0
def attract():
    loc_candidates = []

    for i, p in enumerate(place_list):
        if not p.destroyed and not p.attracted and (
                config.general.max_attracted_players == 0
                or len(p.players) < config.general.max_attracted_players):
            loc_candidates.append(p)

    if len(loc_candidates) == 0:
        return False

    place = random.choice(loc_candidates)
    place.attracted = True
    attracted_players = []

    def append_players_from(location):
        for j, player in enumerate(location.players):
            if player.is_alive and player not in attracted_players:
                attracted_players.append(player)

    attract_range = int(100 / 100 *
                        len([x for x in place_list if not x.destroyed]) /
                        len(place_list))
    append_players_from(place)
    for i, connection in enumerate(place.connection_list):
        append_players_from(connection)
        if attract_range > 1:
            for j, subconnection in enumerate(connection.connection_list):
                append_players_from(subconnection)
                if attract_range > 2:
                    for k, subsubconnection in enumerate(
                            subconnection.connection_list):
                        append_players_from(subsubconnection)

    if len(attracted_players) > sum(player.is_alive
                                    for player in place.players):
        if config.general.max_attracted_players > 0 and len(
                attracted_players) > config.general.max_attracted_players:
            attracted_players = attracted_players[:config.general.
                                                  max_attracted_players]
        alive_players = get_alive_players()

        any_infected = False
        any_healthy = False
        for i, player in enumerate(alive_players):
            if player in attracted_players:
                if player.infected:
                    any_infected = True
                else:
                    any_healthy = True
                move_player(player, place)

        tweet = Tweet()
        tweet.type = TweetType.attraction
        tweet.place = place
        if any_infected and any_healthy:
            tweet.there_was_infection = True
        tweet.player_list = attracted_players
        write_tweet(tweet)
        return True
    else:
        attract()
Example #14
0
def destroy():
    if config.general.match_type == MatchType.districts:
        return False
    list = [x for x in place_list if not x.destroyed]
    if len(list) == 0:
        sys.exit('Error: everything is destroyed')
    place = random.choice(list)

    place.destroyed = True
    place.monster = False
    place.trap_by = None
    place.items = []
    dead_list = []
    escaped_list = []
    route_list = []
    new_location = None

    for j, c in enumerate(place.connection_list):
        if not c.destroyed:
            route_list.append(c)

    if len(route_list) > 0:
        new_location = random.choice(route_list)
    else:
        for j, c in enumerate(place.connection_list):
            for k, sc in enumerate(c.connection_list):
                if not sc.destroyed:
                    route_list.append(sc)

    if len(route_list) > 0:
        new_location = random.choice(route_list)
    else:
        for j, c in enumerate(place.connection_list):
            for k, sc in enumerate(c.connection_list):
                for k, ssc in enumerate(sc.connection_list):
                    if not ssc.destroyed:
                        route_list.append(ssc)

    new_location = random.choice(route_list)

    for i, p in enumerate(place.players):
        if p.is_alive:
            if random.randint(0, 100) >= 75:
                escaped_list.append(p)
            else:
                kill_player(p)
                dead_list.append(p)

    any_infected = False
    any_healthy = False

    for i, p in enumerate(escaped_list):
        if p.infected:
            any_infected = True
        else:
            any_healthy = True
        move_player(p, new_location)

    tweet = Tweet()
    tweet.type = TweetType.destroyed
    tweet.place = place
    tweet.place_2 = new_location
    tweet.player_list = dead_list
    tweet.player_list_2 = escaped_list
    if any_infected and any_healthy:
        tweet.there_was_infection = True
    write_tweet(tweet)
    return True
Example #15
0
def move():
    alive_players = get_alive_players()
    player = random.choice(alive_players)

    loc_candidates = []

    for i, l in enumerate(player.location.connection_list):
        if not l.destroyed:
            loc_candidates.append(l)

    if len(loc_candidates) == 0:
        for j, c in enumerate(player.location.connection_list):
            for k, sc in enumerate(c.connection_list):
                if not sc.destroyed and sc.name != player.location.name:
                    loc_candidates.append(sc)

    if len(loc_candidates) == 0 or player.movement_boost:
        for j, c in enumerate(player.location.connection_list):
            for k, sc in enumerate(c.connection_list):
                for l, ssc in enumerate(sc.connection_list):
                    if not ssc.destroyed and ssc.name != player.location.name:
                        loc_candidates.append(ssc)

    if len(loc_candidates) == 0:
        for j, c in enumerate(player.location.connection_list):
            for k, sc in enumerate(c.connection_list):
                for l, ssc in enumerate(sc.connection_list):
                    for m, sssc in enumerate(ssc.connection_list):
                        if not sssc.destroyed and sssc.name != player.location.name:
                            loc_candidates.append(sssc)

    if len(loc_candidates) == 0:
        candidates = [
            x for x in place_list
            if not x.destroyed and x.name != player.location.name
        ]
        if len(candidates) == 0:
            return False
        else:
            new_location = random.choice(candidates)
    else:
        new_location = random.choice(loc_candidates)

    action_number = random.randint(1, 100)

    tweet = Tweet()

    there_was_infection, infected_or_was_infected_by = who_infected_who(
        player, new_location.players)

    if new_location.trap_by is not None and new_location.trap_by.get_name(
    ) != player.get_name() and not are_friends(new_location.trap_by, player):
        if action_number < 50:
            trapped_by = new_location.trap_by
            new_location.trap_by.kills = new_location.trap_by.kills + 1
            move_player(player, new_location, False)
            kill_player(player)
            tweet.type = TweetType.trapped
            tweet.place = player.location
            tweet.player = player
            tweet.player_2 = trapped_by
            write_tweet(tweet)
            if config.general.match_type == MatchType.districts:
                destroy_tweet = destroy_district_if_needed(player.district)
                if destroy_tweet is not None:
                    write_tweet(destroy_tweet)
        else:
            trapped_by = new_location.trap_by
            new_location.trap_by = None
            tweet.there_was_infection = there_was_infection
            tweet.infected_or_was_infected_by = infected_or_was_infected_by
            move_player(player, new_location)
            tweet = Tweet()
            tweet.type = TweetType.trap_dodged
            tweet.place = player.location
            tweet.player = player
            tweet.player_2 = trapped_by
            write_tweet(tweet)
    else:
        tweet = Tweet()
        if action_number > 90 and len(powerup_list) > 0:
            powerup = random.choice(powerup_list)
            player.powerup_list.append(powerup)
            tweet.item = powerup
        elif action_number > 80:
            player.power = player.power + 2
            tweet.double = True
        elif action_number > 60 and not player.injure_immunity:
            injury = random.choice(injury_list)
            player.injury_list.append(injury)
            tweet.item = injury

        old_location = player.location
        tweet.there_was_infection = there_was_infection
        tweet.infected_or_was_infected_by = infected_or_was_infected_by
        move_player(player, new_location)

        tweet.type = TweetType.somebody_moved
        tweet.place = player.location
        tweet.place_2 = old_location
        tweet.player = player
        write_tweet(tweet)
    return True