Esempio n. 1
0
    //Auto-generate a possible payment we can use to pay for the provided cost
    public Mana GetPaymentForManaCost(ManaCost manaCost)
    {
        Debug.Assert(CanPayManaCost(manaCost));

        Mana manaFinalCost = manaCost.pManaCost.Get();

        //Initially cover the mandatory portions
        Mana manaPayment = new Mana(manaFinalCost[0], manaFinalCost[1], manaFinalCost[2], manaFinalCost[3]);

        //Now we just have to cover the effort portion
        if (manaUsableToPay[Mana.MANATYPE.EFFORT] >= manaFinalCost[Mana.MANATYPE.EFFORT])
        {
            //If we have enough raw effort mana, just use that directly and return
            manaPayment[Mana.MANATYPE.EFFORT] = manaFinalCost[Mana.MANATYPE.EFFORT];
            return(manaPayment);
        }

        //Dump all the raw effort mana we have into the payment (up to the amount of the full cost)
        manaPayment[Mana.MANATYPE.EFFORT] = Mathf.Min(manaUsableToPay[Mana.MANATYPE.EFFORT], manaFinalCost[Mana.MANATYPE.EFFORT]);

        int nEffortLeftToPay = manaFinalCost[Mana.MANATYPE.EFFORT] - manaPayment[Mana.MANATYPE.EFFORT];
        //Now generate a Mana struct representing the mana we have that we haven't yet used in our payment
        Mana manaUsableForEffort = Mana.SubMana(manaUsableToPay, manaPayment);

        //Repeatedly select a random owned mana and add it to the payment
        for (; nEffortLeftToPay > 0; nEffortLeftToPay--)
        {
            int nRandomManaType = Random.Range(0, (int)Mana.MANATYPE.EFFORT);
            for (int i = 0; i < (int)Mana.MANATYPE.EFFORT; i++)
            {
                //Cycle through the types of mana until we find one that we still have a supply of
                int nManaTypeIndex = (nRandomManaType + i) % (int)Mana.MANATYPE.EFFORT;
                if (manaUsableForEffort[nManaTypeIndex] > 0)
                {
                    //We have at least 1 of this mana to use for paying effort
                    manaUsableForEffort[nManaTypeIndex]--;
                    break;
                }
            }
        }

        if (manaCost.CanBePaidWith(manaPayment) == false)
        {
            Debug.LogError("Generated " + manaPayment + " but it can't pay for " + manaCost);
        }

        return(manaPayment);
    }
Esempio n. 2
0
 public static FnValidSelection COVERSCOST(ManaCost manaCostRequired)
 {
     return((object manaPaid, InputSkillSelection selections) => (manaCostRequired.CanBePaidWith((Mana)manaPaid)));
 }
Esempio n. 3
0
    public void PayManaPaymentForCost(Mana manaPaid, ManaCost manaCost)
    {
        Debug.Assert(manaCost.CanBePaidWith(manaPaid));

        manaOwned.ChangeMana(Mana.GetNegatedMana(manaPaid));
    }
Esempio n. 4
0
 //Quickly check if we have enough mana to pay the provided cost
 public bool CanPayManaCost(ManaCost manaCost)
 {
     //Just treat our entire mana pool as a Mana payment and see if it could cover the cost
     return(manaCost.CanBePaidWith(manaUsableToPay));
 }