Exemple #1
0
    /// <summary>
    /// <inheritdoc />
    /// </summary>
    /// <returns></returns>
    public override IEnumerable <GameObject> GetLootItems()
    {
        int target = Value.PickInt();
        int sum    = 0;

        //Sorts the currencies by their value so that higher denominations are prioritized
        var currenciesByValue = Currencies.OrderByDescending(i => i.GetComponentInChildren <CurrencyPickup>().Value);

        //Keep yielding pickups until we've reached our sum
        while (sum < target)
        {
            //Browse the currency items
            foreach (var i in currenciesByValue)
            {
                CurrencyPickup iCurrency = i.GetComponentInChildren <CurrencyPickup>();

                //If the current currency object's value does not exceed the remaining value to yield, then yield it
                if (sum + iCurrency.Value <= target)
                {
                    sum += iCurrency.Value;
                    yield return(i.gameObject);

                    break;
                }
            }
        }
    }
Exemple #2
0
    void Update()
    {
        if (targetCurrency == null)
        {
            if (CurrencySpawner.activeCurrency.Count > 0)
            {
                targetCurrency = CurrencySpawner.activeCurrency.OrderBy(x => (x.transform.position - transform.position).sqrMagnitude).First();
            }
        }

        Vector3 targetPosition = transform.position;

        if (targetCurrency != null)
        {
            target         = targetCurrency.transform;
            targetPosition = new Vector3(target.position.x, transform.position.y, target.position.z);
        }

        Vector3 targetRotation = targetPosition - transform.position;

        if (targetRotation != Vector3.zero)
        {
            transform.rotation = Quaternion.LookRotation(targetRotation);
        }
        transform.position += transform.forward * pig.speed * Time.deltaTime;
    }
Exemple #3
0
    public void SpawnCurrency()
    {
        float          padding        = planeScalar; // prevents currency from spawning inside of walls
        float          randomX        = Random.Range(padding - halfWidth, halfWidth - padding);
        float          randomZ        = Random.Range(padding - halfHeight, halfHeight - padding);
        int            randomIndex    = Random.Range(0, currencyList.Length);
        Currency       currency       = currencyList[randomIndex];
        Transform      currencyPrefab = currency.value < 1f ? coinPrefab : billPrefab;
        Transform      spawn          = Instantiate(currencyPrefab, new Vector3(randomX, currencyPrefab.transform.position.y, randomZ), Quaternion.identity);
        CurrencyPickup pickup         = spawn.GetComponent <CurrencyPickup>();

        pickup.currency = currency;
        activeCurrency.Add(pickup);
    }
 public void AddCurrency(CurrencyPickup currency)
 {
     if (currency.currencyType == CurrencyPickup.typeCurrency.coin)
     {
         PlayerStats.playerStats.coin += currency.value;
         numCoins.text = "Coins: " + coin.ToString();
         //Debug.Log(PlayerStats.playerStats.coin);
     }
     else if (currency.currencyType == CurrencyPickup.typeCurrency.gem)
     {
         PlayerStats.playerStats.gem += currency.value;
         numGems.text = "Gems: " + gem.ToString();
         //Debug.Log(PlayerStats.playerStats.gem);
     }
 }
Exemple #5
0
 public static void Release(CurrencyPickup forsaken)
 {
     activeCurrency.Remove(forsaken);
     Destroy(forsaken.gameObject);
     // TODO Object pooling
 }