Пример #1
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
Пример #2
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
Пример #3
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