Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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