Ejemplo n.º 1
0
    public bool exchange_loot()
    {
        // Pickup the item if we have space
        Loot it_loot        = new Loot();
        bool found_exchange = false;

        if (current_treasure != null)
        {
            Loot treasure_loot = current_treasure.GetComponent <Treasure>().get_treasure_loot();

            if (is_accepting_loot(treasure_loot.loot_weight))
            {
                if ((current_treasure != null) && (Vector3.Distance(transform.position, current_treasure.transform.position) <= 1))
                {
                    current_loot = treasure_loot;
                    return(true);
                }
            }

            foreach (Loot lu in player_loot)
            {
                if (lu.loot_worth < treasure_loot.loot_worth)
                {
                    if ((gold_weight + treasure_loot.loot_weight - lu.loot_weight) <= CAPACITY)
                    {
                        found_exchange = true;
                        if ((it_loot.loot_value == 0) || (it_loot.CompareTo(lu) == 1))
                        {
                            it_loot = lu;
                        }
                    }
                }
            }
            if (found_exchange)
            {
                if (current_treasure != null && Vector3.Distance(transform.position, current_treasure.transform.position) <= 1)
                {
                    current_loot = treasure_loot;
                    player_loot.Remove(it_loot);
                    gold_weight -= it_loot.loot_weight;
                    gold_value  -= it_loot.loot_value;
                    return(true);
                }
            }
        }

        return(false);
    }